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  private const CACHE_MAX = 1000;
52 
58  public const GAID_FOR_UPDATE = 512;
59 
67  public 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 
169  private $mHasSubpages;
170 
172  private $mPageLanguage;
173 
177  private $mDbPageLanguage = false;
178 
180  private $mTitleValue = null;
181 
183  private $mIsBigDeletion = null;
184 
186  private $mIsValid = null;
187  // @}
188 
194  private function getLanguageConverter( $language ) : ILanguageConverter {
195  return MediaWikiServices::getInstance()->getLanguageConverterFactory()
196  ->getLanguageConverter( $language );
197  }
198 
204  return $this->getLanguageConverter( $this->getPageLanguage() );
205  }
206 
215  private static function getTitleFormatter() {
216  return MediaWikiServices::getInstance()->getTitleFormatter();
217  }
218 
227  private static function getInterwikiLookup() {
228  return MediaWikiServices::getInstance()->getInterwikiLookup();
229  }
230 
231  private function __construct() {
232  }
233 
242  public static function newFromDBkey( $key ) {
243  $t = new self();
244 
245  try {
246  $t->secureAndSplit( $key );
247  return $t;
248  } catch ( MalformedTitleException $ex ) {
249  return null;
250  }
251  }
252 
266  public static function newFromTitleValue( TitleValue $titleValue, $forceClone = '' ) {
267  return self::newFromLinkTarget( $titleValue, $forceClone );
268  }
269 
281  public static function newFromLinkTarget( LinkTarget $linkTarget, $forceClone = '' ) {
282  if ( $linkTarget instanceof Title ) {
283  // Special case if it's already a Title object
284  if ( $forceClone === self::NEW_CLONE ) {
285  return clone $linkTarget;
286  } else {
287  return $linkTarget;
288  }
289  }
290  return self::makeTitle(
291  $linkTarget->getNamespace(),
292  $linkTarget->getText(),
293  $linkTarget->getFragment(),
294  $linkTarget->getInterwiki()
295  );
296  }
297 
305  public static function castFromLinkTarget( $linkTarget ) {
306  return $linkTarget ? self::newFromLinkTarget( $linkTarget ) : null;
307  }
308 
329  public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
330  // DWIM: Integers can be passed in here when page titles are used as array keys.
331  if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) {
332  throw new InvalidArgumentException( '$text must be a string.' );
333  }
334  if ( $text === null ) {
335  return null;
336  }
337 
338  try {
339  return self::newFromTextThrow( (string)$text, (int)$defaultNamespace );
340  } catch ( MalformedTitleException $ex ) {
341  return null;
342  }
343  }
344 
364  public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
365  if ( is_object( $text ) ) {
366  throw new MWException( '$text must be a string, given an object' );
367  } elseif ( $text === null ) {
368  // Legacy code relies on MalformedTitleException being thrown in this case
369  // (happens when URL with no title in it is parsed). TODO fix
370  throw new MalformedTitleException( 'title-invalid-empty' );
371  }
372 
374 
375  // Wiki pages often contain multiple links to the same page.
376  // Title normalization and parsing can become expensive on pages with many
377  // links, so we can save a little time by caching them.
378  // In theory these are value objects and won't get changed...
379  if ( $defaultNamespace === NS_MAIN ) {
380  $t = $titleCache->get( $text );
381  if ( $t ) {
382  return $t;
383  }
384  }
385 
386  // Convert things like &eacute; &#257; or &#x3017; into normalized (T16952) text
387  $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
388 
389  $t = new Title();
390  $dbKeyForm = strtr( $filteredText, ' ', '_' );
391 
392  $t->secureAndSplit( $dbKeyForm, (int)$defaultNamespace );
393  if ( $defaultNamespace === NS_MAIN ) {
394  $titleCache->set( $text, $t );
395  }
396  return $t;
397  }
398 
414  public static function newFromURL( $url ) {
415  $t = new Title();
416 
417  # For compatibility with old buggy URLs. "+" is usually not valid in titles,
418  # but some URLs used it as a space replacement and they still come
419  # from some external search tools.
420  if ( strpos( self::legalChars(), '+' ) === false ) {
421  $url = strtr( $url, '+', ' ' );
422  }
423 
424  $dbKeyForm = strtr( $url, ' ', '_' );
425 
426  try {
427  $t->secureAndSplit( $dbKeyForm );
428  return $t;
429  } catch ( MalformedTitleException $ex ) {
430  return null;
431  }
432  }
433 
437  private static function getTitleCache() {
438  if ( self::$titleCache === null ) {
439  self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
440  }
441  return self::$titleCache;
442  }
443 
450  protected static function getSelectFields() {
451  global $wgPageLanguageUseDB;
452 
453  $fields = [
454  'page_namespace', 'page_title', 'page_id',
455  'page_len', 'page_is_redirect', 'page_latest',
456  'page_content_model',
457  ];
458 
459  if ( $wgPageLanguageUseDB ) {
460  $fields[] = 'page_lang';
461  }
462 
463  return $fields;
464  }
465 
473  public static function newFromID( $id, $flags = 0 ) {
474  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
475  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
476  $row = wfGetDB( $index )->selectRow(
477  'page',
478  self::getSelectFields(),
479  [ 'page_id' => $id ],
480  __METHOD__,
481  $options
482  );
483  if ( $row !== false ) {
484  $title = self::newFromRow( $row );
485  } else {
486  $title = null;
487  }
488 
489  return $title;
490  }
491 
498  public static function newFromIDs( $ids ) {
499  if ( !count( $ids ) ) {
500  return [];
501  }
502  $dbr = wfGetDB( DB_REPLICA );
503 
504  $res = $dbr->select(
505  'page',
506  self::getSelectFields(),
507  [ 'page_id' => $ids ],
508  __METHOD__
509  );
510 
511  $titles = [];
512  foreach ( $res as $row ) {
513  $titles[] = self::newFromRow( $row );
514  }
515  return $titles;
516  }
517 
524  public static function newFromRow( $row ) {
525  $t = self::makeTitle( $row->page_namespace, $row->page_title );
526  $t->loadFromRow( $row );
527  return $t;
528  }
529 
536  public function loadFromRow( $row ) {
537  if ( $row ) { // page found
538  if ( isset( $row->page_id ) ) {
539  $this->mArticleID = (int)$row->page_id;
540  }
541  if ( isset( $row->page_len ) ) {
542  $this->mLength = (int)$row->page_len;
543  }
544  if ( isset( $row->page_is_redirect ) ) {
545  $this->mRedirect = (bool)$row->page_is_redirect;
546  }
547  if ( isset( $row->page_latest ) ) {
548  $this->mLatestID = (int)$row->page_latest;
549  }
550  if ( isset( $row->page_content_model ) ) {
551  $this->lazyFillContentModel( $row->page_content_model );
552  } else {
553  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
554  }
555  if ( isset( $row->page_lang ) ) {
556  $this->mDbPageLanguage = (string)$row->page_lang;
557  }
558  if ( isset( $row->page_restrictions ) ) {
559  $this->mOldRestrictions = $row->page_restrictions;
560  }
561  } else { // page not found
562  $this->mArticleID = 0;
563  $this->mLength = 0;
564  $this->mRedirect = false;
565  $this->mLatestID = 0;
566  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
567  }
568  }
569 
592  public static function makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
593  $t = new Title();
594  $t->mInterwiki = $interwiki;
595  $t->mFragment = $fragment;
596  $t->mNamespace = $ns = (int)$ns;
597  $t->mDbkeyform = strtr( $title, ' ', '_' );
598  $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
599  $t->mUrlform = wfUrlencode( $t->mDbkeyform );
600  $t->mTextform = strtr( $title, '_', ' ' );
601  return $t;
602  }
603 
618  public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
619  // NOTE: ideally, this would just call makeTitle() and then isValid(),
620  // but presently, that means more overhead on a potential performance hotspot.
621 
622  if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) {
623  return null;
624  }
625 
626  $t = new Title();
627  $dbKeyForm = self::makeName( $ns, $title, $fragment, $interwiki, true );
628 
629  try {
630  $t->secureAndSplit( $dbKeyForm );
631  return $t;
632  } catch ( MalformedTitleException $ex ) {
633  return null;
634  }
635  }
636 
654  public static function newMainPage( MessageLocalizer $localizer = null ) {
655  if ( $localizer ) {
656  $msg = $localizer->msg( 'mainpage' );
657  } else {
658  $msg = wfMessage( 'mainpage' );
659  }
660 
661  $title = self::newFromText( $msg->inContentLanguage()->text() );
662 
663  // Every page renders at least one link to the Main Page (e.g. sidebar).
664  // If the localised value is invalid, don't produce fatal errors that
665  // would make the wiki inaccessible (and hard to fix the invalid message).
666  // Gracefully fallback...
667  if ( !$title ) {
668  $title = self::newFromText( 'Main Page' );
669  }
670  return $title;
671  }
672 
679  public static function nameOf( $id ) {
680  $dbr = wfGetDB( DB_REPLICA );
681 
682  $s = $dbr->selectRow(
683  'page',
684  [ 'page_namespace', 'page_title' ],
685  [ 'page_id' => $id ],
686  __METHOD__
687  );
688  if ( $s === false ) {
689  return null;
690  }
691 
692  return self::makeName( $s->page_namespace, $s->page_title );
693  }
694 
700  public static function legalChars() {
701  global $wgLegalTitleChars;
702  return $wgLegalTitleChars;
703  }
704 
714  public static function convertByteClassToUnicodeClass( $byteClass ) {
715  $length = strlen( $byteClass );
716  // Input token queue
717  $x0 = $x1 = $x2 = '';
718  // Decoded queue
719  $d0 = $d1 = $d2 = '';
720  // Decoded integer codepoints
721  $ord0 = $ord1 = $ord2 = 0;
722  // Re-encoded queue
723  $r0 = $r1 = $r2 = '';
724  // Output
725  $out = '';
726  // Flags
727  $allowUnicode = false;
728  for ( $pos = 0; $pos < $length; $pos++ ) {
729  // Shift the queues down
730  $x2 = $x1;
731  $x1 = $x0;
732  $d2 = $d1;
733  $d1 = $d0;
734  $ord2 = $ord1;
735  $ord1 = $ord0;
736  $r2 = $r1;
737  $r1 = $r0;
738  // Load the current input token and decoded values
739  $inChar = $byteClass[$pos];
740  if ( $inChar == '\\' ) {
741  if ( preg_match( '/x([0-9a-fA-F]{2})/A', $byteClass, $m, 0, $pos + 1 ) ) {
742  $x0 = $inChar . $m[0];
743  $d0 = chr( hexdec( $m[1] ) );
744  $pos += strlen( $m[0] );
745  } elseif ( preg_match( '/[0-7]{3}/A', $byteClass, $m, 0, $pos + 1 ) ) {
746  $x0 = $inChar . $m[0];
747  $d0 = chr( octdec( $m[0] ) );
748  $pos += strlen( $m[0] );
749  } elseif ( $pos + 1 >= $length ) {
750  $x0 = $d0 = '\\';
751  } else {
752  $d0 = $byteClass[$pos + 1];
753  $x0 = $inChar . $d0;
754  $pos += 1;
755  }
756  } else {
757  $x0 = $d0 = $inChar;
758  }
759  $ord0 = ord( $d0 );
760  // Load the current re-encoded value
761  if ( $ord0 < 32 || $ord0 == 0x7f ) {
762  $r0 = sprintf( '\x%02x', $ord0 );
763  } elseif ( $ord0 >= 0x80 ) {
764  // Allow unicode if a single high-bit character appears
765  $r0 = sprintf( '\x%02x', $ord0 );
766  $allowUnicode = true;
767  // @phan-suppress-next-line PhanParamSuspiciousOrder false positive
768  } elseif ( strpos( '-\\[]^', $d0 ) !== false ) {
769  $r0 = '\\' . $d0;
770  } else {
771  $r0 = $d0;
772  }
773  // Do the output
774  if ( $x0 !== '' && $x1 === '-' && $x2 !== '' ) {
775  // Range
776  if ( $ord2 > $ord0 ) {
777  // Empty range
778  } elseif ( $ord0 >= 0x80 ) {
779  // Unicode range
780  $allowUnicode = true;
781  if ( $ord2 < 0x80 ) {
782  // Keep the non-unicode section of the range
783  $out .= "$r2-\\x7F";
784  }
785  } else {
786  // Normal range
787  $out .= "$r2-$r0";
788  }
789  // Reset state to the initial value
790  $x0 = $x1 = $d0 = $d1 = $r0 = $r1 = '';
791  } elseif ( $ord2 < 0x80 ) {
792  // ASCII character
793  $out .= $r2;
794  }
795  }
796  // @phan-suppress-next-line PhanSuspiciousValueComparison
797  if ( $ord1 < 0x80 ) {
798  $out .= $r1;
799  }
800  if ( $ord0 < 0x80 ) {
801  $out .= $r0;
802  }
803  if ( $allowUnicode ) {
804  $out .= '\u0080-\uFFFF';
805  }
806  return $out;
807  }
808 
820  public static function makeName( $ns, $title, $fragment = '', $interwiki = '',
821  $canonicalNamespace = false
822  ) {
823  if ( $canonicalNamespace ) {
824  $namespace = MediaWikiServices::getInstance()->getNamespaceInfo()->
825  getCanonicalName( $ns );
826  } else {
827  $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns );
828  }
829  $name = $namespace == '' ? $title : "$namespace:$title";
830  if ( strval( $interwiki ) != '' ) {
831  $name = "$interwiki:$name";
832  }
833  if ( strval( $fragment ) != '' ) {
834  $name .= '#' . $fragment;
835  }
836  return $name;
837  }
838 
847  public static function compare( LinkTarget $a, LinkTarget $b ) {
848  return $a->getNamespace() <=> $b->getNamespace()
849  ?: strcmp( $a->getText(), $b->getText() );
850  }
851 
868  public function isValid() {
869  if ( $this->mIsValid !== null ) {
870  return $this->mIsValid;
871  }
872 
873  try {
874  $text = $this->getFullText();
875  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
876 
877  '@phan-var MediaWikiTitleCodec $titleCodec';
878  $parts = $titleCodec->splitTitleString( $text, $this->mNamespace );
879 
880  // Check that nothing changed!
881  // This ensures that $text was already perperly normalized.
882  if ( $parts['fragment'] !== $this->mFragment
883  || $parts['interwiki'] !== $this->mInterwiki
884  || $parts['local_interwiki'] !== $this->mLocalInterwiki
885  || $parts['namespace'] !== $this->mNamespace
886  || $parts['dbkey'] !== $this->mDbkeyform
887  ) {
888  $this->mIsValid = false;
889  return $this->mIsValid;
890  }
891  } catch ( MalformedTitleException $ex ) {
892  $this->mIsValid = false;
893  return $this->mIsValid;
894  }
895 
896  $this->mIsValid = true;
897  return $this->mIsValid;
898  }
899 
907  public function isLocal() {
908  if ( $this->isExternal() ) {
909  $iw = self::getInterwikiLookup()->fetch( $this->mInterwiki );
910  if ( $iw ) {
911  return $iw->isLocal();
912  }
913  }
914  return true;
915  }
916 
922  public function isExternal() {
923  return $this->mInterwiki !== '';
924  }
925 
933  public function getInterwiki() {
934  return $this->mInterwiki;
935  }
936 
942  public function wasLocalInterwiki() {
943  return $this->mLocalInterwiki;
944  }
945 
952  public function isTrans() {
953  if ( !$this->isExternal() ) {
954  return false;
955  }
956 
957  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable();
958  }
959 
965  public function getTransWikiID() {
966  if ( !$this->isExternal() ) {
967  return false;
968  }
969 
970  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID();
971  }
972 
982  public function getTitleValue() {
983  if ( $this->mTitleValue === null ) {
984  try {
985  $this->mTitleValue = new TitleValue(
986  $this->mNamespace,
987  $this->mDbkeyform,
988  $this->mFragment,
989  $this->mInterwiki
990  );
991  } catch ( InvalidArgumentException $ex ) {
992  wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' .
993  $this->getPrefixedText() . ']]: ' . $ex->getMessage() );
994  }
995  }
996 
997  return $this->mTitleValue;
998  }
999 
1005  public function getText() {
1006  return $this->mTextform;
1007  }
1008 
1014  public function getPartialURL() {
1015  return $this->mUrlform;
1016  }
1017 
1023  public function getDBkey() {
1024  return $this->mDbkeyform;
1025  }
1026 
1032  public function getNamespace() {
1033  return $this->mNamespace;
1034  }
1035 
1044  public function getContentModel( $flags = 0 ) {
1045  if ( $this->mForcedContentModel ) {
1046  if ( !$this->mContentModel ) {
1047  throw new RuntimeException( 'Got out of sync; an empty model is being forced' );
1048  }
1049  // Content model is locked to the currently loaded one
1050  return $this->mContentModel;
1051  }
1052 
1053  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
1054  $this->lazyFillContentModel( $this->loadFieldFromDB( 'page_content_model', $flags ) );
1055  } elseif (
1056  ( !$this->mContentModel || $flags & self::GAID_FOR_UPDATE ) &&
1057  $this->getArticleID( $flags )
1058  ) {
1059  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1060  $linkCache->addLinkObj( $this ); # in case we already had an article ID
1061  $this->lazyFillContentModel( $linkCache->getGoodLinkFieldObj( $this, 'model' ) );
1062  }
1063 
1064  if ( !$this->mContentModel ) {
1066  }
1067 
1068  return $this->mContentModel;
1069  }
1070 
1077  public function hasContentModel( $id ) {
1078  return $this->getContentModel() == $id;
1079  }
1080 
1094  public function setContentModel( $model ) {
1095  if ( (string)$model === '' ) {
1096  throw new InvalidArgumentException( "Missing CONTENT_MODEL_* constant" );
1097  }
1098 
1099  $this->mContentModel = $model;
1100  $this->mForcedContentModel = true;
1101  }
1102 
1108  private function lazyFillContentModel( $model ) {
1109  if ( !$this->mForcedContentModel ) {
1110  $this->mContentModel = ( $model === false ) ? false : (string)$model;
1111  }
1112  }
1113 
1119  public function getNsText() {
1120  if ( $this->isExternal() ) {
1121  // This probably shouldn't even happen, except for interwiki transclusion.
1122  // If possible, use the canonical name for the foreign namespace.
1123  $nsText = MediaWikiServices::getInstance()->getNamespaceInfo()->
1124  getCanonicalName( $this->mNamespace );
1125  if ( $nsText !== false ) {
1126  return $nsText;
1127  }
1128  }
1129 
1130  try {
1131  $formatter = self::getTitleFormatter();
1132  return $formatter->getNamespaceName( $this->mNamespace, $this->mDbkeyform );
1133  } catch ( InvalidArgumentException $ex ) {
1134  wfDebug( __METHOD__ . ': ' . $ex->getMessage() );
1135  return false;
1136  }
1137  }
1138 
1144  public function getSubjectNsText() {
1145  $services = MediaWikiServices::getInstance();
1146  return $services->getContentLanguage()->
1147  getNsText( $services->getNamespaceInfo()->getSubject( $this->mNamespace ) );
1148  }
1149 
1155  public function getTalkNsText() {
1156  $services = MediaWikiServices::getInstance();
1157  return $services->getContentLanguage()->
1158  getNsText( $services->getNamespaceInfo()->getTalk( $this->mNamespace ) );
1159  }
1160 
1172  public function canHaveTalkPage() {
1173  return MediaWikiServices::getInstance()->getNamespaceInfo()->canHaveTalkPage( $this );
1174  }
1175 
1186  public function canExist() {
1187  // NOTE: Don't use getArticleID(), we don't want to
1188  // trigger a database query here. This check is supposed to
1189  // act as an optimization, not add extra cost.
1190  if ( $this->mArticleID > 0 ) {
1191  // It exists, so it can exist.
1192  return true;
1193  }
1194 
1195  // NOTE: we call the relatively expensive isValid() method further down,
1196  // but we can bail out early if we already know the title is invalid.
1197  if ( $this->mIsValid === false ) {
1198  // It's invalid, so it can't exist.
1199  return false;
1200  }
1201 
1202  if ( $this->getNamespace() < NS_MAIN ) {
1203  // It's a special page, so it can't exist in the database.
1204  return false;
1205  }
1206 
1207  if ( $this->isExternal() ) {
1208  // If it's external, it's not local, so it can't exist.
1209  return false;
1210  }
1211 
1212  if ( $this->getText() === '' ) {
1213  // The title has no text, so it can't exist in the database.
1214  // It's probably an on-page section link, like "#something".
1215  return false;
1216  }
1217 
1218  // Double check that the title is valid.
1219  return $this->isValid();
1220  }
1221 
1230  public function isWatchable() {
1231  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
1232  return $this->getText() !== '' && !$this->isExternal() &&
1233  $nsInfo->isWatchable( $this->mNamespace );
1234  }
1235 
1241  public function isSpecialPage() {
1242  return $this->mNamespace === NS_SPECIAL;
1243  }
1244 
1251  public function isSpecial( $name ) {
1252  if ( $this->isSpecialPage() ) {
1253  list( $thisName, /* $subpage */ ) =
1254  MediaWikiServices::getInstance()->getSpecialPageFactory()->
1255  resolveAlias( $this->mDbkeyform );
1256  if ( $name == $thisName ) {
1257  return true;
1258  }
1259  }
1260  return false;
1261  }
1262 
1269  public function fixSpecialName() {
1270  if ( $this->isSpecialPage() ) {
1271  $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory();
1272  list( $canonicalName, $par ) = $spFactory->resolveAlias( $this->mDbkeyform );
1273  if ( $canonicalName ) {
1274  $localName = $spFactory->getLocalNameFor( $canonicalName, $par );
1275  if ( $localName != $this->mDbkeyform ) {
1276  return self::makeTitle( NS_SPECIAL, $localName );
1277  }
1278  }
1279  }
1280  return $this;
1281  }
1282 
1293  public function inNamespace( $ns ) {
1294  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1295  equals( $this->mNamespace, $ns );
1296  }
1297 
1305  public function inNamespaces( ...$namespaces ) {
1306  if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) {
1307  $namespaces = $namespaces[0];
1308  }
1309 
1310  foreach ( $namespaces as $ns ) {
1311  if ( $this->inNamespace( $ns ) ) {
1312  return true;
1313  }
1314  }
1315 
1316  return false;
1317  }
1318 
1332  public function hasSubjectNamespace( $ns ) {
1333  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1334  subjectEquals( $this->mNamespace, $ns );
1335  }
1336 
1344  public function isContentPage() {
1345  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1346  isContent( $this->mNamespace );
1347  }
1348 
1355  public function isMovable() {
1356  if (
1357  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1358  isMovable( $this->mNamespace ) || $this->isExternal()
1359  ) {
1360  // Interwiki title or immovable namespace. Hooks don't get to override here
1361  return false;
1362  }
1363 
1364  $result = true;
1365  Hooks::runner()->onTitleIsMovable( $this, $result );
1366  return $result;
1367  }
1368 
1379  public function isMainPage() {
1380  return $this->equals( self::newMainPage() );
1381  }
1382 
1388  public function isSubpage() {
1389  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1390  hasSubpages( $this->mNamespace )
1391  ? strpos( $this->getText(), '/' ) !== false
1392  : false;
1393  }
1394 
1400  public function isConversionTable() {
1401  // @todo ConversionTable should become a separate content model.
1402 
1403  return $this->mNamespace === NS_MEDIAWIKI &&
1404  strpos( $this->getText(), 'Conversiontable/' ) === 0;
1405  }
1406 
1412  public function isWikitextPage() {
1413  return $this->hasContentModel( CONTENT_MODEL_WIKITEXT );
1414  }
1415 
1430  public function isSiteConfigPage() {
1431  return (
1432  $this->isSiteCssConfigPage()
1433  || $this->isSiteJsonConfigPage()
1434  || $this->isSiteJsConfigPage()
1435  );
1436  }
1437 
1444  public function isUserConfigPage() {
1445  return (
1446  $this->isUserCssConfigPage()
1447  || $this->isUserJsonConfigPage()
1448  || $this->isUserJsConfigPage()
1449  );
1450  }
1451 
1458  public function getSkinFromConfigSubpage() {
1459  $subpage = explode( '/', $this->mTextform );
1460  $subpage = $subpage[count( $subpage ) - 1];
1461  $lastdot = strrpos( $subpage, '.' );
1462  if ( $lastdot === false ) {
1463  return $subpage; # Never happens: only called for names ending in '.css'/'.json'/'.js'
1464  }
1465  return substr( $subpage, 0, $lastdot );
1466  }
1467 
1474  public function isUserCssConfigPage() {
1475  return (
1476  $this->mNamespace === NS_USER
1477  && $this->isSubpage()
1478  && $this->hasContentModel( CONTENT_MODEL_CSS )
1479  );
1480  }
1481 
1488  public function isUserJsonConfigPage() {
1489  return (
1490  $this->mNamespace === NS_USER
1491  && $this->isSubpage()
1492  && $this->hasContentModel( CONTENT_MODEL_JSON )
1493  );
1494  }
1495 
1502  public function isUserJsConfigPage() {
1503  return (
1504  $this->mNamespace === NS_USER
1505  && $this->isSubpage()
1507  );
1508  }
1509 
1516  public function isSiteCssConfigPage() {
1517  return (
1518  $this->mNamespace === NS_MEDIAWIKI
1519  && (
1521  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1522  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1523  || substr( $this->mDbkeyform, -4 ) === '.css'
1524  )
1525  );
1526  }
1527 
1534  public function isSiteJsonConfigPage() {
1535  return (
1536  $this->mNamespace === NS_MEDIAWIKI
1537  && (
1539  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1540  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1541  || substr( $this->mDbkeyform, -5 ) === '.json'
1542  )
1543  );
1544  }
1545 
1552  public function isSiteJsConfigPage() {
1553  return (
1554  $this->mNamespace === NS_MEDIAWIKI
1555  && (
1557  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1558  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1559  || substr( $this->mDbkeyform, -3 ) === '.js'
1560  )
1561  );
1562  }
1563 
1570  public function isRawHtmlMessage() {
1571  global $wgRawHtmlMessages;
1572 
1573  if ( !$this->inNamespace( NS_MEDIAWIKI ) ) {
1574  return false;
1575  }
1576  $message = lcfirst( $this->getRootTitle()->getDBkey() );
1577  return in_array( $message, $wgRawHtmlMessages, true );
1578  }
1579 
1585  public function isTalkPage() {
1586  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1587  isTalk( $this->mNamespace );
1588  }
1589 
1601  public function getTalkPage() {
1602  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1603  // Instead of failing on invalid titles, let's just log the issue for now.
1604  // See the discussion on T227817.
1605 
1606  // Is this the same title?
1607  $talkNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $this->mNamespace );
1608  if ( $this->mNamespace == $talkNS ) {
1609  return $this;
1610  }
1611 
1612  $title = self::makeTitle( $talkNS, $this->mDbkeyform );
1613 
1614  $this->warnIfPageCannotExist( $title, __METHOD__ );
1615 
1616  return $title;
1617  // TODO: replace the above with the code below:
1618  // return self::castFromLinkTarget(
1619  // MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) );
1620  }
1621 
1631  public function getTalkPageIfDefined() {
1632  if ( !$this->canHaveTalkPage() ) {
1633  return null;
1634  }
1635 
1636  return $this->getTalkPage();
1637  }
1638 
1646  public function getSubjectPage() {
1647  // Is this the same title?
1648  $subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo()
1649  ->getSubject( $this->mNamespace );
1650  if ( $this->mNamespace == $subjectNS ) {
1651  return $this;
1652  }
1653  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1654  // Instead of failing on invalid titles, let's just log the issue for now.
1655  // See the discussion on T227817.
1656  $title = self::makeTitle( $subjectNS, $this->mDbkeyform );
1657 
1658  $this->warnIfPageCannotExist( $title, __METHOD__ );
1659 
1660  return $title;
1661  // TODO: replace the above with the code below:
1662  // return self::castFromLinkTarget(
1663  // MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
1664  }
1665 
1672  private function warnIfPageCannotExist( Title $title, $method ) {
1673  if ( $this->getText() == '' ) {
1674  wfLogWarning(
1675  $method . ': called on empty title ' . $this->getFullText() . ', returning '
1676  . $title->getFullText()
1677  );
1678 
1679  return true;
1680  }
1681 
1682  if ( $this->getInterwiki() !== '' ) {
1683  wfLogWarning(
1684  $method . ': called on interwiki title ' . $this->getFullText() . ', returning '
1685  . $title->getFullText()
1686  );
1687 
1688  return true;
1689  }
1690 
1691  return false;
1692  }
1693 
1703  public function getOtherPage() {
1704  // NOTE: Depend on the methods in this class instead of their equivalent in NamespaceInfo,
1705  // until their semantics has become exactly the same.
1706  // See the discussion on T227817.
1707  if ( $this->isSpecialPage() ) {
1708  throw new MWException( 'Special pages cannot have other pages' );
1709  }
1710  if ( $this->isTalkPage() ) {
1711  return $this->getSubjectPage();
1712  } else {
1713  if ( !$this->canHaveTalkPage() ) {
1714  throw new MWException( "{$this->getPrefixedText()} does not have an other page" );
1715  }
1716  return $this->getTalkPage();
1717  }
1718  // TODO: replace the above with the code below:
1719  // return self::castFromLinkTarget(
1720  // MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) );
1721  }
1722 
1728  public function getDefaultNamespace() {
1729  return $this->mDefaultNamespace;
1730  }
1731 
1739  public function getFragment() {
1740  return $this->mFragment;
1741  }
1742 
1749  public function hasFragment() {
1750  return $this->mFragment !== '';
1751  }
1752 
1758  public function getFragmentForURL() {
1759  if ( !$this->hasFragment() ) {
1760  return '';
1761  } elseif ( $this->isExternal() ) {
1762  // Note: If the interwiki is unknown, it's treated as a namespace on the local wiki,
1763  // so we treat it like a local interwiki.
1764  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
1765  if ( $interwiki && !$interwiki->isLocal() ) {
1766  return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment );
1767  }
1768  }
1769 
1770  return '#' . Sanitizer::escapeIdForLink( $this->mFragment );
1771  }
1772 
1785  public function setFragment( $fragment ) {
1786  $this->mFragment = strtr( substr( $fragment, 1 ), '_', ' ' );
1787  }
1788 
1796  public function createFragmentTarget( $fragment ) {
1797  return self::makeTitle(
1798  $this->mNamespace,
1799  $this->getText(),
1800  $fragment,
1801  $this->mInterwiki
1802  );
1803  }
1804 
1812  private function prefix( $name ) {
1813  $p = '';
1814  if ( $this->isExternal() ) {
1815  $p = $this->mInterwiki . ':';
1816  }
1817 
1818  if ( $this->mNamespace != 0 ) {
1819  $nsText = $this->getNsText();
1820 
1821  if ( $nsText === false ) {
1822  // See T165149. Awkward, but better than erroneously linking to the main namespace.
1823  $nsText = MediaWikiServices::getInstance()->getContentLanguage()->
1824  getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
1825  }
1826 
1827  $p .= $nsText . ':';
1828  }
1829  return $p . $name;
1830  }
1831 
1838  public function getPrefixedDBkey() {
1839  $s = $this->prefix( $this->mDbkeyform );
1840  $s = strtr( $s, ' ', '_' );
1841  return $s;
1842  }
1843 
1850  public function getPrefixedText() {
1851  if ( $this->prefixedText === null ) {
1852  $s = $this->prefix( $this->mTextform );
1853  $s = strtr( $s, '_', ' ' );
1854  $this->prefixedText = $s;
1855  }
1856  return $this->prefixedText;
1857  }
1858 
1864  public function __toString() {
1865  return $this->getPrefixedText();
1866  }
1867 
1874  public function getFullText() {
1875  $text = $this->getPrefixedText();
1876  if ( $this->hasFragment() ) {
1877  $text .= '#' . $this->mFragment;
1878  }
1879  return $text;
1880  }
1881 
1896  private function findSubpageDivider( $text, $dir ) {
1897  $top = strlen( $text ) - 1;
1898  $bottom = 0;
1899 
1900  while ( $bottom < $top && $text[$bottom] === '/' ) {
1901  $bottom++;
1902  }
1903 
1904  if ( $top < $bottom ) {
1905  return false;
1906  }
1907 
1908  if ( $dir > 0 ) {
1909  $idx = $bottom;
1910  while ( $idx <= $top && $text[$idx] !== '/' ) {
1911  $idx++;
1912  }
1913  } else {
1914  $idx = $top;
1915  while ( $idx > $bottom && $text[$idx] !== '/' ) {
1916  $idx--;
1917  }
1918  }
1919 
1920  if ( $idx < $bottom || $idx > $top ) {
1921  return false;
1922  }
1923 
1924  if ( $idx < 1 ) {
1925  return false;
1926  }
1927 
1928  return $idx;
1929  }
1930 
1935  private function hasSubpagesEnabled() {
1936  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1937  hasSubpages( $this->mNamespace );
1938  }
1939 
1955  public function getRootText() {
1956  $text = $this->getText();
1957  if ( !$this->hasSubpagesEnabled() ) {
1958  return $text;
1959  }
1960 
1961  $firstSlashPos = $this->findSubpageDivider( $text, +1 );
1962  // Don't discard the real title if there's no subpage involved
1963  if ( $firstSlashPos === false ) {
1964  return $text;
1965  }
1966 
1967  return substr( $text, 0, $firstSlashPos );
1968  }
1969 
1982  public function getRootTitle() {
1983  $title = self::makeTitleSafe( $this->mNamespace, $this->getRootText() );
1984  Assert::postcondition(
1985  $title !== null,
1986  'makeTitleSafe() should always return a Title for the text returned by getRootText().'
1987  );
1988  return $title;
1989  }
1990 
2005  public function getBaseText() {
2006  $text = $this->getText();
2007  if ( !$this->hasSubpagesEnabled() ) {
2008  return $text;
2009  }
2010 
2011  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
2012  // Don't discard the real title if there's no subpage involved
2013  if ( $lastSlashPos === false ) {
2014  return $text;
2015  }
2016 
2017  return substr( $text, 0, $lastSlashPos );
2018  }
2019 
2032  public function getBaseTitle() {
2033  $title = self::makeTitleSafe( $this->mNamespace, $this->getBaseText() );
2034  Assert::postcondition(
2035  $title !== null,
2036  'makeTitleSafe() should always return a Title for the text returned by getBaseText().'
2037  );
2038  return $title;
2039  }
2040 
2052  public function getSubpageText() {
2053  $text = $this->getText();
2054  if ( !$this->hasSubpagesEnabled() ) {
2055  return $text;
2056  }
2057 
2058  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
2059  if ( $lastSlashPos === false ) {
2060  // T256922 - Return the title text if no subpages
2061  return $text;
2062  }
2063  return substr( $text, $lastSlashPos + 1 );
2064  }
2065 
2079  public function getSubpage( $text ) {
2080  return self::makeTitleSafe(
2081  $this->mNamespace,
2082  $this->getText() . '/' . $text,
2083  '',
2084  $this->mInterwiki
2085  );
2086  }
2087 
2093  public function getSubpageUrlForm() {
2094  $text = $this->getSubpageText();
2095  $text = wfUrlencode( strtr( $text, ' ', '_' ) );
2096  return $text;
2097  }
2098 
2104  public function getPrefixedURL() {
2105  $s = $this->prefix( $this->mDbkeyform );
2106  $s = wfUrlencode( strtr( $s, ' ', '_' ) );
2107  return $s;
2108  }
2109 
2123  private static function fixUrlQueryArgs( $query, $query2 = false ) {
2124  if ( $query2 !== false ) {
2125  wfDeprecatedMsg( "Title::get{Canonical,Full,Link,Local,Internal}URL " .
2126  "method called with a second parameter is deprecated since MediaWiki 1.19. " .
2127  "Add your parameter to an array passed as the first parameter.", "1.19" );
2128  }
2129  if ( is_array( $query ) ) {
2130  $query = wfArrayToCgi( $query );
2131  }
2132  if ( $query2 ) {
2133  if ( is_string( $query2 ) ) {
2134  // $query2 is a string, we will consider this to be
2135  // a deprecated $variant argument and add it to the query
2136  $query2 = wfArrayToCgi( [ 'variant' => $query2 ] );
2137  } else {
2138  $query2 = wfArrayToCgi( $query2 );
2139  }
2140  // If we have $query content add a & to it first
2141  if ( $query ) {
2142  $query .= '&';
2143  }
2144  // Now append the queries together
2145  $query .= $query2;
2146  }
2147  return $query;
2148  }
2149 
2161  public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
2162  $query = self::fixUrlQueryArgs( $query, $query2 );
2163 
2164  # Hand off all the decisions on urls to getLocalURL
2165  $url = $this->getLocalURL( $query );
2166 
2167  # Expand the url to make it a full url. Note that getLocalURL has the
2168  # potential to output full urls for a variety of reasons, so we use
2169  # wfExpandUrl instead of simply prepending $wgServer
2170  $url = wfExpandUrl( $url, $proto );
2171 
2172  # Finally, add the fragment.
2173  $url .= $this->getFragmentForURL();
2174  Hooks::runner()->onGetFullURL( $this, $url, $query );
2175  return $url;
2176  }
2177 
2194  public function getFullUrlForRedirect( $query = '', $proto = PROTO_CURRENT ) {
2195  $target = $this;
2196  if ( $this->isExternal() ) {
2197  $target = SpecialPage::getTitleFor(
2198  'GoToInterwiki',
2199  $this->getPrefixedDBkey()
2200  );
2201  }
2202  return $target->getFullURL( $query, false, $proto );
2203  }
2204 
2228  public function getLocalURL( $query = '', $query2 = false ) {
2230 
2231  $query = self::fixUrlQueryArgs( $query, $query2 );
2232 
2233  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
2234  if ( $interwiki ) {
2235  $namespace = $this->getNsText();
2236  if ( $namespace != '' ) {
2237  # Can this actually happen? Interwikis shouldn't be parsed.
2238  # Yes! It can in interwiki transclusion. But... it probably shouldn't.
2239  $namespace .= ':';
2240  }
2241  $url = $interwiki->getURL( $namespace . $this->mDbkeyform );
2242  $url = wfAppendQuery( $url, $query );
2243  } else {
2244  $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
2245  if ( $query == '' ) {
2246  $url = str_replace( '$1', $dbkey, $wgArticlePath );
2247  Hooks::runner()->onGetLocalURL__Article( $this, $url );
2248  } else {
2250  $url = false;
2251  $matches = [];
2252 
2254 
2255  if ( $articlePaths
2256  && preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
2257  ) {
2258  $action = urldecode( $matches[2] );
2259  if ( isset( $articlePaths[$action] ) ) {
2260  $query = $matches[1];
2261  if ( isset( $matches[4] ) ) {
2262  $query .= $matches[4];
2263  }
2264  $url = str_replace( '$1', $dbkey, $articlePaths[$action] );
2265  if ( $query != '' ) {
2266  $url = wfAppendQuery( $url, $query );
2267  }
2268  }
2269  }
2270 
2271  if ( $url === false
2273  && preg_match( '/^variant=([^&]*)$/', $query, $matches )
2274  && $this->getPageLanguage()->equals(
2275  MediaWikiServices::getInstance()->getContentLanguage() )
2276  && $this->getPageLanguageConverter()->hasVariants()
2277  ) {
2278  $variant = urldecode( $matches[1] );
2279  if ( $this->getPageLanguageConverter()->hasVariant( $variant ) ) {
2280  // Only do the variant replacement if the given variant is a valid
2281  // variant for the page's language.
2282  $url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath );
2283  $url = str_replace( '$1', $dbkey, $url );
2284  }
2285  }
2286 
2287  if ( $url === false ) {
2288  if ( $query == '-' ) {
2289  $query = '';
2290  }
2291  $url = "{$wgScript}?title={$dbkey}&{$query}";
2292  }
2293  }
2294  Hooks::runner()->onGetLocalURL__Internal( $this, $url, $query );
2295 
2296  // @todo FIXME: This causes breakage in various places when we
2297  // actually expected a local URL and end up with dupe prefixes.
2298  if ( $wgRequest->getVal( 'action' ) == 'render' ) {
2299  $url = $wgServer . $url;
2300  }
2301  }
2302 
2303  if ( $wgMainPageIsDomainRoot && $this->isMainPage() && $query === '' ) {
2304  return '/';
2305  }
2306 
2307  Hooks::runner()->onGetLocalURL( $this, $url, $query );
2308  return $url;
2309  }
2310 
2328  public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
2329  if ( $this->isExternal() || $proto !== false ) {
2330  $ret = $this->getFullURL( $query, $query2, $proto );
2331  } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
2332  $ret = $this->getFragmentForURL();
2333  } else {
2334  $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
2335  }
2336  return $ret;
2337  }
2338 
2353  public function getInternalURL( $query = '', $query2 = false ) {
2354  global $wgInternalServer, $wgServer;
2355  $query = self::fixUrlQueryArgs( $query, $query2 );
2356  $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
2357  $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP );
2358  Hooks::runner()->onGetInternalURL( $this, $url, $query );
2359  return $url;
2360  }
2361 
2375  public function getCanonicalURL( $query = '', $query2 = false ) {
2376  $query = self::fixUrlQueryArgs( $query, $query2 );
2377  $url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL );
2378  Hooks::runner()->onGetCanonicalURL( $this, $url, $query );
2379  return $url;
2380  }
2381 
2387  public function getEditURL() {
2388  if ( $this->isExternal() ) {
2389  return '';
2390  }
2391  $s = $this->getLocalURL( 'action=edit' );
2392 
2393  return $s;
2394  }
2395 
2416  public function quickUserCan( $action, $user = null ) {
2417  wfDeprecated( __METHOD__, '1.33' );
2418  if ( !$user instanceof User ) {
2419  global $wgUser;
2420  $user = $wgUser;
2421  }
2422  return MediaWikiServices::getInstance()->getPermissionManager()
2423  ->quickUserCan( $action, $user, $this );
2424  }
2425 
2441  public function userCan( $action, $user = null, $rigor = PermissionManager::RIGOR_SECURE ) {
2442  wfDeprecated( __METHOD__, '1.33' );
2443  if ( !$user instanceof User ) {
2444  global $wgUser;
2445  $user = $wgUser;
2446  }
2447 
2448  // TODO: this is for b/c, eventually will be removed
2449  if ( $rigor === true ) {
2450  $rigor = PermissionManager::RIGOR_SECURE; // b/c
2451  } elseif ( $rigor === false ) {
2452  $rigor = PermissionManager::RIGOR_QUICK; // b/c
2453  }
2454 
2455  return MediaWikiServices::getInstance()->getPermissionManager()
2456  ->userCan( $action, $user, $this, $rigor );
2457  }
2458 
2480  public function getUserPermissionsErrors(
2481  $action, $user, $rigor = PermissionManager::RIGOR_SECURE, $ignoreErrors = []
2482  ) {
2483  wfDeprecated( __METHOD__, '1.33' );
2484 
2485  // TODO: this is for b/c, eventually will be removed
2486  if ( $rigor === true ) {
2487  $rigor = PermissionManager::RIGOR_SECURE; // b/c
2488  } elseif ( $rigor === false ) {
2489  $rigor = PermissionManager::RIGOR_QUICK; // b/c
2490  }
2491 
2492  return MediaWikiServices::getInstance()->getPermissionManager()
2493  ->getPermissionErrors( $action, $user, $this, $rigor, $ignoreErrors );
2494  }
2495 
2503  public static function getFilteredRestrictionTypes( $exists = true ) {
2504  global $wgRestrictionTypes;
2505  $types = $wgRestrictionTypes;
2506  if ( $exists ) {
2507  # Remove the create restriction for existing titles
2508  $types = array_diff( $types, [ 'create' ] );
2509  } else {
2510  # Only the create and upload restrictions apply to non-existing titles
2511  $types = array_intersect( $types, [ 'create', 'upload' ] );
2512  }
2513  return $types;
2514  }
2515 
2521  public function getRestrictionTypes() {
2522  if ( $this->isSpecialPage() ) {
2523  return [];
2524  }
2525 
2526  $types = self::getFilteredRestrictionTypes( $this->exists() );
2527 
2528  if ( $this->mNamespace !== NS_FILE ) {
2529  # Remove the upload restriction for non-file titles
2530  $types = array_diff( $types, [ 'upload' ] );
2531  }
2532 
2533  Hooks::runner()->onTitleGetRestrictionTypes( $this, $types );
2534 
2535  wfDebug( __METHOD__ . ': applicable restrictions to [[' .
2536  $this->getPrefixedText() . ']] are {' . implode( ',', $types ) . "}" );
2537 
2538  return $types;
2539  }
2540 
2548  public function getTitleProtection() {
2549  $protection = $this->getTitleProtectionInternal();
2550  if ( $protection ) {
2551  if ( $protection['permission'] == 'sysop' ) {
2552  $protection['permission'] = 'editprotected'; // B/C
2553  }
2554  if ( $protection['permission'] == 'autoconfirmed' ) {
2555  $protection['permission'] = 'editsemiprotected'; // B/C
2556  }
2557  }
2558  return $protection;
2559  }
2560 
2571  protected function getTitleProtectionInternal() {
2572  // Can't protect pages in special namespaces
2573  if ( $this->mNamespace < 0 ) {
2574  return false;
2575  }
2576 
2577  // Can't protect pages that exist.
2578  if ( $this->exists() ) {
2579  return false;
2580  }
2581 
2582  if ( $this->mTitleProtection === null ) {
2583  $dbr = wfGetDB( DB_REPLICA );
2584  $commentStore = CommentStore::getStore();
2585  $commentQuery = $commentStore->getJoin( 'pt_reason' );
2586  $res = $dbr->select(
2587  [ 'protected_titles' ] + $commentQuery['tables'],
2588  [
2589  'user' => 'pt_user',
2590  'expiry' => 'pt_expiry',
2591  'permission' => 'pt_create_perm'
2592  ] + $commentQuery['fields'],
2593  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2594  __METHOD__,
2595  [],
2596  $commentQuery['joins']
2597  );
2598 
2599  // fetchRow returns false if there are no rows.
2600  $row = $dbr->fetchRow( $res );
2601  if ( $row ) {
2602  $this->mTitleProtection = [
2603  'user' => $row['user'],
2604  'expiry' => $dbr->decodeExpiry( $row['expiry'] ),
2605  'permission' => $row['permission'],
2606  'reason' => $commentStore->getComment( 'pt_reason', $row )->text,
2607  ];
2608  } else {
2609  $this->mTitleProtection = false;
2610  }
2611  }
2612  return $this->mTitleProtection;
2613  }
2614 
2618  public function deleteTitleProtection() {
2619  $dbw = wfGetDB( DB_MASTER );
2620 
2621  $dbw->delete(
2622  'protected_titles',
2623  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2624  __METHOD__
2625  );
2626  $this->mTitleProtection = false;
2627  }
2628 
2636  public function isSemiProtected( $action = 'edit' ) {
2638 
2639  $restrictions = $this->getRestrictions( $action );
2641  if ( !$restrictions || !$semi ) {
2642  // Not protected, or all protection is full protection
2643  return false;
2644  }
2645 
2646  // Remap autoconfirmed to editsemiprotected for BC
2647  foreach ( array_keys( $semi, 'autoconfirmed' ) as $key ) {
2648  $semi[$key] = 'editsemiprotected';
2649  }
2650  foreach ( array_keys( $restrictions, 'autoconfirmed' ) as $key ) {
2651  $restrictions[$key] = 'editsemiprotected';
2652  }
2653 
2654  return !array_diff( $restrictions, $semi );
2655  }
2656 
2664  public function isProtected( $action = '' ) {
2665  global $wgRestrictionLevels;
2666 
2667  $restrictionTypes = $this->getRestrictionTypes();
2668 
2669  # Special pages have inherent protection
2670  if ( $this->isSpecialPage() ) {
2671  return true;
2672  }
2673 
2674  # Check regular protection levels
2675  foreach ( $restrictionTypes as $type ) {
2676  if ( $action == $type || $action == '' ) {
2677  $r = $this->getRestrictions( $type );
2678  foreach ( $wgRestrictionLevels as $level ) {
2679  if ( in_array( $level, $r ) && $level != '' ) {
2680  return true;
2681  }
2682  }
2683  }
2684  }
2685 
2686  return false;
2687  }
2688 
2697  public function isNamespaceProtected( User $user ) {
2698  global $wgNamespaceProtection;
2699 
2700  if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
2701  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2702  foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
2703  if ( !$permissionManager->userHasRight( $user, $right ) ) {
2704  return true;
2705  }
2706  }
2707  }
2708  return false;
2709  }
2710 
2716  public function isCascadeProtected() {
2717  list( $isCascadeProtected, ) = $this->getCascadeProtectionSources( false );
2718  return $isCascadeProtected;
2719  }
2720 
2730  public function areCascadeProtectionSourcesLoaded( $getPages = true ) {
2731  return $getPages ? $this->mCascadeSources !== null : $this->mHasCascadingRestrictions !== null;
2732  }
2733 
2747  public function getCascadeProtectionSources( $getPages = true ) {
2748  $pagerestrictions = [];
2749 
2750  if ( $this->mCascadeSources !== null && $getPages ) {
2752  } elseif ( $this->mHasCascadingRestrictions !== null && !$getPages ) {
2753  return [ $this->mHasCascadingRestrictions, $pagerestrictions ];
2754  }
2755 
2756  $dbr = wfGetDB( DB_REPLICA );
2757 
2758  if ( $this->mNamespace === NS_FILE ) {
2759  $tables = [ 'imagelinks', 'page_restrictions' ];
2760  $where_clauses = [
2761  'il_to' => $this->mDbkeyform,
2762  'il_from=pr_page',
2763  'pr_cascade' => 1
2764  ];
2765  } else {
2766  $tables = [ 'templatelinks', 'page_restrictions' ];
2767  $where_clauses = [
2768  'tl_namespace' => $this->mNamespace,
2769  'tl_title' => $this->mDbkeyform,
2770  'tl_from=pr_page',
2771  'pr_cascade' => 1
2772  ];
2773  }
2774 
2775  if ( $getPages ) {
2776  $cols = [ 'pr_page', 'page_namespace', 'page_title',
2777  'pr_expiry', 'pr_type', 'pr_level' ];
2778  $where_clauses[] = 'page_id=pr_page';
2779  $tables[] = 'page';
2780  } else {
2781  $cols = [ 'pr_expiry' ];
2782  }
2783 
2784  $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__ );
2785 
2786  $sources = $getPages ? [] : false;
2787  $now = wfTimestampNow();
2788 
2789  foreach ( $res as $row ) {
2790  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2791  if ( $expiry > $now ) {
2792  if ( $getPages ) {
2793  $page_id = $row->pr_page;
2794  $page_ns = $row->page_namespace;
2795  $page_title = $row->page_title;
2796  $sources[$page_id] = self::makeTitle( $page_ns, $page_title );
2797  # Add groups needed for each restriction type if its not already there
2798  # Make sure this restriction type still exists
2799 
2800  if ( !isset( $pagerestrictions[$row->pr_type] ) ) {
2801  $pagerestrictions[$row->pr_type] = [];
2802  }
2803 
2804  if (
2805  isset( $pagerestrictions[$row->pr_type] )
2806  && !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] )
2807  ) {
2808  $pagerestrictions[$row->pr_type][] = $row->pr_level;
2809  }
2810  } else {
2811  $sources = true;
2812  }
2813  }
2814  }
2815 
2816  if ( $getPages ) {
2817  $this->mCascadeSources = $sources;
2818  $this->mCascadingRestrictions = $pagerestrictions;
2819  } else {
2820  $this->mHasCascadingRestrictions = $sources;
2821  }
2822 
2823  return [ $sources, $pagerestrictions ];
2824  }
2825 
2833  public function areRestrictionsLoaded() {
2835  }
2836 
2846  public function getRestrictions( $action ) {
2847  if ( !$this->mRestrictionsLoaded ) {
2848  $this->loadRestrictions();
2849  }
2850  return $this->mRestrictions[$action] ?? [];
2851  }
2852 
2860  public function getAllRestrictions() {
2861  if ( !$this->mRestrictionsLoaded ) {
2862  $this->loadRestrictions();
2863  }
2864  return $this->mRestrictions;
2865  }
2866 
2874  public function getRestrictionExpiry( $action ) {
2875  if ( !$this->mRestrictionsLoaded ) {
2876  $this->loadRestrictions();
2877  }
2878  return $this->mRestrictionsExpiry[$action] ?? false;
2879  }
2880 
2886  public function areRestrictionsCascading() {
2887  if ( !$this->mRestrictionsLoaded ) {
2888  $this->loadRestrictions();
2889  }
2890 
2892  }
2893 
2905  public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
2906  // This function will only read rows from a table that we migrated away
2907  // from before adding READ_LATEST support to loadRestrictions, so we
2908  // don't need to support reading from DB_MASTER here.
2909  $dbr = wfGetDB( DB_REPLICA );
2910 
2911  $restrictionTypes = $this->getRestrictionTypes();
2912 
2913  foreach ( $restrictionTypes as $type ) {
2914  $this->mRestrictions[$type] = [];
2915  $this->mRestrictionsExpiry[$type] = 'infinity';
2916  }
2917 
2918  $this->mCascadeRestriction = false;
2919 
2920  # Backwards-compatibility: also load the restrictions from the page record (old format).
2921  if ( $oldFashionedRestrictions !== null ) {
2922  $this->mOldRestrictions = $oldFashionedRestrictions;
2923  }
2924 
2925  if ( $this->mOldRestrictions === false ) {
2926  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2927  $linkCache->addLinkObj( $this ); # in case we already had an article ID
2928  $this->mOldRestrictions = $linkCache->getGoodLinkFieldObj( $this, 'restrictions' );
2929  }
2930 
2931  if ( $this->mOldRestrictions != '' ) {
2932  foreach ( explode( ':', trim( $this->mOldRestrictions ) ) as $restrict ) {
2933  $temp = explode( '=', trim( $restrict ) );
2934  if ( count( $temp ) == 1 ) {
2935  // old old format should be treated as edit/move restriction
2936  $this->mRestrictions['edit'] = explode( ',', trim( $temp[0] ) );
2937  $this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) );
2938  } else {
2939  $restriction = trim( $temp[1] );
2940  if ( $restriction != '' ) { // some old entries are empty
2941  $this->mRestrictions[$temp[0]] = explode( ',', $restriction );
2942  }
2943  }
2944  }
2945  }
2946 
2947  if ( count( $rows ) ) {
2948  # Current system - load second to make them override.
2949  $now = wfTimestampNow();
2950 
2951  # Cycle through all the restrictions.
2952  foreach ( $rows as $row ) {
2953  // Don't take care of restrictions types that aren't allowed
2954  if ( !in_array( $row->pr_type, $restrictionTypes ) ) {
2955  continue;
2956  }
2957 
2958  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2959 
2960  // Only apply the restrictions if they haven't expired!
2961  if ( !$expiry || $expiry > $now ) {
2962  $this->mRestrictionsExpiry[$row->pr_type] = $expiry;
2963  $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) );
2964 
2965  $this->mCascadeRestriction |= $row->pr_cascade;
2966  }
2967  }
2968  }
2969 
2970  $this->mRestrictionsLoaded = true;
2971  }
2972 
2983  public function loadRestrictions( $oldFashionedRestrictions = null, $flags = 0 ) {
2984  $readLatest = DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST );
2985  if ( $this->mRestrictionsLoaded && !$readLatest ) {
2986  return;
2987  }
2988 
2989  $id = $this->getArticleID( $flags );
2990  if ( $id ) {
2991  $fname = __METHOD__;
2992  $loadRestrictionsFromDb = function ( IDatabase $dbr ) use ( $fname, $id ) {
2993  return iterator_to_array(
2994  $dbr->select(
2995  'page_restrictions',
2996  [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
2997  [ 'pr_page' => $id ],
2998  $fname
2999  )
3000  );
3001  };
3002 
3003  if ( $readLatest ) {
3004  $dbr = wfGetDB( DB_MASTER );
3005  $rows = $loadRestrictionsFromDb( $dbr );
3006  } else {
3007  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
3008  $rows = $cache->getWithSetCallback(
3009  // Page protections always leave a new null revision
3010  $cache->makeKey( 'page-restrictions', 'v1', $id, $this->getLatestRevID() ),
3011  $cache::TTL_DAY,
3012  function ( $curValue, &$ttl, array &$setOpts ) use ( $loadRestrictionsFromDb ) {
3013  $dbr = wfGetDB( DB_REPLICA );
3014 
3015  $setOpts += Database::getCacheSetOptions( $dbr );
3016  $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
3017  if ( $lb->hasOrMadeRecentMasterChanges() ) {
3018  // @TODO: cleanup Title cache and caller assumption mess in general
3019  $ttl = WANObjectCache::TTL_UNCACHEABLE;
3020  }
3021 
3022  return $loadRestrictionsFromDb( $dbr );
3023  }
3024  );
3025  }
3026 
3027  $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
3028  } else {
3029  $title_protection = $this->getTitleProtectionInternal();
3030 
3031  if ( $title_protection ) {
3032  $now = wfTimestampNow();
3033  $expiry = wfGetDB( DB_REPLICA )->decodeExpiry( $title_protection['expiry'] );
3034 
3035  if ( !$expiry || $expiry > $now ) {
3036  // Apply the restrictions
3037  $this->mRestrictionsExpiry['create'] = $expiry;
3038  $this->mRestrictions['create'] =
3039  explode( ',', trim( $title_protection['permission'] ) );
3040  } else { // Get rid of the old restrictions
3041  $this->mTitleProtection = false;
3042  }
3043  } else {
3044  $this->mRestrictionsExpiry['create'] = 'infinity';
3045  }
3046  $this->mRestrictionsLoaded = true;
3047  }
3048  }
3049 
3054  public function flushRestrictions() {
3055  $this->mRestrictionsLoaded = false;
3056  $this->mTitleProtection = null;
3057  }
3058 
3064  public static function purgeExpiredRestrictions() {
3065  if ( wfReadOnly() ) {
3066  return;
3067  }
3068 
3070  wfGetDB( DB_MASTER ),
3071  __METHOD__,
3072  function ( IDatabase $dbw, $fname ) {
3073  $config = MediaWikiServices::getInstance()->getMainConfig();
3074  $ids = $dbw->selectFieldValues(
3075  'page_restrictions',
3076  'pr_id',
3077  [ 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3078  $fname,
3079  [ 'LIMIT' => $config->get( 'UpdateRowsPerQuery' ) ] // T135470
3080  );
3081  if ( $ids ) {
3082  $dbw->delete( 'page_restrictions', [ 'pr_id' => $ids ], $fname );
3083  }
3084  }
3085  ) );
3086 
3088  wfGetDB( DB_MASTER ),
3089  __METHOD__,
3090  function ( IDatabase $dbw, $fname ) {
3091  $dbw->delete(
3092  'protected_titles',
3093  [ 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3094  $fname
3095  );
3096  }
3097  ) );
3098  }
3099 
3105  public function hasSubpages() {
3106  if (
3107  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3108  hasSubpages( $this->mNamespace )
3109  ) {
3110  # Duh
3111  return false;
3112  }
3113 
3114  # We dynamically add a member variable for the purpose of this method
3115  # alone to cache the result. There's no point in having it hanging
3116  # around uninitialized in every Title object; therefore we only add it
3117  # if needed and don't declare it statically.
3118  if ( $this->mHasSubpages === null ) {
3119  $this->mHasSubpages = false;
3120  $subpages = $this->getSubpages( 1 );
3121  if ( $subpages instanceof TitleArray ) {
3122  $this->mHasSubpages = (bool)$subpages->current();
3123  }
3124  }
3125 
3126  return $this->mHasSubpages;
3127  }
3128 
3136  public function getSubpages( $limit = -1 ) {
3137  if (
3138  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3139  hasSubpages( $this->mNamespace )
3140  ) {
3141  return [];
3142  }
3143 
3144  $dbr = wfGetDB( DB_REPLICA );
3145  $conds = [ 'page_namespace' => $this->mNamespace ];
3146  $conds[] = 'page_title ' . $dbr->buildLike( $this->mDbkeyform . '/', $dbr->anyString() );
3147  $options = [];
3148  if ( $limit > -1 ) {
3149  $options['LIMIT'] = $limit;
3150  }
3152  $dbr->select( 'page',
3153  [ 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ],
3154  $conds,
3155  __METHOD__,
3156  $options
3157  )
3158  );
3159  }
3160 
3166  public function isDeleted() {
3167  if ( $this->mNamespace < 0 ) {
3168  $n = 0;
3169  } else {
3170  $dbr = wfGetDB( DB_REPLICA );
3171 
3172  $n = $dbr->selectField( 'archive', 'COUNT(*)',
3173  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3174  __METHOD__
3175  );
3176  if ( $this->mNamespace === NS_FILE ) {
3177  $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
3178  [ 'fa_name' => $this->mDbkeyform ],
3179  __METHOD__
3180  );
3181  }
3182  }
3183  return (int)$n;
3184  }
3185 
3191  public function isDeletedQuick() {
3192  if ( $this->mNamespace < 0 ) {
3193  return false;
3194  }
3195  $dbr = wfGetDB( DB_REPLICA );
3196  $deleted = (bool)$dbr->selectField( 'archive', '1',
3197  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3198  __METHOD__
3199  );
3200  if ( !$deleted && $this->mNamespace === NS_FILE ) {
3201  $deleted = (bool)$dbr->selectField( 'filearchive', '1',
3202  [ 'fa_name' => $this->mDbkeyform ],
3203  __METHOD__
3204  );
3205  }
3206  return $deleted;
3207  }
3208 
3216  public function getArticleID( $flags = 0 ) {
3217  if ( $this->mNamespace < 0 ) {
3218  $this->mArticleID = 0;
3219 
3220  return $this->mArticleID;
3221  }
3222 
3223  if ( $flags & self::GAID_FOR_UPDATE ) {
3224  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3225  $oldUpdate = $linkCache->forUpdate( true );
3226  $linkCache->clearLink( $this );
3227  $this->mArticleID = $linkCache->addLinkObj( $this );
3228  $linkCache->forUpdate( $oldUpdate );
3229  } elseif ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3230  // If mArticleID is >0, pageCond() will use it, making it impossible
3231  // for the call below to return a different result, e.g. after a
3232  // page move.
3233  $this->mArticleID = -1;
3234  $this->mArticleID = (int)$this->loadFieldFromDB( 'page_id', $flags );
3235  } elseif ( $this->mArticleID == -1 ) {
3236  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3237  $this->mArticleID = $linkCache->addLinkObj( $this );
3238  }
3239 
3240  return $this->mArticleID;
3241  }
3242 
3250  public function isRedirect( $flags = 0 ) {
3251  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3252  $this->mRedirect = (bool)$this->loadFieldFromDB( 'page_is_redirect', $flags );
3253  } elseif ( $this->mRedirect === null ) {
3254  if ( $this->getArticleID( $flags ) ) {
3255  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3256  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3257  // Note that LinkCache returns null if it thinks the page does not exist;
3258  // always trust the state of LinkCache over that of this Title instance.
3259  $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
3260  } else {
3261  $this->mRedirect = false;
3262  }
3263  }
3264 
3265  return $this->mRedirect;
3266  }
3267 
3275  public function getLength( $flags = 0 ) {
3276  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3277  $this->mLength = (int)$this->loadFieldFromDB( 'page_len', $flags );
3278  } else {
3279  if ( $this->mLength != -1 ) {
3280  return $this->mLength;
3281  } elseif ( !$this->getArticleID( $flags ) ) {
3282  $this->mLength = 0;
3283  return $this->mLength;
3284  }
3285 
3286  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3287  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3288  // Note that LinkCache returns null if it thinks the page does not exist;
3289  // always trust the state of LinkCache over that of this Title instance.
3290  $this->mLength = (int)$linkCache->getGoodLinkFieldObj( $this, 'length' );
3291  }
3292 
3293  return $this->mLength;
3294  }
3295 
3302  public function getLatestRevID( $flags = 0 ) {
3303  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3304  $this->mLatestID = (int)$this->loadFieldFromDB( 'page_latest', $flags );
3305  } else {
3306  if ( $this->mLatestID !== false ) {
3307  return (int)$this->mLatestID;
3308  } elseif ( !$this->getArticleID( $flags ) ) {
3309  $this->mLatestID = 0;
3310 
3311  return $this->mLatestID;
3312  }
3313 
3314  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3315  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3316  // Note that LinkCache returns null if it thinks the page does not exist;
3317  // always trust the state of LinkCache over that of this Title instance.
3318  $this->mLatestID = (int)$linkCache->getGoodLinkFieldObj( $this, 'revision' );
3319  }
3320 
3321  return $this->mLatestID;
3322  }
3323 
3337  public function resetArticleID( $id ) {
3338  if ( $id === false ) {
3339  $this->mArticleID = -1;
3340  } else {
3341  $this->mArticleID = (int)$id;
3342  }
3343  $this->mRestrictionsLoaded = false;
3344  $this->mRestrictions = [];
3345  $this->mOldRestrictions = false;
3346  $this->mRedirect = null;
3347  $this->mLength = -1;
3348  $this->mLatestID = false;
3349  $this->mContentModel = false;
3350  $this->mForcedContentModel = false;
3351  $this->mEstimateRevisions = null;
3352  $this->mPageLanguage = null;
3353  $this->mDbPageLanguage = false;
3354  $this->mIsBigDeletion = null;
3355 
3356  MediaWikiServices::getInstance()->getLinkCache()->clearLink( $this );
3357  }
3358 
3359  public static function clearCaches() {
3360  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3361  $linkCache->clear();
3362 
3364  $titleCache->clear();
3365  }
3366 
3374  public static function capitalize( $text, $ns = NS_MAIN ) {
3375  $services = MediaWikiServices::getInstance();
3376  if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) {
3377  return $services->getContentLanguage()->ucfirst( $text );
3378  } else {
3379  return $text;
3380  }
3381  }
3382 
3399  private function secureAndSplit( $text, $defaultNamespace = null ) {
3400  if ( $defaultNamespace === null ) {
3401  $defaultNamespace = $this->mDefaultNamespace;
3402  }
3403 
3404  // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
3405  // the parsing code with Title, while avoiding massive refactoring.
3406  // @todo: get rid of secureAndSplit, refactor parsing code.
3407  // @note: getTitleParser() returns a TitleParser implementation which does not have a
3408  // splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
3410  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
3411  '@phan-var MediaWikiTitleCodec $titleCodec';
3412  // MalformedTitleException can be thrown here
3413  $parts = $titleCodec->splitTitleString( $text, $defaultNamespace );
3414 
3415  # Fill fields
3416  $this->setFragment( '#' . $parts['fragment'] );
3417  $this->mInterwiki = $parts['interwiki'];
3418  $this->mLocalInterwiki = $parts['local_interwiki'];
3419  $this->mNamespace = $parts['namespace'];
3420  $this->mDefaultNamespace = $defaultNamespace;
3421 
3422  $this->mDbkeyform = $parts['dbkey'];
3423  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
3424  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
3425 
3426  // splitTitleString() guarantees that this title is valid.
3427  $this->mIsValid = true;
3428 
3429  # We already know that some pages won't be in the database!
3430  if ( $this->isExternal() || $this->isSpecialPage() || $this->mTextform === '' ) {
3431  $this->mArticleID = 0;
3432  }
3433  }
3434 
3447  public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3448  if ( count( $options ) > 0 ) {
3449  $db = wfGetDB( DB_MASTER );
3450  } else {
3451  $db = wfGetDB( DB_REPLICA );
3452  }
3453 
3454  $res = $db->select(
3455  [ 'page', $table ],
3456  self::getSelectFields(),
3457  [
3458  "{$prefix}_from=page_id",
3459  "{$prefix}_namespace" => $this->mNamespace,
3460  "{$prefix}_title" => $this->mDbkeyform ],
3461  __METHOD__,
3462  $options
3463  );
3464 
3465  $retVal = [];
3466  if ( $res->numRows() ) {
3467  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3468  foreach ( $res as $row ) {
3469  $titleObj = self::makeTitle( $row->page_namespace, $row->page_title );
3470  if ( $titleObj ) {
3471  $linkCache->addGoodLinkObjFromRow( $titleObj, $row );
3472  $retVal[] = $titleObj;
3473  }
3474  }
3475  }
3476  return $retVal;
3477  }
3478 
3489  public function getTemplateLinksTo( $options = [] ) {
3490  return $this->getLinksTo( $options, 'templatelinks', 'tl' );
3491  }
3492 
3505  public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3506  $id = $this->getArticleID();
3507 
3508  # If the page doesn't exist; there can't be any link from this page
3509  if ( !$id ) {
3510  return [];
3511  }
3512 
3513  $db = wfGetDB( DB_REPLICA );
3514 
3515  $blNamespace = "{$prefix}_namespace";
3516  $blTitle = "{$prefix}_title";
3517 
3518  $pageQuery = WikiPage::getQueryInfo();
3519  $res = $db->select(
3520  [ $table, 'nestpage' => $pageQuery['tables'] ],
3521  array_merge(
3522  [ $blNamespace, $blTitle ],
3523  $pageQuery['fields']
3524  ),
3525  [ "{$prefix}_from" => $id ],
3526  __METHOD__,
3527  $options,
3528  [ 'nestpage' => [
3529  'LEFT JOIN',
3530  [ "page_namespace=$blNamespace", "page_title=$blTitle" ]
3531  ] ] + $pageQuery['joins']
3532  );
3533 
3534  $retVal = [];
3535  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3536  foreach ( $res as $row ) {
3537  if ( $row->page_id ) {
3538  $titleObj = self::newFromRow( $row );
3539  } else {
3540  $titleObj = self::makeTitle( $row->$blNamespace, $row->$blTitle );
3541  $linkCache->addBadLinkObj( $titleObj );
3542  }
3543  $retVal[] = $titleObj;
3544  }
3545 
3546  return $retVal;
3547  }
3548 
3559  public function getTemplateLinksFrom( $options = [] ) {
3560  return $this->getLinksFrom( $options, 'templatelinks', 'tl' );
3561  }
3562 
3571  public function getBrokenLinksFrom() {
3572  if ( $this->getArticleID() == 0 ) {
3573  # All links from article ID 0 are false positives
3574  return [];
3575  }
3576 
3577  $dbr = wfGetDB( DB_REPLICA );
3578  $res = $dbr->select(
3579  [ 'page', 'pagelinks' ],
3580  [ 'pl_namespace', 'pl_title' ],
3581  [
3582  'pl_from' => $this->getArticleID(),
3583  'page_namespace IS NULL'
3584  ],
3585  __METHOD__, [],
3586  [
3587  'page' => [
3588  'LEFT JOIN',
3589  [ 'pl_namespace=page_namespace', 'pl_title=page_title' ]
3590  ]
3591  ]
3592  );
3593 
3594  $retVal = [];
3595  foreach ( $res as $row ) {
3596  $retVal[] = self::makeTitle( $row->pl_namespace, $row->pl_title );
3597  }
3598  return $retVal;
3599  }
3600 
3607  public function getCdnUrls() {
3608  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3609  return $htmlCache->getUrls( $this );
3610  }
3611 
3616  public function purgeSquid() {
3617  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3618  $htmlCache->purgeTitleUrls( $this, $htmlCache::PURGE_INTENT_TXROUND_REFLECTED );
3619  }
3620 
3628  public function isSingleRevRedirect() {
3629  $dbw = wfGetDB( DB_MASTER );
3630  $dbw->startAtomic( __METHOD__ );
3631 
3632  $row = $dbw->selectRow(
3633  'page',
3634  self::getSelectFields(),
3635  $this->pageCond(),
3636  __METHOD__,
3637  [ 'FOR UPDATE' ]
3638  );
3639  // Update the cached fields
3640  $this->loadFromRow( $row );
3641 
3642  if ( $this->mRedirect && $this->mLatestID ) {
3643  $isSingleRevRedirect = !$dbw->selectField(
3644  'revision',
3645  '1',
3646  [ 'rev_page' => $this->mArticleID, 'rev_id != ' . (int)$this->mLatestID ],
3647  __METHOD__,
3648  [ 'FOR UPDATE' ]
3649  );
3650  } else {
3651  $isSingleRevRedirect = false;
3652  }
3653 
3654  $dbw->endAtomic( __METHOD__ );
3655 
3656  return $isSingleRevRedirect;
3657  }
3658 
3666  public function getParentCategories() {
3667  $data = [];
3668 
3669  $titleKey = $this->getArticleID();
3670 
3671  if ( $titleKey === 0 ) {
3672  return $data;
3673  }
3674 
3675  $dbr = wfGetDB( DB_REPLICA );
3676 
3677  $res = $dbr->select(
3678  'categorylinks',
3679  'cl_to',
3680  [ 'cl_from' => $titleKey ],
3681  __METHOD__
3682  );
3683 
3684  if ( $res->numRows() > 0 ) {
3685  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
3686  foreach ( $res as $row ) {
3687  // $data[] = Title::newFromText( $contLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
3688  $data[$contLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] =
3689  $this->getFullText();
3690  }
3691  }
3692  return $data;
3693  }
3694 
3701  public function getParentCategoryTree( $children = [] ) {
3702  $stack = [];
3703  $parents = $this->getParentCategories();
3704 
3705  if ( $parents ) {
3706  foreach ( $parents as $parent => $current ) {
3707  if ( array_key_exists( $parent, $children ) ) {
3708  # Circular reference
3709  $stack[$parent] = [];
3710  } else {
3711  $nt = self::newFromText( $parent );
3712  if ( $nt ) {
3713  $stack[$parent] = $nt->getParentCategoryTree( $children + [ $parent => 1 ] );
3714  }
3715  }
3716  }
3717  }
3718 
3719  return $stack;
3720  }
3721 
3728  public function pageCond() {
3729  if ( $this->mArticleID > 0 ) {
3730  // PK avoids secondary lookups in InnoDB, shouldn't hurt other DBs
3731  return [ 'page_id' => $this->mArticleID ];
3732  } else {
3733  return [ 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform ];
3734  }
3735  }
3736 
3744  private function getRelativeRevisionID( $revId, $flags, $dir ) {
3745  $rl = MediaWikiServices::getInstance()->getRevisionLookup();
3746  $rev = $rl->getRevisionById( $revId, $flags );
3747  if ( !$rev ) {
3748  return false;
3749  }
3750 
3751  $oldRev = ( $dir === 'next' )
3752  ? $rl->getNextRevision( $rev, $flags )
3753  : $rl->getPreviousRevision( $rev, $flags );
3754 
3755  return $oldRev ? $oldRev->getId() : false;
3756  }
3757 
3766  public function getPreviousRevisionID( $revId, $flags = 0 ) {
3767  return $this->getRelativeRevisionID( $revId, $flags, 'prev' );
3768  }
3769 
3778  public function getNextRevisionID( $revId, $flags = 0 ) {
3779  return $this->getRelativeRevisionID( $revId, $flags, 'next' );
3780  }
3781 
3789  public function getFirstRevision( $flags = 0 ) {
3790  wfDeprecated( __METHOD__, '1.35' );
3791  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
3792  $rev = MediaWikiServices::getInstance()
3793  ->getRevisionLookup()
3794  ->getFirstRevision( $this, $flags );
3795  return $rev ? new Revision( $rev ) : null;
3796  }
3797 
3805  public function getEarliestRevTime( $flags = 0 ) {
3806  $rev = MediaWikiServices::getInstance()
3807  ->getRevisionLookup()
3808  ->getFirstRevision( $this, $flags );
3809  return $rev ? $rev->getTimestamp() : null;
3810  }
3811 
3817  public function isNewPage() {
3818  $dbr = wfGetDB( DB_REPLICA );
3819  return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ );
3820  }
3821 
3827  public function isBigDeletion() {
3828  global $wgDeleteRevisionsLimit;
3829 
3830  if ( !$wgDeleteRevisionsLimit ) {
3831  return false;
3832  }
3833 
3834  if ( $this->mIsBigDeletion === null ) {
3835  $dbr = wfGetDB( DB_REPLICA );
3836 
3837  $revCount = $dbr->selectRowCount(
3838  'revision',
3839  '1',
3840  [ 'rev_page' => $this->getArticleID() ],
3841  __METHOD__,
3842  [ 'LIMIT' => $wgDeleteRevisionsLimit + 1 ]
3843  );
3844 
3845  $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit;
3846  }
3847 
3848  return $this->mIsBigDeletion;
3849  }
3850 
3856  public function estimateRevisionCount() {
3857  if ( !$this->exists() ) {
3858  return 0;
3859  }
3860 
3861  if ( $this->mEstimateRevisions === null ) {
3862  $dbr = wfGetDB( DB_REPLICA );
3863  $this->mEstimateRevisions = $dbr->estimateRowCount( 'revision', '*',
3864  [ 'rev_page' => $this->getArticleID() ], __METHOD__ );
3865  }
3866 
3868  }
3869 
3881  public function countRevisionsBetween( $old, $new, $max = null ) {
3882  wfDeprecated( __METHOD__, '1.35' );
3883  if ( !( $old instanceof Revision ) ) {
3884  $old = Revision::newFromTitle( $this, (int)$old );
3885  }
3886  if ( !( $new instanceof Revision ) ) {
3887  $new = Revision::newFromTitle( $this, (int)$new );
3888  }
3889  if ( !$old || !$new ) {
3890  return 0; // nothing to compare
3891  }
3892  return MediaWikiServices::getInstance()
3893  ->getRevisionStore()
3894  ->countRevisionsBetween(
3895  $this->getArticleID(),
3896  $old->getRevisionRecord(),
3897  $new->getRevisionRecord(),
3898  $max
3899  );
3900  }
3901 
3919  public function getAuthorsBetween( $old, $new, $limit, $options = [] ) {
3920  wfDeprecated( __METHOD__, '1.35' );
3921  if ( !( $old instanceof Revision ) ) {
3922  $old = Revision::newFromTitle( $this, (int)$old );
3923  }
3924  if ( !( $new instanceof Revision ) ) {
3925  $new = Revision::newFromTitle( $this, (int)$new );
3926  }
3927  try {
3928  $users = MediaWikiServices::getInstance()
3929  ->getRevisionStore()
3930  ->getAuthorsBetween(
3931  $this->getArticleID(),
3932  $old->getRevisionRecord(),
3933  $new->getRevisionRecord(),
3934  null,
3935  $limit,
3936  $options
3937  );
3938  return array_map( function ( UserIdentity $user ) {
3939  return $user->getName();
3940  }, $users );
3941  } catch ( InvalidArgumentException $e ) {
3942  return null; // b/c
3943  }
3944  }
3945 
3962  public function countAuthorsBetween( $old, $new, $limit, $options = [] ) {
3963  wfDeprecated( __METHOD__, '1.35' );
3964  $authors = $this->getAuthorsBetween( $old, $new, $limit, $options );
3965  return $authors ? count( $authors ) : 0;
3966  }
3967 
3974  public function equals( LinkTarget $title ) {
3975  // Note: === is necessary for proper matching of number-like titles.
3976  return $this->mInterwiki === $title->getInterwiki()
3977  && $this->mNamespace == $title->getNamespace()
3978  && $this->mDbkeyform === $title->getDBkey();
3979  }
3980 
3987  public function isSubpageOf( Title $title ) {
3988  return $this->mInterwiki === $title->mInterwiki
3989  && $this->mNamespace == $title->mNamespace
3990  && strpos( $this->mDbkeyform, $title->mDbkeyform . '/' ) === 0;
3991  }
3992 
4003  public function exists( $flags = 0 ) {
4004  $exists = $this->getArticleID( $flags ) != 0;
4005  Hooks::runner()->onTitleExists( $this, $exists );
4006  return $exists;
4007  }
4008 
4025  public function isAlwaysKnown() {
4026  $isKnown = null;
4027 
4038  Hooks::runner()->onTitleIsAlwaysKnown( $this, $isKnown );
4039 
4040  if ( $isKnown !== null ) {
4041  return $isKnown;
4042  }
4043 
4044  if ( $this->isExternal() ) {
4045  return true; // any interwiki link might be viewable, for all we know
4046  }
4047 
4048  $services = MediaWikiServices::getInstance();
4049  switch ( $this->mNamespace ) {
4050  case NS_MEDIA:
4051  case NS_FILE:
4052  // file exists, possibly in a foreign repo
4053  return (bool)$services->getRepoGroup()->findFile( $this );
4054  case NS_SPECIAL:
4055  // valid special page
4056  return $services->getSpecialPageFactory()->exists( $this->mDbkeyform );
4057  case NS_MAIN:
4058  // selflink, possibly with fragment
4059  return $this->mDbkeyform == '';
4060  case NS_MEDIAWIKI:
4061  // known system message
4062  return $this->hasSourceText() !== false;
4063  default:
4064  return false;
4065  }
4066  }
4067 
4079  public function isKnown() {
4080  return $this->isAlwaysKnown() || $this->exists();
4081  }
4082 
4088  public function hasSourceText() {
4089  if ( $this->exists() ) {
4090  return true;
4091  }
4092 
4093  if ( $this->mNamespace === NS_MEDIAWIKI ) {
4094  $services = MediaWikiServices::getInstance();
4095  // If the page doesn't exist but is a known system message, default
4096  // message content will be displayed, same for language subpages-
4097  // Use always content language to avoid loading hundreds of languages
4098  // to get the link color.
4099  $contLang = $services->getContentLanguage();
4100  list( $name, ) = $services->getMessageCache()->figureMessage(
4101  $contLang->lcfirst( $this->getText() )
4102  );
4103  $message = wfMessage( $name )->inLanguage( $contLang )->useDatabase( false );
4104  return $message->exists();
4105  }
4106 
4107  return false;
4108  }
4109 
4147  public function getDefaultMessageText() {
4148  if ( $this->mNamespace !== NS_MEDIAWIKI ) { // Just in case
4149  return false;
4150  }
4151 
4152  list( $name, $lang ) = MediaWikiServices::getInstance()->getMessageCache()->figureMessage(
4153  MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $this->getText() )
4154  );
4155  $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
4156 
4157  if ( $message->exists() ) {
4158  return $message->plain();
4159  } else {
4160  return false;
4161  }
4162  }
4163 
4170  public function invalidateCache( $purgeTime = null ) {
4171  if ( wfReadOnly() ) {
4172  return false;
4173  }
4174  if ( $this->mArticleID === 0 ) {
4175  // avoid gap locking if we know it's not there
4176  return true;
4177  }
4178 
4179  $conds = $this->pageCond();
4181  new AutoCommitUpdate(
4182  wfGetDB( DB_MASTER ),
4183  __METHOD__,
4184  function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) {
4185  $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
4186  $dbw->update(
4187  'page',
4188  [ 'page_touched' => $dbTimestamp ],
4189  $conds + [ 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ],
4190  $fname
4191  );
4192 
4193  MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $this );
4194 
4196  $this, null, null, $dbw->getDomainID() );
4197  }
4198  ),
4200  );
4201 
4202  return true;
4203  }
4204 
4210  public function touchLinks() {
4211  $jobs = [];
4213  $this,
4214  'pagelinks',
4215  [ 'causeAction' => 'page-touch' ]
4216  );
4217  if ( $this->mNamespace === NS_CATEGORY ) {
4219  $this,
4220  'categorylinks',
4221  [ 'causeAction' => 'category-touch' ]
4222  );
4223  }
4224 
4225  JobQueueGroup::singleton()->lazyPush( $jobs );
4226  }
4227 
4234  public function getTouched( $db = null ) {
4235  if ( $db === null ) {
4236  $db = wfGetDB( DB_REPLICA );
4237  }
4238  $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ );
4239  return $touched;
4240  }
4241 
4250  public function getNotificationTimestamp( $user = null ) {
4251  // Assume current user if none given
4252  if ( !$user ) {
4253  wfDeprecated( __METHOD__ . ' without passing a $user parameter', '1.35' );
4254  global $wgUser;
4255  $user = $wgUser;
4256  }
4257 
4258  return MediaWikiServices::getInstance()
4259  ->getWatchlistNotificationManager()
4260  ->getTitleNotificationTimestamp( $user, $this );
4261  }
4262 
4269  public function getNamespaceKey( $prepend = 'nstab-' ) {
4270  // Gets the subject namespace of this title
4271  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
4272  $subjectNS = $nsInfo->getSubject( $this->mNamespace );
4273  // Prefer canonical namespace name for HTML IDs
4274  $namespaceKey = $nsInfo->getCanonicalName( $subjectNS );
4275  if ( $namespaceKey === false ) {
4276  // Fallback to localised text
4277  $namespaceKey = $this->getSubjectNsText();
4278  }
4279  // Makes namespace key lowercase
4280  $namespaceKey = MediaWikiServices::getInstance()->getContentLanguage()->lc( $namespaceKey );
4281  // Uses main
4282  if ( $namespaceKey == '' ) {
4283  $namespaceKey = 'main';
4284  }
4285  // Changes file to image for backwards compatibility
4286  if ( $namespaceKey == 'file' ) {
4287  $namespaceKey = 'image';
4288  }
4289  return $prepend . $namespaceKey;
4290  }
4291 
4298  public function getRedirectsHere( $ns = null ) {
4299  $redirs = [];
4300 
4301  $dbr = wfGetDB( DB_REPLICA );
4302  $where = [
4303  'rd_namespace' => $this->mNamespace,
4304  'rd_title' => $this->mDbkeyform,
4305  'rd_from = page_id'
4306  ];
4307  if ( $this->isExternal() ) {
4308  $where['rd_interwiki'] = $this->mInterwiki;
4309  } else {
4310  $where[] = 'rd_interwiki = ' . $dbr->addQuotes( '' ) . ' OR rd_interwiki IS NULL';
4311  }
4312  if ( $ns !== null ) {
4313  $where['page_namespace'] = $ns;
4314  }
4315 
4316  $res = $dbr->select(
4317  [ 'redirect', 'page' ],
4318  [ 'page_namespace', 'page_title' ],
4319  $where,
4320  __METHOD__
4321  );
4322 
4323  foreach ( $res as $row ) {
4324  $redirs[] = self::newFromRow( $row );
4325  }
4326  return $redirs;
4327  }
4328 
4334  public function isValidRedirectTarget() {
4336 
4337  if ( $this->isSpecialPage() ) {
4338  // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
4339  if ( $this->isSpecial( 'Userlogout' ) ) {
4340  return false;
4341  }
4342 
4343  foreach ( $wgInvalidRedirectTargets as $target ) {
4344  if ( $this->isSpecial( $target ) ) {
4345  return false;
4346  }
4347  }
4348  }
4349 
4350  return true;
4351  }
4352 
4358  public function getBacklinkCache() {
4359  return BacklinkCache::get( $this );
4360  }
4361 
4367  public function canUseNoindex() {
4369 
4370  $bannedNamespaces = $wgExemptFromUserRobotsControl ??
4371  MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
4372 
4373  return !in_array( $this->mNamespace, $bannedNamespaces );
4374  }
4375 
4386  public function getCategorySortkey( $prefix = '' ) {
4387  $unprefixed = $this->getText();
4388 
4389  // Anything that uses this hook should only depend
4390  // on the Title object passed in, and should probably
4391  // tell the users to run updateCollations.php --force
4392  // in order to re-sort existing category relations.
4393  Hooks::runner()->onGetDefaultSortkey( $this, $unprefixed );
4394  if ( $prefix !== '' ) {
4395  # Separate with a line feed, so the unprefixed part is only used as
4396  # a tiebreaker when two pages have the exact same prefix.
4397  # In UCA, tab is the only character that can sort above LF
4398  # so we strip both of them from the original prefix.
4399  $prefix = strtr( $prefix, "\n\t", ' ' );
4400  return "$prefix\n$unprefixed";
4401  }
4402  return $unprefixed;
4403  }
4404 
4412  private function getDbPageLanguageCode() {
4413  global $wgPageLanguageUseDB;
4414 
4415  // check, if the page language could be saved in the database, and if so and
4416  // the value is not requested already, lookup the page language using LinkCache
4417  if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) {
4418  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
4419  $linkCache->addLinkObj( $this );
4420  $this->mDbPageLanguage = $linkCache->getGoodLinkFieldObj( $this, 'lang' );
4421  }
4422 
4423  return $this->mDbPageLanguage;
4424  }
4425 
4434  public function getPageLanguage() {
4435  global $wgLang, $wgLanguageCode;
4436  if ( $this->isSpecialPage() ) {
4437  // special pages are in the user language
4438  return $wgLang;
4439  }
4440 
4441  // Checking if DB language is set
4442  $dbPageLanguage = $this->getDbPageLanguageCode();
4443  if ( $dbPageLanguage ) {
4444  return wfGetLangObj( $dbPageLanguage );
4445  }
4446 
4447  if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) {
4448  // Note that this may depend on user settings, so the cache should
4449  // be only per-request.
4450  // NOTE: ContentHandler::getPageLanguage() may need to load the
4451  // content to determine the page language!
4452  // Checking $wgLanguageCode hasn't changed for the benefit of unit
4453  // tests.
4454  $contentHandler = MediaWikiServices::getInstance()
4455  ->getContentHandlerFactory()
4456  ->getContentHandler( $this->getContentModel() );
4457  $langObj = $contentHandler->getPageLanguage( $this );
4458  $this->mPageLanguage = [ $langObj->getCode(), $wgLanguageCode ];
4459  } else {
4460  $langObj = MediaWikiServices::getInstance()->getLanguageFactory()
4461  ->getLanguage( $this->mPageLanguage[0] );
4462  }
4463 
4464  return $langObj;
4465  }
4466 
4475  public function getPageViewLanguage() {
4476  global $wgLang;
4477 
4478  if ( $this->isSpecialPage() ) {
4479  // If the user chooses a variant, the content is actually
4480  // in a language whose code is the variant code.
4481  $variant = $this->getLanguageConverter( $wgLang )->getPreferredVariant();
4482  if ( $wgLang->getCode() !== $variant ) {
4483  return MediaWikiServices::getInstance()->getLanguageFactory()
4484  ->getLanguage( $variant );
4485  }
4486 
4487  return $wgLang;
4488  }
4489 
4490  // Checking if DB language is set
4491  $dbPageLanguage = $this->getDbPageLanguageCode();
4492  if ( $dbPageLanguage ) {
4493  $pageLang = wfGetLangObj( $dbPageLanguage );
4494  $variant = $this->getLanguageConverter( $pageLang )->getPreferredVariant();
4495  if ( $pageLang->getCode() !== $variant ) {
4496  $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()
4497  ->getLanguage( $variant );
4498  }
4499 
4500  return $pageLang;
4501  }
4502 
4503  // @note Can't be cached persistently, depends on user settings.
4504  // @note ContentHandler::getPageViewLanguage() may need to load the
4505  // content to determine the page language!
4506  $contentHandler = MediaWikiServices::getInstance()
4507  ->getContentHandlerFactory()
4508  ->getContentHandler( $this->getContentModel() );
4509  $pageLang = $contentHandler->getPageViewLanguage( $this );
4510  return $pageLang;
4511  }
4512 
4523  public function getEditNotices( $oldid = 0 ) {
4524  $notices = [];
4525 
4526  // Optional notice for the entire namespace
4527  $editnotice_ns = 'editnotice-' . $this->mNamespace;
4528  $msg = wfMessage( $editnotice_ns );
4529  if ( $msg->exists() ) {
4530  $html = $msg->parseAsBlock();
4531  // Edit notices may have complex logic, but output nothing (T91715)
4532  if ( trim( $html ) !== '' ) {
4533  $notices[$editnotice_ns] = Html::rawElement(
4534  'div',
4535  [ 'class' => [
4536  'mw-editnotice',
4537  'mw-editnotice-namespace',
4538  Sanitizer::escapeClass( "mw-$editnotice_ns" )
4539  ] ],
4540  $html
4541  );
4542  }
4543  }
4544 
4545  if (
4546  MediaWikiServices::getInstance()->getNamespaceInfo()->
4547  hasSubpages( $this->mNamespace )
4548  ) {
4549  // Optional notice for page itself and any parent page
4550  $editnotice_base = $editnotice_ns;
4551  foreach ( explode( '/', $this->mDbkeyform ) as $part ) {
4552  $editnotice_base .= '-' . $part;
4553  $msg = wfMessage( $editnotice_base );
4554  if ( $msg->exists() ) {
4555  $html = $msg->parseAsBlock();
4556  if ( trim( $html ) !== '' ) {
4557  $notices[$editnotice_base] = Html::rawElement(
4558  'div',
4559  [ 'class' => [
4560  'mw-editnotice',
4561  'mw-editnotice-base',
4562  Sanitizer::escapeClass( "mw-$editnotice_base" )
4563  ] ],
4564  $html
4565  );
4566  }
4567  }
4568  }
4569  } else {
4570  // Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
4571  $editnoticeText = $editnotice_ns . '-' . strtr( $this->mDbkeyform, '/', '-' );
4572  $msg = wfMessage( $editnoticeText );
4573  if ( $msg->exists() ) {
4574  $html = $msg->parseAsBlock();
4575  if ( trim( $html ) !== '' ) {
4576  $notices[$editnoticeText] = Html::rawElement(
4577  'div',
4578  [ 'class' => [
4579  'mw-editnotice',
4580  'mw-editnotice-page',
4581  Sanitizer::escapeClass( "mw-$editnoticeText" )
4582  ] ],
4583  $html
4584  );
4585  }
4586  }
4587  }
4588 
4589  Hooks::runner()->onTitleGetEditNotices( $this, $oldid, $notices );
4590  return $notices;
4591  }
4592 
4598  private function loadFieldFromDB( $field, $flags ) {
4599  if ( !in_array( $field, self::getSelectFields(), true ) ) {
4600  return false; // field does not exist
4601  }
4602 
4603  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
4604  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
4605 
4606  return wfGetDB( $index )->selectField(
4607  'page',
4608  $field,
4609  $this->pageCond(),
4610  __METHOD__,
4611  $options
4612  );
4613  }
4614 
4618  public function __sleep() {
4619  return [
4620  'mNamespace',
4621  'mDbkeyform',
4622  'mFragment',
4623  'mInterwiki',
4624  'mLocalInterwiki',
4625  'mDefaultNamespace',
4626  ];
4627  }
4628 
4629  public function __wakeup() {
4630  $this->mArticleID = ( $this->mNamespace >= 0 ) ? -1 : 0;
4631  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
4632  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
4633  }
4634 
4635 }
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:1172
Title\getTitleProtection
getTitleProtection()
Is this title subject to title protection? Title protection is the one applied against creation of su...
Definition: Title.php:2548
Title\canUseNoindex
canUseNoindex()
Whether the magic words INDEX and NOINDEX function for this page.
Definition: Title.php:4367
Title\getLocalURL
getLocalURL( $query='', $query2=false)
Get a URL with no fragment or server name (relative URL) from a Title object.
Definition: Title.php:2228
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:228
Title\isSemiProtected
isSemiProtected( $action='edit')
Is this page "semi-protected" - the only protection levels are listed in $wgSemiprotectedRestrictionL...
Definition: Title.php:2636
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:50
Title\isNamespaceProtected
isNamespaceProtected(User $user)
Determines if $user is unable to edit this page because it has been protected by $wgNamespaceProtecti...
Definition: Title.php:2697
Title\getTalkNsText
getTalkNsText()
Get the namespace text of the talk page.
Definition: Title.php:1155
Title\getSubpageText
getSubpageText()
Get the lowest-level subpage name, i.e.
Definition: Title.php:2052
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:329
Title\isBigDeletion
isBigDeletion()
Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit.
Definition: Title.php:3827
Title\getNextRevisionID
getNextRevisionID( $revId, $flags=0)
Get the revision ID of the next revision.
Definition: Title.php:3778
PROTO_CANONICAL
const PROTO_CANONICAL
Definition: Defines.php:212
Title\areCascadeProtectionSourcesLoaded
areCascadeProtectionSourcesLoaded( $getPages=true)
Determines whether cascading protection sources have already been loaded from the database.
Definition: Title.php:2730
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:2503
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:820
Title\getInternalURL
getInternalURL( $query='', $query2=false)
Get the URL form for an internal link.
Definition: Title.php:2353
Title\getFragment
getFragment()
Get the Title fragment (i.e.
Definition: Title.php:1739
$wgExemptFromUserRobotsControl
$wgExemptFromUserRobotsControl
An array of namespace keys in which the INDEX/__NOINDEX__ magic words will not function,...
Definition: DefaultSettings.php:8499
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:1631
Title\inNamespace
inNamespace( $ns)
Returns true if the title is inside the specified namespace.
Definition: Title.php:1293
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:1355
Title\wasLocalInterwiki
wasLocalInterwiki()
Was this a local interwiki link?
Definition: Title.php:942
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:154
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
Title\inNamespaces
inNamespaces(... $namespaces)
Returns true if the title is inside one of the specified namespaces.
Definition: Title.php:1305
Title\isWikitextPage
isWikitextPage()
Does that page contain wikitext, or it is JS, CSS or whatever?
Definition: Title.php:1412
Title\isUserCssConfigPage
isUserCssConfigPage()
Is this a CSS "config" sub-page of a user page?
Definition: Title.php:1474
Title\getBacklinkCache
getBacklinkCache()
Get a backlink cache object.
Definition: Title.php:4358
Title\getPartialURL
getPartialURL()
Get the URL-encoded form of the main part.
Definition: Title.php:1014
$wgLegalTitleChars
$wgLegalTitleChars
Allowed title characters – regex character class Don't change this unless you know what you're doing.
Definition: DefaultSettings.php:4343
Title\clearCaches
static clearCaches()
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:3359
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:982
Title\estimateRevisionCount
estimateRevisionCount()
Get the approximate revision count of this page.
Definition: Title.php:3856
ResourceLoaderWikiModule\invalidateModuleCache
static invalidateModuleCache(Title $title, ?RevisionRecord $old, ?RevisionRecord $new, $domain)
Clear the preloadTitleInfo() cache for all wiki modules on this wiki on page change if it was a JS or...
Definition: ResourceLoaderWikiModule.php:542
Title\countRevisionsBetween
countRevisionsBetween( $old, $new, $max=null)
Get the number of revisions between the given revision.
Definition: Title.php:3881
Title\getPrefixedDBkey
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1838
Title\getDbPageLanguageCode
getDbPageLanguageCode()
Returns the page language code saved in the database, if $wgPageLanguageUseDB is set to true in Local...
Definition: Title.php:4412
Title\getSkinFromConfigSubpage
getSkinFromConfigSubpage()
Trim down a .css, .json, or .js subpage title to get the corresponding skin name.
Definition: Title.php:1458
$wgScript
$wgScript
The URL path to index.php.
Definition: DefaultSettings.php:207
Title\$mHasSubpages
bool $mHasSubpages
Whether a page has any subpages.
Definition: Title.php:169
Title\getTalkPage
getTalkPage()
Get a Title object associated with the talk page of this article.
Definition: Title.php:1601
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:4250
Title\getParentCategoryTree
getParentCategoryTree( $children=[])
Get a tree of parent categories.
Definition: Title.php:3701
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:226
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:2123
Title\fixSpecialName
fixSpecialName()
If the Title refers to a special page alias which is not the local default, resolve the alias,...
Definition: Title.php:1269
Title\getInterwikiLookup
static getInterwikiLookup()
B/C kludge: provide an InterwikiLookup for use by Title.
Definition: Title.php:227
Title\isUserJsConfigPage
isUserJsConfigPage()
Is this a JS "config" sub-page of a user page?
Definition: Title.php:1502
Title\touchLinks
touchLinks()
Update page_touched timestamps and send CDN purge messages for pages linking to this title.
Definition: Title.php:4210
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:308
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1850
Title\getTransWikiID
getTransWikiID()
Returns the DB name of the distant wiki which owns the object.
Definition: Title.php:965
DeferredUpdates\addUpdate
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred update queue for execution at the appropriate time.
Definition: DeferredUpdates.php:106
Title\getArticleID
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:3216
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:2328
Title\$mTitleValue
TitleValue null $mTitleValue
A corresponding TitleValue object.
Definition: Title.php:180
Title\quickUserCan
quickUserCan( $action, $user=null)
Can $user perform $action on this page? This skips potentially expensive cascading permission checks ...
Definition: Title.php:2416
NS_FILE
const NS_FILE
Definition: Defines.php:75
Title\isTalkPage
isTalkPage()
Is this a talk page of some sort?
Definition: Title.php:1585
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1125
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1219
Sanitizer\decodeCharReferencesAndNormalize
static decodeCharReferencesAndNormalize( $text)
Decode any character references, numeric or named entities, in the next and normalize the resulting s...
Definition: Sanitizer.php:1484
$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:92
Sanitizer\escapeClass
static escapeClass( $class)
Given a value, escape it so that it can be used as a CSS class and return it.
Definition: Sanitizer.php:1216
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1086
Title\isExternal
isExternal()
Is this Title interwiki?
Definition: Title.php:922
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:2905
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:654
Title\getDefaultMessageText
getDefaultMessageText()
Get the default (plain) message contents for an page that overrides an interface message key.
Definition: Title.php:4147
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:224
Title\hasSourceText
hasSourceText()
Does this page have source text?
Definition: Title.php:4088
Title\loadFromRow
loadFromRow( $row)
Load Title object fields from a DB row.
Definition: Title.php:536
Title\setFragment
setFragment( $fragment)
Set the fragment for this title.
Definition: Title.php:1785
$res
$res
Definition: testCompression.php:57
IDBAccessObject
Interface for database access objects.
Definition: IDBAccessObject.php:57
Title\equals
equals(LinkTarget $title)
Compare with another title.
Definition: Title.php:3974
Title\$mIsBigDeletion
bool null $mIsBigDeletion
Would deleting this page be a big deletion?
Definition: Title.php:183
Title\convertByteClassToUnicodeClass
static convertByteClassToUnicodeClass( $byteClass)
Utility method for converting a character sequence from bytes to Unicode.
Definition: Title.php:714
Title\hasSubpagesEnabled
hasSubpagesEnabled()
Whether this Title's namespace has subpages enabled.
Definition: Title.php:1935
Title\__wakeup
__wakeup()
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:4629
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:3666
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:3447
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:203
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:1516
MessageLocalizer
Interface for localizing messages in MediaWiki.
Definition: MessageLocalizer.php:29
Title\getNsText
getNsText()
Get the namespace text.
Definition: Title.php:1119
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:54
Title\getLinksFrom
getLinksFrom( $options=[], $table='pagelinks', $prefix='pl')
Get an array of Title objects linked from this Title Also stores the IDs in the link cache.
Definition: Title.php:3505
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
Wikimedia\Rdbms\IDatabase\update
update( $table, $set, $conds, $fname=__METHOD__, $options=[])
Update all rows in a table that match a given condition.
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Definition: GlobalFunctions.php:438
Revision
Definition: Revision.php:40
NS_MAIN
const NS_MAIN
Definition: Defines.php:69
Title\loadFieldFromDB
loadFieldFromDB( $field, $flags)
Definition: Title.php:4598
Title\isCascadeProtected
isCascadeProtected()
Cascading protection: Return true if cascading restrictions apply to this page, false if not.
Definition: Title.php:2716
Revision\newFromTitle
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
Definition: Revision.php:143
Title\getCdnUrls
getCdnUrls()
Get a list of URLs to purge from the CDN cache when this page changes.
Definition: Title.php:3607
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:58
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:1703
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:1430
Title\isUserJsonConfigPage
isUserJsonConfigPage()
Is this a JSON "config" sub-page of a user page?
Definition: Title.php:1488
Wikimedia\Rdbms\IDatabase\timestamp
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for ins...
ContentHandler\getDefaultModelFor
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title.
Definition: ContentHandler.php:194
$wgRawHtmlMessages
string[] $wgRawHtmlMessages
List of messages which might contain raw HTML.
Definition: DefaultSettings.php:9289
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:1023
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
Definition: GlobalFunctions.php:1058
Title\nameOf
static nameOf( $id)
Get the prefixed DB key associated with an ID.
Definition: Title.php:679
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:177
Title\isSpecial
isSpecial( $name)
Returns true if this title resolves to the named special page.
Definition: Title.php:1251
MWException
MediaWiki exception.
Definition: MWException.php:29
Title\getTitleFormatter
static getTitleFormatter()
B/C kludge: provide a TitleParser for use by Title.
Definition: Title.php:215
Title\isMainPage
isMainPage()
Is this the mainpage?
Definition: Title.php:1379
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1026
Title\getSubpage
getSubpage( $text)
Get the title for a subpage of the current page.
Definition: Title.php:2079
Title\getBaseTitle
getBaseTitle()
Get the base page name title, i.e.
Definition: Title.php:2032
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1032
BacklinkCache\get
static get(Title $title)
Create a new BacklinkCache or reuse any existing one.
Definition: BacklinkCache.php:116
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:524
Title\isConversionTable
isConversionTable()
Is this a conversion table for the LanguageConverter?
Definition: Title.php:1400
Title\isProtected
isProtected( $action='')
Does the title correspond to a protected article?
Definition: Title.php:2664
Title\flushRestrictions
flushRestrictions()
Flush the protection cache in this object and force reload from the database.
Definition: Title.php:3054
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2467
Title\getCategorySortkey
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:4386
Title\getInterwiki
getInterwiki()
Get the interwiki prefix.
Definition: Title.php:933
Title\isSiteJsonConfigPage
isSiteJsonConfigPage()
Is this a sitewide JSON "config" page?
Definition: Title.php:1534
$matches
$matches
Definition: NoLocalSettings.php:24
Title\isValidRedirectTarget
isValidRedirectTarget()
Check if this Title is a valid redirect target.
Definition: Title.php:4334
Title\deleteTitleProtection
deleteTitleProtection()
Remove any title protection due to page existing.
Definition: Title.php:2618
Title\__construct
__construct()
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:231
$wgLang
$wgLang
Definition: Setup.php:776
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:2441
Title\getBrokenLinksFrom
getBrokenLinksFrom()
Get an array of Title objects referring to non-existent articles linked from this page.
Definition: Title.php:3571
Title\isUserConfigPage
isUserConfigPage()
Is this a "config" (.css, .json, or .js) sub-page of a user page?
Definition: Title.php:1444
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:211
Title\getLanguageConverter
getLanguageConverter( $language)
Shorthand for getting a Language Converter for specific language.
Definition: Title.php:194
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:1646
MapCacheLRU
Handles a simple LRU key/value map with a maximum number of entries.
Definition: MapCacheLRU.php:38
wfGetLangObj
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
Definition: GlobalFunctions.php:1169
Title\loadRestrictions
loadRestrictions( $oldFashionedRestrictions=null, $flags=0)
Load restrictions from the page_restrictions table.
Definition: Title.php:2983
$wgInvalidRedirectTargets
$wgInvalidRedirectTargets
Array of invalid page redirect targets.
Definition: DefaultSettings.php:4518
Title\getFullText
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
Definition: Title.php:1874
Title\getTitleCache
static getTitleCache()
Definition: Title.php:437
Title\hasFragment
hasFragment()
Check if a Title fragment is set.
Definition: Title.php:1749
Title\getRedirectsHere
getRedirectsHere( $ns=null)
Get all extant redirects to this Title.
Definition: Title.php:4298
MediaWiki\User\UserIdentity\getName
getName()
$title
$title
Definition: testCompression.php:38
Title\warnIfPageCannotExist
warnIfPageCannotExist(Title $title, $method)
Definition: Title.php:1672
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:592
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:1837
Title\getRootText
getRootText()
Get the root page name text without a namespace, i.e.
Definition: Title.php:1955
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:83
$wgNamespaceProtection
$wgNamespaceProtection
Set the minimum permissions required to edit pages in each namespace.
Definition: DefaultSettings.php:5779
Title\canExist
canExist()
Can this title represent a page in the wiki's database?
Definition: Title.php:1186
$wgDeleteRevisionsLimit
$wgDeleteRevisionsLimit
Optional to restrict deletion of pages with higher revision counts to users with the 'bigdelete' perm...
Definition: DefaultSettings.php:5956
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:909
Title\__sleep
__sleep()
Definition: Title.php:4618
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:2375
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:1796
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:1728
Title\newFromTextThrow
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:364
$wgPageLanguageUseDB
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
Definition: DefaultSettings.php:9168
Title\$mPageLanguage
array null $mPageLanguage
The (string) language code of the page's language and content code.
Definition: Title.php:172
Title\isValid
isValid()
Returns true if the title is a valid link target, and that it has been properly normalized.
Definition: Title.php:868
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:2104
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:618
Title\__toString
__toString()
Return a string representation of this title.
Definition: Title.php:1864
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:49
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:3489
$wgMainPageIsDomainRoot
bool $wgMainPageIsDomainRoot
Option to whether serve the main page as the domain root.
Definition: DefaultSettings.php:9549
Title\areRestrictionsCascading
areRestrictionsCascading()
Returns cascading restrictions for the current article.
Definition: Title.php:2886
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:57
Title\getLatestRevID
getLatestRevID( $flags=0)
What is the page_latest field for this page?
Definition: Title.php:3302
Title\areRestrictionsLoaded
areRestrictionsLoaded()
Accessor for mRestrictionsLoaded.
Definition: Title.php:2833
Title\getSubpages
getSubpages( $limit=-1)
Get all subpages of this page.
Definition: Title.php:3136
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:3628
$wgServer
$wgServer
URL of the server.
Definition: DefaultSettings.php:111
Title\GAID_FOR_UPDATE
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define().
Definition: Title.php:58
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:172
Title\getPageViewLanguage
getPageViewLanguage()
Get the language in which the content of this page is written when viewed by user.
Definition: Title.php:4475
Title\newFromDBkey
static newFromDBkey( $key)
Create a new Title from a prefixed DB key.
Definition: Title.php:242
Sanitizer\escapeIdForExternalInterwiki
static escapeIdForExternalInterwiki( $id)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid URL...
Definition: Sanitizer.php:1122
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:3102
Title\isSubpage
isSubpage()
Is this a subpage?
Definition: Title.php:1388
Title\hasContentModel
hasContentModel( $id)
Convenience method for checking a title's content model name.
Definition: Title.php:1077
Title\getRestrictionExpiry
getRestrictionExpiry( $action)
Get the expiry time for the restriction against a given action.
Definition: Title.php:2874
Title\newFromURL
static newFromURL( $url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:414
MediaWiki\Linker\LinkTarget\getFragment
getFragment()
Get the link fragment (i.e.
PROTO_HTTP
const PROTO_HTTP
Definition: Defines.php:208
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:111
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:210
Title\resetArticleID
resetArticleID( $id)
Inject a page ID, reset DB-loaded fields, and clear the link cache for this title.
Definition: Title.php:3337
Title\isSubpageOf
isSubpageOf(Title $title)
Check if this title is a subpage of another title.
Definition: Title.php:3987
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:907
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:1044
Title\newFromIDs
static newFromIDs( $ids)
Make an array of titles from an array of IDs.
Definition: Title.php:498
WikiPage\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new page object.
Definition: WikiPage.php:333
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:281
Title\prefix
prefix( $name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object.
Definition: Title.php:1812
Title\getNamespaceKey
getNamespaceKey( $prepend='nstab-')
Generate strings used for xml 'id' names in monobook tabs.
Definition: Title.php:4269
Title\getEditURL
getEditURL()
Get the edit URL for this Title.
Definition: Title.php:2387
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:2161
Title\isKnown
isKnown()
Does this title refer to a page that can (or might) be meaningfully viewed? In particular,...
Definition: Title.php:4079
$wgArticlePath
$wgArticlePath
The URL path for primary article page views.
Definition: DefaultSettings.php:267
Title\$mIsValid
bool null $mIsValid
Is the title known to be valid?
Definition: Title.php:186
Title\getFirstRevision
getFirstRevision( $flags=0)
Get the first revision of the page.
Definition: Title.php:3789
Title\getAllRestrictions
getAllRestrictions()
Accessor/initialisation for mRestrictions.
Definition: Title.php:2860
Title\getEarliestRevTime
getEarliestRevTime( $flags=0)
Get the oldest revision timestamp of this page.
Definition: Title.php:3805
Title
Represents a title within MediaWiki.
Definition: Title.php:42
$wgActionPaths
$wgActionPaths
To set 'pretty' URL paths for actions other than plain page views, add to this array.
Definition: DefaultSettings.php:446
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:2747
$cache
$cache
Definition: mcc.php:33
$wgSemiprotectedRestrictionLevels
$wgSemiprotectedRestrictionLevels
Restriction levels that should be considered "semiprotected".
Definition: DefaultSettings.php:5770
Title\getRestrictionTypes
getRestrictionTypes()
Returns restriction types for the current Title.
Definition: Title.php:2521
MalformedTitleException
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Definition: MalformedTitleException.php:26
Title\getTitleProtectionInternal
getTitleProtectionInternal()
Fetch title protection settings.
Definition: Title.php:2571
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:3559
Title\isRedirect
isRedirect( $flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
Definition: Title.php:3250
DeferredUpdates\PRESEND
const PRESEND
Definition: DeferredUpdates.php:84
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:3166
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:3374
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:1332
Title\isSpecialPage
isSpecialPage()
Returns true if this is a special page.
Definition: Title.php:1241
MapCacheLRU\get
get( $key, $maxAge=INF, $default=null)
Get the value for a key.
Definition: MapCacheLRU.php:169
Title\purgeSquid
purgeSquid()
Purge all applicable CDN URLs.
Definition: Title.php:3616
Title\getPreviousRevisionID
getPreviousRevisionID( $revId, $flags=0)
Get the revision ID of the previous revision.
Definition: Title.php:3766
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:4434
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:4523
Title\getTouched
getTouched( $db=null)
Get the last touched timestamp.
Definition: Title.php:4234
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
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:5745
Title\getFragmentForURL
getFragmentForURL()
Get the fragment in URL form, including the "#" character if there is one.
Definition: Title.php:1758
Title\exists
exists( $flags=0)
Check if page exists.
Definition: Title.php:4003
NS_USER
const NS_USER
Definition: Defines.php:71
Sanitizer\escapeIdForLink
static escapeIdForLink( $id)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid URL...
Definition: Sanitizer.php:1099
Title\isAlwaysKnown
isAlwaysKnown()
Should links to this title be shown as potentially viewable (i.e.
Definition: Title.php:4025
Title\secureAndSplit
secureAndSplit( $text, $defaultNamespace=null)
Secure and split - main initialisation function for this object.
Definition: Title.php:3399
Title\isDeletedQuick
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:3191
Title\getSubpageUrlForm
getSubpageUrlForm()
Get a URL-encoded form of the subpage text.
Definition: Title.php:2093
MapCacheLRU\clear
clear( $keys=null)
Clear one or several cache entries, or all cache entries.
Definition: MapCacheLRU.php:286
Title\isNewPage
isNewPage()
Check if this is a new page.
Definition: Title.php:3817
$wgRestrictionTypes
$wgRestrictionTypes
Set of available actions that can be restricted via action=protect You probably shouldn't change this...
Definition: DefaultSettings.php:5732
Title\setContentModel
setContentModel( $model)
Set a proposed content model for the page for permissions checking.
Definition: Title.php:1094
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:77
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:225
Title\compare
static compare(LinkTarget $a, LinkTarget $b)
Callback for usort() to do title sorts by (namespace, title)
Definition: Title.php:847
Title\countAuthorsBetween
countAuthorsBetween( $old, $new, $limit, $options=[])
Get the number of authors between the given revisions or revision IDs.
Definition: Title.php:3962
$t
$t
Definition: testCompression.php:74
Title\legalChars
static legalChars()
Get a regex character class describing the legal characters in a link.
Definition: Title.php:700
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:305
Title\isSiteJsConfigPage
isSiteJsConfigPage()
Is this a sitewide JS "config" page?
Definition: Title.php:1552
Title\invalidateCache
invalidateCache( $purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:4170
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:644
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:952
Title\getRestrictions
getRestrictions( $action)
Accessor/initialisation for mRestrictions.
Definition: Title.php:2846
CommentStore\getStore
static getStore()
Definition: CommentStore.php:120
Title\isContentPage
isContentPage()
Is this Title in a namespace which contains content? In other words, is this a content page,...
Definition: Title.php:1344
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:55
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:473
$wgVariantArticlePath
$wgVariantArticlePath
Like $wgArticlePath, but on multi-variant wikis, this provides a path format that describes which par...
Definition: DefaultSettings.php:3297
Title\isRawHtmlMessage
isRawHtmlMessage()
Is this a message which can contain raw HTML?
Definition: Title.php:1570
Title\getSelectFields
static getSelectFields()
Returns a list of fields that are to be selected for initializing Title objects or LinkCache entries.
Definition: Title.php:450
Title\hasSubpages
hasSubpages()
Does this have subpages? (Warning, usually requires an extra DB query.)
Definition: Title.php:3105
Title\getBaseText
getBaseText()
Get the base page name without a namespace, i.e.
Definition: Title.php:2005
Title\pageCond
pageCond()
Get an associative array for selecting this title from the "page" table.
Definition: Title.php:3728
Title\getText
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:1005
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 all rows in a table that match a condition.
Title\purgeExpiredRestrictions
static purgeExpiredRestrictions()
Purge expired restrictions from the page_restrictions table.
Definition: Title.php:3064
$wgInternalServer
$wgInternalServer
Internal server name as known to CDN, if different.
Definition: DefaultSettings.php:2908
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:1108
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:490
Title\getSubjectNsText
getSubjectNsText()
Get the namespace text of the subject (rather than talk) page.
Definition: Title.php:1144
Title\getUserPermissionsErrors
getUserPermissionsErrors( $action, $user, $rigor=PermissionManager::RIGOR_SECURE, $ignoreErrors=[])
Can $user perform $action on this page?
Definition: Title.php:2480
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:39
Title\newFromTitleValue
static newFromTitleValue(TitleValue $titleValue, $forceClone='')
Returns a Title given a TitleValue.
Definition: Title.php:266
Title\getRelativeRevisionID
getRelativeRevisionID( $revId, $flags, $dir)
Get next/previous revision ID relative to another revision ID.
Definition: Title.php:3744
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:346
Title\getFullUrlForRedirect
getFullUrlForRedirect( $query='', $proto=PROTO_CURRENT)
Get a url appropriate for making redirects based on an untrusted url arg.
Definition: Title.php:2194
Title\getRootTitle
getRootTitle()
Get the root page name title, i.e.
Definition: Title.php:1982
$type
$type
Definition: testCompression.php:52
Title\getLength
getLength( $flags=0)
What is the length of this page? Uses link cache, adding it if necessary.
Definition: Title.php:3275
Title\findSubpageDivider
findSubpageDivider( $text, $dir)
Finds the first or last subpage divider (slash) in the string.
Definition: Title.php:1896
Title\getAuthorsBetween
getAuthorsBetween( $old, $new, $limit, $options=[])
Get the authors between the given revisions or revision IDs.
Definition: Title.php:3919
Title\isWatchable
isWatchable()
Can this title be added to a user's watchlist?
Definition: Title.php:1230