MediaWiki  master
Title.php
Go to the documentation of this file.
1 <?php
30 use Wikimedia\Assert\Assert;
33 
42 class Title implements LinkTarget, IDBAccessObject {
44  private static $titleCache = null;
45 
51  const CACHE_MAX = 1000;
52 
58  const GAID_FOR_UPDATE = 512;
59 
67  const NEW_CLONE = 'clone';
68 
74  // @{
75 
77  public $mTextform = '';
79  public $mUrlform = '';
81  public $mDbkeyform = '';
83  public $mNamespace = NS_MAIN;
85  public $mInterwiki = '';
87  private $mLocalInterwiki = false;
89  public $mFragment = '';
90 
92  public $mArticleID = -1;
93 
95  protected $mLatestID = false;
96 
101  private $mContentModel = false;
102 
107  private $mForcedContentModel = false;
108 
111 
113  public $mRestrictions = [];
114 
121  protected $mOldRestrictions = false;
122 
125 
128 
130  protected $mRestrictionsExpiry = [];
131 
134 
137 
139  public $mRestrictionsLoaded = false;
140 
149  public $prefixedText = null;
150 
153 
161 
163  protected $mLength = -1;
164 
166  public $mRedirect = null;
167 
170 
172  private $mHasSubpages;
173 
175  private $mPageLanguage;
176 
180  private $mDbPageLanguage = false;
181 
183  private $mTitleValue = null;
184 
186  private $mIsBigDeletion = null;
187 
189  private $mIsValid = null;
190  // @}
191 
197  private function getLanguageConverter( $language ) : ILanguageConverter {
198  return MediaWikiServices::getInstance()->getLanguageConverterFactory()
199  ->getLanguageConverter( $language );
200  }
201 
207  return $this->getLanguageConverter( $this->getPageLanguage() );
208  }
209 
218  private static function getTitleFormatter() {
219  return MediaWikiServices::getInstance()->getTitleFormatter();
220  }
221 
230  private static function getInterwikiLookup() {
231  return MediaWikiServices::getInstance()->getInterwikiLookup();
232  }
233 
237  function __construct() {
238  }
239 
248  public static function newFromDBkey( $key ) {
249  $t = new self();
250 
251  try {
252  $t->secureAndSplit( $key );
253  return $t;
254  } catch ( MalformedTitleException $ex ) {
255  return null;
256  }
257  }
258 
272  public static function newFromTitleValue( TitleValue $titleValue, $forceClone = '' ) {
273  return self::newFromLinkTarget( $titleValue, $forceClone );
274  }
275 
287  public static function newFromLinkTarget( LinkTarget $linkTarget, $forceClone = '' ) {
288  if ( $linkTarget instanceof Title ) {
289  // Special case if it's already a Title object
290  if ( $forceClone === self::NEW_CLONE ) {
291  return clone $linkTarget;
292  } else {
293  return $linkTarget;
294  }
295  }
296  return self::makeTitle(
297  $linkTarget->getNamespace(),
298  $linkTarget->getText(),
299  $linkTarget->getFragment(),
300  $linkTarget->getInterwiki()
301  );
302  }
303 
311  public static function castFromLinkTarget( $linkTarget ) {
312  return $linkTarget ? self::newFromLinkTarget( $linkTarget ) : null;
313  }
314 
335  public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
336  // DWIM: Integers can be passed in here when page titles are used as array keys.
337  if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) {
338  throw new InvalidArgumentException( '$text must be a string.' );
339  }
340  if ( $text === null ) {
341  return null;
342  }
343 
344  try {
345  return self::newFromTextThrow( (string)$text, (int)$defaultNamespace );
346  } catch ( MalformedTitleException $ex ) {
347  return null;
348  }
349  }
350 
370  public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
371  if ( is_object( $text ) ) {
372  throw new MWException( '$text must be a string, given an object' );
373  } elseif ( $text === null ) {
374  // Legacy code relies on MalformedTitleException being thrown in this case
375  // (happens when URL with no title in it is parsed). TODO fix
376  throw new MalformedTitleException( 'title-invalid-empty' );
377  }
378 
380 
381  // Wiki pages often contain multiple links to the same page.
382  // Title normalization and parsing can become expensive on pages with many
383  // links, so we can save a little time by caching them.
384  // In theory these are value objects and won't get changed...
385  if ( $defaultNamespace == NS_MAIN ) {
386  $t = $titleCache->get( $text );
387  if ( $t ) {
388  return $t;
389  }
390  }
391 
392  // Convert things like &eacute; &#257; or &#x3017; into normalized (T16952) text
393  $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
394 
395  $t = new Title();
396  $dbKeyForm = strtr( $filteredText, ' ', '_' );
397 
398  $t->secureAndSplit( $dbKeyForm, (int)$defaultNamespace );
399  if ( $defaultNamespace == NS_MAIN ) {
400  $titleCache->set( $text, $t );
401  }
402  return $t;
403  }
404 
420  public static function newFromURL( $url ) {
421  $t = new Title();
422 
423  # For compatibility with old buggy URLs. "+" is usually not valid in titles,
424  # but some URLs used it as a space replacement and they still come
425  # from some external search tools.
426  if ( strpos( self::legalChars(), '+' ) === false ) {
427  $url = strtr( $url, '+', ' ' );
428  }
429 
430  $dbKeyForm = strtr( $url, ' ', '_' );
431 
432  try {
433  $t->secureAndSplit( $dbKeyForm );
434  return $t;
435  } catch ( MalformedTitleException $ex ) {
436  return null;
437  }
438  }
439 
443  private static function getTitleCache() {
444  if ( self::$titleCache === null ) {
445  self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
446  }
447  return self::$titleCache;
448  }
449 
457  protected static function getSelectFields() {
459 
460  $fields = [
461  'page_namespace', 'page_title', 'page_id',
462  'page_len', 'page_is_redirect', 'page_latest',
463  ];
464 
465  if ( $wgContentHandlerUseDB ) {
466  $fields[] = 'page_content_model';
467  }
468 
469  if ( $wgPageLanguageUseDB ) {
470  $fields[] = 'page_lang';
471  }
472 
473  return $fields;
474  }
475 
483  public static function newFromID( $id, $flags = 0 ) {
484  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
485  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
486  $row = wfGetDB( $index )->selectRow(
487  'page',
488  self::getSelectFields(),
489  [ 'page_id' => $id ],
490  __METHOD__,
491  $options
492  );
493  if ( $row !== false ) {
494  $title = self::newFromRow( $row );
495  } else {
496  $title = null;
497  }
498 
499  return $title;
500  }
501 
508  public static function newFromIDs( $ids ) {
509  if ( !count( $ids ) ) {
510  return [];
511  }
512  $dbr = wfGetDB( DB_REPLICA );
513 
514  $res = $dbr->select(
515  'page',
516  self::getSelectFields(),
517  [ 'page_id' => $ids ],
518  __METHOD__
519  );
520 
521  $titles = [];
522  foreach ( $res as $row ) {
523  $titles[] = self::newFromRow( $row );
524  }
525  return $titles;
526  }
527 
534  public static function newFromRow( $row ) {
535  $t = self::makeTitle( $row->page_namespace, $row->page_title );
536  $t->loadFromRow( $row );
537  return $t;
538  }
539 
546  public function loadFromRow( $row ) {
547  if ( $row ) { // page found
548  if ( isset( $row->page_id ) ) {
549  $this->mArticleID = (int)$row->page_id;
550  }
551  if ( isset( $row->page_len ) ) {
552  $this->mLength = (int)$row->page_len;
553  }
554  if ( isset( $row->page_is_redirect ) ) {
555  $this->mRedirect = (bool)$row->page_is_redirect;
556  }
557  if ( isset( $row->page_latest ) ) {
558  $this->mLatestID = (int)$row->page_latest;
559  }
560  if ( isset( $row->page_content_model ) ) {
561  $this->lazyFillContentModel( $row->page_content_model );
562  } else {
563  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
564  }
565  if ( isset( $row->page_lang ) ) {
566  $this->mDbPageLanguage = (string)$row->page_lang;
567  }
568  if ( isset( $row->page_restrictions ) ) {
569  $this->mOldRestrictions = $row->page_restrictions;
570  }
571  } else { // page not found
572  $this->mArticleID = 0;
573  $this->mLength = 0;
574  $this->mRedirect = false;
575  $this->mLatestID = 0;
576  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
577  }
578  }
579 
602  public static function makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
603  $t = new Title();
604  $t->mInterwiki = $interwiki;
605  $t->mFragment = $fragment;
606  $t->mNamespace = $ns = (int)$ns;
607  $t->mDbkeyform = strtr( $title, ' ', '_' );
608  $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
609  $t->mUrlform = wfUrlencode( $t->mDbkeyform );
610  $t->mTextform = strtr( $title, '_', ' ' );
611  return $t;
612  }
613 
628  public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
629  // NOTE: ideally, this would just call makeTitle() and then isValid(),
630  // but presently, that means more overhead on a potential performance hotspot.
631 
632  if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) {
633  return null;
634  }
635 
636  $t = new Title();
637  $dbKeyForm = self::makeName( $ns, $title, $fragment, $interwiki, true );
638 
639  try {
640  $t->secureAndSplit( $dbKeyForm );
641  return $t;
642  } catch ( MalformedTitleException $ex ) {
643  return null;
644  }
645  }
646 
664  public static function newMainPage( MessageLocalizer $localizer = null ) {
665  if ( $localizer ) {
666  $msg = $localizer->msg( 'mainpage' );
667  } else {
668  $msg = wfMessage( 'mainpage' );
669  }
670 
671  $title = self::newFromText( $msg->inContentLanguage()->text() );
672 
673  // Every page renders at least one link to the Main Page (e.g. sidebar).
674  // If the localised value is invalid, don't produce fatal errors that
675  // would make the wiki inaccessible (and hard to fix the invalid message).
676  // Gracefully fallback...
677  if ( !$title ) {
678  $title = self::newFromText( 'Main Page' );
679  }
680  return $title;
681  }
682 
689  public static function nameOf( $id ) {
690  $dbr = wfGetDB( DB_REPLICA );
691 
692  $s = $dbr->selectRow(
693  'page',
694  [ 'page_namespace', 'page_title' ],
695  [ 'page_id' => $id ],
696  __METHOD__
697  );
698  if ( $s === false ) {
699  return null;
700  }
701 
702  return self::makeName( $s->page_namespace, $s->page_title );
703  }
704 
710  public static function legalChars() {
711  global $wgLegalTitleChars;
712  return $wgLegalTitleChars;
713  }
714 
724  public static function convertByteClassToUnicodeClass( $byteClass ) {
725  $length = strlen( $byteClass );
726  // Input token queue
727  $x0 = $x1 = $x2 = '';
728  // Decoded queue
729  $d0 = $d1 = $d2 = '';
730  // Decoded integer codepoints
731  $ord0 = $ord1 = $ord2 = 0;
732  // Re-encoded queue
733  $r0 = $r1 = $r2 = '';
734  // Output
735  $out = '';
736  // Flags
737  $allowUnicode = false;
738  for ( $pos = 0; $pos < $length; $pos++ ) {
739  // Shift the queues down
740  $x2 = $x1;
741  $x1 = $x0;
742  $d2 = $d1;
743  $d1 = $d0;
744  $ord2 = $ord1;
745  $ord1 = $ord0;
746  $r2 = $r1;
747  $r1 = $r0;
748  // Load the current input token and decoded values
749  $inChar = $byteClass[$pos];
750  if ( $inChar == '\\' ) {
751  if ( preg_match( '/x([0-9a-fA-F]{2})/A', $byteClass, $m, 0, $pos + 1 ) ) {
752  $x0 = $inChar . $m[0];
753  $d0 = chr( hexdec( $m[1] ) );
754  $pos += strlen( $m[0] );
755  } elseif ( preg_match( '/[0-7]{3}/A', $byteClass, $m, 0, $pos + 1 ) ) {
756  $x0 = $inChar . $m[0];
757  $d0 = chr( octdec( $m[0] ) );
758  $pos += strlen( $m[0] );
759  } elseif ( $pos + 1 >= $length ) {
760  $x0 = $d0 = '\\';
761  } else {
762  $d0 = $byteClass[$pos + 1];
763  $x0 = $inChar . $d0;
764  $pos += 1;
765  }
766  } else {
767  $x0 = $d0 = $inChar;
768  }
769  $ord0 = ord( $d0 );
770  // Load the current re-encoded value
771  if ( $ord0 < 32 || $ord0 == 0x7f ) {
772  $r0 = sprintf( '\x%02x', $ord0 );
773  } elseif ( $ord0 >= 0x80 ) {
774  // Allow unicode if a single high-bit character appears
775  $r0 = sprintf( '\x%02x', $ord0 );
776  $allowUnicode = true;
777  // @phan-suppress-next-line PhanParamSuspiciousOrder false positive
778  } elseif ( strpos( '-\\[]^', $d0 ) !== false ) {
779  $r0 = '\\' . $d0;
780  } else {
781  $r0 = $d0;
782  }
783  // Do the output
784  if ( $x0 !== '' && $x1 === '-' && $x2 !== '' ) {
785  // Range
786  if ( $ord2 > $ord0 ) {
787  // Empty range
788  } elseif ( $ord0 >= 0x80 ) {
789  // Unicode range
790  $allowUnicode = true;
791  if ( $ord2 < 0x80 ) {
792  // Keep the non-unicode section of the range
793  $out .= "$r2-\\x7F";
794  }
795  } else {
796  // Normal range
797  $out .= "$r2-$r0";
798  }
799  // Reset state to the initial value
800  $x0 = $x1 = $d0 = $d1 = $r0 = $r1 = '';
801  } elseif ( $ord2 < 0x80 ) {
802  // ASCII character
803  $out .= $r2;
804  }
805  }
806  if ( $ord1 < 0x80 ) {
807  $out .= $r1;
808  }
809  if ( $ord0 < 0x80 ) {
810  $out .= $r0;
811  }
812  if ( $allowUnicode ) {
813  $out .= '\u0080-\uFFFF';
814  }
815  return $out;
816  }
817 
829  public static function makeName( $ns, $title, $fragment = '', $interwiki = '',
830  $canonicalNamespace = false
831  ) {
832  if ( $canonicalNamespace ) {
833  $namespace = MediaWikiServices::getInstance()->getNamespaceInfo()->
834  getCanonicalName( $ns );
835  } else {
836  $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns );
837  }
838  $name = $namespace == '' ? $title : "$namespace:$title";
839  if ( strval( $interwiki ) != '' ) {
840  $name = "$interwiki:$name";
841  }
842  if ( strval( $fragment ) != '' ) {
843  $name .= '#' . $fragment;
844  }
845  return $name;
846  }
847 
856  public static function compare( LinkTarget $a, LinkTarget $b ) {
857  return $a->getNamespace() <=> $b->getNamespace()
858  ?: strcmp( $a->getText(), $b->getText() );
859  }
860 
877  public function isValid() {
878  if ( $this->mIsValid !== null ) {
879  return $this->mIsValid;
880  }
881 
882  try {
883  $text = $this->getFullText();
884  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
885 
886  '@phan-var MediaWikiTitleCodec $titleCodec';
887  $parts = $titleCodec->splitTitleString( $text, $this->mNamespace );
888 
889  // Check that nothing changed!
890  // This ensures that $text was already perperly normalized.
891  if ( $parts['fragment'] !== $this->mFragment
892  || $parts['interwiki'] !== $this->mInterwiki
893  || $parts['local_interwiki'] !== $this->mLocalInterwiki
894  || $parts['namespace'] !== $this->mNamespace
895  || $parts['dbkey'] !== $this->mDbkeyform
896  ) {
897  $this->mIsValid = false;
898  return $this->mIsValid;
899  }
900  } catch ( MalformedTitleException $ex ) {
901  $this->mIsValid = false;
902  return $this->mIsValid;
903  }
904 
905  $this->mIsValid = true;
906  return $this->mIsValid;
907  }
908 
916  public function isLocal() {
917  if ( $this->isExternal() ) {
918  $iw = self::getInterwikiLookup()->fetch( $this->mInterwiki );
919  if ( $iw ) {
920  return $iw->isLocal();
921  }
922  }
923  return true;
924  }
925 
931  public function isExternal() {
932  return $this->mInterwiki !== '';
933  }
934 
942  public function getInterwiki() {
943  return $this->mInterwiki;
944  }
945 
951  public function wasLocalInterwiki() {
952  return $this->mLocalInterwiki;
953  }
954 
961  public function isTrans() {
962  if ( !$this->isExternal() ) {
963  return false;
964  }
965 
966  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable();
967  }
968 
974  public function getTransWikiID() {
975  if ( !$this->isExternal() ) {
976  return false;
977  }
978 
979  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID();
980  }
981 
991  public function getTitleValue() {
992  if ( $this->mTitleValue === null ) {
993  try {
994  $this->mTitleValue = new TitleValue(
995  $this->mNamespace,
996  $this->mDbkeyform,
997  $this->mFragment,
998  $this->mInterwiki
999  );
1000  } catch ( InvalidArgumentException $ex ) {
1001  wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' .
1002  $this->getPrefixedText() . ']]: ' . $ex->getMessage() . "\n" );
1003  }
1004  }
1005 
1006  return $this->mTitleValue;
1007  }
1008 
1014  public function getText() {
1015  return $this->mTextform;
1016  }
1017 
1023  public function getPartialURL() {
1024  return $this->mUrlform;
1025  }
1026 
1032  public function getDBkey() {
1033  return $this->mDbkeyform;
1034  }
1035 
1042  function getUserCaseDBKey() {
1043  wfDeprecated( __METHOD__, '1.33' );
1044 
1045  return $this->getDBkey();
1046  }
1047 
1053  public function getNamespace() {
1054  return $this->mNamespace;
1055  }
1056 
1065  public function getContentModel( $flags = 0 ) {
1066  if ( $this->mForcedContentModel ) {
1067  if ( !$this->mContentModel ) {
1068  throw new RuntimeException( 'Got out of sync; an empty model is being forced' );
1069  }
1070  // Content model is locked to the currently loaded one
1071  return $this->mContentModel;
1072  }
1073 
1074  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
1075  $this->lazyFillContentModel( $this->loadFieldFromDB( 'page_content_model', $flags ) );
1076  } elseif (
1077  ( !$this->mContentModel || $flags & self::GAID_FOR_UPDATE ) &&
1078  $this->getArticleID( $flags )
1079  ) {
1080  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1081  $linkCache->addLinkObj( $this ); # in case we already had an article ID
1082  $this->lazyFillContentModel( $linkCache->getGoodLinkFieldObj( $this, 'model' ) );
1083  }
1084 
1085  if ( !$this->mContentModel ) {
1087  }
1088 
1089  return $this->mContentModel;
1090  }
1091 
1098  public function hasContentModel( $id ) {
1099  return $this->getContentModel() == $id;
1100  }
1101 
1115  public function setContentModel( $model ) {
1116  if ( (string)$model === '' ) {
1117  throw new InvalidArgumentException( "Missing CONTENT_MODEL_* constant" );
1118  }
1119 
1120  $this->mContentModel = $model;
1121  $this->mForcedContentModel = true;
1122  }
1123 
1129  private function lazyFillContentModel( $model ) {
1130  if ( !$this->mForcedContentModel ) {
1131  $this->mContentModel = ( $model === false ) ? false : (string)$model;
1132  }
1133  }
1134 
1140  public function getNsText() {
1141  if ( $this->isExternal() ) {
1142  // This probably shouldn't even happen, except for interwiki transclusion.
1143  // If possible, use the canonical name for the foreign namespace.
1144  $nsText = MediaWikiServices::getInstance()->getNamespaceInfo()->
1145  getCanonicalName( $this->mNamespace );
1146  if ( $nsText !== false ) {
1147  return $nsText;
1148  }
1149  }
1150 
1151  try {
1152  $formatter = self::getTitleFormatter();
1153  return $formatter->getNamespaceName( $this->mNamespace, $this->mDbkeyform );
1154  } catch ( InvalidArgumentException $ex ) {
1155  wfDebug( __METHOD__ . ': ' . $ex->getMessage() . "\n" );
1156  return false;
1157  }
1158  }
1159 
1165  public function getSubjectNsText() {
1166  $services = MediaWikiServices::getInstance();
1167  return $services->getContentLanguage()->
1168  getNsText( $services->getNamespaceInfo()->getSubject( $this->mNamespace ) );
1169  }
1170 
1176  public function getTalkNsText() {
1177  $services = MediaWikiServices::getInstance();
1178  return $services->getContentLanguage()->
1179  getNsText( $services->getNamespaceInfo()->getTalk( $this->mNamespace ) );
1180  }
1181 
1193  public function canHaveTalkPage() {
1194  return MediaWikiServices::getInstance()->getNamespaceInfo()->canHaveTalkPage( $this );
1195  }
1196 
1207  public function canExist() {
1208  // NOTE: Don't use getArticleID(), we don't want to
1209  // trigger a database query here. This check is supposed to
1210  // act as an optimization, not add extra cost.
1211  if ( $this->mArticleID > 0 ) {
1212  // It exists, so it can exist.
1213  return true;
1214  }
1215 
1216  // NOTE: we call the relatively expensive isValid() method further down,
1217  // but we can bail out early if we already know the title is invalid.
1218  if ( $this->mIsValid === false ) {
1219  // It's invalid, so it can't exist.
1220  return false;
1221  }
1222 
1223  if ( $this->getNamespace() < NS_MAIN ) {
1224  // It's a special page, so it can't exist in the database.
1225  return false;
1226  }
1227 
1228  if ( $this->isExternal() ) {
1229  // If it's external, it's not local, so it can't exist.
1230  return false;
1231  }
1232 
1233  if ( $this->getText() === '' ) {
1234  // The title has no text, so it can't exist in the database.
1235  // It's probably an on-page section link, like "#something".
1236  return false;
1237  }
1238 
1239  // Double check that the title is valid.
1240  return $this->isValid();
1241  }
1242 
1251  public function isWatchable() {
1252  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
1253  return $this->getText() !== '' && !$this->isExternal() &&
1254  $nsInfo->isWatchable( $this->mNamespace );
1255  }
1256 
1262  public function isSpecialPage() {
1263  return $this->mNamespace == NS_SPECIAL;
1264  }
1265 
1272  public function isSpecial( $name ) {
1273  if ( $this->isSpecialPage() ) {
1274  list( $thisName, /* $subpage */ ) =
1275  MediaWikiServices::getInstance()->getSpecialPageFactory()->
1276  resolveAlias( $this->mDbkeyform );
1277  if ( $name == $thisName ) {
1278  return true;
1279  }
1280  }
1281  return false;
1282  }
1283 
1290  public function fixSpecialName() {
1291  if ( $this->isSpecialPage() ) {
1292  $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory();
1293  list( $canonicalName, $par ) = $spFactory->resolveAlias( $this->mDbkeyform );
1294  if ( $canonicalName ) {
1295  $localName = $spFactory->getLocalNameFor( $canonicalName, $par );
1296  if ( $localName != $this->mDbkeyform ) {
1297  return self::makeTitle( NS_SPECIAL, $localName );
1298  }
1299  }
1300  }
1301  return $this;
1302  }
1303 
1314  public function inNamespace( $ns ) {
1315  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1316  equals( $this->mNamespace, $ns );
1317  }
1318 
1326  public function inNamespaces( ...$namespaces ) {
1327  if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) {
1328  $namespaces = $namespaces[0];
1329  }
1330 
1331  foreach ( $namespaces as $ns ) {
1332  if ( $this->inNamespace( $ns ) ) {
1333  return true;
1334  }
1335  }
1336 
1337  return false;
1338  }
1339 
1353  public function hasSubjectNamespace( $ns ) {
1354  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1355  subjectEquals( $this->mNamespace, $ns );
1356  }
1357 
1365  public function isContentPage() {
1366  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1367  isContent( $this->mNamespace );
1368  }
1369 
1376  public function isMovable() {
1377  if (
1378  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1379  isMovable( $this->mNamespace ) || $this->isExternal()
1380  ) {
1381  // Interwiki title or immovable namespace. Hooks don't get to override here
1382  return false;
1383  }
1384 
1385  $result = true;
1386  Hooks::run( 'TitleIsMovable', [ $this, &$result ] );
1387  return $result;
1388  }
1389 
1400  public function isMainPage() {
1401  return $this->equals( self::newMainPage() );
1402  }
1403 
1409  public function isSubpage() {
1410  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1411  hasSubpages( $this->mNamespace )
1412  ? strpos( $this->getText(), '/' ) !== false
1413  : false;
1414  }
1415 
1421  public function isConversionTable() {
1422  // @todo ConversionTable should become a separate content model.
1423 
1424  return $this->mNamespace == NS_MEDIAWIKI &&
1425  strpos( $this->getText(), 'Conversiontable/' ) === 0;
1426  }
1427 
1433  public function isWikitextPage() {
1434  return $this->hasContentModel( CONTENT_MODEL_WIKITEXT );
1435  }
1436 
1451  public function isSiteConfigPage() {
1452  return (
1453  $this->isSiteCssConfigPage()
1454  || $this->isSiteJsonConfigPage()
1455  || $this->isSiteJsConfigPage()
1456  );
1457  }
1458 
1465  public function isUserConfigPage() {
1466  return (
1467  $this->isUserCssConfigPage()
1468  || $this->isUserJsonConfigPage()
1469  || $this->isUserJsConfigPage()
1470  );
1471  }
1472 
1479  public function getSkinFromConfigSubpage() {
1480  $subpage = explode( '/', $this->mTextform );
1481  $subpage = $subpage[count( $subpage ) - 1];
1482  $lastdot = strrpos( $subpage, '.' );
1483  if ( $lastdot === false ) {
1484  return $subpage; # Never happens: only called for names ending in '.css'/'.json'/'.js'
1485  }
1486  return substr( $subpage, 0, $lastdot );
1487  }
1488 
1495  public function isUserCssConfigPage() {
1496  return (
1497  NS_USER == $this->mNamespace
1498  && $this->isSubpage()
1499  && $this->hasContentModel( CONTENT_MODEL_CSS )
1500  );
1501  }
1502 
1509  public function isUserJsonConfigPage() {
1510  return (
1511  NS_USER == $this->mNamespace
1512  && $this->isSubpage()
1513  && $this->hasContentModel( CONTENT_MODEL_JSON )
1514  );
1515  }
1516 
1523  public function isUserJsConfigPage() {
1524  return (
1525  NS_USER == $this->mNamespace
1526  && $this->isSubpage()
1528  );
1529  }
1530 
1537  public function isSiteCssConfigPage() {
1538  return (
1539  NS_MEDIAWIKI == $this->mNamespace
1540  && (
1542  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1543  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1544  || substr( $this->mDbkeyform, -4 ) === '.css'
1545  )
1546  );
1547  }
1548 
1555  public function isSiteJsonConfigPage() {
1556  return (
1557  NS_MEDIAWIKI == $this->mNamespace
1558  && (
1560  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1561  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1562  || substr( $this->mDbkeyform, -5 ) === '.json'
1563  )
1564  );
1565  }
1566 
1573  public function isSiteJsConfigPage() {
1574  return (
1575  NS_MEDIAWIKI == $this->mNamespace
1576  && (
1578  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1579  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1580  || substr( $this->mDbkeyform, -3 ) === '.js'
1581  )
1582  );
1583  }
1584 
1591  public function isRawHtmlMessage() {
1592  global $wgRawHtmlMessages;
1593 
1594  if ( !$this->inNamespace( NS_MEDIAWIKI ) ) {
1595  return false;
1596  }
1597  $message = lcfirst( $this->getRootTitle()->getDBkey() );
1598  return in_array( $message, $wgRawHtmlMessages, true );
1599  }
1600 
1606  public function isTalkPage() {
1607  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1608  isTalk( $this->mNamespace );
1609  }
1610 
1622  public function getTalkPage() {
1623  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1624  // Instead of failing on invalid titles, let's just log the issue for now.
1625  // See the discussion on T227817.
1626 
1627  // Is this the same title?
1628  $talkNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $this->mNamespace );
1629  if ( $this->mNamespace == $talkNS ) {
1630  return $this;
1631  }
1632 
1633  $title = self::makeTitle( $talkNS, $this->mDbkeyform );
1634 
1635  $this->warnIfPageCannotExist( $title, __METHOD__ );
1636 
1637  return $title;
1638  // TODO: replace the above with the code below:
1639  // return self::castFromLinkTarget(
1640  // MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) );
1641  }
1642 
1652  public function getTalkPageIfDefined() {
1653  if ( !$this->canHaveTalkPage() ) {
1654  return null;
1655  }
1656 
1657  return $this->getTalkPage();
1658  }
1659 
1667  public function getSubjectPage() {
1668  // Is this the same title?
1669  $subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo()
1670  ->getSubject( $this->mNamespace );
1671  if ( $this->mNamespace == $subjectNS ) {
1672  return $this;
1673  }
1674  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1675  // Instead of failing on invalid titles, let's just log the issue for now.
1676  // See the discussion on T227817.
1677  $title = self::makeTitle( $subjectNS, $this->mDbkeyform );
1678 
1679  $this->warnIfPageCannotExist( $title, __METHOD__ );
1680 
1681  return $title;
1682  // TODO: replace the above with the code below:
1683  // return self::castFromLinkTarget(
1684  // MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
1685  }
1686 
1693  private function warnIfPageCannotExist( Title $title, $method ) {
1694  if ( $this->getText() == '' ) {
1695  wfLogWarning(
1696  $method . ': called on empty title ' . $this->getFullText() . ', returning '
1697  . $title->getFullText()
1698  );
1699 
1700  return true;
1701  }
1702 
1703  if ( $this->getInterwiki() !== '' ) {
1704  wfLogWarning(
1705  $method . ': called on interwiki title ' . $this->getFullText() . ', returning '
1706  . $title->getFullText()
1707  );
1708 
1709  return true;
1710  }
1711 
1712  return false;
1713  }
1714 
1724  public function getOtherPage() {
1725  // NOTE: Depend on the methods in this class instead of their equivalent in NamespaceInfo,
1726  // until their semantics has become exactly the same.
1727  // See the discussion on T227817.
1728  if ( $this->isSpecialPage() ) {
1729  throw new MWException( 'Special pages cannot have other pages' );
1730  }
1731  if ( $this->isTalkPage() ) {
1732  return $this->getSubjectPage();
1733  } else {
1734  if ( !$this->canHaveTalkPage() ) {
1735  throw new MWException( "{$this->getPrefixedText()} does not have an other page" );
1736  }
1737  return $this->getTalkPage();
1738  }
1739  // TODO: replace the above with the code below:
1740  // return self::castFromLinkTarget(
1741  // MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) );
1742  }
1743 
1749  public function getDefaultNamespace() {
1750  return $this->mDefaultNamespace;
1751  }
1752 
1760  public function getFragment() {
1761  return $this->mFragment;
1762  }
1763 
1770  public function hasFragment() {
1771  return $this->mFragment !== '';
1772  }
1773 
1779  public function getFragmentForURL() {
1780  if ( !$this->hasFragment() ) {
1781  return '';
1782  } elseif ( $this->isExternal() ) {
1783  // Note: If the interwiki is unknown, it's treated as a namespace on the local wiki,
1784  // so we treat it like a local interwiki.
1785  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
1786  if ( $interwiki && !$interwiki->isLocal() ) {
1787  return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment );
1788  }
1789  }
1790 
1791  return '#' . Sanitizer::escapeIdForLink( $this->mFragment );
1792  }
1793 
1806  public function setFragment( $fragment ) {
1807  $this->mFragment = strtr( substr( $fragment, 1 ), '_', ' ' );
1808  }
1809 
1817  public function createFragmentTarget( $fragment ) {
1818  return self::makeTitle(
1819  $this->mNamespace,
1820  $this->getText(),
1821  $fragment,
1822  $this->mInterwiki
1823  );
1824  }
1825 
1833  private function prefix( $name ) {
1834  $p = '';
1835  if ( $this->isExternal() ) {
1836  $p = $this->mInterwiki . ':';
1837  }
1838 
1839  if ( $this->mNamespace != 0 ) {
1840  $nsText = $this->getNsText();
1841 
1842  if ( $nsText === false ) {
1843  // See T165149. Awkward, but better than erroneously linking to the main namespace.
1844  $nsText = MediaWikiServices::getInstance()->getContentLanguage()->
1845  getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
1846  }
1847 
1848  $p .= $nsText . ':';
1849  }
1850  return $p . $name;
1851  }
1852 
1859  public function getPrefixedDBkey() {
1860  $s = $this->prefix( $this->mDbkeyform );
1861  $s = strtr( $s, ' ', '_' );
1862  return $s;
1863  }
1864 
1871  public function getPrefixedText() {
1872  if ( $this->prefixedText === null ) {
1873  $s = $this->prefix( $this->mTextform );
1874  $s = strtr( $s, '_', ' ' );
1875  $this->prefixedText = $s;
1876  }
1877  return $this->prefixedText;
1878  }
1879 
1885  public function __toString() {
1886  return $this->getPrefixedText();
1887  }
1888 
1895  public function getFullText() {
1896  $text = $this->getPrefixedText();
1897  if ( $this->hasFragment() ) {
1898  $text .= '#' . $this->mFragment;
1899  }
1900  return $text;
1901  }
1902 
1918  public function getRootText() {
1919  if (
1920  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1921  hasSubpages( $this->mNamespace )
1922  || strtok( $this->getText(), '/' ) === false
1923  ) {
1924  return $this->getText();
1925  }
1926 
1927  return strtok( $this->getText(), '/' );
1928  }
1929 
1942  public function getRootTitle() {
1943  $title = self::makeTitleSafe( $this->mNamespace, $this->getRootText() );
1944  Assert::postcondition(
1945  $title !== null,
1946  'makeTitleSafe() should always return a Title for the text returned by getRootText().'
1947  );
1948  return $title;
1949  }
1950 
1965  public function getBaseText() {
1966  $text = $this->getText();
1967  if (
1968  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1969  hasSubpages( $this->mNamespace )
1970  ) {
1971  return $text;
1972  }
1973 
1974  $lastSlashPos = strrpos( $text, '/' );
1975  // Don't discard the real title if there's no subpage involved
1976  if ( $lastSlashPos === false ) {
1977  return $text;
1978  }
1979 
1980  return substr( $text, 0, $lastSlashPos );
1981  }
1982 
1995  public function getBaseTitle() {
1996  $title = self::makeTitleSafe( $this->mNamespace, $this->getBaseText() );
1997  Assert::postcondition(
1998  $title !== null,
1999  'makeTitleSafe() should always return a Title for the text returned by getBaseText().'
2000  );
2001  return $title;
2002  }
2003 
2015  public function getSubpageText() {
2016  if (
2017  !MediaWikiServices::getInstance()->getNamespaceInfo()->
2018  hasSubpages( $this->mNamespace )
2019  ) {
2020  return $this->mTextform;
2021  }
2022  $parts = explode( '/', $this->mTextform );
2023  return $parts[count( $parts ) - 1];
2024  }
2025 
2039  public function getSubpage( $text ) {
2040  return self::makeTitleSafe(
2041  $this->mNamespace,
2042  $this->getText() . '/' . $text,
2043  '',
2044  $this->mInterwiki
2045  );
2046  }
2047 
2053  public function getSubpageUrlForm() {
2054  $text = $this->getSubpageText();
2055  $text = wfUrlencode( strtr( $text, ' ', '_' ) );
2056  return $text;
2057  }
2058 
2064  public function getPrefixedURL() {
2065  $s = $this->prefix( $this->mDbkeyform );
2066  $s = wfUrlencode( strtr( $s, ' ', '_' ) );
2067  return $s;
2068  }
2069 
2083  private static function fixUrlQueryArgs( $query, $query2 = false ) {
2084  if ( $query2 !== false ) {
2085  wfDeprecated( "Title::get{Canonical,Full,Link,Local,Internal}URL " .
2086  "method called with a second parameter is deprecated. Add your " .
2087  "parameter to an array passed as the first parameter.", "1.19" );
2088  }
2089  if ( is_array( $query ) ) {
2090  $query = wfArrayToCgi( $query );
2091  }
2092  if ( $query2 ) {
2093  if ( is_string( $query2 ) ) {
2094  // $query2 is a string, we will consider this to be
2095  // a deprecated $variant argument and add it to the query
2096  $query2 = wfArrayToCgi( [ 'variant' => $query2 ] );
2097  } else {
2098  $query2 = wfArrayToCgi( $query2 );
2099  }
2100  // If we have $query content add a & to it first
2101  if ( $query ) {
2102  $query .= '&';
2103  }
2104  // Now append the queries together
2105  $query .= $query2;
2106  }
2107  return $query;
2108  }
2109 
2121  public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
2122  $query = self::fixUrlQueryArgs( $query, $query2 );
2123 
2124  # Hand off all the decisions on urls to getLocalURL
2125  $url = $this->getLocalURL( $query );
2126 
2127  # Expand the url to make it a full url. Note that getLocalURL has the
2128  # potential to output full urls for a variety of reasons, so we use
2129  # wfExpandUrl instead of simply prepending $wgServer
2130  $url = wfExpandUrl( $url, $proto );
2131 
2132  # Finally, add the fragment.
2133  $url .= $this->getFragmentForURL();
2134  // Avoid PHP 7.1 warning from passing $this by reference
2135  $titleRef = $this;
2136  Hooks::run( 'GetFullURL', [ &$titleRef, &$url, $query ] );
2137  return $url;
2138  }
2139 
2156  public function getFullUrlForRedirect( $query = '', $proto = PROTO_CURRENT ) {
2157  $target = $this;
2158  if ( $this->isExternal() ) {
2159  $target = SpecialPage::getTitleFor(
2160  'GoToInterwiki',
2161  $this->getPrefixedDBkey()
2162  );
2163  }
2164  return $target->getFullURL( $query, false, $proto );
2165  }
2166 
2190  public function getLocalURL( $query = '', $query2 = false ) {
2192 
2193  $query = self::fixUrlQueryArgs( $query, $query2 );
2194 
2195  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
2196  if ( $interwiki ) {
2197  $namespace = $this->getNsText();
2198  if ( $namespace != '' ) {
2199  # Can this actually happen? Interwikis shouldn't be parsed.
2200  # Yes! It can in interwiki transclusion. But... it probably shouldn't.
2201  $namespace .= ':';
2202  }
2203  $url = $interwiki->getURL( $namespace . $this->mDbkeyform );
2204  $url = wfAppendQuery( $url, $query );
2205  } else {
2206  $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
2207  if ( $query == '' ) {
2208  $url = str_replace( '$1', $dbkey, $wgArticlePath );
2209  // Avoid PHP 7.1 warning from passing $this by reference
2210  $titleRef = $this;
2211  Hooks::run( 'GetLocalURL::Article', [ &$titleRef, &$url ] );
2212  } else {
2214  $url = false;
2215  $matches = [];
2216 
2218 
2219  if ( $articlePaths
2220  && preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
2221  ) {
2222  $action = urldecode( $matches[2] );
2223  if ( isset( $articlePaths[$action] ) ) {
2224  $query = $matches[1];
2225  if ( isset( $matches[4] ) ) {
2226  $query .= $matches[4];
2227  }
2228  $url = str_replace( '$1', $dbkey, $articlePaths[$action] );
2229  if ( $query != '' ) {
2230  $url = wfAppendQuery( $url, $query );
2231  }
2232  }
2233  }
2234 
2235  if ( $url === false
2237  && preg_match( '/^variant=([^&]*)$/', $query, $matches )
2238  && $this->getPageLanguage()->equals(
2239  MediaWikiServices::getInstance()->getContentLanguage() )
2240  && $this->getPageLanguageConverter()->hasVariants()
2241  ) {
2242  $variant = urldecode( $matches[1] );
2243  if ( $this->getPageLanguageConverter()->hasVariant( $variant ) ) {
2244  // Only do the variant replacement if the given variant is a valid
2245  // variant for the page's language.
2246  $url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath );
2247  $url = str_replace( '$1', $dbkey, $url );
2248  }
2249  }
2250 
2251  if ( $url === false ) {
2252  if ( $query == '-' ) {
2253  $query = '';
2254  }
2255  $url = "{$wgScript}?title={$dbkey}&{$query}";
2256  }
2257  }
2258  // Avoid PHP 7.1 warning from passing $this by reference
2259  $titleRef = $this;
2260  Hooks::run( 'GetLocalURL::Internal', [ &$titleRef, &$url, $query ] );
2261 
2262  // @todo FIXME: This causes breakage in various places when we
2263  // actually expected a local URL and end up with dupe prefixes.
2264  if ( $wgRequest->getVal( 'action' ) == 'render' ) {
2265  $url = $wgServer . $url;
2266  }
2267  }
2268 
2269  if ( $wgMainPageIsDomainRoot && $this->isMainPage() && $query === '' ) {
2270  return '/';
2271  }
2272 
2273  // Avoid PHP 7.1 warning from passing $this by reference
2274  $titleRef = $this;
2275  Hooks::run( 'GetLocalURL', [ &$titleRef, &$url, $query ] );
2276  return $url;
2277  }
2278 
2296  public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
2297  if ( $this->isExternal() || $proto !== false ) {
2298  $ret = $this->getFullURL( $query, $query2, $proto );
2299  } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
2300  $ret = $this->getFragmentForURL();
2301  } else {
2302  $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
2303  }
2304  return $ret;
2305  }
2306 
2321  public function getInternalURL( $query = '', $query2 = false ) {
2322  global $wgInternalServer, $wgServer;
2323  $query = self::fixUrlQueryArgs( $query, $query2 );
2324  $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
2325  $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP );
2326  // Avoid PHP 7.1 warning from passing $this by reference
2327  $titleRef = $this;
2328  Hooks::run( 'GetInternalURL', [ &$titleRef, &$url, $query ] );
2329  return $url;
2330  }
2331 
2345  public function getCanonicalURL( $query = '', $query2 = false ) {
2346  $query = self::fixUrlQueryArgs( $query, $query2 );
2347  $url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL );
2348  // Avoid PHP 7.1 warning from passing $this by reference
2349  $titleRef = $this;
2350  Hooks::run( 'GetCanonicalURL', [ &$titleRef, &$url, $query ] );
2351  return $url;
2352  }
2353 
2359  public function getEditURL() {
2360  if ( $this->isExternal() ) {
2361  return '';
2362  }
2363  $s = $this->getLocalURL( 'action=edit' );
2364 
2365  return $s;
2366  }
2367 
2388  public function quickUserCan( $action, $user = null ) {
2389  wfDeprecated( __METHOD__, '1.33' );
2390  if ( !$user instanceof User ) {
2391  global $wgUser;
2392  $user = $wgUser;
2393  }
2394  return MediaWikiServices::getInstance()->getPermissionManager()
2395  ->quickUserCan( $action, $user, $this );
2396  }
2397 
2413  public function userCan( $action, $user = null, $rigor = PermissionManager::RIGOR_SECURE ) {
2414  wfDeprecated( __METHOD__, '1.33' );
2415  if ( !$user instanceof User ) {
2416  global $wgUser;
2417  $user = $wgUser;
2418  }
2419 
2420  // TODO: this is for b/c, eventually will be removed
2421  if ( $rigor === true ) {
2422  $rigor = PermissionManager::RIGOR_SECURE; // b/c
2423  } elseif ( $rigor === false ) {
2424  $rigor = PermissionManager::RIGOR_QUICK; // b/c
2425  }
2426 
2427  return MediaWikiServices::getInstance()->getPermissionManager()
2428  ->userCan( $action, $user, $this, $rigor );
2429  }
2430 
2452  public function getUserPermissionsErrors(
2453  $action, $user, $rigor = PermissionManager::RIGOR_SECURE, $ignoreErrors = []
2454  ) {
2455  // TODO: this is for b/c, eventually will be removed
2456  if ( $rigor === true ) {
2457  $rigor = PermissionManager::RIGOR_SECURE; // b/c
2458  } elseif ( $rigor === false ) {
2459  $rigor = PermissionManager::RIGOR_QUICK; // b/c
2460  }
2461 
2462  return MediaWikiServices::getInstance()->getPermissionManager()
2463  ->getPermissionErrors( $action, $user, $this, $rigor, $ignoreErrors );
2464  }
2465 
2473  public static function getFilteredRestrictionTypes( $exists = true ) {
2474  global $wgRestrictionTypes;
2475  $types = $wgRestrictionTypes;
2476  if ( $exists ) {
2477  # Remove the create restriction for existing titles
2478  $types = array_diff( $types, [ 'create' ] );
2479  } else {
2480  # Only the create and upload restrictions apply to non-existing titles
2481  $types = array_intersect( $types, [ 'create', 'upload' ] );
2482  }
2483  return $types;
2484  }
2485 
2491  public function getRestrictionTypes() {
2492  if ( $this->isSpecialPage() ) {
2493  return [];
2494  }
2495 
2496  $types = self::getFilteredRestrictionTypes( $this->exists() );
2497 
2498  if ( $this->mNamespace != NS_FILE ) {
2499  # Remove the upload restriction for non-file titles
2500  $types = array_diff( $types, [ 'upload' ] );
2501  }
2502 
2503  Hooks::run( 'TitleGetRestrictionTypes', [ $this, &$types ] );
2504 
2505  wfDebug( __METHOD__ . ': applicable restrictions to [[' .
2506  $this->getPrefixedText() . ']] are {' . implode( ',', $types ) . "}\n" );
2507 
2508  return $types;
2509  }
2510 
2518  public function getTitleProtection() {
2519  $protection = $this->getTitleProtectionInternal();
2520  if ( $protection ) {
2521  if ( $protection['permission'] == 'sysop' ) {
2522  $protection['permission'] = 'editprotected'; // B/C
2523  }
2524  if ( $protection['permission'] == 'autoconfirmed' ) {
2525  $protection['permission'] = 'editsemiprotected'; // B/C
2526  }
2527  }
2528  return $protection;
2529  }
2530 
2541  protected function getTitleProtectionInternal() {
2542  // Can't protect pages in special namespaces
2543  if ( $this->mNamespace < 0 ) {
2544  return false;
2545  }
2546 
2547  // Can't protect pages that exist.
2548  if ( $this->exists() ) {
2549  return false;
2550  }
2551 
2552  if ( $this->mTitleProtection === null ) {
2553  $dbr = wfGetDB( DB_REPLICA );
2554  $commentStore = CommentStore::getStore();
2555  $commentQuery = $commentStore->getJoin( 'pt_reason' );
2556  $res = $dbr->select(
2557  [ 'protected_titles' ] + $commentQuery['tables'],
2558  [
2559  'user' => 'pt_user',
2560  'expiry' => 'pt_expiry',
2561  'permission' => 'pt_create_perm'
2562  ] + $commentQuery['fields'],
2563  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2564  __METHOD__,
2565  [],
2566  $commentQuery['joins']
2567  );
2568 
2569  // fetchRow returns false if there are no rows.
2570  $row = $dbr->fetchRow( $res );
2571  if ( $row ) {
2572  $this->mTitleProtection = [
2573  'user' => $row['user'],
2574  'expiry' => $dbr->decodeExpiry( $row['expiry'] ),
2575  'permission' => $row['permission'],
2576  'reason' => $commentStore->getComment( 'pt_reason', $row )->text,
2577  ];
2578  } else {
2579  $this->mTitleProtection = false;
2580  }
2581  }
2582  return $this->mTitleProtection;
2583  }
2584 
2588  public function deleteTitleProtection() {
2589  $dbw = wfGetDB( DB_MASTER );
2590 
2591  $dbw->delete(
2592  'protected_titles',
2593  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2594  __METHOD__
2595  );
2596  $this->mTitleProtection = false;
2597  }
2598 
2606  public function isSemiProtected( $action = 'edit' ) {
2608 
2609  $restrictions = $this->getRestrictions( $action );
2611  if ( !$restrictions || !$semi ) {
2612  // Not protected, or all protection is full protection
2613  return false;
2614  }
2615 
2616  // Remap autoconfirmed to editsemiprotected for BC
2617  foreach ( array_keys( $semi, 'autoconfirmed' ) as $key ) {
2618  $semi[$key] = 'editsemiprotected';
2619  }
2620  foreach ( array_keys( $restrictions, 'autoconfirmed' ) as $key ) {
2621  $restrictions[$key] = 'editsemiprotected';
2622  }
2623 
2624  return !array_diff( $restrictions, $semi );
2625  }
2626 
2634  public function isProtected( $action = '' ) {
2635  global $wgRestrictionLevels;
2636 
2637  $restrictionTypes = $this->getRestrictionTypes();
2638 
2639  # Special pages have inherent protection
2640  if ( $this->isSpecialPage() ) {
2641  return true;
2642  }
2643 
2644  # Check regular protection levels
2645  foreach ( $restrictionTypes as $type ) {
2646  if ( $action == $type || $action == '' ) {
2647  $r = $this->getRestrictions( $type );
2648  foreach ( $wgRestrictionLevels as $level ) {
2649  if ( in_array( $level, $r ) && $level != '' ) {
2650  return true;
2651  }
2652  }
2653  }
2654  }
2655 
2656  return false;
2657  }
2658 
2667  public function isNamespaceProtected( User $user ) {
2668  global $wgNamespaceProtection;
2669 
2670  if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
2671  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2672  foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
2673  if ( !$permissionManager->userHasRight( $user, $right ) ) {
2674  return true;
2675  }
2676  }
2677  }
2678  return false;
2679  }
2680 
2686  public function isCascadeProtected() {
2687  list( $isCascadeProtected, ) = $this->getCascadeProtectionSources( false );
2688  return $isCascadeProtected;
2689  }
2690 
2700  public function areCascadeProtectionSourcesLoaded( $getPages = true ) {
2701  return $getPages ? $this->mCascadeSources !== null : $this->mHasCascadingRestrictions !== null;
2702  }
2703 
2717  public function getCascadeProtectionSources( $getPages = true ) {
2718  $pagerestrictions = [];
2719 
2720  if ( $this->mCascadeSources !== null && $getPages ) {
2722  } elseif ( $this->mHasCascadingRestrictions !== null && !$getPages ) {
2723  return [ $this->mHasCascadingRestrictions, $pagerestrictions ];
2724  }
2725 
2726  $dbr = wfGetDB( DB_REPLICA );
2727 
2728  if ( $this->mNamespace == NS_FILE ) {
2729  $tables = [ 'imagelinks', 'page_restrictions' ];
2730  $where_clauses = [
2731  'il_to' => $this->mDbkeyform,
2732  'il_from=pr_page',
2733  'pr_cascade' => 1
2734  ];
2735  } else {
2736  $tables = [ 'templatelinks', 'page_restrictions' ];
2737  $where_clauses = [
2738  'tl_namespace' => $this->mNamespace,
2739  'tl_title' => $this->mDbkeyform,
2740  'tl_from=pr_page',
2741  'pr_cascade' => 1
2742  ];
2743  }
2744 
2745  if ( $getPages ) {
2746  $cols = [ 'pr_page', 'page_namespace', 'page_title',
2747  'pr_expiry', 'pr_type', 'pr_level' ];
2748  $where_clauses[] = 'page_id=pr_page';
2749  $tables[] = 'page';
2750  } else {
2751  $cols = [ 'pr_expiry' ];
2752  }
2753 
2754  $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__ );
2755 
2756  $sources = $getPages ? [] : false;
2757  $now = wfTimestampNow();
2758 
2759  foreach ( $res as $row ) {
2760  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2761  if ( $expiry > $now ) {
2762  if ( $getPages ) {
2763  $page_id = $row->pr_page;
2764  $page_ns = $row->page_namespace;
2765  $page_title = $row->page_title;
2766  $sources[$page_id] = self::makeTitle( $page_ns, $page_title );
2767  # Add groups needed for each restriction type if its not already there
2768  # Make sure this restriction type still exists
2769 
2770  if ( !isset( $pagerestrictions[$row->pr_type] ) ) {
2771  $pagerestrictions[$row->pr_type] = [];
2772  }
2773 
2774  if (
2775  isset( $pagerestrictions[$row->pr_type] )
2776  && !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] )
2777  ) {
2778  $pagerestrictions[$row->pr_type][] = $row->pr_level;
2779  }
2780  } else {
2781  $sources = true;
2782  }
2783  }
2784  }
2785 
2786  if ( $getPages ) {
2787  $this->mCascadeSources = $sources;
2788  $this->mCascadingRestrictions = $pagerestrictions;
2789  } else {
2790  $this->mHasCascadingRestrictions = $sources;
2791  }
2792 
2793  return [ $sources, $pagerestrictions ];
2794  }
2795 
2803  public function areRestrictionsLoaded() {
2805  }
2806 
2816  public function getRestrictions( $action ) {
2817  if ( !$this->mRestrictionsLoaded ) {
2818  $this->loadRestrictions();
2819  }
2820  return $this->mRestrictions[$action] ?? [];
2821  }
2822 
2830  public function getAllRestrictions() {
2831  if ( !$this->mRestrictionsLoaded ) {
2832  $this->loadRestrictions();
2833  }
2834  return $this->mRestrictions;
2835  }
2836 
2844  public function getRestrictionExpiry( $action ) {
2845  if ( !$this->mRestrictionsLoaded ) {
2846  $this->loadRestrictions();
2847  }
2848  return $this->mRestrictionsExpiry[$action] ?? false;
2849  }
2850 
2857  if ( !$this->mRestrictionsLoaded ) {
2858  $this->loadRestrictions();
2859  }
2860 
2862  }
2863 
2875  public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
2876  // This function will only read rows from a table that we migrated away
2877  // from before adding READ_LATEST support to loadRestrictions, so we
2878  // don't need to support reading from DB_MASTER here.
2879  $dbr = wfGetDB( DB_REPLICA );
2880 
2881  $restrictionTypes = $this->getRestrictionTypes();
2882 
2883  foreach ( $restrictionTypes as $type ) {
2884  $this->mRestrictions[$type] = [];
2885  $this->mRestrictionsExpiry[$type] = 'infinity';
2886  }
2887 
2888  $this->mCascadeRestriction = false;
2889 
2890  # Backwards-compatibility: also load the restrictions from the page record (old format).
2891  if ( $oldFashionedRestrictions !== null ) {
2892  $this->mOldRestrictions = $oldFashionedRestrictions;
2893  }
2894 
2895  if ( $this->mOldRestrictions === false ) {
2896  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2897  $linkCache->addLinkObj( $this ); # in case we already had an article ID
2898  $this->mOldRestrictions = $linkCache->getGoodLinkFieldObj( $this, 'restrictions' );
2899  }
2900 
2901  if ( $this->mOldRestrictions != '' ) {
2902  foreach ( explode( ':', trim( $this->mOldRestrictions ) ) as $restrict ) {
2903  $temp = explode( '=', trim( $restrict ) );
2904  if ( count( $temp ) == 1 ) {
2905  // old old format should be treated as edit/move restriction
2906  $this->mRestrictions['edit'] = explode( ',', trim( $temp[0] ) );
2907  $this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) );
2908  } else {
2909  $restriction = trim( $temp[1] );
2910  if ( $restriction != '' ) { // some old entries are empty
2911  $this->mRestrictions[$temp[0]] = explode( ',', $restriction );
2912  }
2913  }
2914  }
2915  }
2916 
2917  if ( count( $rows ) ) {
2918  # Current system - load second to make them override.
2919  $now = wfTimestampNow();
2920 
2921  # Cycle through all the restrictions.
2922  foreach ( $rows as $row ) {
2923  // Don't take care of restrictions types that aren't allowed
2924  if ( !in_array( $row->pr_type, $restrictionTypes ) ) {
2925  continue;
2926  }
2927 
2928  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2929 
2930  // Only apply the restrictions if they haven't expired!
2931  if ( !$expiry || $expiry > $now ) {
2932  $this->mRestrictionsExpiry[$row->pr_type] = $expiry;
2933  $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) );
2934 
2935  $this->mCascadeRestriction |= $row->pr_cascade;
2936  }
2937  }
2938  }
2939 
2940  $this->mRestrictionsLoaded = true;
2941  }
2942 
2953  public function loadRestrictions( $oldFashionedRestrictions = null, $flags = 0 ) {
2954  $readLatest = DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST );
2955  if ( $this->mRestrictionsLoaded && !$readLatest ) {
2956  return;
2957  }
2958 
2959  $id = $this->getArticleID( $flags );
2960  if ( $id ) {
2961  $fname = __METHOD__;
2962  $loadRestrictionsFromDb = function ( IDatabase $dbr ) use ( $fname, $id ) {
2963  return iterator_to_array(
2964  $dbr->select(
2965  'page_restrictions',
2966  [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
2967  [ 'pr_page' => $id ],
2968  $fname
2969  )
2970  );
2971  };
2972 
2973  if ( $readLatest ) {
2974  $dbr = wfGetDB( DB_MASTER );
2975  $rows = $loadRestrictionsFromDb( $dbr );
2976  } else {
2977  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
2978  $rows = $cache->getWithSetCallback(
2979  // Page protections always leave a new null revision
2980  $cache->makeKey( 'page-restrictions', 'v1', $id, $this->getLatestRevID() ),
2981  $cache::TTL_DAY,
2982  function ( $curValue, &$ttl, array &$setOpts ) use ( $loadRestrictionsFromDb ) {
2983  $dbr = wfGetDB( DB_REPLICA );
2984 
2985  $setOpts += Database::getCacheSetOptions( $dbr );
2986  $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
2987  if ( $lb->hasOrMadeRecentMasterChanges() ) {
2988  // @TODO: cleanup Title cache and caller assumption mess in general
2989  $ttl = WANObjectCache::TTL_UNCACHEABLE;
2990  }
2991 
2992  return $loadRestrictionsFromDb( $dbr );
2993  }
2994  );
2995  }
2996 
2997  $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
2998  } else {
2999  $title_protection = $this->getTitleProtectionInternal();
3000 
3001  if ( $title_protection ) {
3002  $now = wfTimestampNow();
3003  $expiry = wfGetDB( DB_REPLICA )->decodeExpiry( $title_protection['expiry'] );
3004 
3005  if ( !$expiry || $expiry > $now ) {
3006  // Apply the restrictions
3007  $this->mRestrictionsExpiry['create'] = $expiry;
3008  $this->mRestrictions['create'] =
3009  explode( ',', trim( $title_protection['permission'] ) );
3010  } else { // Get rid of the old restrictions
3011  $this->mTitleProtection = false;
3012  }
3013  } else {
3014  $this->mRestrictionsExpiry['create'] = 'infinity';
3015  }
3016  $this->mRestrictionsLoaded = true;
3017  }
3018  }
3019 
3024  public function flushRestrictions() {
3025  $this->mRestrictionsLoaded = false;
3026  $this->mTitleProtection = null;
3027  }
3028 
3034  static function purgeExpiredRestrictions() {
3035  if ( wfReadOnly() ) {
3036  return;
3037  }
3038 
3040  wfGetDB( DB_MASTER ),
3041  __METHOD__,
3042  function ( IDatabase $dbw, $fname ) {
3043  $config = MediaWikiServices::getInstance()->getMainConfig();
3044  $ids = $dbw->selectFieldValues(
3045  'page_restrictions',
3046  'pr_id',
3047  [ 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3048  $fname,
3049  [ 'LIMIT' => $config->get( 'UpdateRowsPerQuery' ) ] // T135470
3050  );
3051  if ( $ids ) {
3052  $dbw->delete( 'page_restrictions', [ 'pr_id' => $ids ], $fname );
3053  }
3054  }
3055  ) );
3056 
3058  wfGetDB( DB_MASTER ),
3059  __METHOD__,
3060  function ( IDatabase $dbw, $fname ) {
3061  $dbw->delete(
3062  'protected_titles',
3063  [ 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3064  $fname
3065  );
3066  }
3067  ) );
3068  }
3069 
3075  public function hasSubpages() {
3076  if (
3077  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3078  hasSubpages( $this->mNamespace )
3079  ) {
3080  # Duh
3081  return false;
3082  }
3083 
3084  # We dynamically add a member variable for the purpose of this method
3085  # alone to cache the result. There's no point in having it hanging
3086  # around uninitialized in every Title object; therefore we only add it
3087  # if needed and don't declare it statically.
3088  if ( $this->mHasSubpages === null ) {
3089  $this->mHasSubpages = false;
3090  $subpages = $this->getSubpages( 1 );
3091  if ( $subpages instanceof TitleArray ) {
3092  $this->mHasSubpages = (bool)$subpages->current();
3093  }
3094  }
3095 
3096  return $this->mHasSubpages;
3097  }
3098 
3106  public function getSubpages( $limit = -1 ) {
3107  if (
3108  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3109  hasSubpages( $this->mNamespace )
3110  ) {
3111  return [];
3112  }
3113 
3114  $dbr = wfGetDB( DB_REPLICA );
3115  $conds = [ 'page_namespace' => $this->mNamespace ];
3116  $conds[] = 'page_title ' . $dbr->buildLike( $this->mDbkeyform . '/', $dbr->anyString() );
3117  $options = [];
3118  if ( $limit > -1 ) {
3119  $options['LIMIT'] = $limit;
3120  }
3122  $dbr->select( 'page',
3123  [ 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ],
3124  $conds,
3125  __METHOD__,
3126  $options
3127  )
3128  );
3129  }
3130 
3136  public function isDeleted() {
3137  if ( $this->mNamespace < 0 ) {
3138  $n = 0;
3139  } else {
3140  $dbr = wfGetDB( DB_REPLICA );
3141 
3142  $n = $dbr->selectField( 'archive', 'COUNT(*)',
3143  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3144  __METHOD__
3145  );
3146  if ( $this->mNamespace == NS_FILE ) {
3147  $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
3148  [ 'fa_name' => $this->mDbkeyform ],
3149  __METHOD__
3150  );
3151  }
3152  }
3153  return (int)$n;
3154  }
3155 
3161  public function isDeletedQuick() {
3162  if ( $this->mNamespace < 0 ) {
3163  return false;
3164  }
3165  $dbr = wfGetDB( DB_REPLICA );
3166  $deleted = (bool)$dbr->selectField( 'archive', '1',
3167  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3168  __METHOD__
3169  );
3170  if ( !$deleted && $this->mNamespace == NS_FILE ) {
3171  $deleted = (bool)$dbr->selectField( 'filearchive', '1',
3172  [ 'fa_name' => $this->mDbkeyform ],
3173  __METHOD__
3174  );
3175  }
3176  return $deleted;
3177  }
3178 
3186  public function getArticleID( $flags = 0 ) {
3187  if ( $this->mNamespace < 0 ) {
3188  $this->mArticleID = 0;
3189 
3190  return $this->mArticleID;
3191  }
3192 
3193  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3194  if ( $flags & self::GAID_FOR_UPDATE ) {
3195  $oldUpdate = $linkCache->forUpdate( true );
3196  $linkCache->clearLink( $this );
3197  $this->mArticleID = $linkCache->addLinkObj( $this );
3198  $linkCache->forUpdate( $oldUpdate );
3199  } elseif ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3200  $this->mArticleID = (int)$this->loadFieldFromDB( 'page_id', $flags );
3201  } elseif ( $this->mArticleID == -1 ) {
3202  $this->mArticleID = $linkCache->addLinkObj( $this );
3203  }
3204 
3205  return $this->mArticleID;
3206  }
3207 
3215  public function isRedirect( $flags = 0 ) {
3216  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3217  $this->mRedirect = (bool)$this->loadFieldFromDB( 'page_is_redirect', $flags );
3218  } elseif ( $this->mRedirect === null ) {
3219  if ( $this->getArticleID( $flags ) ) {
3220  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3221  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3222  // Note that LinkCache returns null if it thinks the page does not exist;
3223  // always trust the state of LinkCache over that of this Title instance.
3224  $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
3225  } else {
3226  $this->mRedirect = false;
3227  }
3228  }
3229 
3230  return $this->mRedirect;
3231  }
3232 
3240  public function getLength( $flags = 0 ) {
3241  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3242  $this->mLength = (int)$this->loadFieldFromDB( 'page_len', $flags );
3243  } else {
3244  if ( $this->mLength != -1 ) {
3245  return $this->mLength;
3246  } elseif ( !$this->getArticleID( $flags ) ) {
3247  $this->mLength = 0;
3248  return $this->mLength;
3249  }
3250 
3251  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3252  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3253  // Note that LinkCache returns null if it thinks the page does not exist;
3254  // always trust the state of LinkCache over that of this Title instance.
3255  $this->mLength = (int)$linkCache->getGoodLinkFieldObj( $this, 'length' );
3256  }
3257 
3258  return $this->mLength;
3259  }
3260 
3267  public function getLatestRevID( $flags = 0 ) {
3268  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3269  $this->mLatestID = (int)$this->loadFieldFromDB( 'page_latest', $flags );
3270  } else {
3271  if ( $this->mLatestID !== false ) {
3272  return (int)$this->mLatestID;
3273  } elseif ( !$this->getArticleID( $flags ) ) {
3274  $this->mLatestID = 0;
3275 
3276  return $this->mLatestID;
3277  }
3278 
3279  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3280  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3281  // Note that LinkCache returns null if it thinks the page does not exist;
3282  // always trust the state of LinkCache over that of this Title instance.
3283  $this->mLatestID = (int)$linkCache->getGoodLinkFieldObj( $this, 'revision' );
3284  }
3285 
3286  return $this->mLatestID;
3287  }
3288 
3299  public function resetArticleID( $id ) {
3300  if ( $id === false ) {
3301  $this->mArticleID = -1;
3302  } else {
3303  $this->mArticleID = (int)$id;
3304  }
3305  $this->mRestrictionsLoaded = false;
3306  $this->mRestrictions = [];
3307  $this->mOldRestrictions = false;
3308  $this->mRedirect = null;
3309  $this->mLength = -1;
3310  $this->mLatestID = false;
3311  $this->mContentModel = false;
3312  $this->mForcedContentModel = false;
3313  $this->mEstimateRevisions = null;
3314  $this->mPageLanguage = null;
3315  $this->mDbPageLanguage = false;
3316  $this->mIsBigDeletion = null;
3317 
3318  MediaWikiServices::getInstance()->getLinkCache()->clearLink( $this );
3319  }
3320 
3321  public static function clearCaches() {
3322  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3323  $linkCache->clear();
3324 
3326  $titleCache->clear();
3327  }
3328 
3336  public static function capitalize( $text, $ns = NS_MAIN ) {
3337  $services = MediaWikiServices::getInstance();
3338  if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) {
3339  return $services->getContentLanguage()->ucfirst( $text );
3340  } else {
3341  return $text;
3342  }
3343  }
3344 
3361  private function secureAndSplit( $text, $defaultNamespace = null ) {
3362  if ( $defaultNamespace === null ) {
3363  $defaultNamespace = $this->mDefaultNamespace;
3364  }
3365 
3366  // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
3367  // the parsing code with Title, while avoiding massive refactoring.
3368  // @todo: get rid of secureAndSplit, refactor parsing code.
3369  // @note: getTitleParser() returns a TitleParser implementation which does not have a
3370  // splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
3372  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
3373  '@phan-var MediaWikiTitleCodec $titleCodec';
3374  // MalformedTitleException can be thrown here
3375  $parts = $titleCodec->splitTitleString( $text, $defaultNamespace );
3376 
3377  # Fill fields
3378  $this->setFragment( '#' . $parts['fragment'] );
3379  $this->mInterwiki = $parts['interwiki'];
3380  $this->mLocalInterwiki = $parts['local_interwiki'];
3381  $this->mNamespace = $parts['namespace'];
3382  $this->mDefaultNamespace = $defaultNamespace;
3383 
3384  $this->mDbkeyform = $parts['dbkey'];
3385  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
3386  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
3387 
3388  // splitTitleString() guarantees that this title is valid.
3389  $this->mIsValid = true;
3390 
3391  # We already know that some pages won't be in the database!
3392  if ( $this->isExternal() || $this->isSpecialPage() || $this->mTextform === '' ) {
3393  $this->mArticleID = 0;
3394  }
3395  }
3396 
3409  public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3410  if ( count( $options ) > 0 ) {
3411  $db = wfGetDB( DB_MASTER );
3412  } else {
3413  $db = wfGetDB( DB_REPLICA );
3414  }
3415 
3416  $res = $db->select(
3417  [ 'page', $table ],
3418  self::getSelectFields(),
3419  [
3420  "{$prefix}_from=page_id",
3421  "{$prefix}_namespace" => $this->mNamespace,
3422  "{$prefix}_title" => $this->mDbkeyform ],
3423  __METHOD__,
3424  $options
3425  );
3426 
3427  $retVal = [];
3428  if ( $res->numRows() ) {
3429  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3430  foreach ( $res as $row ) {
3431  $titleObj = self::makeTitle( $row->page_namespace, $row->page_title );
3432  if ( $titleObj ) {
3433  $linkCache->addGoodLinkObjFromRow( $titleObj, $row );
3434  $retVal[] = $titleObj;
3435  }
3436  }
3437  }
3438  return $retVal;
3439  }
3440 
3451  public function getTemplateLinksTo( $options = [] ) {
3452  return $this->getLinksTo( $options, 'templatelinks', 'tl' );
3453  }
3454 
3467  public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3468  $id = $this->getArticleID();
3469 
3470  # If the page doesn't exist; there can't be any link from this page
3471  if ( !$id ) {
3472  return [];
3473  }
3474 
3475  $db = wfGetDB( DB_REPLICA );
3476 
3477  $blNamespace = "{$prefix}_namespace";
3478  $blTitle = "{$prefix}_title";
3479 
3480  $pageQuery = WikiPage::getQueryInfo();
3481  $res = $db->select(
3482  [ $table, 'nestpage' => $pageQuery['tables'] ],
3483  array_merge(
3484  [ $blNamespace, $blTitle ],
3485  $pageQuery['fields']
3486  ),
3487  [ "{$prefix}_from" => $id ],
3488  __METHOD__,
3489  $options,
3490  [ 'nestpage' => [
3491  'LEFT JOIN',
3492  [ "page_namespace=$blNamespace", "page_title=$blTitle" ]
3493  ] ] + $pageQuery['joins']
3494  );
3495 
3496  $retVal = [];
3497  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3498  foreach ( $res as $row ) {
3499  if ( $row->page_id ) {
3500  $titleObj = self::newFromRow( $row );
3501  } else {
3502  $titleObj = self::makeTitle( $row->$blNamespace, $row->$blTitle );
3503  $linkCache->addBadLinkObj( $titleObj );
3504  }
3505  $retVal[] = $titleObj;
3506  }
3507 
3508  return $retVal;
3509  }
3510 
3521  public function getTemplateLinksFrom( $options = [] ) {
3522  return $this->getLinksFrom( $options, 'templatelinks', 'tl' );
3523  }
3524 
3533  public function getBrokenLinksFrom() {
3534  if ( $this->getArticleID() == 0 ) {
3535  # All links from article ID 0 are false positives
3536  return [];
3537  }
3538 
3539  $dbr = wfGetDB( DB_REPLICA );
3540  $res = $dbr->select(
3541  [ 'page', 'pagelinks' ],
3542  [ 'pl_namespace', 'pl_title' ],
3543  [
3544  'pl_from' => $this->getArticleID(),
3545  'page_namespace IS NULL'
3546  ],
3547  __METHOD__, [],
3548  [
3549  'page' => [
3550  'LEFT JOIN',
3551  [ 'pl_namespace=page_namespace', 'pl_title=page_title' ]
3552  ]
3553  ]
3554  );
3555 
3556  $retVal = [];
3557  foreach ( $res as $row ) {
3558  $retVal[] = self::makeTitle( $row->pl_namespace, $row->pl_title );
3559  }
3560  return $retVal;
3561  }
3562 
3569  public function getCdnUrls() {
3570  $urls = [
3571  $this->getInternalURL(),
3572  $this->getInternalURL( 'action=history' )
3573  ];
3574 
3575  if ( $this->getPageLanguageConverter()->hasVariants() ) {
3576  $variants = $this->getPageLanguageConverter()->getVariants();
3577  foreach ( $variants as $vCode ) {
3578  $urls[] = $this->getInternalURL( $vCode );
3579  }
3580  }
3581 
3582  // If we are looking at a css/js user subpage, purge the action=raw.
3583  if ( $this->isUserJsConfigPage() ) {
3584  $urls[] = $this->getInternalURL( 'action=raw&ctype=text/javascript' );
3585  } elseif ( $this->isUserJsonConfigPage() ) {
3586  $urls[] = $this->getInternalURL( 'action=raw&ctype=application/json' );
3587  } elseif ( $this->isUserCssConfigPage() ) {
3588  $urls[] = $this->getInternalURL( 'action=raw&ctype=text/css' );
3589  }
3590 
3591  Hooks::run( 'TitleSquidURLs', [ $this, &$urls ] );
3592  return $urls;
3593  }
3594 
3598  public function purgeSquid() {
3600  new CdnCacheUpdate( $this->getCdnUrls() ),
3602  );
3603  }
3604 
3612  public function isSingleRevRedirect() {
3613  $dbw = wfGetDB( DB_MASTER );
3614  $dbw->startAtomic( __METHOD__ );
3615 
3616  $row = $dbw->selectRow(
3617  'page',
3618  self::getSelectFields(),
3619  $this->pageCond(),
3620  __METHOD__,
3621  [ 'FOR UPDATE' ]
3622  );
3623  // Update the cached fields
3624  $this->loadFromRow( $row );
3625 
3626  if ( $this->mRedirect && $this->mLatestID ) {
3627  $isSingleRevRedirect = !$dbw->selectField(
3628  'revision',
3629  '1',
3630  [ 'rev_page' => $this->mArticleID, 'rev_id != ' . (int)$this->mLatestID ],
3631  __METHOD__,
3632  [ 'FOR UPDATE' ]
3633  );
3634  } else {
3635  $isSingleRevRedirect = false;
3636  }
3637 
3638  $dbw->endAtomic( __METHOD__ );
3639 
3640  return $isSingleRevRedirect;
3641  }
3642 
3650  public function getParentCategories() {
3651  $data = [];
3652 
3653  $titleKey = $this->getArticleID();
3654 
3655  if ( $titleKey === 0 ) {
3656  return $data;
3657  }
3658 
3659  $dbr = wfGetDB( DB_REPLICA );
3660 
3661  $res = $dbr->select(
3662  'categorylinks',
3663  'cl_to',
3664  [ 'cl_from' => $titleKey ],
3665  __METHOD__
3666  );
3667 
3668  if ( $res->numRows() > 0 ) {
3669  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
3670  foreach ( $res as $row ) {
3671  // $data[] = Title::newFromText( $contLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
3672  $data[$contLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] =
3673  $this->getFullText();
3674  }
3675  }
3676  return $data;
3677  }
3678 
3685  public function getParentCategoryTree( $children = [] ) {
3686  $stack = [];
3687  $parents = $this->getParentCategories();
3688 
3689  if ( $parents ) {
3690  foreach ( $parents as $parent => $current ) {
3691  if ( array_key_exists( $parent, $children ) ) {
3692  # Circular reference
3693  $stack[$parent] = [];
3694  } else {
3695  $nt = self::newFromText( $parent );
3696  if ( $nt ) {
3697  $stack[$parent] = $nt->getParentCategoryTree( $children + [ $parent => 1 ] );
3698  }
3699  }
3700  }
3701  }
3702 
3703  return $stack;
3704  }
3705 
3712  public function pageCond() {
3713  if ( $this->mArticleID > 0 ) {
3714  // PK avoids secondary lookups in InnoDB, shouldn't hurt other DBs
3715  return [ 'page_id' => $this->mArticleID ];
3716  } else {
3717  return [ 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform ];
3718  }
3719  }
3720 
3728  private function getRelativeRevisionID( $revId, $flags, $dir ) {
3729  $rl = MediaWikiServices::getInstance()->getRevisionLookup();
3730  $rev = $rl->getRevisionById( $revId, $flags );
3731  if ( !$rev ) {
3732  return false;
3733  }
3734 
3735  $oldRev = ( $dir === 'next' )
3736  ? $rl->getNextRevision( $rev, $flags )
3737  : $rl->getPreviousRevision( $rev, $flags );
3738 
3739  return $oldRev ? $oldRev->getId() : false;
3740  }
3741 
3750  public function getPreviousRevisionID( $revId, $flags = 0 ) {
3751  return $this->getRelativeRevisionID( $revId, $flags, 'prev' );
3752  }
3753 
3762  public function getNextRevisionID( $revId, $flags = 0 ) {
3763  return $this->getRelativeRevisionID( $revId, $flags, 'next' );
3764  }
3765 
3772  public function getFirstRevision( $flags = 0 ) {
3773  $pageId = $this->getArticleID( $flags );
3774  if ( $pageId ) {
3775  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
3776  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
3778  $row = wfGetDB( $index )->selectRow(
3779  $revQuery['tables'], $revQuery['fields'],
3780  [ 'rev_page' => $pageId ],
3781  __METHOD__,
3782  array_merge(
3783  [
3784  'ORDER BY' => [ 'rev_timestamp ASC', 'rev_id ASC' ],
3785  'IGNORE INDEX' => [ 'revision' => 'rev_timestamp' ], // See T159319
3786  ],
3787  $options
3788  ),
3789  $revQuery['joins']
3790  );
3791  if ( $row ) {
3792  return new Revision( $row, 0, $this );
3793  }
3794  }
3795  return null;
3796  }
3797 
3804  public function getEarliestRevTime( $flags = 0 ) {
3805  $rev = $this->getFirstRevision( $flags );
3806  return $rev ? $rev->getTimestamp() : null;
3807  }
3808 
3814  public function isNewPage() {
3815  $dbr = wfGetDB( DB_REPLICA );
3816  return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ );
3817  }
3818 
3824  public function isBigDeletion() {
3825  global $wgDeleteRevisionsLimit;
3826 
3827  if ( !$wgDeleteRevisionsLimit ) {
3828  return false;
3829  }
3830 
3831  if ( $this->mIsBigDeletion === null ) {
3832  $dbr = wfGetDB( DB_REPLICA );
3833 
3834  $revCount = $dbr->selectRowCount(
3835  'revision',
3836  '1',
3837  [ 'rev_page' => $this->getArticleID() ],
3838  __METHOD__,
3839  [ 'LIMIT' => $wgDeleteRevisionsLimit + 1 ]
3840  );
3841 
3842  $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit;
3843  }
3844 
3845  return $this->mIsBigDeletion;
3846  }
3847 
3853  public function estimateRevisionCount() {
3854  if ( !$this->exists() ) {
3855  return 0;
3856  }
3857 
3858  if ( $this->mEstimateRevisions === null ) {
3859  $dbr = wfGetDB( DB_REPLICA );
3860  $this->mEstimateRevisions = $dbr->estimateRowCount( 'revision', '*',
3861  [ 'rev_page' => $this->getArticleID() ], __METHOD__ );
3862  }
3863 
3865  }
3866 
3878  public function countRevisionsBetween( $old, $new, $max = null ) {
3879  if ( !( $old instanceof Revision ) ) {
3880  $old = Revision::newFromTitle( $this, (int)$old );
3881  }
3882  if ( !( $new instanceof Revision ) ) {
3883  $new = Revision::newFromTitle( $this, (int)$new );
3884  }
3885  if ( !$old || !$new ) {
3886  return 0; // nothing to compare
3887  }
3888  return MediaWikiServices::getInstance()
3889  ->getRevisionStore()
3890  ->countRevisionsBetween(
3891  $this->getArticleID(),
3892  $old->getRevisionRecord(),
3893  $new->getRevisionRecord(),
3894  $max
3895  );
3896  }
3897 
3915  public function getAuthorsBetween( $old, $new, $limit, $options = [] ) {
3916  if ( !( $old instanceof Revision ) ) {
3917  $old = Revision::newFromTitle( $this, (int)$old );
3918  }
3919  if ( !( $new instanceof Revision ) ) {
3920  $new = Revision::newFromTitle( $this, (int)$new );
3921  }
3922  try {
3923  $users = MediaWikiServices::getInstance()
3924  ->getRevisionStore()
3925  ->getAuthorsBetween(
3926  $this->getArticleID(),
3927  $old->getRevisionRecord(),
3928  $new->getRevisionRecord(),
3929  null,
3930  $limit,
3931  $options
3932  );
3933  return array_map( function ( UserIdentity $user ) {
3934  return $user->getName();
3935  }, $users );
3936  } catch ( InvalidArgumentException $e ) {
3937  return null; // b/c
3938  }
3939  }
3940 
3957  public function countAuthorsBetween( $old, $new, $limit, $options = [] ) {
3958  $authors = $this->getAuthorsBetween( $old, $new, $limit, $options );
3959  return $authors ? count( $authors ) : 0;
3960  }
3961 
3968  public function equals( LinkTarget $title ) {
3969  // Note: === is necessary for proper matching of number-like titles.
3970  return $this->mInterwiki === $title->getInterwiki()
3971  && $this->mNamespace == $title->getNamespace()
3972  && $this->mDbkeyform === $title->getDBkey();
3973  }
3974 
3981  public function isSubpageOf( Title $title ) {
3982  return $this->mInterwiki === $title->mInterwiki
3983  && $this->mNamespace == $title->mNamespace
3984  && strpos( $this->mDbkeyform, $title->mDbkeyform . '/' ) === 0;
3985  }
3986 
3997  public function exists( $flags = 0 ) {
3998  $exists = $this->getArticleID( $flags ) != 0;
3999  Hooks::run( 'TitleExists', [ $this, &$exists ] );
4000  return $exists;
4001  }
4002 
4019  public function isAlwaysKnown() {
4020  $isKnown = null;
4021 
4032  Hooks::run( 'TitleIsAlwaysKnown', [ $this, &$isKnown ] );
4033 
4034  if ( $isKnown !== null ) {
4035  return $isKnown;
4036  }
4037 
4038  if ( $this->isExternal() ) {
4039  return true; // any interwiki link might be viewable, for all we know
4040  }
4041 
4042  $services = MediaWikiServices::getInstance();
4043  switch ( $this->mNamespace ) {
4044  case NS_MEDIA:
4045  case NS_FILE:
4046  // file exists, possibly in a foreign repo
4047  return (bool)$services->getRepoGroup()->findFile( $this );
4048  case NS_SPECIAL:
4049  // valid special page
4050  return $services->getSpecialPageFactory()->exists( $this->mDbkeyform );
4051  case NS_MAIN:
4052  // selflink, possibly with fragment
4053  return $this->mDbkeyform == '';
4054  case NS_MEDIAWIKI:
4055  // known system message
4056  return $this->hasSourceText() !== false;
4057  default:
4058  return false;
4059  }
4060  }
4061 
4073  public function isKnown() {
4074  return $this->isAlwaysKnown() || $this->exists();
4075  }
4076 
4082  public function hasSourceText() {
4083  if ( $this->exists() ) {
4084  return true;
4085  }
4086 
4087  if ( $this->mNamespace == NS_MEDIAWIKI ) {
4088  // If the page doesn't exist but is a known system message, default
4089  // message content will be displayed, same for language subpages-
4090  // Use always content language to avoid loading hundreds of languages
4091  // to get the link color.
4092  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
4093  list( $name, ) = MessageCache::singleton()->figureMessage(
4094  $contLang->lcfirst( $this->getText() )
4095  );
4096  $message = wfMessage( $name )->inLanguage( $contLang )->useDatabase( false );
4097  return $message->exists();
4098  }
4099 
4100  return false;
4101  }
4102 
4140  public function getDefaultMessageText() {
4141  if ( $this->mNamespace != NS_MEDIAWIKI ) { // Just in case
4142  return false;
4143  }
4144 
4145  list( $name, $lang ) = MessageCache::singleton()->figureMessage(
4146  MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $this->getText() )
4147  );
4148  $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
4149 
4150  if ( $message->exists() ) {
4151  return $message->plain();
4152  } else {
4153  return false;
4154  }
4155  }
4156 
4163  public function invalidateCache( $purgeTime = null ) {
4164  if ( wfReadOnly() ) {
4165  return false;
4166  }
4167  if ( $this->mArticleID === 0 ) {
4168  // avoid gap locking if we know it's not there
4169  return true;
4170  }
4171 
4172  $conds = $this->pageCond();
4174  new AutoCommitUpdate(
4175  wfGetDB( DB_MASTER ),
4176  __METHOD__,
4177  function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) {
4178  $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
4179  $dbw->update(
4180  'page',
4181  [ 'page_touched' => $dbTimestamp ],
4182  $conds + [ 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ],
4183  $fname
4184  );
4185 
4186  MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $this );
4187 
4189  $this, null, null, $dbw->getDomainID() );
4190  }
4191  ),
4193  );
4194 
4195  return true;
4196  }
4197 
4203  public function touchLinks() {
4204  $jobs = [];
4206  $this,
4207  'pagelinks',
4208  [ 'causeAction' => 'page-touch' ]
4209  );
4210  if ( $this->mNamespace == NS_CATEGORY ) {
4212  $this,
4213  'categorylinks',
4214  [ 'causeAction' => 'category-touch' ]
4215  );
4216  }
4217 
4218  JobQueueGroup::singleton()->lazyPush( $jobs );
4219  }
4220 
4227  public function getTouched( $db = null ) {
4228  if ( $db === null ) {
4229  $db = wfGetDB( DB_REPLICA );
4230  }
4231  $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ );
4232  return $touched;
4233  }
4234 
4241  public function getNotificationTimestamp( $user = null ) {
4242  // Assume current user if none given
4243  if ( !$user ) {
4244  wfDeprecated( __METHOD__ . ' without passing a $user parameter', '1.35' );
4245  global $wgUser;
4246  $user = $wgUser;
4247  }
4248  // Check cache first
4249  $uid = $user->getId();
4250  if ( !$uid ) {
4251  return false;
4252  }
4253  // avoid isset here, as it'll return false for null entries
4254  if ( array_key_exists( $uid, $this->mNotificationTimestamp ) ) {
4255  return $this->mNotificationTimestamp[$uid];
4256  }
4257  // Don't cache too much!
4258  if ( count( $this->mNotificationTimestamp ) >= self::CACHE_MAX ) {
4259  $this->mNotificationTimestamp = [];
4260  }
4261 
4262  $store = MediaWikiServices::getInstance()->getWatchedItemStore();
4263  $watchedItem = $store->getWatchedItem( $user, $this );
4264  if ( $watchedItem ) {
4265  $this->mNotificationTimestamp[$uid] = $watchedItem->getNotificationTimestamp();
4266  } else {
4267  $this->mNotificationTimestamp[$uid] = false;
4268  }
4269 
4270  return $this->mNotificationTimestamp[$uid];
4271  }
4272 
4279  public function getNamespaceKey( $prepend = 'nstab-' ) {
4280  // Gets the subject namespace of this title
4281  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
4282  $subjectNS = $nsInfo->getSubject( $this->mNamespace );
4283  // Prefer canonical namespace name for HTML IDs
4284  $namespaceKey = $nsInfo->getCanonicalName( $subjectNS );
4285  if ( $namespaceKey === false ) {
4286  // Fallback to localised text
4287  $namespaceKey = $this->getSubjectNsText();
4288  }
4289  // Makes namespace key lowercase
4290  $namespaceKey = MediaWikiServices::getInstance()->getContentLanguage()->lc( $namespaceKey );
4291  // Uses main
4292  if ( $namespaceKey == '' ) {
4293  $namespaceKey = 'main';
4294  }
4295  // Changes file to image for backwards compatibility
4296  if ( $namespaceKey == 'file' ) {
4297  $namespaceKey = 'image';
4298  }
4299  return $prepend . $namespaceKey;
4300  }
4301 
4308  public function getRedirectsHere( $ns = null ) {
4309  $redirs = [];
4310 
4311  $dbr = wfGetDB( DB_REPLICA );
4312  $where = [
4313  'rd_namespace' => $this->mNamespace,
4314  'rd_title' => $this->mDbkeyform,
4315  'rd_from = page_id'
4316  ];
4317  if ( $this->isExternal() ) {
4318  $where['rd_interwiki'] = $this->mInterwiki;
4319  } else {
4320  $where[] = 'rd_interwiki = ' . $dbr->addQuotes( '' ) . ' OR rd_interwiki IS NULL';
4321  }
4322  if ( $ns !== null ) {
4323  $where['page_namespace'] = $ns;
4324  }
4325 
4326  $res = $dbr->select(
4327  [ 'redirect', 'page' ],
4328  [ 'page_namespace', 'page_title' ],
4329  $where,
4330  __METHOD__
4331  );
4332 
4333  foreach ( $res as $row ) {
4334  $redirs[] = self::newFromRow( $row );
4335  }
4336  return $redirs;
4337  }
4338 
4344  public function isValidRedirectTarget() {
4346 
4347  if ( $this->isSpecialPage() ) {
4348  // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
4349  if ( $this->isSpecial( 'Userlogout' ) ) {
4350  return false;
4351  }
4352 
4353  foreach ( $wgInvalidRedirectTargets as $target ) {
4354  if ( $this->isSpecial( $target ) ) {
4355  return false;
4356  }
4357  }
4358  }
4359 
4360  return true;
4361  }
4362 
4368  public function getBacklinkCache() {
4369  return BacklinkCache::get( $this );
4370  }
4371 
4377  public function canUseNoindex() {
4379 
4380  $bannedNamespaces = $wgExemptFromUserRobotsControl ??
4381  MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
4382 
4383  return !in_array( $this->mNamespace, $bannedNamespaces );
4384  }
4385 
4396  public function getCategorySortkey( $prefix = '' ) {
4397  $unprefixed = $this->getText();
4398 
4399  // Anything that uses this hook should only depend
4400  // on the Title object passed in, and should probably
4401  // tell the users to run updateCollations.php --force
4402  // in order to re-sort existing category relations.
4403  Hooks::run( 'GetDefaultSortkey', [ $this, &$unprefixed ] );
4404  if ( $prefix !== '' ) {
4405  # Separate with a line feed, so the unprefixed part is only used as
4406  # a tiebreaker when two pages have the exact same prefix.
4407  # In UCA, tab is the only character that can sort above LF
4408  # so we strip both of them from the original prefix.
4409  $prefix = strtr( $prefix, "\n\t", ' ' );
4410  return "$prefix\n$unprefixed";
4411  }
4412  return $unprefixed;
4413  }
4414 
4422  private function getDbPageLanguageCode() {
4423  global $wgPageLanguageUseDB;
4424 
4425  // check, if the page language could be saved in the database, and if so and
4426  // the value is not requested already, lookup the page language using LinkCache
4427  if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) {
4428  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
4429  $linkCache->addLinkObj( $this );
4430  $this->mDbPageLanguage = $linkCache->getGoodLinkFieldObj( $this, 'lang' );
4431  }
4432 
4433  return $this->mDbPageLanguage;
4434  }
4435 
4444  public function getPageLanguage() {
4445  global $wgLang, $wgLanguageCode;
4446  if ( $this->isSpecialPage() ) {
4447  // special pages are in the user language
4448  return $wgLang;
4449  }
4450 
4451  // Checking if DB language is set
4452  $dbPageLanguage = $this->getDbPageLanguageCode();
4453  if ( $dbPageLanguage ) {
4454  return wfGetLangObj( $dbPageLanguage );
4455  }
4456 
4457  if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) {
4458  // Note that this may depend on user settings, so the cache should
4459  // be only per-request.
4460  // NOTE: ContentHandler::getPageLanguage() may need to load the
4461  // content to determine the page language!
4462  // Checking $wgLanguageCode hasn't changed for the benefit of unit
4463  // tests.
4464  $contentHandler = MediaWikiServices::getInstance()
4465  ->getContentHandlerFactory()
4466  ->getContentHandler( $this->getContentModel() );
4467  $langObj = $contentHandler->getPageLanguage( $this );
4468  $this->mPageLanguage = [ $langObj->getCode(), $wgLanguageCode ];
4469  } else {
4470  $langObj = MediaWikiServices::getInstance()->getLanguageFactory()
4471  ->getLanguage( $this->mPageLanguage[0] );
4472  }
4473 
4474  return $langObj;
4475  }
4476 
4485  public function getPageViewLanguage() {
4486  global $wgLang;
4487 
4488  if ( $this->isSpecialPage() ) {
4489  // If the user chooses a variant, the content is actually
4490  // in a language whose code is the variant code.
4491  $variant = $this->getLanguageConverter( $wgLang )->getPreferredVariant();
4492  if ( $wgLang->getCode() !== $variant ) {
4493  return MediaWikiServices::getInstance()->getLanguageFactory()
4494  ->getLanguage( $variant );
4495  }
4496 
4497  return $wgLang;
4498  }
4499 
4500  // Checking if DB language is set
4501  $dbPageLanguage = $this->getDbPageLanguageCode();
4502  if ( $dbPageLanguage ) {
4503  $pageLang = wfGetLangObj( $dbPageLanguage );
4504  $variant = $this->getLanguageConverter( $pageLang )->getPreferredVariant();
4505  if ( $pageLang->getCode() !== $variant ) {
4506  $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()
4507  ->getLanguage( $variant );
4508  }
4509 
4510  return $pageLang;
4511  }
4512 
4513  // @note Can't be cached persistently, depends on user settings.
4514  // @note ContentHandler::getPageViewLanguage() may need to load the
4515  // content to determine the page language!
4516  $contentHandler = MediaWikiServices::getInstance()
4517  ->getContentHandlerFactory()
4518  ->getContentHandler( $this->getContentModel() );
4519  $pageLang = $contentHandler->getPageViewLanguage( $this );
4520  return $pageLang;
4521  }
4522 
4533  public function getEditNotices( $oldid = 0 ) {
4534  $notices = [];
4535 
4536  // Optional notice for the entire namespace
4537  $editnotice_ns = 'editnotice-' . $this->mNamespace;
4538  $msg = wfMessage( $editnotice_ns );
4539  if ( $msg->exists() ) {
4540  $html = $msg->parseAsBlock();
4541  // Edit notices may have complex logic, but output nothing (T91715)
4542  if ( trim( $html ) !== '' ) {
4543  $notices[$editnotice_ns] = Html::rawElement(
4544  'div',
4545  [ 'class' => [
4546  'mw-editnotice',
4547  'mw-editnotice-namespace',
4548  Sanitizer::escapeClass( "mw-$editnotice_ns" )
4549  ] ],
4550  $html
4551  );
4552  }
4553  }
4554 
4555  if (
4556  MediaWikiServices::getInstance()->getNamespaceInfo()->
4557  hasSubpages( $this->mNamespace )
4558  ) {
4559  // Optional notice for page itself and any parent page
4560  $editnotice_base = $editnotice_ns;
4561  foreach ( explode( '/', $this->mDbkeyform ) as $part ) {
4562  $editnotice_base .= '-' . $part;
4563  $msg = wfMessage( $editnotice_base );
4564  if ( $msg->exists() ) {
4565  $html = $msg->parseAsBlock();
4566  if ( trim( $html ) !== '' ) {
4567  $notices[$editnotice_base] = Html::rawElement(
4568  'div',
4569  [ 'class' => [
4570  'mw-editnotice',
4571  'mw-editnotice-base',
4572  Sanitizer::escapeClass( "mw-$editnotice_base" )
4573  ] ],
4574  $html
4575  );
4576  }
4577  }
4578  }
4579  } else {
4580  // Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
4581  $editnoticeText = $editnotice_ns . '-' . strtr( $this->mDbkeyform, '/', '-' );
4582  $msg = wfMessage( $editnoticeText );
4583  if ( $msg->exists() ) {
4584  $html = $msg->parseAsBlock();
4585  if ( trim( $html ) !== '' ) {
4586  $notices[$editnoticeText] = Html::rawElement(
4587  'div',
4588  [ 'class' => [
4589  'mw-editnotice',
4590  'mw-editnotice-page',
4591  Sanitizer::escapeClass( "mw-$editnoticeText" )
4592  ] ],
4593  $html
4594  );
4595  }
4596  }
4597  }
4598 
4599  Hooks::run( 'TitleGetEditNotices', [ $this, $oldid, &$notices ] );
4600  return $notices;
4601  }
4602 
4608  private function loadFieldFromDB( $field, $flags ) {
4609  if ( !in_array( $field, self::getSelectFields(), true ) ) {
4610  return false; // field does not exist
4611  }
4612 
4613  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
4614  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
4615 
4616  return wfGetDB( $index )->selectField(
4617  'page',
4618  $field,
4619  $this->pageCond(),
4620  __METHOD__,
4621  $options
4622  );
4623  }
4624 
4628  public function __sleep() {
4629  return [
4630  'mNamespace',
4631  'mDbkeyform',
4632  'mFragment',
4633  'mInterwiki',
4634  'mLocalInterwiki',
4635  'mDefaultNamespace',
4636  ];
4637  }
4638 
4639  public function __wakeup() {
4640  $this->mArticleID = ( $this->mNamespace >= 0 ) ? -1 : 0;
4641  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
4642  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
4643  }
4644 
4645 }
Title\$mLocalInterwiki
bool $mLocalInterwiki
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:87
Title\$mRestrictions
array $mRestrictions
Array of groups allowed to edit this article.
Definition: Title.php:113
Title\canHaveTalkPage
canHaveTalkPage()
Can this title have a corresponding talk page?
Definition: Title.php:1193
Title\getTitleProtection
getTitleProtection()
Is this title subject to title protection? Title protection is the one applied against creation of su...
Definition: Title.php:2518
Title\canUseNoindex
canUseNoindex()
Whether the magic words INDEX and NOINDEX function for this page.
Definition: Title.php:4377
Title\getLocalURL
getLocalURL( $query='', $query2=false)
Get a URL with no fragment or server name (relative URL) from a Title object.
Definition: Title.php:2190
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:219
Title\isSemiProtected
isSemiProtected( $action='edit')
Is this page "semi-protected" - the only protection levels are listed in $wgSemiprotectedRestrictionL...
Definition: Title.php:2606
Title\$mHasCascadingRestrictions
bool $mHasCascadingRestrictions
Are cascading restrictions in effect on this page?
Definition: Title.php:133
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:49
Title\isNamespaceProtected
isNamespaceProtected(User $user)
Determines if $user is unable to edit this page because it has been protected by $wgNamespaceProtecti...
Definition: Title.php:2667
Title\getTalkNsText
getTalkNsText()
Get the namespace text of the talk page.
Definition: Title.php:1176
Title\getSubpageText
getSubpageText()
Get the lowest-level subpage name, i.e.
Definition: Title.php:2015
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:335
Title\isBigDeletion
isBigDeletion()
Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit.
Definition: Title.php:3824
Title\getNextRevisionID
getNextRevisionID( $revId, $flags=0)
Get the revision ID of the next revision.
Definition: Title.php:3762
PROTO_CANONICAL
const PROTO_CANONICAL
Definition: Defines.php:203
Title\areCascadeProtectionSourcesLoaded
areCascadeProtectionSourcesLoaded( $getPages=true)
Determines whether cascading protection sources have already been loaded from the database.
Definition: Title.php:2700
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:2473
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:829
Title\getInternalURL
getInternalURL( $query='', $query2=false)
Get the URL form for an internal link.
Definition: Title.php:2321
$wgActionPaths
$wgActionPaths
Definition: img_auth.php:49
Title\getFragment
getFragment()
Get the Title fragment (i.e.
Definition: Title.php:1760
$wgExemptFromUserRobotsControl
$wgExemptFromUserRobotsControl
An array of namespace keys in which the INDEX/__NOINDEX__ magic words will not function,...
Definition: DefaultSettings.php:8055
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:1652
Title\inNamespace
inNamespace( $ns)
Returns true if the title is inside the specified namespace.
Definition: Title.php:1314
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:107
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:1376
Title\wasLocalInterwiki
wasLocalInterwiki()
Was this a local interwiki link?
Definition: Title.php:951
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:134
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:35
Title\inNamespaces
inNamespaces(... $namespaces)
Returns true if the title is inside one of the specified namespaces.
Definition: Title.php:1326
Title\isWikitextPage
isWikitextPage()
Does that page contain wikitext, or it is JS, CSS or whatever?
Definition: Title.php:1433
Title\isUserCssConfigPage
isUserCssConfigPage()
Is this a CSS "config" sub-page of a user page?
Definition: Title.php:1495
Title\getBacklinkCache
getBacklinkCache()
Get a backlink cache object.
Definition: Title.php:4368
Title\getPartialURL
getPartialURL()
Get the URL-encoded form of the main part.
Definition: Title.php:1023
$wgLegalTitleChars
$wgLegalTitleChars
Allowed title characters – regex character class Don't change this unless you know what you're doing.
Definition: DefaultSettings.php:3947
Title\clearCaches
static clearCaches()
Text form (spaces not underscores) of the main part.
Definition: Title.php:3321
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:991
Title\estimateRevisionCount
estimateRevisionCount()
Get the approximate revision count of this page.
Definition: Title.php:3853
Title\countRevisionsBetween
countRevisionsBetween( $old, $new, $max=null)
Get the number of revisions between the given revision.
Definition: Title.php:3878
Title\getPrefixedDBkey
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1859
Title\getDbPageLanguageCode
getDbPageLanguageCode()
Returns the page language code saved in the database, if $wgPageLanguageUseDB is set to true in Local...
Definition: Title.php:4422
Title\getSkinFromConfigSubpage
getSkinFromConfigSubpage()
Trim down a .css, .json, or .js subpage title to get the corresponding skin name.
Definition: Title.php:1479
$wgScript
$wgScript
The URL path to index.php.
Definition: DefaultSettings.php:185
Title\$mHasSubpages
bool $mHasSubpages
Whether a page has any subpages.
Definition: Title.php:172
Title\getTalkPage
getTalkPage()
Get a Title object associated with the talk page of this article.
Definition: Title.php:1622
Title\NEW_CLONE
const NEW_CLONE
Flag for use with factory methods like newFromLinkTarget() that have a $forceClone parameter.
Definition: Title.php:67
Title\getNotificationTimestamp
getNotificationTimestamp( $user=null)
Get the timestamp when this page was updated since the user last saw it.
Definition: Title.php:4241
Title\getParentCategoryTree
getParentCategoryTree( $children=[])
Get a tree of parent categories.
Definition: Title.php:3685
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:217
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:2083
Title\fixSpecialName
fixSpecialName()
If the Title refers to a special page alias which is not the local default, resolve the alias,...
Definition: Title.php:1290
Title\getInterwikiLookup
static getInterwikiLookup()
B/C kludge: provide an InterwikiLookup for use by Title.
Definition: Title.php:230
Title\isUserJsConfigPage
isUserJsConfigPage()
Is this a JS "config" sub-page of a user page?
Definition: Title.php:1523
Title\touchLinks
touchLinks()
Update page_touched timestamps and send CDN purge messages for pages linking to this title.
Definition: Title.php:4203
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:309
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1871
Title\getTransWikiID
getTransWikiID()
Returns the DB name of the distant wiki which owns the object.
Definition: Title.php:974
DeferredUpdates\addUpdate
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred list to be run later by execute()
Definition: DeferredUpdates.php:85
Title\getArticleID
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:3186
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:2296
Title\$mTitleValue
TitleValue null $mTitleValue
A corresponding TitleValue object.
Definition: Title.php:183
Title\quickUserCan
quickUserCan( $action, $user=null)
Can $user perform $action on this page? This skips potentially expensive cascading permission checks ...
Definition: Title.php:2388
NS_FILE
const NS_FILE
Definition: Defines.php:66
Title\isTalkPage
isTalkPage()
Is this a talk page of some sort?
Definition: Title.php:1606
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1171
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1265
$s
$s
Definition: mergeMessageFileList.php:185
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:83
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1079
Title\isExternal
isExternal()
Is this Title interwiki?
Definition: Title.php:931
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:2875
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:664
Title\getDefaultMessageText
getDefaultMessageText()
Get the default (plain) message contents for an page that overrides an interface message key.
Definition: Title.php:4140
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:215
Title\hasSourceText
hasSourceText()
Does this page have source text?
Definition: Title.php:4082
Title\loadFromRow
loadFromRow( $row)
Load Title object fields from a DB row.
Definition: Title.php:546
Title\setFragment
setFragment( $fragment)
Set the fragment for this title.
Definition: Title.php:1806
$res
$res
Definition: testCompression.php:54
IDBAccessObject
Interface for database access objects.
Definition: IDBAccessObject.php:55
Title\equals
equals(LinkTarget $title)
Compare with another title.
Definition: Title.php:3968
$wgContentHandlerUseDB
$wgContentHandlerUseDB
Set to false to disable use of the database fields introduced by the ContentHandler facility.
Definition: DefaultSettings.php:8616
Title\$mIsBigDeletion
bool null $mIsBigDeletion
Would deleting this page be a big deletion?
Definition: Title.php:186
Title\convertByteClassToUnicodeClass
static convertByteClassToUnicodeClass( $byteClass)
Utility method for converting a character sequence from bytes to Unicode.
Definition: Title.php:724
Title\__wakeup
__wakeup()
Text form (spaces not underscores) of the main part.
Definition: Title.php:4639
$revQuery
$revQuery
Definition: testCompression.php:53
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
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:3650
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:3409
Title\$mContentModel
bool string $mContentModel
ID of the page's content model, i.e.
Definition: Title.php:101
Title\getPageLanguageConverter
getPageLanguageConverter()
Shorthand for getting a Language Converter for page's language.
Definition: Title.php:206
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:1537
MessageLocalizer
Interface for localizing messages in MediaWiki.
Definition: MessageLocalizer.php:27
Title\getNsText
getNsText()
Get the namespace text.
Definition: Title.php:1140
Title\$mDbkeyform
string $mDbkeyform
Main part with underscores.
Definition: Title.php:81
Title\$mUrlform
string $mUrlform
URL-encoded form of the main part.
Definition: Title.php:79
$dbr
$dbr
Definition: testCompression.php:52
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:3467
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:121
PathRouter\getActionPaths
static getActionPaths(array $actionPaths, $articlePath)
Definition: PathRouter.php:430
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:439
Revision
Definition: Revision.php:40
NS_MAIN
const NS_MAIN
Definition: Defines.php:60
Title\loadFieldFromDB
loadFieldFromDB( $field, $flags)
Definition: Title.php:4608
Title\isCascadeProtected
isCascadeProtected()
Cascading protection: Return true if cascading restrictions apply to this page, false if not.
Definition: Title.php:2686
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:138
Title\getCdnUrls
getCdnUrls()
Get a list of URLs to purge from the CDN cache when this page changes.
Definition: Title.php:3569
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:49
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:1724
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:1451
Title\isUserJsonConfigPage
isUserJsonConfigPage()
Is this a JSON "config" sub-page of a user page?
Definition: Title.php:1509
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:188
$wgRawHtmlMessages
string[] $wgRawHtmlMessages
List of messages which might contain raw HTML.
Definition: DefaultSettings.php:8838
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:1032
Revision\getQueryInfo
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
Definition: Revision.php:315
Title\nameOf
static nameOf( $id)
Get the prefixed DB key associated with an ID.
Definition: Title.php:689
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:180
Title\isSpecial
isSpecial( $name)
Returns true if this title resolves to the named special page.
Definition: Title.php:1272
MWException
MediaWiki exception.
Definition: MWException.php:26
Title\getTitleFormatter
static getTitleFormatter()
B/C kludge: provide a TitleParser for use by Title.
Definition: Title.php:218
Title\isMainPage
isMainPage()
Is this the mainpage?
Definition: Title.php:1400
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1045
Title\getSubpage
getSubpage( $text)
Get the title for a subpage of the current page.
Definition: Title.php:2039
Title\getBaseTitle
getBaseTitle()
Get the base page name title, i.e.
Definition: Title.php:1995
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1053
BacklinkCache\get
static get(Title $title)
Create a new BacklinkCache or reuse any existing one.
Definition: BacklinkCache.php:113
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:534
Title\isConversionTable
isConversionTable()
Is this a conversion table for the LanguageConverter?
Definition: Title.php:1421
Title\isProtected
isProtected( $action='')
Does the title correspond to a protected article?
Definition: Title.php:2634
Title\flushRestrictions
flushRestrictions()
Flush the protection cache in this object and force reload from the database.
Definition: Title.php:3024
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2564
Title\getCategorySortkey
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:4396
Title\getInterwiki
getInterwiki()
Get the interwiki prefix.
Definition: Title.php:942
Title\isSiteJsonConfigPage
isSiteJsonConfigPage()
Is this a sitewide JSON "config" page?
Definition: Title.php:1555
$matches
$matches
Definition: NoLocalSettings.php:24
Title\isValidRedirectTarget
isValidRedirectTarget()
Check if this Title is a valid redirect target.
Definition: Title.php:4344
Title\deleteTitleProtection
deleteTitleProtection()
Remove any title protection due to page existing.
Definition: Title.php:2588
Title\__construct
__construct()
Definition: Title.php:237
$wgLang
$wgLang
Definition: Setup.php:852
MediaWiki\Interwiki\InterwikiLookup
Service interface for looking up Interwiki records.
Definition: InterwikiLookup.php:32
Title\userCan
userCan( $action, $user=null, $rigor=PermissionManager::RIGOR_SECURE)
Can $user perform $action on this page?
Definition: Title.php:2413
Title\getBrokenLinksFrom
getBrokenLinksFrom()
Get an array of Title objects referring to non-existent articles linked from this page.
Definition: Title.php:3533
Title\isUserConfigPage
isUserConfigPage()
Is this a "config" (.css, .json, or .js) sub-page of a user page?
Definition: Title.php:1465
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:202
Title\getLanguageConverter
getLanguageConverter( $language)
Shorthand for getting a Language Converter for specific language.
Definition: Title.php:197
Title\$mCascadeSources
array $mCascadeSources
Where are the cascading restrictions coming from on this page?
Definition: Title.php:136
Title\getSubjectPage
getSubjectPage()
Get a title object associated with the subject page of this talk page.
Definition: Title.php:1667
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:1215
Title\loadRestrictions
loadRestrictions( $oldFashionedRestrictions=null, $flags=0)
Load restrictions from the page_restrictions table.
Definition: Title.php:2953
$wgInvalidRedirectTargets
$wgInvalidRedirectTargets
Array of invalid page redirect targets.
Definition: DefaultSettings.php:4131
Title\getFullText
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
Definition: Title.php:1895
Title\getTitleCache
static getTitleCache()
Definition: Title.php:443
Title\hasFragment
hasFragment()
Check if a Title fragment is set.
Definition: Title.php:1770
Title\getRedirectsHere
getRedirectsHere( $ns=null)
Get all extant redirects to this Title.
Definition: Title.php:4308
MediaWiki\User\UserIdentity\getName
getName()
$title
$title
Definition: testCompression.php:36
Title\warnIfPageCannotExist
warnIfPageCannotExist(Title $title, $method)
Definition: Title.php:1693
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:602
Title\$mInterwiki
string $mInterwiki
Interwiki prefix.
Definition: Title.php:85
Title\$mCascadeRestriction
bool $mCascadeRestriction
Cascade restrictions on this page to included templates and images?
Definition: Title.php:124
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1902
Title\getRootText
getRootText()
Get the root page name text without a namespace, i.e.
Definition: Title.php:1918
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:74
$wgNamespaceProtection
$wgNamespaceProtection
Set the minimum permissions required to edit pages in each namespace.
Definition: DefaultSettings.php:5364
Title\canExist
canExist()
Can this title represent a page in the wiki's database?
Definition: Title.php:1207
$wgDeleteRevisionsLimit
$wgDeleteRevisionsLimit
Optional to restrict deletion of pages with higher revision counts to users with the 'bigdelete' perm...
Definition: DefaultSettings.php:5541
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:149
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:913
Title\__sleep
__sleep()
Definition: Title.php:4628
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:2345
MessageCache\singleton
static singleton()
Get the singleton instance of this class.
Definition: MessageCache.php:127
Title\$mRedirect
null $mRedirect
Is the article at this title a redirect?
Definition: Title.php:166
Title\createFragmentTarget
createFragmentTarget( $fragment)
Creates a new Title for a different fragment of the same page.
Definition: Title.php:1817
Title\$mNamespace
int $mNamespace
Namespace index, i.e.
Definition: Title.php:83
Title\getDefaultNamespace
getDefaultNamespace()
Get the default namespace index, for when there is no namespace.
Definition: Title.php:1749
ResourceLoaderWikiModule\invalidateModuleCache
static invalidateModuleCache(Title $title, ?Revision $old, ?Revision $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:540
Title\newFromTextThrow
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:370
$wgPageLanguageUseDB
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
Definition: DefaultSettings.php:8704
Title\$mPageLanguage
array null $mPageLanguage
The (string) language code of the page's language and content code.
Definition: Title.php:175
Title\isValid
isValid()
Returns true if the title is a valid link target, and that it has been properly normalized.
Definition: Title.php:877
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:2064
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:628
Title\__toString
__toString()
Return a string representation of this title.
Definition: Title.php:1885
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:48
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:3451
$wgMainPageIsDomainRoot
bool $wgMainPageIsDomainRoot
Option to whether serve the main page as the domain root.
Definition: DefaultSettings.php:9109
Title\areRestrictionsCascading
areRestrictionsCascading()
Returns cascading restrictions for the current article.
Definition: Title.php:2856
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:48
CdnCacheUpdate
Handles purging the appropriate CDN objects given a list of URLs or Title instances.
Definition: CdnCacheUpdate.php:30
Title\getLatestRevID
getLatestRevID( $flags=0)
What is the page_latest field for this page?
Definition: Title.php:3267
Title\areRestrictionsLoaded
areRestrictionsLoaded()
Accessor for mRestrictionsLoaded.
Definition: Title.php:2803
Title\getSubpages
getSubpages( $limit=-1)
Get all subpages of this page.
Definition: Title.php:3106
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:3612
$wgServer
$wgServer
URL of the server.
Definition: DefaultSettings.php:105
Title\GAID_FOR_UPDATE
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define().
Definition: Title.php:58
Title\getPageViewLanguage
getPageViewLanguage()
Get the language in which the content of this page is written when viewed by user.
Definition: Title.php:4485
Title\newFromDBkey
static newFromDBkey( $key)
Create a new Title from a prefixed DB key.
Definition: Title.php:248
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:2988
Title\isSubpage
isSubpage()
Is this a subpage?
Definition: Title.php:1409
Title\hasContentModel
hasContentModel( $id)
Convenience method for checking a title's content model name.
Definition: Title.php:1098
Title\getRestrictionExpiry
getRestrictionExpiry( $action)
Get the expiry time for the restriction against a given action.
Definition: Title.php:2844
Title\newFromURL
static newFromURL( $url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:420
MediaWiki\Linker\LinkTarget\getFragment
getFragment()
Get the link fragment (i.e.
PROTO_HTTP
const PROTO_HTTP
Definition: Defines.php:199
Title\$mRestrictionsExpiry
array $mRestrictionsExpiry
When do the restrictions on this page expire?
Definition: Title.php:130
MapCacheLRU\set
set( $key, $value, $rank=self::RANK_TOP)
Set a key/value pair.
Definition: MapCacheLRU.php:110
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:201
Title\resetArticleID
resetArticleID( $id)
Inject a page ID, reset DB-loaded fields, and clear the link cache for this title.
Definition: Title.php:3299
Title\isSubpageOf
isSubpageOf(Title $title)
Check if this title is a subpage of another title.
Definition: Title.php:3981
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:916
Title\$mFragment
string $mFragment
Title fragment (i.e.
Definition: Title.php:89
Title\getContentModel
getContentModel( $flags=0)
Get the page's content model id, see the CONTENT_MODEL_XXX constants.
Definition: Title.php:1065
Title\$mNotificationTimestamp
array $mNotificationTimestamp
Associative array of user ID -> timestamp/false.
Definition: Title.php:169
Title\newFromIDs
static newFromIDs( $ids)
Make an array of titles from an array of IDs.
Definition: Title.php:508
Wikimedia\Rdbms\IDatabase\update
update( $table, $values, $conds, $fname=__METHOD__, $options=[])
UPDATE wrapper.
WikiPage\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new page object.
Definition: WikiPage.php:396
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:287
Title\prefix
prefix( $name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object.
Definition: Title.php:1833
Title\getNamespaceKey
getNamespaceKey( $prepend='nstab-')
Generate strings used for xml 'id' names in monobook tabs.
Definition: Title.php:4279
Title\getEditURL
getEditURL()
Get the edit URL for this Title.
Definition: Title.php:2359
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:2121
Title\isKnown
isKnown()
Does this title refer to a page that can (or might) be meaningfully viewed? In particular,...
Definition: Title.php:4073
$wgArticlePath
$wgArticlePath
Definition: img_auth.php:48
Title\$mIsValid
bool null $mIsValid
Is the title known to be valid?
Definition: Title.php:189
Title\getFirstRevision
getFirstRevision( $flags=0)
Get the first revision of the page.
Definition: Title.php:3772
Title\getAllRestrictions
getAllRestrictions()
Accessor/initialisation for mRestrictions.
Definition: Title.php:2830
Title\getEarliestRevTime
getEarliestRevTime( $flags=0)
Get the oldest revision timestamp of this page.
Definition: Title.php:3804
Title
Represents a title within MediaWiki.
Definition: Title.php:42
Title\$mCascadingRestrictions
$mCascadingRestrictions
Caching the results of getCascadeProtectionSources.
Definition: Title.php:127
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:2717
$cache
$cache
Definition: mcc.php:33
$wgSemiprotectedRestrictionLevels
$wgSemiprotectedRestrictionLevels
Restriction levels that should be considered "semiprotected".
Definition: DefaultSettings.php:5355
Title\getRestrictionTypes
getRestrictionTypes()
Returns restriction types for the current Title.
Definition: Title.php:2491
MalformedTitleException
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Definition: MalformedTitleException.php:25
Title\getTitleProtectionInternal
getTitleProtectionInternal()
Fetch title protection settings.
Definition: Title.php:2541
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:3521
Title\isRedirect
isRedirect( $flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
Definition: Title.php:3215
DeferredUpdates\PRESEND
const PRESEND
Definition: DeferredUpdates.php:69
Title\$mArticleID
int $mArticleID
Article ID, fetched from the link cache on demand.
Definition: Title.php:92
Title\isDeleted
isDeleted()
Is there a version of this page in the deletion archive?
Definition: Title.php:3136
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:3336
Title\$mDefaultNamespace
int $mDefaultNamespace
Namespace index when there is no namespace.
Definition: Title.php:160
Title\$mLength
int $mLength
The page length, 0 for special pages.
Definition: Title.php:163
Title\$mEstimateRevisions
int $mEstimateRevisions
Estimated number of revisions; null of not loaded.
Definition: Title.php:110
Title\hasSubjectNamespace
hasSubjectNamespace( $ns)
Returns true if the title has the same subject namespace as the namespace specified.
Definition: Title.php:1353
Title\isSpecialPage
isSpecialPage()
Returns true if this is a special page.
Definition: Title.php:1262
MapCacheLRU\get
get( $key, $maxAge=INF, $default=null)
Get the value for a key.
Definition: MapCacheLRU.php:168
Title\purgeSquid
purgeSquid()
Purge all applicable CDN URLs.
Definition: Title.php:3598
Title\getPreviousRevisionID
getPreviousRevisionID( $revId, $flags=0)
Get the revision ID of the previous revision.
Definition: Title.php:3750
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:4444
Title\CACHE_MAX
const CACHE_MAX
Title::newFromText maintains a cache to avoid expensive re-normalization of commonly used titles.
Definition: Title.php:51
Title\getEditNotices
getEditNotices( $oldid=0)
Get a list of rendered edit notices for this page.
Definition: Title.php:4533
Title\getTouched
getTouched( $db=null)
Get the last touched timestamp.
Definition: Title.php:4227
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:5330
Title\getFragmentForURL
getFragmentForURL()
Get the fragment in URL form, including the "#" character if there is one.
Definition: Title.php:1779
Title\exists
exists( $flags=0)
Check if page exists.
Definition: Title.php:3997
NS_USER
const NS_USER
Definition: Defines.php:62
Title\isAlwaysKnown
isAlwaysKnown()
Should links to this title be shown as potentially viewable (i.e.
Definition: Title.php:4019
Title\secureAndSplit
secureAndSplit( $text, $defaultNamespace=null)
Secure and split - main initialisation function for this object.
Definition: Title.php:3361
Title\isDeletedQuick
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:3161
Title\getSubpageUrlForm
getSubpageUrlForm()
Get a URL-encoded form of the subpage text.
Definition: Title.php:2053
MapCacheLRU\clear
clear( $keys=null)
Clear one or several cache entries, or all cache entries.
Definition: MapCacheLRU.php:285
Title\isNewPage
isNewPage()
Check if this is a new page.
Definition: Title.php:3814
$wgRestrictionTypes
$wgRestrictionTypes
Set of available actions that can be restricted via action=protect You probably shouldn't change this...
Definition: DefaultSettings.php:5317
Title\setContentModel
setContentModel( $model)
Set a proposed content model for the page for permissions checking.
Definition: Title.php:1115
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:68
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:216
Title\compare
static compare(LinkTarget $a, LinkTarget $b)
Callback for usort() to do title sorts by (namespace, title)
Definition: Title.php:856
Title\countAuthorsBetween
countAuthorsBetween( $old, $new, $limit, $options=[])
Get the number of authors between the given revisions or revision IDs.
Definition: Title.php:3957
$t
$t
Definition: testCompression.php:71
Title\legalChars
static legalChars()
Get a regex character class describing the legal characters in a link.
Definition: Title.php:710
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:311
Title\isSiteJsConfigPage
isSiteJsConfigPage()
Is this a sitewide JS "config" page?
Definition: Title.php:1573
Title\invalidateCache
invalidateCache( $purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:4163
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:719
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:961
Title\getRestrictions
getRestrictions( $action)
Accessor/initialisation for mRestrictions.
Definition: Title.php:2816
CommentStore\getStore
static getStore()
Definition: CommentStore.php:116
Title\isContentPage
isContentPage()
Is this Title in a namespace which contains content? In other words, is this a content page,...
Definition: Title.php:1365
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:52
Title\$titleCache
static MapCacheLRU null $titleCache
Definition: Title.php:44
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:483
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
$wgVariantArticlePath
$wgVariantArticlePath
Like $wgArticlePath, but on multi-variant wikis, this provides a path format that describes which par...
Definition: DefaultSettings.php:3183
Title\getUserCaseDBKey
getUserCaseDBKey()
Same as getDBkey()
Definition: Title.php:1042
Title\isRawHtmlMessage
isRawHtmlMessage()
Is this a message which can contain raw HTML?
Definition: Title.php:1591
Title\getSelectFields
static getSelectFields()
Returns a list of fields that are to be selected for initializing Title objects or LinkCache entries.
Definition: Title.php:457
Title\hasSubpages
hasSubpages()
Does this have subpages? (Warning, usually requires an extra DB query.)
Definition: Title.php:3075
Title\getBaseText
getBaseText()
Get the base page name without a namespace, i.e.
Definition: Title.php:1965
Title\pageCond
pageCond()
Get an associative array for selecting this title from the "page" table.
Definition: Title.php:3712
Title\getText
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:1014
Title\$mTextform
string $mTextform
Text form (spaces not underscores) of the main part.
Definition: Title.php:77
Wikimedia\Rdbms\IDatabase\delete
delete( $table, $conds, $fname=__METHOD__)
DELETE query wrapper.
Title\purgeExpiredRestrictions
static purgeExpiredRestrictions()
Purge expired restrictions from the page_restrictions table.
Definition: Title.php:3034
$wgInternalServer
$wgInternalServer
Internal server name as known to CDN, if different.
Definition: DefaultSettings.php:2802
Title\$mLatestID
bool int $mLatestID
ID of most recent revision.
Definition: Title.php:95
Title\$mRestrictionsLoaded
bool $mRestrictionsLoaded
Boolean for initialisation on demand.
Definition: Title.php:139
Title\lazyFillContentModel
lazyFillContentModel( $model)
If the content model field is not frozen then update it with a retreived value.
Definition: Title.php:1129
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:491
Title\getSubjectNsText
getSubjectNsText()
Get the namespace text of the subject (rather than talk) page.
Definition: Title.php:1165
Title\getUserPermissionsErrors
getUserPermissionsErrors( $action, $user, $rigor=PermissionManager::RIGOR_SECURE, $ignoreErrors=[])
Can $user perform $action on this page?
Definition: Title.php:2452
Title\$mTitleProtection
mixed $mTitleProtection
Cached value for getTitleProtection (create protection)
Definition: Title.php:152
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:37
Title\newFromTitleValue
static newFromTitleValue(TitleValue $titleValue, $forceClone='')
Returns a Title given a TitleValue.
Definition: Title.php:272
Title\getRelativeRevisionID
getRelativeRevisionID( $revId, $flags, $dir)
Get next/previous revision ID relative to another revision ID.
Definition: Title.php:3728
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:347
Title\getFullUrlForRedirect
getFullUrlForRedirect( $query='', $proto=PROTO_CURRENT)
Get a url appropriate for making redirects based on an untrusted url arg.
Definition: Title.php:2156
Title\getRootTitle
getRootTitle()
Get the root page name title, i.e.
Definition: Title.php:1942
$type
$type
Definition: testCompression.php:50
Title\getLength
getLength( $flags=0)
What is the length of this page? Uses link cache, adding it if necessary.
Definition: Title.php:3240
Title\getAuthorsBetween
getAuthorsBetween( $old, $new, $limit, $options=[])
Get the authors between the given revisions or revision IDs.
Definition: Title.php:3915
Title\isWatchable
isWatchable()
Can this title be added to a user's watchlist?
Definition: Title.php:1251