| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
namespace MediaWiki\SpecialPage; |
| 25 |
|
| 26 |
use ErrorPageError; |
| 27 |
use MediaWiki\Auth\AuthManager; |
| 28 |
use MediaWiki\Config\Config; |
| 29 |
use MediaWiki\Context\IContextSource; |
| 30 |
use MediaWiki\Context\RequestContext; |
| 31 |
use MediaWiki\HookContainer\HookContainer; |
| 32 |
use MediaWiki\HookContainer\HookRunner; |
| 33 |
use MediaWiki\Language\Language; |
| 34 |
use MediaWiki\Language\RawMessage; |
| 35 |
use MediaWiki\Linker\LinkRenderer; |
| 36 |
use MediaWiki\MainConfigNames; |
| 37 |
use MediaWiki\MediaWikiServices; |
| 38 |
use MediaWiki\Message\Message; |
| 39 |
use MediaWiki\Navigation\PagerNavigationBuilder; |
| 40 |
use MediaWiki\Output\OutputPage; |
| 41 |
use MediaWiki\Permissions\Authority; |
| 42 |
use MediaWiki\Permissions\PermissionStatus; |
| 43 |
use MediaWiki\Request\WebRequest; |
| 44 |
use MediaWiki\Title\Title; |
| 45 |
use MediaWiki\Title\TitleValue; |
| 46 |
use MediaWiki\User\User; |
| 47 |
use MessageLocalizer; |
| 48 |
use MWCryptRand; |
| 49 |
use PermissionsError; |
| 50 |
use ReadOnlyError; |
| 51 |
use SearchEngineFactory; |
| 52 |
use Skin; |
| 53 |
use UserNotLoggedIn; |
| 54 |
use Wikimedia\Message\MessageSpecifier; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
class SpecialPage implements MessageLocalizer { |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
protected $mName; |
| 73 |
|
| 74 |
|
| 75 |
private $mLocalName; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
protected $mRestriction; |
| 82 |
|
| 83 |
|
| 84 |
private $mListed; |
| 85 |
|
| 86 |
|
| 87 |
protected $mIncluding; |
| 88 |
|
| 89 |
|
| 90 |
protected $mIncludable; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
protected $mContext; |
| 97 |
|
| 98 |
|
| 99 |
private $contentLanguage; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
private $linkRenderer = null; |
| 105 |
|
| 106 |
|
| 107 |
private $hookContainer; |
| 108 |
|
| 109 |
private $hookRunner; |
| 110 |
|
| 111 |
|
| 112 |
private $authManager = null; |
| 113 |
|
| 114 |
|
| 115 |
private $specialPageFactory; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
public static function newSearchPage( User $user ) { |
| 128 |
|
| 129 |
$userOptionsManager = MediaWikiServices::getInstance()->getUserOptionsManager(); |
| 130 |
$title = $userOptionsManager->getOption( $user, 'search-special-page' ); |
| 131 |
if ( $title ) { |
| 132 |
$page = self::getTitleFor( $title ); |
| 133 |
$factory = MediaWikiServices::getInstance()->getSpecialPageFactory(); |
| 134 |
if ( $factory->exists( $page->getText() ) ) { |
| 135 |
return $page; |
| 136 |
} |
| 137 |
} |
| 138 |
return self::getTitleFor( 'Search' ); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
public static function getTitleFor( $name, $subpage = false, $fragment = '' ) { |
| 155 |
return Title::newFromLinkTarget( |
| 156 |
self::getTitleValueFor( $name, $subpage, $fragment ) |
| 157 |
); |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
public static function getTitleValueFor( $name, $subpage = false, $fragment = '' ) { |
| 170 |
$name = MediaWikiServices::getInstance()->getSpecialPageFactory()-> |
| 171 |
getLocalNameFor( $name, $subpage ); |
| 172 |
|
| 173 |
return new TitleValue( NS_SPECIAL, $name, $fragment ); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
public static function getSafeTitleFor( $name, $subpage = false ) { |
| 184 |
$name = MediaWikiServices::getInstance()->getSpecialPageFactory()-> |
| 185 |
getLocalNameFor( $name, $subpage ); |
| 186 |
if ( $name ) { |
| 187 |
return Title::makeTitleSafe( NS_SPECIAL, $name ); |
| 188 |
} else { |
| 189 |
return null; |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
public function __construct( |
| 213 |
$name = '', $restriction = '', $listed = true, |
| 214 |
$function = false, $file = '', $includable = false |
| 215 |
) { |
| 216 |
$this->mName = $name; |
| 217 |
$this->mRestriction = $restriction; |
| 218 |
$this->mListed = $listed; |
| 219 |
$this->mIncludable = $includable; |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
public function getName() { |
| 227 |
return $this->mName; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
public function getRestriction() { |
| 235 |
return $this->mRestriction; |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
public function isListed() { |
| 247 |
return $this->mListed; |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
public function isIncludable() { |
| 256 |
return $this->mIncludable; |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
public function maxIncludeCacheTime() { |
| 271 |
return $this->getConfig()->get( MainConfigNames::MiserMode ) ? $this->getCacheTTL() : 0; |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
protected function getCacheTTL() { |
| 279 |
return 60 * 60; |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
public function including( $x = null ) { |
| 288 |
return wfSetVar( $this->mIncluding, $x ); |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
public function getLocalName() { |
| 297 |
if ( !isset( $this->mLocalName ) ) { |
| 298 |
$this->mLocalName = $this->getSpecialPageFactory()->getLocalNameFor( $this->mName ); |
| 299 |
} |
| 300 |
|
| 301 |
return $this->mLocalName; |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
public function isExpensive() { |
| 314 |
return false; |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
public function isCached() { |
| 328 |
return false; |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
public function isRestricted() { |
| 340 |
|
| 341 |
return $this->mRestriction != '' && !MediaWikiServices::getInstance() |
| 342 |
->getGroupPermissionsLookup() |
| 343 |
->groupHasPermission( '*', $this->mRestriction ); |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
public function userCanExecute( User $user ) { |
| 356 |
return MediaWikiServices::getInstance() |
| 357 |
->getPermissionManager() |
| 358 |
->userHasRight( $user, $this->mRestriction ); |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
protected function authorizeAction( ?string $action = null ): PermissionStatus { |
| 373 |
$action ??= $this->getRestriction(); |
| 374 |
|
| 375 |
if ( !$action ) { |
| 376 |
return PermissionStatus::newGood(); |
| 377 |
} |
| 378 |
|
| 379 |
$status = PermissionStatus::newEmpty(); |
| 380 |
$this->getAuthority()->authorizeAction( $action, $status ); |
| 381 |
return $status; |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
protected function displayRestrictionError() { |
| 391 |
throw new PermissionsError( $this->mRestriction ); |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
public function checkPermissions() { |
| 403 |
if ( !$this->userCanExecute( $this->getUser() ) ) { |
| 404 |
$this->displayRestrictionError(); |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
public function checkReadOnly() { |
| 416 |
|
| 417 |
|
| 418 |
if ( MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly() ) { |
| 419 |
throw new ReadOnlyError; |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
public function requireLogin( |
| 435 |
$reasonMsg = 'exception-nologin-text', $titleMsg = 'exception-nologin' |
| 436 |
) { |
| 437 |
if ( $this->getUser()->isAnon() ) { |
| 438 |
throw new UserNotLoggedIn( $reasonMsg, $titleMsg ); |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
public function requireNamedUser( |
| 455 |
$reasonMsg = 'exception-nologin-text', $titleMsg = 'exception-nologin', bool $alwaysRedirectToLoginPage = false |
| 456 |
) { |
| 457 |
if ( !$this->getUser()->isNamed() ) { |
| 458 |
throw new UserNotLoggedIn( $reasonMsg, $titleMsg, [], $alwaysRedirectToLoginPage ); |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
protected function getLoginSecurityLevel() { |
| 471 |
return false; |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
protected function setReauthPostData( array $data ) { |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
protected function checkLoginSecurityLevel( $level = null ) { |
| 520 |
$level = $level ?: $this->getName(); |
| 521 |
$key = 'SpecialPage:reauth:' . $this->getName(); |
| 522 |
$request = $this->getRequest(); |
| 523 |
|
| 524 |
$securityStatus = $this->getAuthManager()->securitySensitiveOperationStatus( $level ); |
| 525 |
if ( $securityStatus === AuthManager::SEC_OK ) { |
| 526 |
$uniqueId = $request->getVal( 'postUniqueId' ); |
| 527 |
if ( $uniqueId ) { |
| 528 |
$key .= ':' . $uniqueId; |
| 529 |
$session = $request->getSession(); |
| 530 |
$data = $session->getSecret( $key ); |
| 531 |
if ( $data ) { |
| 532 |
$session->remove( $key ); |
| 533 |
$this->setReauthPostData( $data ); |
| 534 |
} |
| 535 |
} |
| 536 |
return true; |
| 537 |
} elseif ( $securityStatus === AuthManager::SEC_REAUTH ) { |
| 538 |
$title = self::getTitleFor( 'Userlogin' ); |
| 539 |
$queryParams = $request->getQueryValues(); |
| 540 |
|
| 541 |
if ( $request->wasPosted() ) { |
| 542 |
$data = array_diff_assoc( $request->getValues(), $request->getQueryValues() ); |
| 543 |
if ( $data ) { |
| 544 |
|
| 545 |
$uniqueId = MWCryptRand::generateHex( 6 ); |
| 546 |
$key .= ':' . $uniqueId; |
| 547 |
$queryParams['postUniqueId'] = $uniqueId; |
| 548 |
$session = $request->getSession(); |
| 549 |
$session->persist(); |
| 550 |
$session->setSecret( $key, $data ); |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
$query = [ |
| 555 |
'returnto' => $this->getFullTitle()->getPrefixedDBkey(), |
| 556 |
'returntoquery' => wfArrayToCgi( array_diff_key( $queryParams, [ 'title' => true ] ) ), |
| 557 |
'force' => $level, |
| 558 |
]; |
| 559 |
$url = $title->getFullURL( $query, false, PROTO_HTTPS ); |
| 560 |
|
| 561 |
$this->getOutput()->redirect( $url ); |
| 562 |
return false; |
| 563 |
} |
| 564 |
|
| 565 |
$titleMessage = wfMessage( 'specialpage-securitylevel-not-allowed-title' ); |
| 566 |
$errorMessage = wfMessage( 'specialpage-securitylevel-not-allowed' ); |
| 567 |
throw new ErrorPageError( $titleMessage, $errorMessage ); |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
final protected function setAuthManager( AuthManager $authManager ) { |
| 577 |
$this->authManager = $authManager; |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
final protected function getAuthManager(): AuthManager { |
| 587 |
if ( $this->authManager === null ) { |
| 588 |
|
| 589 |
|
| 590 |
$this->authManager = MediaWikiServices::getInstance()->getAuthManager(); |
| 591 |
} |
| 592 |
return $this->authManager; |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
public function prefixSearchSubpages( $search, $limit, $offset ) { |
| 613 |
$subpages = $this->getSubpagesForPrefixSearch(); |
| 614 |
if ( !$subpages ) { |
| 615 |
return []; |
| 616 |
} |
| 617 |
|
| 618 |
return self::prefixSearchArray( $search, $limit, $subpages, $offset ); |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
protected function getSubpagesForPrefixSearch() { |
| 631 |
return []; |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
public function getAssociatedNavigationLinks() { |
| 642 |
return []; |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
protected function prefixSearchString( |
| 655 |
$search, |
| 656 |
$limit, |
| 657 |
$offset, |
| 658 |
?SearchEngineFactory $searchEngineFactory = null |
| 659 |
) { |
| 660 |
$title = Title::newFromText( $search ); |
| 661 |
if ( !$title || !$title->canExist() ) { |
| 662 |
|
| 663 |
return []; |
| 664 |
} |
| 665 |
|
| 666 |
$searchEngine = $searchEngineFactory |
| 667 |
? $searchEngineFactory->create() |
| 668 |
|
| 669 |
|
| 670 |
: MediaWikiServices::getInstance()->newSearchEngine(); |
| 671 |
$searchEngine->setLimitOffset( $limit, $offset ); |
| 672 |
$searchEngine->setNamespaces( [] ); |
| 673 |
$result = $searchEngine->defaultPrefixSearch( $search ); |
| 674 |
return array_map( static function ( Title $t ) { |
| 675 |
return $t->getPrefixedText(); |
| 676 |
}, $result ); |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
protected static function prefixSearchArray( $search, $limit, array $subpages, $offset ) { |
| 691 |
$escaped = preg_quote( $search, '/' ); |
| 692 |
return array_slice( preg_grep( "/^$escaped/i", |
| 693 |
array_slice( $subpages, $offset ) ), 0, $limit ); |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
protected function setHeaders() { |
| 701 |
$out = $this->getOutput(); |
| 702 |
$out->setArticleRelated( false ); |
| 703 |
$out->setRobotPolicy( $this->getRobotPolicy() ); |
| 704 |
$title = $this->getDescription(); |
| 705 |
|
| 706 |
if ( is_string( $title ) ) { |
| 707 |
wfDeprecated( "string return from {$this->getName()}::getDescription()", '1.41' ); |
| 708 |
$title = ( new RawMessage( '$1' ) )->rawParams( $title ); |
| 709 |
} |
| 710 |
$out->setPageTitleMsg( $title ); |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
final public function run( $subPage ) { |
| 721 |
if ( !$this->getHookRunner()->onSpecialPageBeforeExecute( $this, $subPage ) ) { |
| 722 |
return; |
| 723 |
} |
| 724 |
|
| 725 |
if ( $this->beforeExecute( $subPage ) === false ) { |
| 726 |
return; |
| 727 |
} |
| 728 |
$this->execute( $subPage ); |
| 729 |
$this->afterExecute( $subPage ); |
| 730 |
|
| 731 |
$this->getHookRunner()->onSpecialPageAfterExecute( $this, $subPage ); |
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
protected function beforeExecute( $subPage ) { |
| 745 |
|
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
protected function afterExecute( $subPage ) { |
| 757 |
|
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
public function execute( $subPage ) { |
| 771 |
$this->setHeaders(); |
| 772 |
$this->checkPermissions(); |
| 773 |
$securityLevel = $this->getLoginSecurityLevel(); |
| 774 |
if ( $securityLevel !== false && !$this->checkLoginSecurityLevel( $securityLevel ) ) { |
| 775 |
return; |
| 776 |
} |
| 777 |
$this->outputHeader(); |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
protected function outputHeader( $summaryMessageKey = '' ) { |
| 791 |
if ( $summaryMessageKey == '' ) { |
| 792 |
$msg = strtolower( $this->getName() ) . '-summary'; |
| 793 |
} else { |
| 794 |
$msg = $summaryMessageKey; |
| 795 |
} |
| 796 |
if ( !$this->msg( $msg )->isDisabled() && !$this->including() ) { |
| 797 |
$this->getOutput()->wrapWikiMsg( |
| 798 |
"<div class='mw-specialpage-summary'>\n$1\n</div>", $msg ); |
| 799 |
} |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
public function getDescription() { |
| 816 |
return $this->msg( strtolower( $this->mName ) ); |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
public function getShortDescription( string $path = '' ): string { |
| 831 |
$lowerPath = strtolower( str_replace( '/', '-', $path ) ); |
| 832 |
$shortKey = 'special-tab-' . $lowerPath; |
| 833 |
$shortKey .= '-short'; |
| 834 |
$msgShort = $this->msg( $shortKey ); |
| 835 |
return $msgShort->text(); |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
public function getPageTitle( $subpage = false ) { |
| 846 |
return self::getTitleFor( $this->mName, $subpage ); |
| 847 |
} |
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
public function setContext( $context ) { |
| 856 |
$this->mContext = $context; |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
public function getContext() { |
| 866 |
if ( !( $this->mContext instanceof IContextSource ) ) { |
| 867 |
wfDebug( __METHOD__ . " called and \$mContext is null. " . |
| 868 |
"Using RequestContext::getMain()" ); |
| 869 |
|
| 870 |
$this->mContext = RequestContext::getMain(); |
| 871 |
} |
| 872 |
return $this->mContext; |
| 873 |
} |
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
public function getRequest() { |
| 882 |
return $this->getContext()->getRequest(); |
| 883 |
} |
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
public function getOutput() { |
| 892 |
return $this->getContext()->getOutput(); |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
public function getUser() { |
| 902 |
return $this->getContext()->getUser(); |
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
public function getAuthority(): Authority { |
| 912 |
return $this->getContext()->getAuthority(); |
| 913 |
} |
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
public function getSkin() { |
| 922 |
return $this->getContext()->getSkin(); |
| 923 |
} |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
public function getLanguage() { |
| 932 |
return $this->getContext()->getLanguage(); |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
final public function getContentLanguage(): Language { |
| 942 |
if ( $this->contentLanguage === null ) { |
| 943 |
|
| 944 |
|
| 945 |
$this->contentLanguage = MediaWikiServices::getInstance()->getContentLanguage(); |
| 946 |
} |
| 947 |
return $this->contentLanguage; |
| 948 |
} |
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
final public function setContentLanguage( Language $contentLanguage ) { |
| 958 |
$this->contentLanguage = $contentLanguage; |
| 959 |
} |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
public function getConfig() { |
| 967 |
return $this->getContext()->getConfig(); |
| 968 |
} |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
public function getFullTitle() { |
| 977 |
return $this->getContext()->getTitle(); |
| 978 |
} |
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
protected function getRobotPolicy() { |
| 988 |
return 'noindex,nofollow'; |
| 989 |
} |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
public function msg( $key, ...$params ) { |
| 1001 |
$message = $this->getContext()->msg( $key, ...$params ); |
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
if ( $this->including() ) { |
| 1007 |
$message->setInterfaceMessageFlag( false ); |
| 1008 |
} |
| 1009 |
|
| 1010 |
return $message; |
| 1011 |
} |
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
protected function addFeedLinks( $params ) { |
| 1019 |
$feedTemplate = wfScript( 'api' ); |
| 1020 |
|
| 1021 |
foreach ( $this->getConfig()->get( MainConfigNames::FeedClasses ) as $format => $class ) { |
| 1022 |
$theseParams = $params + [ 'feedformat' => $format ]; |
| 1023 |
$url = wfAppendQuery( $feedTemplate, $theseParams ); |
| 1024 |
$this->getOutput()->addFeedLink( $format, $url ); |
| 1025 |
} |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
public function addHelpLink( $to, $overrideBaseUrl = false ) { |
| 1037 |
if ( $this->including() ) { |
| 1038 |
return; |
| 1039 |
} |
| 1040 |
|
| 1041 |
$msg = $this->msg( strtolower( $this->getName() ) . '-helppage' ); |
| 1042 |
|
| 1043 |
if ( !$msg->isDisabled() ) { |
| 1044 |
$title = Title::newFromText( $msg->plain() ); |
| 1045 |
if ( $title instanceof Title ) { |
| 1046 |
$this->getOutput()->addHelpLink( $title->getLocalURL(), true ); |
| 1047 |
} |
| 1048 |
} else { |
| 1049 |
$this->getOutput()->addHelpLink( $to, $overrideBaseUrl ); |
| 1050 |
} |
| 1051 |
} |
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
public function getFinalGroupName() { |
| 1062 |
$name = $this->getName(); |
| 1063 |
|
| 1064 |
|
| 1065 |
$msg = $this->msg( 'specialpages-specialpagegroup-' . strtolower( $name ) )->inContentLanguage(); |
| 1066 |
if ( !$msg->isBlank() ) { |
| 1067 |
$group = $msg->text(); |
| 1068 |
} else { |
| 1069 |
|
| 1070 |
$group = $this->getGroupName(); |
| 1071 |
} |
| 1072 |
|
| 1073 |
return $group; |
| 1074 |
} |
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
public function doesWrites() { |
| 1097 |
return false; |
| 1098 |
} |
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
protected function getGroupName() { |
| 1111 |
return 'other'; |
| 1112 |
} |
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
protected function useTransactionalTimeLimit() { |
| 1119 |
if ( $this->getRequest()->wasPosted() ) { |
| 1120 |
wfTransactionalTimeLimit(); |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
public function getLinkRenderer(): LinkRenderer { |
| 1129 |
if ( $this->linkRenderer === null ) { |
| 1130 |
|
| 1131 |
$this->linkRenderer = MediaWikiServices::getInstance()->getLinkRendererFactory() |
| 1132 |
->create(); |
| 1133 |
} |
| 1134 |
return $this->linkRenderer; |
| 1135 |
} |
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
public function setLinkRenderer( LinkRenderer $linkRenderer ) { |
| 1142 |
$this->linkRenderer = $linkRenderer; |
| 1143 |
} |
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
protected function buildPrevNextNavigation( |
| 1156 |
$offset, |
| 1157 |
$limit, |
| 1158 |
array $query = [], |
| 1159 |
$atend = false, |
| 1160 |
$subpage = false |
| 1161 |
) { |
| 1162 |
$navBuilder = new PagerNavigationBuilder( $this ); |
| 1163 |
$navBuilder |
| 1164 |
->setPage( $this->getPageTitle( $subpage ) ) |
| 1165 |
->setLinkQuery( [ 'limit' => $limit, 'offset' => $offset ] + $query ) |
| 1166 |
->setLimitLinkQueryParam( 'limit' ) |
| 1167 |
->setCurrentLimit( $limit ) |
| 1168 |
->setPrevTooltipMsg( 'prevn-title' ) |
| 1169 |
->setNextTooltipMsg( 'nextn-title' ) |
| 1170 |
->setLimitTooltipMsg( 'shown-title' ); |
| 1171 |
|
| 1172 |
if ( $offset > 0 ) { |
| 1173 |
$navBuilder->setPrevLinkQuery( [ 'offset' => (string)max( $offset - $limit, 0 ) ] ); |
| 1174 |
} |
| 1175 |
if ( !$atend ) { |
| 1176 |
$navBuilder->setNextLinkQuery( [ 'offset' => (string)( $offset + $limit ) ] ); |
| 1177 |
} |
| 1178 |
|
| 1179 |
return $navBuilder->getHtml(); |
| 1180 |
} |
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
public function setHookContainer( HookContainer $hookContainer ) { |
| 1188 |
$this->hookContainer = $hookContainer; |
| 1189 |
$this->hookRunner = new HookRunner( $hookContainer ); |
| 1190 |
} |
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
protected function getHookContainer() { |
| 1197 |
if ( !$this->hookContainer ) { |
| 1198 |
$this->hookContainer = MediaWikiServices::getInstance()->getHookContainer(); |
| 1199 |
} |
| 1200 |
return $this->hookContainer; |
| 1201 |
} |
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
protected function getHookRunner() { |
| 1210 |
if ( !$this->hookRunner ) { |
| 1211 |
$this->hookRunner = new HookRunner( $this->getHookContainer() ); |
| 1212 |
} |
| 1213 |
return $this->hookRunner; |
| 1214 |
} |
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
final public function setSpecialPageFactory( SpecialPageFactory $specialPageFactory ) { |
| 1222 |
$this->specialPageFactory = $specialPageFactory; |
| 1223 |
} |
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
final protected function getSpecialPageFactory(): SpecialPageFactory { |
| 1230 |
if ( !$this->specialPageFactory ) { |
| 1231 |
|
| 1232 |
|
| 1233 |
$this->specialPageFactory = MediaWikiServices::getInstance()->getSpecialPageFactory(); |
| 1234 |
} |
| 1235 |
return $this->specialPageFactory; |
| 1236 |
} |
| 1237 |
} |
| 1238 |
|
| 1239 |
|
| 1240 |
class_alias( SpecialPage::class, 'SpecialPage' ); |