MediaWiki  master
Title.php
Go to the documentation of this file.
1 <?php
36 use Wikimedia\Assert\Assert;
37 use Wikimedia\Assert\PreconditionException;
39 
51 
53  private static $titleCache = null;
54 
60  private const CACHE_MAX = 1000;
61 
67  public const GAID_FOR_UPDATE = 512;
68 
76  public const NEW_CLONE = 'clone';
77 
78  /***************************************************************************/
79  // region Private member variables
91  public $mTextform = '';
92 
98  public $mUrlform = '';
99 
105  public $mDbkeyform = '';
106 
113 
119  public $mInterwiki = '';
120 
122  private $mLocalInterwiki = false;
123 
129  public $mFragment = '';
130 
132  public $mArticleID = -1;
133 
135  protected $mLatestID = false;
136 
141  private $mContentModel = false;
142 
147  private $mForcedContentModel = false;
148 
151 
160  public $prefixedText = null;
161 
169 
171  protected $mLength = -1;
172 
174  public $mRedirect = null;
175 
177  private $mHasSubpages;
178 
180  private $mPageLanguage;
181 
185  private $mDbPageLanguage = false;
186 
188  private $mTitleValue = null;
189 
191  private $mIsBigDeletion = null;
192 
194  private $mIsValid = null;
195 
197  private $mInstanceCacheKey = null;
198 
199  // endregion -- end of private member variables
201  /***************************************************************************/
202 
208  private function getLanguageConverter( $language ): ILanguageConverter {
209  return MediaWikiServices::getInstance()->getLanguageConverterFactory()
210  ->getLanguageConverter( $language );
211  }
212 
218  return $this->getLanguageConverter( $this->getPageLanguage() );
219  }
220 
229  private static function getTitleFormatter() {
230  return MediaWikiServices::getInstance()->getTitleFormatter();
231  }
232 
241  private static function getInterwikiLookup() {
242  return MediaWikiServices::getInstance()->getInterwikiLookup();
243  }
244 
245  private function __construct() {
246  }
247 
256  public static function newFromDBkey( $key ) {
257  $t = new self();
258 
259  try {
260  $t->secureAndSplit( $key );
261  return $t;
262  } catch ( MalformedTitleException $ex ) {
263  return null;
264  }
265  }
266 
280  public static function newFromTitleValue( TitleValue $titleValue, $forceClone = '' ) {
281  return self::newFromLinkTarget( $titleValue, $forceClone );
282  }
283 
295  public static function newFromLinkTarget( LinkTarget $linkTarget, $forceClone = '' ) {
296  if ( $linkTarget instanceof Title ) {
297  // Special case if it's already a Title object
298  if ( $forceClone === self::NEW_CLONE ) {
299  return clone $linkTarget;
300  } else {
301  return $linkTarget;
302  }
303  }
304  return self::makeTitle(
305  $linkTarget->getNamespace(),
306  $linkTarget->getText(),
307  $linkTarget->getFragment(),
308  $linkTarget->getInterwiki()
309  );
310  }
311 
319  public static function castFromLinkTarget( $linkTarget ) {
320  return $linkTarget ? self::newFromLinkTarget( $linkTarget ) : null;
321  }
322 
332  public static function castFromPageIdentity( ?PageIdentity $pageIdentity ): ?Title {
333  return self::castFromPageReference( $pageIdentity );
334  }
335 
345  public static function castFromPageReference( ?PageReference $pageReference ): ?Title {
346  if ( !$pageReference ) {
347  return null;
348  }
349 
350  if ( $pageReference instanceof Title ) {
351  return $pageReference;
352  }
353 
354  $pageReference->assertWiki( self::LOCAL );
355  $title = self::makeTitle( $pageReference->getNamespace(), $pageReference->getDBkey() );
356 
357  if ( $pageReference instanceof PageIdentity ) {
358  $title->mArticleID = $pageReference->getId();
359  }
360  return $title;
361  }
362 
383  public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
384  // DWIM: Integers can be passed in here when page titles are used as array keys.
385  if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) {
386  throw new InvalidArgumentException( '$text must be a string.' );
387  }
388  if ( $text === null ) {
389  return null;
390  }
391 
392  try {
393  return self::newFromTextThrow( (string)$text, (int)$defaultNamespace );
394  } catch ( MalformedTitleException $ex ) {
395  return null;
396  }
397  }
398 
418  public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
419  if ( is_object( $text ) ) {
420  throw new MWException( '$text must be a string, given an object' );
421  } elseif ( $text === null ) {
422  // Legacy code relies on MalformedTitleException being thrown in this case
423  // TODO: fix(happens when URL with no title in it is parsed).
424  throw new MalformedTitleException( 'title-invalid-empty' );
425  }
426 
428 
429  // Wiki pages often contain multiple links to the same page.
430  // Title normalization and parsing can become expensive on pages with many
431  // links, so we can save a little time by caching them.
432  if ( $defaultNamespace === NS_MAIN ) {
433  $t = $titleCache->get( $text );
434  if ( $t ) {
435  return $t;
436  }
437  }
438 
439  // Convert things like &eacute; &#257; or &#x3017; into normalized (T16952) text
440  $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
441 
442  $t = new Title();
443  $dbKeyForm = strtr( $filteredText, ' ', '_' );
444 
445  $t->secureAndSplit( $dbKeyForm, (int)$defaultNamespace );
446  if ( $defaultNamespace === NS_MAIN ) {
447  $t->mInstanceCacheKey = $text;
448  $titleCache->set( $text, $t );
449  }
450  return $t;
451  }
452 
457  private function uncache() {
458  if ( $this->mInstanceCacheKey !== null ) {
460  $titleCache->clear( $this->mInstanceCacheKey );
461  $this->mInstanceCacheKey = null;
462  }
463  }
464 
480  public static function newFromURL( $url ) {
481  $t = new Title();
482 
483  # For compatibility with old buggy URLs. "+" is usually not valid in titles,
484  # but some URLs used it as a space replacement and they still come
485  # from some external search tools.
486  if ( strpos( self::legalChars(), '+' ) === false ) {
487  $url = strtr( $url, '+', ' ' );
488  }
489 
490  $dbKeyForm = strtr( $url, ' ', '_' );
491 
492  try {
493  $t->secureAndSplit( $dbKeyForm );
494  return $t;
495  } catch ( MalformedTitleException $ex ) {
496  return null;
497  }
498  }
499 
503  private static function getTitleCache() {
504  if ( self::$titleCache === null ) {
505  self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
506  }
507  return self::$titleCache;
508  }
509 
518  protected static function getSelectFields() {
519  return MediaWikiServices::getInstance()->getPageStore()->getSelectFields();
520  }
521 
529  public static function newFromID( $id, $flags = 0 ) {
530  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
531  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
532  $row = wfGetDB( $index )->selectRow(
533  'page',
534  self::getSelectFields(),
535  [ 'page_id' => $id ],
536  __METHOD__,
537  $options
538  );
539  if ( $row !== false ) {
540  $title = self::newFromRow( $row );
541  } else {
542  $title = null;
543  }
544 
545  return $title;
546  }
547 
554  public static function newFromIDs( $ids ) {
555  if ( !count( $ids ) ) {
556  return [];
557  }
558  $dbr = wfGetDB( DB_REPLICA );
559 
560  $res = $dbr->select(
561  'page',
562  self::getSelectFields(),
563  [ 'page_id' => $ids ],
564  __METHOD__
565  );
566 
567  $titles = [];
568  foreach ( $res as $row ) {
569  $titles[] = self::newFromRow( $row );
570  }
571  return $titles;
572  }
573 
580  public static function newFromRow( $row ) {
581  $t = self::makeTitle( $row->page_namespace, $row->page_title );
582  $t->loadFromRow( $row );
583  return $t;
584  }
585 
592  public function loadFromRow( $row ) {
593  if ( $row ) { // page found
594  if ( isset( $row->page_id ) ) {
595  $this->mArticleID = (int)$row->page_id;
596  }
597  if ( isset( $row->page_len ) ) {
598  $this->mLength = (int)$row->page_len;
599  }
600  if ( isset( $row->page_is_redirect ) ) {
601  $this->mRedirect = (bool)$row->page_is_redirect;
602  }
603  if ( isset( $row->page_latest ) ) {
604  $this->mLatestID = (int)$row->page_latest;
605  }
606  if ( isset( $row->page_content_model ) ) {
607  $this->lazyFillContentModel( $row->page_content_model );
608  } else {
609  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
610  }
611  if ( isset( $row->page_lang ) ) {
612  $this->mDbPageLanguage = (string)$row->page_lang;
613  }
614  if ( isset( $row->page_restrictions ) ) {
615  // If we have them handy, save them so we don't need to look them up later
616  MediaWikiServices::getInstance()->getRestrictionStore()
617  ->registerOldRestrictions( $this, $row->page_restrictions );
618 
619  }
620  } else { // page not found
621  $this->mArticleID = 0;
622  $this->mLength = 0;
623  $this->mRedirect = false;
624  $this->mLatestID = 0;
625  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
626  }
627  }
628 
651  public static function makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
652  $t = new Title();
653  $t->mInterwiki = $interwiki;
654  $t->mFragment = self::normalizeFragment( $fragment );
655  $t->mNamespace = $ns = (int)$ns;
656  $t->mDbkeyform = strtr( $title, ' ', '_' );
657  $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
658  $t->mUrlform = wfUrlencode( $t->mDbkeyform );
659  $t->mTextform = strtr( $title, '_', ' ' );
660  return $t;
661  }
662 
677  public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
678  // NOTE: ideally, this would just call makeTitle() and then isValid(),
679  // but presently, that means more overhead on a potential performance hotspot.
680 
681  if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) {
682  return null;
683  }
684 
685  $t = new Title();
686  $dbKeyForm = self::makeName( $ns, $title, $fragment, $interwiki, true );
687 
688  try {
689  $t->secureAndSplit( $dbKeyForm );
690  return $t;
691  } catch ( MalformedTitleException $ex ) {
692  return null;
693  }
694  }
695 
713  public static function newMainPage( MessageLocalizer $localizer = null ) {
714  if ( $localizer ) {
715  $msg = $localizer->msg( 'mainpage' );
716  } else {
717  $msg = wfMessage( 'mainpage' );
718  }
719 
720  $title = self::newFromText( $msg->inContentLanguage()->text() );
721 
722  // Every page renders at least one link to the Main Page (e.g. sidebar).
723  // If the localised value is invalid, don't produce fatal errors that
724  // would make the wiki inaccessible (and hard to fix the invalid message).
725  // Gracefully fallback...
726  if ( !$title ) {
727  $title = self::newFromText( 'Main Page' );
728  }
729  return $title;
730  }
731 
737  public static function legalChars() {
738  global $wgLegalTitleChars;
739  return $wgLegalTitleChars;
740  }
741 
751  public static function convertByteClassToUnicodeClass( $byteClass ) {
752  $length = strlen( $byteClass );
753  // Input token queue
754  $x0 = $x1 = $x2 = '';
755  // Decoded queue
756  $d0 = $d1 = '';
757  // Decoded integer codepoints
758  $ord0 = $ord1 = $ord2 = 0;
759  // Re-encoded queue
760  $r0 = $r1 = $r2 = '';
761  // Output
762  $out = '';
763  // Flags
764  $allowUnicode = false;
765  for ( $pos = 0; $pos < $length; $pos++ ) {
766  // Shift the queues down
767  $x2 = $x1;
768  $x1 = $x0;
769  $d1 = $d0;
770  $ord2 = $ord1;
771  $ord1 = $ord0;
772  $r2 = $r1;
773  $r1 = $r0;
774  // Load the current input token and decoded values
775  $inChar = $byteClass[$pos];
776  if ( $inChar === '\\' ) {
777  if ( preg_match( '/x([0-9a-fA-F]{2})/A', $byteClass, $m, 0, $pos + 1 ) ) {
778  $x0 = $inChar . $m[0];
779  $d0 = chr( hexdec( $m[1] ) );
780  $pos += strlen( $m[0] );
781  } elseif ( preg_match( '/[0-7]{3}/A', $byteClass, $m, 0, $pos + 1 ) ) {
782  $x0 = $inChar . $m[0];
783  $d0 = chr( octdec( $m[0] ) );
784  $pos += strlen( $m[0] );
785  } elseif ( $pos + 1 >= $length ) {
786  $x0 = $d0 = '\\';
787  } else {
788  $d0 = $byteClass[$pos + 1];
789  $x0 = $inChar . $d0;
790  $pos++;
791  }
792  } else {
793  $x0 = $d0 = $inChar;
794  }
795  $ord0 = ord( $d0 );
796  // Load the current re-encoded value
797  if ( $ord0 < 32 || $ord0 == 0x7f ) {
798  $r0 = sprintf( '\x%02x', $ord0 );
799  } elseif ( $ord0 >= 0x80 ) {
800  // Allow unicode if a single high-bit character appears
801  $r0 = sprintf( '\x%02x', $ord0 );
802  $allowUnicode = true;
803  // @phan-suppress-next-line PhanParamSuspiciousOrder false positive
804  } elseif ( strpos( '-\\[]^', $d0 ) !== false ) {
805  $r0 = '\\' . $d0;
806  } else {
807  $r0 = $d0;
808  }
809  // Do the output
810  // @phan-suppress-next-line PhanPluginRedundantAssignmentInLoop Confusing, $r1 is set later
811  if ( $x0 !== '' && $x1 === '-' && $x2 !== '' ) {
812  // Range
813  if ( $ord2 > $ord0 ) {
814  // Empty range
815  } elseif ( $ord0 >= 0x80 ) {
816  // Unicode range
817  $allowUnicode = true;
818  if ( $ord2 < 0x80 ) {
819  // Keep the non-unicode section of the range
820  $out .= "$r2-\\x7F";
821  }
822  } else {
823  // Normal range
824  $out .= "$r2-$r0";
825  }
826  // Reset state to the initial value
827  $x0 = $x1 = $d0 = $d1 = $r0 = $r1 = '';
828  } elseif ( $ord2 < 0x80 ) {
829  // ASCII character
830  $out .= $r2;
831  }
832  }
833  // @phan-suppress-next-line PhanSuspiciousValueComparison
834  if ( $ord1 < 0x80 ) {
835  $out .= $r1;
836  }
837  if ( $ord0 < 0x80 ) {
838  $out .= $r0;
839  }
840  if ( $allowUnicode ) {
841  $out .= '\u0080-\uFFFF';
842  }
843  return $out;
844  }
845 
857  public static function makeName( $ns, $title, $fragment = '', $interwiki = '',
858  $canonicalNamespace = false
859  ) {
860  if ( $canonicalNamespace ) {
861  $namespace = MediaWikiServices::getInstance()->getNamespaceInfo()->
862  getCanonicalName( $ns );
863  } else {
864  $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns );
865  }
866  $name = $namespace == '' ? $title : "$namespace:$title";
867  if ( strval( $interwiki ) != '' ) {
868  $name = "$interwiki:$name";
869  }
870  if ( strval( $fragment ) != '' ) {
871  $name .= '#' . $fragment;
872  }
873  return $name;
874  }
875 
884  public static function compare( $a, $b ) {
885  return $a->getNamespace() <=> $b->getNamespace()
886  ?: strcmp( $a->getDBkey(), $b->getDBkey() );
887  }
888 
905  public function isValid() {
906  if ( $this->mIsValid !== null ) {
907  return $this->mIsValid;
908  }
909 
910  try {
911  $text = $this->getFullText();
912  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
913 
914  '@phan-var MediaWikiTitleCodec $titleCodec';
915  $parts = $titleCodec->splitTitleString( $text, $this->mNamespace );
916 
917  // Check that nothing changed!
918  // This ensures that $text was already properly normalized.
919  if ( $parts['fragment'] !== $this->mFragment
920  || $parts['interwiki'] !== $this->mInterwiki
921  || $parts['local_interwiki'] !== $this->mLocalInterwiki
922  || $parts['namespace'] !== $this->mNamespace
923  || $parts['dbkey'] !== $this->mDbkeyform
924  ) {
925  $this->mIsValid = false;
926  return $this->mIsValid;
927  }
928  } catch ( MalformedTitleException $ex ) {
929  $this->mIsValid = false;
930  return $this->mIsValid;
931  }
932 
933  $this->mIsValid = true;
934  return $this->mIsValid;
935  }
936 
944  public function isLocal() {
945  if ( $this->isExternal() ) {
946  $iw = self::getInterwikiLookup()->fetch( $this->mInterwiki );
947  if ( $iw ) {
948  return $iw->isLocal();
949  }
950  }
951  return true;
952  }
953 
959  public function isExternal() {
960  return $this->mInterwiki !== '';
961  }
962 
970  public function getInterwiki() {
971  return $this->mInterwiki;
972  }
973 
979  public function wasLocalInterwiki() {
980  return $this->mLocalInterwiki;
981  }
982 
989  public function isTrans() {
990  if ( !$this->isExternal() ) {
991  return false;
992  }
993 
994  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable();
995  }
996 
1002  public function getTransWikiID() {
1003  if ( !$this->isExternal() ) {
1004  return false;
1005  }
1006 
1007  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID();
1008  }
1009 
1019  public function getTitleValue() {
1020  if ( $this->mTitleValue === null ) {
1021  try {
1022  $this->mTitleValue = new TitleValue(
1023  $this->mNamespace,
1024  $this->mDbkeyform,
1025  $this->mFragment,
1026  $this->mInterwiki
1027  );
1028  } catch ( InvalidArgumentException $ex ) {
1029  wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' .
1030  $this->getPrefixedText() . ']]: ' . $ex->getMessage() );
1031  }
1032  }
1033 
1034  return $this->mTitleValue;
1035  }
1036 
1042  public function getText() {
1043  return $this->mTextform;
1044  }
1045 
1051  public function getPartialURL() {
1052  return $this->mUrlform;
1053  }
1054 
1060  public function getDBkey(): string {
1061  return $this->mDbkeyform;
1062  }
1063 
1069  public function getNamespace(): int {
1070  return $this->mNamespace;
1071  }
1072 
1081  public function getContentModel( $flags = 0 ) {
1082  if ( $this->mForcedContentModel ) {
1083  if ( !$this->mContentModel ) {
1084  throw new RuntimeException( 'Got out of sync; an empty model is being forced' );
1085  }
1086  // Content model is locked to the currently loaded one
1087  return $this->mContentModel;
1088  }
1089 
1090  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
1091  $this->lazyFillContentModel( $this->loadFieldFromDB( 'page_content_model', $flags ) );
1092  } elseif (
1093  ( !$this->mContentModel || $flags & self::GAID_FOR_UPDATE ) &&
1094  $this->getArticleID( $flags )
1095  ) {
1096  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1097  $linkCache->addLinkObj( $this ); # in case we already had an article ID
1098  $this->lazyFillContentModel( $linkCache->getGoodLinkFieldObj( $this, 'model' ) );
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 
1273  public function isWatchable() {
1274  wfDeprecated( __METHOD__, '1.37' );
1275  $watchlistManager = MediaWikiServices::getInstance()->getWatchlistManager();
1276  return $watchlistManager->isWatchable( $this );
1277  }
1278 
1284  public function isSpecialPage() {
1285  return $this->mNamespace === NS_SPECIAL;
1286  }
1287 
1294  public function isSpecial( $name ) {
1295  if ( $this->isSpecialPage() ) {
1296  list( $thisName, /* $subpage */ ) =
1297  MediaWikiServices::getInstance()->getSpecialPageFactory()->
1298  resolveAlias( $this->mDbkeyform );
1299  if ( $name == $thisName ) {
1300  return true;
1301  }
1302  }
1303  return false;
1304  }
1305 
1312  public function fixSpecialName() {
1313  if ( $this->isSpecialPage() ) {
1314  $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory();
1315  list( $canonicalName, $par ) = $spFactory->resolveAlias( $this->mDbkeyform );
1316  if ( $canonicalName ) {
1317  $localName = $spFactory->getLocalNameFor( $canonicalName, $par );
1318  if ( $localName != $this->mDbkeyform ) {
1319  return self::makeTitle( NS_SPECIAL, $localName );
1320  }
1321  }
1322  }
1323  return $this;
1324  }
1325 
1336  public function inNamespace( $ns ) {
1337  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1338  equals( $this->mNamespace, $ns );
1339  }
1340 
1348  public function inNamespaces( ...$namespaces ) {
1349  if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) {
1350  $namespaces = $namespaces[0];
1351  }
1352 
1353  foreach ( $namespaces as $ns ) {
1354  if ( $this->inNamespace( $ns ) ) {
1355  return true;
1356  }
1357  }
1358 
1359  return false;
1360  }
1361 
1375  public function hasSubjectNamespace( $ns ) {
1376  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1377  subjectEquals( $this->mNamespace, $ns );
1378  }
1379 
1387  public function isContentPage() {
1388  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1389  isContent( $this->mNamespace );
1390  }
1391 
1398  public function isMovable() {
1399  if (
1400  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1401  isMovable( $this->mNamespace ) || $this->isExternal()
1402  ) {
1403  // Interwiki title or immovable namespace. Hooks don't get to override here
1404  return false;
1405  }
1406 
1407  $result = true;
1408  Hooks::runner()->onTitleIsMovable( $this, $result );
1409  return $result;
1410  }
1411 
1422  public function isMainPage() {
1423  return $this->equals( self::newMainPage() );
1424  }
1425 
1431  public function isSubpage() {
1432  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1433  hasSubpages( $this->mNamespace )
1434  ? strpos( $this->getText(), '/' ) !== false
1435  : false;
1436  }
1437 
1443  public function isConversionTable() {
1444  // @todo ConversionTable should become a separate content model.
1445 
1446  return $this->mNamespace === NS_MEDIAWIKI &&
1447  strpos( $this->getText(), 'Conversiontable/' ) === 0;
1448  }
1449 
1455  public function isWikitextPage() {
1456  return $this->hasContentModel( CONTENT_MODEL_WIKITEXT );
1457  }
1458 
1473  public function isSiteConfigPage() {
1474  return (
1475  $this->isSiteCssConfigPage()
1476  || $this->isSiteJsonConfigPage()
1477  || $this->isSiteJsConfigPage()
1478  );
1479  }
1480 
1487  public function isUserConfigPage() {
1488  return (
1489  $this->isUserCssConfigPage()
1490  || $this->isUserJsonConfigPage()
1491  || $this->isUserJsConfigPage()
1492  );
1493  }
1494 
1501  public function getSkinFromConfigSubpage() {
1502  $text = $this->getText();
1503  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
1504  if ( $lastSlashPos === false ) {
1505  return '';
1506  }
1507 
1508  $lastDot = strrpos( $text, '.', $lastSlashPos );
1509  if ( $lastDot === false ) {
1510  return '';
1511  }
1512 
1513  return substr( $text, $lastSlashPos + 1, $lastDot - $lastSlashPos - 1 );
1514  }
1515 
1522  public function isUserCssConfigPage() {
1523  return (
1524  $this->mNamespace === NS_USER
1525  && $this->isSubpage()
1526  && $this->hasContentModel( CONTENT_MODEL_CSS )
1527  );
1528  }
1529 
1536  public function isUserJsonConfigPage() {
1537  return (
1538  $this->mNamespace === NS_USER
1539  && $this->isSubpage()
1540  && $this->hasContentModel( CONTENT_MODEL_JSON )
1541  );
1542  }
1543 
1550  public function isUserJsConfigPage() {
1551  return (
1552  $this->mNamespace === NS_USER
1553  && $this->isSubpage()
1555  );
1556  }
1557 
1564  public function isSiteCssConfigPage() {
1565  return (
1566  $this->mNamespace === NS_MEDIAWIKI
1567  && (
1569  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1570  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1571  || substr( $this->mDbkeyform, -4 ) === '.css'
1572  )
1573  );
1574  }
1575 
1582  public function isSiteJsonConfigPage() {
1583  return (
1584  $this->mNamespace === NS_MEDIAWIKI
1585  && (
1587  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1588  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1589  || substr( $this->mDbkeyform, -5 ) === '.json'
1590  )
1591  );
1592  }
1593 
1600  public function isSiteJsConfigPage() {
1601  return (
1602  $this->mNamespace === NS_MEDIAWIKI
1603  && (
1605  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1606  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1607  || substr( $this->mDbkeyform, -3 ) === '.js'
1608  )
1609  );
1610  }
1611 
1618  public function isRawHtmlMessage() {
1619  global $wgRawHtmlMessages;
1620 
1621  if ( !$this->inNamespace( NS_MEDIAWIKI ) ) {
1622  return false;
1623  }
1624  $message = lcfirst( $this->getRootTitle()->getDBkey() );
1625  return in_array( $message, $wgRawHtmlMessages, true );
1626  }
1627 
1633  public function isTalkPage() {
1634  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1635  isTalk( $this->mNamespace );
1636  }
1637 
1649  public function getTalkPage() {
1650  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1651  // Instead of failing on invalid titles, let's just log the issue for now.
1652  // See the discussion on T227817.
1653 
1654  // Is this the same title?
1655  $talkNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $this->mNamespace );
1656  if ( $this->mNamespace == $talkNS ) {
1657  return $this;
1658  }
1659 
1660  $title = self::makeTitle( $talkNS, $this->mDbkeyform );
1661 
1662  $this->warnIfPageCannotExist( $title, __METHOD__ );
1663 
1664  return $title;
1665  // TODO: replace the above with the code below:
1666  // return self::castFromLinkTarget(
1667  // MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) );
1668  }
1669 
1679  public function getTalkPageIfDefined() {
1680  if ( !$this->canHaveTalkPage() ) {
1681  return null;
1682  }
1683 
1684  return $this->getTalkPage();
1685  }
1686 
1694  public function getSubjectPage() {
1695  // Is this the same title?
1696  $subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo()
1697  ->getSubject( $this->mNamespace );
1698  if ( $this->mNamespace == $subjectNS ) {
1699  return $this;
1700  }
1701  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1702  // Instead of failing on invalid titles, let's just log the issue for now.
1703  // See the discussion on T227817.
1704  $title = self::makeTitle( $subjectNS, $this->mDbkeyform );
1705 
1706  $this->warnIfPageCannotExist( $title, __METHOD__ );
1707 
1708  return $title;
1709  // TODO: replace the above with the code below:
1710  // return self::castFromLinkTarget(
1711  // MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
1712  }
1713 
1720  private function warnIfPageCannotExist( Title $title, $method ) {
1721  if ( $this->getText() == '' ) {
1722  wfLogWarning(
1723  $method . ': called on empty title ' . $this->getFullText() . ', returning '
1724  . $title->getFullText()
1725  );
1726 
1727  return true;
1728  }
1729 
1730  if ( $this->getInterwiki() !== '' ) {
1731  wfLogWarning(
1732  $method . ': called on interwiki title ' . $this->getFullText() . ', returning '
1733  . $title->getFullText()
1734  );
1735 
1736  return true;
1737  }
1738 
1739  return false;
1740  }
1741 
1751  public function getOtherPage() {
1752  // NOTE: Depend on the methods in this class instead of their equivalent in NamespaceInfo,
1753  // until their semantics has become exactly the same.
1754  // See the discussion on T227817.
1755  if ( $this->isSpecialPage() ) {
1756  throw new MWException( 'Special pages cannot have other pages' );
1757  }
1758  if ( $this->isTalkPage() ) {
1759  return $this->getSubjectPage();
1760  } else {
1761  if ( !$this->canHaveTalkPage() ) {
1762  throw new MWException( "{$this->getPrefixedText()} does not have an other page" );
1763  }
1764  return $this->getTalkPage();
1765  }
1766  // TODO: replace the above with the code below:
1767  // return self::castFromLinkTarget(
1768  // MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) );
1769  }
1770 
1777  public function getDefaultNamespace() {
1778  wfDeprecated( __METHOD__, '1.37' );
1779  return $this->mDefaultNamespace;
1780  }
1781 
1789  public function getFragment() {
1790  return $this->mFragment;
1791  }
1792 
1799  public function hasFragment() {
1800  return $this->mFragment !== '';
1801  }
1802 
1808  public function getFragmentForURL() {
1809  if ( !$this->hasFragment() ) {
1810  return '';
1811  } elseif ( $this->isExternal() ) {
1812  // Note: If the interwiki is unknown, it's treated as a namespace on the local wiki,
1813  // so we treat it like a local interwiki.
1814  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
1815  if ( $interwiki && !$interwiki->isLocal() ) {
1816  return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment );
1817  }
1818  }
1819 
1820  return '#' . Sanitizer::escapeIdForLink( $this->mFragment );
1821  }
1822 
1833  public function setFragment( $fragment ) {
1834  $this->uncache();
1835  $this->mFragment = self::normalizeFragment( $fragment );
1836  }
1837 
1845  public function createFragmentTarget( $fragment ) {
1846  return self::makeTitle(
1847  $this->mNamespace,
1848  $this->getText(),
1849  $fragment,
1850  $this->mInterwiki
1851  );
1852  }
1853 
1860  private static function normalizeFragment( $fragment ) {
1861  if ( strpos( $fragment, '#' ) === 0 ) {
1862  $fragment = substr( $fragment, 1 );
1863  }
1864  return strtr( $fragment, '_', ' ' );
1865  }
1866 
1874  private function prefix( $name ) {
1875  $p = '';
1876  if ( $this->isExternal() ) {
1877  $p = $this->mInterwiki . ':';
1878  }
1879 
1880  if ( $this->mNamespace != 0 ) {
1881  $nsText = $this->getNsText();
1882 
1883  if ( $nsText === false ) {
1884  // See T165149. Awkward, but better than erroneously linking to the main namespace.
1885  $nsText = MediaWikiServices::getInstance()->getContentLanguage()->
1886  getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
1887  }
1888 
1889  $p .= $nsText . ':';
1890  }
1891  return $p . $name;
1892  }
1893 
1900  public function getPrefixedDBkey() {
1901  $s = $this->prefix( $this->mDbkeyform );
1902  $s = strtr( $s, ' ', '_' );
1903  return $s;
1904  }
1905 
1912  public function getPrefixedText() {
1913  if ( $this->prefixedText === null ) {
1914  $s = $this->prefix( $this->mTextform );
1915  $s = strtr( $s, '_', ' ' );
1916  $this->prefixedText = $s;
1917  }
1918  return $this->prefixedText;
1919  }
1920 
1926  public function __toString(): string {
1927  return $this->getPrefixedText();
1928  }
1929 
1936  public function getFullText() {
1937  $text = $this->getPrefixedText();
1938  if ( $this->hasFragment() ) {
1939  $text .= '#' . $this->mFragment;
1940  }
1941  return $text;
1942  }
1943 
1958  private function findSubpageDivider( $text, $dir ) {
1959  if ( $dir > 0 ) {
1960  // Skip leading slashes, but keep the last one when there is nothing but slashes
1961  $bottom = strspn( $text, '/', 0, -1 );
1962  $idx = strpos( $text, '/', $bottom );
1963  } else {
1964  // Any slash from the end can be a divider, as subpage names can be empty
1965  $idx = strrpos( $text, '/' );
1966  }
1967 
1968  // The first character can never be a divider, as that would result in an empty base
1969  return $idx === 0 ? false : $idx;
1970  }
1971 
1976  private function hasSubpagesEnabled() {
1977  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1978  hasSubpages( $this->mNamespace );
1979  }
1980 
1996  public function getRootText() {
1997  $text = $this->getText();
1998  if ( !$this->hasSubpagesEnabled() ) {
1999  return $text;
2000  }
2001 
2002  $firstSlashPos = $this->findSubpageDivider( $text, +1 );
2003  // Don't discard the real title if there's no subpage involved
2004  if ( $firstSlashPos === false ) {
2005  return $text;
2006  }
2007 
2008  return substr( $text, 0, $firstSlashPos );
2009  }
2010 
2023  public function getRootTitle() {
2024  $title = self::makeTitleSafe( $this->mNamespace, $this->getRootText() );
2025  Assert::postcondition(
2026  $title !== null,
2027  'makeTitleSafe() should always return a Title for the text returned by getRootText().'
2028  );
2029  return $title;
2030  }
2031 
2046  public function getBaseText() {
2047  $text = $this->getText();
2048  if ( !$this->hasSubpagesEnabled() ) {
2049  return $text;
2050  }
2051 
2052  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
2053  // Don't discard the real title if there's no subpage involved
2054  if ( $lastSlashPos === false ) {
2055  return $text;
2056  }
2057 
2058  return substr( $text, 0, $lastSlashPos );
2059  }
2060 
2073  public function getBaseTitle() {
2074  $title = self::makeTitleSafe( $this->mNamespace, $this->getBaseText() );
2075  Assert::postcondition(
2076  $title !== null,
2077  'makeTitleSafe() should always return a Title for the text returned by getBaseText().'
2078  );
2079  return $title;
2080  }
2081 
2093  public function getSubpageText() {
2094  $text = $this->getText();
2095  if ( !$this->hasSubpagesEnabled() ) {
2096  return $text;
2097  }
2098 
2099  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
2100  if ( $lastSlashPos === false ) {
2101  // T256922 - Return the title text if no subpages
2102  return $text;
2103  }
2104  return substr( $text, $lastSlashPos + 1 );
2105  }
2106 
2120  public function getSubpage( $text ) {
2121  return self::makeTitleSafe(
2122  $this->mNamespace,
2123  $this->getText() . '/' . $text,
2124  '',
2125  $this->mInterwiki
2126  );
2127  }
2128 
2134  public function getSubpageUrlForm() {
2135  $text = $this->getSubpageText();
2136  $text = wfUrlencode( strtr( $text, ' ', '_' ) );
2137  return $text;
2138  }
2139 
2145  public function getPrefixedURL() {
2146  $s = $this->prefix( $this->mDbkeyform );
2147  $s = wfUrlencode( strtr( $s, ' ', '_' ) );
2148  return $s;
2149  }
2150 
2164  private static function fixUrlQueryArgs( $query, $query2 = false ) {
2165  if ( $query2 !== false ) {
2166  wfDeprecatedMsg( "Title::get{Canonical,Full,Link,Local,Internal}URL " .
2167  "method called with a second parameter is deprecated since MediaWiki 1.19. " .
2168  "Add your parameter to an array passed as the first parameter.", "1.19" );
2169  }
2170  if ( is_array( $query ) ) {
2171  $query = wfArrayToCgi( $query );
2172  }
2173  if ( $query2 ) {
2174  if ( is_string( $query2 ) ) {
2175  // $query2 is a string, we will consider this to be
2176  // a deprecated $variant argument and add it to the query
2177  $query2 = wfArrayToCgi( [ 'variant' => $query2 ] );
2178  } else {
2179  $query2 = wfArrayToCgi( $query2 );
2180  }
2181  // If we have $query content add a & to it first
2182  if ( $query ) {
2183  $query .= '&';
2184  }
2185  // Now append the queries together
2186  $query .= $query2;
2187  }
2188  return $query;
2189  }
2190 
2202  public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
2203  $query = self::fixUrlQueryArgs( $query, $query2 );
2204 
2205  # Hand off all the decisions on urls to getLocalURL
2206  $url = $this->getLocalURL( $query );
2207 
2208  # Expand the url to make it a full url. Note that getLocalURL has the
2209  # potential to output full urls for a variety of reasons, so we use
2210  # wfExpandUrl instead of simply prepending $wgServer
2211  $url = wfExpandUrl( $url, $proto );
2212 
2213  # Finally, add the fragment.
2214  $url .= $this->getFragmentForURL();
2215  Hooks::runner()->onGetFullURL( $this, $url, $query );
2216  return $url;
2217  }
2218 
2235  public function getFullUrlForRedirect( $query = '', $proto = PROTO_CURRENT ) {
2236  $target = $this;
2237  if ( $this->isExternal() ) {
2238  $target = SpecialPage::getTitleFor(
2239  'GoToInterwiki',
2240  $this->getPrefixedDBkey()
2241  );
2242  }
2243  return $target->getFullURL( $query, false, $proto );
2244  }
2245 
2269  public function getLocalURL( $query = '', $query2 = false ) {
2271 
2272  $query = self::fixUrlQueryArgs( $query, $query2 );
2273 
2274  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
2275  if ( $interwiki ) {
2276  $namespace = $this->getNsText();
2277  if ( $namespace != '' ) {
2278  # Can this actually happen? Interwikis shouldn't be parsed.
2279  # Yes! It can in interwiki transclusion. But... it probably shouldn't.
2280  $namespace .= ':';
2281  }
2282  $url = $interwiki->getURL( $namespace . $this->mDbkeyform );
2283  $url = wfAppendQuery( $url, $query );
2284  } else {
2285  $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
2286  if ( $query == '' ) {
2287  if ( $wgMainPageIsDomainRoot && $this->isMainPage() ) {
2288  $url = '/';
2289  } else {
2290  $url = str_replace( '$1', $dbkey, $wgArticlePath );
2291  }
2292  Hooks::runner()->onGetLocalURL__Article( $this, $url );
2293  } else {
2295  $url = false;
2296  $matches = [];
2297 
2299 
2300  if ( $articlePaths
2301  && preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
2302  ) {
2303  $action = urldecode( $matches[2] );
2304  if ( isset( $articlePaths[$action] ) ) {
2305  $query = $matches[1];
2306  if ( isset( $matches[4] ) ) {
2307  $query .= $matches[4];
2308  }
2309  $url = str_replace( '$1', $dbkey, $articlePaths[$action] );
2310  if ( $query != '' ) {
2311  $url = wfAppendQuery( $url, $query );
2312  }
2313  }
2314  }
2315 
2316  if ( $url === false
2318  && preg_match( '/^variant=([^&]*)$/', $query, $matches )
2319  && $this->getPageLanguage()->equals(
2320  MediaWikiServices::getInstance()->getContentLanguage() )
2321  && $this->getPageLanguageConverter()->hasVariants()
2322  ) {
2323  $variant = urldecode( $matches[1] );
2324  if ( $this->getPageLanguageConverter()->hasVariant( $variant ) ) {
2325  // Only do the variant replacement if the given variant is a valid
2326  // variant for the page's language.
2327  $url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath );
2328  $url = str_replace( '$1', $dbkey, $url );
2329  }
2330  }
2331 
2332  if ( $url === false ) {
2333  if ( $query == '-' ) {
2334  $query = '';
2335  }
2336  $url = "{$wgScript}?title={$dbkey}&{$query}";
2337  }
2338  }
2339  Hooks::runner()->onGetLocalURL__Internal( $this, $url, $query );
2340 
2341  // @todo FIXME: This causes breakage in various places when we
2342  // actually expected a local URL and end up with dupe prefixes.
2343  if ( $wgRequest->getRawVal( 'action' ) == 'render' ) {
2344  LoggerFactory::getInstance( 'T263581' )
2345  ->debug(
2346  "Title::getLocalURL called from render action",
2347  [
2348  'title' => $this->getPrefixedDBkey(),
2349  'exception' => new Exception()
2350  ]
2351  );
2352  $url = $wgServer . $url;
2353  }
2354  }
2355 
2356  Hooks::runner()->onGetLocalURL( $this, $url, $query );
2357  return $url;
2358  }
2359 
2377  public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
2378  if ( $this->isExternal() || $proto !== false ) {
2379  $ret = $this->getFullURL( $query, $query2, $proto );
2380  } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
2381  $ret = $this->getFragmentForURL();
2382  } else {
2383  $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
2384  }
2385  return $ret;
2386  }
2387 
2402  public function getInternalURL( $query = '', $query2 = false ) {
2403  global $wgInternalServer, $wgServer;
2404  $query = self::fixUrlQueryArgs( $query, $query2 );
2405  $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
2406  $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP );
2407  Hooks::runner()->onGetInternalURL( $this, $url, $query );
2408  return $url;
2409  }
2410 
2424  public function getCanonicalURL( $query = '', $query2 = false ) {
2425  $query = self::fixUrlQueryArgs( $query, $query2 );
2426  $url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL );
2427  Hooks::runner()->onGetCanonicalURL( $this, $url, $query );
2428  return $url;
2429  }
2430 
2436  public function getEditURL() {
2437  if ( $this->isExternal() ) {
2438  return '';
2439  }
2440  $s = $this->getLocalURL( 'action=edit' );
2441 
2442  return $s;
2443  }
2444 
2455  public static function getFilteredRestrictionTypes( $exists = true ) {
2456  return MediaWikiServices::getInstance()
2457  ->getRestrictionStore()
2458  ->listAllRestrictionTypes( $exists );
2459  }
2460 
2468  public function getRestrictionTypes() {
2469  return MediaWikiServices::getInstance()
2470  ->getRestrictionStore()
2471  ->listApplicableRestrictionTypes( $this );
2472  }
2473 
2483  public function getTitleProtection() {
2484  return MediaWikiServices::getInstance()->getRestrictionStore()->getCreateProtection( $this )
2485  ?: false;
2486  }
2487 
2493  public function deleteTitleProtection() {
2494  MediaWikiServices::getInstance()->getRestrictionStore()->deleteCreateProtection( $this );
2495  }
2496 
2506  public function isSemiProtected( $action = 'edit' ) {
2507  return MediaWikiServices::getInstance()->getRestrictionStore()->isSemiProtected(
2508  $this, $action
2509  );
2510  }
2511 
2521  public function isProtected( $action = '' ) {
2522  return MediaWikiServices::getInstance()->getRestrictionStore()->isProtected(
2523  $this, $action
2524  );
2525  }
2526 
2535  public function isNamespaceProtected( User $user ) {
2536  global $wgNamespaceProtection;
2537 
2538  wfDeprecated( __METHOD__, '1.34' );
2539 
2540  if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
2541  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2542  foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
2543  if ( !$permissionManager->userHasRight( $user, $right ) ) {
2544  return true;
2545  }
2546  }
2547  }
2548  return false;
2549  }
2550 
2558  public function isCascadeProtected() {
2559  return MediaWikiServices::getInstance()->getRestrictionStore()->isCascadeProtected( $this );
2560  }
2561 
2572  return MediaWikiServices::getInstance()->getRestrictionStore()
2573  ->areCascadeProtectionSourcesLoaded( $this );
2574  }
2575 
2591  public function getCascadeProtectionSources( $getPages = true ) {
2592  $restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
2593  if ( !$getPages ) {
2594  return [ $restrictionStore->isCascadeProtected( $this ), [] ];
2595  }
2596 
2597  $ret = $restrictionStore->getCascadeProtectionSources( $this );
2598  $ret[0] = array_map( 'Title::castFromPageIdentity', $ret[0] );
2599  return $ret;
2600  }
2601 
2611  public function areRestrictionsLoaded() {
2612  return MediaWikiServices::getInstance()
2613  ->getRestrictionStore()
2614  ->areRestrictionsLoaded( $this );
2615  }
2616 
2628  public function getRestrictions( $action ) {
2629  return MediaWikiServices::getInstance()->getRestrictionStore()->getRestrictions( $this, $action );
2630  }
2631 
2641  public function getAllRestrictions() {
2642  return MediaWikiServices::getInstance()->getRestrictionStore()->getAllRestrictions( $this );
2643  }
2644 
2654  public function getRestrictionExpiry( $action ) {
2655  return MediaWikiServices::getInstance()->getRestrictionStore()->getRestrictionExpiry(
2656  $this, $action
2657  ) ?? false;
2658  }
2659 
2667  public function areRestrictionsCascading() {
2668  return MediaWikiServices::getInstance()
2669  ->getRestrictionStore()
2670  ->areRestrictionsCascading( $this );
2671  }
2672 
2686  public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
2687  MediaWikiServices::getInstance()->getRestrictionStore()->loadRestrictionsFromRows(
2688  $this, $rows, $oldFashionedRestrictions
2689  );
2690  }
2691 
2704  public function loadRestrictions( $oldFashionedRestrictions = null, $flags = 0 ) {
2705  MediaWikiServices::getInstance()->getRestrictionStore()->loadRestrictions( $this, $flags,
2706  $oldFashionedRestrictions );
2707  }
2708 
2715  public function flushRestrictions() {
2716  MediaWikiServices::getInstance()->getRestrictionStore()->flushRestrictions( $this );
2717  }
2718 
2724  public static function purgeExpiredRestrictions() {
2725  if ( wfReadOnly() ) {
2726  return;
2727  }
2728 
2730  wfGetDB( DB_PRIMARY ),
2731  __METHOD__,
2732  static function ( IDatabase $dbw, $fname ) {
2733  $config = MediaWikiServices::getInstance()->getMainConfig();
2734  $ids = $dbw->selectFieldValues(
2735  'page_restrictions',
2736  'pr_id',
2737  [ 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
2738  $fname,
2739  [ 'LIMIT' => $config->get( 'UpdateRowsPerQuery' ) ] // T135470
2740  );
2741  if ( $ids ) {
2742  $dbw->delete( 'page_restrictions', [ 'pr_id' => $ids ], $fname );
2743  }
2744  }
2745  ) );
2746 
2748  wfGetDB( DB_PRIMARY ),
2749  __METHOD__,
2750  static function ( IDatabase $dbw, $fname ) {
2751  $dbw->delete(
2752  'protected_titles',
2753  [ 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
2754  $fname
2755  );
2756  }
2757  ) );
2758  }
2759 
2765  public function hasSubpages() {
2766  if (
2767  !MediaWikiServices::getInstance()->getNamespaceInfo()->
2768  hasSubpages( $this->mNamespace )
2769  ) {
2770  # Duh
2771  return false;
2772  }
2773 
2774  # We dynamically add a member variable for the purpose of this method
2775  # alone to cache the result. There's no point in having it hanging
2776  # around uninitialized in every Title object; therefore we only add it
2777  # if needed and don't declare it statically.
2778  if ( $this->mHasSubpages === null ) {
2779  $subpages = $this->getSubpages( 1 );
2780  $this->mHasSubpages = $subpages instanceof TitleArray && $subpages->count();
2781  }
2782 
2783  return $this->mHasSubpages;
2784  }
2785 
2793  public function getSubpages( $limit = -1 ) {
2794  if (
2795  !MediaWikiServices::getInstance()->getNamespaceInfo()->
2796  hasSubpages( $this->mNamespace )
2797  ) {
2798  return [];
2799  }
2800 
2801  $options = [];
2802  if ( $limit > -1 ) {
2803  $options['LIMIT'] = $limit;
2804  }
2805 
2806  $pageStore = MediaWikiServices::getInstance()->getPageStore();
2807  $query = $pageStore->newSelectQueryBuilder()
2808  ->fields( $pageStore->getSelectFields() )
2809  ->whereTitlePrefix( $this->getNamespace(), $this->getDBkey() . '/' )
2810  ->options( $options )
2811  ->caller( __METHOD__ );
2812 
2813  return TitleArray::newFromResult( $query->fetchResultSet() );
2814  }
2815 
2822  public function isDeleted() {
2823  return $this->getDeletedEditsCount();
2824  }
2825 
2832  public function getDeletedEditsCount() {
2833  if ( $this->mNamespace < 0 ) {
2834  $n = 0;
2835  } else {
2836  $dbr = wfGetDB( DB_REPLICA );
2837 
2838  $n = $dbr->selectField( 'archive', 'COUNT(*)',
2839  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
2840  __METHOD__
2841  );
2842  if ( $this->mNamespace === NS_FILE ) {
2843  $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
2844  [ 'fa_name' => $this->mDbkeyform ],
2845  __METHOD__
2846  );
2847  }
2848  }
2849  return (int)$n;
2850  }
2851 
2858  public function isDeletedQuick() {
2859  return $this->hasDeletedEdits();
2860  }
2861 
2868  public function hasDeletedEdits() {
2869  if ( $this->mNamespace < 0 ) {
2870  return false;
2871  }
2872  $dbr = wfGetDB( DB_REPLICA );
2873  $deleted = (bool)$dbr->selectField( 'archive', '1',
2874  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
2875  __METHOD__
2876  );
2877  if ( !$deleted && $this->mNamespace === NS_FILE ) {
2878  $deleted = (bool)$dbr->selectField( 'filearchive', '1',
2879  [ 'fa_name' => $this->mDbkeyform ],
2880  __METHOD__
2881  );
2882  }
2883  return $deleted;
2884  }
2885 
2893  public function getArticleID( $flags = 0 ) {
2894  if ( !$this->canExist() ) {
2895  $this->mArticleID = 0;
2896 
2897  return $this->mArticleID;
2898  }
2899 
2900  if ( $flags & self::GAID_FOR_UPDATE ) {
2901  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2902  $linkCache->clearLink( $this );
2903  $this->mArticleID = $linkCache->addLinkObj( $this, self::READ_LATEST );
2904  } elseif ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
2905  // If mArticleID is >0, pageCond() will use it, making it impossible
2906  // for the call below to return a different result, e.g. after a
2907  // page move.
2908  $this->mArticleID = -1;
2909  $this->mArticleID = (int)$this->loadFieldFromDB( 'page_id', $flags );
2910  } elseif ( $this->mArticleID == -1 ) {
2911  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2912  $this->mArticleID = $linkCache->addLinkObj( $this );
2913  }
2914 
2915  return $this->mArticleID;
2916  }
2917 
2932  public function isRedirect( $flags = 0 ) {
2933  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
2934  $this->mRedirect = (bool)$this->loadFieldFromDB( 'page_is_redirect', $flags );
2935  } elseif ( $this->mRedirect === null ) {
2936  if ( $this->getArticleID( $flags ) ) {
2937  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2938  $linkCache->addLinkObj( $this ); // in case we already had an article ID
2939  // Note that LinkCache returns null if it thinks the page does not exist;
2940  // always trust the state of LinkCache over that of this Title instance.
2941  $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
2942  } else {
2943  $this->mRedirect = false;
2944  }
2945  }
2946 
2947  return $this->mRedirect;
2948  }
2949 
2957  public function getLength( $flags = 0 ) {
2958  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
2959  $this->mLength = (int)$this->loadFieldFromDB( 'page_len', $flags );
2960  } else {
2961  if ( $this->mLength != -1 ) {
2962  return $this->mLength;
2963  } elseif ( !$this->getArticleID( $flags ) ) {
2964  $this->mLength = 0;
2965  return $this->mLength;
2966  }
2967 
2968  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2969  $linkCache->addLinkObj( $this ); // in case we already had an article ID
2970  // Note that LinkCache returns null if it thinks the page does not exist;
2971  // always trust the state of LinkCache over that of this Title instance.
2972  $this->mLength = (int)$linkCache->getGoodLinkFieldObj( $this, 'length' );
2973  }
2974 
2975  return $this->mLength;
2976  }
2977 
2984  public function getLatestRevID( $flags = 0 ) {
2985  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
2986  $this->mLatestID = (int)$this->loadFieldFromDB( 'page_latest', $flags );
2987  } else {
2988  if ( $this->mLatestID !== false ) {
2989  return (int)$this->mLatestID;
2990  } elseif ( !$this->getArticleID( $flags ) ) {
2991  $this->mLatestID = 0;
2992 
2993  return $this->mLatestID;
2994  }
2995 
2996  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2997  $linkCache->addLinkObj( $this ); // in case we already had an article ID
2998  // Note that LinkCache returns null if it thinks the page does not exist;
2999  // always trust the state of LinkCache over that of this Title instance.
3000  $this->mLatestID = (int)$linkCache->getGoodLinkFieldObj( $this, 'revision' );
3001  }
3002 
3003  return $this->mLatestID;
3004  }
3005 
3019  public function resetArticleID( $id ) {
3020  if ( $id === false ) {
3021  $this->mArticleID = -1;
3022  } else {
3023  $this->mArticleID = (int)$id;
3024  }
3025  $this->mRedirect = null;
3026  $this->mLength = -1;
3027  $this->mLatestID = false;
3028  $this->mContentModel = false;
3029  $this->mForcedContentModel = false;
3030  $this->mEstimateRevisions = null;
3031  $this->mPageLanguage = null;
3032  $this->mDbPageLanguage = false;
3033  $this->mIsBigDeletion = null;
3034 
3035  MediaWikiServices::getInstance()->getLinkCache()->clearLink( $this );
3036  MediaWikiServices::getInstance()->getRestrictionStore()->flushRestrictions( $this );
3037  }
3038 
3039  public static function clearCaches() {
3040  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3041  $linkCache->clear();
3042 
3044  $titleCache->clear();
3045  }
3046 
3054  public static function capitalize( $text, $ns = NS_MAIN ) {
3055  $services = MediaWikiServices::getInstance();
3056  if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) {
3057  return $services->getContentLanguage()->ucfirst( $text );
3058  } else {
3059  return $text;
3060  }
3061  }
3062 
3079  private function secureAndSplit( $text, $defaultNamespace = null ) {
3080  if ( $defaultNamespace === null ) {
3081  $defaultNamespace = $this->mDefaultNamespace;
3082  }
3083 
3084  // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
3085  // the parsing code with Title, while avoiding massive refactoring.
3086  // @todo: get rid of secureAndSplit, refactor parsing code.
3087  // @note: getTitleParser() returns a TitleParser implementation which does not have a
3088  // splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
3090  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
3091  '@phan-var MediaWikiTitleCodec $titleCodec';
3092  // MalformedTitleException can be thrown here
3093  $parts = $titleCodec->splitTitleString( $text, $defaultNamespace );
3094 
3095  # Fill fields
3096  $this->setFragment( '#' . $parts['fragment'] );
3097  $this->mInterwiki = $parts['interwiki'];
3098  $this->mLocalInterwiki = $parts['local_interwiki'];
3099  $this->mNamespace = $parts['namespace'];
3100  $this->mDefaultNamespace = $defaultNamespace;
3101 
3102  $this->mDbkeyform = $parts['dbkey'];
3103  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
3104  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
3105 
3106  // splitTitleString() guarantees that this title is valid.
3107  $this->mIsValid = true;
3108 
3109  # We already know that some pages won't be in the database!
3110  if ( $this->isExternal() || $this->isSpecialPage() || $this->mTextform === '' ) {
3111  $this->mArticleID = 0;
3112  }
3113  }
3114 
3127  public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3128  if ( count( $options ) > 0 ) {
3129  $db = wfGetDB( DB_PRIMARY );
3130  } else {
3131  $db = wfGetDB( DB_REPLICA );
3132  }
3133 
3134  $res = $db->select(
3135  [ 'page', $table ],
3137  [
3138  "{$prefix}_from=page_id",
3139  "{$prefix}_namespace" => $this->mNamespace,
3140  "{$prefix}_title" => $this->mDbkeyform ],
3141  __METHOD__,
3142  $options
3143  );
3144 
3145  $retVal = [];
3146  if ( $res->numRows() ) {
3147  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3148  foreach ( $res as $row ) {
3149  $titleObj = self::makeTitle( $row->page_namespace, $row->page_title );
3150  if ( $titleObj ) {
3151  $linkCache->addGoodLinkObjFromRow( $titleObj, $row );
3152  $retVal[] = $titleObj;
3153  }
3154  }
3155  }
3156  return $retVal;
3157  }
3158 
3169  public function getTemplateLinksTo( $options = [] ) {
3170  return $this->getLinksTo( $options, 'templatelinks', 'tl' );
3171  }
3172 
3185  public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3186  $id = $this->getArticleID();
3187 
3188  # If the page doesn't exist; there can't be any link from this page
3189  if ( !$id ) {
3190  return [];
3191  }
3192 
3193  $db = wfGetDB( DB_REPLICA );
3194 
3195  $blNamespace = "{$prefix}_namespace";
3196  $blTitle = "{$prefix}_title";
3197 
3198  $pageQuery = WikiPage::getQueryInfo();
3199  $res = $db->select(
3200  [ $table, 'nestpage' => $pageQuery['tables'] ],
3201  array_merge(
3202  [ $blNamespace, $blTitle ],
3203  $pageQuery['fields']
3204  ),
3205  [ "{$prefix}_from" => $id ],
3206  __METHOD__,
3207  $options,
3208  [ 'nestpage' => [
3209  'LEFT JOIN',
3210  [ "page_namespace=$blNamespace", "page_title=$blTitle" ]
3211  ] ] + $pageQuery['joins']
3212  );
3213 
3214  $retVal = [];
3215  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3216  foreach ( $res as $row ) {
3217  if ( $row->page_id ) {
3218  $titleObj = self::newFromRow( $row );
3219  } else {
3220  $titleObj = self::makeTitle( $row->$blNamespace, $row->$blTitle );
3221  $linkCache->addBadLinkObj( $titleObj );
3222  }
3223  $retVal[] = $titleObj;
3224  }
3225 
3226  return $retVal;
3227  }
3228 
3239  public function getTemplateLinksFrom( $options = [] ) {
3240  return $this->getLinksFrom( $options, 'templatelinks', 'tl' );
3241  }
3242 
3251  public function getBrokenLinksFrom() {
3252  if ( $this->getArticleID() == 0 ) {
3253  # All links from article ID 0 are false positives
3254  return [];
3255  }
3256 
3257  $dbr = wfGetDB( DB_REPLICA );
3258  $res = $dbr->select(
3259  [ 'page', 'pagelinks' ],
3260  [ 'pl_namespace', 'pl_title' ],
3261  [
3262  'pl_from' => $this->getArticleID(),
3263  'page_namespace IS NULL'
3264  ],
3265  __METHOD__, [],
3266  [
3267  'page' => [
3268  'LEFT JOIN',
3269  [ 'pl_namespace=page_namespace', 'pl_title=page_title' ]
3270  ]
3271  ]
3272  );
3273 
3274  $retVal = [];
3275  foreach ( $res as $row ) {
3276  $retVal[] = self::makeTitle( $row->pl_namespace, $row->pl_title );
3277  }
3278  return $retVal;
3279  }
3280 
3287  public function getCdnUrls() {
3288  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3289  return $htmlCache->getUrls( $this );
3290  }
3291 
3296  public function purgeSquid() {
3297  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3298  $htmlCache->purgeTitleUrls( $this, $htmlCache::PURGE_INTENT_TXROUND_REFLECTED );
3299  }
3300 
3308  public function isSingleRevRedirect() {
3309  $dbw = wfGetDB( DB_PRIMARY );
3310  $dbw->startAtomic( __METHOD__ );
3311 
3312  $row = $dbw->selectRow(
3313  'page',
3314  self::getSelectFields(),
3315  $this->pageCond(),
3316  __METHOD__,
3317  [ 'FOR UPDATE' ]
3318  );
3319  // Update the cached fields
3320  $this->loadFromRow( $row );
3321 
3322  if ( $this->mRedirect && $this->mLatestID ) {
3323  $isSingleRevRedirect = !$dbw->selectField(
3324  'revision',
3325  '1',
3326  [ 'rev_page' => $this->mArticleID, 'rev_id != ' . (int)$this->mLatestID ],
3327  __METHOD__,
3328  [ 'FOR UPDATE' ]
3329  );
3330  } else {
3331  $isSingleRevRedirect = false;
3332  }
3333 
3334  $dbw->endAtomic( __METHOD__ );
3335 
3336  return $isSingleRevRedirect;
3337  }
3338 
3346  public function getParentCategories() {
3347  $data = [];
3348 
3349  $titleKey = $this->getArticleID();
3350 
3351  if ( $titleKey === 0 ) {
3352  return $data;
3353  }
3354 
3355  $dbr = wfGetDB( DB_REPLICA );
3356 
3357  $res = $dbr->select(
3358  'categorylinks',
3359  'cl_to',
3360  [ 'cl_from' => $titleKey ],
3361  __METHOD__
3362  );
3363 
3364  if ( $res->numRows() > 0 ) {
3365  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
3366  foreach ( $res as $row ) {
3367  // $data[] = Title::newFromText( $contLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
3368  $data[$contLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] =
3369  $this->getFullText();
3370  }
3371  }
3372  return $data;
3373  }
3374 
3381  public function getParentCategoryTree( $children = [] ) {
3382  $stack = [];
3383  $parents = $this->getParentCategories();
3384 
3385  if ( $parents ) {
3386  foreach ( $parents as $parent => $current ) {
3387  if ( array_key_exists( $parent, $children ) ) {
3388  # Circular reference
3389  $stack[$parent] = [];
3390  } else {
3391  $nt = self::newFromText( $parent );
3392  if ( $nt ) {
3393  $stack[$parent] = $nt->getParentCategoryTree( $children + [ $parent => 1 ] );
3394  }
3395  }
3396  }
3397  }
3398 
3399  return $stack;
3400  }
3401 
3408  public function pageCond() {
3409  if ( $this->mArticleID > 0 ) {
3410  // PK avoids secondary lookups in InnoDB, shouldn't hurt other DBs
3411  return [ 'page_id' => $this->mArticleID ];
3412  } else {
3413  return [ 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform ];
3414  }
3415  }
3416 
3422  public function isNewPage() {
3423  $dbr = wfGetDB( DB_REPLICA );
3424  return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ );
3425  }
3426 
3433  public function isBigDeletion() {
3434  global $wgDeleteRevisionsLimit;
3435 
3436  if ( !$wgDeleteRevisionsLimit ) {
3437  return false;
3438  }
3439 
3440  if ( $this->mIsBigDeletion === null ) {
3441  $dbr = wfGetDB( DB_REPLICA );
3442 
3443  $revCount = $dbr->selectRowCount(
3444  'revision',
3445  '1',
3446  [ 'rev_page' => $this->getArticleID() ],
3447  __METHOD__,
3448  [ 'LIMIT' => $wgDeleteRevisionsLimit + 1 ]
3449  );
3450 
3451  $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit;
3452  }
3453 
3454  return $this->mIsBigDeletion;
3455  }
3456 
3462  public function estimateRevisionCount() {
3463  if ( !$this->exists() ) {
3464  return 0;
3465  }
3466 
3467  if ( $this->mEstimateRevisions === null ) {
3468  $dbr = wfGetDB( DB_REPLICA );
3469  $this->mEstimateRevisions = $dbr->estimateRowCount( 'revision', '*',
3470  [ 'rev_page' => $this->getArticleID() ], __METHOD__ );
3471  }
3472 
3474  }
3475 
3490  public function equals( object $other ) {
3491  if ( $other instanceof Title ) {
3492  // NOTE: In contrast to isSameLinkAs(), this ignores the fragment part!
3493  // NOTE: In contrast to isSamePageAs(), this ignores the page ID!
3494  // NOTE: === is necessary for proper matching of number-like titles
3495  return $this->getInterwiki() === $other->getInterwiki()
3496  && $this->getNamespace() === $other->getNamespace()
3497  && $this->getDBkey() === $other->getDBkey();
3498  } else {
3499  return false;
3500  }
3501  }
3502 
3510  public function isSameLinkAs( LinkTarget $other ) {
3511  // NOTE: keep in sync with TitleValue::isSameLinkAs()!
3512  // NOTE: === is needed for number-like titles
3513  return ( $other->getInterwiki() === $this->getInterwiki() )
3514  && ( $other->getDBkey() === $this->getDBkey() )
3515  && ( $other->getNamespace() === $this->getNamespace() )
3516  && ( $other->getFragment() === $this->getFragment() );
3517  }
3518 
3526  public function isSamePageAs( PageReference $other ): bool {
3527  // NOTE: keep in sync with PageIdentityValue::isSamePageAs()!
3528 
3529  if ( $other->getWikiId() !== $this->getWikiId() ) {
3530  return false;
3531  }
3532 
3533  if ( $other->getNamespace() !== $this->getNamespace()
3534  || $other->getDBkey() !== $this->getDBkey() ) {
3535  return false;
3536  }
3537 
3538  return true;
3539  }
3540 
3547  public function isSubpageOf( Title $title ) {
3548  return $this->mInterwiki === $title->mInterwiki
3549  && $this->mNamespace == $title->mNamespace
3550  && strpos( $this->mDbkeyform, $title->mDbkeyform . '/' ) === 0;
3551  }
3552 
3563  public function exists( $flags = 0 ): bool {
3564  $exists = $this->getArticleID( $flags ) != 0;
3565  Hooks::runner()->onTitleExists( $this, $exists );
3566  return $exists;
3567  }
3568 
3585  public function isAlwaysKnown() {
3586  $isKnown = null;
3587 
3598  Hooks::runner()->onTitleIsAlwaysKnown( $this, $isKnown );
3599 
3600  if ( $isKnown !== null ) {
3601  return $isKnown;
3602  }
3603 
3604  if ( $this->isExternal() ) {
3605  return true; // any interwiki link might be viewable, for all we know
3606  }
3607 
3608  $services = MediaWikiServices::getInstance();
3609  switch ( $this->mNamespace ) {
3610  case NS_MEDIA:
3611  case NS_FILE:
3612  // file exists, possibly in a foreign repo
3613  return (bool)$services->getRepoGroup()->findFile( $this );
3614  case NS_SPECIAL:
3615  // valid special page
3616  return $services->getSpecialPageFactory()->exists( $this->mDbkeyform );
3617  case NS_MAIN:
3618  // selflink, possibly with fragment
3619  return $this->mDbkeyform == '';
3620  case NS_MEDIAWIKI:
3621  // known system message
3622  return $this->hasSourceText() !== false;
3623  default:
3624  return false;
3625  }
3626  }
3627 
3639  public function isKnown() {
3640  return $this->isAlwaysKnown() || $this->exists();
3641  }
3642 
3648  public function hasSourceText() {
3649  if ( $this->exists() ) {
3650  return true;
3651  }
3652 
3653  if ( $this->mNamespace === NS_MEDIAWIKI ) {
3654  $services = MediaWikiServices::getInstance();
3655  // If the page doesn't exist but is a known system message, default
3656  // message content will be displayed, same for language subpages-
3657  // Use always content language to avoid loading hundreds of languages
3658  // to get the link color.
3659  $contLang = $services->getContentLanguage();
3660  list( $name, ) = $services->getMessageCache()->figureMessage(
3661  $contLang->lcfirst( $this->getText() )
3662  );
3663  $message = wfMessage( $name )->inLanguage( $contLang )->useDatabase( false );
3664  return $message->exists();
3665  }
3666 
3667  return false;
3668  }
3669 
3707  public function getDefaultMessageText() {
3708  if ( $this->mNamespace !== NS_MEDIAWIKI ) { // Just in case
3709  return false;
3710  }
3711 
3712  list( $name, $lang ) = MediaWikiServices::getInstance()->getMessageCache()->figureMessage(
3713  MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $this->getText() )
3714  );
3715  $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
3716 
3717  if ( $message->exists() ) {
3718  return $message->plain();
3719  } else {
3720  return false;
3721  }
3722  }
3723 
3730  public function invalidateCache( $purgeTime = null ) {
3731  if ( wfReadOnly() ) {
3732  return false;
3733  }
3734  if ( $this->mArticleID === 0 ) {
3735  // avoid gap locking if we know it's not there
3736  return true;
3737  }
3738 
3739  $conds = $this->pageCond();
3741  new AutoCommitUpdate(
3742  wfGetDB( DB_PRIMARY ),
3743  __METHOD__,
3744  function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) {
3745  $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
3746  $dbw->update(
3747  'page',
3748  [ 'page_touched' => $dbTimestamp ],
3749  $conds + [ 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ],
3750  $fname
3751  );
3752 
3753  MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $this );
3754 
3756  $this, null, null, $dbw->getDomainID() );
3757  }
3758  ),
3759  DeferredUpdates::PRESEND
3760  );
3761 
3762  return true;
3763  }
3764 
3770  public function touchLinks() {
3771  $jobs = [];
3773  $this,
3774  'pagelinks',
3775  [ 'causeAction' => 'page-touch' ]
3776  );
3777  if ( $this->mNamespace === NS_CATEGORY ) {
3779  $this,
3780  'categorylinks',
3781  [ 'causeAction' => 'category-touch' ]
3782  );
3783  }
3784 
3785  JobQueueGroup::singleton()->lazyPush( $jobs );
3786  }
3787 
3794  public function getTouched( $db = null ) {
3795  if ( $db === null ) {
3796  $db = wfGetDB( DB_REPLICA );
3797  }
3798  $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ );
3799  return $touched;
3800  }
3801 
3810  public function getNotificationTimestamp( User $user ) {
3811  return MediaWikiServices::getInstance()
3812  ->getWatchlistManager()
3813  ->getTitleNotificationTimestamp( $user, $this );
3814  }
3815 
3822  public function getNamespaceKey( $prepend = 'nstab-' ) {
3823  // Gets the subject namespace of this title
3824  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
3825  $subjectNS = $nsInfo->getSubject( $this->mNamespace );
3826  // Prefer canonical namespace name for HTML IDs
3827  $namespaceKey = $nsInfo->getCanonicalName( $subjectNS );
3828  if ( $namespaceKey === false ) {
3829  // Fallback to localised text
3830  $namespaceKey = $this->getSubjectNsText();
3831  }
3832  // Makes namespace key lowercase
3833  $namespaceKey = MediaWikiServices::getInstance()->getContentLanguage()->lc( $namespaceKey );
3834  // Uses main
3835  if ( $namespaceKey == '' ) {
3836  $namespaceKey = 'main';
3837  }
3838  // Changes file to image for backwards compatibility
3839  if ( $namespaceKey == 'file' ) {
3840  $namespaceKey = 'image';
3841  }
3842  return $prepend . $namespaceKey;
3843  }
3844 
3851  public function getRedirectsHere( $ns = null ) {
3852  $redirs = [];
3853 
3854  $dbr = wfGetDB( DB_REPLICA );
3855  $where = [
3856  'rd_namespace' => $this->mNamespace,
3857  'rd_title' => $this->mDbkeyform,
3858  'rd_from = page_id'
3859  ];
3860  if ( $this->isExternal() ) {
3861  $where['rd_interwiki'] = $this->mInterwiki;
3862  } else {
3863  $where[] = 'rd_interwiki = ' . $dbr->addQuotes( '' ) . ' OR rd_interwiki IS NULL';
3864  }
3865  if ( $ns !== null ) {
3866  $where['page_namespace'] = $ns;
3867  }
3868 
3869  $res = $dbr->select(
3870  [ 'redirect', 'page' ],
3871  [ 'page_namespace', 'page_title' ],
3872  $where,
3873  __METHOD__
3874  );
3875 
3876  foreach ( $res as $row ) {
3877  $redirs[] = self::newFromRow( $row );
3878  }
3879  return $redirs;
3880  }
3881 
3887  public function isValidRedirectTarget() {
3889 
3890  if ( $this->isSpecialPage() ) {
3891  // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
3892  if ( $this->isSpecial( 'Userlogout' ) ) {
3893  return false;
3894  }
3895 
3896  foreach ( $wgInvalidRedirectTargets as $target ) {
3897  if ( $this->isSpecial( $target ) ) {
3898  return false;
3899  }
3900  }
3901 
3902  return true;
3903  } elseif ( $this->getDBkey() === '' ) {
3904  // relative section links are not valid redirect targets (T278367)
3905  return false;
3906  }
3907 
3908  return $this->isValid();
3909  }
3910 
3918  public function getBacklinkCache(): BacklinkCache {
3919  wfDeprecated( __METHOD__, '1.37' );
3920  return MediaWikiServices::getInstance()->getBacklinkCacheFactory()
3921  ->getBacklinkCache( $this );
3922  }
3923 
3929  public function canUseNoindex() {
3931 
3932  $bannedNamespaces = $wgExemptFromUserRobotsControl ??
3933  MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
3934 
3935  return !in_array( $this->mNamespace, $bannedNamespaces );
3936  }
3937 
3948  public function getCategorySortkey( $prefix = '' ) {
3949  $unprefixed = $this->getText();
3950 
3951  // Anything that uses this hook should only depend
3952  // on the Title object passed in, and should probably
3953  // tell the users to run updateCollations.php --force
3954  // in order to re-sort existing category relations.
3955  Hooks::runner()->onGetDefaultSortkey( $this, $unprefixed );
3956  if ( $prefix !== '' ) {
3957  # Separate with a line feed, so the unprefixed part is only used as
3958  # a tiebreaker when two pages have the exact same prefix.
3959  # In UCA, tab is the only character that can sort above LF
3960  # so we strip both of them from the original prefix.
3961  $prefix = strtr( $prefix, "\n\t", ' ' );
3962  return "$prefix\n$unprefixed";
3963  }
3964  return $unprefixed;
3965  }
3966 
3974  private function getDbPageLanguageCode() {
3975  global $wgPageLanguageUseDB;
3976 
3977  // check, if the page language could be saved in the database, and if so and
3978  // the value is not requested already, lookup the page language using LinkCache
3979  if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) {
3980  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3981  $linkCache->addLinkObj( $this );
3982  $this->mDbPageLanguage = $linkCache->getGoodLinkFieldObj( $this, 'lang' );
3983  }
3984 
3985  return $this->mDbPageLanguage;
3986  }
3987 
3996  public function getPageLanguage() {
3997  global $wgLang, $wgLanguageCode;
3998  if ( $this->isSpecialPage() ) {
3999  // special pages are in the user language
4000  return $wgLang;
4001  }
4002 
4003  // Checking if DB language is set
4004  $dbPageLanguage = $this->getDbPageLanguageCode();
4005  if ( $dbPageLanguage ) {
4006  return wfGetLangObj( $dbPageLanguage );
4007  }
4008 
4009  if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) {
4010  // Note that this may depend on user settings, so the cache should
4011  // be only per-request.
4012  // NOTE: ContentHandler::getPageLanguage() may need to load the
4013  // content to determine the page language!
4014  // Checking $wgLanguageCode hasn't changed for the benefit of unit
4015  // tests.
4016  $contentHandler = MediaWikiServices::getInstance()
4017  ->getContentHandlerFactory()
4018  ->getContentHandler( $this->getContentModel() );
4019  $langObj = $contentHandler->getPageLanguage( $this );
4020  $this->mPageLanguage = [ $langObj->getCode(), $wgLanguageCode ];
4021  } else {
4022  $langObj = MediaWikiServices::getInstance()->getLanguageFactory()
4023  ->getLanguage( $this->mPageLanguage[0] );
4024  }
4025 
4026  return $langObj;
4027  }
4028 
4037  public function getPageViewLanguage() {
4038  global $wgLang;
4039 
4040  if ( $this->isSpecialPage() ) {
4041  // If the user chooses a variant, the content is actually
4042  // in a language whose code is the variant code.
4043  $variant = $this->getLanguageConverter( $wgLang )->getPreferredVariant();
4044  if ( $wgLang->getCode() !== $variant ) {
4045  return MediaWikiServices::getInstance()->getLanguageFactory()
4046  ->getLanguage( $variant );
4047  }
4048 
4049  return $wgLang;
4050  }
4051 
4052  // Checking if DB language is set
4053  $dbPageLanguage = $this->getDbPageLanguageCode();
4054  if ( $dbPageLanguage ) {
4055  $pageLang = wfGetLangObj( $dbPageLanguage );
4056  $variant = $this->getLanguageConverter( $pageLang )->getPreferredVariant();
4057  if ( $pageLang->getCode() !== $variant ) {
4058  $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()
4059  ->getLanguage( $variant );
4060  }
4061 
4062  return $pageLang;
4063  }
4064 
4065  // @note Can't be cached persistently, depends on user settings.
4066  // @note ContentHandler::getPageViewLanguage() may need to load the
4067  // content to determine the page language!
4068  $contentHandler = MediaWikiServices::getInstance()
4069  ->getContentHandlerFactory()
4070  ->getContentHandler( $this->getContentModel() );
4071  $pageLang = $contentHandler->getPageViewLanguage( $this );
4072  return $pageLang;
4073  }
4074 
4085  public function getEditNotices( $oldid = 0 ) {
4086  $notices = [];
4087 
4088  // Optional notice for the entire namespace
4089  $editnotice_ns = 'editnotice-' . $this->mNamespace;
4090  $msg = wfMessage( $editnotice_ns );
4091  if ( $msg->exists() ) {
4092  $html = $msg->parseAsBlock();
4093  // Edit notices may have complex logic, but output nothing (T91715)
4094  if ( trim( $html ) !== '' ) {
4095  $notices[$editnotice_ns] = Html::rawElement(
4096  'div',
4097  [ 'class' => [
4098  'mw-editnotice',
4099  'mw-editnotice-namespace',
4100  Sanitizer::escapeClass( "mw-$editnotice_ns" )
4101  ] ],
4102  $html
4103  );
4104  }
4105  }
4106 
4107  if (
4108  MediaWikiServices::getInstance()->getNamespaceInfo()->
4109  hasSubpages( $this->mNamespace )
4110  ) {
4111  // Optional notice for page itself and any parent page
4112  $editnotice_base = $editnotice_ns;
4113  foreach ( explode( '/', $this->mDbkeyform ) as $part ) {
4114  $editnotice_base .= '-' . $part;
4115  $msg = wfMessage( $editnotice_base );
4116  if ( $msg->exists() ) {
4117  $html = $msg->parseAsBlock();
4118  if ( trim( $html ) !== '' ) {
4119  $notices[$editnotice_base] = Html::rawElement(
4120  'div',
4121  [ 'class' => [
4122  'mw-editnotice',
4123  'mw-editnotice-base',
4124  Sanitizer::escapeClass( "mw-$editnotice_base" )
4125  ] ],
4126  $html
4127  );
4128  }
4129  }
4130  }
4131  } else {
4132  // Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
4133  $editnoticeText = $editnotice_ns . '-' . strtr( $this->mDbkeyform, '/', '-' );
4134  $msg = wfMessage( $editnoticeText );
4135  if ( $msg->exists() ) {
4136  $html = $msg->parseAsBlock();
4137  if ( trim( $html ) !== '' ) {
4138  $notices[$editnoticeText] = Html::rawElement(
4139  'div',
4140  [ 'class' => [
4141  'mw-editnotice',
4142  'mw-editnotice-page',
4143  Sanitizer::escapeClass( "mw-$editnoticeText" )
4144  ] ],
4145  $html
4146  );
4147  }
4148  }
4149  }
4150 
4151  Hooks::runner()->onTitleGetEditNotices( $this, $oldid, $notices );
4152  return $notices;
4153  }
4154 
4160  private function loadFieldFromDB( $field, $flags ) {
4161  if ( !in_array( $field, self::getSelectFields(), true ) ) {
4162  return false; // field does not exist
4163  }
4164 
4165  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
4166  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
4167 
4168  return wfGetDB( $index )->selectField(
4169  'page',
4170  $field,
4171  $this->pageCond(),
4172  __METHOD__,
4173  $options
4174  );
4175  }
4176 
4180  public function __sleep() {
4181  return [
4182  'mNamespace',
4183  'mDbkeyform',
4184  'mFragment',
4185  'mInterwiki',
4186  'mLocalInterwiki',
4187  'mDefaultNamespace',
4188  ];
4189  }
4190 
4191  public function __wakeup() {
4192  $this->mArticleID = ( $this->mNamespace >= 0 ) ? -1 : 0;
4193  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
4194  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
4195  }
4196 
4197  public function __clone() {
4198  $this->mInstanceCacheKey = null;
4199  }
4200 
4210  public function getWikiId() {
4211  return self::LOCAL;
4212  }
4213 
4230  public function getId( $wikiId = self::LOCAL ): int {
4231  $this->assertWiki( $wikiId );
4232  $this->assertProperPage();
4233  return $this->getArticleID();
4234  }
4235 
4248  private function assertProperPage() {
4249  Assert::precondition(
4250  $this->canExist(),
4251  'This Title instance does not represent a proper page, but merely a link target.'
4252  );
4253  }
4254 
4267  public function toPageIdentity(): ProperPageIdentity {
4268  // TODO: replace individual member fields with a PageIdentityValue that is always present
4269 
4270  $this->assertProperPage();
4271 
4272  return new PageIdentityValue(
4273  $this->getId(),
4274  $this->getNamespace(),
4275  $this->getDBkey(),
4276  self::LOCAL
4277  );
4278  }
4279 
4294  public function toPageRecord( $flags = 0 ): ExistingPageRecord {
4295  // TODO: Cache this? Construct is more efficiently?
4296 
4297  $this->assertProperPage();
4298 
4299  Assert::precondition(
4300  $this->exists(),
4301  'This Title instance does not represent an existing page: ' . $this
4302  );
4303 
4304  return new PageStoreRecord(
4305  (object)[
4306  'page_id' => $this->getArticleID( $flags ),
4307  'page_namespace' => $this->getNamespace(),
4308  'page_title' => $this->getDBkey(),
4309  'page_wiki_id' => $this->getWikiId(),
4310  'page_latest' => $this->getLatestRevID( $flags ),
4311  'page_is_new' => $this->isNewPage(), // no flags?
4312  'page_is_redirect' => $this->isRedirect( $flags ),
4313  'page_touched' => $this->getTouched(), // no flags?
4314  'page_lang' => $this->getDbPageLanguageCode() ?: null,
4315  ],
4316  PageIdentity::LOCAL
4317  );
4318  }
4319 
4320 }
Title\$mLocalInterwiki
bool $mLocalInterwiki
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:122
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:2483
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:3929
Title\getLocalURL
getLocalURL( $query='', $query2=false)
Get a URL with no fragment or server name (relative URL) from a Title object.
Definition: Title.php:2269
Title\isSemiProtected
isSemiProtected( $action='edit')
Is this page "semi-protected" - the only protection levels are listed in $wgSemiprotectedRestrictionL...
Definition: Title.php:2506
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:2535
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:1860
Title\getSubpageText
getSubpageText()
Get the lowest-level subpage name, i.e.
Definition: Title.php:2093
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:383
Title\isBigDeletion
isBigDeletion()
Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit.
Definition: Title.php:3433
MediaWiki\Linker\LinkTarget\getText
getText()
Returns the link in text form, without namespace prefix or fragment.
Title\getFilteredRestrictionTypes
static getFilteredRestrictionTypes( $exists=true)
Get a filtered list of all restriction types supported by this wiki.
Definition: Title.php:2455
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:857
Title\getInternalURL
getInternalURL( $query='', $query2=false)
Get the URL form for an internal link.
Definition: Title.php:2402
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
Title\getFragment
getFragment()
Get the Title fragment (i.e.
Definition: Title.php:1789
$wgExemptFromUserRobotsControl
$wgExemptFromUserRobotsControl
An array of namespace keys in which the INDEX/__NOINDEX__ magic words will not function,...
Definition: DefaultSettings.php:9247
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:1679
Title\inNamespace
inNamespace( $ns)
Returns true if the title is inside the specified namespace.
Definition: Title.php:1336
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:147
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:1398
Title\wasLocalInterwiki
wasLocalInterwiki()
Was this a local interwiki link?
Definition: Title.php:979
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:193
$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:1348
Title\isWikitextPage
isWikitextPage()
Does that page contain wikitext, or it is JS, CSS or whatever?
Definition: Title.php:1455
Title\isUserCssConfigPage
isUserCssConfigPage()
Is this a CSS "config" sub-page of a user page?
Definition: Title.php:1522
Title\getBacklinkCache
getBacklinkCache()
Get a backlink cache object.
Definition: Title.php:3918
$wgRequest
$wgRequest
Definition: Setup.php:702
Title\getPartialURL
getPartialURL()
Get the URL-encoded form of the main part.
Definition: Title.php:1051
$wgLegalTitleChars
$wgLegalTitleChars
Allowed title characters – regex character class Don't change this unless you know what you're doing.
Definition: DefaultSettings.php:4650
Title\clearCaches
static clearCaches()
Definition: Title.php:3039
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:1019
Title\estimateRevisionCount
estimateRevisionCount()
Get the approximate revision count of this page.
Definition: Title.php:3462
Title\getPrefixedDBkey
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1900
Title\getDbPageLanguageCode
getDbPageLanguageCode()
Returns the page language code saved in the database, if $wgPageLanguageUseDB is set to true in Local...
Definition: Title.php:3974
Title\getSkinFromConfigSubpage
getSkinFromConfigSubpage()
Trim down a .css, .json, or .js subpage title to get the corresponding skin name.
Definition: Title.php:1501
$wgScript
$wgScript
The URL path to index.php.
Definition: DefaultSettings.php:206
Title\$mHasSubpages
bool $mHasSubpages
Whether a page has any subpages.
Definition: Title.php:177
Title\getTalkPage
getTalkPage()
Get a Title object associated with the talk page of this article.
Definition: Title.php:1649
Title\NEW_CLONE
const NEW_CLONE
Flag for use with factory methods like newFromLinkTarget() that have a $forceClone parameter.
Definition: Title.php:76
Title\getParentCategoryTree
getParentCategoryTree( $children=[])
Get a tree of parent categories.
Definition: Title.php:3381
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:2164
Title\fixSpecialName
fixSpecialName()
If the Title refers to a special page alias which is not the local default, resolve the alias,...
Definition: Title.php:1312
Title\getInterwikiLookup
static getInterwikiLookup()
B/C kludge: provide an InterwikiLookup for use by Title.
Definition: Title.php:241
Title\isUserJsConfigPage
isUserJsConfigPage()
Is this a JS "config" sub-page of a user page?
Definition: Title.php:1550
Title\touchLinks
touchLinks()
Update page_touched timestamps and send CDN purge messages for pages linking to this title.
Definition: Title.php:3770
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:1912
Title\getTransWikiID
getTransWikiID()
Returns the DB name of the distant wiki which owns the object.
Definition: Title.php:1002
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:119
Title\getArticleID
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:2893
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:2377
Title\$mTitleValue
TitleValue null $mTitleValue
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:188
Title\isTalkPage
isTalkPage()
Is this a talk page of some sort?
Definition: Title.php:1633
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1101
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1186
Sanitizer\decodeCharReferencesAndNormalize
static decodeCharReferencesAndNormalize( $text)
Decode any character references, numeric or named entities, in the next and normalize the resulting s...
Definition: Sanitizer.php:1246
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:107
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:973
Title\getNotificationTimestamp
getNotificationTimestamp(User $user)
Get the timestamp when this page was updated since the user last saw it.
Definition: Title.php:3810
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:959
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:197
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:2686
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:713
Title\getDefaultMessageText
getDefaultMessageText()
Get the default (plain) message contents for an page that overrides an interface message key.
Definition: Title.php:3707
Title\hasSourceText
hasSourceText()
Does this page have source text?
Definition: Title.php:3648
Title\loadFromRow
loadFromRow( $row)
Load Title object fields from a DB row.
Definition: Title.php:592
Title\setFragment
setFragment( $fragment)
Set the fragment for this title.
Definition: Title.php:1833
$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:191
Title\convertByteClassToUnicodeClass
static convertByteClassToUnicodeClass( $byteClass)
Utility method for converting a character sequence from bytes to Unicode.
Definition: Title.php:751
Title\hasSubpagesEnabled
hasSubpagesEnabled()
Whether this Title's namespace has subpages enabled.
Definition: Title.php:1976
Title\__wakeup
__wakeup()
Definition: Title.php:4191
$wgLang
$wgLang
Definition: Setup.php:831
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:382
Title\getParentCategories
getParentCategories()
Get categories to which this Title belongs and return an array of categories' names.
Definition: Title.php:3346
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:3127
Title\$mContentModel
bool string $mContentModel
ID of the page's content model, i.e.
Definition: Title.php:141
Title\getPageLanguageConverter
getPageLanguageConverter()
Shorthand for getting a Language Converter for page's language.
Definition: Title.php:217
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:1564
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:174
Title\$mDbkeyform
string $mDbkeyform
Definition: Title.php:105
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:332
Title\$mUrlform
string $mUrlform
Definition: Title.php:98
$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:3185
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\loadFieldFromDB
loadFieldFromDB( $field, $flags)
Definition: Title.php:4160
Title\isCascadeProtected
isCascadeProtected()
Cascading protection: Return true if cascading restrictions apply to this page, false if not.
Definition: Title.php:2558
Title\getCdnUrls
getCdnUrls()
Get a list of URLs to purge from the CDN cache when this page changes.
Definition: Title.php:3287
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:1751
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:1473
Title\isUserJsonConfigPage
isUserJsonConfigPage()
Is this a JSON "config" sub-page of a user page?
Definition: Title.php:1536
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:198
$wgRawHtmlMessages
string[] $wgRawHtmlMessages
List of messages which might contain raw HTML.
Definition: DefaultSettings.php:3667
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:1060
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:185
Title\isSpecial
isSpecial( $name)
Returns true if this title resolves to the named special page.
Definition: Title.php:1294
MWException
MediaWiki exception.
Definition: MWException.php:29
Title\getTitleFormatter
static getTitleFormatter()
B/C kludge: provide a TitleParser for use by Title.
Definition: Title.php:229
Title\isSamePageAs
isSamePageAs(PageReference $other)
Definition: Title.php:3526
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:560
Title\isMainPage
isMainPage()
Is this the mainpage?
Definition: Title.php:1422
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Definition: GlobalFunctions.php:997
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
Title\getSubpage
getSubpage( $text)
Get the title for a subpage of the current page.
Definition: Title.php:2120
Title\getBaseTitle
getBaseTitle()
Get the base page name title, i.e.
Definition: Title.php:2073
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1069
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:580
Title\isConversionTable
isConversionTable()
Is this a conversion table for the LanguageConverter?
Definition: Title.php:1443
Title\isProtected
isProtected( $action='')
Does the title correspond to a protected article?
Definition: Title.php:2521
Title\flushRestrictions
flushRestrictions()
Flush the protection cache in this object and force reload from the database.
Definition: Title.php:2715
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2202
Title\getCategorySortkey
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:3948
Title\getInterwiki
getInterwiki()
Get the interwiki prefix.
Definition: Title.php:970
Title\isSiteJsonConfigPage
isSiteJsonConfigPage()
Is this a sitewide JSON "config" page?
Definition: Title.php:1582
$matches
$matches
Definition: NoLocalSettings.php:24
Title\isValidRedirectTarget
isValidRedirectTarget()
Check if this Title is a valid redirect target.
Definition: Title.php:3887
Title\deleteTitleProtection
deleteTitleProtection()
Remove any title protection due to page existing.
Definition: Title.php:2493
Title\__construct
__construct()
Definition: Title.php:245
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:3251
Title\isUserConfigPage
isUserConfigPage()
Is this a "config" (.css, .json, or .js) sub-page of a user page?
Definition: Title.php:1487
Title\getLanguageConverter
getLanguageConverter( $language)
Shorthand for getting a Language Converter for specific language.
Definition: Title.php:208
Title\getSubjectPage
getSubjectPage()
Get a title object associated with the subject page of this talk page.
Definition: Title.php:1694
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:1136
Title\loadRestrictions
loadRestrictions( $oldFashionedRestrictions=null, $flags=0)
Load restrictions from the page_restrictions table.
Definition: Title.php:2704
$wgInvalidRedirectTargets
$wgInvalidRedirectTargets
Array of invalid page redirect targets.
Definition: DefaultSettings.php:4738
Title\getFullText
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
Definition: Title.php:1936
Title\getTitleCache
static getTitleCache()
Definition: Title.php:503
Title\hasFragment
hasFragment()
Check if a Title fragment is set.
Definition: Title.php:1799
Title\getRedirectsHere
getRedirectsHere( $ns=null)
Get all extant redirects to this Title.
Definition: Title.php:3851
$title
$title
Definition: testCompression.php:38
Title\warnIfPageCannotExist
warnIfPageCannotExist(Title $title, $method)
Definition: Title.php:1720
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:651
Title\$mInterwiki
string $mInterwiki
Definition: Title.php:119
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:1996
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:6194
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:6371
Title\$prefixedText
string null $prefixedText
Text form including namespace/interwiki, initialised on demand.
Definition: Title.php:160
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:4180
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:2424
Title\createFragmentTarget
createFragmentTarget( $fragment)
Creates a new Title for a different fragment of the same page.
Definition: Title.php:1845
Title\areCascadeProtectionSourcesLoaded
areCascadeProtectionSourcesLoaded()
Determines whether cascading protection sources have already been loaded from the database.
Definition: Title.php:2571
Title\$mNamespace
int $mNamespace
Definition: Title.php:112
Title\getDefaultNamespace
getDefaultNamespace()
Get the default namespace index, for when there is no namespace.
Definition: Title.php:1777
Title\newFromTextThrow
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:418
$wgPageLanguageUseDB
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
Definition: DefaultSettings.php:2546
Title\$mPageLanguage
array null $mPageLanguage
The (string) language code of the page's language and content code.
Definition: Title.php:180
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:905
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:884
Title\getPrefixedURL
getPrefixedURL()
Get a URL-encoded title (not an actual URL) including interwiki.
Definition: Title.php:2145
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:677
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:1926
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:4230
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
DBAccessObjectUtils\hasFlags
static hasFlags( $bitfield, $flags)
Definition: DBAccessObjectUtils.php:35
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:3169
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:500
Title\areRestrictionsCascading
areRestrictionsCascading()
Returns cascading restrictions for the current article.
Definition: Title.php:2667
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:2984
Title\areRestrictionsLoaded
areRestrictionsLoaded()
Accessor for mRestrictionsLoaded.
Definition: Title.php:2611
Title\hasDeletedEdits
hasDeletedEdits()
Is there a version of this page in the deletion archive?
Definition: Title.php:2868
Title\getSubpages
getSubpages( $limit=-1)
Get all subpages of this page.
Definition: Title.php:2793
Title\assertProperPage
assertProperPage()
Code that requires this Title to be a "proper page" in the sense defined by PageIdentity should call ...
Definition: Title.php:4248
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:3308
$wgServer
$wgServer
URL of the server.
Definition: DefaultSettings.php:110
Title\GAID_FOR_UPDATE
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define().
Definition: Title.php:67
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:4037
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:256
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:862
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:3437
Title\isSubpage
isSubpage()
Is this a subpage?
Definition: Title.php:1431
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:2654
Title\newFromURL
static newFromURL( $url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:480
MediaWiki\Linker\LinkTarget\getDBkey
getDBkey()
Get the main part with underscores.
MediaWiki\Linker\LinkTarget\getFragment
getFragment()
Get the link fragment (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:3019
Title\isSubpageOf
isSubpageOf(Title $title)
Check if this title is a subpage of another title.
Definition: Title.php:3547
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:944
Title\$mFragment
string $mFragment
Definition: Title.php:129
Title\getContentModel
getContentModel( $flags=0)
Get the page's content model id, see the CONTENT_MODEL_XXX constants.
Definition: Title.php:1081
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:554
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:367
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:295
Title\prefix
prefix( $name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object.
Definition: Title.php:1874
Title\getNamespaceKey
getNamespaceKey( $prepend='nstab-')
Generate strings used for xml 'id' names in monobook tabs.
Definition: Title.php:3822
Title\getEditURL
getEditURL()
Get the edit URL for this Title.
Definition: Title.php:2436
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:2202
Title\isKnown
isKnown()
Does this title refer to a page that can (or might) be meaningfully viewed? In particular,...
Definition: Title.php:3639
$watchlistManager
WatchlistManager $watchlistManager
Definition: ApiWatchlistTrait.php:30
$wgArticlePath
$wgArticlePath
The URL path for primary article page views.
Definition: DefaultSettings.php:266
Title\$mIsValid
bool null $mIsValid
Is the title known to be valid?
Definition: Title.php:194
Title\equals
equals(object $other)
Compares with another Title.
Definition: Title.php:3490
Title\getAllRestrictions
getAllRestrictions()
Accessor/initialisation for mRestrictions.
Definition: Title.php:2641
Title
Represents a title within MediaWiki.
Definition: Title.php:48
$wgActionPaths
$wgActionPaths
To set 'pretty' URL paths for actions other than plain page views, add to this array.
Definition: DefaultSettings.php:490
Title\isSameLinkAs
isSameLinkAs(LinkTarget $other)
Definition: Title.php:3510
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:2591
Title\getRestrictionTypes
getRestrictionTypes()
Returns restriction types for the current Title.
Definition: Title.php:2468
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:3239
Title\isRedirect
isRedirect( $flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
Definition: Title.php:2932
Title\$mArticleID
int $mArticleID
Article ID, fetched from the link cache on demand.
Definition: Title.php:132
Title\isDeleted
isDeleted()
Is there a version of this page in the deletion archive?
Definition: Title.php:2822
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:3054
Title\$mDefaultNamespace
int $mDefaultNamespace
Namespace index when there is no namespace.
Definition: Title.php:168
Title\$mLength
int $mLength
The page length, 0 for special pages.
Definition: Title.php:171
Title\$mEstimateRevisions
int $mEstimateRevisions
Estimated number of revisions; null of not loaded.
Definition: Title.php:150
Title\hasSubjectNamespace
hasSubjectNamespace( $ns)
Returns true if the title has the same subject namespace as the namespace specified.
Definition: Title.php:1375
Title\isSpecialPage
isSpecialPage()
Returns true if this is a special page.
Definition: Title.php:1284
MapCacheLRU\get
get( $key, $maxAge=INF, $default=null)
Get the value for a key.
Definition: MapCacheLRU.php:169
Title\purgeSquid
purgeSquid()
Purge all applicable CDN URLs.
Definition: Title.php:3296
Title\getDeletedEditsCount
getDeletedEditsCount()
Is there a version of this page in the deletion archive?
Definition: Title.php:2832
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:3996
Title\CACHE_MAX
const CACHE_MAX
Title::newFromText maintains a cache to avoid expensive re-normalization of commonly used titles.
Definition: Title.php:60
Title\getEditNotices
getEditNotices( $oldid=0)
Get a list of rendered edit notices for this page.
Definition: Title.php:4085
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:209
Title\getTouched
getTouched( $db=null)
Get the last touched timestamp.
Definition: Title.php:3794
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
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:1808
Title\exists
exists( $flags=0)
Check if page exists.
Definition: Title.php:3563
Title\__clone
__clone()
Definition: Title.php:4197
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:839
Title\isAlwaysKnown
isAlwaysKnown()
Should links to this title be shown as potentially viewable (i.e.
Definition: Title.php:3585
Title\secureAndSplit
secureAndSplit( $text, $defaultNamespace=null)
Secure and split - main initialisation function for this object.
Definition: Title.php:3079
Title\isDeletedQuick
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:2858
Title\getSubpageUrlForm
getSubpageUrlForm()
Get a URL-encoded form of the subpage text.
Definition: Title.php:2134
MapCacheLRU\clear
clear( $keys=null)
Clear one or several cache entries, or all cache entries.
Definition: MapCacheLRU.php:283
Title\castFromPageReference
static castFromPageReference(?PageReference $pageReference)
Return a Title for a given Reference.
Definition: Title.php:345
Title\isNewPage
isNewPage()
Check if this is a new page.
Definition: Title.php:3422
Title\toPageIdentity
toPageIdentity()
Returns the page represented by this Title as a ProperPageIdentity.
Definition: Title.php:4267
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:737
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:319
Title\isSiteJsConfigPage
isSiteJsConfigPage()
Is this a sitewide JS "config" page?
Definition: Title.php:1600
Title\invalidateCache
invalidateCache( $purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:3730
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:989
Title\getRestrictions
getRestrictions( $action)
Accessor/initialisation for mRestrictions.
Definition: Title.php:2628
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:1387
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:457
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:68
Title\$titleCache
static MapCacheLRU null $titleCache
Definition: Title.php:53
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:529
$wgVariantArticlePath
$wgVariantArticlePath
Like $wgArticlePath, but on multi-variant wikis, this provides a path format that describes which par...
Definition: DefaultSettings.php:3626
Title\isRawHtmlMessage
isRawHtmlMessage()
Is this a message which can contain raw HTML?
Definition: Title.php:1618
Title\getSelectFields
static getSelectFields()
Returns a list of fields that are to be selected for initializing Title objects or LinkCache entries.
Definition: Title.php:518
Title\hasSubpages
hasSubpages()
Does this have subpages? (Warning, usually requires an extra DB query.)
Definition: Title.php:2765
Title\getBaseText
getBaseText()
Get the base page name without a namespace, i.e.
Definition: Title.php:2046
Title\pageCond
pageCond()
Get an associative array for selecting this title from the "page" table.
Definition: Title.php:3408
Title\getText
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:1042
Title\$mTextform
string $mTextform
Definition: Title.php:91
Title\toPageRecord
toPageRecord( $flags=0)
Returns the page represented by this Title as a ProperPageRecord.
Definition: Title.php:4294
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:2724
$wgInternalServer
$wgInternalServer
Internal server name as known to CDN, if different.
Definition: DefaultSettings.php:3244
Title\$mLatestID
bool int $mLatestID
ID of most recent revision.
Definition: Title.php:135
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:4210
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:280
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:2235
Title\getRootTitle
getRootTitle()
Get the root page name title, i.e.
Definition: Title.php:2023
Title\getLength
getLength( $flags=0)
What is the length of this page? Uses link cache, adding it if necessary.
Definition: Title.php:2957
Title\findSubpageDivider
findSubpageDivider( $text, $dir)
Finds the first or last subpage divider (slash) in the string.
Definition: Title.php:1958
Title\isWatchable
isWatchable()
Can this title be added to a user's watchlist?
Definition: Title.php:1273