| 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 |
|
| 25 |
namespace MediaWiki\Title; |
| 26 |
|
| 27 |
use HTMLCacheUpdateJob; |
| 28 |
use InvalidArgumentException; |
| 29 |
use MapCacheLRU; |
| 30 |
use MediaWiki\Cache\LinkCache; |
| 31 |
use MediaWiki\Context\RequestContext; |
| 32 |
use MediaWiki\DAO\WikiAwareEntityTrait; |
| 33 |
use MediaWiki\Deferred\AutoCommitUpdate; |
| 34 |
use MediaWiki\Deferred\DeferredUpdates; |
| 35 |
use MediaWiki\HookContainer\HookRunner; |
| 36 |
use MediaWiki\Html\Html; |
| 37 |
use MediaWiki\Interwiki\InterwikiLookup; |
| 38 |
use MediaWiki\Language\ILanguageConverter; |
| 39 |
use MediaWiki\Language\Language; |
| 40 |
use MediaWiki\Linker\LinkTarget; |
| 41 |
use MediaWiki\MainConfigNames; |
| 42 |
use MediaWiki\MediaWikiServices; |
| 43 |
use MediaWiki\Message\Message; |
| 44 |
use MediaWiki\Page\ExistingPageRecord; |
| 45 |
use MediaWiki\Page\PageIdentity; |
| 46 |
use MediaWiki\Page\PageIdentityValue; |
| 47 |
use MediaWiki\Page\PageReference; |
| 48 |
use MediaWiki\Page\PageStoreRecord; |
| 49 |
use MediaWiki\Page\ProperPageIdentity; |
| 50 |
use MediaWiki\Parser\Sanitizer; |
| 51 |
use MediaWiki\Request\PathRouter; |
| 52 |
use MediaWiki\ResourceLoader\WikiModule; |
| 53 |
use MediaWiki\SpecialPage\SpecialPage; |
| 54 |
use MediaWiki\Utils\MWTimestamp; |
| 55 |
use MessageLocalizer; |
| 56 |
use MWException; |
| 57 |
use RuntimeException; |
| 58 |
use stdClass; |
| 59 |
use Stringable; |
| 60 |
use Wikimedia\Assert\Assert; |
| 61 |
use Wikimedia\Assert\PreconditionException; |
| 62 |
use Wikimedia\Parsoid\Core\LinkTarget as ParsoidLinkTarget; |
| 63 |
use Wikimedia\Parsoid\Core\LinkTargetTrait; |
| 64 |
use Wikimedia\Rdbms\DBAccessObjectUtils; |
| 65 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 66 |
use Wikimedia\Rdbms\IDatabase; |
| 67 |
use Wikimedia\Rdbms\IDBAccessObject; |
| 68 |
use WikiPage; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
class Title implements Stringable, LinkTarget, PageIdentity { |
| 79 |
use WikiAwareEntityTrait; |
| 80 |
use LinkTargetTrait; |
| 81 |
|
| 82 |
|
| 83 |
private static $titleCache = null; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
private static ?Title $cachedMainPage = null; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
private const CACHE_MAX = 1000; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public const NEW_CLONE = 'clone'; |
| 106 |
|
| 107 |
|
| 108 |
private $mTextform = ''; |
| 109 |
|
| 110 |
|
| 111 |
private $mUrlform = ''; |
| 112 |
|
| 113 |
|
| 114 |
private $mDbkeyform = ''; |
| 115 |
|
| 116 |
|
| 117 |
private $mNamespace = NS_MAIN; |
| 118 |
|
| 119 |
|
| 120 |
private $mInterwiki = ''; |
| 121 |
|
| 122 |
|
| 123 |
private $mLocalInterwiki = false; |
| 124 |
|
| 125 |
|
| 126 |
private $mFragment = ''; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public $mArticleID = -1; |
| 138 |
|
| 139 |
|
| 140 |
protected $mLatestID = false; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
private $mContentModel = false; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
private $mForcedContentModel = false; |
| 153 |
|
| 154 |
|
| 155 |
private $mEstimateRevisions; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
public $prefixedText = null; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
private const DEFAULT_NAMESPACE = NS_MAIN; |
| 173 |
|
| 174 |
|
| 175 |
protected $mLength = -1; |
| 176 |
|
| 177 |
|
| 178 |
public $mRedirect = null; |
| 179 |
|
| 180 |
|
| 181 |
private $mHasSubpages; |
| 182 |
|
| 183 |
|
| 184 |
private $mPageLanguage; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
private $mDbPageLanguage = false; |
| 190 |
|
| 191 |
|
| 192 |
private $mTitleValue = null; |
| 193 |
|
| 194 |
|
| 195 |
private $mIsBigDeletion = null; |
| 196 |
|
| 197 |
|
| 198 |
private $mIsValid = null; |
| 199 |
|
| 200 |
|
| 201 |
private $mInstanceCacheKey = null; |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
private function getLanguageConverter( $language ): ILanguageConverter { |
| 213 |
return MediaWikiServices::getInstance()->getLanguageConverterFactory() |
| 214 |
->getLanguageConverter( $language ); |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
private function getPageLanguageConverter(): ILanguageConverter { |
| 222 |
return $this->getLanguageConverter( $this->getPageLanguage() ); |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
private function getDbProvider(): IConnectionProvider { |
| 230 |
return MediaWikiServices::getInstance()->getConnectionProvider(); |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
private static function getTitleFormatter() { |
| 242 |
return MediaWikiServices::getInstance()->getTitleFormatter(); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
private static function getInterwikiLookup() { |
| 254 |
return MediaWikiServices::getInstance()->getInterwikiLookup(); |
| 255 |
} |
| 256 |
|
| 257 |
private function __construct() { |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
public static function newFromDBkey( $key ) { |
| 269 |
$t = new self(); |
| 270 |
|
| 271 |
try { |
| 272 |
$t->secureAndSplit( $key ); |
| 273 |
return $t; |
| 274 |
} catch ( MalformedTitleException $ex ) { |
| 275 |
return null; |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
public static function newFromLinkTarget( ParsoidLinkTarget $linkTarget, $forceClone = '' ) { |
| 291 |
if ( $linkTarget instanceof Title ) { |
| 292 |
|
| 293 |
if ( $forceClone === self::NEW_CLONE ) { |
| 294 |
return clone $linkTarget; |
| 295 |
} else { |
| 296 |
return $linkTarget; |
| 297 |
} |
| 298 |
} |
| 299 |
return self::makeTitle( |
| 300 |
$linkTarget->getNamespace(), |
| 301 |
$linkTarget->getText(), |
| 302 |
$linkTarget->getFragment(), |
| 303 |
$linkTarget->getInterwiki() |
| 304 |
); |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
public static function castFromLinkTarget( ?ParsoidLinkTarget $linkTarget ) { |
| 315 |
if ( !$linkTarget ) { |
| 316 |
return null; |
| 317 |
} |
| 318 |
return self::newFromLinkTarget( $linkTarget ); |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
public static function newFromPageIdentity( PageIdentity $pageIdentity ): Title { |
| 330 |
return self::newFromPageReference( $pageIdentity ); |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
public static function castFromPageIdentity( ?PageIdentity $pageIdentity ): ?Title { |
| 341 |
return self::castFromPageReference( $pageIdentity ); |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
public static function newFromPageReference( PageReference $pageReference ): Title { |
| 353 |
if ( $pageReference instanceof Title ) { |
| 354 |
return $pageReference; |
| 355 |
} |
| 356 |
|
| 357 |
$pageReference->assertWiki( self::LOCAL ); |
| 358 |
$title = self::makeTitle( $pageReference->getNamespace(), $pageReference->getDBkey() ); |
| 359 |
|
| 360 |
if ( $pageReference instanceof PageIdentity ) { |
| 361 |
$title->mArticleID = $pageReference->getId(); |
| 362 |
} |
| 363 |
return $title; |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
public static function castFromPageReference( ?PageReference $pageReference ): ?Title { |
| 374 |
if ( !$pageReference ) { |
| 375 |
return null; |
| 376 |
} |
| 377 |
return self::newFromPageReference( $pageReference ); |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
public static function newFromText( $text, $defaultNamespace = NS_MAIN ) { |
| 400 |
|
| 401 |
if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) { |
| 402 |
throw new InvalidArgumentException( '$text must be a string.' ); |
| 403 |
} |
| 404 |
if ( $text === null || $text === '' ) { |
| 405 |
return null; |
| 406 |
} |
| 407 |
|
| 408 |
try { |
| 409 |
return self::newFromTextThrow( (string)$text, (int)$defaultNamespace ); |
| 410 |
} catch ( MalformedTitleException $ex ) { |
| 411 |
return null; |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) { |
| 435 |
if ( is_object( $text ) ) { |
| 436 |
throw new InvalidArgumentException( '$text must be a string, given an object' ); |
| 437 |
} elseif ( $text === null ) { |
| 438 |
|
| 439 |
|
| 440 |
throw new MalformedTitleException( 'title-invalid-empty' ); |
| 441 |
} |
| 442 |
|
| 443 |
$titleCache = self::getTitleCache(); |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
if ( $defaultNamespace === NS_MAIN ) { |
| 449 |
$t = $titleCache->get( $text ); |
| 450 |
if ( $t ) { |
| 451 |
return $t; |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
|
| 456 |
$filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text ); |
| 457 |
|
| 458 |
$t = new Title(); |
| 459 |
$dbKeyForm = strtr( $filteredText, ' ', '_' ); |
| 460 |
|
| 461 |
$t->secureAndSplit( $dbKeyForm, (int)$defaultNamespace ); |
| 462 |
if ( $defaultNamespace === NS_MAIN ) { |
| 463 |
$t->mInstanceCacheKey = $text; |
| 464 |
$titleCache->set( $text, $t ); |
| 465 |
} |
| 466 |
return $t; |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
private function uncache() { |
| 474 |
if ( $this->mInstanceCacheKey !== null ) { |
| 475 |
$titleCache = self::getTitleCache(); |
| 476 |
$titleCache->clear( $this->mInstanceCacheKey ); |
| 477 |
$this->mInstanceCacheKey = null; |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
public static function newFromURL( $url ) { |
| 497 |
$t = new Title(); |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
if ( !str_contains( self::legalChars(), '+' ) ) { |
| 503 |
$url = strtr( $url, '+', ' ' ); |
| 504 |
} |
| 505 |
|
| 506 |
$dbKeyForm = strtr( $url, ' ', '_' ); |
| 507 |
|
| 508 |
try { |
| 509 |
$t->secureAndSplit( $dbKeyForm ); |
| 510 |
return $t; |
| 511 |
} catch ( MalformedTitleException $ex ) { |
| 512 |
return null; |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
private static function getTitleCache() { |
| 520 |
if ( self::$titleCache === null ) { |
| 521 |
self::$titleCache = new MapCacheLRU( self::CACHE_MAX ); |
| 522 |
} |
| 523 |
return self::$titleCache; |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
public static function newFromID( $id, $flags = 0 ) { |
| 534 |
$pageStore = MediaWikiServices::getInstance()->getPageStore(); |
| 535 |
$dbr = DBAccessObjectUtils::getDBFromRecency( |
| 536 |
MediaWikiServices::getInstance()->getConnectionProvider(), |
| 537 |
$flags |
| 538 |
); |
| 539 |
$row = $dbr->newSelectQueryBuilder() |
| 540 |
->select( $pageStore->getSelectFields() ) |
| 541 |
->from( 'page' ) |
| 542 |
->where( [ 'page_id' => $id ] ) |
| 543 |
->recency( $flags ) |
| 544 |
->caller( __METHOD__ )->fetchRow(); |
| 545 |
if ( $row !== false ) { |
| 546 |
$title = self::newFromRow( $row ); |
| 547 |
} else { |
| 548 |
$title = null; |
| 549 |
} |
| 550 |
|
| 551 |
return $title; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
public static function newFromRow( $row ) { |
| 561 |
$t = self::makeTitle( $row->page_namespace, $row->page_title ); |
| 562 |
$t->loadFromRow( $row ); |
| 563 |
return $t; |
| 564 |
} |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
public function loadFromRow( $row ) { |
| 573 |
if ( $row ) { |
| 574 |
if ( isset( $row->page_id ) ) { |
| 575 |
$this->mArticleID = (int)$row->page_id; |
| 576 |
} |
| 577 |
if ( isset( $row->page_len ) ) { |
| 578 |
$this->mLength = (int)$row->page_len; |
| 579 |
} |
| 580 |
if ( isset( $row->page_is_redirect ) ) { |
| 581 |
$this->mRedirect = (bool)$row->page_is_redirect; |
| 582 |
} |
| 583 |
if ( isset( $row->page_latest ) ) { |
| 584 |
$this->mLatestID = (int)$row->page_latest; |
| 585 |
} |
| 586 |
if ( isset( $row->page_content_model ) ) { |
| 587 |
$this->lazyFillContentModel( $row->page_content_model ); |
| 588 |
} else { |
| 589 |
$this->lazyFillContentModel( false ); |
| 590 |
} |
| 591 |
if ( isset( $row->page_lang ) ) { |
| 592 |
$this->mDbPageLanguage = (string)$row->page_lang; |
| 593 |
} |
| 594 |
} else { |
| 595 |
$this->mArticleID = 0; |
| 596 |
$this->mLength = 0; |
| 597 |
$this->mRedirect = false; |
| 598 |
$this->mLatestID = 0; |
| 599 |
$this->lazyFillContentModel( false ); |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
public static function makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) { |
| 626 |
$t = new Title(); |
| 627 |
$t->mInterwiki = $interwiki; |
| 628 |
$t->mFragment = self::normalizeFragment( $fragment ); |
| 629 |
$t->mNamespace = $ns = (int)$ns; |
| 630 |
$t->mDbkeyform = strtr( $title, ' ', '_' ); |
| 631 |
$t->mArticleID = ( $ns >= 0 ) ? -1 : 0; |
| 632 |
$t->mUrlform = wfUrlencode( $t->mDbkeyform ); |
| 633 |
$t->mTextform = strtr( $title, '_', ' ' ); |
| 634 |
return $t; |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) { |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) { |
| 656 |
return null; |
| 657 |
} |
| 658 |
|
| 659 |
$t = new Title(); |
| 660 |
$dbKeyForm = self::makeName( $ns, $title, $fragment, $interwiki, true ); |
| 661 |
|
| 662 |
try { |
| 663 |
$t->secureAndSplit( $dbKeyForm ); |
| 664 |
return $t; |
| 665 |
} catch ( MalformedTitleException $ex ) { |
| 666 |
return null; |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
public static function newMainPage( ?MessageLocalizer $localizer = null ) { |
| 688 |
static $recursionGuard = false; |
| 689 |
|
| 690 |
$title = null; |
| 691 |
|
| 692 |
if ( !$recursionGuard ) { |
| 693 |
$msg = $localizer ? $localizer->msg( 'mainpage' ) : wfMessage( 'mainpage' ); |
| 694 |
|
| 695 |
$recursionGuard = true; |
| 696 |
$title = self::newFromText( $msg->inContentLanguage()->text() ); |
| 697 |
$recursionGuard = false; |
| 698 |
} |
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
return $title ?? self::makeTitle( NS_MAIN, 'Main Page' ); |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
public static function legalChars() { |
| 721 |
global $wgLegalTitleChars; |
| 722 |
return $wgLegalTitleChars; |
| 723 |
} |
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
public static function convertByteClassToUnicodeClass( $byteClass ) { |
| 735 |
$length = strlen( $byteClass ); |
| 736 |
|
| 737 |
$x0 = $x1 = $x2 = ''; |
| 738 |
|
| 739 |
$d0 = $d1 = ''; |
| 740 |
|
| 741 |
$ord0 = $ord1 = $ord2 = 0; |
| 742 |
|
| 743 |
$r0 = $r1 = $r2 = ''; |
| 744 |
|
| 745 |
$out = ''; |
| 746 |
|
| 747 |
$allowUnicode = false; |
| 748 |
for ( $pos = 0; $pos < $length; $pos++ ) { |
| 749 |
|
| 750 |
$x2 = $x1; |
| 751 |
$x1 = $x0; |
| 752 |
$d1 = $d0; |
| 753 |
$ord2 = $ord1; |
| 754 |
$ord1 = $ord0; |
| 755 |
$r2 = $r1; |
| 756 |
$r1 = $r0; |
| 757 |
|
| 758 |
$inChar = $byteClass[$pos]; |
| 759 |
if ( $inChar === '\\' ) { |
| 760 |
if ( preg_match( '/x([0-9a-fA-F]{2})/A', $byteClass, $m, 0, $pos + 1 ) ) { |
| 761 |
$x0 = $inChar . $m[0]; |
| 762 |
$d0 = chr( hexdec( $m[1] ) ); |
| 763 |
$pos += strlen( $m[0] ); |
| 764 |
} elseif ( preg_match( '/[0-7]{3}/A', $byteClass, $m, 0, $pos + 1 ) ) { |
| 765 |
$x0 = $inChar . $m[0]; |
| 766 |
$d0 = chr( octdec( $m[0] ) ); |
| 767 |
$pos += strlen( $m[0] ); |
| 768 |
} elseif ( $pos + 1 >= $length ) { |
| 769 |
$x0 = $d0 = '\\'; |
| 770 |
} else { |
| 771 |
$d0 = $byteClass[$pos + 1]; |
| 772 |
$x0 = $inChar . $d0; |
| 773 |
$pos++; |
| 774 |
} |
| 775 |
} else { |
| 776 |
$x0 = $d0 = $inChar; |
| 777 |
} |
| 778 |
$ord0 = ord( $d0 ); |
| 779 |
|
| 780 |
if ( $ord0 < 32 || $ord0 == 0x7f ) { |
| 781 |
$r0 = sprintf( '\x%02x', $ord0 ); |
| 782 |
} elseif ( $ord0 >= 0x80 ) { |
| 783 |
|
| 784 |
$r0 = sprintf( '\x%02x', $ord0 ); |
| 785 |
$allowUnicode = true; |
| 786 |
|
| 787 |
} elseif ( strpos( '-\\[]^', $d0 ) !== false ) { |
| 788 |
$r0 = '\\' . $d0; |
| 789 |
} else { |
| 790 |
$r0 = $d0; |
| 791 |
} |
| 792 |
|
| 793 |
if ( $x0 !== '' && $x1 === '-' && $x2 !== '' ) { |
| 794 |
|
| 795 |
if ( $ord2 > $ord0 ) { |
| 796 |
|
| 797 |
} elseif ( $ord0 >= 0x80 ) { |
| 798 |
|
| 799 |
$allowUnicode = true; |
| 800 |
if ( $ord2 < 0x80 ) { |
| 801 |
|
| 802 |
$out .= "$r2-\\x7F"; |
| 803 |
} |
| 804 |
} else { |
| 805 |
|
| 806 |
$out .= "$r2-$r0"; |
| 807 |
} |
| 808 |
|
| 809 |
|
| 810 |
$x0 = $x1 = $d0 = $d1 = $r0 = $r1 = ''; |
| 811 |
} elseif ( $ord2 < 0x80 ) { |
| 812 |
|
| 813 |
$out .= $r2; |
| 814 |
} |
| 815 |
} |
| 816 |
|
| 817 |
if ( $ord1 < 0x80 ) { |
| 818 |
$out .= $r1; |
| 819 |
} |
| 820 |
if ( $ord0 < 0x80 ) { |
| 821 |
$out .= $r0; |
| 822 |
} |
| 823 |
if ( $allowUnicode ) { |
| 824 |
$out .= '\u0080-\uFFFF'; |
| 825 |
} |
| 826 |
return $out; |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
public static function makeName( $ns, $title, $fragment = '', $interwiki = '', |
| 841 |
$canonicalNamespace = false |
| 842 |
) { |
| 843 |
if ( $canonicalNamespace ) { |
| 844 |
$namespace = MediaWikiServices::getInstance()->getNamespaceInfo()-> |
| 845 |
getCanonicalName( $ns ); |
| 846 |
} else { |
| 847 |
$namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns ); |
| 848 |
} |
| 849 |
if ( $namespace === false ) { |
| 850 |
|
| 851 |
$namespace = self::makeName( NS_SPECIAL, "Badtitle/NS$ns", '', '', $canonicalNamespace ); |
| 852 |
} |
| 853 |
$name = $namespace === '' ? $title : "$namespace:$title"; |
| 854 |
if ( strval( $interwiki ) != '' ) { |
| 855 |
$name = "$interwiki:$name"; |
| 856 |
} |
| 857 |
if ( strval( $fragment ) != '' ) { |
| 858 |
$name .= '#' . $fragment; |
| 859 |
} |
| 860 |
return $name; |
| 861 |
} |
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
public static function compare( $a, $b ) { |
| 872 |
return $a->getNamespace() <=> $b->getNamespace() |
| 873 |
?: strcmp( $a->getDBkey(), $b->getDBkey() ); |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
public function isValid() { |
| 893 |
if ( $this->mIsValid !== null ) { |
| 894 |
return $this->mIsValid; |
| 895 |
} |
| 896 |
|
| 897 |
try { |
| 898 |
|
| 899 |
|
| 900 |
$text = self::makeName( $this->mNamespace, $this->mDbkeyform, $this->mFragment, $this->mInterwiki, true ); |
| 901 |
$titleCodec = MediaWikiServices::getInstance()->getTitleParser(); |
| 902 |
|
| 903 |
'@phan-var MediaWikiTitleCodec $titleCodec'; |
| 904 |
$parts = $titleCodec->splitTitleString( $text, $this->mNamespace ); |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
if ( $parts['fragment'] !== $this->mFragment |
| 909 |
|| $parts['interwiki'] !== $this->mInterwiki |
| 910 |
|| $parts['local_interwiki'] !== $this->mLocalInterwiki |
| 911 |
|| $parts['namespace'] !== $this->mNamespace |
| 912 |
|| $parts['dbkey'] !== $this->mDbkeyform |
| 913 |
) { |
| 914 |
$this->mIsValid = false; |
| 915 |
return $this->mIsValid; |
| 916 |
} |
| 917 |
} catch ( MalformedTitleException $ex ) { |
| 918 |
$this->mIsValid = false; |
| 919 |
return $this->mIsValid; |
| 920 |
} |
| 921 |
|
| 922 |
$this->mIsValid = true; |
| 923 |
return $this->mIsValid; |
| 924 |
} |
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
public function isLocal() { |
| 934 |
if ( $this->isExternal() ) { |
| 935 |
$iw = self::getInterwikiLookup()->fetch( $this->mInterwiki ); |
| 936 |
if ( $iw ) { |
| 937 |
return $iw->isLocal(); |
| 938 |
} |
| 939 |
} |
| 940 |
return true; |
| 941 |
} |
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
public function getInterwiki(): string { |
| 951 |
return $this->mInterwiki; |
| 952 |
} |
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
public function wasLocalInterwiki() { |
| 960 |
return $this->mLocalInterwiki; |
| 961 |
} |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
public function isTrans() { |
| 970 |
if ( !$this->isExternal() ) { |
| 971 |
return false; |
| 972 |
} |
| 973 |
|
| 974 |
return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable(); |
| 975 |
} |
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
public function getTransWikiID() { |
| 983 |
if ( !$this->isExternal() ) { |
| 984 |
return false; |
| 985 |
} |
| 986 |
|
| 987 |
return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID(); |
| 988 |
} |
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
public function getTitleValue() { |
| 1000 |
if ( $this->mTitleValue === null ) { |
| 1001 |
try { |
| 1002 |
$this->mTitleValue = new TitleValue( |
| 1003 |
$this->mNamespace, |
| 1004 |
$this->mDbkeyform, |
| 1005 |
$this->mFragment, |
| 1006 |
$this->mInterwiki |
| 1007 |
); |
| 1008 |
} catch ( InvalidArgumentException $ex ) { |
| 1009 |
wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' . |
| 1010 |
$this->getPrefixedText() . ']]: ' . $ex->getMessage() ); |
| 1011 |
} |
| 1012 |
} |
| 1013 |
|
| 1014 |
return $this->mTitleValue; |
| 1015 |
} |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
public function getText(): string { |
| 1023 |
return $this->mTextform; |
| 1024 |
} |
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
public function getPartialURL() { |
| 1032 |
return $this->mUrlform; |
| 1033 |
} |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
public function getDBkey(): string { |
| 1041 |
return $this->mDbkeyform; |
| 1042 |
} |
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
public function getNamespace(): int { |
| 1050 |
return $this->mNamespace; |
| 1051 |
} |
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
private function shouldReadLatest( int $flags ) { |
| 1060 |
return ( $flags & ( IDBAccessObject::READ_LATEST ) ) > 0; |
| 1061 |
} |
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
public function getContentModel( $flags = 0 ) { |
| 1072 |
if ( $this->mForcedContentModel ) { |
| 1073 |
if ( !$this->mContentModel ) { |
| 1074 |
throw new RuntimeException( 'Got out of sync; an empty model is being forced' ); |
| 1075 |
} |
| 1076 |
|
| 1077 |
return $this->mContentModel; |
| 1078 |
} |
| 1079 |
|
| 1080 |
if ( $this->shouldReadLatest( $flags ) || !$this->mContentModel ) { |
| 1081 |
$this->lazyFillContentModel( $this->getFieldFromPageStore( 'page_content_model', $flags ) ); |
| 1082 |
} |
| 1083 |
|
| 1084 |
if ( !$this->mContentModel ) { |
| 1085 |
$slotRoleregistry = MediaWikiServices::getInstance()->getSlotRoleRegistry(); |
| 1086 |
$mainSlotHandler = $slotRoleregistry->getRoleHandler( 'main' ); |
| 1087 |
$this->lazyFillContentModel( $mainSlotHandler->getDefaultModel( $this ) ); |
| 1088 |
} |
| 1089 |
|
| 1090 |
return $this->mContentModel; |
| 1091 |
} |
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
public function hasContentModel( $id ) { |
| 1100 |
return $this->getContentModel() == $id; |
| 1101 |
} |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
public function setContentModel( $model ) { |
| 1120 |
if ( (string)$model === '' ) { |
| 1121 |
throw new InvalidArgumentException( "Missing CONTENT_MODEL_* constant" ); |
| 1122 |
} |
| 1123 |
|
| 1124 |
$this->uncache(); |
| 1125 |
$this->mContentModel = $model; |
| 1126 |
$this->mForcedContentModel = true; |
| 1127 |
} |
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
private function lazyFillContentModel( $model ) { |
| 1135 |
if ( !$this->mForcedContentModel ) { |
| 1136 |
$this->mContentModel = ( $model === false ) ? false : (string)$model; |
| 1137 |
} |
| 1138 |
} |
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
public function getNsText() { |
| 1146 |
if ( $this->isExternal() ) { |
| 1147 |
|
| 1148 |
|
| 1149 |
if ( $this->mNamespace === NS_MAIN ) { |
| 1150 |
|
| 1151 |
return ''; |
| 1152 |
} else { |
| 1153 |
$nsText = MediaWikiServices::getInstance()->getNamespaceInfo()-> |
| 1154 |
getCanonicalName( $this->mNamespace ); |
| 1155 |
if ( $nsText !== false ) { |
| 1156 |
return $nsText; |
| 1157 |
} |
| 1158 |
} |
| 1159 |
} |
| 1160 |
|
| 1161 |
try { |
| 1162 |
$formatter = self::getTitleFormatter(); |
| 1163 |
return $formatter->getNamespaceName( $this->mNamespace, $this->mDbkeyform ); |
| 1164 |
} catch ( InvalidArgumentException $ex ) { |
| 1165 |
wfDebug( __METHOD__ . ': ' . $ex->getMessage() ); |
| 1166 |
return false; |
| 1167 |
} |
| 1168 |
} |
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
public function getSubjectNsText() { |
| 1176 |
$services = MediaWikiServices::getInstance(); |
| 1177 |
return $services->getContentLanguage()-> |
| 1178 |
getNsText( $services->getNamespaceInfo()->getSubject( $this->mNamespace ) ); |
| 1179 |
} |
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
public function getTalkNsText() { |
| 1187 |
$services = MediaWikiServices::getInstance(); |
| 1188 |
return $services->getContentLanguage()-> |
| 1189 |
getNsText( $services->getNamespaceInfo()->getTalk( $this->mNamespace ) ); |
| 1190 |
} |
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
public function canHaveTalkPage() { |
| 1204 |
return MediaWikiServices::getInstance()->getNamespaceInfo()->canHaveTalkPage( $this ); |
| 1205 |
} |
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
public function canExist(): bool { |
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
if ( $this->mArticleID > 0 ) { |
| 1222 |
|
| 1223 |
return true; |
| 1224 |
} |
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
if ( $this->mIsValid === false ) { |
| 1229 |
|
| 1230 |
return false; |
| 1231 |
} |
| 1232 |
|
| 1233 |
if ( $this->getNamespace() < NS_MAIN ) { |
| 1234 |
|
| 1235 |
return false; |
| 1236 |
} |
| 1237 |
|
| 1238 |
if ( $this->isExternal() ) { |
| 1239 |
|
| 1240 |
return false; |
| 1241 |
} |
| 1242 |
|
| 1243 |
if ( $this->getText() === '' ) { |
| 1244 |
|
| 1245 |
|
| 1246 |
return false; |
| 1247 |
} |
| 1248 |
|
| 1249 |
|
| 1250 |
return $this->isValid(); |
| 1251 |
} |
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
public function isSpecialPage() { |
| 1259 |
return $this->mNamespace === NS_SPECIAL; |
| 1260 |
} |
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
public function isSpecial( $name ) { |
| 1269 |
if ( $this->isSpecialPage() ) { |
| 1270 |
[ $thisName, ] = |
| 1271 |
MediaWikiServices::getInstance()->getSpecialPageFactory()-> |
| 1272 |
resolveAlias( $this->mDbkeyform ); |
| 1273 |
if ( $name == $thisName ) { |
| 1274 |
return true; |
| 1275 |
} |
| 1276 |
} |
| 1277 |
return false; |
| 1278 |
} |
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
public function fixSpecialName() { |
| 1287 |
if ( $this->isSpecialPage() ) { |
| 1288 |
$spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory(); |
| 1289 |
[ $canonicalName, $par ] = $spFactory->resolveAlias( $this->mDbkeyform ); |
| 1290 |
if ( $canonicalName ) { |
| 1291 |
$localName = $spFactory->getLocalNameFor( $canonicalName, $par ); |
| 1292 |
if ( $localName != $this->mDbkeyform ) { |
| 1293 |
return self::makeTitle( NS_SPECIAL, $localName ); |
| 1294 |
} |
| 1295 |
} |
| 1296 |
} |
| 1297 |
return $this; |
| 1298 |
} |
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
public function inNamespace( int $ns ): bool { |
| 1308 |
return MediaWikiServices::getInstance()->getNamespaceInfo()-> |
| 1309 |
equals( $this->mNamespace, $ns ); |
| 1310 |
} |
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
public function inNamespaces( ...$namespaces ) { |
| 1320 |
if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) { |
| 1321 |
$namespaces = $namespaces[0]; |
| 1322 |
} |
| 1323 |
|
| 1324 |
foreach ( $namespaces as $ns ) { |
| 1325 |
if ( $this->inNamespace( $ns ) ) { |
| 1326 |
return true; |
| 1327 |
} |
| 1328 |
} |
| 1329 |
|
| 1330 |
return false; |
| 1331 |
} |
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
public function hasSubjectNamespace( $ns ) { |
| 1347 |
return MediaWikiServices::getInstance()->getNamespaceInfo()-> |
| 1348 |
subjectEquals( $this->mNamespace, $ns ); |
| 1349 |
} |
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
public function isContentPage() { |
| 1359 |
return MediaWikiServices::getInstance()->getNamespaceInfo()-> |
| 1360 |
isContent( $this->mNamespace ); |
| 1361 |
} |
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
public function isMovable() { |
| 1370 |
$services = MediaWikiServices::getInstance(); |
| 1371 |
if ( |
| 1372 |
!$services->getNamespaceInfo()-> |
| 1373 |
isMovable( $this->mNamespace ) || $this->isExternal() |
| 1374 |
) { |
| 1375 |
|
| 1376 |
return false; |
| 1377 |
} |
| 1378 |
|
| 1379 |
$result = true; |
| 1380 |
( new HookRunner( $services->getHookContainer() ) )->onTitleIsMovable( $this, $result ); |
| 1381 |
return $result; |
| 1382 |
} |
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
public function isMainPage() { |
| 1392 |
self::$cachedMainPage ??= self::newMainPage(); |
| 1393 |
return $this->equals( self::$cachedMainPage ); |
| 1394 |
} |
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
public function isSubpage() { |
| 1402 |
return MediaWikiServices::getInstance() |
| 1403 |
->getNamespaceInfo() |
| 1404 |
->hasSubpages( $this->mNamespace ) |
| 1405 |
&& str_contains( $this->getText(), '/' ); |
| 1406 |
} |
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
public function isConversionTable() { |
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
return $this->mNamespace === NS_MEDIAWIKI && |
| 1418 |
str_starts_with( $this->getText(), 'Conversiontable/' ); |
| 1419 |
} |
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
public function isWikitextPage() { |
| 1427 |
return $this->hasContentModel( CONTENT_MODEL_WIKITEXT ); |
| 1428 |
} |
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
public function isSiteConfigPage() { |
| 1445 |
return ( |
| 1446 |
$this->isSiteCssConfigPage() |
| 1447 |
|| $this->isSiteJsonConfigPage() |
| 1448 |
|| $this->isSiteJsConfigPage() |
| 1449 |
); |
| 1450 |
} |
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
public function isUserConfigPage() { |
| 1459 |
return ( |
| 1460 |
$this->isUserCssConfigPage() |
| 1461 |
|| $this->isUserJsonConfigPage() |
| 1462 |
|| $this->isUserJsConfigPage() |
| 1463 |
); |
| 1464 |
} |
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
public function getSkinFromConfigSubpage() { |
| 1473 |
$text = $this->getText(); |
| 1474 |
$lastSlashPos = $this->findSubpageDivider( $text, -1 ); |
| 1475 |
if ( $lastSlashPos === false ) { |
| 1476 |
return ''; |
| 1477 |
} |
| 1478 |
|
| 1479 |
$lastDot = strrpos( $text, '.', $lastSlashPos ); |
| 1480 |
if ( $lastDot === false ) { |
| 1481 |
return ''; |
| 1482 |
} |
| 1483 |
|
| 1484 |
return substr( $text, $lastSlashPos + 1, $lastDot - $lastSlashPos - 1 ); |
| 1485 |
} |
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
public function isUserCssConfigPage() { |
| 1494 |
return ( |
| 1495 |
$this->mNamespace === NS_USER |
| 1496 |
&& $this->isSubpage() |
| 1497 |
&& $this->hasContentModel( CONTENT_MODEL_CSS ) |
| 1498 |
); |
| 1499 |
} |
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
public function isUserJsonConfigPage() { |
| 1508 |
return ( |
| 1509 |
$this->mNamespace === NS_USER |
| 1510 |
&& $this->isSubpage() |
| 1511 |
&& $this->hasContentModel( CONTENT_MODEL_JSON ) |
| 1512 |
); |
| 1513 |
} |
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
public function isUserJsConfigPage() { |
| 1522 |
return ( |
| 1523 |
$this->mNamespace === NS_USER |
| 1524 |
&& $this->isSubpage() |
| 1525 |
&& $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) |
| 1526 |
); |
| 1527 |
} |
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
public function isSiteCssConfigPage() { |
| 1536 |
return ( |
| 1537 |
$this->mNamespace === NS_MEDIAWIKI |
| 1538 |
&& ( |
| 1539 |
$this->hasContentModel( CONTENT_MODEL_CSS ) |
| 1540 |
|
| 1541 |
|
| 1542 |
|| str_ends_with( $this->mDbkeyform, '.css' ) |
| 1543 |
) |
| 1544 |
); |
| 1545 |
} |
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
public function isSiteJsonConfigPage() { |
| 1554 |
return ( |
| 1555 |
$this->mNamespace === NS_MEDIAWIKI |
| 1556 |
&& ( |
| 1557 |
$this->hasContentModel( CONTENT_MODEL_JSON ) |
| 1558 |
|
| 1559 |
|
| 1560 |
|| str_ends_with( $this->mDbkeyform, '.json' ) |
| 1561 |
) |
| 1562 |
); |
| 1563 |
} |
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
public function isSiteJsConfigPage() { |
| 1572 |
return ( |
| 1573 |
$this->mNamespace === NS_MEDIAWIKI |
| 1574 |
&& ( |
| 1575 |
$this->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) |
| 1576 |
|
| 1577 |
|
| 1578 |
|| str_ends_with( $this->mDbkeyform, '.js' ) |
| 1579 |
) |
| 1580 |
); |
| 1581 |
} |
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
public function isRawHtmlMessage() { |
| 1590 |
global $wgRawHtmlMessages; |
| 1591 |
|
| 1592 |
if ( !$this->inNamespace( NS_MEDIAWIKI ) ) { |
| 1593 |
return false; |
| 1594 |
} |
| 1595 |
$message = lcfirst( $this->getRootTitle()->getDBkey() ); |
| 1596 |
return in_array( $message, $wgRawHtmlMessages, true ); |
| 1597 |
} |
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
public function isTalkPage() { |
| 1605 |
return MediaWikiServices::getInstance()->getNamespaceInfo()-> |
| 1606 |
isTalk( $this->mNamespace ); |
| 1607 |
} |
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
public function getTalkPage() { |
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
$talkNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $this->mNamespace ); |
| 1627 |
if ( $this->mNamespace == $talkNS ) { |
| 1628 |
return $this; |
| 1629 |
} |
| 1630 |
|
| 1631 |
$title = self::makeTitle( $talkNS, $this->mDbkeyform ); |
| 1632 |
|
| 1633 |
$this->warnIfPageCannotExist( $title, __METHOD__ ); |
| 1634 |
|
| 1635 |
return $title; |
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
} |
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
public function getTalkPageIfDefined() { |
| 1651 |
if ( !$this->canHaveTalkPage() ) { |
| 1652 |
return null; |
| 1653 |
} |
| 1654 |
|
| 1655 |
return $this->getTalkPage(); |
| 1656 |
} |
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
public function getSubjectPage() { |
| 1666 |
|
| 1667 |
$subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo() |
| 1668 |
->getSubject( $this->mNamespace ); |
| 1669 |
if ( $this->mNamespace == $subjectNS ) { |
| 1670 |
return $this; |
| 1671 |
} |
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
$title = self::makeTitle( $subjectNS, $this->mDbkeyform ); |
| 1676 |
|
| 1677 |
$this->warnIfPageCannotExist( $title, __METHOD__ ); |
| 1678 |
|
| 1679 |
return $title; |
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
} |
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
private function warnIfPageCannotExist( Title $title, $method ) { |
| 1692 |
if ( $this->getText() == '' ) { |
| 1693 |
wfLogWarning( |
| 1694 |
$method . ': called on empty title ' . $this->getFullText() . ', returning ' |
| 1695 |
. $title->getFullText() |
| 1696 |
); |
| 1697 |
|
| 1698 |
return true; |
| 1699 |
} |
| 1700 |
|
| 1701 |
if ( $this->getInterwiki() !== '' ) { |
| 1702 |
wfLogWarning( |
| 1703 |
$method . ': called on interwiki title ' . $this->getFullText() . ', returning ' |
| 1704 |
. $title->getFullText() |
| 1705 |
); |
| 1706 |
|
| 1707 |
return true; |
| 1708 |
} |
| 1709 |
|
| 1710 |
return false; |
| 1711 |
} |
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
public function getOtherPage() { |
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
if ( $this->isSpecialPage() ) { |
| 1727 |
throw new MWException( 'Special pages cannot have other pages' ); |
| 1728 |
} |
| 1729 |
if ( $this->isTalkPage() ) { |
| 1730 |
return $this->getSubjectPage(); |
| 1731 |
} else { |
| 1732 |
if ( !$this->canHaveTalkPage() ) { |
| 1733 |
throw new MWException( "{$this->getPrefixedText()} does not have an other page" ); |
| 1734 |
} |
| 1735 |
return $this->getTalkPage(); |
| 1736 |
} |
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
} |
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
public function getFragment(): string { |
| 1750 |
return $this->mFragment; |
| 1751 |
} |
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
public function getFragmentForURL() { |
| 1759 |
if ( !$this->hasFragment() ) { |
| 1760 |
return ''; |
| 1761 |
} elseif ( $this->isExternal() ) { |
| 1762 |
|
| 1763 |
|
| 1764 |
$interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki ); |
| 1765 |
if ( $interwiki && !$interwiki->isLocal() ) { |
| 1766 |
return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment ); |
| 1767 |
} |
| 1768 |
} |
| 1769 |
|
| 1770 |
return '#' . Sanitizer::escapeIdForLink( $this->mFragment ); |
| 1771 |
} |
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
public function setFragment( $fragment ) { |
| 1784 |
$this->uncache(); |
| 1785 |
$this->mFragment = self::normalizeFragment( $fragment ); |
| 1786 |
} |
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
public function createFragmentTarget( string $fragment ): self { |
| 1796 |
return self::makeTitle( |
| 1797 |
$this->mNamespace, |
| 1798 |
$this->getText(), |
| 1799 |
$fragment, |
| 1800 |
$this->mInterwiki |
| 1801 |
); |
| 1802 |
} |
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
private static function normalizeFragment( $fragment ) { |
| 1811 |
if ( str_starts_with( $fragment, '#' ) ) { |
| 1812 |
$fragment = substr( $fragment, 1 ); |
| 1813 |
} |
| 1814 |
return strtr( $fragment, '_', ' ' ); |
| 1815 |
} |
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
private function prefix( $name ) { |
| 1825 |
$p = ''; |
| 1826 |
if ( $this->isExternal() ) { |
| 1827 |
$p = $this->mInterwiki . ':'; |
| 1828 |
} |
| 1829 |
|
| 1830 |
if ( $this->mNamespace != 0 ) { |
| 1831 |
$nsText = $this->getNsText(); |
| 1832 |
|
| 1833 |
if ( $nsText === false ) { |
| 1834 |
|
| 1835 |
$nsText = MediaWikiServices::getInstance()->getContentLanguage()-> |
| 1836 |
getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}"; |
| 1837 |
} |
| 1838 |
|
| 1839 |
$p .= $nsText . ':'; |
| 1840 |
} |
| 1841 |
return $p . $name; |
| 1842 |
} |
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
public function getPrefixedDBkey() { |
| 1851 |
$s = $this->prefix( $this->mDbkeyform ); |
| 1852 |
$s = strtr( $s, ' ', '_' ); |
| 1853 |
return $s; |
| 1854 |
} |
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
public function getPrefixedText() { |
| 1863 |
if ( $this->prefixedText === null ) { |
| 1864 |
$s = $this->prefix( $this->mTextform ); |
| 1865 |
$s = strtr( $s, '_', ' ' ); |
| 1866 |
$this->prefixedText = $s; |
| 1867 |
} |
| 1868 |
return $this->prefixedText; |
| 1869 |
} |
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
public function __toString(): string { |
| 1877 |
return $this->getPrefixedText(); |
| 1878 |
} |
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
public function getFullText() { |
| 1887 |
$text = $this->getPrefixedText(); |
| 1888 |
if ( $this->hasFragment() ) { |
| 1889 |
$text .= '#' . $this->mFragment; |
| 1890 |
} |
| 1891 |
return $text; |
| 1892 |
} |
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
private function findSubpageDivider( $text, $dir ) { |
| 1909 |
if ( $dir > 0 ) { |
| 1910 |
|
| 1911 |
$bottom = strspn( $text, '/', 0, -1 ); |
| 1912 |
$idx = strpos( $text, '/', $bottom ); |
| 1913 |
} else { |
| 1914 |
|
| 1915 |
$idx = strrpos( $text, '/' ); |
| 1916 |
} |
| 1917 |
|
| 1918 |
|
| 1919 |
return $idx === 0 ? false : $idx; |
| 1920 |
} |
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
private function hasSubpagesEnabled() { |
| 1927 |
return MediaWikiServices::getInstance()->getNamespaceInfo()-> |
| 1928 |
hasSubpages( $this->mNamespace ); |
| 1929 |
} |
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
public function getRootText() { |
| 1947 |
$text = $this->getText(); |
| 1948 |
if ( !$this->hasSubpagesEnabled() ) { |
| 1949 |
return $text; |
| 1950 |
} |
| 1951 |
|
| 1952 |
$firstSlashPos = $this->findSubpageDivider( $text, +1 ); |
| 1953 |
|
| 1954 |
if ( $firstSlashPos === false ) { |
| 1955 |
return $text; |
| 1956 |
} |
| 1957 |
|
| 1958 |
return substr( $text, 0, $firstSlashPos ); |
| 1959 |
} |
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
public function getRootTitle() { |
| 1974 |
$title = self::makeTitleSafe( $this->mNamespace, $this->getRootText() ); |
| 1975 |
|
| 1976 |
if ( !$title ) { |
| 1977 |
if ( !$this->isValid() ) { |
| 1978 |
|
| 1979 |
|
| 1980 |
return $this; |
| 1981 |
} |
| 1982 |
|
| 1983 |
Assert::postcondition( |
| 1984 |
$title !== null, |
| 1985 |
'makeTitleSafe() should always return a Title for the text ' . |
| 1986 |
'returned by getRootText().' |
| 1987 |
); |
| 1988 |
} |
| 1989 |
|
| 1990 |
return $title; |
| 1991 |
} |
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
public function getBaseText() { |
| 2008 |
$text = $this->getText(); |
| 2009 |
if ( !$this->hasSubpagesEnabled() ) { |
| 2010 |
return $text; |
| 2011 |
} |
| 2012 |
|
| 2013 |
$lastSlashPos = $this->findSubpageDivider( $text, -1 ); |
| 2014 |
|
| 2015 |
if ( $lastSlashPos === false ) { |
| 2016 |
return $text; |
| 2017 |
} |
| 2018 |
|
| 2019 |
return substr( $text, 0, $lastSlashPos ); |
| 2020 |
} |
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
public function getBaseTitle() { |
| 2035 |
$title = self::makeTitleSafe( $this->mNamespace, $this->getBaseText() ); |
| 2036 |
|
| 2037 |
if ( !$title ) { |
| 2038 |
if ( !$this->isValid() ) { |
| 2039 |
|
| 2040 |
|
| 2041 |
return $this; |
| 2042 |
} |
| 2043 |
|
| 2044 |
Assert::postcondition( |
| 2045 |
$title !== null, |
| 2046 |
'makeTitleSafe() should always return a Title for the text ' . |
| 2047 |
'returned by getBaseText().' |
| 2048 |
); |
| 2049 |
} |
| 2050 |
|
| 2051 |
return $title; |
| 2052 |
} |
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
public function getSubpageText() { |
| 2066 |
$text = $this->getText(); |
| 2067 |
if ( !$this->hasSubpagesEnabled() ) { |
| 2068 |
return $text; |
| 2069 |
} |
| 2070 |
|
| 2071 |
$lastSlashPos = $this->findSubpageDivider( $text, -1 ); |
| 2072 |
if ( $lastSlashPos === false ) { |
| 2073 |
|
| 2074 |
return $text; |
| 2075 |
} |
| 2076 |
return substr( $text, $lastSlashPos + 1 ); |
| 2077 |
} |
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
public function getSubpage( $text ) { |
| 2093 |
return self::makeTitleSafe( |
| 2094 |
$this->mNamespace, |
| 2095 |
$this->getText() . '/' . $text, |
| 2096 |
'', |
| 2097 |
$this->mInterwiki |
| 2098 |
); |
| 2099 |
} |
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
public function getSubpageUrlForm() { |
| 2107 |
$text = $this->getSubpageText(); |
| 2108 |
$text = wfUrlencode( strtr( $text, ' ', '_' ) ); |
| 2109 |
return $text; |
| 2110 |
} |
| 2111 |
|
| 2112 |
|
| 2113 |
|
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
public function getPrefixedURL() { |
| 2118 |
$s = $this->prefix( $this->mDbkeyform ); |
| 2119 |
$s = wfUrlencode( strtr( $s, ' ', '_' ) ); |
| 2120 |
return $s; |
| 2121 |
} |
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) { |
| 2135 |
$services = MediaWikiServices::getInstance(); |
| 2136 |
|
| 2137 |
$query = is_array( $query ) ? wfArrayToCgi( $query ) : $query; |
| 2138 |
|
| 2139 |
|
| 2140 |
$url = $this->getLocalURL( $query ); |
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
$url = (string)$services->getUrlUtils()->expand( $url, $proto ); |
| 2146 |
|
| 2147 |
|
| 2148 |
$url .= $this->getFragmentForURL(); |
| 2149 |
( new HookRunner( $services->getHookContainer() ) )->onGetFullURL( $this, $url, $query ); |
| 2150 |
return $url; |
| 2151 |
} |
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
public function getFullUrlForRedirect( $query = '', $proto = PROTO_CURRENT ) { |
| 2170 |
$target = $this; |
| 2171 |
if ( $this->isExternal() ) { |
| 2172 |
$target = SpecialPage::getTitleFor( |
| 2173 |
'GoToInterwiki', |
| 2174 |
$this->getPrefixedDBkey() |
| 2175 |
); |
| 2176 |
} |
| 2177 |
return $target->getFullURL( $query, false, $proto ); |
| 2178 |
} |
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
public function getLocalURL( $query = '' ) { |
| 2198 |
global $wgArticlePath, $wgScript, $wgMainPageIsDomainRoot; |
| 2199 |
|
| 2200 |
$query = is_array( $query ) ? wfArrayToCgi( $query ) : $query; |
| 2201 |
|
| 2202 |
$services = MediaWikiServices::getInstance(); |
| 2203 |
$hookRunner = new HookRunner( $services->getHookContainer() ); |
| 2204 |
$interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki ); |
| 2205 |
if ( $interwiki ) { |
| 2206 |
$namespace = $this->getNsText(); |
| 2207 |
if ( $namespace != '' ) { |
| 2208 |
|
| 2209 |
|
| 2210 |
$namespace .= ':'; |
| 2211 |
} |
| 2212 |
$url = $interwiki->getURL( $namespace . $this->mDbkeyform ); |
| 2213 |
$url = wfAppendQuery( $url, $query ); |
| 2214 |
} else { |
| 2215 |
$dbkey = wfUrlencode( $this->getPrefixedDBkey() ); |
| 2216 |
if ( $query == '' ) { |
| 2217 |
if ( $wgMainPageIsDomainRoot && $this->isMainPage() ) { |
| 2218 |
$url = '/'; |
| 2219 |
} else { |
| 2220 |
$url = str_replace( '$1', $dbkey, $wgArticlePath ); |
| 2221 |
} |
| 2222 |
$hookRunner->onGetLocalURL__Article( $this, $url ); |
| 2223 |
} else { |
| 2224 |
global $wgVariantArticlePath, $wgActionPaths; |
| 2225 |
$url = false; |
| 2226 |
$matches = []; |
| 2227 |
|
| 2228 |
$articlePaths = PathRouter::getActionPaths( $wgActionPaths, $wgArticlePath ); |
| 2229 |
|
| 2230 |
if ( $articlePaths |
| 2231 |
&& preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) |
| 2232 |
) { |
| 2233 |
$action = urldecode( $matches[2] ); |
| 2234 |
if ( isset( $articlePaths[$action] ) ) { |
| 2235 |
$query = $matches[1]; |
| 2236 |
if ( isset( $matches[4] ) ) { |
| 2237 |
$query .= $matches[4]; |
| 2238 |
} |
| 2239 |
$url = str_replace( '$1', $dbkey, $articlePaths[$action] ); |
| 2240 |
if ( $query != '' ) { |
| 2241 |
$url = wfAppendQuery( $url, $query ); |
| 2242 |
} |
| 2243 |
} |
| 2244 |
} |
| 2245 |
|
| 2246 |
if ( $url === false |
| 2247 |
&& $wgVariantArticlePath |
| 2248 |
&& preg_match( '/^variant=([^&]*)$/', $query, $matches ) |
| 2249 |
&& $this->getPageLanguage()->equals( $services->getContentLanguage() ) |
| 2250 |
&& $this->getPageLanguageConverter()->hasVariants() |
| 2251 |
) { |
| 2252 |
$variant = urldecode( $matches[1] ); |
| 2253 |
if ( $this->getPageLanguageConverter()->hasVariant( $variant ) ) { |
| 2254 |
|
| 2255 |
|
| 2256 |
$url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath ); |
| 2257 |
$url = str_replace( '$1', $dbkey, $url ); |
| 2258 |
} |
| 2259 |
} |
| 2260 |
|
| 2261 |
if ( $url === false ) { |
| 2262 |
if ( $query == '-' ) { |
| 2263 |
$query = ''; |
| 2264 |
} |
| 2265 |
$url = "{$wgScript}?title={$dbkey}&{$query}"; |
| 2266 |
} |
| 2267 |
} |
| 2268 |
$hookRunner->onGetLocalURL__Internal( $this, $url, $query ); |
| 2269 |
} |
| 2270 |
|
| 2271 |
$hookRunner->onGetLocalURL( $this, $url, $query ); |
| 2272 |
return $url; |
| 2273 |
} |
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
public function getLinkURL( $query = '', $query2 = false, $proto = false ) { |
| 2293 |
if ( $this->isExternal() || $proto !== false ) { |
| 2294 |
$ret = $this->getFullURL( $query, false, $proto ); |
| 2295 |
} elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) { |
| 2296 |
$ret = $this->getFragmentForURL(); |
| 2297 |
} else { |
| 2298 |
$ret = $this->getLocalURL( $query ) . $this->getFragmentForURL(); |
| 2299 |
} |
| 2300 |
return $ret; |
| 2301 |
} |
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
public function getInternalURL( $query = '' ) { |
| 2317 |
global $wgInternalServer, $wgServer; |
| 2318 |
$services = MediaWikiServices::getInstance(); |
| 2319 |
|
| 2320 |
$query = is_array( $query ) ? wfArrayToCgi( $query ) : $query; |
| 2321 |
|
| 2322 |
$server = $wgInternalServer !== false ? $wgInternalServer : $wgServer; |
| 2323 |
$url = (string)$services->getUrlUtils()->expand( $server . $this->getLocalURL( $query ), PROTO_HTTP ); |
| 2324 |
( new HookRunner( $services->getHookContainer() ) ) |
| 2325 |
->onGetInternalURL( $this, $url, $query ); |
| 2326 |
return $url; |
| 2327 |
} |
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
public function getCanonicalURL( $query = '' ) { |
| 2342 |
$services = MediaWikiServices::getInstance(); |
| 2343 |
|
| 2344 |
$query = is_array( $query ) ? wfArrayToCgi( $query ) : $query; |
| 2345 |
|
| 2346 |
$url = (string)$services->getUrlUtils()->expand( |
| 2347 |
$this->getLocalURL( $query ) . $this->getFragmentForURL(), |
| 2348 |
PROTO_CANONICAL |
| 2349 |
); |
| 2350 |
( new HookRunner( $services->getHookContainer() ) ) |
| 2351 |
->onGetCanonicalURL( $this, $url, $query ); |
| 2352 |
return $url; |
| 2353 |
} |
| 2354 |
|
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
public function getEditURL() { |
| 2361 |
if ( $this->isExternal() ) { |
| 2362 |
return ''; |
| 2363 |
} |
| 2364 |
$s = $this->getLocalURL( 'action=edit' ); |
| 2365 |
|
| 2366 |
return $s; |
| 2367 |
} |
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
public function getTitleProtection() { |
| 2380 |
wfDeprecated( __METHOD__, '1.37' ); |
| 2381 |
return MediaWikiServices::getInstance()->getRestrictionStore()->getCreateProtection( $this ) |
| 2382 |
?: false; |
| 2383 |
} |
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
public function deleteTitleProtection() { |
| 2391 |
MediaWikiServices::getInstance()->getRestrictionStore()->deleteCreateProtection( $this ); |
| 2392 |
} |
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
public function loadRestrictions( $flags = 0 ) { |
| 2403 |
wfDeprecated( __METHOD__, '1.37' ); |
| 2404 |
MediaWikiServices::getInstance()->getRestrictionStore()->loadRestrictions( $this, $flags ); |
| 2405 |
} |
| 2406 |
|
| 2407 |
|
| 2408 |
|
| 2409 |
|
| 2410 |
|
| 2411 |
|
| 2412 |
|
| 2413 |
public function flushRestrictions() { |
| 2414 |
wfDeprecated( __METHOD__, '1.37' ); |
| 2415 |
MediaWikiServices::getInstance()->getRestrictionStore()->flushRestrictions( $this ); |
| 2416 |
} |
| 2417 |
|
| 2418 |
|
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
|
| 2423 |
public static function purgeExpiredRestrictions() { |
| 2424 |
if ( MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly() ) { |
| 2425 |
return; |
| 2426 |
} |
| 2427 |
|
| 2428 |
DeferredUpdates::addUpdate( new AutoCommitUpdate( |
| 2429 |
MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(), |
| 2430 |
__METHOD__, |
| 2431 |
static function ( IDatabase $dbw, $fname ) { |
| 2432 |
$config = MediaWikiServices::getInstance()->getMainConfig(); |
| 2433 |
$ids = $dbw->newSelectQueryBuilder() |
| 2434 |
->select( 'pr_id' ) |
| 2435 |
->from( 'page_restrictions' ) |
| 2436 |
->where( $dbw->expr( 'pr_expiry', '<', $dbw->timestamp() ) ) |
| 2437 |
->limit( $config->get( MainConfigNames::UpdateRowsPerQuery ) ) |
| 2438 |
->caller( $fname )->fetchFieldValues(); |
| 2439 |
if ( $ids ) { |
| 2440 |
$dbw->newDeleteQueryBuilder() |
| 2441 |
->deleteFrom( 'page_restrictions' ) |
| 2442 |
->where( [ 'pr_id' => $ids ] ) |
| 2443 |
->caller( $fname )->execute(); |
| 2444 |
} |
| 2445 |
|
| 2446 |
$dbw->newDeleteQueryBuilder() |
| 2447 |
->deleteFrom( 'protected_titles' ) |
| 2448 |
->where( $dbw->expr( 'pt_expiry', '<', $dbw->timestamp() ) ) |
| 2449 |
->caller( $fname )->execute(); |
| 2450 |
} |
| 2451 |
) ); |
| 2452 |
} |
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
public function hasSubpages() { |
| 2460 |
if ( |
| 2461 |
!MediaWikiServices::getInstance()->getNamespaceInfo()-> |
| 2462 |
hasSubpages( $this->mNamespace ) |
| 2463 |
) { |
| 2464 |
|
| 2465 |
return false; |
| 2466 |
} |
| 2467 |
|
| 2468 |
|
| 2469 |
|
| 2470 |
|
| 2471 |
|
| 2472 |
if ( $this->mHasSubpages === null ) { |
| 2473 |
$subpages = $this->getSubpages( 1 ); |
| 2474 |
$this->mHasSubpages = $subpages instanceof TitleArrayFromResult && $subpages->count(); |
| 2475 |
} |
| 2476 |
|
| 2477 |
return $this->mHasSubpages; |
| 2478 |
} |
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
public function getSubpages( $limit = -1 ) { |
| 2488 |
if ( |
| 2489 |
!MediaWikiServices::getInstance()->getNamespaceInfo()-> |
| 2490 |
hasSubpages( $this->mNamespace ) |
| 2491 |
) { |
| 2492 |
return []; |
| 2493 |
} |
| 2494 |
|
| 2495 |
$services = MediaWikiServices::getInstance(); |
| 2496 |
$pageStore = $services->getPageStore(); |
| 2497 |
$titleFactory = $services->getTitleFactory(); |
| 2498 |
$query = $pageStore->newSelectQueryBuilder() |
| 2499 |
->fields( $pageStore->getSelectFields() ) |
| 2500 |
->whereTitlePrefix( $this->getNamespace(), $this->getDBkey() . '/' ) |
| 2501 |
->caller( __METHOD__ ); |
| 2502 |
if ( $limit > -1 ) { |
| 2503 |
$query->limit( $limit ); |
| 2504 |
} |
| 2505 |
|
| 2506 |
return $titleFactory->newTitleArrayFromResult( $query->fetchResultSet() ); |
| 2507 |
} |
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
|
| 2513 |
|
| 2514 |
|
| 2515 |
public function isDeleted() { |
| 2516 |
return $this->getDeletedEditsCount(); |
| 2517 |
} |
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
public function getDeletedEditsCount() { |
| 2526 |
if ( $this->mNamespace < 0 ) { |
| 2527 |
return 0; |
| 2528 |
} |
| 2529 |
|
| 2530 |
$dbr = $this->getDbProvider()->getReplicaDatabase(); |
| 2531 |
$n = (int)$dbr->newSelectQueryBuilder() |
| 2532 |
->select( 'COUNT(*)' ) |
| 2533 |
->from( 'archive' ) |
| 2534 |
->where( [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ] ) |
| 2535 |
->caller( __METHOD__ )->fetchField(); |
| 2536 |
if ( $this->mNamespace === NS_FILE ) { |
| 2537 |
$n += $dbr->newSelectQueryBuilder() |
| 2538 |
->select( 'COUNT(*)' ) |
| 2539 |
->from( 'filearchive' ) |
| 2540 |
->where( [ 'fa_name' => $this->mDbkeyform ] ) |
| 2541 |
->caller( __METHOD__ )->fetchField(); |
| 2542 |
} |
| 2543 |
return $n; |
| 2544 |
} |
| 2545 |
|
| 2546 |
|
| 2547 |
|
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
|
| 2552 |
public function isDeletedQuick() { |
| 2553 |
return $this->hasDeletedEdits(); |
| 2554 |
} |
| 2555 |
|
| 2556 |
|
| 2557 |
|
| 2558 |
|
| 2559 |
|
| 2560 |
|
| 2561 |
|
| 2562 |
public function hasDeletedEdits() { |
| 2563 |
if ( $this->mNamespace < 0 ) { |
| 2564 |
return false; |
| 2565 |
} |
| 2566 |
$dbr = $this->getDbProvider()->getReplicaDatabase(); |
| 2567 |
$deleted = (bool)$dbr->newSelectQueryBuilder() |
| 2568 |
->select( '1' ) |
| 2569 |
->from( 'archive' ) |
| 2570 |
->where( [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ] ) |
| 2571 |
->caller( __METHOD__ )->fetchField(); |
| 2572 |
if ( !$deleted && $this->mNamespace === NS_FILE ) { |
| 2573 |
$deleted = (bool)$dbr->newSelectQueryBuilder() |
| 2574 |
->select( '1' ) |
| 2575 |
->from( 'filearchive' ) |
| 2576 |
->where( [ 'fa_name' => $this->mDbkeyform ] ) |
| 2577 |
->caller( __METHOD__ )->fetchField(); |
| 2578 |
} |
| 2579 |
return $deleted; |
| 2580 |
} |
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
public function getArticleID( $flags = 0 ) { |
| 2590 |
if ( $this->mArticleID === -1 && !$this->canExist() ) { |
| 2591 |
$this->mArticleID = 0; |
| 2592 |
|
| 2593 |
return $this->mArticleID; |
| 2594 |
} |
| 2595 |
|
| 2596 |
if ( $this->mArticleID === -1 || $this->shouldReadLatest( $flags ) ) { |
| 2597 |
$this->mArticleID = (int)$this->getFieldFromPageStore( 'page_id', $flags ); |
| 2598 |
} |
| 2599 |
|
| 2600 |
return $this->mArticleID; |
| 2601 |
} |
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
public function isRedirect( $flags = 0 ) { |
| 2618 |
if ( $this->shouldReadLatest( $flags ) || $this->mRedirect === null ) { |
| 2619 |
$this->mRedirect = (bool)$this->getFieldFromPageStore( 'page_is_redirect', $flags ); |
| 2620 |
} |
| 2621 |
|
| 2622 |
return $this->mRedirect; |
| 2623 |
} |
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
|
| 2628 |
|
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
public function getLength( $flags = 0 ) { |
| 2633 |
if ( $this->shouldReadLatest( $flags ) || $this->mLength < 0 ) { |
| 2634 |
$this->mLength = (int)$this->getFieldFromPageStore( 'page_len', $flags ); |
| 2635 |
} |
| 2636 |
|
| 2637 |
if ( $this->mLength < 0 ) { |
| 2638 |
$this->mLength = 0; |
| 2639 |
} |
| 2640 |
|
| 2641 |
return $this->mLength; |
| 2642 |
} |
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
|
| 2650 |
public function getLatestRevID( $flags = 0 ) { |
| 2651 |
if ( $this->shouldReadLatest( $flags ) || $this->mLatestID === false ) { |
| 2652 |
$this->mLatestID = (int)$this->getFieldFromPageStore( 'page_latest', $flags ); |
| 2653 |
} |
| 2654 |
|
| 2655 |
if ( !$this->mLatestID ) { |
| 2656 |
$this->mLatestID = 0; |
| 2657 |
} |
| 2658 |
|
| 2659 |
return $this->mLatestID; |
| 2660 |
} |
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
|
| 2665 |
|
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
public function resetArticleID( $id ) { |
| 2676 |
if ( $id === false ) { |
| 2677 |
$this->mArticleID = -1; |
| 2678 |
} else { |
| 2679 |
$this->mArticleID = (int)$id; |
| 2680 |
} |
| 2681 |
$this->mRedirect = null; |
| 2682 |
$this->mLength = -1; |
| 2683 |
$this->mLatestID = false; |
| 2684 |
$this->mContentModel = false; |
| 2685 |
$this->mForcedContentModel = false; |
| 2686 |
$this->mEstimateRevisions = null; |
| 2687 |
$this->mPageLanguage = null; |
| 2688 |
$this->mDbPageLanguage = false; |
| 2689 |
$this->mIsBigDeletion = null; |
| 2690 |
|
| 2691 |
$this->uncache(); |
| 2692 |
MediaWikiServices::getInstance()->getLinkCache()->clearLink( $this ); |
| 2693 |
MediaWikiServices::getInstance()->getRestrictionStore()->flushRestrictions( $this ); |
| 2694 |
} |
| 2695 |
|
| 2696 |
public static function clearCaches() { |
| 2697 |
$linkCache = MediaWikiServices::getInstance()->getLinkCache(); |
| 2698 |
$linkCache->clear(); |
| 2699 |
|
| 2700 |
|
| 2701 |
self::$cachedMainPage = null; |
| 2702 |
|
| 2703 |
$titleCache = self::getTitleCache(); |
| 2704 |
$titleCache->clear(); |
| 2705 |
} |
| 2706 |
|
| 2707 |
|
| 2708 |
|
| 2709 |
|
| 2710 |
|
| 2711 |
|
| 2712 |
|
| 2713 |
|
| 2714 |
public static function capitalize( $text, $ns = NS_MAIN ) { |
| 2715 |
$services = MediaWikiServices::getInstance(); |
| 2716 |
if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) { |
| 2717 |
return $services->getContentLanguage()->ucfirst( $text ); |
| 2718 |
} else { |
| 2719 |
return $text; |
| 2720 |
} |
| 2721 |
} |
| 2722 |
|
| 2723 |
|
| 2724 |
|
| 2725 |
|
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
|
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
|
| 2738 |
|
| 2739 |
private function secureAndSplit( $text, $defaultNamespace = null ) { |
| 2740 |
$defaultNamespace ??= self::DEFAULT_NAMESPACE; |
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
|
| 2748 |
$titleCodec = MediaWikiServices::getInstance()->getTitleParser(); |
| 2749 |
'@phan-var MediaWikiTitleCodec $titleCodec'; |
| 2750 |
|
| 2751 |
$parts = $titleCodec->splitTitleString( $text, $defaultNamespace ); |
| 2752 |
|
| 2753 |
|
| 2754 |
$this->setFragment( '#' . $parts['fragment'] ); |
| 2755 |
$this->mInterwiki = $parts['interwiki']; |
| 2756 |
$this->mLocalInterwiki = $parts['local_interwiki']; |
| 2757 |
$this->mNamespace = $parts['namespace']; |
| 2758 |
|
| 2759 |
$this->mDbkeyform = $parts['dbkey']; |
| 2760 |
$this->mUrlform = wfUrlencode( $this->mDbkeyform ); |
| 2761 |
$this->mTextform = strtr( $this->mDbkeyform, '_', ' ' ); |
| 2762 |
|
| 2763 |
|
| 2764 |
$this->mIsValid = true; |
| 2765 |
|
| 2766 |
|
| 2767 |
if ( $this->isExternal() || $this->isSpecialPage() || $this->mTextform === '' ) { |
| 2768 |
$this->mArticleID = 0; |
| 2769 |
} |
| 2770 |
} |
| 2771 |
|
| 2772 |
|
| 2773 |
|
| 2774 |
|
| 2775 |
|
| 2776 |
|
| 2777 |
|
| 2778 |
|
| 2779 |
|
| 2780 |
|
| 2781 |
|
| 2782 |
|
| 2783 |
|
| 2784 |
public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) { |
| 2785 |
if ( count( $options ) > 0 ) { |
| 2786 |
$db = $this->getDbProvider()->getPrimaryDatabase(); |
| 2787 |
} else { |
| 2788 |
$db = $this->getDbProvider()->getReplicaDatabase(); |
| 2789 |
} |
| 2790 |
|
| 2791 |
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration(); |
| 2792 |
if ( isset( $linksMigration::$mapping[$table] ) ) { |
| 2793 |
$titleConds = $linksMigration->getLinksConditions( $table, $this ); |
| 2794 |
} else { |
| 2795 |
$titleConds = [ |
| 2796 |
"{$prefix}_namespace" => $this->mNamespace, |
| 2797 |
"{$prefix}_title" => $this->mDbkeyform |
| 2798 |
]; |
| 2799 |
} |
| 2800 |
|
| 2801 |
$res = $db->newSelectQueryBuilder() |
| 2802 |
->select( LinkCache::getSelectFields() ) |
| 2803 |
->from( $table ) |
| 2804 |
->join( 'page', null, "{$prefix}_from=page_id" ) |
| 2805 |
->where( $titleConds ) |
| 2806 |
->options( $options ) |
| 2807 |
->caller( __METHOD__ ) |
| 2808 |
->fetchResultSet(); |
| 2809 |
|
| 2810 |
$retVal = []; |
| 2811 |
if ( $res->numRows() ) { |
| 2812 |
$linkCache = MediaWikiServices::getInstance()->getLinkCache(); |
| 2813 |
foreach ( $res as $row ) { |
| 2814 |
$titleObj = self::makeTitle( $row->page_namespace, $row->page_title ); |
| 2815 |
if ( $titleObj ) { |
| 2816 |
$linkCache->addGoodLinkObjFromRow( $titleObj, $row ); |
| 2817 |
$retVal[] = $titleObj; |
| 2818 |
} |
| 2819 |
} |
| 2820 |
} |
| 2821 |
return $retVal; |
| 2822 |
} |
| 2823 |
|
| 2824 |
|
| 2825 |
|
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
|
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
public function getTemplateLinksTo( $options = [] ) { |
| 2835 |
return $this->getLinksTo( $options, 'templatelinks', 'tl' ); |
| 2836 |
} |
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
|
| 2846 |
|
| 2847 |
|
| 2848 |
|
| 2849 |
|
| 2850 |
public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) { |
| 2851 |
$id = $this->getArticleID(); |
| 2852 |
|
| 2853 |
|
| 2854 |
if ( !$id ) { |
| 2855 |
return []; |
| 2856 |
} |
| 2857 |
|
| 2858 |
$db = $this->getDbProvider()->getReplicaDatabase(); |
| 2859 |
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration(); |
| 2860 |
|
| 2861 |
$queryBuilder = $db->newSelectQueryBuilder(); |
| 2862 |
if ( isset( $linksMigration::$mapping[$table] ) ) { |
| 2863 |
[ $blNamespace, $blTitle ] = $linksMigration->getTitleFields( $table ); |
| 2864 |
$linktargetQueryInfo = $linksMigration->getQueryInfo( $table ); |
| 2865 |
$queryBuilder->queryInfo( $linktargetQueryInfo ); |
| 2866 |
} else { |
| 2867 |
$blNamespace = "{$prefix}_namespace"; |
| 2868 |
$blTitle = "{$prefix}_title"; |
| 2869 |
$queryBuilder->select( [ $blNamespace, $blTitle ] ) |
| 2870 |
->from( $table ); |
| 2871 |
} |
| 2872 |
|
| 2873 |
$pageQuery = WikiPage::getQueryInfo(); |
| 2874 |
$res = $queryBuilder |
| 2875 |
->where( [ "{$prefix}_from" => $id ] ) |
| 2876 |
->leftJoin( 'page', null, [ "page_namespace=$blNamespace", "page_title=$blTitle" ] ) |
| 2877 |
->fields( $pageQuery['fields'] ) |
| 2878 |
->options( $options ) |
| 2879 |
->caller( __METHOD__ ) |
| 2880 |
->fetchResultSet(); |
| 2881 |
|
| 2882 |
$retVal = []; |
| 2883 |
$linkCache = MediaWikiServices::getInstance()->getLinkCache(); |
| 2884 |
foreach ( $res as $row ) { |
| 2885 |
if ( $row->page_id ) { |
| 2886 |
$titleObj = self::newFromRow( $row ); |
| 2887 |
} else { |
| 2888 |
$titleObj = self::makeTitle( $row->$blNamespace, $row->$blTitle ); |
| 2889 |
$linkCache->addBadLinkObj( $titleObj ); |
| 2890 |
} |
| 2891 |
$retVal[] = $titleObj; |
| 2892 |
} |
| 2893 |
|
| 2894 |
return $retVal; |
| 2895 |
} |
| 2896 |
|
| 2897 |
|
| 2898 |
|
| 2899 |
|
| 2900 |
|
| 2901 |
|
| 2902 |
|
| 2903 |
|
| 2904 |
|
| 2905 |
|
| 2906 |
|
| 2907 |
public function getTemplateLinksFrom( $options = [] ) { |
| 2908 |
return $this->getLinksFrom( $options, 'templatelinks', 'tl' ); |
| 2909 |
} |
| 2910 |
|
| 2911 |
|
| 2912 |
|
| 2913 |
|
| 2914 |
|
| 2915 |
|
| 2916 |
|
| 2917 |
|
| 2918 |
public function isSingleRevRedirect() { |
| 2919 |
$dbw = $this->getDbProvider()->getPrimaryDatabase(); |
| 2920 |
$dbw->startAtomic( __METHOD__ ); |
| 2921 |
$pageStore = MediaWikiServices::getInstance()->getPageStore(); |
| 2922 |
|
| 2923 |
$row = $dbw->newSelectQueryBuilder() |
| 2924 |
->select( $pageStore->getSelectFields() ) |
| 2925 |
->from( 'page' ) |
| 2926 |
->where( $this->pageCond() ) |
| 2927 |
->caller( __METHOD__ )->fetchRow(); |
| 2928 |
|
| 2929 |
$this->loadFromRow( $row ); |
| 2930 |
|
| 2931 |
if ( $this->mRedirect && $this->mLatestID ) { |
| 2932 |
$isSingleRevRedirect = !$dbw->newSelectQueryBuilder() |
| 2933 |
->select( '1' ) |
| 2934 |
->forUpdate() |
| 2935 |
->from( 'revision' ) |
| 2936 |
->where( [ 'rev_page' => $this->mArticleID, $dbw->expr( 'rev_id', '!=', (int)$this->mLatestID ) ] ) |
| 2937 |
->caller( __METHOD__ )->fetchField(); |
| 2938 |
} else { |
| 2939 |
$isSingleRevRedirect = false; |
| 2940 |
} |
| 2941 |
|
| 2942 |
$dbw->endAtomic( __METHOD__ ); |
| 2943 |
|
| 2944 |
return $isSingleRevRedirect; |
| 2945 |
} |
| 2946 |
|
| 2947 |
|
| 2948 |
|
| 2949 |
|
| 2950 |
|
| 2951 |
|
| 2952 |
|
| 2953 |
|
| 2954 |
public function getParentCategories() { |
| 2955 |
$data = []; |
| 2956 |
|
| 2957 |
$titleKey = $this->getArticleID(); |
| 2958 |
|
| 2959 |
if ( $titleKey === 0 ) { |
| 2960 |
return $data; |
| 2961 |
} |
| 2962 |
|
| 2963 |
$dbr = $this->getDbProvider()->getReplicaDatabase(); |
| 2964 |
|
| 2965 |
$res = $dbr->newSelectQueryBuilder() |
| 2966 |
->select( 'cl_to' ) |
| 2967 |
->from( 'categorylinks' ) |
| 2968 |
->where( [ 'cl_from' => $titleKey ] ) |
| 2969 |
->caller( __METHOD__ )->fetchResultSet(); |
| 2970 |
|
| 2971 |
if ( $res->numRows() > 0 ) { |
| 2972 |
$contLang = MediaWikiServices::getInstance()->getContentLanguage(); |
| 2973 |
foreach ( $res as $row ) { |
| 2974 |
|
| 2975 |
$data[$contLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] = |
| 2976 |
$this->getFullText(); |
| 2977 |
} |
| 2978 |
} |
| 2979 |
return $data; |
| 2980 |
} |
| 2981 |
|
| 2982 |
|
| 2983 |
|
| 2984 |
|
| 2985 |
|
| 2986 |
|
| 2987 |
|
| 2988 |
public function getParentCategoryTree( $children = [] ) { |
| 2989 |
$stack = []; |
| 2990 |
$parents = $this->getParentCategories(); |
| 2991 |
|
| 2992 |
if ( $parents ) { |
| 2993 |
foreach ( $parents as $parent => $current ) { |
| 2994 |
if ( array_key_exists( $parent, $children ) ) { |
| 2995 |
|
| 2996 |
$stack[$parent] = []; |
| 2997 |
} else { |
| 2998 |
$nt = self::newFromText( $parent ); |
| 2999 |
if ( $nt ) { |
| 3000 |
$stack[$parent] = $nt->getParentCategoryTree( $children + [ $parent => 1 ] ); |
| 3001 |
} |
| 3002 |
} |
| 3003 |
} |
| 3004 |
} |
| 3005 |
|
| 3006 |
return $stack; |
| 3007 |
} |
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
|
| 3012 |
|
| 3013 |
|
| 3014 |
|
| 3015 |
public function pageCond() { |
| 3016 |
if ( $this->mArticleID > 0 ) { |
| 3017 |
|
| 3018 |
return [ 'page_id' => $this->mArticleID ]; |
| 3019 |
} else { |
| 3020 |
return [ 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform ]; |
| 3021 |
} |
| 3022 |
} |
| 3023 |
|
| 3024 |
|
| 3025 |
|
| 3026 |
|
| 3027 |
|
| 3028 |
|
| 3029 |
|
| 3030 |
|
| 3031 |
|
| 3032 |
public function isNewPage( $flags = IDBAccessObject::READ_NORMAL ) { |
| 3033 |
|
| 3034 |
return (bool)$this->getFieldFromPageStore( 'page_is_new', $flags ); |
| 3035 |
} |
| 3036 |
|
| 3037 |
|
| 3038 |
|
| 3039 |
|
| 3040 |
|
| 3041 |
|
| 3042 |
|
| 3043 |
public function isBigDeletion() { |
| 3044 |
global $wgDeleteRevisionsLimit; |
| 3045 |
|
| 3046 |
if ( !$wgDeleteRevisionsLimit ) { |
| 3047 |
return false; |
| 3048 |
} |
| 3049 |
|
| 3050 |
if ( $this->mIsBigDeletion === null ) { |
| 3051 |
$dbr = $this->getDbProvider()->getReplicaDatabase(); |
| 3052 |
$revCount = $dbr->newSelectQueryBuilder() |
| 3053 |
->select( '1' ) |
| 3054 |
->from( 'revision' ) |
| 3055 |
->where( [ 'rev_page' => $this->getArticleID() ] ) |
| 3056 |
->limit( $wgDeleteRevisionsLimit + 1 ) |
| 3057 |
->caller( __METHOD__ )->fetchRowCount(); |
| 3058 |
|
| 3059 |
$this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit; |
| 3060 |
} |
| 3061 |
|
| 3062 |
return $this->mIsBigDeletion; |
| 3063 |
} |
| 3064 |
|
| 3065 |
|
| 3066 |
|
| 3067 |
|
| 3068 |
|
| 3069 |
|
| 3070 |
public function estimateRevisionCount() { |
| 3071 |
if ( !$this->exists() ) { |
| 3072 |
return 0; |
| 3073 |
} |
| 3074 |
|
| 3075 |
if ( $this->mEstimateRevisions === null ) { |
| 3076 |
$dbr = $this->getDbProvider()->getReplicaDatabase(); |
| 3077 |
$this->mEstimateRevisions = $dbr->newSelectQueryBuilder() |
| 3078 |
->select( '*' ) |
| 3079 |
->from( 'revision' ) |
| 3080 |
->where( [ 'rev_page' => $this->getArticleID() ] ) |
| 3081 |
->caller( __METHOD__ ) |
| 3082 |
->estimateRowCount(); |
| 3083 |
} |
| 3084 |
|
| 3085 |
return $this->mEstimateRevisions; |
| 3086 |
} |
| 3087 |
|
| 3088 |
|
| 3089 |
|
| 3090 |
|
| 3091 |
|
| 3092 |
|
| 3093 |
|
| 3094 |
|
| 3095 |
|
| 3096 |
|
| 3097 |
|
| 3098 |
|
| 3099 |
|
| 3100 |
|
| 3101 |
|
| 3102 |
public function equals( object $other ) { |
| 3103 |
|
| 3104 |
|
| 3105 |
|
| 3106 |
return $other instanceof Title |
| 3107 |
&& $this->getInterwiki() === $other->getInterwiki() |
| 3108 |
&& $this->getNamespace() === $other->getNamespace() |
| 3109 |
&& $this->getDBkey() === $other->getDBkey(); |
| 3110 |
} |
| 3111 |
|
| 3112 |
|
| 3113 |
|
| 3114 |
|
| 3115 |
|
| 3116 |
public function isSamePageAs( PageReference $other ): bool { |
| 3117 |
|
| 3118 |
return $this->getWikiId() === $other->getWikiId() |
| 3119 |
&& $this->getNamespace() === $other->getNamespace() |
| 3120 |
&& $this->getDBkey() === $other->getDBkey(); |
| 3121 |
} |
| 3122 |
|
| 3123 |
|
| 3124 |
|
| 3125 |
|
| 3126 |
|
| 3127 |
|
| 3128 |
|
| 3129 |
public function isSubpageOf( Title $title ) { |
| 3130 |
return $this->mInterwiki === $title->mInterwiki |
| 3131 |
&& $this->mNamespace == $title->mNamespace |
| 3132 |
&& str_starts_with( $this->mDbkeyform, $title->mDbkeyform . '/' ); |
| 3133 |
} |
| 3134 |
|
| 3135 |
|
| 3136 |
|
| 3137 |
|
| 3138 |
|
| 3139 |
|
| 3140 |
|
| 3141 |
|
| 3142 |
|
| 3143 |
|
| 3144 |
|
| 3145 |
public function exists( $flags = 0 ): bool { |
| 3146 |
$exists = $this->getArticleID( $flags ) != 0; |
| 3147 |
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onTitleExists( $this, $exists ); |
| 3148 |
return $exists; |
| 3149 |
} |
| 3150 |
|
| 3151 |
|
| 3152 |
|
| 3153 |
|
| 3154 |
|
| 3155 |
|
| 3156 |
|
| 3157 |
|
| 3158 |
|
| 3159 |
|
| 3160 |
|
| 3161 |
|
| 3162 |
|
| 3163 |
|
| 3164 |
|
| 3165 |
|
| 3166 |
|
| 3167 |
public function isAlwaysKnown() { |
| 3168 |
$isKnown = null; |
| 3169 |
|
| 3170 |
$services = MediaWikiServices::getInstance(); |
| 3171 |
( new HookRunner( $services->getHookContainer() ) )->onTitleIsAlwaysKnown( $this, $isKnown ); |
| 3172 |
|
| 3173 |
if ( $isKnown !== null ) { |
| 3174 |
return $isKnown; |
| 3175 |
} |
| 3176 |
|
| 3177 |
if ( $this->isExternal() ) { |
| 3178 |
return true; |
| 3179 |
} |
| 3180 |
|
| 3181 |
switch ( $this->mNamespace ) { |
| 3182 |
case NS_MEDIA: |
| 3183 |
case NS_FILE: |
| 3184 |
|
| 3185 |
return (bool)$services->getRepoGroup()->findFile( $this ); |
| 3186 |
case NS_SPECIAL: |
| 3187 |
|
| 3188 |
return $services->getSpecialPageFactory()->exists( $this->mDbkeyform ); |
| 3189 |
case NS_MAIN: |
| 3190 |
|
| 3191 |
return $this->mDbkeyform == ''; |
| 3192 |
case NS_MEDIAWIKI: |
| 3193 |
|
| 3194 |
return $this->hasSourceText() !== false; |
| 3195 |
default: |
| 3196 |
return false; |
| 3197 |
} |
| 3198 |
} |
| 3199 |
|
| 3200 |
|
| 3201 |
|
| 3202 |
|
| 3203 |
|
| 3204 |
|
| 3205 |
|
| 3206 |
|
| 3207 |
|
| 3208 |
|
| 3209 |
|
| 3210 |
|
| 3211 |
public function isKnown() { |
| 3212 |
return $this->isAlwaysKnown() || $this->exists(); |
| 3213 |
} |
| 3214 |
|
| 3215 |
|
| 3216 |
|
| 3217 |
|
| 3218 |
|
| 3219 |
|
| 3220 |
public function hasSourceText() { |
| 3221 |
if ( $this->exists() ) { |
| 3222 |
return true; |
| 3223 |
} |
| 3224 |
|
| 3225 |
if ( $this->mNamespace === NS_MEDIAWIKI ) { |
| 3226 |
$services = MediaWikiServices::getInstance(); |
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
|
| 3231 |
$contLang = $services->getContentLanguage(); |
| 3232 |
[ $name, ] = $services->getMessageCache()->figureMessage( |
| 3233 |
$contLang->lcfirst( $this->getText() ) |
| 3234 |
); |
| 3235 |
$message = wfMessage( $name )->inLanguage( $contLang )->useDatabase( false ); |
| 3236 |
return $message->exists(); |
| 3237 |
} |
| 3238 |
|
| 3239 |
return false; |
| 3240 |
} |
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
|
| 3245 |
|
| 3246 |
|
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
|
| 3254 |
|
| 3255 |
|
| 3256 |
|
| 3257 |
|
| 3258 |
|
| 3259 |
|
| 3260 |
|
| 3261 |
|
| 3262 |
|
| 3263 |
|
| 3264 |
|
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
|
| 3271 |
|
| 3272 |
|
| 3273 |
|
| 3274 |
|
| 3275 |
|
| 3276 |
|
| 3277 |
|
| 3278 |
|
| 3279 |
public function getDefaultMessageText() { |
| 3280 |
$message = $this->getDefaultSystemMessage(); |
| 3281 |
|
| 3282 |
return $message ? $message->plain() : false; |
| 3283 |
} |
| 3284 |
|
| 3285 |
|
| 3286 |
|
| 3287 |
|
| 3288 |
|
| 3289 |
|
| 3290 |
|
| 3291 |
|
| 3292 |
public function getDefaultSystemMessage(): ?Message { |
| 3293 |
if ( $this->mNamespace !== NS_MEDIAWIKI ) { |
| 3294 |
return null; |
| 3295 |
} |
| 3296 |
|
| 3297 |
[ $name, $lang ] = MediaWikiServices::getInstance()->getMessageCache()->figureMessage( |
| 3298 |
MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $this->getText() ) |
| 3299 |
); |
| 3300 |
|
| 3301 |
if ( wfMessage( $name )->inLanguage( $lang )->useDatabase( false )->exists() ) { |
| 3302 |
return wfMessage( $name )->inLanguage( $lang ); |
| 3303 |
} else { |
| 3304 |
return null; |
| 3305 |
} |
| 3306 |
} |
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
public function invalidateCache( $purgeTime = null ) { |
| 3315 |
if ( MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly() ) { |
| 3316 |
return false; |
| 3317 |
} |
| 3318 |
if ( $this->mArticleID === 0 ) { |
| 3319 |
|
| 3320 |
return true; |
| 3321 |
} |
| 3322 |
|
| 3323 |
$conds = $this->pageCond(); |
| 3324 |
|
| 3325 |
|
| 3326 |
|
| 3327 |
|
| 3328 |
|
| 3329 |
|
| 3330 |
|
| 3331 |
DeferredUpdates::addUpdate( |
| 3332 |
new AutoCommitUpdate( |
| 3333 |
$this->getDbProvider()->getPrimaryDatabase(), |
| 3334 |
__METHOD__, |
| 3335 |
function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) { |
| 3336 |
$dbTimestamp = $dbw->timestamp( $purgeTime ?: time() ); |
| 3337 |
$update = $dbw->newUpdateQueryBuilder() |
| 3338 |
->update( 'page' ) |
| 3339 |
->set( [ 'page_touched' => $dbTimestamp ] ) |
| 3340 |
->where( $conds ) |
| 3341 |
->andWhere( $dbw->expr( 'page_touched', '<', $dbTimestamp ) ); |
| 3342 |
|
| 3343 |
if ( mt_rand( 1, 10 ) === 1 ) { |
| 3344 |
$update->andSet( [ 'page_random' => wfRandom() ] ); |
| 3345 |
} |
| 3346 |
|
| 3347 |
$update->caller( $fname )->execute(); |
| 3348 |
|
| 3349 |
MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $this ); |
| 3350 |
|
| 3351 |
WikiModule::invalidateModuleCache( |
| 3352 |
$this, null, null, $dbw->getDomainID() ); |
| 3353 |
} |
| 3354 |
), |
| 3355 |
DeferredUpdates::PRESEND |
| 3356 |
); |
| 3357 |
|
| 3358 |
return true; |
| 3359 |
} |
| 3360 |
|
| 3361 |
|
| 3362 |
|
| 3363 |
|
| 3364 |
|
| 3365 |
|
| 3366 |
public function touchLinks() { |
| 3367 |
$jobs = []; |
| 3368 |
$jobs[] = HTMLCacheUpdateJob::newForBacklinks( |
| 3369 |
$this, |
| 3370 |
'pagelinks', |
| 3371 |
[ 'causeAction' => 'page-touch' ] |
| 3372 |
); |
| 3373 |
if ( $this->mNamespace === NS_CATEGORY ) { |
| 3374 |
$jobs[] = HTMLCacheUpdateJob::newForBacklinks( |
| 3375 |
$this, |
| 3376 |
'categorylinks', |
| 3377 |
[ 'causeAction' => 'category-touch' ] |
| 3378 |
); |
| 3379 |
} |
| 3380 |
|
| 3381 |
MediaWikiServices::getInstance()->getJobQueueGroup()->lazyPush( $jobs ); |
| 3382 |
} |
| 3383 |
|
| 3384 |
|
| 3385 |
|
| 3386 |
|
| 3387 |
|
| 3388 |
|
| 3389 |
|
| 3390 |
public function getTouched( int $flags = IDBAccessObject::READ_NORMAL ) { |
| 3391 |
$touched = $this->getFieldFromPageStore( 'page_touched', $flags ); |
| 3392 |
return $touched ? MWTimestamp::convert( TS_MW, $touched ) : false; |
| 3393 |
} |
| 3394 |
|
| 3395 |
|
| 3396 |
|
| 3397 |
|
| 3398 |
|
| 3399 |
|
| 3400 |
|
| 3401 |
public function getNamespaceKey( $prepend = 'nstab-' ) { |
| 3402 |
|
| 3403 |
$nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); |
| 3404 |
$subjectNS = $nsInfo->getSubject( $this->mNamespace ); |
| 3405 |
|
| 3406 |
$namespaceKey = $nsInfo->getCanonicalName( $subjectNS ); |
| 3407 |
if ( $namespaceKey === false ) { |
| 3408 |
|
| 3409 |
$namespaceKey = $this->getSubjectNsText(); |
| 3410 |
} |
| 3411 |
|
| 3412 |
$namespaceKey = MediaWikiServices::getInstance()->getContentLanguage()->lc( $namespaceKey ); |
| 3413 |
|
| 3414 |
if ( $namespaceKey == '' ) { |
| 3415 |
$namespaceKey = 'main'; |
| 3416 |
} |
| 3417 |
|
| 3418 |
if ( $namespaceKey == 'file' ) { |
| 3419 |
$namespaceKey = 'image'; |
| 3420 |
} |
| 3421 |
return $prepend . $namespaceKey; |
| 3422 |
} |
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
|
| 3427 |
|
| 3428 |
|
| 3429 |
|
| 3430 |
public function getRedirectsHere( $ns = null ) { |
| 3431 |
$redirs = []; |
| 3432 |
|
| 3433 |
$queryBuilder = $this->getDbProvider()->getReplicaDatabase()->newSelectQueryBuilder() |
| 3434 |
->select( [ 'page_namespace', 'page_title' ] ) |
| 3435 |
->from( 'redirect' ) |
| 3436 |
->join( 'page', null, 'rd_from = page_id' ) |
| 3437 |
->where( [ |
| 3438 |
'rd_namespace' => $this->mNamespace, |
| 3439 |
'rd_title' => $this->mDbkeyform, |
| 3440 |
'rd_interwiki' => $this->isExternal() ? $this->mInterwiki : '', |
| 3441 |
] ); |
| 3442 |
|
| 3443 |
if ( $ns !== null ) { |
| 3444 |
$queryBuilder->andWhere( [ 'page_namespace' => $ns ] ); |
| 3445 |
} |
| 3446 |
|
| 3447 |
$res = $queryBuilder->caller( __METHOD__ )->fetchResultSet(); |
| 3448 |
|
| 3449 |
foreach ( $res as $row ) { |
| 3450 |
$redirs[] = self::newFromRow( $row ); |
| 3451 |
} |
| 3452 |
return $redirs; |
| 3453 |
} |
| 3454 |
|
| 3455 |
|
| 3456 |
|
| 3457 |
|
| 3458 |
|
| 3459 |
|
| 3460 |
public function isValidRedirectTarget() { |
| 3461 |
global $wgInvalidRedirectTargets; |
| 3462 |
|
| 3463 |
if ( $this->isSpecialPage() ) { |
| 3464 |
|
| 3465 |
foreach ( [ 'Userlogout', ...$wgInvalidRedirectTargets ] as $target ) { |
| 3466 |
if ( $this->isSpecial( $target ) ) { |
| 3467 |
return false; |
| 3468 |
} |
| 3469 |
} |
| 3470 |
return true; |
| 3471 |
} |
| 3472 |
|
| 3473 |
|
| 3474 |
return $this->getDBkey() !== '' && $this->isValid(); |
| 3475 |
} |
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
|
| 3482 |
public function canUseNoindex() { |
| 3483 |
global $wgExemptFromUserRobotsControl; |
| 3484 |
|
| 3485 |
$bannedNamespaces = $wgExemptFromUserRobotsControl ?? |
| 3486 |
MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces(); |
| 3487 |
|
| 3488 |
return !in_array( $this->mNamespace, $bannedNamespaces ); |
| 3489 |
} |
| 3490 |
|
| 3491 |
|
| 3492 |
|
| 3493 |
|
| 3494 |
|
| 3495 |
|
| 3496 |
|
| 3497 |
|
| 3498 |
|
| 3499 |
|
| 3500 |
|
| 3501 |
public function getCategorySortkey( $prefix = '' ) { |
| 3502 |
$unprefixed = $this->getText(); |
| 3503 |
|
| 3504 |
|
| 3505 |
|
| 3506 |
|
| 3507 |
|
| 3508 |
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) ) |
| 3509 |
->onGetDefaultSortkey( $this, $unprefixed ); |
| 3510 |
if ( $prefix !== '' ) { |
| 3511 |
|
| 3512 |
|
| 3513 |
|
| 3514 |
|
| 3515 |
$prefix = strtr( $prefix, "\n\t", ' ' ); |
| 3516 |
return "$prefix\n$unprefixed"; |
| 3517 |
} |
| 3518 |
return $unprefixed; |
| 3519 |
} |
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
|
| 3524 |
|
| 3525 |
|
| 3526 |
|
| 3527 |
|
| 3528 |
|
| 3529 |
|
| 3530 |
private function getDbPageLanguageCode( int $flags = 0 ): ?string { |
| 3531 |
global $wgPageLanguageUseDB; |
| 3532 |
|
| 3533 |
|
| 3534 |
|
| 3535 |
if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) { |
| 3536 |
$this->mDbPageLanguage = $this->getFieldFromPageStore( 'page_lang', $flags ) ?: null; |
| 3537 |
} |
| 3538 |
|
| 3539 |
return $this->mDbPageLanguage ?: null; |
| 3540 |
} |
| 3541 |
|
| 3542 |
|
| 3543 |
|
| 3544 |
|
| 3545 |
|
| 3546 |
|
| 3547 |
|
| 3548 |
|
| 3549 |
private function getDbPageLanguage(): ?Language { |
| 3550 |
$languageCode = $this->getDbPageLanguageCode(); |
| 3551 |
if ( $languageCode === null ) { |
| 3552 |
return null; |
| 3553 |
} |
| 3554 |
$services = MediaWikiServices::getInstance(); |
| 3555 |
if ( !$services->getLanguageNameUtils()->isKnownLanguageTag( $languageCode ) ) { |
| 3556 |
return null; |
| 3557 |
} |
| 3558 |
return $services->getLanguageFactory()->getLanguage( $languageCode ); |
| 3559 |
} |
| 3560 |
|
| 3561 |
|
| 3562 |
|
| 3563 |
|
| 3564 |
|
| 3565 |
|
| 3566 |
|
| 3567 |
|
| 3568 |
|
| 3569 |
public function getPageLanguage() { |
| 3570 |
global $wgLanguageCode; |
| 3571 |
if ( $this->isSpecialPage() ) { |
| 3572 |
|
| 3573 |
return RequestContext::getMain()->getLanguage(); |
| 3574 |
} |
| 3575 |
|
| 3576 |
|
| 3577 |
$dbPageLanguage = $this->getDbPageLanguage(); |
| 3578 |
if ( $dbPageLanguage ) { |
| 3579 |
return $dbPageLanguage; |
| 3580 |
} |
| 3581 |
|
| 3582 |
$services = MediaWikiServices::getInstance(); |
| 3583 |
if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) { |
| 3584 |
|
| 3585 |
|
| 3586 |
|
| 3587 |
|
| 3588 |
|
| 3589 |
|
| 3590 |
$contentHandler = $services->getContentHandlerFactory() |
| 3591 |
->getContentHandler( $this->getContentModel() ); |
| 3592 |
$langObj = $contentHandler->getPageLanguage( $this ); |
| 3593 |
$this->mPageLanguage = [ $langObj->getCode(), $wgLanguageCode ]; |
| 3594 |
} else { |
| 3595 |
$langObj = $services->getLanguageFactory() |
| 3596 |
->getLanguage( $this->mPageLanguage[0] ); |
| 3597 |
} |
| 3598 |
|
| 3599 |
return $langObj; |
| 3600 |
} |
| 3601 |
|
| 3602 |
|
| 3603 |
|
| 3604 |
|
| 3605 |
|
| 3606 |
|
| 3607 |
|
| 3608 |
|
| 3609 |
|
| 3610 |
|
| 3611 |
|
| 3612 |
public function getPageViewLanguage() { |
| 3613 |
wfDeprecated( __METHOD__, '1.42' ); |
| 3614 |
$services = MediaWikiServices::getInstance(); |
| 3615 |
|
| 3616 |
if ( $this->isSpecialPage() ) { |
| 3617 |
|
| 3618 |
|
| 3619 |
$userLang = RequestContext::getMain()->getLanguage(); |
| 3620 |
$variant = $this->getLanguageConverter( $userLang )->getPreferredVariant(); |
| 3621 |
if ( $userLang->getCode() !== $variant ) { |
| 3622 |
return $services->getLanguageFactory() |
| 3623 |
->getLanguage( $variant ); |
| 3624 |
} |
| 3625 |
|
| 3626 |
return $userLang; |
| 3627 |
} |
| 3628 |
|
| 3629 |
|
| 3630 |
$pageLang = $this->getDbPageLanguage(); |
| 3631 |
if ( $pageLang ) { |
| 3632 |
$variant = $this->getLanguageConverter( $pageLang )->getPreferredVariant(); |
| 3633 |
if ( $pageLang->getCode() !== $variant ) { |
| 3634 |
return $services->getLanguageFactory() |
| 3635 |
->getLanguage( $variant ); |
| 3636 |
} |
| 3637 |
|
| 3638 |
return $pageLang; |
| 3639 |
} |
| 3640 |
|
| 3641 |
|
| 3642 |
|
| 3643 |
|
| 3644 |
$contentHandler = $services->getContentHandlerFactory() |
| 3645 |
->getContentHandler( $this->getContentModel() ); |
| 3646 |
$pageLang = $contentHandler->getPageViewLanguage( $this ); |
| 3647 |
return $pageLang; |
| 3648 |
} |
| 3649 |
|
| 3650 |
|
| 3651 |
|
| 3652 |
|
| 3653 |
|
| 3654 |
|
| 3655 |
|
| 3656 |
|
| 3657 |
|
| 3658 |
|
| 3659 |
|
| 3660 |
public function getEditNotices( $oldid = 0 ) { |
| 3661 |
$notices = []; |
| 3662 |
|
| 3663 |
$editnotice_base = 'editnotice-' . $this->mNamespace; |
| 3664 |
|
| 3665 |
$messages = [ $editnotice_base => 'namespace' ]; |
| 3666 |
|
| 3667 |
if ( |
| 3668 |
MediaWikiServices::getInstance()->getNamespaceInfo()-> |
| 3669 |
hasSubpages( $this->mNamespace ) |
| 3670 |
) { |
| 3671 |
|
| 3672 |
foreach ( explode( '/', $this->mDbkeyform ) as $part ) { |
| 3673 |
$editnotice_base .= '-' . $part; |
| 3674 |
$messages[$editnotice_base] = 'base'; |
| 3675 |
} |
| 3676 |
} else { |
| 3677 |
|
| 3678 |
$messages[$editnotice_base . '-' . strtr( $this->mDbkeyform, '/', '-' )] = 'page'; |
| 3679 |
} |
| 3680 |
|
| 3681 |
foreach ( $messages as $editnoticeText => $class ) { |
| 3682 |
|
| 3683 |
|
| 3684 |
|
| 3685 |
|
| 3686 |
… |
| 3687 |
$msg = wfMessage( $editnoticeText )->page( $this ); |
| 3688 |
if ( $msg->exists() ) { |
| 3689 |
$html = $msg->parseAsBlock(); |
| 3690 |
|
| 3691 |
if ( trim( $html ) !== '' ) { |
| 3692 |
$notices[$editnoticeText] = Html::rawElement( |
| 3693 |
'div', |
| 3694 |
[ 'class' => [ |
| 3695 |
'mw-editnotice', |
| 3696 |
|
| 3697 |
|
| 3698 |
|
| 3699 |
|
| 3700 |
"mw-editnotice-$class", |
| 3701 |
|
| 3702 |
|
| 3703 |
… |
| 3704 |
Sanitizer::escapeClass( "mw-$editnoticeText" ) |
| 3705 |
] ], |
| 3706 |
$html |
| 3707 |
); |
| 3708 |
} |
| 3709 |
} |
| 3710 |
} |
| 3711 |
|
| 3712 |
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) ) |
| 3713 |
->onTitleGetEditNotices( $this, $oldid, $notices ); |
| 3714 |
return $notices; |
| 3715 |
} |
| 3716 |
|
| 3717 |
|
| 3718 |
|
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
private function getFieldFromPageStore( $field, $flags ) { |
| 3723 |
$pageStore = MediaWikiServices::getInstance()->getPageStore(); |
| 3724 |
|
| 3725 |
if ( !in_array( $field, $pageStore->getSelectFields(), true ) ) { |
| 3726 |
throw new InvalidArgumentException( "Unknown field: $field" ); |
| 3727 |
} |
| 3728 |
|
| 3729 |
if ( $flags === IDBAccessObject::READ_NORMAL && $this->mArticleID === 0 ) { |
| 3730 |
|
| 3731 |
return false; |
| 3732 |
} |
| 3733 |
|
| 3734 |
if ( !$this->canExist() ) { |
| 3735 |
return false; |
| 3736 |
} |
| 3737 |
|
| 3738 |
$page = $pageStore->getPageByReference( $this, $flags ); |
| 3739 |
|
| 3740 |
if ( $page instanceof PageStoreRecord ) { |
| 3741 |
return $page->getField( $field ); |
| 3742 |
} else { |
| 3743 |
|
| 3744 |
|
| 3745 |
|
| 3746 |
|
| 3747 |
$this->mArticleID = 0; |
| 3748 |
return false; |
| 3749 |
} |
| 3750 |
} |
| 3751 |
|
| 3752 |
|
| 3753 |
|
| 3754 |
|
| 3755 |
public function __sleep() { |
| 3756 |
return [ |
| 3757 |
'mNamespace', |
| 3758 |
'mDbkeyform', |
| 3759 |
'mFragment', |
| 3760 |
'mInterwiki', |
| 3761 |
'mLocalInterwiki', |
| 3762 |
]; |
| 3763 |
} |
| 3764 |
|
| 3765 |
public function __wakeup() { |
| 3766 |
$this->mArticleID = ( $this->mNamespace >= 0 ) ? -1 : 0; |
| 3767 |
$this->mUrlform = wfUrlencode( $this->mDbkeyform ); |
| 3768 |
$this->mTextform = strtr( $this->mDbkeyform, '_', ' ' ); |
| 3769 |
} |
| 3770 |
|
| 3771 |
public function __clone() { |
| 3772 |
$this->mInstanceCacheKey = null; |
| 3773 |
} |
| 3774 |
|
| 3775 |
|
| 3776 |
|
| 3777 |
|
| 3778 |
|
| 3779 |
|
| 3780 |
|
| 3781 |
|
| 3782 |
|
| 3783 |
|
| 3784 |
public function getWikiId() { |
| 3785 |
return self::LOCAL; |
| 3786 |
} |
| 3787 |
|
| 3788 |
|
| 3789 |
|
| 3790 |
|
| 3791 |
|
| 3792 |
|
| 3793 |
|
| 3794 |
|
| 3795 |
|
| 3796 |
|
| 3797 |
|
| 3798 |
|
| 3799 |
|
| 3800 |
|
| 3801 |
|
| 3802 |
|
| 3803 |
|
| 3804 |
public function getId( $wikiId = self::LOCAL ): int { |
| 3805 |
$this->assertWiki( $wikiId ); |
| 3806 |
$this->assertProperPage(); |
| 3807 |
return $this->getArticleID(); |
| 3808 |
} |
| 3809 |
|
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
|
| 3815 |
|
| 3816 |
|
| 3817 |
|
| 3818 |
|
| 3819 |
|
| 3820 |
|
| 3821 |
|
| 3822 |
private function assertProperPage() { |
| 3823 |
Assert::precondition( |
| 3824 |
$this->canExist(), |
| 3825 |
'This Title instance does not represent a proper page, but merely a link target.' |
| 3826 |
); |
| 3827 |
} |
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
|
| 3832 |
|
| 3833 |
|
| 3834 |
|
| 3835 |
|
| 3836 |
|
| 3837 |
|
| 3838 |
|
| 3839 |
|
| 3840 |
|
| 3841 |
public function toPageIdentity(): ProperPageIdentity { |
| 3842 |
|
| 3843 |
|
| 3844 |
$this->assertProperPage(); |
| 3845 |
|
| 3846 |
return new PageIdentityValue( |
| 3847 |
$this->getId(), |
| 3848 |
$this->getNamespace(), |
| 3849 |
$this->getDBkey(), |
| 3850 |
$this->getWikiId() |
| 3851 |
); |
| 3852 |
} |
| 3853 |
|
| 3854 |
|
| 3855 |
|
| 3856 |
|
| 3857 |
|
| 3858 |
|
| 3859 |
|
| 3860 |
|
| 3861 |
|
| 3862 |
|
| 3863 |
|
| 3864 |
|
| 3865 |
|
| 3866 |
|
| 3867 |
|
| 3868 |
public function toPageRecord( $flags = 0 ): ExistingPageRecord { |
| 3869 |
|
| 3870 |
|
| 3871 |
$this->assertProperPage(); |
| 3872 |
|
| 3873 |
Assert::precondition( |
| 3874 |
$this->exists( $flags ), |
| 3875 |
'This Title instance does not represent an existing page: ' . $this |
| 3876 |
); |
| 3877 |
|
| 3878 |
return new PageStoreRecord( |
| 3879 |
(object)[ |
| 3880 |
'page_id' => $this->getArticleID( $flags ), |
| 3881 |
'page_namespace' => $this->getNamespace(), |
| 3882 |
'page_title' => $this->getDBkey(), |
| 3883 |
'page_wiki_id' => $this->getWikiId(), |
| 3884 |
'page_latest' => $this->getLatestRevID( $flags ), |
| 3885 |
'page_is_new' => $this->isNewPage( $flags ), |
| 3886 |
'page_is_redirect' => $this->isRedirect( $flags ), |
| 3887 |
'page_touched' => $this->getTouched( $flags ), |
| 3888 |
'page_lang' => $this->getDbPageLanguageCode( $flags ), |
| 3889 |
], |
| 3890 |
PageIdentity::LOCAL |
| 3891 |
); |
| 3892 |
} |
| 3893 |
|
| 3894 |
} |
| 3895 |
|
| 3896 |
|
| 3897 |
class_alias( Title::class, 'Title' ); |