MediaWiki  master
Title.php
Go to the documentation of this file.
1 <?php
33 use Wikimedia\Assert\Assert;
34 use Wikimedia\Assert\PreconditionException;
37 
48 
50  private static $titleCache = null;
51 
57  private const CACHE_MAX = 1000;
58 
64  public const GAID_FOR_UPDATE = 512;
65 
73  public const NEW_CLONE = 'clone';
74 
75  /***************************************************************************/
76  // region Private member variables
84  public $mTextform = '';
86  public $mUrlform = '';
88  public $mDbkeyform = '';
90  public $mNamespace = NS_MAIN;
92  public $mInterwiki = '';
94  private $mLocalInterwiki = false;
96  public $mFragment = '';
97 
99  public $mArticleID = -1;
100 
102  protected $mLatestID = false;
103 
108  private $mContentModel = false;
109 
114  private $mForcedContentModel = false;
115 
118 
120  public $mRestrictions = [];
121 
128  protected $mOldRestrictions = false;
129 
132 
135 
137  protected $mRestrictionsExpiry = [];
138 
141 
144 
146  public $mRestrictionsLoaded = false;
147 
156  public $prefixedText = null;
157 
160 
168 
170  protected $mLength = -1;
171 
173  public $mRedirect = null;
174 
176  private $mHasSubpages;
177 
179  private $mPageLanguage;
180 
184  private $mDbPageLanguage = false;
185 
187  private $mTitleValue = null;
188 
190  private $mIsBigDeletion = null;
191 
193  private $mIsValid = null;
194 
195  // endregion -- end of private member variables
197  /***************************************************************************/
198 
204  private function getLanguageConverter( $language ) : ILanguageConverter {
205  return MediaWikiServices::getInstance()->getLanguageConverterFactory()
206  ->getLanguageConverter( $language );
207  }
208 
214  return $this->getLanguageConverter( $this->getPageLanguage() );
215  }
216 
225  private static function getTitleFormatter() {
226  return MediaWikiServices::getInstance()->getTitleFormatter();
227  }
228 
237  private static function getInterwikiLookup() {
238  return MediaWikiServices::getInstance()->getInterwikiLookup();
239  }
240 
241  private function __construct() {
242  }
243 
252  public static function newFromDBkey( $key ) {
253  $t = new self();
254 
255  try {
256  $t->secureAndSplit( $key );
257  return $t;
258  } catch ( MalformedTitleException $ex ) {
259  return null;
260  }
261  }
262 
276  public static function newFromTitleValue( TitleValue $titleValue, $forceClone = '' ) {
277  return self::newFromLinkTarget( $titleValue, $forceClone );
278  }
279 
291  public static function newFromLinkTarget( LinkTarget $linkTarget, $forceClone = '' ) {
292  if ( $linkTarget instanceof Title ) {
293  // Special case if it's already a Title object
294  if ( $forceClone === self::NEW_CLONE ) {
295  return clone $linkTarget;
296  } else {
297  return $linkTarget;
298  }
299  }
300  return self::makeTitle(
301  $linkTarget->getNamespace(),
302  $linkTarget->getText(),
303  $linkTarget->getFragment(),
304  $linkTarget->getInterwiki()
305  );
306  }
307 
315  public static function castFromLinkTarget( $linkTarget ) {
316  return $linkTarget ? self::newFromLinkTarget( $linkTarget ) : null;
317  }
318 
328  public static function castFromPageIdentity( ?PageIdentity $pageIdentity ) : ?Title {
329  if ( !$pageIdentity ) {
330  return null;
331  }
332 
333  if ( $pageIdentity instanceof Title ) {
334  return $pageIdentity;
335  }
336 
337  $pageIdentity->assertWiki( self::LOCAL );
338  $title = self::makeTitle( $pageIdentity->getNamespace(), $pageIdentity->getDBkey() );
339  $title->resetArticleID( $pageIdentity->getId() );
340  return $title;
341  }
342 
363  public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
364  // DWIM: Integers can be passed in here when page titles are used as array keys.
365  if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) {
366  throw new InvalidArgumentException( '$text must be a string.' );
367  }
368  if ( $text === null ) {
369  return null;
370  }
371 
372  try {
373  return self::newFromTextThrow( (string)$text, (int)$defaultNamespace );
374  } catch ( MalformedTitleException $ex ) {
375  return null;
376  }
377  }
378 
398  public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
399  if ( is_object( $text ) ) {
400  throw new MWException( '$text must be a string, given an object' );
401  } elseif ( $text === null ) {
402  // Legacy code relies on MalformedTitleException being thrown in this case
403  // (happens when URL with no title in it is parsed). TODO fix
404  throw new MalformedTitleException( 'title-invalid-empty' );
405  }
406 
408 
409  // Wiki pages often contain multiple links to the same page.
410  // Title normalization and parsing can become expensive on pages with many
411  // links, so we can save a little time by caching them.
412  // In theory these are value objects and won't get changed...
413  if ( $defaultNamespace === NS_MAIN ) {
414  $t = $titleCache->get( $text );
415  if ( $t ) {
416  return $t;
417  }
418  }
419 
420  // Convert things like &eacute; &#257; or &#x3017; into normalized (T16952) text
421  $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
422 
423  $t = new Title();
424  $dbKeyForm = strtr( $filteredText, ' ', '_' );
425 
426  $t->secureAndSplit( $dbKeyForm, (int)$defaultNamespace );
427  if ( $defaultNamespace === NS_MAIN ) {
428  $titleCache->set( $text, $t );
429  }
430  return $t;
431  }
432 
448  public static function newFromURL( $url ) {
449  $t = new Title();
450 
451  # For compatibility with old buggy URLs. "+" is usually not valid in titles,
452  # but some URLs used it as a space replacement and they still come
453  # from some external search tools.
454  if ( strpos( self::legalChars(), '+' ) === false ) {
455  $url = strtr( $url, '+', ' ' );
456  }
457 
458  $dbKeyForm = strtr( $url, ' ', '_' );
459 
460  try {
461  $t->secureAndSplit( $dbKeyForm );
462  return $t;
463  } catch ( MalformedTitleException $ex ) {
464  return null;
465  }
466  }
467 
471  private static function getTitleCache() {
472  if ( self::$titleCache === null ) {
473  self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
474  }
475  return self::$titleCache;
476  }
477 
484  protected static function getSelectFields() {
485  global $wgPageLanguageUseDB;
486 
487  $fields = [
488  'page_namespace', 'page_title', 'page_id',
489  'page_len', 'page_is_redirect', 'page_latest',
490  'page_content_model',
491  ];
492 
493  if ( $wgPageLanguageUseDB ) {
494  $fields[] = 'page_lang';
495  }
496 
497  return $fields;
498  }
499 
507  public static function newFromID( $id, $flags = 0 ) {
508  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
509  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
510  $row = wfGetDB( $index )->selectRow(
511  'page',
512  self::getSelectFields(),
513  [ 'page_id' => $id ],
514  __METHOD__,
515  $options
516  );
517  if ( $row !== false ) {
518  $title = self::newFromRow( $row );
519  } else {
520  $title = null;
521  }
522 
523  return $title;
524  }
525 
532  public static function newFromIDs( $ids ) {
533  if ( !count( $ids ) ) {
534  return [];
535  }
536  $dbr = wfGetDB( DB_REPLICA );
537 
538  $res = $dbr->select(
539  'page',
540  self::getSelectFields(),
541  [ 'page_id' => $ids ],
542  __METHOD__
543  );
544 
545  $titles = [];
546  foreach ( $res as $row ) {
547  $titles[] = self::newFromRow( $row );
548  }
549  return $titles;
550  }
551 
558  public static function newFromRow( $row ) {
559  $t = self::makeTitle( $row->page_namespace, $row->page_title );
560  $t->loadFromRow( $row );
561  return $t;
562  }
563 
570  public function loadFromRow( $row ) {
571  if ( $row ) { // page found
572  if ( isset( $row->page_id ) ) {
573  $this->mArticleID = (int)$row->page_id;
574  }
575  if ( isset( $row->page_len ) ) {
576  $this->mLength = (int)$row->page_len;
577  }
578  if ( isset( $row->page_is_redirect ) ) {
579  $this->mRedirect = (bool)$row->page_is_redirect;
580  }
581  if ( isset( $row->page_latest ) ) {
582  $this->mLatestID = (int)$row->page_latest;
583  }
584  if ( isset( $row->page_content_model ) ) {
585  $this->lazyFillContentModel( $row->page_content_model );
586  } else {
587  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
588  }
589  if ( isset( $row->page_lang ) ) {
590  $this->mDbPageLanguage = (string)$row->page_lang;
591  }
592  if ( isset( $row->page_restrictions ) ) {
593  $this->mOldRestrictions = $row->page_restrictions;
594  }
595  } else { // page not found
596  $this->mArticleID = 0;
597  $this->mLength = 0;
598  $this->mRedirect = false;
599  $this->mLatestID = 0;
600  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
601  }
602  }
603 
626  public static function makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
627  $t = new Title();
628  $t->mInterwiki = $interwiki;
629  $t->mFragment = $fragment;
630  $t->mNamespace = $ns = (int)$ns;
631  $t->mDbkeyform = strtr( $title, ' ', '_' );
632  $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
633  $t->mUrlform = wfUrlencode( $t->mDbkeyform );
634  $t->mTextform = strtr( $title, '_', ' ' );
635  return $t;
636  }
637 
652  public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
653  // NOTE: ideally, this would just call makeTitle() and then isValid(),
654  // but presently, that means more overhead on a potential performance hotspot.
655 
656  if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) {
657  return null;
658  }
659 
660  $t = new Title();
661  $dbKeyForm = self::makeName( $ns, $title, $fragment, $interwiki, true );
662 
663  try {
664  $t->secureAndSplit( $dbKeyForm );
665  return $t;
666  } catch ( MalformedTitleException $ex ) {
667  return null;
668  }
669  }
670 
688  public static function newMainPage( MessageLocalizer $localizer = null ) {
689  if ( $localizer ) {
690  $msg = $localizer->msg( 'mainpage' );
691  } else {
692  $msg = wfMessage( 'mainpage' );
693  }
694 
695  $title = self::newFromText( $msg->inContentLanguage()->text() );
696 
697  // Every page renders at least one link to the Main Page (e.g. sidebar).
698  // If the localised value is invalid, don't produce fatal errors that
699  // would make the wiki inaccessible (and hard to fix the invalid message).
700  // Gracefully fallback...
701  if ( !$title ) {
702  $title = self::newFromText( 'Main Page' );
703  }
704  return $title;
705  }
706 
714  public static function nameOf( $id ) {
715  wfDeprecated( __METHOD__, '1.36' );
716 
717  $dbr = wfGetDB( DB_REPLICA );
718 
719  $s = $dbr->selectRow(
720  'page',
721  [ 'page_namespace', 'page_title' ],
722  [ 'page_id' => $id ],
723  __METHOD__
724  );
725  if ( $s === false ) {
726  return null;
727  }
728 
729  return self::makeName( $s->page_namespace, $s->page_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  if ( $x0 !== '' && $x1 === '-' && $x2 !== '' ) {
811  // Range
812  if ( $ord2 > $ord0 ) {
813  // Empty range
814  } elseif ( $ord0 >= 0x80 ) {
815  // Unicode range
816  $allowUnicode = true;
817  if ( $ord2 < 0x80 ) {
818  // Keep the non-unicode section of the range
819  $out .= "$r2-\\x7F";
820  }
821  } else {
822  // Normal range
823  $out .= "$r2-$r0";
824  }
825  // Reset state to the initial value
826  $x0 = $x1 = $d0 = $d1 = $r0 = $r1 = '';
827  } elseif ( $ord2 < 0x80 ) {
828  // ASCII character
829  $out .= $r2;
830  }
831  }
832  // @phan-suppress-next-line PhanSuspiciousValueComparison
833  if ( $ord1 < 0x80 ) {
834  $out .= $r1;
835  }
836  if ( $ord0 < 0x80 ) {
837  $out .= $r0;
838  }
839  if ( $allowUnicode ) {
840  $out .= '\u0080-\uFFFF';
841  }
842  return $out;
843  }
844 
856  public static function makeName( $ns, $title, $fragment = '', $interwiki = '',
857  $canonicalNamespace = false
858  ) {
859  if ( $canonicalNamespace ) {
860  $namespace = MediaWikiServices::getInstance()->getNamespaceInfo()->
861  getCanonicalName( $ns );
862  } else {
863  $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns );
864  }
865  $name = $namespace == '' ? $title : "$namespace:$title";
866  if ( strval( $interwiki ) != '' ) {
867  $name = "$interwiki:$name";
868  }
869  if ( strval( $fragment ) != '' ) {
870  $name .= '#' . $fragment;
871  }
872  return $name;
873  }
874 
883  public static function compare( LinkTarget $a, LinkTarget $b ) {
884  return $a->getNamespace() <=> $b->getNamespace()
885  ?: strcmp( $a->getText(), $b->getText() );
886  }
887 
904  public function isValid() {
905  if ( $this->mIsValid !== null ) {
906  return $this->mIsValid;
907  }
908 
909  try {
910  $text = $this->getFullText();
911  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
912 
913  '@phan-var MediaWikiTitleCodec $titleCodec';
914  $parts = $titleCodec->splitTitleString( $text, $this->mNamespace );
915 
916  // Check that nothing changed!
917  // This ensures that $text was already perperly normalized.
918  if ( $parts['fragment'] !== $this->mFragment
919  || $parts['interwiki'] !== $this->mInterwiki
920  || $parts['local_interwiki'] !== $this->mLocalInterwiki
921  || $parts['namespace'] !== $this->mNamespace
922  || $parts['dbkey'] !== $this->mDbkeyform
923  ) {
924  $this->mIsValid = false;
925  return $this->mIsValid;
926  }
927  } catch ( MalformedTitleException $ex ) {
928  $this->mIsValid = false;
929  return $this->mIsValid;
930  }
931 
932  $this->mIsValid = true;
933  return $this->mIsValid;
934  }
935 
943  public function isLocal() {
944  if ( $this->isExternal() ) {
945  $iw = self::getInterwikiLookup()->fetch( $this->mInterwiki );
946  if ( $iw ) {
947  return $iw->isLocal();
948  }
949  }
950  return true;
951  }
952 
958  public function isExternal() {
959  return $this->mInterwiki !== '';
960  }
961 
969  public function getInterwiki() {
970  return $this->mInterwiki;
971  }
972 
978  public function wasLocalInterwiki() {
979  return $this->mLocalInterwiki;
980  }
981 
988  public function isTrans() {
989  if ( !$this->isExternal() ) {
990  return false;
991  }
992 
993  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable();
994  }
995 
1001  public function getTransWikiID() {
1002  if ( !$this->isExternal() ) {
1003  return false;
1004  }
1005 
1006  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID();
1007  }
1008 
1018  public function getTitleValue() {
1019  if ( $this->mTitleValue === null ) {
1020  try {
1021  $this->mTitleValue = new TitleValue(
1022  $this->mNamespace,
1023  $this->mDbkeyform,
1024  $this->mFragment,
1025  $this->mInterwiki
1026  );
1027  } catch ( InvalidArgumentException $ex ) {
1028  wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' .
1029  $this->getPrefixedText() . ']]: ' . $ex->getMessage() );
1030  }
1031  }
1032 
1033  return $this->mTitleValue;
1034  }
1035 
1041  public function getText() {
1042  return $this->mTextform;
1043  }
1044 
1050  public function getPartialURL() {
1051  return $this->mUrlform;
1052  }
1053 
1059  public function getDBkey(): string {
1060  return $this->mDbkeyform;
1061  }
1062 
1068  public function getNamespace(): int {
1069  return $this->mNamespace;
1070  }
1071 
1080  public function getContentModel( $flags = 0 ) {
1081  if ( $this->mForcedContentModel ) {
1082  if ( !$this->mContentModel ) {
1083  throw new RuntimeException( 'Got out of sync; an empty model is being forced' );
1084  }
1085  // Content model is locked to the currently loaded one
1086  return $this->mContentModel;
1087  }
1088 
1089  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
1090  $this->lazyFillContentModel( $this->loadFieldFromDB( 'page_content_model', $flags ) );
1091  } elseif (
1092  ( !$this->mContentModel || $flags & self::GAID_FOR_UPDATE ) &&
1093  $this->getArticleID( $flags )
1094  ) {
1095  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1096  $linkCache->addLinkObj( $this ); # in case we already had an article ID
1097  $this->lazyFillContentModel( $linkCache->getGoodLinkFieldObj( $this, 'model' ) );
1098  }
1099 
1100  if ( !$this->mContentModel ) {
1102  }
1103 
1104  return $this->mContentModel;
1105  }
1106 
1113  public function hasContentModel( $id ) {
1114  return $this->getContentModel() == $id;
1115  }
1116 
1130  public function setContentModel( $model ) {
1131  if ( (string)$model === '' ) {
1132  throw new InvalidArgumentException( "Missing CONTENT_MODEL_* constant" );
1133  }
1134 
1135  $this->mContentModel = $model;
1136  $this->mForcedContentModel = true;
1137  }
1138 
1144  private function lazyFillContentModel( $model ) {
1145  if ( !$this->mForcedContentModel ) {
1146  $this->mContentModel = ( $model === false ) ? false : (string)$model;
1147  }
1148  }
1149 
1155  public function getNsText() {
1156  if ( $this->isExternal() ) {
1157  // This probably shouldn't even happen, except for interwiki transclusion.
1158  // If possible, use the canonical name for the foreign namespace.
1159  $nsText = MediaWikiServices::getInstance()->getNamespaceInfo()->
1160  getCanonicalName( $this->mNamespace );
1161  if ( $nsText !== false ) {
1162  return $nsText;
1163  }
1164  }
1165 
1166  try {
1167  $formatter = self::getTitleFormatter();
1168  return $formatter->getNamespaceName( $this->mNamespace, $this->mDbkeyform );
1169  } catch ( InvalidArgumentException $ex ) {
1170  wfDebug( __METHOD__ . ': ' . $ex->getMessage() );
1171  return false;
1172  }
1173  }
1174 
1180  public function getSubjectNsText() {
1181  $services = MediaWikiServices::getInstance();
1182  return $services->getContentLanguage()->
1183  getNsText( $services->getNamespaceInfo()->getSubject( $this->mNamespace ) );
1184  }
1185 
1191  public function getTalkNsText() {
1192  $services = MediaWikiServices::getInstance();
1193  return $services->getContentLanguage()->
1194  getNsText( $services->getNamespaceInfo()->getTalk( $this->mNamespace ) );
1195  }
1196 
1208  public function canHaveTalkPage() {
1209  return MediaWikiServices::getInstance()->getNamespaceInfo()->canHaveTalkPage( $this );
1210  }
1211 
1222  public function canExist(): bool {
1223  // NOTE: Don't use getArticleID(), we don't want to
1224  // trigger a database query here. This check is supposed to
1225  // act as an optimization, not add extra cost.
1226  if ( $this->mArticleID > 0 ) {
1227  // It exists, so it can exist.
1228  return true;
1229  }
1230 
1231  // NOTE: we call the relatively expensive isValid() method further down,
1232  // but we can bail out early if we already know the title is invalid.
1233  if ( $this->mIsValid === false ) {
1234  // It's invalid, so it can't exist.
1235  return false;
1236  }
1237 
1238  if ( $this->getNamespace() < NS_MAIN ) {
1239  // It's a special page, so it can't exist in the database.
1240  return false;
1241  }
1242 
1243  if ( $this->isExternal() ) {
1244  // If it's external, it's not local, so it can't exist.
1245  return false;
1246  }
1247 
1248  if ( $this->getText() === '' ) {
1249  // The title has no text, so it can't exist in the database.
1250  // It's probably an on-page section link, like "#something".
1251  return false;
1252  }
1253 
1254  // Double check that the title is valid.
1255  return $this->isValid();
1256  }
1257 
1266  public function isWatchable() {
1267  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
1268  return $this->getText() !== '' && !$this->isExternal() &&
1269  $nsInfo->isWatchable( $this->mNamespace );
1270  }
1271 
1277  public function isSpecialPage() {
1278  return $this->mNamespace === NS_SPECIAL;
1279  }
1280 
1287  public function isSpecial( $name ) {
1288  if ( $this->isSpecialPage() ) {
1289  list( $thisName, /* $subpage */ ) =
1290  MediaWikiServices::getInstance()->getSpecialPageFactory()->
1291  resolveAlias( $this->mDbkeyform );
1292  if ( $name == $thisName ) {
1293  return true;
1294  }
1295  }
1296  return false;
1297  }
1298 
1305  public function fixSpecialName() {
1306  if ( $this->isSpecialPage() ) {
1307  $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory();
1308  list( $canonicalName, $par ) = $spFactory->resolveAlias( $this->mDbkeyform );
1309  if ( $canonicalName ) {
1310  $localName = $spFactory->getLocalNameFor( $canonicalName, $par );
1311  if ( $localName != $this->mDbkeyform ) {
1312  return self::makeTitle( NS_SPECIAL, $localName );
1313  }
1314  }
1315  }
1316  return $this;
1317  }
1318 
1329  public function inNamespace( $ns ) {
1330  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1331  equals( $this->mNamespace, $ns );
1332  }
1333 
1341  public function inNamespaces( ...$namespaces ) {
1342  if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) {
1343  $namespaces = $namespaces[0];
1344  }
1345 
1346  foreach ( $namespaces as $ns ) {
1347  if ( $this->inNamespace( $ns ) ) {
1348  return true;
1349  }
1350  }
1351 
1352  return false;
1353  }
1354 
1368  public function hasSubjectNamespace( $ns ) {
1369  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1370  subjectEquals( $this->mNamespace, $ns );
1371  }
1372 
1380  public function isContentPage() {
1381  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1382  isContent( $this->mNamespace );
1383  }
1384 
1391  public function isMovable() {
1392  if (
1393  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1394  isMovable( $this->mNamespace ) || $this->isExternal()
1395  ) {
1396  // Interwiki title or immovable namespace. Hooks don't get to override here
1397  return false;
1398  }
1399 
1400  $result = true;
1401  Hooks::runner()->onTitleIsMovable( $this, $result );
1402  return $result;
1403  }
1404 
1415  public function isMainPage() {
1416  return $this->equals( self::newMainPage() );
1417  }
1418 
1424  public function isSubpage() {
1425  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1426  hasSubpages( $this->mNamespace )
1427  ? strpos( $this->getText(), '/' ) !== false
1428  : false;
1429  }
1430 
1436  public function isConversionTable() {
1437  // @todo ConversionTable should become a separate content model.
1438 
1439  return $this->mNamespace === NS_MEDIAWIKI &&
1440  strpos( $this->getText(), 'Conversiontable/' ) === 0;
1441  }
1442 
1448  public function isWikitextPage() {
1449  return $this->hasContentModel( CONTENT_MODEL_WIKITEXT );
1450  }
1451 
1466  public function isSiteConfigPage() {
1467  return (
1468  $this->isSiteCssConfigPage()
1469  || $this->isSiteJsonConfigPage()
1470  || $this->isSiteJsConfigPage()
1471  );
1472  }
1473 
1480  public function isUserConfigPage() {
1481  return (
1482  $this->isUserCssConfigPage()
1483  || $this->isUserJsonConfigPage()
1484  || $this->isUserJsConfigPage()
1485  );
1486  }
1487 
1494  public function getSkinFromConfigSubpage() {
1495  $subpage = explode( '/', $this->mTextform );
1496  $subpage = $subpage[count( $subpage ) - 1];
1497  $lastdot = strrpos( $subpage, '.' );
1498  if ( $lastdot === false ) {
1499  return $subpage; # Never happens: only called for names ending in '.css'/'.json'/'.js'
1500  }
1501  return substr( $subpage, 0, $lastdot );
1502  }
1503 
1510  public function isUserCssConfigPage() {
1511  return (
1512  $this->mNamespace === NS_USER
1513  && $this->isSubpage()
1514  && $this->hasContentModel( CONTENT_MODEL_CSS )
1515  );
1516  }
1517 
1524  public function isUserJsonConfigPage() {
1525  return (
1526  $this->mNamespace === NS_USER
1527  && $this->isSubpage()
1528  && $this->hasContentModel( CONTENT_MODEL_JSON )
1529  );
1530  }
1531 
1538  public function isUserJsConfigPage() {
1539  return (
1540  $this->mNamespace === NS_USER
1541  && $this->isSubpage()
1543  );
1544  }
1545 
1552  public function isSiteCssConfigPage() {
1553  return (
1554  $this->mNamespace === NS_MEDIAWIKI
1555  && (
1557  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1558  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1559  || substr( $this->mDbkeyform, -4 ) === '.css'
1560  )
1561  );
1562  }
1563 
1570  public function isSiteJsonConfigPage() {
1571  return (
1572  $this->mNamespace === NS_MEDIAWIKI
1573  && (
1575  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1576  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1577  || substr( $this->mDbkeyform, -5 ) === '.json'
1578  )
1579  );
1580  }
1581 
1588  public function isSiteJsConfigPage() {
1589  return (
1590  $this->mNamespace === NS_MEDIAWIKI
1591  && (
1593  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1594  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1595  || substr( $this->mDbkeyform, -3 ) === '.js'
1596  )
1597  );
1598  }
1599 
1606  public function isRawHtmlMessage() {
1607  global $wgRawHtmlMessages;
1608 
1609  if ( !$this->inNamespace( NS_MEDIAWIKI ) ) {
1610  return false;
1611  }
1612  $message = lcfirst( $this->getRootTitle()->getDBkey() );
1613  return in_array( $message, $wgRawHtmlMessages, true );
1614  }
1615 
1621  public function isTalkPage() {
1622  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1623  isTalk( $this->mNamespace );
1624  }
1625 
1637  public function getTalkPage() {
1638  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1639  // Instead of failing on invalid titles, let's just log the issue for now.
1640  // See the discussion on T227817.
1641 
1642  // Is this the same title?
1643  $talkNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $this->mNamespace );
1644  if ( $this->mNamespace == $talkNS ) {
1645  return $this;
1646  }
1647 
1648  $title = self::makeTitle( $talkNS, $this->mDbkeyform );
1649 
1650  $this->warnIfPageCannotExist( $title, __METHOD__ );
1651 
1652  return $title;
1653  // TODO: replace the above with the code below:
1654  // return self::castFromLinkTarget(
1655  // MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) );
1656  }
1657 
1667  public function getTalkPageIfDefined() {
1668  if ( !$this->canHaveTalkPage() ) {
1669  return null;
1670  }
1671 
1672  return $this->getTalkPage();
1673  }
1674 
1682  public function getSubjectPage() {
1683  // Is this the same title?
1684  $subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo()
1685  ->getSubject( $this->mNamespace );
1686  if ( $this->mNamespace == $subjectNS ) {
1687  return $this;
1688  }
1689  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1690  // Instead of failing on invalid titles, let's just log the issue for now.
1691  // See the discussion on T227817.
1692  $title = self::makeTitle( $subjectNS, $this->mDbkeyform );
1693 
1694  $this->warnIfPageCannotExist( $title, __METHOD__ );
1695 
1696  return $title;
1697  // TODO: replace the above with the code below:
1698  // return self::castFromLinkTarget(
1699  // MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
1700  }
1701 
1708  private function warnIfPageCannotExist( Title $title, $method ) {
1709  if ( $this->getText() == '' ) {
1710  wfLogWarning(
1711  $method . ': called on empty title ' . $this->getFullText() . ', returning '
1712  . $title->getFullText()
1713  );
1714 
1715  return true;
1716  }
1717 
1718  if ( $this->getInterwiki() !== '' ) {
1719  wfLogWarning(
1720  $method . ': called on interwiki title ' . $this->getFullText() . ', returning '
1721  . $title->getFullText()
1722  );
1723 
1724  return true;
1725  }
1726 
1727  return false;
1728  }
1729 
1739  public function getOtherPage() {
1740  // NOTE: Depend on the methods in this class instead of their equivalent in NamespaceInfo,
1741  // until their semantics has become exactly the same.
1742  // See the discussion on T227817.
1743  if ( $this->isSpecialPage() ) {
1744  throw new MWException( 'Special pages cannot have other pages' );
1745  }
1746  if ( $this->isTalkPage() ) {
1747  return $this->getSubjectPage();
1748  } else {
1749  if ( !$this->canHaveTalkPage() ) {
1750  throw new MWException( "{$this->getPrefixedText()} does not have an other page" );
1751  }
1752  return $this->getTalkPage();
1753  }
1754  // TODO: replace the above with the code below:
1755  // return self::castFromLinkTarget(
1756  // MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) );
1757  }
1758 
1764  public function getDefaultNamespace() {
1765  return $this->mDefaultNamespace;
1766  }
1767 
1775  public function getFragment() {
1776  return $this->mFragment;
1777  }
1778 
1785  public function hasFragment() {
1786  return $this->mFragment !== '';
1787  }
1788 
1794  public function getFragmentForURL() {
1795  if ( !$this->hasFragment() ) {
1796  return '';
1797  } elseif ( $this->isExternal() ) {
1798  // Note: If the interwiki is unknown, it's treated as a namespace on the local wiki,
1799  // so we treat it like a local interwiki.
1800  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
1801  if ( $interwiki && !$interwiki->isLocal() ) {
1802  return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment );
1803  }
1804  }
1805 
1806  return '#' . Sanitizer::escapeIdForLink( $this->mFragment );
1807  }
1808 
1821  public function setFragment( $fragment ) {
1822  $this->mFragment = strtr( substr( $fragment, 1 ), '_', ' ' );
1823  }
1824 
1832  public function createFragmentTarget( $fragment ) {
1833  return self::makeTitle(
1834  $this->mNamespace,
1835  $this->getText(),
1836  $fragment,
1837  $this->mInterwiki
1838  );
1839  }
1840 
1848  private function prefix( $name ) {
1849  $p = '';
1850  if ( $this->isExternal() ) {
1851  $p = $this->mInterwiki . ':';
1852  }
1853 
1854  if ( $this->mNamespace != 0 ) {
1855  $nsText = $this->getNsText();
1856 
1857  if ( $nsText === false ) {
1858  // See T165149. Awkward, but better than erroneously linking to the main namespace.
1859  $nsText = MediaWikiServices::getInstance()->getContentLanguage()->
1860  getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
1861  }
1862 
1863  $p .= $nsText . ':';
1864  }
1865  return $p . $name;
1866  }
1867 
1874  public function getPrefixedDBkey() {
1875  $s = $this->prefix( $this->mDbkeyform );
1876  $s = strtr( $s, ' ', '_' );
1877  return $s;
1878  }
1879 
1886  public function getPrefixedText() {
1887  if ( $this->prefixedText === null ) {
1888  $s = $this->prefix( $this->mTextform );
1889  $s = strtr( $s, '_', ' ' );
1890  $this->prefixedText = $s;
1891  }
1892  return $this->prefixedText;
1893  }
1894 
1900  public function __toString(): string {
1901  return $this->getPrefixedText();
1902  }
1903 
1910  public function getFullText() {
1911  $text = $this->getPrefixedText();
1912  if ( $this->hasFragment() ) {
1913  $text .= '#' . $this->mFragment;
1914  }
1915  return $text;
1916  }
1917 
1932  private function findSubpageDivider( $text, $dir ) {
1933  $top = strlen( $text ) - 1;
1934  $bottom = 0;
1935 
1936  while ( $bottom < $top && $text[$bottom] === '/' ) {
1937  $bottom++;
1938  }
1939 
1940  if ( $top < $bottom ) {
1941  return false;
1942  }
1943 
1944  if ( $dir > 0 ) {
1945  $idx = $bottom;
1946  while ( $idx <= $top && $text[$idx] !== '/' ) {
1947  $idx++;
1948  }
1949  } else {
1950  $idx = $top;
1951  while ( $idx > $bottom && $text[$idx] !== '/' ) {
1952  $idx--;
1953  }
1954  }
1955 
1956  if ( $idx < $bottom || $idx > $top ) {
1957  return false;
1958  }
1959 
1960  if ( $idx < 1 ) {
1961  return false;
1962  }
1963 
1964  return $idx;
1965  }
1966 
1971  private function hasSubpagesEnabled() {
1972  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1973  hasSubpages( $this->mNamespace );
1974  }
1975 
1991  public function getRootText() {
1992  $text = $this->getText();
1993  if ( !$this->hasSubpagesEnabled() ) {
1994  return $text;
1995  }
1996 
1997  $firstSlashPos = $this->findSubpageDivider( $text, +1 );
1998  // Don't discard the real title if there's no subpage involved
1999  if ( $firstSlashPos === false ) {
2000  return $text;
2001  }
2002 
2003  return substr( $text, 0, $firstSlashPos );
2004  }
2005 
2018  public function getRootTitle() {
2019  $title = self::makeTitleSafe( $this->mNamespace, $this->getRootText() );
2020  Assert::postcondition(
2021  $title !== null,
2022  'makeTitleSafe() should always return a Title for the text returned by getRootText().'
2023  );
2024  return $title;
2025  }
2026 
2041  public function getBaseText() {
2042  $text = $this->getText();
2043  if ( !$this->hasSubpagesEnabled() ) {
2044  return $text;
2045  }
2046 
2047  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
2048  // Don't discard the real title if there's no subpage involved
2049  if ( $lastSlashPos === false ) {
2050  return $text;
2051  }
2052 
2053  return substr( $text, 0, $lastSlashPos );
2054  }
2055 
2068  public function getBaseTitle() {
2069  $title = self::makeTitleSafe( $this->mNamespace, $this->getBaseText() );
2070  Assert::postcondition(
2071  $title !== null,
2072  'makeTitleSafe() should always return a Title for the text returned by getBaseText().'
2073  );
2074  return $title;
2075  }
2076 
2088  public function getSubpageText() {
2089  $text = $this->getText();
2090  if ( !$this->hasSubpagesEnabled() ) {
2091  return $text;
2092  }
2093 
2094  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
2095  if ( $lastSlashPos === false ) {
2096  // T256922 - Return the title text if no subpages
2097  return $text;
2098  }
2099  return substr( $text, $lastSlashPos + 1 );
2100  }
2101 
2115  public function getSubpage( $text ) {
2116  return self::makeTitleSafe(
2117  $this->mNamespace,
2118  $this->getText() . '/' . $text,
2119  '',
2120  $this->mInterwiki
2121  );
2122  }
2123 
2129  public function getSubpageUrlForm() {
2130  $text = $this->getSubpageText();
2131  $text = wfUrlencode( strtr( $text, ' ', '_' ) );
2132  return $text;
2133  }
2134 
2140  public function getPrefixedURL() {
2141  $s = $this->prefix( $this->mDbkeyform );
2142  $s = wfUrlencode( strtr( $s, ' ', '_' ) );
2143  return $s;
2144  }
2145 
2159  private static function fixUrlQueryArgs( $query, $query2 = false ) {
2160  if ( $query2 !== false ) {
2161  wfDeprecatedMsg( "Title::get{Canonical,Full,Link,Local,Internal}URL " .
2162  "method called with a second parameter is deprecated since MediaWiki 1.19. " .
2163  "Add your parameter to an array passed as the first parameter.", "1.19" );
2164  }
2165  if ( is_array( $query ) ) {
2166  $query = wfArrayToCgi( $query );
2167  }
2168  if ( $query2 ) {
2169  if ( is_string( $query2 ) ) {
2170  // $query2 is a string, we will consider this to be
2171  // a deprecated $variant argument and add it to the query
2172  $query2 = wfArrayToCgi( [ 'variant' => $query2 ] );
2173  } else {
2174  $query2 = wfArrayToCgi( $query2 );
2175  }
2176  // If we have $query content add a & to it first
2177  if ( $query ) {
2178  $query .= '&';
2179  }
2180  // Now append the queries together
2181  $query .= $query2;
2182  }
2183  return $query;
2184  }
2185 
2197  public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
2198  $query = self::fixUrlQueryArgs( $query, $query2 );
2199 
2200  # Hand off all the decisions on urls to getLocalURL
2201  $url = $this->getLocalURL( $query );
2202 
2203  # Expand the url to make it a full url. Note that getLocalURL has the
2204  # potential to output full urls for a variety of reasons, so we use
2205  # wfExpandUrl instead of simply prepending $wgServer
2206  $url = wfExpandUrl( $url, $proto );
2207 
2208  # Finally, add the fragment.
2209  $url .= $this->getFragmentForURL();
2210  Hooks::runner()->onGetFullURL( $this, $url, $query );
2211  return $url;
2212  }
2213 
2230  public function getFullUrlForRedirect( $query = '', $proto = PROTO_CURRENT ) {
2231  $target = $this;
2232  if ( $this->isExternal() ) {
2233  $target = SpecialPage::getTitleFor(
2234  'GoToInterwiki',
2235  $this->getPrefixedDBkey()
2236  );
2237  }
2238  return $target->getFullURL( $query, false, $proto );
2239  }
2240 
2264  public function getLocalURL( $query = '', $query2 = false ) {
2266 
2267  $query = self::fixUrlQueryArgs( $query, $query2 );
2268 
2269  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
2270  if ( $interwiki ) {
2271  $namespace = $this->getNsText();
2272  if ( $namespace != '' ) {
2273  # Can this actually happen? Interwikis shouldn't be parsed.
2274  # Yes! It can in interwiki transclusion. But... it probably shouldn't.
2275  $namespace .= ':';
2276  }
2277  $url = $interwiki->getURL( $namespace . $this->mDbkeyform );
2278  $url = wfAppendQuery( $url, $query );
2279  } else {
2280  $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
2281  if ( $query == '' ) {
2282  $url = str_replace( '$1', $dbkey, $wgArticlePath );
2283  Hooks::runner()->onGetLocalURL__Article( $this, $url );
2284  } else {
2286  $url = false;
2287  $matches = [];
2288 
2290 
2291  if ( $articlePaths
2292  && preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
2293  ) {
2294  $action = urldecode( $matches[2] );
2295  if ( isset( $articlePaths[$action] ) ) {
2296  $query = $matches[1];
2297  if ( isset( $matches[4] ) ) {
2298  $query .= $matches[4];
2299  }
2300  $url = str_replace( '$1', $dbkey, $articlePaths[$action] );
2301  if ( $query != '' ) {
2302  $url = wfAppendQuery( $url, $query );
2303  }
2304  }
2305  }
2306 
2307  if ( $url === false
2309  && preg_match( '/^variant=([^&]*)$/', $query, $matches )
2310  && $this->getPageLanguage()->equals(
2311  MediaWikiServices::getInstance()->getContentLanguage() )
2312  && $this->getPageLanguageConverter()->hasVariants()
2313  ) {
2314  $variant = urldecode( $matches[1] );
2315  if ( $this->getPageLanguageConverter()->hasVariant( $variant ) ) {
2316  // Only do the variant replacement if the given variant is a valid
2317  // variant for the page's language.
2318  $url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath );
2319  $url = str_replace( '$1', $dbkey, $url );
2320  }
2321  }
2322 
2323  if ( $url === false ) {
2324  if ( $query == '-' ) {
2325  $query = '';
2326  }
2327  $url = "{$wgScript}?title={$dbkey}&{$query}";
2328  }
2329  }
2330  Hooks::runner()->onGetLocalURL__Internal( $this, $url, $query );
2331 
2332  // @todo FIXME: This causes breakage in various places when we
2333  // actually expected a local URL and end up with dupe prefixes.
2334  if ( $wgRequest->getVal( 'action' ) == 'render' ) {
2335  LoggerFactory::getInstance( 'T263581' )
2336  ->debug(
2337  "Title::getLocalURL called from render action",
2338  [
2339  'title' => $this->getPrefixedDBkey(),
2340  'exception' => new Exception()
2341  ]
2342  );
2343  $url = $wgServer . $url;
2344  }
2345  }
2346 
2347  if ( $wgMainPageIsDomainRoot && $this->isMainPage() && $query === '' ) {
2348  return '/';
2349  }
2350 
2351  Hooks::runner()->onGetLocalURL( $this, $url, $query );
2352  return $url;
2353  }
2354 
2372  public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
2373  if ( $this->isExternal() || $proto !== false ) {
2374  $ret = $this->getFullURL( $query, $query2, $proto );
2375  } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
2376  $ret = $this->getFragmentForURL();
2377  } else {
2378  $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
2379  }
2380  return $ret;
2381  }
2382 
2397  public function getInternalURL( $query = '', $query2 = false ) {
2398  global $wgInternalServer, $wgServer;
2399  $query = self::fixUrlQueryArgs( $query, $query2 );
2400  $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
2401  $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP );
2402  Hooks::runner()->onGetInternalURL( $this, $url, $query );
2403  return $url;
2404  }
2405 
2419  public function getCanonicalURL( $query = '', $query2 = false ) {
2420  $query = self::fixUrlQueryArgs( $query, $query2 );
2421  $url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL );
2422  Hooks::runner()->onGetCanonicalURL( $this, $url, $query );
2423  return $url;
2424  }
2425 
2431  public function getEditURL() {
2432  if ( $this->isExternal() ) {
2433  return '';
2434  }
2435  $s = $this->getLocalURL( 'action=edit' );
2436 
2437  return $s;
2438  }
2439 
2447  public static function getFilteredRestrictionTypes( $exists = true ) {
2448  global $wgRestrictionTypes;
2449  $types = $wgRestrictionTypes;
2450  if ( $exists ) {
2451  # Remove the create restriction for existing titles
2452  $types = array_diff( $types, [ 'create' ] );
2453  } else {
2454  # Only the create and upload restrictions apply to non-existing titles
2455  $types = array_intersect( $types, [ 'create', 'upload' ] );
2456  }
2457  return $types;
2458  }
2459 
2465  public function getRestrictionTypes() {
2466  if ( $this->isSpecialPage() ) {
2467  return [];
2468  }
2469 
2470  $types = self::getFilteredRestrictionTypes( $this->exists() );
2471 
2472  if ( $this->mNamespace !== NS_FILE ) {
2473  # Remove the upload restriction for non-file titles
2474  $types = array_diff( $types, [ 'upload' ] );
2475  }
2476 
2477  Hooks::runner()->onTitleGetRestrictionTypes( $this, $types );
2478 
2479  wfDebug( __METHOD__ . ': applicable restrictions to [[' .
2480  $this->getPrefixedText() . ']] are {' . implode( ',', $types ) . "}" );
2481 
2482  return $types;
2483  }
2484 
2492  public function getTitleProtection() {
2493  $protection = $this->getTitleProtectionInternal();
2494  if ( $protection ) {
2495  if ( $protection['permission'] == 'sysop' ) {
2496  $protection['permission'] = 'editprotected'; // B/C
2497  }
2498  if ( $protection['permission'] == 'autoconfirmed' ) {
2499  $protection['permission'] = 'editsemiprotected'; // B/C
2500  }
2501  }
2502  return $protection;
2503  }
2504 
2515  protected function getTitleProtectionInternal() {
2516  // Can't protect pages in special namespaces
2517  if ( $this->mNamespace < 0 ) {
2518  return false;
2519  }
2520 
2521  // Can't protect pages that exist.
2522  if ( $this->exists() ) {
2523  return false;
2524  }
2525 
2526  if ( $this->mTitleProtection === null ) {
2527  $dbr = wfGetDB( DB_REPLICA );
2528  $commentStore = CommentStore::getStore();
2529  $commentQuery = $commentStore->getJoin( 'pt_reason' );
2530  $res = $dbr->select(
2531  [ 'protected_titles' ] + $commentQuery['tables'],
2532  [
2533  'user' => 'pt_user',
2534  'expiry' => 'pt_expiry',
2535  'permission' => 'pt_create_perm'
2536  ] + $commentQuery['fields'],
2537  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2538  __METHOD__,
2539  [],
2540  $commentQuery['joins']
2541  );
2542 
2543  // fetchRow returns false if there are no rows.
2544  $row = $dbr->fetchRow( $res );
2545  if ( $row ) {
2546  $this->mTitleProtection = [
2547  'user' => $row['user'],
2548  'expiry' => $dbr->decodeExpiry( $row['expiry'] ),
2549  'permission' => $row['permission'],
2550  'reason' => $commentStore->getComment( 'pt_reason', $row )->text,
2551  ];
2552  } else {
2553  $this->mTitleProtection = false;
2554  }
2555  }
2556  return $this->mTitleProtection;
2557  }
2558 
2562  public function deleteTitleProtection() {
2563  $dbw = wfGetDB( DB_MASTER );
2564 
2565  $dbw->delete(
2566  'protected_titles',
2567  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2568  __METHOD__
2569  );
2570  $this->mTitleProtection = false;
2571  }
2572 
2580  public function isSemiProtected( $action = 'edit' ) {
2582 
2583  $restrictions = $this->getRestrictions( $action );
2585  if ( !$restrictions || !$semi ) {
2586  // Not protected, or all protection is full protection
2587  return false;
2588  }
2589 
2590  // Remap autoconfirmed to editsemiprotected for BC
2591  foreach ( array_keys( $semi, 'autoconfirmed' ) as $key ) {
2592  $semi[$key] = 'editsemiprotected';
2593  }
2594  foreach ( array_keys( $restrictions, 'autoconfirmed' ) as $key ) {
2595  $restrictions[$key] = 'editsemiprotected';
2596  }
2597 
2598  return !array_diff( $restrictions, $semi );
2599  }
2600 
2608  public function isProtected( $action = '' ) {
2609  global $wgRestrictionLevels;
2610 
2611  $restrictionTypes = $this->getRestrictionTypes();
2612 
2613  # Special pages have inherent protection
2614  if ( $this->isSpecialPage() ) {
2615  return true;
2616  }
2617 
2618  # Check regular protection levels
2619  foreach ( $restrictionTypes as $type ) {
2620  if ( $action == $type || $action == '' ) {
2621  $r = $this->getRestrictions( $type );
2622  foreach ( $wgRestrictionLevels as $level ) {
2623  if ( in_array( $level, $r ) && $level != '' ) {
2624  return true;
2625  }
2626  }
2627  }
2628  }
2629 
2630  return false;
2631  }
2632 
2641  public function isNamespaceProtected( User $user ) {
2642  global $wgNamespaceProtection;
2643 
2644  if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
2645  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2646  foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
2647  if ( !$permissionManager->userHasRight( $user, $right ) ) {
2648  return true;
2649  }
2650  }
2651  }
2652  return false;
2653  }
2654 
2660  public function isCascadeProtected() {
2661  list( $isCascadeProtected, ) = $this->getCascadeProtectionSources( false );
2662  return $isCascadeProtected;
2663  }
2664 
2674  public function areCascadeProtectionSourcesLoaded( $getPages = true ) {
2675  return $getPages ? $this->mCascadeSources !== null : $this->mHasCascadingRestrictions !== null;
2676  }
2677 
2691  public function getCascadeProtectionSources( $getPages = true ) {
2692  $pagerestrictions = [];
2693 
2694  if ( $this->mCascadeSources !== null && $getPages ) {
2696  } elseif ( $this->mHasCascadingRestrictions !== null && !$getPages ) {
2697  return [ $this->mHasCascadingRestrictions, $pagerestrictions ];
2698  }
2699 
2700  $dbr = wfGetDB( DB_REPLICA );
2701 
2702  if ( $this->mNamespace === NS_FILE ) {
2703  $tables = [ 'imagelinks', 'page_restrictions' ];
2704  $where_clauses = [
2705  'il_to' => $this->mDbkeyform,
2706  'il_from=pr_page',
2707  'pr_cascade' => 1
2708  ];
2709  } else {
2710  $tables = [ 'templatelinks', 'page_restrictions' ];
2711  $where_clauses = [
2712  'tl_namespace' => $this->mNamespace,
2713  'tl_title' => $this->mDbkeyform,
2714  'tl_from=pr_page',
2715  'pr_cascade' => 1
2716  ];
2717  }
2718 
2719  if ( $getPages ) {
2720  $cols = [ 'pr_page', 'page_namespace', 'page_title',
2721  'pr_expiry', 'pr_type', 'pr_level' ];
2722  $where_clauses[] = 'page_id=pr_page';
2723  $tables[] = 'page';
2724  } else {
2725  $cols = [ 'pr_expiry' ];
2726  }
2727 
2728  $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__ );
2729 
2730  $sources = $getPages ? [] : false;
2731  $now = wfTimestampNow();
2732 
2733  foreach ( $res as $row ) {
2734  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2735  if ( $expiry > $now ) {
2736  if ( $getPages ) {
2737  $page_id = $row->pr_page;
2738  $page_ns = $row->page_namespace;
2739  $page_title = $row->page_title;
2740  $sources[$page_id] = self::makeTitle( $page_ns, $page_title );
2741  # Add groups needed for each restriction type if its not already there
2742  # Make sure this restriction type still exists
2743 
2744  if ( !isset( $pagerestrictions[$row->pr_type] ) ) {
2745  $pagerestrictions[$row->pr_type] = [];
2746  }
2747 
2748  if (
2749  isset( $pagerestrictions[$row->pr_type] )
2750  && !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] )
2751  ) {
2752  $pagerestrictions[$row->pr_type][] = $row->pr_level;
2753  }
2754  } else {
2755  $sources = true;
2756  }
2757  }
2758  }
2759 
2760  if ( $getPages ) {
2761  $this->mCascadeSources = $sources;
2762  $this->mCascadingRestrictions = $pagerestrictions;
2763  } else {
2764  $this->mHasCascadingRestrictions = $sources;
2765  }
2766 
2767  return [ $sources, $pagerestrictions ];
2768  }
2769 
2777  public function areRestrictionsLoaded() {
2779  }
2780 
2790  public function getRestrictions( $action ) {
2791  if ( !$this->mRestrictionsLoaded ) {
2792  $this->loadRestrictions();
2793  }
2794  return $this->mRestrictions[$action] ?? [];
2795  }
2796 
2804  public function getAllRestrictions() {
2805  if ( !$this->mRestrictionsLoaded ) {
2806  $this->loadRestrictions();
2807  }
2808  return $this->mRestrictions;
2809  }
2810 
2818  public function getRestrictionExpiry( $action ) {
2819  if ( !$this->mRestrictionsLoaded ) {
2820  $this->loadRestrictions();
2821  }
2822  return $this->mRestrictionsExpiry[$action] ?? false;
2823  }
2824 
2830  public function areRestrictionsCascading() {
2831  if ( !$this->mRestrictionsLoaded ) {
2832  $this->loadRestrictions();
2833  }
2834 
2836  }
2837 
2849  public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
2850  // This function will only read rows from a table that we migrated away
2851  // from before adding READ_LATEST support to loadRestrictions, so we
2852  // don't need to support reading from DB_MASTER here.
2853  $dbr = wfGetDB( DB_REPLICA );
2854 
2855  $restrictionTypes = $this->getRestrictionTypes();
2856 
2857  foreach ( $restrictionTypes as $type ) {
2858  $this->mRestrictions[$type] = [];
2859  $this->mRestrictionsExpiry[$type] = 'infinity';
2860  }
2861 
2862  $this->mCascadeRestriction = false;
2863 
2864  # Backwards-compatibility: also load the restrictions from the page record (old format).
2865  if ( $oldFashionedRestrictions !== null ) {
2866  $this->mOldRestrictions = $oldFashionedRestrictions;
2867  }
2868 
2869  if ( $this->mOldRestrictions === false ) {
2870  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2871  $linkCache->addLinkObj( $this ); # in case we already had an article ID
2872  $this->mOldRestrictions = $linkCache->getGoodLinkFieldObj( $this, 'restrictions' );
2873  }
2874 
2875  if ( $this->mOldRestrictions != '' ) {
2876  foreach ( explode( ':', trim( $this->mOldRestrictions ) ) as $restrict ) {
2877  $temp = explode( '=', trim( $restrict ) );
2878  if ( count( $temp ) == 1 ) {
2879  // old old format should be treated as edit/move restriction
2880  $this->mRestrictions['edit'] = explode( ',', trim( $temp[0] ) );
2881  $this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) );
2882  } else {
2883  $restriction = trim( $temp[1] );
2884  if ( $restriction != '' ) { // some old entries are empty
2885  $this->mRestrictions[$temp[0]] = explode( ',', $restriction );
2886  }
2887  }
2888  }
2889  }
2890 
2891  if ( count( $rows ) ) {
2892  # Current system - load second to make them override.
2893  $now = wfTimestampNow();
2894 
2895  # Cycle through all the restrictions.
2896  foreach ( $rows as $row ) {
2897  // Don't take care of restrictions types that aren't allowed
2898  if ( !in_array( $row->pr_type, $restrictionTypes ) ) {
2899  continue;
2900  }
2901 
2902  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2903 
2904  // Only apply the restrictions if they haven't expired!
2905  if ( !$expiry || $expiry > $now ) {
2906  $this->mRestrictionsExpiry[$row->pr_type] = $expiry;
2907  $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) );
2908 
2909  $this->mCascadeRestriction = $this->mCascadeRestriction || $row->pr_cascade;
2910  }
2911  }
2912  }
2913 
2914  $this->mRestrictionsLoaded = true;
2915  }
2916 
2927  public function loadRestrictions( $oldFashionedRestrictions = null, $flags = 0 ) {
2928  $readLatest = DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST );
2929  if ( $this->mRestrictionsLoaded && !$readLatest ) {
2930  return;
2931  }
2932 
2933  $id = $this->getArticleID( $flags );
2934  if ( $id ) {
2935  $fname = __METHOD__;
2936  $loadRestrictionsFromDb = static function ( IDatabase $dbr ) use ( $fname, $id ) {
2937  return iterator_to_array(
2938  $dbr->select(
2939  'page_restrictions',
2940  [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
2941  [ 'pr_page' => $id ],
2942  $fname
2943  )
2944  );
2945  };
2946 
2947  if ( $readLatest ) {
2948  $dbr = wfGetDB( DB_MASTER );
2949  $rows = $loadRestrictionsFromDb( $dbr );
2950  } else {
2951  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
2952  $rows = $cache->getWithSetCallback(
2953  // Page protections always leave a new null revision
2954  $cache->makeKey( 'page-restrictions', 'v1', $id, $this->getLatestRevID() ),
2955  $cache::TTL_DAY,
2956  static function ( $curValue, &$ttl, array &$setOpts ) use ( $loadRestrictionsFromDb ) {
2957  $dbr = wfGetDB( DB_REPLICA );
2958 
2959  $setOpts += Database::getCacheSetOptions( $dbr );
2960  $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
2961  if ( $lb->hasOrMadeRecentMasterChanges() ) {
2962  // @TODO: cleanup Title cache and caller assumption mess in general
2963  $ttl = WANObjectCache::TTL_UNCACHEABLE;
2964  }
2965 
2966  return $loadRestrictionsFromDb( $dbr );
2967  }
2968  );
2969  }
2970 
2971  $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
2972  } else {
2973  $title_protection = $this->getTitleProtectionInternal();
2974 
2975  if ( $title_protection ) {
2976  $now = wfTimestampNow();
2977  $expiry = wfGetDB( DB_REPLICA )->decodeExpiry( $title_protection['expiry'] );
2978 
2979  if ( !$expiry || $expiry > $now ) {
2980  // Apply the restrictions
2981  $this->mRestrictionsExpiry['create'] = $expiry;
2982  $this->mRestrictions['create'] =
2983  explode( ',', trim( $title_protection['permission'] ) );
2984  } else { // Get rid of the old restrictions
2985  $this->mTitleProtection = false;
2986  }
2987  } else {
2988  $this->mRestrictionsExpiry['create'] = 'infinity';
2989  }
2990  $this->mRestrictionsLoaded = true;
2991  }
2992  }
2993 
2998  public function flushRestrictions() {
2999  $this->mRestrictionsLoaded = false;
3000  $this->mTitleProtection = null;
3001  }
3002 
3008  public static function purgeExpiredRestrictions() {
3009  if ( wfReadOnly() ) {
3010  return;
3011  }
3012 
3014  wfGetDB( DB_MASTER ),
3015  __METHOD__,
3016  static function ( IDatabase $dbw, $fname ) {
3017  $config = MediaWikiServices::getInstance()->getMainConfig();
3018  $ids = $dbw->selectFieldValues(
3019  'page_restrictions',
3020  'pr_id',
3021  [ 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3022  $fname,
3023  [ 'LIMIT' => $config->get( 'UpdateRowsPerQuery' ) ] // T135470
3024  );
3025  if ( $ids ) {
3026  $dbw->delete( 'page_restrictions', [ 'pr_id' => $ids ], $fname );
3027  }
3028  }
3029  ) );
3030 
3032  wfGetDB( DB_MASTER ),
3033  __METHOD__,
3034  static function ( IDatabase $dbw, $fname ) {
3035  $dbw->delete(
3036  'protected_titles',
3037  [ 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3038  $fname
3039  );
3040  }
3041  ) );
3042  }
3043 
3049  public function hasSubpages() {
3050  if (
3051  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3052  hasSubpages( $this->mNamespace )
3053  ) {
3054  # Duh
3055  return false;
3056  }
3057 
3058  # We dynamically add a member variable for the purpose of this method
3059  # alone to cache the result. There's no point in having it hanging
3060  # around uninitialized in every Title object; therefore we only add it
3061  # if needed and don't declare it statically.
3062  if ( $this->mHasSubpages === null ) {
3063  $this->mHasSubpages = false;
3064  $subpages = $this->getSubpages( 1 );
3065  if ( $subpages instanceof TitleArray ) {
3066  $this->mHasSubpages = (bool)$subpages->current();
3067  }
3068  }
3069 
3070  return $this->mHasSubpages;
3071  }
3072 
3080  public function getSubpages( $limit = -1 ) {
3081  if (
3082  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3083  hasSubpages( $this->mNamespace )
3084  ) {
3085  return [];
3086  }
3087 
3088  $dbr = wfGetDB( DB_REPLICA );
3089  $conds = [ 'page_namespace' => $this->mNamespace ];
3090  $conds[] = 'page_title ' . $dbr->buildLike( $this->mDbkeyform . '/', $dbr->anyString() );
3091  $options = [];
3092  if ( $limit > -1 ) {
3093  $options['LIMIT'] = $limit;
3094  }
3096  $dbr->select( 'page',
3097  [ 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ],
3098  $conds,
3099  __METHOD__,
3100  $options
3101  )
3102  );
3103  }
3104 
3111  public function isDeleted() {
3112  return $this->getDeletedEditsCount();
3113  }
3114 
3121  public function getDeletedEditsCount() {
3122  if ( $this->mNamespace < 0 ) {
3123  $n = 0;
3124  } else {
3125  $dbr = wfGetDB( DB_REPLICA );
3126 
3127  $n = $dbr->selectField( 'archive', 'COUNT(*)',
3128  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3129  __METHOD__
3130  );
3131  if ( $this->mNamespace === NS_FILE ) {
3132  $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
3133  [ 'fa_name' => $this->mDbkeyform ],
3134  __METHOD__
3135  );
3136  }
3137  }
3138  return (int)$n;
3139  }
3140 
3147  public function isDeletedQuick() {
3148  return $this->hasDeletedEdits();
3149  }
3150 
3157  public function hasDeletedEdits() {
3158  if ( $this->mNamespace < 0 ) {
3159  return false;
3160  }
3161  $dbr = wfGetDB( DB_REPLICA );
3162  $deleted = (bool)$dbr->selectField( 'archive', '1',
3163  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3164  __METHOD__
3165  );
3166  if ( !$deleted && $this->mNamespace === NS_FILE ) {
3167  $deleted = (bool)$dbr->selectField( 'filearchive', '1',
3168  [ 'fa_name' => $this->mDbkeyform ],
3169  __METHOD__
3170  );
3171  }
3172  return $deleted;
3173  }
3174 
3182  public function getArticleID( $flags = 0 ) {
3183  if ( $this->mNamespace < 0 ) {
3184  $this->mArticleID = 0;
3185 
3186  return $this->mArticleID;
3187  }
3188 
3189  if ( $flags & self::GAID_FOR_UPDATE ) {
3190  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3191  $oldUpdate = $linkCache->forUpdate( true );
3192  $linkCache->clearLink( $this );
3193  $this->mArticleID = $linkCache->addLinkObj( $this );
3194  $linkCache->forUpdate( $oldUpdate );
3195  } elseif ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3196  // If mArticleID is >0, pageCond() will use it, making it impossible
3197  // for the call below to return a different result, e.g. after a
3198  // page move.
3199  $this->mArticleID = -1;
3200  $this->mArticleID = (int)$this->loadFieldFromDB( 'page_id', $flags );
3201  } elseif ( $this->mArticleID == -1 ) {
3202  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3203  $this->mArticleID = $linkCache->addLinkObj( $this );
3204  }
3205 
3206  return $this->mArticleID;
3207  }
3208 
3223  public function isRedirect( $flags = 0 ) {
3224  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3225  $this->mRedirect = (bool)$this->loadFieldFromDB( 'page_is_redirect', $flags );
3226  } elseif ( $this->mRedirect === null ) {
3227  if ( $this->getArticleID( $flags ) ) {
3228  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3229  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3230  // Note that LinkCache returns null if it thinks the page does not exist;
3231  // always trust the state of LinkCache over that of this Title instance.
3232  $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
3233  } else {
3234  $this->mRedirect = false;
3235  }
3236  }
3237 
3238  return $this->mRedirect;
3239  }
3240 
3248  public function getLength( $flags = 0 ) {
3249  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3250  $this->mLength = (int)$this->loadFieldFromDB( 'page_len', $flags );
3251  } else {
3252  if ( $this->mLength != -1 ) {
3253  return $this->mLength;
3254  } elseif ( !$this->getArticleID( $flags ) ) {
3255  $this->mLength = 0;
3256  return $this->mLength;
3257  }
3258 
3259  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3260  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3261  // Note that LinkCache returns null if it thinks the page does not exist;
3262  // always trust the state of LinkCache over that of this Title instance.
3263  $this->mLength = (int)$linkCache->getGoodLinkFieldObj( $this, 'length' );
3264  }
3265 
3266  return $this->mLength;
3267  }
3268 
3275  public function getLatestRevID( $flags = 0 ) {
3276  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3277  $this->mLatestID = (int)$this->loadFieldFromDB( 'page_latest', $flags );
3278  } else {
3279  if ( $this->mLatestID !== false ) {
3280  return (int)$this->mLatestID;
3281  } elseif ( !$this->getArticleID( $flags ) ) {
3282  $this->mLatestID = 0;
3283 
3284  return $this->mLatestID;
3285  }
3286 
3287  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3288  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3289  // Note that LinkCache returns null if it thinks the page does not exist;
3290  // always trust the state of LinkCache over that of this Title instance.
3291  $this->mLatestID = (int)$linkCache->getGoodLinkFieldObj( $this, 'revision' );
3292  }
3293 
3294  return $this->mLatestID;
3295  }
3296 
3310  public function resetArticleID( $id ) {
3311  if ( $id === false ) {
3312  $this->mArticleID = -1;
3313  } else {
3314  $this->mArticleID = (int)$id;
3315  }
3316  $this->mRestrictionsLoaded = false;
3317  $this->mRestrictions = [];
3318  $this->mOldRestrictions = false;
3319  $this->mRedirect = null;
3320  $this->mLength = -1;
3321  $this->mLatestID = false;
3322  $this->mContentModel = false;
3323  $this->mForcedContentModel = false;
3324  $this->mEstimateRevisions = null;
3325  $this->mPageLanguage = null;
3326  $this->mDbPageLanguage = false;
3327  $this->mIsBigDeletion = null;
3328 
3329  MediaWikiServices::getInstance()->getLinkCache()->clearLink( $this );
3330  }
3331 
3332  public static function clearCaches() {
3333  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3334  $linkCache->clear();
3335 
3337  $titleCache->clear();
3338  }
3339 
3347  public static function capitalize( $text, $ns = NS_MAIN ) {
3348  $services = MediaWikiServices::getInstance();
3349  if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) {
3350  return $services->getContentLanguage()->ucfirst( $text );
3351  } else {
3352  return $text;
3353  }
3354  }
3355 
3372  private function secureAndSplit( $text, $defaultNamespace = null ) {
3373  if ( $defaultNamespace === null ) {
3374  $defaultNamespace = $this->mDefaultNamespace;
3375  }
3376 
3377  // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
3378  // the parsing code with Title, while avoiding massive refactoring.
3379  // @todo: get rid of secureAndSplit, refactor parsing code.
3380  // @note: getTitleParser() returns a TitleParser implementation which does not have a
3381  // splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
3383  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
3384  '@phan-var MediaWikiTitleCodec $titleCodec';
3385  // MalformedTitleException can be thrown here
3386  $parts = $titleCodec->splitTitleString( $text, $defaultNamespace );
3387 
3388  # Fill fields
3389  $this->setFragment( '#' . $parts['fragment'] );
3390  $this->mInterwiki = $parts['interwiki'];
3391  $this->mLocalInterwiki = $parts['local_interwiki'];
3392  $this->mNamespace = $parts['namespace'];
3393  $this->mDefaultNamespace = $defaultNamespace;
3394 
3395  $this->mDbkeyform = $parts['dbkey'];
3396  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
3397  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
3398 
3399  // splitTitleString() guarantees that this title is valid.
3400  $this->mIsValid = true;
3401 
3402  # We already know that some pages won't be in the database!
3403  if ( $this->isExternal() || $this->isSpecialPage() || $this->mTextform === '' ) {
3404  $this->mArticleID = 0;
3405  }
3406  }
3407 
3420  public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3421  if ( count( $options ) > 0 ) {
3422  $db = wfGetDB( DB_MASTER );
3423  } else {
3424  $db = wfGetDB( DB_REPLICA );
3425  }
3426 
3427  $res = $db->select(
3428  [ 'page', $table ],
3429  self::getSelectFields(),
3430  [
3431  "{$prefix}_from=page_id",
3432  "{$prefix}_namespace" => $this->mNamespace,
3433  "{$prefix}_title" => $this->mDbkeyform ],
3434  __METHOD__,
3435  $options
3436  );
3437 
3438  $retVal = [];
3439  if ( $res->numRows() ) {
3440  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3441  foreach ( $res as $row ) {
3442  $titleObj = self::makeTitle( $row->page_namespace, $row->page_title );
3443  if ( $titleObj ) {
3444  $linkCache->addGoodLinkObjFromRow( $titleObj, $row );
3445  $retVal[] = $titleObj;
3446  }
3447  }
3448  }
3449  return $retVal;
3450  }
3451 
3462  public function getTemplateLinksTo( $options = [] ) {
3463  return $this->getLinksTo( $options, 'templatelinks', 'tl' );
3464  }
3465 
3478  public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3479  $id = $this->getArticleID();
3480 
3481  # If the page doesn't exist; there can't be any link from this page
3482  if ( !$id ) {
3483  return [];
3484  }
3485 
3486  $db = wfGetDB( DB_REPLICA );
3487 
3488  $blNamespace = "{$prefix}_namespace";
3489  $blTitle = "{$prefix}_title";
3490 
3491  $pageQuery = WikiPage::getQueryInfo();
3492  $res = $db->select(
3493  [ $table, 'nestpage' => $pageQuery['tables'] ],
3494  array_merge(
3495  [ $blNamespace, $blTitle ],
3496  $pageQuery['fields']
3497  ),
3498  [ "{$prefix}_from" => $id ],
3499  __METHOD__,
3500  $options,
3501  [ 'nestpage' => [
3502  'LEFT JOIN',
3503  [ "page_namespace=$blNamespace", "page_title=$blTitle" ]
3504  ] ] + $pageQuery['joins']
3505  );
3506 
3507  $retVal = [];
3508  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3509  foreach ( $res as $row ) {
3510  if ( $row->page_id ) {
3511  $titleObj = self::newFromRow( $row );
3512  } else {
3513  $titleObj = self::makeTitle( $row->$blNamespace, $row->$blTitle );
3514  $linkCache->addBadLinkObj( $titleObj );
3515  }
3516  $retVal[] = $titleObj;
3517  }
3518 
3519  return $retVal;
3520  }
3521 
3532  public function getTemplateLinksFrom( $options = [] ) {
3533  return $this->getLinksFrom( $options, 'templatelinks', 'tl' );
3534  }
3535 
3544  public function getBrokenLinksFrom() {
3545  if ( $this->getArticleID() == 0 ) {
3546  # All links from article ID 0 are false positives
3547  return [];
3548  }
3549 
3550  $dbr = wfGetDB( DB_REPLICA );
3551  $res = $dbr->select(
3552  [ 'page', 'pagelinks' ],
3553  [ 'pl_namespace', 'pl_title' ],
3554  [
3555  'pl_from' => $this->getArticleID(),
3556  'page_namespace IS NULL'
3557  ],
3558  __METHOD__, [],
3559  [
3560  'page' => [
3561  'LEFT JOIN',
3562  [ 'pl_namespace=page_namespace', 'pl_title=page_title' ]
3563  ]
3564  ]
3565  );
3566 
3567  $retVal = [];
3568  foreach ( $res as $row ) {
3569  $retVal[] = self::makeTitle( $row->pl_namespace, $row->pl_title );
3570  }
3571  return $retVal;
3572  }
3573 
3580  public function getCdnUrls() {
3581  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3582  return $htmlCache->getUrls( $this );
3583  }
3584 
3589  public function purgeSquid() {
3590  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3591  $htmlCache->purgeTitleUrls( $this, $htmlCache::PURGE_INTENT_TXROUND_REFLECTED );
3592  }
3593 
3601  public function isSingleRevRedirect() {
3602  $dbw = wfGetDB( DB_MASTER );
3603  $dbw->startAtomic( __METHOD__ );
3604 
3605  $row = $dbw->selectRow(
3606  'page',
3607  self::getSelectFields(),
3608  $this->pageCond(),
3609  __METHOD__,
3610  [ 'FOR UPDATE' ]
3611  );
3612  // Update the cached fields
3613  $this->loadFromRow( $row );
3614 
3615  if ( $this->mRedirect && $this->mLatestID ) {
3616  $isSingleRevRedirect = !$dbw->selectField(
3617  'revision',
3618  '1',
3619  [ 'rev_page' => $this->mArticleID, 'rev_id != ' . (int)$this->mLatestID ],
3620  __METHOD__,
3621  [ 'FOR UPDATE' ]
3622  );
3623  } else {
3624  $isSingleRevRedirect = false;
3625  }
3626 
3627  $dbw->endAtomic( __METHOD__ );
3628 
3629  return $isSingleRevRedirect;
3630  }
3631 
3639  public function getParentCategories() {
3640  $data = [];
3641 
3642  $titleKey = $this->getArticleID();
3643 
3644  if ( $titleKey === 0 ) {
3645  return $data;
3646  }
3647 
3648  $dbr = wfGetDB( DB_REPLICA );
3649 
3650  $res = $dbr->select(
3651  'categorylinks',
3652  'cl_to',
3653  [ 'cl_from' => $titleKey ],
3654  __METHOD__
3655  );
3656 
3657  if ( $res->numRows() > 0 ) {
3658  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
3659  foreach ( $res as $row ) {
3660  // $data[] = Title::newFromText( $contLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
3661  $data[$contLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] =
3662  $this->getFullText();
3663  }
3664  }
3665  return $data;
3666  }
3667 
3674  public function getParentCategoryTree( $children = [] ) {
3675  $stack = [];
3676  $parents = $this->getParentCategories();
3677 
3678  if ( $parents ) {
3679  foreach ( $parents as $parent => $current ) {
3680  if ( array_key_exists( $parent, $children ) ) {
3681  # Circular reference
3682  $stack[$parent] = [];
3683  } else {
3684  $nt = self::newFromText( $parent );
3685  if ( $nt ) {
3686  $stack[$parent] = $nt->getParentCategoryTree( $children + [ $parent => 1 ] );
3687  }
3688  }
3689  }
3690  }
3691 
3692  return $stack;
3693  }
3694 
3701  public function pageCond() {
3702  if ( $this->mArticleID > 0 ) {
3703  // PK avoids secondary lookups in InnoDB, shouldn't hurt other DBs
3704  return [ 'page_id' => $this->mArticleID ];
3705  } else {
3706  return [ 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform ];
3707  }
3708  }
3709 
3717  private function getRelativeRevisionID( $revId, $flags, $dir ) {
3718  $rl = MediaWikiServices::getInstance()->getRevisionLookup();
3719  $rev = $rl->getRevisionById( $revId, $flags );
3720  if ( !$rev ) {
3721  return false;
3722  }
3723 
3724  $oldRev = ( $dir === 'next' )
3725  ? $rl->getNextRevision( $rev, $flags )
3726  : $rl->getPreviousRevision( $rev, $flags );
3727 
3728  return $oldRev ? $oldRev->getId() : false;
3729  }
3730 
3739  public function getPreviousRevisionID( $revId, $flags = 0 ) {
3740  wfDeprecated( __METHOD__, '1.34' );
3741  return $this->getRelativeRevisionID( $revId, $flags, 'prev' );
3742  }
3743 
3752  public function getNextRevisionID( $revId, $flags = 0 ) {
3753  wfDeprecated( __METHOD__, '1.34' );
3754  return $this->getRelativeRevisionID( $revId, $flags, 'next' );
3755  }
3756 
3764  public function getFirstRevision( $flags = 0 ) {
3765  wfDeprecated( __METHOD__, '1.35' );
3766  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
3767  $rev = MediaWikiServices::getInstance()
3768  ->getRevisionLookup()
3769  ->getFirstRevision( $this, $flags );
3770  return $rev ? new Revision( $rev ) : null;
3771  }
3772 
3780  public function getEarliestRevTime( $flags = 0 ) {
3781  wfDeprecated( __METHOD__, '1.35' );
3782  $rev = MediaWikiServices::getInstance()
3783  ->getRevisionLookup()
3784  ->getFirstRevision( $this, $flags );
3785  return $rev ? $rev->getTimestamp() : null;
3786  }
3787 
3793  public function isNewPage() {
3794  $dbr = wfGetDB( DB_REPLICA );
3795  return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ );
3796  }
3797 
3803  public function isBigDeletion() {
3804  global $wgDeleteRevisionsLimit;
3805 
3806  if ( !$wgDeleteRevisionsLimit ) {
3807  return false;
3808  }
3809 
3810  if ( $this->mIsBigDeletion === null ) {
3811  $dbr = wfGetDB( DB_REPLICA );
3812 
3813  $revCount = $dbr->selectRowCount(
3814  'revision',
3815  '1',
3816  [ 'rev_page' => $this->getArticleID() ],
3817  __METHOD__,
3818  [ 'LIMIT' => $wgDeleteRevisionsLimit + 1 ]
3819  );
3820 
3821  $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit;
3822  }
3823 
3824  return $this->mIsBigDeletion;
3825  }
3826 
3832  public function estimateRevisionCount() {
3833  if ( !$this->exists() ) {
3834  return 0;
3835  }
3836 
3837  if ( $this->mEstimateRevisions === null ) {
3838  $dbr = wfGetDB( DB_REPLICA );
3839  $this->mEstimateRevisions = $dbr->estimateRowCount( 'revision', '*',
3840  [ 'rev_page' => $this->getArticleID() ], __METHOD__ );
3841  }
3842 
3844  }
3845 
3862  public function countAuthorsBetween( $old, $new, $limit, $options = [] ) {
3863  wfDeprecated( __METHOD__, '1.35' );
3864  $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
3865 
3866  if ( !( $old instanceof Revision ) ) {
3867  $old = Revision::newFromTitle( $this, (int)$old );
3868  }
3869  if ( !( $new instanceof Revision ) ) {
3870  $new = Revision::newFromTitle( $this, (int)$new );
3871  }
3872  if ( !$old || !$new ) {
3873  return 0; // nothing to compare
3874  }
3875 
3876  return $revisionStore->countAuthorsBetween(
3877  $this->getArticleID(),
3878  $old->getRevisionRecord(),
3879  $new->getRevisionRecord(),
3880  null,
3881  $limit,
3882  $options
3883  );
3884  }
3885 
3900  public function equals( object $other ) {
3901  if ( $other instanceof Title ) {
3902  // NOTE: In contrast to isSameLinkAs(), this ignores the fragment part!
3903  // NOTE: In contrast to isSamePageAs(), this ignores the page ID!
3904  // NOTE: === is necessary for proper matching of number-like titles
3905  return $this->getInterwiki() === $other->getInterwiki()
3906  && $this->getNamespace() === $other->getNamespace()
3907  && $this->getDBkey() === $other->getDBkey();
3908  } else {
3909  return false;
3910  }
3911  }
3912 
3920  public function isSameLinkAs( LinkTarget $other ) {
3921  // NOTE: keep in sync with TitleValue::isSameLinkAs()!
3922  // NOTE: === is needed for number-like titles
3923  return ( $other->getInterwiki() === $this->getInterwiki() )
3924  && ( $other->getDBkey() === $this->getDBkey() )
3925  && ( $other->getNamespace() === $this->getNamespace() )
3926  && ( $other->getFragment() === $this->getFragment() );
3927  }
3928 
3936  public function isSamePageAs( PageIdentity $other ) {
3937  // NOTE: keep in sync with PageIdentityValue::isSamePageAs()!
3938 
3939  if ( $other->getWikiId() !== $this->getWikiId()
3940  || $other->getId() !== $this->getId() ) {
3941  return false;
3942  }
3943 
3944  if ( $this->getId() === 0 ) {
3945  if ( $other->getNamespace() !== $this->getNamespace()
3946  || $other->getDBkey() !== $this->getDBkey() ) {
3947  return false;
3948  }
3949  }
3950 
3951  return true;
3952  }
3953 
3960  public function isSubpageOf( Title $title ) {
3961  return $this->mInterwiki === $title->mInterwiki
3962  && $this->mNamespace == $title->mNamespace
3963  && strpos( $this->mDbkeyform, $title->mDbkeyform . '/' ) === 0;
3964  }
3965 
3976  public function exists( $flags = 0 ): bool {
3977  $exists = $this->getArticleID( $flags ) != 0;
3978  Hooks::runner()->onTitleExists( $this, $exists );
3979  return $exists;
3980  }
3981 
3998  public function isAlwaysKnown() {
3999  $isKnown = null;
4000 
4011  Hooks::runner()->onTitleIsAlwaysKnown( $this, $isKnown );
4012 
4013  if ( $isKnown !== null ) {
4014  return $isKnown;
4015  }
4016 
4017  if ( $this->isExternal() ) {
4018  return true; // any interwiki link might be viewable, for all we know
4019  }
4020 
4021  $services = MediaWikiServices::getInstance();
4022  switch ( $this->mNamespace ) {
4023  case NS_MEDIA:
4024  case NS_FILE:
4025  // file exists, possibly in a foreign repo
4026  return (bool)$services->getRepoGroup()->findFile( $this );
4027  case NS_SPECIAL:
4028  // valid special page
4029  return $services->getSpecialPageFactory()->exists( $this->mDbkeyform );
4030  case NS_MAIN:
4031  // selflink, possibly with fragment
4032  return $this->mDbkeyform == '';
4033  case NS_MEDIAWIKI:
4034  // known system message
4035  return $this->hasSourceText() !== false;
4036  default:
4037  return false;
4038  }
4039  }
4040 
4052  public function isKnown() {
4053  return $this->isAlwaysKnown() || $this->exists();
4054  }
4055 
4061  public function hasSourceText() {
4062  if ( $this->exists() ) {
4063  return true;
4064  }
4065 
4066  if ( $this->mNamespace === NS_MEDIAWIKI ) {
4067  $services = MediaWikiServices::getInstance();
4068  // If the page doesn't exist but is a known system message, default
4069  // message content will be displayed, same for language subpages-
4070  // Use always content language to avoid loading hundreds of languages
4071  // to get the link color.
4072  $contLang = $services->getContentLanguage();
4073  list( $name, ) = $services->getMessageCache()->figureMessage(
4074  $contLang->lcfirst( $this->getText() )
4075  );
4076  $message = wfMessage( $name )->inLanguage( $contLang )->useDatabase( false );
4077  return $message->exists();
4078  }
4079 
4080  return false;
4081  }
4082 
4120  public function getDefaultMessageText() {
4121  if ( $this->mNamespace !== NS_MEDIAWIKI ) { // Just in case
4122  return false;
4123  }
4124 
4125  list( $name, $lang ) = MediaWikiServices::getInstance()->getMessageCache()->figureMessage(
4126  MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $this->getText() )
4127  );
4128  $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
4129 
4130  if ( $message->exists() ) {
4131  return $message->plain();
4132  } else {
4133  return false;
4134  }
4135  }
4136 
4143  public function invalidateCache( $purgeTime = null ) {
4144  if ( wfReadOnly() ) {
4145  return false;
4146  }
4147  if ( $this->mArticleID === 0 ) {
4148  // avoid gap locking if we know it's not there
4149  return true;
4150  }
4151 
4152  $conds = $this->pageCond();
4154  new AutoCommitUpdate(
4155  wfGetDB( DB_MASTER ),
4156  __METHOD__,
4157  function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) {
4158  $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
4159  $dbw->update(
4160  'page',
4161  [ 'page_touched' => $dbTimestamp ],
4162  $conds + [ 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ],
4163  $fname
4164  );
4165 
4166  MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $this );
4167 
4169  $this, null, null, $dbw->getDomainID() );
4170  }
4171  ),
4172  DeferredUpdates::PRESEND
4173  );
4174 
4175  return true;
4176  }
4177 
4183  public function touchLinks() {
4184  $jobs = [];
4186  $this,
4187  'pagelinks',
4188  [ 'causeAction' => 'page-touch' ]
4189  );
4190  if ( $this->mNamespace === NS_CATEGORY ) {
4192  $this,
4193  'categorylinks',
4194  [ 'causeAction' => 'category-touch' ]
4195  );
4196  }
4197 
4198  JobQueueGroup::singleton()->lazyPush( $jobs );
4199  }
4200 
4207  public function getTouched( $db = null ) {
4208  if ( $db === null ) {
4209  $db = wfGetDB( DB_REPLICA );
4210  }
4211  $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ );
4212  return $touched;
4213  }
4214 
4223  public function getNotificationTimestamp( User $user ) {
4224  return MediaWikiServices::getInstance()
4225  ->getWatchlistNotificationManager()
4226  ->getTitleNotificationTimestamp( $user, $this );
4227  }
4228 
4235  public function getNamespaceKey( $prepend = 'nstab-' ) {
4236  // Gets the subject namespace of this title
4237  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
4238  $subjectNS = $nsInfo->getSubject( $this->mNamespace );
4239  // Prefer canonical namespace name for HTML IDs
4240  $namespaceKey = $nsInfo->getCanonicalName( $subjectNS );
4241  if ( $namespaceKey === false ) {
4242  // Fallback to localised text
4243  $namespaceKey = $this->getSubjectNsText();
4244  }
4245  // Makes namespace key lowercase
4246  $namespaceKey = MediaWikiServices::getInstance()->getContentLanguage()->lc( $namespaceKey );
4247  // Uses main
4248  if ( $namespaceKey == '' ) {
4249  $namespaceKey = 'main';
4250  }
4251  // Changes file to image for backwards compatibility
4252  if ( $namespaceKey == 'file' ) {
4253  $namespaceKey = 'image';
4254  }
4255  return $prepend . $namespaceKey;
4256  }
4257 
4264  public function getRedirectsHere( $ns = null ) {
4265  $redirs = [];
4266 
4267  $dbr = wfGetDB( DB_REPLICA );
4268  $where = [
4269  'rd_namespace' => $this->mNamespace,
4270  'rd_title' => $this->mDbkeyform,
4271  'rd_from = page_id'
4272  ];
4273  if ( $this->isExternal() ) {
4274  $where['rd_interwiki'] = $this->mInterwiki;
4275  } else {
4276  $where[] = 'rd_interwiki = ' . $dbr->addQuotes( '' ) . ' OR rd_interwiki IS NULL';
4277  }
4278  if ( $ns !== null ) {
4279  $where['page_namespace'] = $ns;
4280  }
4281 
4282  $res = $dbr->select(
4283  [ 'redirect', 'page' ],
4284  [ 'page_namespace', 'page_title' ],
4285  $where,
4286  __METHOD__
4287  );
4288 
4289  foreach ( $res as $row ) {
4290  $redirs[] = self::newFromRow( $row );
4291  }
4292  return $redirs;
4293  }
4294 
4300  public function isValidRedirectTarget() {
4302 
4303  if ( $this->isSpecialPage() ) {
4304  // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
4305  if ( $this->isSpecial( 'Userlogout' ) ) {
4306  return false;
4307  }
4308 
4309  foreach ( $wgInvalidRedirectTargets as $target ) {
4310  if ( $this->isSpecial( $target ) ) {
4311  return false;
4312  }
4313  }
4314  }
4315 
4316  return true;
4317  }
4318 
4324  public function getBacklinkCache() {
4325  return BacklinkCache::get( $this );
4326  }
4327 
4333  public function canUseNoindex() {
4335 
4336  $bannedNamespaces = $wgExemptFromUserRobotsControl ??
4337  MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
4338 
4339  return !in_array( $this->mNamespace, $bannedNamespaces );
4340  }
4341 
4352  public function getCategorySortkey( $prefix = '' ) {
4353  $unprefixed = $this->getText();
4354 
4355  // Anything that uses this hook should only depend
4356  // on the Title object passed in, and should probably
4357  // tell the users to run updateCollations.php --force
4358  // in order to re-sort existing category relations.
4359  Hooks::runner()->onGetDefaultSortkey( $this, $unprefixed );
4360  if ( $prefix !== '' ) {
4361  # Separate with a line feed, so the unprefixed part is only used as
4362  # a tiebreaker when two pages have the exact same prefix.
4363  # In UCA, tab is the only character that can sort above LF
4364  # so we strip both of them from the original prefix.
4365  $prefix = strtr( $prefix, "\n\t", ' ' );
4366  return "$prefix\n$unprefixed";
4367  }
4368  return $unprefixed;
4369  }
4370 
4378  private function getDbPageLanguageCode() {
4379  global $wgPageLanguageUseDB;
4380 
4381  // check, if the page language could be saved in the database, and if so and
4382  // the value is not requested already, lookup the page language using LinkCache
4383  if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) {
4384  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
4385  $linkCache->addLinkObj( $this );
4386  $this->mDbPageLanguage = $linkCache->getGoodLinkFieldObj( $this, 'lang' );
4387  }
4388 
4389  return $this->mDbPageLanguage;
4390  }
4391 
4400  public function getPageLanguage() {
4401  global $wgLang, $wgLanguageCode;
4402  if ( $this->isSpecialPage() ) {
4403  // special pages are in the user language
4404  return $wgLang;
4405  }
4406 
4407  // Checking if DB language is set
4408  $dbPageLanguage = $this->getDbPageLanguageCode();
4409  if ( $dbPageLanguage ) {
4410  return wfGetLangObj( $dbPageLanguage );
4411  }
4412 
4413  if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) {
4414  // Note that this may depend on user settings, so the cache should
4415  // be only per-request.
4416  // NOTE: ContentHandler::getPageLanguage() may need to load the
4417  // content to determine the page language!
4418  // Checking $wgLanguageCode hasn't changed for the benefit of unit
4419  // tests.
4420  $contentHandler = MediaWikiServices::getInstance()
4421  ->getContentHandlerFactory()
4422  ->getContentHandler( $this->getContentModel() );
4423  $langObj = $contentHandler->getPageLanguage( $this );
4424  $this->mPageLanguage = [ $langObj->getCode(), $wgLanguageCode ];
4425  } else {
4426  $langObj = MediaWikiServices::getInstance()->getLanguageFactory()
4427  ->getLanguage( $this->mPageLanguage[0] );
4428  }
4429 
4430  return $langObj;
4431  }
4432 
4441  public function getPageViewLanguage() {
4442  global $wgLang;
4443 
4444  if ( $this->isSpecialPage() ) {
4445  // If the user chooses a variant, the content is actually
4446  // in a language whose code is the variant code.
4447  $variant = $this->getLanguageConverter( $wgLang )->getPreferredVariant();
4448  if ( $wgLang->getCode() !== $variant ) {
4449  return MediaWikiServices::getInstance()->getLanguageFactory()
4450  ->getLanguage( $variant );
4451  }
4452 
4453  return $wgLang;
4454  }
4455 
4456  // Checking if DB language is set
4457  $dbPageLanguage = $this->getDbPageLanguageCode();
4458  if ( $dbPageLanguage ) {
4459  $pageLang = wfGetLangObj( $dbPageLanguage );
4460  $variant = $this->getLanguageConverter( $pageLang )->getPreferredVariant();
4461  if ( $pageLang->getCode() !== $variant ) {
4462  $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()
4463  ->getLanguage( $variant );
4464  }
4465 
4466  return $pageLang;
4467  }
4468 
4469  // @note Can't be cached persistently, depends on user settings.
4470  // @note ContentHandler::getPageViewLanguage() may need to load the
4471  // content to determine the page language!
4472  $contentHandler = MediaWikiServices::getInstance()
4473  ->getContentHandlerFactory()
4474  ->getContentHandler( $this->getContentModel() );
4475  $pageLang = $contentHandler->getPageViewLanguage( $this );
4476  return $pageLang;
4477  }
4478 
4489  public function getEditNotices( $oldid = 0 ) {
4490  $notices = [];
4491 
4492  // Optional notice for the entire namespace
4493  $editnotice_ns = 'editnotice-' . $this->mNamespace;
4494  $msg = wfMessage( $editnotice_ns );
4495  if ( $msg->exists() ) {
4496  $html = $msg->parseAsBlock();
4497  // Edit notices may have complex logic, but output nothing (T91715)
4498  if ( trim( $html ) !== '' ) {
4499  $notices[$editnotice_ns] = Html::rawElement(
4500  'div',
4501  [ 'class' => [
4502  'mw-editnotice',
4503  'mw-editnotice-namespace',
4504  Sanitizer::escapeClass( "mw-$editnotice_ns" )
4505  ] ],
4506  $html
4507  );
4508  }
4509  }
4510 
4511  if (
4512  MediaWikiServices::getInstance()->getNamespaceInfo()->
4513  hasSubpages( $this->mNamespace )
4514  ) {
4515  // Optional notice for page itself and any parent page
4516  $editnotice_base = $editnotice_ns;
4517  foreach ( explode( '/', $this->mDbkeyform ) as $part ) {
4518  $editnotice_base .= '-' . $part;
4519  $msg = wfMessage( $editnotice_base );
4520  if ( $msg->exists() ) {
4521  $html = $msg->parseAsBlock();
4522  if ( trim( $html ) !== '' ) {
4523  $notices[$editnotice_base] = Html::rawElement(
4524  'div',
4525  [ 'class' => [
4526  'mw-editnotice',
4527  'mw-editnotice-base',
4528  Sanitizer::escapeClass( "mw-$editnotice_base" )
4529  ] ],
4530  $html
4531  );
4532  }
4533  }
4534  }
4535  } else {
4536  // Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
4537  $editnoticeText = $editnotice_ns . '-' . strtr( $this->mDbkeyform, '/', '-' );
4538  $msg = wfMessage( $editnoticeText );
4539  if ( $msg->exists() ) {
4540  $html = $msg->parseAsBlock();
4541  if ( trim( $html ) !== '' ) {
4542  $notices[$editnoticeText] = Html::rawElement(
4543  'div',
4544  [ 'class' => [
4545  'mw-editnotice',
4546  'mw-editnotice-page',
4547  Sanitizer::escapeClass( "mw-$editnoticeText" )
4548  ] ],
4549  $html
4550  );
4551  }
4552  }
4553  }
4554 
4555  Hooks::runner()->onTitleGetEditNotices( $this, $oldid, $notices );
4556  return $notices;
4557  }
4558 
4564  private function loadFieldFromDB( $field, $flags ) {
4565  if ( !in_array( $field, self::getSelectFields(), true ) ) {
4566  return false; // field does not exist
4567  }
4568 
4569  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
4570  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
4571 
4572  return wfGetDB( $index )->selectField(
4573  'page',
4574  $field,
4575  $this->pageCond(),
4576  __METHOD__,
4577  $options
4578  );
4579  }
4580 
4584  public function __sleep() {
4585  return [
4586  'mNamespace',
4587  'mDbkeyform',
4588  'mFragment',
4589  'mInterwiki',
4590  'mLocalInterwiki',
4591  'mDefaultNamespace',
4592  ];
4593  }
4594 
4595  public function __wakeup() {
4596  $this->mArticleID = ( $this->mNamespace >= 0 ) ? -1 : 0;
4597  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
4598  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
4599  }
4600 
4610  public function getWikiId() {
4611  return self::LOCAL;
4612  }
4613 
4630  public function getId( $wikiId = self::LOCAL ): int {
4631  $this->assertWiki( $wikiId );
4632  $this->assertProperPage();
4633  return $this->getArticleID();
4634  }
4635 
4648  private function assertProperPage() {
4649  Assert::precondition(
4650  $this->canExist(),
4651  'This Title instance does not represent a proper page, but merely a link target.'
4652  );
4653 
4654  Assert::precondition(
4655  $this->getFragment() === '',
4656  'This Title instance represents a fragment link.'
4657  );
4658  }
4659 
4672  public function toPageIdentity() : ProperPageIdentity {
4673  // TODO: replace individual member fields with a PageIdentityValue that is always present
4674 
4675  $this->assertProperPage();
4676 
4677  return new PageIdentityValue(
4678  $this->getId(),
4679  $this->getNamespace(),
4680  $this->getDBkey(),
4681  self::LOCAL
4682  );
4683  }
4684 
4685 }
Title\$mLocalInterwiki
bool $mLocalInterwiki
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:94
Title\$mRestrictions
array $mRestrictions
Array of groups allowed to edit this article.
Definition: Title.php:120
Title\canHaveTalkPage
canHaveTalkPage()
Can this title have a corresponding talk page?
Definition: Title.php:1208
Title\getTitleProtection
getTitleProtection()
Is this title subject to title protection? Title protection is the one applied against creation of su...
Definition: Title.php:2492
Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition: PageIdentity.php:65
Title\canUseNoindex
canUseNoindex()
Whether the magic words INDEX and NOINDEX function for this page.
Definition: Title.php:4333
Title\getLocalURL
getLocalURL( $query='', $query2=false)
Get a URL with no fragment or server name (relative URL) from a Title object.
Definition: Title.php:2264
Title\isSemiProtected
isSemiProtected( $action='edit')
Is this page "semi-protected" - the only protection levels are listed in $wgSemiprotectedRestrictionL...
Definition: Title.php:2580
MediaWiki\DAO\WikiAwareEntityTrait
trait WikiAwareEntityTrait
Definition: WikiAwareEntityTrait.php:32
Title\$mHasCascadingRestrictions
bool $mHasCascadingRestrictions
Are cascading restrictions in effect on this page?
Definition: Title.php:140
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:50
Title\isNamespaceProtected
isNamespaceProtected(User $user)
Determines if $user is unable to edit this page because it has been protected by $wgNamespaceProtecti...
Definition: Title.php:2641
Title\getTalkNsText
getTalkNsText()
Get the namespace text of the talk page.
Definition: Title.php:1191
Title\getSubpageText
getSubpageText()
Get the lowest-level subpage name, i.e.
Definition: Title.php:2088
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:363
Title\isBigDeletion
isBigDeletion()
Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit.
Definition: Title.php:3803
Title\getNextRevisionID
getNextRevisionID( $revId, $flags=0)
Get the revision ID of the next revision.
Definition: Title.php:3752
Page\PageIdentity\getDBkey
getDBkey()
Get the page title in DB key form.
Title\areCascadeProtectionSourcesLoaded
areCascadeProtectionSourcesLoaded( $getPages=true)
Determines whether cascading protection sources have already been loaded from the database.
Definition: Title.php:2674
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:2447
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:856
Title\getInternalURL
getInternalURL( $query='', $query2=false)
Get the URL form for an internal link.
Definition: Title.php:2397
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
Title\getFragment
getFragment()
Get the Title fragment (i.e.
Definition: Title.php:1775
$wgExemptFromUserRobotsControl
$wgExemptFromUserRobotsControl
An array of namespace keys in which the INDEX/__NOINDEX__ magic words will not function,...
Definition: DefaultSettings.php:8589
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:1667
Title\inNamespace
inNamespace( $ns)
Returns true if the title is inside the specified namespace.
Definition: Title.php:1329
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:114
TitleArray\newFromResult
static newFromResult( $res)
Definition: TitleArray.php:42
Title\isMovable
isMovable()
Would anybody with sufficient privileges be able to move this page? Some pages just aren't movable.
Definition: Title.php:1391
Title\wasLocalInterwiki
wasLocalInterwiki()
Was this a local interwiki link?
Definition: Title.php:978
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:173
$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:1341
Title\isWikitextPage
isWikitextPage()
Does that page contain wikitext, or it is JS, CSS or whatever?
Definition: Title.php:1448
Title\isUserCssConfigPage
isUserCssConfigPage()
Is this a CSS "config" sub-page of a user page?
Definition: Title.php:1510
Title\getBacklinkCache
getBacklinkCache()
Get a backlink cache object.
Definition: Title.php:4324
Title\getPartialURL
getPartialURL()
Get the URL-encoded form of the main part.
Definition: Title.php:1050
$wgLegalTitleChars
$wgLegalTitleChars
Allowed title characters – regex character class Don't change this unless you know what you're doing.
Definition: DefaultSettings.php:4454
Title\clearCaches
static clearCaches()
Definition: Title.php:3332
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:1018
Title\estimateRevisionCount
estimateRevisionCount()
Get the approximate revision count of this page.
Definition: Title.php:3832
ResourceLoaderWikiModule\invalidateModuleCache
static invalidateModuleCache(Title $title, ?RevisionRecord $old, ?RevisionRecord $new, $domain)
Clear the preloadTitleInfo() cache for all wiki modules on this wiki on page change if it was a JS or...
Definition: ResourceLoaderWikiModule.php:547
Title\getPrefixedDBkey
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1874
Title\getDbPageLanguageCode
getDbPageLanguageCode()
Returns the page language code saved in the database, if $wgPageLanguageUseDB is set to true in Local...
Definition: Title.php:4378
Title\getSkinFromConfigSubpage
getSkinFromConfigSubpage()
Trim down a .css, .json, or .js subpage title to get the corresponding skin name.
Definition: Title.php:1494
$wgScript
$wgScript
The URL path to index.php.
Definition: DefaultSettings.php:204
Title\$mHasSubpages
bool $mHasSubpages
Whether a page has any subpages.
Definition: Title.php:176
Title\getTalkPage
getTalkPage()
Get a Title object associated with the talk page of this article.
Definition: Title.php:1637
Title\NEW_CLONE
const NEW_CLONE
Flag for use with factory methods like newFromLinkTarget() that have a $forceClone parameter.
Definition: Title.php:73
Title\getParentCategoryTree
getParentCategoryTree( $children=[])
Get a tree of parent categories.
Definition: Title.php:3674
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:2159
Title\fixSpecialName
fixSpecialName()
If the Title refers to a special page alias which is not the local default, resolve the alias,...
Definition: Title.php:1305
Title\getInterwikiLookup
static getInterwikiLookup()
B/C kludge: provide an InterwikiLookup for use by Title.
Definition: Title.php:237
Title\isUserJsConfigPage
isUserJsConfigPage()
Is this a JS "config" sub-page of a user page?
Definition: Title.php:1538
Title\touchLinks
touchLinks()
Update page_touched timestamps and send CDN purge messages for pages linking to this title.
Definition: Title.php:4183
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:313
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1886
Title\getTransWikiID
getTransWikiID()
Returns the DB name of the distant wiki which owns the object.
Definition: Title.php:1001
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:3182
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:2372
Title\$mTitleValue
TitleValue null $mTitleValue
A corresponding TitleValue object.
Definition: Title.php:187
Page\PageIdentity\getId
getId( $wikiId=self::LOCAL)
Returns the page ID.
Title\isTalkPage
isTalkPage()
Is this a talk page of some sort?
Definition: Title.php:1621
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1135
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1231
Sanitizer\decodeCharReferencesAndNormalize
static decodeCharReferencesAndNormalize( $text)
Decode any character references, numeric or named entities, in the next and normalize the resulting s...
Definition: Sanitizer.php:1245
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php: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:972
Title\getNotificationTimestamp
getNotificationTimestamp(User $user)
Get the timestamp when this page was updated since the user last saw it.
Definition: Title.php:4223
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1094
Title\isExternal
isExternal()
Is this Title interwiki?
Definition: Title.php:958
DBAccessObjectUtils\getDBOptions
static getDBOptions( $bitfield)
Get an appropriate DB index, options, and fallback DB index for a query.
Definition: DBAccessObjectUtils.php:52
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:2849
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:688
Title\getDefaultMessageText
getDefaultMessageText()
Get the default (plain) message contents for an page that overrides an interface message key.
Definition: Title.php:4120
Title\hasSourceText
hasSourceText()
Does this page have source text?
Definition: Title.php:4061
Title\loadFromRow
loadFromRow( $row)
Load Title object fields from a DB row.
Definition: Title.php:570
Title\setFragment
setFragment( $fragment)
Set the fragment for this title.
Definition: Title.php:1821
$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:190
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:1971
Title\__wakeup
__wakeup()
Definition: Title.php:4595
$wgLang
$wgLang
Definition: Setup.php:782
HTMLCacheUpdateJob\newForBacklinks
static newForBacklinks(Title $title, $table, $params=[])
Definition: HTMLCacheUpdateJob.php:59
Title\getParentCategories
getParentCategories()
Get categories to which this Title belongs and return an array of categories' names.
Definition: Title.php:3639
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:3420
Title\$mContentModel
bool string $mContentModel
ID of the page's content model, i.e.
Definition: Title.php:108
Title\getPageLanguageConverter
getPageLanguageConverter()
Shorthand for getting a Language Converter for page's language.
Definition: Title.php:213
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:1552
MessageLocalizer
Interface for localizing messages in MediaWiki.
Definition: MessageLocalizer.php:29
Title\getNsText
getNsText()
Get the namespace text.
Definition: Title.php:1155
Title\$mRedirect
null bool $mRedirect
Is the article at this title a redirect?
Definition: Title.php:173
Title\$mDbkeyform
string $mDbkeyform
Main part with underscores.
Definition: Title.php:88
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:328
Title\$mUrlform
string $mUrlform
URL-encoded form of the main part.
Definition: Title.php:86
$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:3478
Title\$mOldRestrictions
string bool $mOldRestrictions
Comma-separated set of permission keys indicating who can move or edit the page from the page table,...
Definition: Title.php:128
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:443
Revision
Definition: Revision.php:40
Title\loadFieldFromDB
loadFieldFromDB( $field, $flags)
Definition: Title.php:4564
Title\isCascadeProtected
isCascadeProtected()
Cascading protection: Return true if cascading restrictions apply to this page, false if not.
Definition: Title.php:2660
Revision\newFromTitle
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
Definition: Revision.php:143
Title\getCdnUrls
getCdnUrls()
Get a list of URLs to purge from the CDN cache when this page changes.
Definition: Title.php:3580
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:1739
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:1466
Title\isUserJsonConfigPage
isUserJsonConfigPage()
Is this a JSON "config" sub-page of a user page?
Definition: Title.php:1524
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:223
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:205
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:194
$wgRawHtmlMessages
string[] $wgRawHtmlMessages
List of messages which might contain raw HTML.
Definition: DefaultSettings.php:9386
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:1059
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
Definition: GlobalFunctions.php:1066
Title\nameOf
static nameOf( $id)
Get the prefixed DB key associated with an ID.
Definition: Title.php:714
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:184
Title\isSpecial
isSpecial( $name)
Returns true if this title resolves to the named special page.
Definition: Title.php:1287
MWException
MediaWiki exception.
Definition: MWException.php:29
Title\getTitleFormatter
static getTitleFormatter()
B/C kludge: provide a TitleParser for use by Title.
Definition: Title.php:225
Title\isMainPage
isMainPage()
Is this the mainpage?
Definition: Title.php:1415
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1034
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:2115
Title\getBaseTitle
getBaseTitle()
Get the base page name title, i.e.
Definition: Title.php:2068
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1068
BacklinkCache\get
static get(Title $title)
Create a new BacklinkCache or reuse any existing one.
Definition: BacklinkCache.php:116
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:558
Title\isConversionTable
isConversionTable()
Is this a conversion table for the LanguageConverter?
Definition: Title.php:1436
Title\isProtected
isProtected( $action='')
Does the title correspond to a protected article?
Definition: Title.php:2608
Title\flushRestrictions
flushRestrictions()
Flush the protection cache in this object and force reload from the database.
Definition: Title.php:2998
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2467
Title\getCategorySortkey
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:4352
Title\getInterwiki
getInterwiki()
Get the interwiki prefix.
Definition: Title.php:969
Title\isSiteJsonConfigPage
isSiteJsonConfigPage()
Is this a sitewide JSON "config" page?
Definition: Title.php:1570
$matches
$matches
Definition: NoLocalSettings.php:24
Title\isValidRedirectTarget
isValidRedirectTarget()
Check if this Title is a valid redirect target.
Definition: Title.php:4300
Title\deleteTitleProtection
deleteTitleProtection()
Remove any title protection due to page existing.
Definition: Title.php:2562
Title\__construct
__construct()
Definition: Title.php:241
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:3544
Title\isUserConfigPage
isUserConfigPage()
Is this a "config" (.css, .json, or .js) sub-page of a user page?
Definition: Title.php:1480
Title\getLanguageConverter
getLanguageConverter( $language)
Shorthand for getting a Language Converter for specific language.
Definition: Title.php:204
Title\$mCascadeSources
array $mCascadeSources
Where are the cascading restrictions coming from on this page?
Definition: Title.php:143
Title\getSubjectPage
getSubjectPage()
Get a title object associated with the subject page of this talk page.
Definition: Title.php:1682
MapCacheLRU
Handles a simple LRU key/value map with a maximum number of entries.
Definition: MapCacheLRU.php:37
wfGetLangObj
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
Definition: GlobalFunctions.php:1181
Title\loadRestrictions
loadRestrictions( $oldFashionedRestrictions=null, $flags=0)
Load restrictions from the page_restrictions table.
Definition: Title.php:2927
$wgInvalidRedirectTargets
$wgInvalidRedirectTargets
Array of invalid page redirect targets.
Definition: DefaultSettings.php:4627
Title\getFullText
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
Definition: Title.php:1910
Title\getTitleCache
static getTitleCache()
Definition: Title.php:471
Title\hasFragment
hasFragment()
Check if a Title fragment is set.
Definition: Title.php:1785
Title\getRedirectsHere
getRedirectsHere( $ns=null)
Get all extant redirects to this Title.
Definition: Title.php:4264
$title
$title
Definition: testCompression.php:38
Title\warnIfPageCannotExist
warnIfPageCannotExist(Title $title, $method)
Definition: Title.php:1708
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:626
Title\$mInterwiki
string $mInterwiki
Interwiki prefix.
Definition: Title.php:92
Title\$mCascadeRestriction
bool $mCascadeRestriction
Cascade restrictions on this page to included templates and images?
Definition: Title.php:131
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1861
Title\getRootText
getRootText()
Get the root page name text without a namespace, i.e.
Definition: Title.php:1991
PROTO_CANONICAL
const PROTO_CANONICAL
Definition: Defines.php:207
$wgNamespaceProtection
$wgNamespaceProtection
Set the minimum permissions required to edit pages in each namespace.
Definition: DefaultSettings.php:5874
Title\canExist
canExist()
Can this title represent a page in the wiki's database?
Definition: Title.php:1222
$wgDeleteRevisionsLimit
$wgDeleteRevisionsLimit
Optional to restrict deletion of pages with higher revision counts to users with the 'bigdelete' perm...
Definition: DefaultSettings.php:6051
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Title\$prefixedText
string null $prefixedText
Text form including namespace/interwiki, initialised on demand.
Definition: Title.php:156
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:915
Title\__sleep
__sleep()
Definition: Title.php:4584
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:2419
Title\createFragmentTarget
createFragmentTarget( $fragment)
Creates a new Title for a different fragment of the same page.
Definition: Title.php:1832
Title\$mNamespace
int $mNamespace
Namespace index, i.e.
Definition: Title.php:90
Title\getDefaultNamespace
getDefaultNamespace()
Get the default namespace index, for when there is no namespace.
Definition: Title.php:1764
Title\newFromTextThrow
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:398
$wgPageLanguageUseDB
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
Definition: DefaultSettings.php:9265
Title\$mPageLanguage
array null $mPageLanguage
The (string) language code of the page's language and content code.
Definition: Title.php:179
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:206
Title\isValid
isValid()
Returns true if the title is a valid link target, and that it has been properly normalized.
Definition: Title.php:904
AtomicSectionUpdate
Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
Definition: AtomicSectionUpdate.php:9
Title\getPrefixedURL
getPrefixedURL()
Get a URL-encoded title (not an actual URL) including interwiki.
Definition: Title.php:2140
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:652
Title\__toString
__toString()
Return a string representation of this title.
Definition: Title.php:1900
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:4630
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:28
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:3462
$wgMainPageIsDomainRoot
bool $wgMainPageIsDomainRoot
Option to whether serve the main page as the domain root.
Definition: DefaultSettings.php:9650
Title\areRestrictionsCascading
areRestrictionsCascading()
Returns cascading restrictions for the current article.
Definition: Title.php:2830
Title\getLatestRevID
getLatestRevID( $flags=0)
What is the page_latest field for this page?
Definition: Title.php:3275
Title\areRestrictionsLoaded
areRestrictionsLoaded()
Accessor for mRestrictionsLoaded.
Definition: Title.php:2777
Title\hasDeletedEdits
hasDeletedEdits()
Is there a version of this page in the deletion archive?
Definition: Title.php:3157
Title\getSubpages
getSubpages( $limit=-1)
Get all subpages of this page.
Definition: Title.php:3080
Title\assertProperPage
assertProperPage()
Code that requires this Title to be a "proper page" in the sense defined by PageIdentity should call ...
Definition: Title.php:4648
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:3601
$wgServer
$wgServer
URL of the server.
Definition: DefaultSettings.php:108
Title\GAID_FOR_UPDATE
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define().
Definition: Title.php:64
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:172
Title\getPageViewLanguage
getPageViewLanguage()
Get the language in which the content of this page is written when viewed by user.
Definition: Title.php:4441
Title\newFromDBkey
static newFromDBkey( $key)
Create a new Title from a prefixed DB key.
Definition: Title.php:252
Sanitizer\escapeIdForExternalInterwiki
static escapeIdForExternalInterwiki( $id)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid URL...
Definition: Sanitizer.php:861
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:3196
Title\isSubpage
isSubpage()
Is this a subpage?
Definition: Title.php:1424
Title\hasContentModel
hasContentModel( $id)
Convenience method for checking a title's content model name.
Definition: Title.php:1113
Title\getRestrictionExpiry
getRestrictionExpiry( $action)
Get the expiry time for the restriction against a given action.
Definition: Title.php:2818
Title\newFromURL
static newFromURL( $url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:448
MediaWiki\Linker\LinkTarget\getDBkey
getDBkey()
Get the main part with underscores.
MediaWiki\Linker\LinkTarget\getFragment
getFragment()
Get the link fragment (i.e.
Title\$mRestrictionsExpiry
array $mRestrictionsExpiry
When do the restrictions on this page expire?
Definition: Title.php:137
MapCacheLRU\set
set( $key, $value, $rank=self::RANK_TOP)
Set a key/value pair.
Definition: MapCacheLRU.php:110
Title\resetArticleID
resetArticleID( $id)
Inject a page ID, reset DB-loaded fields, and clear the link cache for this title.
Definition: Title.php:3310
Title\isSubpageOf
isSubpageOf(Title $title)
Check if this title is a subpage of another title.
Definition: Title.php:3960
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:943
Title\$mFragment
string $mFragment
Title fragment (i.e.
Definition: Title.php:96
Title\getContentModel
getContentModel( $flags=0)
Get the page's content model id, see the CONTENT_MODEL_XXX constants.
Definition: Title.php:1080
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:219
Title\newFromIDs
static newFromIDs( $ids)
Make an array of titles from an array of IDs.
Definition: Title.php:532
NS_USER
const NS_USER
Definition: Defines.php:66
WikiPage\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new page object.
Definition: WikiPage.php:370
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:291
Title\prefix
prefix( $name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object.
Definition: Title.php:1848
Title\getNamespaceKey
getNamespaceKey( $prepend='nstab-')
Generate strings used for xml 'id' names in monobook tabs.
Definition: Title.php:4235
Title\getEditURL
getEditURL()
Get the edit URL for this Title.
Definition: Title.php:2431
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:2197
Title\isKnown
isKnown()
Does this title refer to a page that can (or might) be meaningfully viewed? In particular,...
Definition: Title.php:4052
$wgArticlePath
$wgArticlePath
The URL path for primary article page views.
Definition: DefaultSettings.php:264
Title\$mIsValid
bool null $mIsValid
Is the title known to be valid?
Definition: Title.php:193
Title\equals
equals(object $other)
Compares with another Title.
Definition: Title.php:3900
Title\getFirstRevision
getFirstRevision( $flags=0)
Get the first revision of the page.
Definition: Title.php:3764
Title\getAllRestrictions
getAllRestrictions()
Accessor/initialisation for mRestrictions.
Definition: Title.php:2804
Title\getEarliestRevTime
getEarliestRevTime( $flags=0)
Get the oldest revision timestamp of this page.
Definition: Title.php:3780
Title
Represents a title within MediaWiki.
Definition: Title.php:46
$wgActionPaths
$wgActionPaths
To set 'pretty' URL paths for actions other than plain page views, add to this array.
Definition: DefaultSettings.php:488
Title\$mCascadingRestrictions
$mCascadingRestrictions
Caching the results of getCascadeProtectionSources.
Definition: Title.php:134
Title\isSameLinkAs
isSameLinkAs(LinkTarget $other)
Definition: Title.php:3920
JobQueueGroup\singleton
static singleton( $domain=false)
Definition: JobQueueGroup.php:70
Title\getCascadeProtectionSources
getCascadeProtectionSources( $getPages=true)
Cascading protection: Get the source of any cascading restrictions on this page.
Definition: Title.php:2691
$cache
$cache
Definition: mcc.php:33
$wgSemiprotectedRestrictionLevels
$wgSemiprotectedRestrictionLevels
Restriction levels that should be considered "semiprotected".
Definition: DefaultSettings.php:5865
Title\getRestrictionTypes
getRestrictionTypes()
Returns restriction types for the current Title.
Definition: Title.php:2465
MalformedTitleException
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Definition: MalformedTitleException.php:26
Title\getTitleProtectionInternal
getTitleProtectionInternal()
Fetch title protection settings.
Definition: Title.php:2515
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:3532
Title\isRedirect
isRedirect( $flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
Definition: Title.php:3223
Title\$mArticleID
int $mArticleID
Article ID, fetched from the link cache on demand.
Definition: Title.php:99
Title\isDeleted
isDeleted()
Is there a version of this page in the deletion archive?
Definition: Title.php:3111
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:3347
Title\$mDefaultNamespace
int $mDefaultNamespace
Namespace index when there is no namespace.
Definition: Title.php:167
Title\$mLength
int $mLength
The page length, 0 for special pages.
Definition: Title.php:170
Title\$mEstimateRevisions
int $mEstimateRevisions
Estimated number of revisions; null of not loaded.
Definition: Title.php:117
Title\hasSubjectNamespace
hasSubjectNamespace( $ns)
Returns true if the title has the same subject namespace as the namespace specified.
Definition: Title.php:1368
Title\isSpecialPage
isSpecialPage()
Returns true if this is a special page.
Definition: Title.php:1277
MapCacheLRU\get
get( $key, $maxAge=INF, $default=null)
Get the value for a key.
Definition: MapCacheLRU.php:172
Title\purgeSquid
purgeSquid()
Purge all applicable CDN URLs.
Definition: Title.php:3589
Title\getDeletedEditsCount
getDeletedEditsCount()
Is there a version of this page in the deletion archive?
Definition: Title.php:3121
Title\getPreviousRevisionID
getPreviousRevisionID( $revId, $flags=0)
Get the revision ID of the previous revision.
Definition: Title.php:3739
TitleArray
The TitleArray class only exists to provide the newFromResult method at pre- sent.
Definition: TitleArray.php:35
Title\getPageLanguage
getPageLanguage()
Get the language in which the content of this page is written in wikitext.
Definition: Title.php:4400
Title\CACHE_MAX
const CACHE_MAX
Title::newFromText maintains a cache to avoid expensive re-normalization of commonly used titles.
Definition: Title.php:57
Title\getEditNotices
getEditNotices( $oldid=0)
Get a list of rendered edit notices for this page.
Definition: Title.php:4489
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:220
Title\getTouched
getTouched( $db=null)
Get the last touched timestamp.
Definition: Title.php:4207
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:212
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.
$wgRestrictionLevels
$wgRestrictionLevels
Rights which can be required for each protection level (via action=protect)
Definition: DefaultSettings.php:5840
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:78
Page\PageIdentityValue
Immutable value object representing a page identity.
Definition: PageIdentityValue.php:43
Title\isSamePageAs
isSamePageAs(PageIdentity $other)
Definition: Title.php:3936
Page\PageIdentity\getWikiId
getWikiId()
Get the ID of the wiki this page belongs to.
Title\getFragmentForURL
getFragmentForURL()
Get the fragment in URL form, including the "#" character if there is one.
Definition: Title.php:1794
Title\exists
exists( $flags=0)
Check if page exists.
Definition: Title.php:3976
Sanitizer\escapeIdForLink
static escapeIdForLink( $id)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid URL...
Definition: Sanitizer.php:838
Title\isAlwaysKnown
isAlwaysKnown()
Should links to this title be shown as potentially viewable (i.e.
Definition: Title.php:3998
Title\secureAndSplit
secureAndSplit( $text, $defaultNamespace=null)
Secure and split - main initialisation function for this object.
Definition: Title.php:3372
Title\isDeletedQuick
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:3147
Title\getSubpageUrlForm
getSubpageUrlForm()
Get a URL-encoded form of the subpage text.
Definition: Title.php:2129
MapCacheLRU\clear
clear( $keys=null)
Clear one or several cache entries, or all cache entries.
Definition: MapCacheLRU.php:289
Title\isNewPage
isNewPage()
Check if this is a new page.
Definition: Title.php:3793
$wgRestrictionTypes
$wgRestrictionTypes
Set of available actions that can be restricted via action=protect You probably shouldn't change this...
Definition: DefaultSettings.php:5827
Title\toPageIdentity
toPageIdentity()
Returns the page represented by this Title as a ProperPageIdentity.
Definition: Title.php:4672
Title\setContentModel
setContentModel( $model)
Set a proposed content model for the page for permissions checking.
Definition: Title.php:1130
Title\compare
static compare(LinkTarget $a, LinkTarget $b)
Callback for usort() to do title sorts by (namespace, title)
Definition: Title.php:883
Title\countAuthorsBetween
countAuthorsBetween( $old, $new, $limit, $options=[])
Get the number of authors between the given revisions or revision IDs.
Definition: Title.php:3862
$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:315
Title\isSiteJsConfigPage
isSiteJsConfigPage()
Is this a sitewide JS "config" page?
Definition: Title.php:1588
Title\invalidateCache
invalidateCache( $purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:4143
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:651
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:988
Title\getRestrictions
getRestrictions( $action)
Accessor/initialisation for mRestrictions.
Definition: Title.php:2790
CommentStore\getStore
static getStore()
Definition: CommentStore.php:120
Title\isContentPage
isContentPage()
Is this Title in a namespace which contains content? In other words, is this a content page,...
Definition: Title.php:1380
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:221
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:66
Title\$titleCache
static MapCacheLRU null $titleCache
Definition: Title.php:50
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:507
$wgVariantArticlePath
$wgVariantArticlePath
Like $wgArticlePath, but on multi-variant wikis, this provides a path format that describes which par...
Definition: DefaultSettings.php:3391
Title\isRawHtmlMessage
isRawHtmlMessage()
Is this a message which can contain raw HTML?
Definition: Title.php:1606
Title\getSelectFields
static getSelectFields()
Returns a list of fields that are to be selected for initializing Title objects or LinkCache entries.
Definition: Title.php:484
Title\hasSubpages
hasSubpages()
Does this have subpages? (Warning, usually requires an extra DB query.)
Definition: Title.php:3049
Title\getBaseText
getBaseText()
Get the base page name without a namespace, i.e.
Definition: Title.php:2041
Title\pageCond
pageCond()
Get an associative array for selecting this title from the "page" table.
Definition: Title.php:3701
Title\getText
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:1041
Page\PageIdentity\getNamespace
getNamespace()
Returns the page's namespace number.
Title\$mTextform
string $mTextform
Text form (spaces not underscores) of the main part.
Definition: Title.php:84
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:3008
$wgInternalServer
$wgInternalServer
Internal server name as known to CDN, if different.
Definition: DefaultSettings.php:3003
Title\$mLatestID
bool int $mLatestID
ID of most recent revision.
Definition: Title.php:102
PROTO_HTTP
const PROTO_HTTP
Definition: Defines.php:203
Title\$mRestrictionsLoaded
bool $mRestrictionsLoaded
Boolean for initialisation on demand.
Definition: Title.php:146
Title\getWikiId
getWikiId()
Returns false to indicate that this Title belongs to the local wiki.
Definition: Title.php:4610
Title\lazyFillContentModel
lazyFillContentModel( $model)
If the content model field is not frozen then update it with a retreived value.
Definition: Title.php:1144
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:495
Title\getSubjectNsText
getSubjectNsText()
Get the namespace text of the subject (rather than talk) page.
Definition: Title.php:1180
Title\$mTitleProtection
mixed $mTitleProtection
Cached value for getTitleProtection (create protection)
Definition: Title.php:159
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:276
Title\getRelativeRevisionID
getRelativeRevisionID( $revId, $flags, $dir)
Get next/previous revision ID relative to another revision ID.
Definition: Title.php:3717
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:351
Title\getFullUrlForRedirect
getFullUrlForRedirect( $query='', $proto=PROTO_CURRENT)
Get a url appropriate for making redirects based on an untrusted url arg.
Definition: Title.php:2230
Title\getRootTitle
getRootTitle()
Get the root page name title, i.e.
Definition: Title.php:2018
$type
$type
Definition: testCompression.php:52
Title\getLength
getLength( $flags=0)
What is the length of this page? Uses link cache, adding it if necessary.
Definition: Title.php:3248
Title\findSubpageDivider
findSubpageDivider( $text, $dir)
Finds the first or last subpage divider (slash) in the string.
Definition: Title.php:1932
Title\isWatchable
isWatchable()
Can this title be added to a user's watchlist?
Definition: Title.php:1266