MediaWiki  master
Title.php
Go to the documentation of this file.
1 <?php
35 use Wikimedia\Assert\Assert;
36 use Wikimedia\Assert\PreconditionException;
38 
50 
52  private static $titleCache = null;
53 
59  private const CACHE_MAX = 1000;
60 
66  public const GAID_FOR_UPDATE = 512;
67 
75  public const NEW_CLONE = 'clone';
76 
78  private $mTextform = '';
79 
81  private $mUrlform = '';
82 
84  private $mDbkeyform = '';
85 
87  private $mNamespace = NS_MAIN;
88 
90  private $mInterwiki = '';
91 
93  private $mLocalInterwiki = false;
94 
96  private $mFragment = '';
97 
98  /***************************************************************************/
99  // region Private member variables
107  public $mArticleID = -1;
108 
110  protected $mLatestID = false;
111 
116  private $mContentModel = false;
117 
122  private $mForcedContentModel = false;
123 
126 
135  public $prefixedText = null;
136 
144 
146  protected $mLength = -1;
147 
149  public $mRedirect = null;
150 
152  private $mHasSubpages;
153 
155  private $mPageLanguage;
156 
160  private $mDbPageLanguage = false;
161 
163  private $mTitleValue = null;
164 
166  private $mIsBigDeletion = null;
167 
169  private $mIsValid = null;
170 
172  private $mInstanceCacheKey = null;
173 
174  // endregion -- end of private member variables
176  /***************************************************************************/
177 
183  private function getLanguageConverter( $language ): ILanguageConverter {
184  return MediaWikiServices::getInstance()->getLanguageConverterFactory()
185  ->getLanguageConverter( $language );
186  }
187 
193  return $this->getLanguageConverter( $this->getPageLanguage() );
194  }
195 
204  private static function getTitleFormatter() {
205  return MediaWikiServices::getInstance()->getTitleFormatter();
206  }
207 
216  private static function getInterwikiLookup() {
217  return MediaWikiServices::getInstance()->getInterwikiLookup();
218  }
219 
220  private function __construct() {
221  // Phan is being silly about callable|string, see T297352.
222  // Note that the silliness doesn't trigger for 'getText', because gettext() exists
223  // as a global built-in function.
224  $this->deprecatePublicPropertyFallback( 'mTextform', '1.38', 'getText' );
225 
226  // @phan-suppress-next-line PhanUndeclaredFunctionInCallable
227  $this->deprecatePublicPropertyFallback( 'mUrlform', '1.38', 'getPartialURL' );
228 
229  // @phan-suppress-next-line PhanUndeclaredFunctionInCallable
230  $this->deprecatePublicPropertyFallback( 'mDbkeyform', '1.38', 'getDBkey' );
231 
232  // @phan-suppress-next-line PhanUndeclaredFunctionInCallable
233  $this->deprecatePublicPropertyFallback( 'mNamespace', '1.38', 'getNamespace' );
234 
235  // @phan-suppress-next-line PhanUndeclaredFunctionInCallable
236  $this->deprecatePublicPropertyFallback( 'mInterwiki', '1.38', 'getInterwiki' );
237 
238  // @phan-suppress-next-line PhanUndeclaredFunctionInCallable
239  $this->deprecatePublicPropertyFallback( 'mFragment', '1.38', 'getFragment', 'setFragment' );
240  }
241 
250  public static function newFromDBkey( $key ) {
251  $t = new self();
252 
253  try {
254  $t->secureAndSplit( $key );
255  return $t;
256  } catch ( MalformedTitleException $ex ) {
257  return null;
258  }
259  }
260 
274  public static function newFromTitleValue( TitleValue $titleValue, $forceClone = '' ) {
275  return self::newFromLinkTarget( $titleValue, $forceClone );
276  }
277 
289  public static function newFromLinkTarget( LinkTarget $linkTarget, $forceClone = '' ) {
290  if ( $linkTarget instanceof Title ) {
291  // Special case if it's already a Title object
292  if ( $forceClone === self::NEW_CLONE ) {
293  return clone $linkTarget;
294  } else {
295  return $linkTarget;
296  }
297  }
298  return self::makeTitle(
299  $linkTarget->getNamespace(),
300  $linkTarget->getText(),
301  $linkTarget->getFragment(),
302  $linkTarget->getInterwiki()
303  );
304  }
305 
313  public static function castFromLinkTarget( $linkTarget ) {
314  return $linkTarget ? self::newFromLinkTarget( $linkTarget ) : null;
315  }
316 
326  public static function castFromPageIdentity( ?PageIdentity $pageIdentity ): ?Title {
327  return self::castFromPageReference( $pageIdentity );
328  }
329 
339  public static function castFromPageReference( ?PageReference $pageReference ): ?Title {
340  if ( !$pageReference ) {
341  return null;
342  }
343 
344  if ( $pageReference instanceof Title ) {
345  return $pageReference;
346  }
347 
348  $pageReference->assertWiki( self::LOCAL );
349  $title = self::makeTitle( $pageReference->getNamespace(), $pageReference->getDBkey() );
350 
351  if ( $pageReference instanceof PageIdentity ) {
352  $title->mArticleID = $pageReference->getId();
353  }
354  return $title;
355  }
356 
377  public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
378  // DWIM: Integers can be passed in here when page titles are used as array keys.
379  if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) {
380  throw new InvalidArgumentException( '$text must be a string.' );
381  }
382  if ( $text === null ) {
383  return null;
384  }
385 
386  try {
387  return self::newFromTextThrow( (string)$text, (int)$defaultNamespace );
388  } catch ( MalformedTitleException $ex ) {
389  return null;
390  }
391  }
392 
412  public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
413  if ( is_object( $text ) ) {
414  throw new MWException( '$text must be a string, given an object' );
415  } elseif ( $text === null ) {
416  // Legacy code relies on MalformedTitleException being thrown in this case
417  // TODO: fix(happens when URL with no title in it is parsed).
418  throw new MalformedTitleException( 'title-invalid-empty' );
419  }
420 
422 
423  // Wiki pages often contain multiple links to the same page.
424  // Title normalization and parsing can become expensive on pages with many
425  // links, so we can save a little time by caching them.
426  if ( $defaultNamespace === NS_MAIN ) {
427  $t = $titleCache->get( $text );
428  if ( $t ) {
429  return $t;
430  }
431  }
432 
433  // Convert things like &eacute; &#257; or &#x3017; into normalized (T16952) text
434  $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
435 
436  $t = new Title();
437  $dbKeyForm = strtr( $filteredText, ' ', '_' );
438 
439  $t->secureAndSplit( $dbKeyForm, (int)$defaultNamespace );
440  if ( $defaultNamespace === NS_MAIN ) {
441  $t->mInstanceCacheKey = $text;
442  $titleCache->set( $text, $t );
443  }
444  return $t;
445  }
446 
451  private function uncache() {
452  if ( $this->mInstanceCacheKey !== null ) {
454  $titleCache->clear( $this->mInstanceCacheKey );
455  $this->mInstanceCacheKey = null;
456  }
457  }
458 
474  public static function newFromURL( $url ) {
475  $t = new Title();
476 
477  # For compatibility with old buggy URLs. "+" is usually not valid in titles,
478  # but some URLs used it as a space replacement and they still come
479  # from some external search tools.
480  if ( strpos( self::legalChars(), '+' ) === false ) {
481  $url = strtr( $url, '+', ' ' );
482  }
483 
484  $dbKeyForm = strtr( $url, ' ', '_' );
485 
486  try {
487  $t->secureAndSplit( $dbKeyForm );
488  return $t;
489  } catch ( MalformedTitleException $ex ) {
490  return null;
491  }
492  }
493 
497  private static function getTitleCache() {
498  if ( self::$titleCache === null ) {
499  self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
500  }
501  return self::$titleCache;
502  }
503 
512  protected static function getSelectFields() {
513  return MediaWikiServices::getInstance()->getPageStore()->getSelectFields();
514  }
515 
523  public static function newFromID( $id, $flags = 0 ) {
524  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
525  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
526  $row = wfGetDB( $index )->selectRow(
527  'page',
528  self::getSelectFields(),
529  [ 'page_id' => $id ],
530  __METHOD__,
531  $options
532  );
533  if ( $row !== false ) {
534  $title = self::newFromRow( $row );
535  } else {
536  $title = null;
537  }
538 
539  return $title;
540  }
541 
549  public static function newFromIDs( $ids ) {
550  wfDeprecated( __METHOD__, '1.38' );
551 
552  if ( !count( $ids ) ) {
553  return [];
554  }
555  $dbr = wfGetDB( DB_REPLICA );
556 
557  $res = $dbr->select(
558  'page',
559  self::getSelectFields(),
560  [ 'page_id' => $ids ],
561  __METHOD__
562  );
563 
564  $titles = [];
565  foreach ( $res as $row ) {
566  $titles[] = self::newFromRow( $row );
567  }
568  return $titles;
569  }
570 
577  public static function newFromRow( $row ) {
578  $t = self::makeTitle( $row->page_namespace, $row->page_title );
579  $t->loadFromRow( $row );
580  return $t;
581  }
582 
589  public function loadFromRow( $row ) {
590  if ( $row ) { // page found
591  if ( isset( $row->page_id ) ) {
592  $this->mArticleID = (int)$row->page_id;
593  }
594  if ( isset( $row->page_len ) ) {
595  $this->mLength = (int)$row->page_len;
596  }
597  if ( isset( $row->page_is_redirect ) ) {
598  $this->mRedirect = (bool)$row->page_is_redirect;
599  }
600  if ( isset( $row->page_latest ) ) {
601  $this->mLatestID = (int)$row->page_latest;
602  }
603  if ( isset( $row->page_content_model ) ) {
604  $this->lazyFillContentModel( $row->page_content_model );
605  } else {
606  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
607  }
608  if ( isset( $row->page_lang ) ) {
609  $this->mDbPageLanguage = (string)$row->page_lang;
610  }
611  if ( isset( $row->page_restrictions ) ) {
612  // If we have them handy, save them so we don't need to look them up later
613  MediaWikiServices::getInstance()->getRestrictionStore()
614  ->registerOldRestrictions( $this, $row->page_restrictions );
615 
616  }
617  } else { // page not found
618  $this->mArticleID = 0;
619  $this->mLength = 0;
620  $this->mRedirect = false;
621  $this->mLatestID = 0;
622  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
623  }
624  }
625 
648  public static function makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
649  $t = new Title();
650  $t->mInterwiki = $interwiki;
651  $t->mFragment = self::normalizeFragment( $fragment );
652  $t->mNamespace = $ns = (int)$ns;
653  $t->mDbkeyform = strtr( $title, ' ', '_' );
654  $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
655  $t->mUrlform = wfUrlencode( $t->mDbkeyform );
656  $t->mTextform = strtr( $title, '_', ' ' );
657  return $t;
658  }
659 
674  public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
675  // NOTE: ideally, this would just call makeTitle() and then isValid(),
676  // but presently, that means more overhead on a potential performance hotspot.
677 
678  if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) {
679  return null;
680  }
681 
682  $t = new Title();
683  $dbKeyForm = self::makeName( $ns, $title, $fragment, $interwiki, true );
684 
685  try {
686  $t->secureAndSplit( $dbKeyForm );
687  return $t;
688  } catch ( MalformedTitleException $ex ) {
689  return null;
690  }
691  }
692 
710  public static function newMainPage( MessageLocalizer $localizer = null ) {
711  if ( $localizer ) {
712  $msg = $localizer->msg( 'mainpage' );
713  } else {
714  $msg = wfMessage( 'mainpage' );
715  }
716 
717  $title = self::newFromText( $msg->inContentLanguage()->text() );
718 
719  // Every page renders at least one link to the Main Page (e.g. sidebar).
720  // If the localised value is invalid, don't produce fatal errors that
721  // would make the wiki inaccessible (and hard to fix the invalid message).
722  // Gracefully fallback...
723  if ( !$title ) {
724  $title = self::newFromText( 'Main Page' );
725  }
726  return $title;
727  }
728 
734  public static function legalChars() {
735  global $wgLegalTitleChars;
736  return $wgLegalTitleChars;
737  }
738 
748  public static function convertByteClassToUnicodeClass( $byteClass ) {
749  $length = strlen( $byteClass );
750  // Input token queue
751  $x0 = $x1 = $x2 = '';
752  // Decoded queue
753  $d0 = $d1 = '';
754  // Decoded integer codepoints
755  $ord0 = $ord1 = $ord2 = 0;
756  // Re-encoded queue
757  $r0 = $r1 = $r2 = '';
758  // Output
759  $out = '';
760  // Flags
761  $allowUnicode = false;
762  for ( $pos = 0; $pos < $length; $pos++ ) {
763  // Shift the queues down
764  $x2 = $x1;
765  $x1 = $x0;
766  $d1 = $d0;
767  $ord2 = $ord1;
768  $ord1 = $ord0;
769  $r2 = $r1;
770  $r1 = $r0;
771  // Load the current input token and decoded values
772  $inChar = $byteClass[$pos];
773  if ( $inChar === '\\' ) {
774  if ( preg_match( '/x([0-9a-fA-F]{2})/A', $byteClass, $m, 0, $pos + 1 ) ) {
775  $x0 = $inChar . $m[0];
776  $d0 = chr( hexdec( $m[1] ) );
777  $pos += strlen( $m[0] );
778  } elseif ( preg_match( '/[0-7]{3}/A', $byteClass, $m, 0, $pos + 1 ) ) {
779  $x0 = $inChar . $m[0];
780  $d0 = chr( octdec( $m[0] ) );
781  $pos += strlen( $m[0] );
782  } elseif ( $pos + 1 >= $length ) {
783  $x0 = $d0 = '\\';
784  } else {
785  $d0 = $byteClass[$pos + 1];
786  $x0 = $inChar . $d0;
787  $pos++;
788  }
789  } else {
790  $x0 = $d0 = $inChar;
791  }
792  $ord0 = ord( $d0 );
793  // Load the current re-encoded value
794  if ( $ord0 < 32 || $ord0 == 0x7f ) {
795  $r0 = sprintf( '\x%02x', $ord0 );
796  } elseif ( $ord0 >= 0x80 ) {
797  // Allow unicode if a single high-bit character appears
798  $r0 = sprintf( '\x%02x', $ord0 );
799  $allowUnicode = true;
800  // @phan-suppress-next-line PhanParamSuspiciousOrder false positive
801  } elseif ( strpos( '-\\[]^', $d0 ) !== false ) {
802  $r0 = '\\' . $d0;
803  } else {
804  $r0 = $d0;
805  }
806  // Do the output
807  // @phan-suppress-next-line PhanPluginRedundantAssignmentInLoop Confusing, $r1 is set later
808  if ( $x0 !== '' && $x1 === '-' && $x2 !== '' ) {
809  // Range
810  if ( $ord2 > $ord0 ) {
811  // Empty range
812  } elseif ( $ord0 >= 0x80 ) {
813  // Unicode range
814  $allowUnicode = true;
815  if ( $ord2 < 0x80 ) {
816  // Keep the non-unicode section of the range
817  $out .= "$r2-\\x7F";
818  }
819  } else {
820  // Normal range
821  $out .= "$r2-$r0";
822  }
823  // Reset state to the initial value
824  $x0 = $x1 = $d0 = $d1 = $r0 = $r1 = '';
825  } elseif ( $ord2 < 0x80 ) {
826  // ASCII character
827  $out .= $r2;
828  }
829  }
830  // @phan-suppress-next-line PhanSuspiciousValueComparison
831  if ( $ord1 < 0x80 ) {
832  $out .= $r1;
833  }
834  if ( $ord0 < 0x80 ) {
835  $out .= $r0;
836  }
837  if ( $allowUnicode ) {
838  $out .= '\u0080-\uFFFF';
839  }
840  return $out;
841  }
842 
854  public static function makeName( $ns, $title, $fragment = '', $interwiki = '',
855  $canonicalNamespace = false
856  ) {
857  if ( $canonicalNamespace ) {
858  $namespace = MediaWikiServices::getInstance()->getNamespaceInfo()->
859  getCanonicalName( $ns );
860  } else {
861  $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns );
862  }
863  $name = $namespace == '' ? $title : "$namespace:$title";
864  if ( strval( $interwiki ) != '' ) {
865  $name = "$interwiki:$name";
866  }
867  if ( strval( $fragment ) != '' ) {
868  $name .= '#' . $fragment;
869  }
870  return $name;
871  }
872 
881  public static function compare( $a, $b ) {
882  return $a->getNamespace() <=> $b->getNamespace()
883  ?: strcmp( $a->getDBkey(), $b->getDBkey() );
884  }
885 
902  public function isValid() {
903  if ( $this->mIsValid !== null ) {
904  return $this->mIsValid;
905  }
906 
907  try {
908  $text = $this->getFullText();
909  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
910 
911  '@phan-var MediaWikiTitleCodec $titleCodec';
912  $parts = $titleCodec->splitTitleString( $text, $this->mNamespace );
913 
914  // Check that nothing changed!
915  // This ensures that $text was already properly normalized.
916  if ( $parts['fragment'] !== $this->mFragment
917  || $parts['interwiki'] !== $this->mInterwiki
918  || $parts['local_interwiki'] !== $this->mLocalInterwiki
919  || $parts['namespace'] !== $this->mNamespace
920  || $parts['dbkey'] !== $this->mDbkeyform
921  ) {
922  $this->mIsValid = false;
923  return $this->mIsValid;
924  }
925  } catch ( MalformedTitleException $ex ) {
926  $this->mIsValid = false;
927  return $this->mIsValid;
928  }
929 
930  $this->mIsValid = true;
931  return $this->mIsValid;
932  }
933 
941  public function isLocal() {
942  if ( $this->isExternal() ) {
943  $iw = self::getInterwikiLookup()->fetch( $this->mInterwiki );
944  if ( $iw ) {
945  return $iw->isLocal();
946  }
947  }
948  return true;
949  }
950 
956  public function isExternal(): bool {
957  return $this->mInterwiki !== '';
958  }
959 
967  public function getInterwiki(): string {
968  return $this->mInterwiki;
969  }
970 
976  public function wasLocalInterwiki() {
977  return $this->mLocalInterwiki;
978  }
979 
986  public function isTrans() {
987  if ( !$this->isExternal() ) {
988  return false;
989  }
990 
991  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable();
992  }
993 
999  public function getTransWikiID() {
1000  if ( !$this->isExternal() ) {
1001  return false;
1002  }
1003 
1004  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID();
1005  }
1006 
1016  public function getTitleValue() {
1017  if ( $this->mTitleValue === null ) {
1018  try {
1019  $this->mTitleValue = new TitleValue(
1020  $this->mNamespace,
1021  $this->mDbkeyform,
1022  $this->mFragment,
1023  $this->mInterwiki
1024  );
1025  } catch ( InvalidArgumentException $ex ) {
1026  wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' .
1027  $this->getPrefixedText() . ']]: ' . $ex->getMessage() );
1028  }
1029  }
1030 
1031  return $this->mTitleValue;
1032  }
1033 
1039  public function getText(): string {
1040  return $this->mTextform;
1041  }
1042 
1048  public function getPartialURL() {
1049  return $this->mUrlform;
1050  }
1051 
1057  public function getDBkey(): string {
1058  return $this->mDbkeyform;
1059  }
1060 
1066  public function getNamespace(): int {
1067  return $this->mNamespace;
1068  }
1069 
1076  private function shouldReadLatest( int $flags ) {
1077  return ( $flags & ( self::READ_LATEST | self::GAID_FOR_UPDATE ) ) > 0;
1078  }
1079 
1088  public function getContentModel( $flags = 0 ) {
1089  if ( $this->mForcedContentModel ) {
1090  if ( !$this->mContentModel ) {
1091  throw new RuntimeException( 'Got out of sync; an empty model is being forced' );
1092  }
1093  // Content model is locked to the currently loaded one
1094  return $this->mContentModel;
1095  }
1096 
1097  if ( $this->shouldReadLatest( $flags ) || !$this->mContentModel ) {
1098  $this->lazyFillContentModel( $this->getFieldFromPageStore( 'page_content_model', $flags ) );
1099  }
1100 
1101  if ( !$this->mContentModel ) {
1103  }
1104 
1105  return $this->mContentModel;
1106  }
1107 
1114  public function hasContentModel( $id ) {
1115  return $this->getContentModel() == $id;
1116  }
1117 
1134  public function setContentModel( $model ) {
1135  if ( (string)$model === '' ) {
1136  throw new InvalidArgumentException( "Missing CONTENT_MODEL_* constant" );
1137  }
1138 
1139  $this->uncache();
1140  $this->mContentModel = $model;
1141  $this->mForcedContentModel = true;
1142  }
1143 
1149  private function lazyFillContentModel( $model ) {
1150  if ( !$this->mForcedContentModel ) {
1151  $this->mContentModel = ( $model === false ) ? false : (string)$model;
1152  }
1153  }
1154 
1160  public function getNsText() {
1161  if ( $this->isExternal() ) {
1162  // This probably shouldn't even happen, except for interwiki transclusion.
1163  // If possible, use the canonical name for the foreign namespace.
1164  $nsText = MediaWikiServices::getInstance()->getNamespaceInfo()->
1165  getCanonicalName( $this->mNamespace );
1166  if ( $nsText !== false ) {
1167  return $nsText;
1168  }
1169  }
1170 
1171  try {
1172  $formatter = self::getTitleFormatter();
1173  return $formatter->getNamespaceName( $this->mNamespace, $this->mDbkeyform );
1174  } catch ( InvalidArgumentException $ex ) {
1175  wfDebug( __METHOD__ . ': ' . $ex->getMessage() );
1176  return false;
1177  }
1178  }
1179 
1185  public function getSubjectNsText() {
1186  $services = MediaWikiServices::getInstance();
1187  return $services->getContentLanguage()->
1188  getNsText( $services->getNamespaceInfo()->getSubject( $this->mNamespace ) );
1189  }
1190 
1196  public function getTalkNsText() {
1197  $services = MediaWikiServices::getInstance();
1198  return $services->getContentLanguage()->
1199  getNsText( $services->getNamespaceInfo()->getTalk( $this->mNamespace ) );
1200  }
1201 
1213  public function canHaveTalkPage() {
1214  return MediaWikiServices::getInstance()->getNamespaceInfo()->canHaveTalkPage( $this );
1215  }
1216 
1227  public function canExist(): bool {
1228  // NOTE: Don't use getArticleID(), we don't want to
1229  // trigger a database query here. This check is supposed to
1230  // act as an optimization, not add extra cost.
1231  if ( $this->mArticleID > 0 ) {
1232  // It exists, so it can exist.
1233  return true;
1234  }
1235 
1236  // NOTE: we call the relatively expensive isValid() method further down,
1237  // but we can bail out early if we already know the title is invalid.
1238  if ( $this->mIsValid === false ) {
1239  // It's invalid, so it can't exist.
1240  return false;
1241  }
1242 
1243  if ( $this->getNamespace() < NS_MAIN ) {
1244  // It's a special page, so it can't exist in the database.
1245  return false;
1246  }
1247 
1248  if ( $this->isExternal() ) {
1249  // If it's external, it's not local, so it can't exist.
1250  return false;
1251  }
1252 
1253  if ( $this->getText() === '' ) {
1254  // The title has no text, so it can't exist in the database.
1255  // It's probably an on-page section link, like "#something".
1256  return false;
1257  }
1258 
1259  // Double check that the title is valid.
1260  return $this->isValid();
1261  }
1262 
1268  public function isSpecialPage() {
1269  return $this->mNamespace === NS_SPECIAL;
1270  }
1271 
1278  public function isSpecial( $name ) {
1279  if ( $this->isSpecialPage() ) {
1280  list( $thisName, /* $subpage */ ) =
1281  MediaWikiServices::getInstance()->getSpecialPageFactory()->
1282  resolveAlias( $this->mDbkeyform );
1283  if ( $name == $thisName ) {
1284  return true;
1285  }
1286  }
1287  return false;
1288  }
1289 
1296  public function fixSpecialName() {
1297  if ( $this->isSpecialPage() ) {
1298  $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory();
1299  list( $canonicalName, $par ) = $spFactory->resolveAlias( $this->mDbkeyform );
1300  if ( $canonicalName ) {
1301  $localName = $spFactory->getLocalNameFor( $canonicalName, $par );
1302  if ( $localName != $this->mDbkeyform ) {
1303  return self::makeTitle( NS_SPECIAL, $localName );
1304  }
1305  }
1306  }
1307  return $this;
1308  }
1309 
1317  public function inNamespace( int $ns ): bool {
1318  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1319  equals( $this->mNamespace, $ns );
1320  }
1321 
1329  public function inNamespaces( ...$namespaces ) {
1330  if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) {
1331  $namespaces = $namespaces[0];
1332  }
1333 
1334  foreach ( $namespaces as $ns ) {
1335  if ( $this->inNamespace( $ns ) ) {
1336  return true;
1337  }
1338  }
1339 
1340  return false;
1341  }
1342 
1356  public function hasSubjectNamespace( $ns ) {
1357  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1358  subjectEquals( $this->mNamespace, $ns );
1359  }
1360 
1368  public function isContentPage() {
1369  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1370  isContent( $this->mNamespace );
1371  }
1372 
1379  public function isMovable() {
1380  if (
1381  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1382  isMovable( $this->mNamespace ) || $this->isExternal()
1383  ) {
1384  // Interwiki title or immovable namespace. Hooks don't get to override here
1385  return false;
1386  }
1387 
1388  $result = true;
1389  Hooks::runner()->onTitleIsMovable( $this, $result );
1390  return $result;
1391  }
1392 
1403  public function isMainPage() {
1404  return $this->equals( self::newMainPage() );
1405  }
1406 
1412  public function isSubpage() {
1413  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1414  hasSubpages( $this->mNamespace )
1415  ? strpos( $this->getText(), '/' ) !== false
1416  : false;
1417  }
1418 
1424  public function isConversionTable() {
1425  // @todo ConversionTable should become a separate content model.
1426 
1427  return $this->mNamespace === NS_MEDIAWIKI &&
1428  strpos( $this->getText(), 'Conversiontable/' ) === 0;
1429  }
1430 
1436  public function isWikitextPage() {
1437  return $this->hasContentModel( CONTENT_MODEL_WIKITEXT );
1438  }
1439 
1454  public function isSiteConfigPage() {
1455  return (
1456  $this->isSiteCssConfigPage()
1457  || $this->isSiteJsonConfigPage()
1458  || $this->isSiteJsConfigPage()
1459  );
1460  }
1461 
1468  public function isUserConfigPage() {
1469  return (
1470  $this->isUserCssConfigPage()
1471  || $this->isUserJsonConfigPage()
1472  || $this->isUserJsConfigPage()
1473  );
1474  }
1475 
1482  public function getSkinFromConfigSubpage() {
1483  $text = $this->getText();
1484  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
1485  if ( $lastSlashPos === false ) {
1486  return '';
1487  }
1488 
1489  $lastDot = strrpos( $text, '.', $lastSlashPos );
1490  if ( $lastDot === false ) {
1491  return '';
1492  }
1493 
1494  return substr( $text, $lastSlashPos + 1, $lastDot - $lastSlashPos - 1 );
1495  }
1496 
1503  public function isUserCssConfigPage() {
1504  return (
1505  $this->mNamespace === NS_USER
1506  && $this->isSubpage()
1507  && $this->hasContentModel( CONTENT_MODEL_CSS )
1508  );
1509  }
1510 
1517  public function isUserJsonConfigPage() {
1518  return (
1519  $this->mNamespace === NS_USER
1520  && $this->isSubpage()
1521  && $this->hasContentModel( CONTENT_MODEL_JSON )
1522  );
1523  }
1524 
1531  public function isUserJsConfigPage() {
1532  return (
1533  $this->mNamespace === NS_USER
1534  && $this->isSubpage()
1536  );
1537  }
1538 
1545  public function isSiteCssConfigPage() {
1546  return (
1547  $this->mNamespace === NS_MEDIAWIKI
1548  && (
1550  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1551  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1552  || substr( $this->mDbkeyform, -4 ) === '.css'
1553  )
1554  );
1555  }
1556 
1563  public function isSiteJsonConfigPage() {
1564  return (
1565  $this->mNamespace === NS_MEDIAWIKI
1566  && (
1568  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1569  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1570  || substr( $this->mDbkeyform, -5 ) === '.json'
1571  )
1572  );
1573  }
1574 
1581  public function isSiteJsConfigPage() {
1582  return (
1583  $this->mNamespace === NS_MEDIAWIKI
1584  && (
1586  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1587  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1588  || substr( $this->mDbkeyform, -3 ) === '.js'
1589  )
1590  );
1591  }
1592 
1599  public function isRawHtmlMessage() {
1600  global $wgRawHtmlMessages;
1601 
1602  if ( !$this->inNamespace( NS_MEDIAWIKI ) ) {
1603  return false;
1604  }
1605  $message = lcfirst( $this->getRootTitle()->getDBkey() );
1606  return in_array( $message, $wgRawHtmlMessages, true );
1607  }
1608 
1614  public function isTalkPage() {
1615  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1616  isTalk( $this->mNamespace );
1617  }
1618 
1630  public function getTalkPage() {
1631  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1632  // Instead of failing on invalid titles, let's just log the issue for now.
1633  // See the discussion on T227817.
1634 
1635  // Is this the same title?
1636  $talkNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $this->mNamespace );
1637  if ( $this->mNamespace == $talkNS ) {
1638  return $this;
1639  }
1640 
1641  $title = self::makeTitle( $talkNS, $this->mDbkeyform );
1642 
1643  $this->warnIfPageCannotExist( $title, __METHOD__ );
1644 
1645  return $title;
1646  // TODO: replace the above with the code below:
1647  // return self::castFromLinkTarget(
1648  // MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) );
1649  }
1650 
1660  public function getTalkPageIfDefined() {
1661  if ( !$this->canHaveTalkPage() ) {
1662  return null;
1663  }
1664 
1665  return $this->getTalkPage();
1666  }
1667 
1675  public function getSubjectPage() {
1676  // Is this the same title?
1677  $subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo()
1678  ->getSubject( $this->mNamespace );
1679  if ( $this->mNamespace == $subjectNS ) {
1680  return $this;
1681  }
1682  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1683  // Instead of failing on invalid titles, let's just log the issue for now.
1684  // See the discussion on T227817.
1685  $title = self::makeTitle( $subjectNS, $this->mDbkeyform );
1686 
1687  $this->warnIfPageCannotExist( $title, __METHOD__ );
1688 
1689  return $title;
1690  // TODO: replace the above with the code below:
1691  // return self::castFromLinkTarget(
1692  // MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
1693  }
1694 
1701  private function warnIfPageCannotExist( Title $title, $method ) {
1702  if ( $this->getText() == '' ) {
1703  wfLogWarning(
1704  $method . ': called on empty title ' . $this->getFullText() . ', returning '
1705  . $title->getFullText()
1706  );
1707 
1708  return true;
1709  }
1710 
1711  if ( $this->getInterwiki() !== '' ) {
1712  wfLogWarning(
1713  $method . ': called on interwiki title ' . $this->getFullText() . ', returning '
1714  . $title->getFullText()
1715  );
1716 
1717  return true;
1718  }
1719 
1720  return false;
1721  }
1722 
1732  public function getOtherPage() {
1733  // NOTE: Depend on the methods in this class instead of their equivalent in NamespaceInfo,
1734  // until their semantics has become exactly the same.
1735  // See the discussion on T227817.
1736  if ( $this->isSpecialPage() ) {
1737  throw new MWException( 'Special pages cannot have other pages' );
1738  }
1739  if ( $this->isTalkPage() ) {
1740  return $this->getSubjectPage();
1741  } else {
1742  if ( !$this->canHaveTalkPage() ) {
1743  throw new MWException( "{$this->getPrefixedText()} does not have an other page" );
1744  }
1745  return $this->getTalkPage();
1746  }
1747  // TODO: replace the above with the code below:
1748  // return self::castFromLinkTarget(
1749  // MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) );
1750  }
1751 
1758  public function getDefaultNamespace() {
1759  wfDeprecated( __METHOD__, '1.37' );
1760  return $this->mDefaultNamespace;
1761  }
1762 
1770  public function getFragment(): string {
1771  return $this->mFragment;
1772  }
1773 
1780  public function hasFragment(): bool {
1781  return $this->mFragment !== '';
1782  }
1783 
1789  public function getFragmentForURL() {
1790  if ( !$this->hasFragment() ) {
1791  return '';
1792  } elseif ( $this->isExternal() ) {
1793  // Note: If the interwiki is unknown, it's treated as a namespace on the local wiki,
1794  // so we treat it like a local interwiki.
1795  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
1796  if ( $interwiki && !$interwiki->isLocal() ) {
1797  return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment );
1798  }
1799  }
1800 
1801  return '#' . Sanitizer::escapeIdForLink( $this->mFragment );
1802  }
1803 
1814  public function setFragment( $fragment ) {
1815  $this->uncache();
1816  $this->mFragment = self::normalizeFragment( $fragment );
1817  }
1818 
1826  public function createFragmentTarget( string $fragment ): self {
1827  return self::makeTitle(
1828  $this->mNamespace,
1829  $this->getText(),
1830  $fragment,
1831  $this->mInterwiki
1832  );
1833  }
1834 
1841  private static function normalizeFragment( $fragment ) {
1842  if ( strpos( $fragment, '#' ) === 0 ) {
1843  $fragment = substr( $fragment, 1 );
1844  }
1845  return strtr( $fragment, '_', ' ' );
1846  }
1847 
1855  private function prefix( $name ) {
1856  $p = '';
1857  if ( $this->isExternal() ) {
1858  $p = $this->mInterwiki . ':';
1859  }
1860 
1861  if ( $this->mNamespace != 0 ) {
1862  $nsText = $this->getNsText();
1863 
1864  if ( $nsText === false ) {
1865  // See T165149. Awkward, but better than erroneously linking to the main namespace.
1866  $nsText = MediaWikiServices::getInstance()->getContentLanguage()->
1867  getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
1868  }
1869 
1870  $p .= $nsText . ':';
1871  }
1872  return $p . $name;
1873  }
1874 
1881  public function getPrefixedDBkey() {
1882  $s = $this->prefix( $this->mDbkeyform );
1883  $s = strtr( $s, ' ', '_' );
1884  return $s;
1885  }
1886 
1893  public function getPrefixedText() {
1894  if ( $this->prefixedText === null ) {
1895  $s = $this->prefix( $this->mTextform );
1896  $s = strtr( $s, '_', ' ' );
1897  $this->prefixedText = $s;
1898  }
1899  return $this->prefixedText;
1900  }
1901 
1907  public function __toString(): string {
1908  return $this->getPrefixedText();
1909  }
1910 
1917  public function getFullText() {
1918  $text = $this->getPrefixedText();
1919  if ( $this->hasFragment() ) {
1920  $text .= '#' . $this->mFragment;
1921  }
1922  return $text;
1923  }
1924 
1939  private function findSubpageDivider( $text, $dir ) {
1940  if ( $dir > 0 ) {
1941  // Skip leading slashes, but keep the last one when there is nothing but slashes
1942  $bottom = strspn( $text, '/', 0, -1 );
1943  $idx = strpos( $text, '/', $bottom );
1944  } else {
1945  // Any slash from the end can be a divider, as subpage names can be empty
1946  $idx = strrpos( $text, '/' );
1947  }
1948 
1949  // The first character can never be a divider, as that would result in an empty base
1950  return $idx === 0 ? false : $idx;
1951  }
1952 
1957  private function hasSubpagesEnabled() {
1958  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1959  hasSubpages( $this->mNamespace );
1960  }
1961 
1977  public function getRootText() {
1978  $text = $this->getText();
1979  if ( !$this->hasSubpagesEnabled() ) {
1980  return $text;
1981  }
1982 
1983  $firstSlashPos = $this->findSubpageDivider( $text, +1 );
1984  // Don't discard the real title if there's no subpage involved
1985  if ( $firstSlashPos === false ) {
1986  return $text;
1987  }
1988 
1989  return substr( $text, 0, $firstSlashPos );
1990  }
1991 
2004  public function getRootTitle() {
2005  $title = self::makeTitleSafe( $this->mNamespace, $this->getRootText() );
2006  Assert::postcondition(
2007  $title !== null,
2008  'makeTitleSafe() should always return a Title for the text returned by getRootText().'
2009  );
2010  return $title;
2011  }
2012 
2027  public function getBaseText() {
2028  $text = $this->getText();
2029  if ( !$this->hasSubpagesEnabled() ) {
2030  return $text;
2031  }
2032 
2033  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
2034  // Don't discard the real title if there's no subpage involved
2035  if ( $lastSlashPos === false ) {
2036  return $text;
2037  }
2038 
2039  return substr( $text, 0, $lastSlashPos );
2040  }
2041 
2054  public function getBaseTitle() {
2055  $title = self::makeTitleSafe( $this->mNamespace, $this->getBaseText() );
2056  Assert::postcondition(
2057  $title !== null,
2058  'makeTitleSafe() should always return a Title for the text returned by getBaseText().'
2059  );
2060  return $title;
2061  }
2062 
2074  public function getSubpageText() {
2075  $text = $this->getText();
2076  if ( !$this->hasSubpagesEnabled() ) {
2077  return $text;
2078  }
2079 
2080  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
2081  if ( $lastSlashPos === false ) {
2082  // T256922 - Return the title text if no subpages
2083  return $text;
2084  }
2085  return substr( $text, $lastSlashPos + 1 );
2086  }
2087 
2101  public function getSubpage( $text ) {
2102  return self::makeTitleSafe(
2103  $this->mNamespace,
2104  $this->getText() . '/' . $text,
2105  '',
2106  $this->mInterwiki
2107  );
2108  }
2109 
2115  public function getSubpageUrlForm() {
2116  $text = $this->getSubpageText();
2117  $text = wfUrlencode( strtr( $text, ' ', '_' ) );
2118  return $text;
2119  }
2120 
2126  public function getPrefixedURL() {
2127  $s = $this->prefix( $this->mDbkeyform );
2128  $s = wfUrlencode( strtr( $s, ' ', '_' ) );
2129  return $s;
2130  }
2131 
2145  private static function fixUrlQueryArgs( $query, $query2 = false ) {
2146  if ( $query2 !== false ) {
2147  wfDeprecatedMsg( "Title::get{Canonical,Full,Link,Local,Internal}URL " .
2148  "method called with a second parameter is deprecated since MediaWiki 1.19. " .
2149  "Add your parameter to an array passed as the first parameter.", "1.19" );
2150  }
2151  if ( is_array( $query ) ) {
2152  $query = wfArrayToCgi( $query );
2153  }
2154  if ( $query2 ) {
2155  if ( is_string( $query2 ) ) {
2156  // $query2 is a string, we will consider this to be
2157  // a deprecated $variant argument and add it to the query
2158  $query2 = wfArrayToCgi( [ 'variant' => $query2 ] );
2159  } else {
2160  $query2 = wfArrayToCgi( $query2 );
2161  }
2162  // If we have $query content add a & to it first
2163  if ( $query ) {
2164  $query .= '&';
2165  }
2166  // Now append the queries together
2167  $query .= $query2;
2168  }
2169  return $query;
2170  }
2171 
2183  public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
2184  $query = self::fixUrlQueryArgs( $query, $query2 );
2185 
2186  # Hand off all the decisions on urls to getLocalURL
2187  $url = $this->getLocalURL( $query );
2188 
2189  # Expand the url to make it a full url. Note that getLocalURL has the
2190  # potential to output full urls for a variety of reasons, so we use
2191  # wfExpandUrl instead of simply prepending $wgServer
2192  $url = wfExpandUrl( $url, $proto );
2193 
2194  # Finally, add the fragment.
2195  $url .= $this->getFragmentForURL();
2196  Hooks::runner()->onGetFullURL( $this, $url, $query );
2197  return $url;
2198  }
2199 
2216  public function getFullUrlForRedirect( $query = '', $proto = PROTO_CURRENT ) {
2217  $target = $this;
2218  if ( $this->isExternal() ) {
2219  $target = SpecialPage::getTitleFor(
2220  'GoToInterwiki',
2221  $this->getPrefixedDBkey()
2222  );
2223  }
2224  return $target->getFullURL( $query, false, $proto );
2225  }
2226 
2250  public function getLocalURL( $query = '', $query2 = false ) {
2252 
2253  $query = self::fixUrlQueryArgs( $query, $query2 );
2254 
2255  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
2256  if ( $interwiki ) {
2257  $namespace = $this->getNsText();
2258  if ( $namespace != '' ) {
2259  # Can this actually happen? Interwikis shouldn't be parsed.
2260  # Yes! It can in interwiki transclusion. But... it probably shouldn't.
2261  $namespace .= ':';
2262  }
2263  $url = $interwiki->getURL( $namespace . $this->mDbkeyform );
2264  $url = wfAppendQuery( $url, $query );
2265  } else {
2266  $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
2267  if ( $query == '' ) {
2268  if ( $wgMainPageIsDomainRoot && $this->isMainPage() ) {
2269  $url = '/';
2270  } else {
2271  $url = str_replace( '$1', $dbkey, $wgArticlePath );
2272  }
2273  Hooks::runner()->onGetLocalURL__Article( $this, $url );
2274  } else {
2276  $url = false;
2277  $matches = [];
2278 
2280 
2281  if ( $articlePaths
2282  && preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
2283  ) {
2284  $action = urldecode( $matches[2] );
2285  if ( isset( $articlePaths[$action] ) ) {
2286  $query = $matches[1];
2287  if ( isset( $matches[4] ) ) {
2288  $query .= $matches[4];
2289  }
2290  $url = str_replace( '$1', $dbkey, $articlePaths[$action] );
2291  if ( $query != '' ) {
2292  $url = wfAppendQuery( $url, $query );
2293  }
2294  }
2295  }
2296 
2297  if ( $url === false
2299  && preg_match( '/^variant=([^&]*)$/', $query, $matches )
2300  && $this->getPageLanguage()->equals(
2301  MediaWikiServices::getInstance()->getContentLanguage() )
2302  && $this->getPageLanguageConverter()->hasVariants()
2303  ) {
2304  $variant = urldecode( $matches[1] );
2305  if ( $this->getPageLanguageConverter()->hasVariant( $variant ) ) {
2306  // Only do the variant replacement if the given variant is a valid
2307  // variant for the page's language.
2308  $url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath );
2309  $url = str_replace( '$1', $dbkey, $url );
2310  }
2311  }
2312 
2313  if ( $url === false ) {
2314  if ( $query == '-' ) {
2315  $query = '';
2316  }
2317  $url = "{$wgScript}?title={$dbkey}&{$query}";
2318  }
2319  }
2320  Hooks::runner()->onGetLocalURL__Internal( $this, $url, $query );
2321  }
2322 
2323  Hooks::runner()->onGetLocalURL( $this, $url, $query );
2324  return $url;
2325  }
2326 
2344  public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
2345  if ( $this->isExternal() || $proto !== false ) {
2346  $ret = $this->getFullURL( $query, $query2, $proto );
2347  } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
2348  $ret = $this->getFragmentForURL();
2349  } else {
2350  $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
2351  }
2352  return $ret;
2353  }
2354 
2369  public function getInternalURL( $query = '', $query2 = false ) {
2370  global $wgInternalServer, $wgServer;
2371  $query = self::fixUrlQueryArgs( $query, $query2 );
2372  $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
2373  $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP );
2374  Hooks::runner()->onGetInternalURL( $this, $url, $query );
2375  return $url;
2376  }
2377 
2391  public function getCanonicalURL( $query = '', $query2 = false ) {
2392  $query = self::fixUrlQueryArgs( $query, $query2 );
2393  $url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL );
2394  Hooks::runner()->onGetCanonicalURL( $this, $url, $query );
2395  return $url;
2396  }
2397 
2403  public function getEditURL() {
2404  if ( $this->isExternal() ) {
2405  return '';
2406  }
2407  $s = $this->getLocalURL( 'action=edit' );
2408 
2409  return $s;
2410  }
2411 
2422  public static function getFilteredRestrictionTypes( $exists = true ) {
2423  return MediaWikiServices::getInstance()
2424  ->getRestrictionStore()
2425  ->listAllRestrictionTypes( $exists );
2426  }
2427 
2435  public function getRestrictionTypes() {
2436  return MediaWikiServices::getInstance()
2437  ->getRestrictionStore()
2438  ->listApplicableRestrictionTypes( $this );
2439  }
2440 
2450  public function getTitleProtection() {
2451  return MediaWikiServices::getInstance()->getRestrictionStore()->getCreateProtection( $this )
2452  ?: false;
2453  }
2454 
2460  public function deleteTitleProtection() {
2461  MediaWikiServices::getInstance()->getRestrictionStore()->deleteCreateProtection( $this );
2462  }
2463 
2473  public function isSemiProtected( $action = 'edit' ) {
2474  return MediaWikiServices::getInstance()->getRestrictionStore()->isSemiProtected(
2475  $this, $action
2476  );
2477  }
2478 
2488  public function isProtected( $action = '' ) {
2489  return MediaWikiServices::getInstance()->getRestrictionStore()->isProtected(
2490  $this, $action
2491  );
2492  }
2493 
2502  public function isNamespaceProtected( User $user ) {
2503  global $wgNamespaceProtection;
2504 
2505  wfDeprecated( __METHOD__, '1.34' );
2506 
2507  if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
2508  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2509  foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
2510  if ( !$permissionManager->userHasRight( $user, $right ) ) {
2511  return true;
2512  }
2513  }
2514  }
2515  return false;
2516  }
2517 
2525  public function isCascadeProtected() {
2526  return MediaWikiServices::getInstance()->getRestrictionStore()->isCascadeProtected( $this );
2527  }
2528 
2539  return MediaWikiServices::getInstance()->getRestrictionStore()
2540  ->areCascadeProtectionSourcesLoaded( $this );
2541  }
2542 
2558  public function getCascadeProtectionSources( $getPages = true ) {
2559  $restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
2560  if ( !$getPages ) {
2561  return [ $restrictionStore->isCascadeProtected( $this ), [] ];
2562  }
2563 
2564  $ret = $restrictionStore->getCascadeProtectionSources( $this );
2565  $ret[0] = array_map( 'Title::castFromPageIdentity', $ret[0] );
2566  return $ret;
2567  }
2568 
2578  public function areRestrictionsLoaded() {
2579  return MediaWikiServices::getInstance()
2580  ->getRestrictionStore()
2581  ->areRestrictionsLoaded( $this );
2582  }
2583 
2595  public function getRestrictions( $action ) {
2596  return MediaWikiServices::getInstance()->getRestrictionStore()->getRestrictions( $this, $action );
2597  }
2598 
2608  public function getAllRestrictions() {
2609  return MediaWikiServices::getInstance()->getRestrictionStore()->getAllRestrictions( $this );
2610  }
2611 
2621  public function getRestrictionExpiry( $action ) {
2622  return MediaWikiServices::getInstance()->getRestrictionStore()->getRestrictionExpiry(
2623  $this, $action
2624  ) ?? false;
2625  }
2626 
2634  public function areRestrictionsCascading() {
2635  return MediaWikiServices::getInstance()
2636  ->getRestrictionStore()
2637  ->areRestrictionsCascading( $this );
2638  }
2639 
2653  public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
2654  MediaWikiServices::getInstance()->getRestrictionStore()->loadRestrictionsFromRows(
2655  $this, $rows, $oldFashionedRestrictions
2656  );
2657  }
2658 
2671  public function loadRestrictions( $oldFashionedRestrictions = null, $flags = 0 ) {
2672  MediaWikiServices::getInstance()->getRestrictionStore()->loadRestrictions( $this, $flags,
2673  $oldFashionedRestrictions );
2674  }
2675 
2682  public function flushRestrictions() {
2683  MediaWikiServices::getInstance()->getRestrictionStore()->flushRestrictions( $this );
2684  }
2685 
2691  public static function purgeExpiredRestrictions() {
2692  if ( wfReadOnly() ) {
2693  return;
2694  }
2695 
2697  wfGetDB( DB_PRIMARY ),
2698  __METHOD__,
2699  static function ( IDatabase $dbw, $fname ) {
2700  $config = MediaWikiServices::getInstance()->getMainConfig();
2701  $ids = $dbw->selectFieldValues(
2702  'page_restrictions',
2703  'pr_id',
2704  [ 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
2705  $fname,
2706  [ 'LIMIT' => $config->get( 'UpdateRowsPerQuery' ) ] // T135470
2707  );
2708  if ( $ids ) {
2709  $dbw->delete( 'page_restrictions', [ 'pr_id' => $ids ], $fname );
2710  }
2711  }
2712  ) );
2713 
2715  wfGetDB( DB_PRIMARY ),
2716  __METHOD__,
2717  static function ( IDatabase $dbw, $fname ) {
2718  $dbw->delete(
2719  'protected_titles',
2720  [ 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
2721  $fname
2722  );
2723  }
2724  ) );
2725  }
2726 
2732  public function hasSubpages() {
2733  if (
2734  !MediaWikiServices::getInstance()->getNamespaceInfo()->
2735  hasSubpages( $this->mNamespace )
2736  ) {
2737  # Duh
2738  return false;
2739  }
2740 
2741  # We dynamically add a member variable for the purpose of this method
2742  # alone to cache the result. There's no point in having it hanging
2743  # around uninitialized in every Title object; therefore we only add it
2744  # if needed and don't declare it statically.
2745  if ( $this->mHasSubpages === null ) {
2746  $subpages = $this->getSubpages( 1 );
2747  $this->mHasSubpages = $subpages instanceof TitleArray && $subpages->count();
2748  }
2749 
2750  return $this->mHasSubpages;
2751  }
2752 
2760  public function getSubpages( $limit = -1 ) {
2761  if (
2762  !MediaWikiServices::getInstance()->getNamespaceInfo()->
2763  hasSubpages( $this->mNamespace )
2764  ) {
2765  return [];
2766  }
2767 
2768  $options = [];
2769  if ( $limit > -1 ) {
2770  $options['LIMIT'] = $limit;
2771  }
2772 
2773  $pageStore = MediaWikiServices::getInstance()->getPageStore();
2774  $query = $pageStore->newSelectQueryBuilder()
2775  ->fields( $pageStore->getSelectFields() )
2776  ->whereTitlePrefix( $this->getNamespace(), $this->getDBkey() . '/' )
2777  ->options( $options )
2778  ->caller( __METHOD__ );
2779 
2780  return TitleArray::newFromResult( $query->fetchResultSet() );
2781  }
2782 
2789  public function isDeleted() {
2790  return $this->getDeletedEditsCount();
2791  }
2792 
2799  public function getDeletedEditsCount() {
2800  if ( $this->mNamespace < 0 ) {
2801  $n = 0;
2802  } else {
2803  $dbr = wfGetDB( DB_REPLICA );
2804 
2805  $n = $dbr->selectField( 'archive', 'COUNT(*)',
2806  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
2807  __METHOD__
2808  );
2809  if ( $this->mNamespace === NS_FILE ) {
2810  $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
2811  [ 'fa_name' => $this->mDbkeyform ],
2812  __METHOD__
2813  );
2814  }
2815  }
2816  return (int)$n;
2817  }
2818 
2825  public function isDeletedQuick() {
2826  return $this->hasDeletedEdits();
2827  }
2828 
2835  public function hasDeletedEdits() {
2836  if ( $this->mNamespace < 0 ) {
2837  return false;
2838  }
2839  $dbr = wfGetDB( DB_REPLICA );
2840  $deleted = (bool)$dbr->selectField( 'archive', '1',
2841  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
2842  __METHOD__
2843  );
2844  if ( !$deleted && $this->mNamespace === NS_FILE ) {
2845  $deleted = (bool)$dbr->selectField( 'filearchive', '1',
2846  [ 'fa_name' => $this->mDbkeyform ],
2847  __METHOD__
2848  );
2849  }
2850  return $deleted;
2851  }
2852 
2860  public function getArticleID( $flags = 0 ) {
2861  if ( $this->mArticleID === -1 && !$this->canExist() ) {
2862  $this->mArticleID = 0;
2863 
2864  return $this->mArticleID;
2865  }
2866 
2867  if ( $this->mArticleID === -1 || $this->shouldReadLatest( $flags ) ) {
2868  $this->mArticleID = (int)$this->getFieldFromPageStore( 'page_id', $flags );
2869  }
2870 
2871  return $this->mArticleID;
2872  }
2873 
2888  public function isRedirect( $flags = 0 ) {
2889  if ( $this->shouldReadLatest( $flags ) || $this->mRedirect === null ) {
2890  $this->mRedirect = (bool)$this->getFieldFromPageStore( 'page_is_redirect', $flags );
2891  }
2892 
2893  return $this->mRedirect;
2894  }
2895 
2903  public function getLength( $flags = 0 ) {
2904  if ( $this->shouldReadLatest( $flags ) || $this->mLength < 0 ) {
2905  $this->mLength = (int)$this->getFieldFromPageStore( 'page_len', $flags );
2906  }
2907 
2908  if ( $this->mLength < 0 ) {
2909  $this->mLength = 0;
2910  }
2911 
2912  return $this->mLength;
2913  }
2914 
2921  public function getLatestRevID( $flags = 0 ) {
2922  if ( $this->shouldReadLatest( $flags ) || $this->mLatestID === false ) {
2923  $this->mLatestID = (int)$this->getFieldFromPageStore( 'page_latest', $flags );
2924  }
2925 
2926  if ( !$this->mLatestID ) {
2927  $this->mLatestID = 0;
2928  }
2929 
2930  return $this->mLatestID;
2931  }
2932 
2946  public function resetArticleID( $id ) {
2947  if ( $id === false ) {
2948  $this->mArticleID = -1;
2949  } else {
2950  $this->mArticleID = (int)$id;
2951  }
2952  $this->mRedirect = null;
2953  $this->mLength = -1;
2954  $this->mLatestID = false;
2955  $this->mContentModel = false;
2956  $this->mForcedContentModel = false;
2957  $this->mEstimateRevisions = null;
2958  $this->mPageLanguage = null;
2959  $this->mDbPageLanguage = false;
2960  $this->mIsBigDeletion = null;
2961 
2962  MediaWikiServices::getInstance()->getLinkCache()->clearLink( $this );
2963  MediaWikiServices::getInstance()->getRestrictionStore()->flushRestrictions( $this );
2964  }
2965 
2966  public static function clearCaches() {
2967  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2968  $linkCache->clear();
2969 
2971  $titleCache->clear();
2972  }
2973 
2981  public static function capitalize( $text, $ns = NS_MAIN ) {
2982  $services = MediaWikiServices::getInstance();
2983  if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) {
2984  return $services->getContentLanguage()->ucfirst( $text );
2985  } else {
2986  return $text;
2987  }
2988  }
2989 
3006  private function secureAndSplit( $text, $defaultNamespace = null ) {
3007  if ( $defaultNamespace === null ) {
3008  $defaultNamespace = $this->mDefaultNamespace;
3009  }
3010 
3011  // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
3012  // the parsing code with Title, while avoiding massive refactoring.
3013  // @todo: get rid of secureAndSplit, refactor parsing code.
3014  // @note: getTitleParser() returns a TitleParser implementation which does not have a
3015  // splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
3017  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
3018  '@phan-var MediaWikiTitleCodec $titleCodec';
3019  // MalformedTitleException can be thrown here
3020  $parts = $titleCodec->splitTitleString( $text, $defaultNamespace );
3021 
3022  # Fill fields
3023  $this->setFragment( '#' . $parts['fragment'] );
3024  $this->mInterwiki = $parts['interwiki'];
3025  $this->mLocalInterwiki = $parts['local_interwiki'];
3026  $this->mNamespace = $parts['namespace'];
3027  $this->mDefaultNamespace = $defaultNamespace;
3028 
3029  $this->mDbkeyform = $parts['dbkey'];
3030  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
3031  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
3032 
3033  // splitTitleString() guarantees that this title is valid.
3034  $this->mIsValid = true;
3035 
3036  # We already know that some pages won't be in the database!
3037  if ( $this->isExternal() || $this->isSpecialPage() || $this->mTextform === '' ) {
3038  $this->mArticleID = 0;
3039  }
3040  }
3041 
3054  public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3055  if ( count( $options ) > 0 ) {
3056  $db = wfGetDB( DB_PRIMARY );
3057  } else {
3058  $db = wfGetDB( DB_REPLICA );
3059  }
3060 
3061  $res = $db->select(
3062  [ 'page', $table ],
3064  [
3065  "{$prefix}_from=page_id",
3066  "{$prefix}_namespace" => $this->mNamespace,
3067  "{$prefix}_title" => $this->mDbkeyform ],
3068  __METHOD__,
3069  $options
3070  );
3071 
3072  $retVal = [];
3073  if ( $res->numRows() ) {
3074  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3075  foreach ( $res as $row ) {
3076  $titleObj = self::makeTitle( $row->page_namespace, $row->page_title );
3077  if ( $titleObj ) {
3078  $linkCache->addGoodLinkObjFromRow( $titleObj, $row );
3079  $retVal[] = $titleObj;
3080  }
3081  }
3082  }
3083  return $retVal;
3084  }
3085 
3096  public function getTemplateLinksTo( $options = [] ) {
3097  return $this->getLinksTo( $options, 'templatelinks', 'tl' );
3098  }
3099 
3112  public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3113  $id = $this->getArticleID();
3114 
3115  # If the page doesn't exist; there can't be any link from this page
3116  if ( !$id ) {
3117  return [];
3118  }
3119 
3120  $db = wfGetDB( DB_REPLICA );
3121 
3122  $blNamespace = "{$prefix}_namespace";
3123  $blTitle = "{$prefix}_title";
3124 
3125  $pageQuery = WikiPage::getQueryInfo();
3126  $res = $db->select(
3127  [ $table, 'nestpage' => $pageQuery['tables'] ],
3128  array_merge(
3129  [ $blNamespace, $blTitle ],
3130  $pageQuery['fields']
3131  ),
3132  [ "{$prefix}_from" => $id ],
3133  __METHOD__,
3134  $options,
3135  [ 'nestpage' => [
3136  'LEFT JOIN',
3137  [ "page_namespace=$blNamespace", "page_title=$blTitle" ]
3138  ] ] + $pageQuery['joins']
3139  );
3140 
3141  $retVal = [];
3142  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3143  foreach ( $res as $row ) {
3144  if ( $row->page_id ) {
3145  $titleObj = self::newFromRow( $row );
3146  } else {
3147  $titleObj = self::makeTitle( $row->$blNamespace, $row->$blTitle );
3148  $linkCache->addBadLinkObj( $titleObj );
3149  }
3150  $retVal[] = $titleObj;
3151  }
3152 
3153  return $retVal;
3154  }
3155 
3166  public function getTemplateLinksFrom( $options = [] ) {
3167  return $this->getLinksFrom( $options, 'templatelinks', 'tl' );
3168  }
3169 
3178  public function getBrokenLinksFrom() {
3179  if ( $this->getArticleID() == 0 ) {
3180  # All links from article ID 0 are false positives
3181  return [];
3182  }
3183 
3184  $dbr = wfGetDB( DB_REPLICA );
3185  $res = $dbr->select(
3186  [ 'page', 'pagelinks' ],
3187  [ 'pl_namespace', 'pl_title' ],
3188  [
3189  'pl_from' => $this->getArticleID(),
3190  'page_namespace IS NULL'
3191  ],
3192  __METHOD__, [],
3193  [
3194  'page' => [
3195  'LEFT JOIN',
3196  [ 'pl_namespace=page_namespace', 'pl_title=page_title' ]
3197  ]
3198  ]
3199  );
3200 
3201  $retVal = [];
3202  foreach ( $res as $row ) {
3203  $retVal[] = self::makeTitle( $row->pl_namespace, $row->pl_title );
3204  }
3205  return $retVal;
3206  }
3207 
3214  public function getCdnUrls() {
3215  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3216  return $htmlCache->getUrls( $this );
3217  }
3218 
3223  public function purgeSquid() {
3224  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3225  $htmlCache->purgeTitleUrls( $this, $htmlCache::PURGE_INTENT_TXROUND_REFLECTED );
3226  }
3227 
3235  public function isSingleRevRedirect() {
3236  $dbw = wfGetDB( DB_PRIMARY );
3237  $dbw->startAtomic( __METHOD__ );
3238 
3239  $row = $dbw->selectRow(
3240  'page',
3241  self::getSelectFields(),
3242  $this->pageCond(),
3243  __METHOD__,
3244  [ 'FOR UPDATE' ]
3245  );
3246  // Update the cached fields
3247  $this->loadFromRow( $row );
3248 
3249  if ( $this->mRedirect && $this->mLatestID ) {
3250  $isSingleRevRedirect = !$dbw->selectField(
3251  'revision',
3252  '1',
3253  [ 'rev_page' => $this->mArticleID, 'rev_id != ' . (int)$this->mLatestID ],
3254  __METHOD__,
3255  [ 'FOR UPDATE' ]
3256  );
3257  } else {
3258  $isSingleRevRedirect = false;
3259  }
3260 
3261  $dbw->endAtomic( __METHOD__ );
3262 
3263  return $isSingleRevRedirect;
3264  }
3265 
3273  public function getParentCategories() {
3274  $data = [];
3275 
3276  $titleKey = $this->getArticleID();
3277 
3278  if ( $titleKey === 0 ) {
3279  return $data;
3280  }
3281 
3282  $dbr = wfGetDB( DB_REPLICA );
3283 
3284  $res = $dbr->select(
3285  'categorylinks',
3286  'cl_to',
3287  [ 'cl_from' => $titleKey ],
3288  __METHOD__
3289  );
3290 
3291  if ( $res->numRows() > 0 ) {
3292  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
3293  foreach ( $res as $row ) {
3294  // $data[] = Title::newFromText( $contLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
3295  $data[$contLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] =
3296  $this->getFullText();
3297  }
3298  }
3299  return $data;
3300  }
3301 
3308  public function getParentCategoryTree( $children = [] ) {
3309  $stack = [];
3310  $parents = $this->getParentCategories();
3311 
3312  if ( $parents ) {
3313  foreach ( $parents as $parent => $current ) {
3314  if ( array_key_exists( $parent, $children ) ) {
3315  # Circular reference
3316  $stack[$parent] = [];
3317  } else {
3318  $nt = self::newFromText( $parent );
3319  if ( $nt ) {
3320  $stack[$parent] = $nt->getParentCategoryTree( $children + [ $parent => 1 ] );
3321  }
3322  }
3323  }
3324  }
3325 
3326  return $stack;
3327  }
3328 
3335  public function pageCond() {
3336  if ( $this->mArticleID > 0 ) {
3337  // PK avoids secondary lookups in InnoDB, shouldn't hurt other DBs
3338  return [ 'page_id' => $this->mArticleID ];
3339  } else {
3340  return [ 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform ];
3341  }
3342  }
3343 
3352  public function isNewPage( $flags = self::READ_NORMAL ) {
3353  // NOTE: we rely on PHP casting "0" to false here.
3354  return (bool)$this->getFieldFromPageStore( 'page_is_new', $flags );
3355  }
3356 
3363  public function isBigDeletion() {
3364  global $wgDeleteRevisionsLimit;
3365 
3366  if ( !$wgDeleteRevisionsLimit ) {
3367  return false;
3368  }
3369 
3370  if ( $this->mIsBigDeletion === null ) {
3371  $dbr = wfGetDB( DB_REPLICA );
3372 
3373  $revCount = $dbr->selectRowCount(
3374  'revision',
3375  '1',
3376  [ 'rev_page' => $this->getArticleID() ],
3377  __METHOD__,
3378  [ 'LIMIT' => $wgDeleteRevisionsLimit + 1 ]
3379  );
3380 
3381  $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit;
3382  }
3383 
3384  return $this->mIsBigDeletion;
3385  }
3386 
3392  public function estimateRevisionCount() {
3393  if ( !$this->exists() ) {
3394  return 0;
3395  }
3396 
3397  if ( $this->mEstimateRevisions === null ) {
3398  $dbr = wfGetDB( DB_REPLICA );
3399  $this->mEstimateRevisions = $dbr->estimateRowCount( 'revision', '*',
3400  [ 'rev_page' => $this->getArticleID() ], __METHOD__ );
3401  }
3402 
3404  }
3405 
3420  public function equals( object $other ) {
3421  if ( $other instanceof Title ) {
3422  // NOTE: In contrast to isSameLinkAs(), this ignores the fragment part!
3423  // NOTE: In contrast to isSamePageAs(), this ignores the page ID!
3424  // NOTE: === is necessary for proper matching of number-like titles
3425  return $this->getInterwiki() === $other->getInterwiki()
3426  && $this->getNamespace() === $other->getNamespace()
3427  && $this->getDBkey() === $other->getDBkey();
3428  } else {
3429  return false;
3430  }
3431  }
3432 
3440  public function isSameLinkAs( LinkTarget $other ): bool {
3441  // NOTE: keep in sync with TitleValue::isSameLinkAs()!
3442  // NOTE: === is needed for number-like titles
3443  return ( $other->getInterwiki() === $this->getInterwiki() )
3444  && ( $other->getDBkey() === $this->getDBkey() )
3445  && ( $other->getNamespace() === $this->getNamespace() )
3446  && ( $other->getFragment() === $this->getFragment() );
3447  }
3448 
3456  public function isSamePageAs( PageReference $other ): bool {
3457  // NOTE: keep in sync with PageIdentityValue::isSamePageAs()!
3458 
3459  if ( $other->getWikiId() !== $this->getWikiId() ) {
3460  return false;
3461  }
3462 
3463  if ( $other->getNamespace() !== $this->getNamespace()
3464  || $other->getDBkey() !== $this->getDBkey() ) {
3465  return false;
3466  }
3467 
3468  return true;
3469  }
3470 
3477  public function isSubpageOf( Title $title ) {
3478  return $this->mInterwiki === $title->mInterwiki
3479  && $this->mNamespace == $title->mNamespace
3480  && strpos( $this->mDbkeyform, $title->mDbkeyform . '/' ) === 0;
3481  }
3482 
3493  public function exists( $flags = 0 ): bool {
3494  $exists = $this->getArticleID( $flags ) != 0;
3495  Hooks::runner()->onTitleExists( $this, $exists );
3496  return $exists;
3497  }
3498 
3515  public function isAlwaysKnown() {
3516  $isKnown = null;
3517 
3528  Hooks::runner()->onTitleIsAlwaysKnown( $this, $isKnown );
3529 
3530  if ( $isKnown !== null ) {
3531  return $isKnown;
3532  }
3533 
3534  if ( $this->isExternal() ) {
3535  return true; // any interwiki link might be viewable, for all we know
3536  }
3537 
3538  $services = MediaWikiServices::getInstance();
3539  switch ( $this->mNamespace ) {
3540  case NS_MEDIA:
3541  case NS_FILE:
3542  // file exists, possibly in a foreign repo
3543  return (bool)$services->getRepoGroup()->findFile( $this );
3544  case NS_SPECIAL:
3545  // valid special page
3546  return $services->getSpecialPageFactory()->exists( $this->mDbkeyform );
3547  case NS_MAIN:
3548  // selflink, possibly with fragment
3549  return $this->mDbkeyform == '';
3550  case NS_MEDIAWIKI:
3551  // known system message
3552  return $this->hasSourceText() !== false;
3553  default:
3554  return false;
3555  }
3556  }
3557 
3569  public function isKnown() {
3570  return $this->isAlwaysKnown() || $this->exists();
3571  }
3572 
3578  public function hasSourceText() {
3579  if ( $this->exists() ) {
3580  return true;
3581  }
3582 
3583  if ( $this->mNamespace === NS_MEDIAWIKI ) {
3584  $services = MediaWikiServices::getInstance();
3585  // If the page doesn't exist but is a known system message, default
3586  // message content will be displayed, same for language subpages-
3587  // Use always content language to avoid loading hundreds of languages
3588  // to get the link color.
3589  $contLang = $services->getContentLanguage();
3590  list( $name, ) = $services->getMessageCache()->figureMessage(
3591  $contLang->lcfirst( $this->getText() )
3592  );
3593  $message = wfMessage( $name )->inLanguage( $contLang )->useDatabase( false );
3594  return $message->exists();
3595  }
3596 
3597  return false;
3598  }
3599 
3637  public function getDefaultMessageText() {
3638  if ( $this->mNamespace !== NS_MEDIAWIKI ) { // Just in case
3639  return false;
3640  }
3641 
3642  list( $name, $lang ) = MediaWikiServices::getInstance()->getMessageCache()->figureMessage(
3643  MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $this->getText() )
3644  );
3645  $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
3646 
3647  if ( $message->exists() ) {
3648  return $message->plain();
3649  } else {
3650  return false;
3651  }
3652  }
3653 
3660  public function invalidateCache( $purgeTime = null ) {
3661  if ( wfReadOnly() ) {
3662  return false;
3663  }
3664  if ( $this->mArticleID === 0 ) {
3665  // avoid gap locking if we know it's not there
3666  return true;
3667  }
3668 
3669  $conds = $this->pageCond();
3671  new AutoCommitUpdate(
3672  wfGetDB( DB_PRIMARY ),
3673  __METHOD__,
3674  function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) {
3675  $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
3676  $dbw->update(
3677  'page',
3678  [ 'page_touched' => $dbTimestamp ],
3679  $conds + [ 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ],
3680  $fname
3681  );
3682 
3683  MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $this );
3684 
3686  $this, null, null, $dbw->getDomainID() );
3687  }
3688  ),
3689  DeferredUpdates::PRESEND
3690  );
3691 
3692  return true;
3693  }
3694 
3700  public function touchLinks() {
3701  $jobs = [];
3703  $this,
3704  'pagelinks',
3705  [ 'causeAction' => 'page-touch' ]
3706  );
3707  if ( $this->mNamespace === NS_CATEGORY ) {
3709  $this,
3710  'categorylinks',
3711  [ 'causeAction' => 'category-touch' ]
3712  );
3713  }
3714 
3715  JobQueueGroup::singleton()->lazyPush( $jobs );
3716  }
3717 
3727  public function getTouched( $flags = self::READ_NORMAL ) {
3728  if ( is_object( $flags ) ) {
3730  __METHOD__ . ' was called with a ' . get_class( $flags )
3731  . ' instance instead of an integer!',
3732  '1.38'
3733  );
3734  $flags = self::READ_LATEST;
3735  }
3736 
3737  $touched = $this->getFieldFromPageStore( 'page_touched', $flags );
3738  return MWTimestamp::convert( TS_MW, $touched );
3739  }
3740 
3749  public function getNotificationTimestamp( User $user ) {
3750  return MediaWikiServices::getInstance()
3751  ->getWatchlistManager()
3752  ->getTitleNotificationTimestamp( $user, $this );
3753  }
3754 
3761  public function getNamespaceKey( $prepend = 'nstab-' ) {
3762  // Gets the subject namespace of this title
3763  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
3764  $subjectNS = $nsInfo->getSubject( $this->mNamespace );
3765  // Prefer canonical namespace name for HTML IDs
3766  $namespaceKey = $nsInfo->getCanonicalName( $subjectNS );
3767  if ( $namespaceKey === false ) {
3768  // Fallback to localised text
3769  $namespaceKey = $this->getSubjectNsText();
3770  }
3771  // Makes namespace key lowercase
3772  $namespaceKey = MediaWikiServices::getInstance()->getContentLanguage()->lc( $namespaceKey );
3773  // Uses main
3774  if ( $namespaceKey == '' ) {
3775  $namespaceKey = 'main';
3776  }
3777  // Changes file to image for backwards compatibility
3778  if ( $namespaceKey == 'file' ) {
3779  $namespaceKey = 'image';
3780  }
3781  return $prepend . $namespaceKey;
3782  }
3783 
3790  public function getRedirectsHere( $ns = null ) {
3791  $redirs = [];
3792 
3793  $dbr = wfGetDB( DB_REPLICA );
3794  $where = [
3795  'rd_namespace' => $this->mNamespace,
3796  'rd_title' => $this->mDbkeyform,
3797  'rd_from = page_id'
3798  ];
3799  if ( $this->isExternal() ) {
3800  $where['rd_interwiki'] = $this->mInterwiki;
3801  } else {
3802  $where[] = 'rd_interwiki = ' . $dbr->addQuotes( '' ) . ' OR rd_interwiki IS NULL';
3803  }
3804  if ( $ns !== null ) {
3805  $where['page_namespace'] = $ns;
3806  }
3807 
3808  $res = $dbr->select(
3809  [ 'redirect', 'page' ],
3810  [ 'page_namespace', 'page_title' ],
3811  $where,
3812  __METHOD__
3813  );
3814 
3815  foreach ( $res as $row ) {
3816  $redirs[] = self::newFromRow( $row );
3817  }
3818  return $redirs;
3819  }
3820 
3826  public function isValidRedirectTarget() {
3828 
3829  if ( $this->isSpecialPage() ) {
3830  // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
3831  if ( $this->isSpecial( 'Userlogout' ) ) {
3832  return false;
3833  }
3834 
3835  foreach ( $wgInvalidRedirectTargets as $target ) {
3836  if ( $this->isSpecial( $target ) ) {
3837  return false;
3838  }
3839  }
3840 
3841  return true;
3842  } elseif ( $this->getDBkey() === '' ) {
3843  // relative section links are not valid redirect targets (T278367)
3844  return false;
3845  }
3846 
3847  return $this->isValid();
3848  }
3849 
3857  public function getBacklinkCache(): BacklinkCache {
3858  wfDeprecated( __METHOD__, '1.37' );
3859  return MediaWikiServices::getInstance()->getBacklinkCacheFactory()
3860  ->getBacklinkCache( $this );
3861  }
3862 
3868  public function canUseNoindex() {
3870 
3871  $bannedNamespaces = $wgExemptFromUserRobotsControl ??
3872  MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
3873 
3874  return !in_array( $this->mNamespace, $bannedNamespaces );
3875  }
3876 
3887  public function getCategorySortkey( $prefix = '' ) {
3888  $unprefixed = $this->getText();
3889 
3890  // Anything that uses this hook should only depend
3891  // on the Title object passed in, and should probably
3892  // tell the users to run updateCollations.php --force
3893  // in order to re-sort existing category relations.
3894  Hooks::runner()->onGetDefaultSortkey( $this, $unprefixed );
3895  if ( $prefix !== '' ) {
3896  # Separate with a line feed, so the unprefixed part is only used as
3897  # a tiebreaker when two pages have the exact same prefix.
3898  # In UCA, tab is the only character that can sort above LF
3899  # so we strip both of them from the original prefix.
3900  $prefix = strtr( $prefix, "\n\t", ' ' );
3901  return "$prefix\n$unprefixed";
3902  }
3903  return $unprefixed;
3904  }
3905 
3915  private function getDbPageLanguageCode( int $flags = 0 ): ?string {
3916  global $wgPageLanguageUseDB;
3917 
3918  // check, if the page language could be saved in the database, and if so and
3919  // the value is not requested already, lookup the page language using PageStore
3920  if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) {
3921  $this->mDbPageLanguage = $this->getFieldFromPageStore( 'page_lang', $flags );
3922  }
3923 
3924  return $this->mDbPageLanguage ?: null;
3925  }
3926 
3935  public function getPageLanguage() {
3936  global $wgLang, $wgLanguageCode;
3937  if ( $this->isSpecialPage() ) {
3938  // special pages are in the user language
3939  return $wgLang;
3940  }
3941 
3942  // Checking if DB language is set
3943  $dbPageLanguage = $this->getDbPageLanguageCode();
3944  if ( $dbPageLanguage ) {
3945  return wfGetLangObj( $dbPageLanguage );
3946  }
3947 
3948  if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) {
3949  // Note that this may depend on user settings, so the cache should
3950  // be only per-request.
3951  // NOTE: ContentHandler::getPageLanguage() may need to load the
3952  // content to determine the page language!
3953  // Checking $wgLanguageCode hasn't changed for the benefit of unit
3954  // tests.
3955  $contentHandler = MediaWikiServices::getInstance()
3956  ->getContentHandlerFactory()
3957  ->getContentHandler( $this->getContentModel() );
3958  $langObj = $contentHandler->getPageLanguage( $this );
3959  $this->mPageLanguage = [ $langObj->getCode(), $wgLanguageCode ];
3960  } else {
3961  $langObj = MediaWikiServices::getInstance()->getLanguageFactory()
3962  ->getLanguage( $this->mPageLanguage[0] );
3963  }
3964 
3965  return $langObj;
3966  }
3967 
3976  public function getPageViewLanguage() {
3977  global $wgLang;
3978 
3979  if ( $this->isSpecialPage() ) {
3980  // If the user chooses a variant, the content is actually
3981  // in a language whose code is the variant code.
3982  $variant = $this->getLanguageConverter( $wgLang )->getPreferredVariant();
3983  if ( $wgLang->getCode() !== $variant ) {
3984  return MediaWikiServices::getInstance()->getLanguageFactory()
3985  ->getLanguage( $variant );
3986  }
3987 
3988  return $wgLang;
3989  }
3990 
3991  // Checking if DB language is set
3992  $dbPageLanguage = $this->getDbPageLanguageCode();
3993  if ( $dbPageLanguage ) {
3994  $pageLang = wfGetLangObj( $dbPageLanguage );
3995  $variant = $this->getLanguageConverter( $pageLang )->getPreferredVariant();
3996  if ( $pageLang->getCode() !== $variant ) {
3997  $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()
3998  ->getLanguage( $variant );
3999  }
4000 
4001  return $pageLang;
4002  }
4003 
4004  // @note Can't be cached persistently, depends on user settings.
4005  // @note ContentHandler::getPageViewLanguage() may need to load the
4006  // content to determine the page language!
4007  $contentHandler = MediaWikiServices::getInstance()
4008  ->getContentHandlerFactory()
4009  ->getContentHandler( $this->getContentModel() );
4010  $pageLang = $contentHandler->getPageViewLanguage( $this );
4011  return $pageLang;
4012  }
4013 
4024  public function getEditNotices( $oldid = 0 ) {
4025  $notices = [];
4026 
4027  // Optional notice for the entire namespace
4028  $editnotice_ns = 'editnotice-' . $this->mNamespace;
4029  $msg = wfMessage( $editnotice_ns );
4030  if ( $msg->exists() ) {
4031  $html = $msg->parseAsBlock();
4032  // Edit notices may have complex logic, but output nothing (T91715)
4033  if ( trim( $html ) !== '' ) {
4034  $notices[$editnotice_ns] = Html::rawElement(
4035  'div',
4036  [ 'class' => [
4037  'mw-editnotice',
4038  'mw-editnotice-namespace',
4039  Sanitizer::escapeClass( "mw-$editnotice_ns" )
4040  ] ],
4041  $html
4042  );
4043  }
4044  }
4045 
4046  if (
4047  MediaWikiServices::getInstance()->getNamespaceInfo()->
4048  hasSubpages( $this->mNamespace )
4049  ) {
4050  // Optional notice for page itself and any parent page
4051  $editnotice_base = $editnotice_ns;
4052  foreach ( explode( '/', $this->mDbkeyform ) as $part ) {
4053  $editnotice_base .= '-' . $part;
4054  $msg = wfMessage( $editnotice_base );
4055  if ( $msg->exists() ) {
4056  $html = $msg->parseAsBlock();
4057  if ( trim( $html ) !== '' ) {
4058  $notices[$editnotice_base] = Html::rawElement(
4059  'div',
4060  [ 'class' => [
4061  'mw-editnotice',
4062  'mw-editnotice-base',
4063  Sanitizer::escapeClass( "mw-$editnotice_base" )
4064  ] ],
4065  $html
4066  );
4067  }
4068  }
4069  }
4070  } else {
4071  // Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
4072  $editnoticeText = $editnotice_ns . '-' . strtr( $this->mDbkeyform, '/', '-' );
4073  $msg = wfMessage( $editnoticeText );
4074  if ( $msg->exists() ) {
4075  $html = $msg->parseAsBlock();
4076  if ( trim( $html ) !== '' ) {
4077  $notices[$editnoticeText] = Html::rawElement(
4078  'div',
4079  [ 'class' => [
4080  'mw-editnotice',
4081  'mw-editnotice-page',
4082  Sanitizer::escapeClass( "mw-$editnoticeText" )
4083  ] ],
4084  $html
4085  );
4086  }
4087  }
4088  }
4089 
4090  Hooks::runner()->onTitleGetEditNotices( $this, $oldid, $notices );
4091  return $notices;
4092  }
4093 
4099  private function getFieldFromPageStore( $field, $flags ) {
4100  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
4101 
4102  $pageStore = MediaWikiServices::getInstance()->getPageStore();
4103 
4104  if ( !in_array( $field, $pageStore->getSelectFields(), true ) ) {
4105  throw new InvalidArgumentException( "Unknown field: $field" );
4106  }
4107 
4108  if ( $flags === self::READ_NORMAL && $this->mArticleID === 0 ) {
4109  // page does not exist
4110  return false;
4111  }
4112 
4113  if ( !$this->canExist() ) {
4114  return false;
4115  }
4116 
4117  $page = $pageStore->getPageByReference( $this, $flags );
4118 
4119  if ( $page instanceof PageStoreRecord ) {
4120  return $page->getField( $field );
4121  } else {
4122  // page does not exist
4123  return false;
4124  }
4125  }
4126 
4130  public function __sleep() {
4131  return [
4132  'mNamespace',
4133  'mDbkeyform',
4134  'mFragment',
4135  'mInterwiki',
4136  'mLocalInterwiki',
4137  'mDefaultNamespace',
4138  ];
4139  }
4140 
4141  public function __wakeup() {
4142  $this->mArticleID = ( $this->mNamespace >= 0 ) ? -1 : 0;
4143  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
4144  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
4145  }
4146 
4147  public function __clone() {
4148  $this->mInstanceCacheKey = null;
4149  }
4150 
4160  public function getWikiId() {
4161  return self::LOCAL;
4162  }
4163 
4180  public function getId( $wikiId = self::LOCAL ): int {
4181  $this->assertWiki( $wikiId );
4182  $this->assertProperPage();
4183  return $this->getArticleID();
4184  }
4185 
4198  private function assertProperPage() {
4199  Assert::precondition(
4200  $this->canExist(),
4201  'This Title instance does not represent a proper page, but merely a link target.'
4202  );
4203  }
4204 
4217  public function toPageIdentity(): ProperPageIdentity {
4218  // TODO: replace individual member fields with a PageIdentityValue that is always present
4219 
4220  $this->assertProperPage();
4221 
4222  return new PageIdentityValue(
4223  $this->getId(),
4224  $this->getNamespace(),
4225  $this->getDBkey(),
4226  self::LOCAL
4227  );
4228  }
4229 
4244  public function toPageRecord( $flags = 0 ): ExistingPageRecord {
4245  // TODO: Cache this? Construct is more efficiently?
4246 
4247  $this->assertProperPage();
4248 
4249  Assert::precondition(
4250  $this->exists(),
4251  'This Title instance does not represent an existing page: ' . $this
4252  );
4253 
4254  return new PageStoreRecord(
4255  (object)[
4256  'page_id' => $this->getArticleID( $flags ),
4257  'page_namespace' => $this->getNamespace(),
4258  'page_title' => $this->getDBkey(),
4259  'page_wiki_id' => $this->getWikiId(),
4260  'page_latest' => $this->getLatestRevID( $flags ),
4261  'page_is_new' => $this->isNewPage( $flags ),
4262  'page_is_redirect' => $this->isRedirect( $flags ),
4263  'page_touched' => $this->getTouched( $flags ),
4264  'page_lang' => $this->getDbPageLanguageCode( $flags ),
4265  ],
4266  PageIdentity::LOCAL
4267  );
4268  }
4269 
4270 }
Title\$mLocalInterwiki
bool $mLocalInterwiki
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:93
Title\canHaveTalkPage
canHaveTalkPage()
Can this title have a corresponding talk page?
Definition: Title.php:1213
Title\getTitleProtection
getTitleProtection()
Is this title subject to title protection? Title protection is the one applied against creation of su...
Definition: Title.php:2450
Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition: PageIdentity.php:64
Title\canUseNoindex
canUseNoindex()
Whether the magic words INDEX and NOINDEX function for this page.
Definition: Title.php:3868
Title\getLocalURL
getLocalURL( $query='', $query2=false)
Get a URL with no fragment or server name (relative URL) from a Title object.
Definition: Title.php:2250
Title\isSemiProtected
isSemiProtected( $action='edit')
Is this page "semi-protected" - the only protection levels are listed in $wgSemiprotectedRestrictionL...
Definition: Title.php:2473
MediaWiki\DAO\WikiAwareEntityTrait
trait WikiAwareEntityTrait
Definition: WikiAwareEntityTrait.php:32
Title\isNamespaceProtected
isNamespaceProtected(User $user)
Determines if $user is unable to edit this page because it has been protected by $wgNamespaceProtecti...
Definition: Title.php:2502
Title\getTalkNsText
getTalkNsText()
Get the namespace text of the talk page.
Definition: Title.php:1196
Title\normalizeFragment
static normalizeFragment( $fragment)
Normalizes fragment part of the title.
Definition: Title.php:1841
Title\getSubpageText
getSubpageText()
Get the lowest-level subpage name, i.e.
Definition: Title.php:2074
MediaWiki\Linker\LinkTarget\getInterwiki
getInterwiki()
The interwiki component of this LinkTarget.
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:377
Title\isBigDeletion
isBigDeletion()
Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit.
Definition: Title.php:3363
MediaWiki\Linker\LinkTarget\getText
getText()
Get the main part of the link target, in text form.
Title\getFilteredRestrictionTypes
static getFilteredRestrictionTypes( $exists=true)
Get a filtered list of all restriction types supported by this wiki.
Definition: Title.php:2422
Title\makeName
static makeName( $ns, $title, $fragment='', $interwiki='', $canonicalNamespace=false)
Make a prefixed DB key from a DB key and a namespace index.
Definition: Title.php:854
Title\getInternalURL
getInternalURL( $query='', $query2=false)
Get the URL form for an internal link.
Definition: Title.php:2369
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
Title\getFragment
getFragment()
Get the Title fragment (i.e.
Definition: Title.php:1770
$wgExemptFromUserRobotsControl
$wgExemptFromUserRobotsControl
An array of namespace keys in which the INDEX/__NOINDEX__ magic words will not function,...
Definition: DefaultSettings.php:9257
Title\getTalkPageIfDefined
getTalkPageIfDefined()
Get a Title object associated with the talk page of this article, if such a talk page can exist.
Definition: Title.php:1660
Title\$mForcedContentModel
bool $mForcedContentModel
If a content model was forced via setContentModel() this will be true to avoid having other code path...
Definition: Title.php:122
TitleArray\newFromResult
static newFromResult( $res)
Definition: TitleArray.php:44
Title\isMovable
isMovable()
Would anybody with sufficient privileges be able to move this page? Some pages just aren't movable.
Definition: Title.php:1379
Title\wasLocalInterwiki
wasLocalInterwiki()
Was this a local interwiki link?
Definition: Title.php:976
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:204
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
Title\inNamespaces
inNamespaces(... $namespaces)
Returns true if the title is inside one of the specified namespaces.
Definition: Title.php:1329
Title\isWikitextPage
isWikitextPage()
Does that page contain wikitext, or it is JS, CSS or whatever?
Definition: Title.php:1436
Title\isUserCssConfigPage
isUserCssConfigPage()
Is this a CSS "config" sub-page of a user page?
Definition: Title.php:1503
Title\getBacklinkCache
getBacklinkCache()
Get a backlink cache object.
Definition: Title.php:3857
Title\getPartialURL
getPartialURL()
Get the URL-encoded form of the main part.
Definition: Title.php:1048
$wgLegalTitleChars
$wgLegalTitleChars
Allowed title characters – regex character class Don't change this unless you know what you're doing.
Definition: DefaultSettings.php:4657
Title\clearCaches
static clearCaches()
Definition: Title.php:2966
AutoCommitUpdate
Deferrable Update for closure/callback updates that should use auto-commit mode.
Definition: AutoCommitUpdate.php:9
Title\getTitleValue
getTitleValue()
Get a TitleValue object representing this Title.
Definition: Title.php:1016
Title\estimateRevisionCount
estimateRevisionCount()
Get the approximate revision count of this page.
Definition: Title.php:3392
Title\getPrefixedDBkey
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1881
Title\getSkinFromConfigSubpage
getSkinFromConfigSubpage()
Trim down a .css, .json, or .js subpage title to get the corresponding skin name.
Definition: Title.php:1482
$wgScript
$wgScript
The URL path to index.php.
Definition: DefaultSettings.php:204
Title\$mHasSubpages
bool $mHasSubpages
Whether a page has any subpages.
Definition: Title.php:152
Title\getTalkPage
getTalkPage()
Get a Title object associated with the talk page of this article.
Definition: Title.php:1630
Title\NEW_CLONE
const NEW_CLONE
Flag for use with factory methods like newFromLinkTarget() that have a $forceClone parameter.
Definition: Title.php:75
Title\getParentCategoryTree
getParentCategoryTree( $children=[])
Get a tree of parent categories.
Definition: Title.php:3308
Title\fixUrlQueryArgs
static fixUrlQueryArgs( $query, $query2=false)
Helper to fix up the get{Canonical,Full,Link,Local,Internal}URL args get{Canonical,...
Definition: Title.php:2145
Title\fixSpecialName
fixSpecialName()
If the Title refers to a special page alias which is not the local default, resolve the alias,...
Definition: Title.php:1296
Title\getInterwikiLookup
static getInterwikiLookup()
B/C kludge: provide an InterwikiLookup for use by Title.
Definition: Title.php:216
Title\isUserJsConfigPage
isUserJsConfigPage()
Is this a JS "config" sub-page of a user page?
Definition: Title.php:1531
Title\touchLinks
touchLinks()
Update page_touched timestamps and send CDN purge messages for pages linking to this title.
Definition: Title.php:3700
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:292
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1893
Title\getTransWikiID
getTransWikiID()
Returns the DB name of the distant wiki which owns the object.
Definition: Title.php:999
DeferredUpdates\addUpdate
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the pending update queue for execution at the appropriate time.
Definition: DeferredUpdates.php:125
Title\getArticleID
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:2860
Title\getLinkURL
getLinkURL( $query='', $query2=false, $proto=false)
Get a URL that's the simplest URL that will be valid to link, locally, to the current Title.
Definition: Title.php:2344
Title\$mTitleValue
TitleValue null $mTitleValue
ID of the page's content model, i.e.
Definition: Title.php:163
Title\isTalkPage
isTalkPage()
Is this a talk page of some sort?
Definition: Title.php:1614
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1082
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1167
Title\getDbPageLanguageCode
getDbPageLanguageCode(int $flags=0)
Returns the page language code saved in the database, if $wgPageLanguageUseDB is set to true in Local...
Definition: Title.php:3915
Sanitizer\decodeCharReferencesAndNormalize
static decodeCharReferencesAndNormalize( $text)
Decode any character references, numeric or named entities, in the next and normalize the resulting s...
Definition: Sanitizer.php:1245
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:131
Sanitizer\escapeClass
static escapeClass( $class)
Given a value, escape it so that it can be used as a CSS class and return it.
Definition: Sanitizer.php:972
Title\getNotificationTimestamp
getNotificationTimestamp(User $user)
Get the timestamp when this page was updated since the user last saw it.
Definition: Title.php:3749
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1056
Title\isExternal
isExternal()
Is this Title interwiki?
Definition: Title.php:956
DBAccessObjectUtils\getDBOptions
static getDBOptions( $bitfield)
Get an appropriate DB index, options, and fallback DB index for a query.
Definition: DBAccessObjectUtils.php:52
Title\$mInstanceCacheKey
string null $mInstanceCacheKey
The key of this instance in the internal Title instance cache.
Definition: Title.php:172
BacklinkCache
Class for fetching backlink lists, approximate backlink counts and partitions.
Definition: BacklinkCache.php:50
Title\loadRestrictionsFromRows
loadRestrictionsFromRows( $rows, $oldFashionedRestrictions=null)
Compiles list of active page restrictions from both page table (pre 1.10) and page_restrictions table...
Definition: Title.php:2653
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:710
Title\getDefaultMessageText
getDefaultMessageText()
Get the default (plain) message contents for an page that overrides an interface message key.
Definition: Title.php:3637
Title\hasSourceText
hasSourceText()
Does this page have source text?
Definition: Title.php:3578
Title\loadFromRow
loadFromRow( $row)
Load Title object fields from a DB row.
Definition: Title.php:589
Title\setFragment
setFragment( $fragment)
Set the fragment for this title.
Definition: Title.php:1814
$res
$res
Definition: testCompression.php:57
IDBAccessObject
Interface for database access objects.
Definition: IDBAccessObject.php:57
Title\$mIsBigDeletion
bool null $mIsBigDeletion
Would deleting this page be a big deletion?
Definition: Title.php:166
Title\convertByteClassToUnicodeClass
static convertByteClassToUnicodeClass( $byteClass)
Utility method for converting a character sequence from bytes to Unicode.
Definition: Title.php:748
Title\hasSubpagesEnabled
hasSubpagesEnabled()
Whether this Title's namespace has subpages enabled.
Definition: Title.php:1957
Title\__wakeup
__wakeup()
Definition: Title.php:4141
$wgLang
$wgLang
Definition: Setup.php:861
Page\PageReference
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
Definition: PageReference.php:49
LinkCache\getSelectFields
static getSelectFields()
Fields that LinkCache needs to select.
Definition: LinkCache.php:384
Title\getParentCategories
getParentCategories()
Get categories to which this Title belongs and return an array of categories' names.
Definition: Title.php:3273
Title\getLinksTo
getLinksTo( $options=[], $table='pagelinks', $prefix='pl')
Get an array of Title objects linking to this Title Also stores the IDs in the link cache.
Definition: Title.php:3054
Title\$mContentModel
bool string $mContentModel
ID of the page's content model, i.e.
Definition: Title.php:116
Title\getPageLanguageConverter
getPageLanguageConverter()
Shorthand for getting a Language Converter for page's language.
Definition: Title.php:192
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
Title\isSiteCssConfigPage
isSiteCssConfigPage()
Is this a sitewide CSS "config" page?
Definition: Title.php:1545
MessageLocalizer
Interface for localizing messages in MediaWiki.
Definition: MessageLocalizer.php:29
Title\getNsText
getNsText()
Get the namespace text.
Definition: Title.php:1160
Page\PageStoreRecord
Immutable data record representing an editable page on a wiki.
Definition: PageStoreRecord.php:33
Title\$mRedirect
null bool $mRedirect
Is the article at this title a redirect?
Definition: Title.php:149
Title\$mDbkeyform
string $mDbkeyform
Main part with underscores.
Definition: Title.php:84
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
Title\castFromPageIdentity
static castFromPageIdentity(?PageIdentity $pageIdentity)
Return a Title for a given PageIdentity.
Definition: Title.php:326
Title\$mUrlform
string $mUrlform
URL-encoded form of the main part.
Definition: Title.php:81
$dbr
$dbr
Definition: testCompression.php:54
Title\getLinksFrom
getLinksFrom( $options=[], $table='pagelinks', $prefix='pl')
Get an array of Title objects linked from this Title Also stores the IDs in the link cache.
Definition: Title.php:3112
PathRouter\getActionPaths
static getActionPaths(array $actionPaths, $articlePath)
Definition: PathRouter.php:430
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:53
Wikimedia\Rdbms\IDatabase\update
update( $table, $set, $conds, $fname=__METHOD__, $options=[])
Update all rows in a table that match a given condition.
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Definition: GlobalFunctions.php:422
Title\isCascadeProtected
isCascadeProtected()
Cascading protection: Return true if cascading restrictions apply to this page, false if not.
Definition: Title.php:2525
Title\getCdnUrls
getCdnUrls()
Get a list of URLs to purge from the CDN cache when this page changes.
Definition: Title.php:3214
Title\getOtherPage
getOtherPage()
Get the other title for this page, if this is a subject page get the talk page, if it is a subject pa...
Definition: Title.php:1732
MediaWiki\Linker\LinkTarget\getNamespace
getNamespace()
Get the namespace index.
Title\isSiteConfigPage
isSiteConfigPage()
Could this MediaWiki namespace page contain custom CSS, JSON, or JavaScript for the global UI.
Definition: Title.php:1454
Title\isUserJsonConfigPage
isUserJsonConfigPage()
Is this a JSON "config" sub-page of a user page?
Definition: Title.php:1517
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:212
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:194
Wikimedia\Rdbms\IDatabase\timestamp
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for ins...
ContentHandler\getDefaultModelFor
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title.
Definition: ContentHandler.php:201
deprecatePublicPropertyFallback
deprecatePublicPropertyFallback(string $property, string $version, $getter, $setter=null, $class=null, $component=null)
Mark a removed public property as deprecated and provide fallback getter and setter callables.
Definition: DeprecationHelper.php:125
$wgRawHtmlMessages
string[] $wgRawHtmlMessages
List of messages which might contain raw HTML.
Definition: DefaultSettings.php:3681
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:1057
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
Definition: GlobalFunctions.php:1028
Title\$mDbPageLanguage
string bool null $mDbPageLanguage
The page language code from the database, null if not saved in the database or false if not loaded,...
Definition: Title.php:160
Title\isSpecial
isSpecial( $name)
Returns true if this title resolves to the named special page.
Definition: Title.php:1278
MWException
MediaWiki exception.
Definition: MWException.php:29
Title\getTitleFormatter
static getTitleFormatter()
B/C kludge: provide a TitleParser for use by Title.
Definition: Title.php:204
Title\isSamePageAs
isSamePageAs(PageReference $other)
Definition: Title.php:3456
ResourceLoaderWikiModule\invalidateModuleCache
static invalidateModuleCache(PageIdentity $page, ?RevisionRecord $old, ?RevisionRecord $new, string $domain)
Clear the preloadTitleInfo() cache for all wiki modules on this wiki on page change if it was a JS or...
Definition: ResourceLoaderWikiModule.php:664
Title\isMainPage
isMainPage()
Is this the mainpage?
Definition: Title.php:1403
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Definition: GlobalFunctions.php:997
Title\getSubpage
getSubpage( $text)
Get the title for a subpage of the current page.
Definition: Title.php:2101
Title\getBaseTitle
getBaseTitle()
Get the base page name title, i.e.
Definition: Title.php:2054
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1066
Page\PageReference\getNamespace
getNamespace()
Returns the page's namespace number.
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:577
Title\isConversionTable
isConversionTable()
Is this a conversion table for the LanguageConverter?
Definition: Title.php:1424
Title\isProtected
isProtected( $action='')
Does the title correspond to a protected article?
Definition: Title.php:2488
Title\flushRestrictions
flushRestrictions()
Flush the protection cache in this object and force reload from the database.
Definition: Title.php:2682
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2186
Title\getCategorySortkey
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:3887
Title\getInterwiki
getInterwiki()
Get the interwiki prefix.
Definition: Title.php:967
Title\isSiteJsonConfigPage
isSiteJsonConfigPage()
Is this a sitewide JSON "config" page?
Definition: Title.php:1563
$matches
$matches
Definition: NoLocalSettings.php:24
Title\isValidRedirectTarget
isValidRedirectTarget()
Check if this Title is a valid redirect target.
Definition: Title.php:3826
Title\deleteTitleProtection
deleteTitleProtection()
Remove any title protection due to page existing.
Definition: Title.php:2460
Title\__construct
__construct()
Definition: Title.php:220
MediaWiki\Interwiki\InterwikiLookup
Service interface for looking up Interwiki records.
Definition: InterwikiLookup.php:32
Title\getBrokenLinksFrom
getBrokenLinksFrom()
Get an array of Title objects referring to non-existent articles linked from this page.
Definition: Title.php:3178
Title\getFieldFromPageStore
getFieldFromPageStore( $field, $flags)
Definition: Title.php:4099
Title\isUserConfigPage
isUserConfigPage()
Is this a "config" (.css, .json, or .js) sub-page of a user page?
Definition: Title.php:1468
Title\getLanguageConverter
getLanguageConverter( $language)
Shorthand for getting a Language Converter for specific language.
Definition: Title.php:183
Title\getSubjectPage
getSubjectPage()
Get a title object associated with the subject page of this talk page.
Definition: Title.php:1675
MapCacheLRU
Handles a simple LRU key/value map with a maximum number of entries.
Definition: MapCacheLRU.php:36
wfGetLangObj
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
Definition: GlobalFunctions.php:1117
Title\loadRestrictions
loadRestrictions( $oldFashionedRestrictions=null, $flags=0)
Load restrictions from the page_restrictions table.
Definition: Title.php:2671
$wgInvalidRedirectTargets
$wgInvalidRedirectTargets
Array of invalid page redirect targets.
Definition: DefaultSettings.php:4745
Title\getFullText
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
Definition: Title.php:1917
Title\getTitleCache
static getTitleCache()
Definition: Title.php:497
Title\hasFragment
hasFragment()
Check if a Title fragment is set.
Definition: Title.php:1780
Title\getRedirectsHere
getRedirectsHere( $ns=null)
Get all extant redirects to this Title.
Definition: Title.php:3790
$title
$title
Definition: testCompression.php:38
Title\warnIfPageCannotExist
warnIfPageCannotExist(Title $title, $method)
Definition: Title.php:1701
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:648
Title\$mInterwiki
string $mInterwiki
Interwiki prefix.
Definition: Title.php:90
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
Title\getRootText
getRootText()
Get the root page name text without a namespace, i.e.
Definition: Title.php:1977
PROTO_CANONICAL
const PROTO_CANONICAL
Definition: Defines.php:196
$wgNamespaceProtection
$wgNamespaceProtection
Set the minimum permissions required to edit pages in each namespace.
Definition: DefaultSettings.php:6230
Title\canExist
canExist()
Can this title represent a page in the wiki's database?
Definition: Title.php:1227
$wgDeleteRevisionsLimit
$wgDeleteRevisionsLimit
Optional to restrict deletion of pages with higher revision counts to users with the 'bigdelete' perm...
Definition: DefaultSettings.php:6407
Title\$prefixedText
string null $prefixedText
Text form including namespace/interwiki, initialised on demand.
Definition: Title.php:135
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:894
Title\__sleep
__sleep()
Definition: Title.php:4130
Page\PageReference\getWikiId
getWikiId()
Get the ID of the wiki this page belongs to.
Title\getCanonicalURL
getCanonicalURL( $query='', $query2=false)
Get the URL for a canonical link, for use in things like IRC and e-mail notifications.
Definition: Title.php:2391
Title\areCascadeProtectionSourcesLoaded
areCascadeProtectionSourcesLoaded()
Determines whether cascading protection sources have already been loaded from the database.
Definition: Title.php:2538
Title\$mNamespace
int $mNamespace
Namespace index, i.e.
Definition: Title.php:87
Title\getDefaultNamespace
getDefaultNamespace()
Get the default namespace index, for when there is no namespace.
Definition: Title.php:1758
Title\newFromTextThrow
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:412
$wgPageLanguageUseDB
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
Definition: DefaultSettings.php:2570
Title\$mPageLanguage
array null $mPageLanguage
The (string) language code of the page's language and content code.
Definition: Title.php:155
Title\shouldReadLatest
shouldReadLatest(int $flags)
Definition: Title.php:1076
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:195
Title\isValid
isValid()
Returns true if the title is a valid link target, and that it has been properly normalized.
Definition: Title.php:902
AtomicSectionUpdate
Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
Definition: AtomicSectionUpdate.php:9
Title\compare
static compare( $a, $b)
Callback for usort() to do title sorts by (namespace, title)
Definition: Title.php:881
Title\getPrefixedURL
getPrefixedURL()
Get a URL-encoded title (not an actual URL) including interwiki.
Definition: Title.php:2126
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:674
Page\ExistingPageRecord
Data record representing a page that currently exists as an editable page on a wiki.
Definition: ExistingPageRecord.php:15
Title\__toString
__toString()
Return a string representation of this title.
Definition: Title.php:1907
Page\ProperPageIdentity
Interface for objects representing a page that is (or could be, or used to be) an editable page on a ...
Definition: ProperPageIdentity.php:43
Title\getId
getId( $wikiId=self::LOCAL)
Returns the page ID.
Definition: Title.php:4180
Title\createFragmentTarget
createFragmentTarget(string $fragment)
Creates a new Title for a different fragment of the same page.
Definition: Title.php:1826
MediaWiki\DAO\WikiAwareEntity\assertWiki
assertWiki( $wikiId)
Throws if $wikiId is different from the return value of getWikiId().
$s
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
Definition: mergeMessageFileList.php:206
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:52
ILanguageConverter
The shared interface for all language converters.
Definition: ILanguageConverter.php:29
Title\getTemplateLinksTo
getTemplateLinksTo( $options=[])
Get an array of Title objects using this Title as a template Also stores the IDs in the link cache.
Definition: Title.php:3096
Page\PageReference\getDBkey
getDBkey()
Get the page title in DB key form.
$wgMainPageIsDomainRoot
bool $wgMainPageIsDomainRoot
Option to whether serve the main page as the domain root.
Definition: DefaultSettings.php:498
Title\areRestrictionsCascading
areRestrictionsCascading()
Returns cascading restrictions for the current article.
Definition: Title.php:2634
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
Title\getLatestRevID
getLatestRevID( $flags=0)
What is the page_latest field for this page?
Definition: Title.php:2921
Title\areRestrictionsLoaded
areRestrictionsLoaded()
Accessor for mRestrictionsLoaded.
Definition: Title.php:2578
Title\hasDeletedEdits
hasDeletedEdits()
Is there a version of this page in the deletion archive?
Definition: Title.php:2835
Title\getSubpages
getSubpages( $limit=-1)
Get all subpages of this page.
Definition: Title.php:2760
Title\assertProperPage
assertProperPage()
Code that requires this Title to be a "proper page" in the sense defined by PageIdentity should call ...
Definition: Title.php:4198
Wikimedia\Rdbms\IDatabase\getDomainID
getDomainID()
Return the currently selected domain ID.
Title\isSingleRevRedirect
isSingleRevRedirect()
Locks the page row and check if this page is single revision redirect.
Definition: Title.php:3235
$wgServer
$wgServer
URL of the server.
Definition: DefaultSettings.php:108
Title\GAID_FOR_UPDATE
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define().
Definition: Title.php:66
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:173
Title\getPageViewLanguage
getPageViewLanguage()
Get the language in which the content of this page is written when viewed by user.
Definition: Title.php:3976
HTMLCacheUpdateJob\newForBacklinks
static newForBacklinks(PageReference $page, $table, $params=[])
Definition: HTMLCacheUpdateJob.php:61
Title\newFromDBkey
static newFromDBkey( $key)
Create a new Title from a prefixed DB key.
Definition: Title.php:250
Sanitizer\escapeIdForExternalInterwiki
static escapeIdForExternalInterwiki( $id)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid URL...
Definition: Sanitizer.php:861
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:3451
Title\isSubpage
isSubpage()
Is this a subpage?
Definition: Title.php:1412
Title\hasContentModel
hasContentModel( $id)
Convenience method for checking a title's content model name.
Definition: Title.php:1114
Title\getRestrictionExpiry
getRestrictionExpiry( $action)
Get the expiry time for the restriction against a given action.
Definition: Title.php:2621
Title\newFromURL
static newFromURL( $url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:474
MediaWiki\Linker\LinkTarget\getDBkey
getDBkey()
Get the main part of the link target, in canonical database form.
MediaWiki\Linker\LinkTarget\getFragment
getFragment()
Get the link fragment in text form (i.e.
MapCacheLRU\set
set( $key, $value, $rank=self::RANK_TOP)
Set a key/value pair.
Definition: MapCacheLRU.php:109
Title\resetArticleID
resetArticleID( $id)
Inject a page ID, reset DB-loaded fields, and clear the link cache for this title.
Definition: Title.php:2946
Title\isSubpageOf
isSubpageOf(Title $title)
Check if this title is a subpage of another title.
Definition: Title.php:3477
Title\isLocal
isLocal()
Determine whether the object refers to a page within this project (either this wiki or a wiki with a ...
Definition: Title.php:941
Title\$mFragment
string $mFragment
Title fragment (i.e.
Definition: Title.php:96
Title\getContentModel
getContentModel( $flags=0)
Get the page's content model id, see the CONTENT_MODEL_XXX constants.
Definition: Title.php:1088
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:208
Title\newFromIDs
static newFromIDs( $ids)
Make an array of titles from an array of IDs.
Definition: Title.php:549
NS_USER
const NS_USER
Definition: Defines.php:66
WikiPage\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new page object.
Definition: WikiPage.php:370
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:289
Title\prefix
prefix( $name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object.
Definition: Title.php:1855
Title\getNamespaceKey
getNamespaceKey( $prepend='nstab-')
Generate strings used for xml 'id' names in monobook tabs.
Definition: Title.php:3761
Title\getEditURL
getEditURL()
Get the edit URL for this Title.
Definition: Title.php:2403
Title\getFullURL
getFullURL( $query='', $query2=false, $proto=PROTO_RELATIVE)
Get a real URL referring to this title, with interwiki link and fragment.
Definition: Title.php:2183
Title\isKnown
isKnown()
Does this title refer to a page that can (or might) be meaningfully viewed? In particular,...
Definition: Title.php:3569
Title\inNamespace
inNamespace(int $ns)
Returns true if the title is inside the specified namespace.
Definition: Title.php:1317
$wgArticlePath
$wgArticlePath
The URL path for primary article page views.
Definition: DefaultSettings.php:264
Title\$mIsValid
bool null $mIsValid
Is the title known to be valid?
Definition: Title.php:169
Title\equals
equals(object $other)
Compares with another Title.
Definition: Title.php:3420
Title\getAllRestrictions
getAllRestrictions()
Accessor/initialisation for mRestrictions.
Definition: Title.php:2608
Title
Represents a title within MediaWiki.
Definition: Title.php:47
$wgActionPaths
$wgActionPaths
To set 'pretty' URL paths for actions other than plain page views, add to this array.
Definition: DefaultSettings.php:488
Title\isSameLinkAs
isSameLinkAs(LinkTarget $other)
Definition: Title.php:3440
JobQueueGroup\singleton
static singleton( $domain=false)
Definition: JobQueueGroup.php:114
Title\getCascadeProtectionSources
getCascadeProtectionSources( $getPages=true)
Cascading protection: Get the source of any cascading restrictions on this page.
Definition: Title.php:2558
Title\getRestrictionTypes
getRestrictionTypes()
Returns restriction types for the current Title.
Definition: Title.php:2435
MalformedTitleException
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Definition: MalformedTitleException.php:26
Wikimedia\Rdbms\IDatabase\addQuotes
addQuotes( $s)
Escape and quote a raw value string for use in a SQL query.
Title\getTemplateLinksFrom
getTemplateLinksFrom( $options=[])
Get an array of Title objects used on this Title as a template Also stores the IDs in the link cache.
Definition: Title.php:3166
Title\isRedirect
isRedirect( $flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
Definition: Title.php:2888
Title\$mArticleID
int $mArticleID
Article ID, fetched from the link cache on demand.
Definition: Title.php:107
Title\isDeleted
isDeleted()
Is there a version of this page in the deletion archive?
Definition: Title.php:2789
Title\capitalize
static capitalize( $text, $ns=NS_MAIN)
Capitalize a text string for a title if it belongs to a namespace that capitalizes.
Definition: Title.php:2981
Title\$mDefaultNamespace
int $mDefaultNamespace
Namespace index when there is no namespace.
Definition: Title.php:143
Title\$mLength
int $mLength
The page length, 0 for special pages.
Definition: Title.php:146
Title\$mEstimateRevisions
int $mEstimateRevisions
Estimated number of revisions; null of not loaded.
Definition: Title.php:125
Title\hasSubjectNamespace
hasSubjectNamespace( $ns)
Returns true if the title has the same subject namespace as the namespace specified.
Definition: Title.php:1356
Title\isSpecialPage
isSpecialPage()
Returns true if this is a special page.
Definition: Title.php:1268
MapCacheLRU\get
get( $key, $maxAge=INF, $default=null)
Get the value for a key.
Definition: MapCacheLRU.php:172
Title\purgeSquid
purgeSquid()
Purge all applicable CDN URLs.
Definition: Title.php:3223
Title\getDeletedEditsCount
getDeletedEditsCount()
Is there a version of this page in the deletion archive?
Definition: Title.php:2799
TitleArray
The TitleArray class only exists to provide the newFromResult method at pre- sent.
Definition: TitleArray.php:37
Title\getPageLanguage
getPageLanguage()
Get the language in which the content of this page is written in wikitext.
Definition: Title.php:3935
Title\CACHE_MAX
const CACHE_MAX
Title::newFromText maintains a cache to avoid expensive re-normalization of commonly used titles.
Definition: Title.php:59
Title\getEditNotices
getEditNotices( $oldid=0)
Get a list of rendered edit notices for this page.
Definition: Title.php:4024
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:209
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:213
Page\PageIdentity\exists
exists()
Checks if the page currently exists.
Wikimedia\Rdbms\IDatabase\selectFieldValues
selectFieldValues( $table, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[])
A SELECT wrapper which returns a list of single field values from result rows.
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:78
Page\PageIdentityValue
Immutable value object representing a page identity.
Definition: PageIdentityValue.php:41
Title\getFragmentForURL
getFragmentForURL()
Get the fragment in URL form, including the "#" character if there is one.
Definition: Title.php:1789
Title\exists
exists( $flags=0)
Check if page exists.
Definition: Title.php:3493
Title\__clone
__clone()
Definition: Title.php:4147
Title\getTouched
getTouched( $flags=self::READ_NORMAL)
Get the last touched timestamp.
Definition: Title.php:3727
Sanitizer\escapeIdForLink
static escapeIdForLink( $id)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid URL...
Definition: Sanitizer.php:838
Title\isAlwaysKnown
isAlwaysKnown()
Should links to this title be shown as potentially viewable (i.e.
Definition: Title.php:3515
Title\secureAndSplit
secureAndSplit( $text, $defaultNamespace=null)
Secure and split - main initialisation function for this object.
Definition: Title.php:3006
Title\isDeletedQuick
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:2825
Title\getSubpageUrlForm
getSubpageUrlForm()
Get a URL-encoded form of the subpage text.
Definition: Title.php:2115
MapCacheLRU\clear
clear( $keys=null)
Clear one or several cache entries, or all cache entries.
Definition: MapCacheLRU.php:289
Title\castFromPageReference
static castFromPageReference(?PageReference $pageReference)
Return a Title for a given Reference.
Definition: Title.php:339
Title\toPageIdentity
toPageIdentity()
Returns the page represented by this Title as a ProperPageIdentity.
Definition: Title.php:4217
Title\setContentModel
setContentModel( $model)
Set a proposed content model for the page for permissions checking.
Definition: Title.php:1134
$t
$t
Definition: testCompression.php:74
Title\legalChars
static legalChars()
Get a regex character class describing the legal characters in a link.
Definition: Title.php:734
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:313
Title\isSiteJsConfigPage
isSiteJsConfigPage()
Is this a sitewide JS "config" page?
Definition: Title.php:1581
Title\invalidateCache
invalidateCache( $purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:3660
NS_FILE
const NS_FILE
Definition: Defines.php:70
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
Title\isTrans
isTrans()
Determine whether the object refers to a page within this project and is transcludable.
Definition: Title.php:986
Title\isNewPage
isNewPage( $flags=self::READ_NORMAL)
Check if this is a new page.
Definition: Title.php:3352
Title\getRestrictions
getRestrictions( $action)
Accessor/initialisation for mRestrictions.
Definition: Title.php:2595
DeprecationHelper
trait DeprecationHelper
Use this trait in classes which have properties for which public access is deprecated or implementati...
Definition: DeprecationHelper.php:60
Title\isContentPage
isContentPage()
Is this Title in a namespace which contains content? In other words, is this a content page,...
Definition: Title.php:1368
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:210
Title\uncache
uncache()
Removes this instance from the internal title cache, so it can be modified in-place without polluting...
Definition: Title.php:451
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:67
Title\$titleCache
static MapCacheLRU null $titleCache
Definition: Title.php:52
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:523
$wgVariantArticlePath
$wgVariantArticlePath
Like $wgArticlePath, but on multi-variant wikis, this provides a path format that describes which par...
Definition: DefaultSettings.php:3640
Title\isRawHtmlMessage
isRawHtmlMessage()
Is this a message which can contain raw HTML?
Definition: Title.php:1599
Title\getSelectFields
static getSelectFields()
Returns a list of fields that are to be selected for initializing Title objects.
Definition: Title.php:512
Title\hasSubpages
hasSubpages()
Does this have subpages? (Warning, usually requires an extra DB query.)
Definition: Title.php:2732
Title\getBaseText
getBaseText()
Get the base page name without a namespace, i.e.
Definition: Title.php:2027
Title\pageCond
pageCond()
Get an associative array for selecting this title from the "page" table.
Definition: Title.php:3335
Title\getText
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:1039
Title\$mTextform
string $mTextform
Text form (spaces not underscores) of the main part.
Definition: Title.php:78
Title\toPageRecord
toPageRecord( $flags=0)
Returns the page represented by this Title as a ProperPageRecord.
Definition: Title.php:4244
Wikimedia\Rdbms\IDatabase\delete
delete( $table, $conds, $fname=__METHOD__)
Delete all rows in a table that match a condition.
Title\purgeExpiredRestrictions
static purgeExpiredRestrictions()
Purge expired restrictions from the page_restrictions table.
Definition: Title.php:2691
$wgInternalServer
$wgInternalServer
Internal server name as known to CDN, if different.
Definition: DefaultSettings.php:3267
Title\$mLatestID
bool int $mLatestID
ID of most recent revision.
Definition: Title.php:110
PROTO_HTTP
const PROTO_HTTP
Definition: Defines.php:192
Title\getWikiId
getWikiId()
Returns false to indicate that this Title belongs to the local wiki.
Definition: Title.php:4160
Title\lazyFillContentModel
lazyFillContentModel( $model)
If the content model field is not frozen then update it with a retrieved value.
Definition: Title.php:1149
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:474
Title\getSubjectNsText
getSubjectNsText()
Get the namespace text of the subject (rather than talk) page.
Definition: Title.php:1185
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:40
Title\newFromTitleValue
static newFromTitleValue(TitleValue $titleValue, $forceClone='')
Returns a Title given a TitleValue.
Definition: Title.php:274
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
Definition: GlobalFunctions.php:330
Title\getFullUrlForRedirect
getFullUrlForRedirect( $query='', $proto=PROTO_CURRENT)
Get a url appropriate for making redirects based on an untrusted url arg.
Definition: Title.php:2216
Title\getRootTitle
getRootTitle()
Get the root page name title, i.e.
Definition: Title.php:2004
Title\getLength
getLength( $flags=0)
What is the length of this page? Uses link cache, adding it if necessary.
Definition: Title.php:2903
Title\findSubpageDivider
findSubpageDivider( $text, $dir)
Finds the first or last subpage divider (slash) in the string.
Definition: Title.php:1939