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 
170 
172  private $mHasSubpages;
173 
175  private $mPageLanguage;
176 
180  private $mDbPageLanguage = false;
181 
183  private $mTitleValue = null;
184 
186  private $mIsBigDeletion = null;
187 
189  private $mIsValid = null;
190  // @}
191 
197  private function getLanguageConverter( $language ) : ILanguageConverter {
198  return MediaWikiServices::getInstance()->getLanguageConverterFactory()
199  ->getLanguageConverter( $language );
200  }
201 
207  return $this->getLanguageConverter( $this->getPageLanguage() );
208  }
209 
218  private static function getTitleFormatter() {
219  return MediaWikiServices::getInstance()->getTitleFormatter();
220  }
221 
230  private static function getInterwikiLookup() {
231  return MediaWikiServices::getInstance()->getInterwikiLookup();
232  }
233 
234  private function __construct() {
235  }
236 
245  public static function newFromDBkey( $key ) {
246  $t = new self();
247 
248  try {
249  $t->secureAndSplit( $key );
250  return $t;
251  } catch ( MalformedTitleException $ex ) {
252  return null;
253  }
254  }
255 
269  public static function newFromTitleValue( TitleValue $titleValue, $forceClone = '' ) {
270  return self::newFromLinkTarget( $titleValue, $forceClone );
271  }
272 
284  public static function newFromLinkTarget( LinkTarget $linkTarget, $forceClone = '' ) {
285  if ( $linkTarget instanceof Title ) {
286  // Special case if it's already a Title object
287  if ( $forceClone === self::NEW_CLONE ) {
288  return clone $linkTarget;
289  } else {
290  return $linkTarget;
291  }
292  }
293  return self::makeTitle(
294  $linkTarget->getNamespace(),
295  $linkTarget->getText(),
296  $linkTarget->getFragment(),
297  $linkTarget->getInterwiki()
298  );
299  }
300 
308  public static function castFromLinkTarget( $linkTarget ) {
309  return $linkTarget ? self::newFromLinkTarget( $linkTarget ) : null;
310  }
311 
332  public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
333  // DWIM: Integers can be passed in here when page titles are used as array keys.
334  if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) {
335  throw new InvalidArgumentException( '$text must be a string.' );
336  }
337  if ( $text === null ) {
338  return null;
339  }
340 
341  try {
342  return self::newFromTextThrow( (string)$text, (int)$defaultNamespace );
343  } catch ( MalformedTitleException $ex ) {
344  return null;
345  }
346  }
347 
367  public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
368  if ( is_object( $text ) ) {
369  throw new MWException( '$text must be a string, given an object' );
370  } elseif ( $text === null ) {
371  // Legacy code relies on MalformedTitleException being thrown in this case
372  // (happens when URL with no title in it is parsed). TODO fix
373  throw new MalformedTitleException( 'title-invalid-empty' );
374  }
375 
377 
378  // Wiki pages often contain multiple links to the same page.
379  // Title normalization and parsing can become expensive on pages with many
380  // links, so we can save a little time by caching them.
381  // In theory these are value objects and won't get changed...
382  if ( $defaultNamespace == NS_MAIN ) {
383  $t = $titleCache->get( $text );
384  if ( $t ) {
385  return $t;
386  }
387  }
388 
389  // Convert things like &eacute; &#257; or &#x3017; into normalized (T16952) text
390  $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
391 
392  $t = new Title();
393  $dbKeyForm = strtr( $filteredText, ' ', '_' );
394 
395  $t->secureAndSplit( $dbKeyForm, (int)$defaultNamespace );
396  if ( $defaultNamespace == NS_MAIN ) {
397  $titleCache->set( $text, $t );
398  }
399  return $t;
400  }
401 
417  public static function newFromURL( $url ) {
418  $t = new Title();
419 
420  # For compatibility with old buggy URLs. "+" is usually not valid in titles,
421  # but some URLs used it as a space replacement and they still come
422  # from some external search tools.
423  if ( strpos( self::legalChars(), '+' ) === false ) {
424  $url = strtr( $url, '+', ' ' );
425  }
426 
427  $dbKeyForm = strtr( $url, ' ', '_' );
428 
429  try {
430  $t->secureAndSplit( $dbKeyForm );
431  return $t;
432  } catch ( MalformedTitleException $ex ) {
433  return null;
434  }
435  }
436 
440  private static function getTitleCache() {
441  if ( self::$titleCache === null ) {
442  self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
443  }
444  return self::$titleCache;
445  }
446 
453  protected static function getSelectFields() {
454  global $wgPageLanguageUseDB;
455 
456  $fields = [
457  'page_namespace', 'page_title', 'page_id',
458  'page_len', 'page_is_redirect', 'page_latest',
459  'page_content_model',
460  ];
461 
462  if ( $wgPageLanguageUseDB ) {
463  $fields[] = 'page_lang';
464  }
465 
466  return $fields;
467  }
468 
476  public static function newFromID( $id, $flags = 0 ) {
477  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
478  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
479  $row = wfGetDB( $index )->selectRow(
480  'page',
481  self::getSelectFields(),
482  [ 'page_id' => $id ],
483  __METHOD__,
484  $options
485  );
486  if ( $row !== false ) {
487  $title = self::newFromRow( $row );
488  } else {
489  $title = null;
490  }
491 
492  return $title;
493  }
494 
501  public static function newFromIDs( $ids ) {
502  if ( !count( $ids ) ) {
503  return [];
504  }
505  $dbr = wfGetDB( DB_REPLICA );
506 
507  $res = $dbr->select(
508  'page',
509  self::getSelectFields(),
510  [ 'page_id' => $ids ],
511  __METHOD__
512  );
513 
514  $titles = [];
515  foreach ( $res as $row ) {
516  $titles[] = self::newFromRow( $row );
517  }
518  return $titles;
519  }
520 
527  public static function newFromRow( $row ) {
528  $t = self::makeTitle( $row->page_namespace, $row->page_title );
529  $t->loadFromRow( $row );
530  return $t;
531  }
532 
539  public function loadFromRow( $row ) {
540  if ( $row ) { // page found
541  if ( isset( $row->page_id ) ) {
542  $this->mArticleID = (int)$row->page_id;
543  }
544  if ( isset( $row->page_len ) ) {
545  $this->mLength = (int)$row->page_len;
546  }
547  if ( isset( $row->page_is_redirect ) ) {
548  $this->mRedirect = (bool)$row->page_is_redirect;
549  }
550  if ( isset( $row->page_latest ) ) {
551  $this->mLatestID = (int)$row->page_latest;
552  }
553  if ( isset( $row->page_content_model ) ) {
554  $this->lazyFillContentModel( $row->page_content_model );
555  } else {
556  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
557  }
558  if ( isset( $row->page_lang ) ) {
559  $this->mDbPageLanguage = (string)$row->page_lang;
560  }
561  if ( isset( $row->page_restrictions ) ) {
562  $this->mOldRestrictions = $row->page_restrictions;
563  }
564  } else { // page not found
565  $this->mArticleID = 0;
566  $this->mLength = 0;
567  $this->mRedirect = false;
568  $this->mLatestID = 0;
569  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
570  }
571  }
572 
595  public static function makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
596  $t = new Title();
597  $t->mInterwiki = $interwiki;
598  $t->mFragment = $fragment;
599  $t->mNamespace = $ns = (int)$ns;
600  $t->mDbkeyform = strtr( $title, ' ', '_' );
601  $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
602  $t->mUrlform = wfUrlencode( $t->mDbkeyform );
603  $t->mTextform = strtr( $title, '_', ' ' );
604  return $t;
605  }
606 
621  public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
622  // NOTE: ideally, this would just call makeTitle() and then isValid(),
623  // but presently, that means more overhead on a potential performance hotspot.
624 
625  if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) {
626  return null;
627  }
628 
629  $t = new Title();
630  $dbKeyForm = self::makeName( $ns, $title, $fragment, $interwiki, true );
631 
632  try {
633  $t->secureAndSplit( $dbKeyForm );
634  return $t;
635  } catch ( MalformedTitleException $ex ) {
636  return null;
637  }
638  }
639 
657  public static function newMainPage( MessageLocalizer $localizer = null ) {
658  if ( $localizer ) {
659  $msg = $localizer->msg( 'mainpage' );
660  } else {
661  $msg = wfMessage( 'mainpage' );
662  }
663 
664  $title = self::newFromText( $msg->inContentLanguage()->text() );
665 
666  // Every page renders at least one link to the Main Page (e.g. sidebar).
667  // If the localised value is invalid, don't produce fatal errors that
668  // would make the wiki inaccessible (and hard to fix the invalid message).
669  // Gracefully fallback...
670  if ( !$title ) {
671  $title = self::newFromText( 'Main Page' );
672  }
673  return $title;
674  }
675 
682  public static function nameOf( $id ) {
683  $dbr = wfGetDB( DB_REPLICA );
684 
685  $s = $dbr->selectRow(
686  'page',
687  [ 'page_namespace', 'page_title' ],
688  [ 'page_id' => $id ],
689  __METHOD__
690  );
691  if ( $s === false ) {
692  return null;
693  }
694 
695  return self::makeName( $s->page_namespace, $s->page_title );
696  }
697 
703  public static function legalChars() {
704  global $wgLegalTitleChars;
705  return $wgLegalTitleChars;
706  }
707 
717  public static function convertByteClassToUnicodeClass( $byteClass ) {
718  $length = strlen( $byteClass );
719  // Input token queue
720  $x0 = $x1 = $x2 = '';
721  // Decoded queue
722  $d0 = $d1 = $d2 = '';
723  // Decoded integer codepoints
724  $ord0 = $ord1 = $ord2 = 0;
725  // Re-encoded queue
726  $r0 = $r1 = $r2 = '';
727  // Output
728  $out = '';
729  // Flags
730  $allowUnicode = false;
731  for ( $pos = 0; $pos < $length; $pos++ ) {
732  // Shift the queues down
733  $x2 = $x1;
734  $x1 = $x0;
735  $d2 = $d1;
736  $d1 = $d0;
737  $ord2 = $ord1;
738  $ord1 = $ord0;
739  $r2 = $r1;
740  $r1 = $r0;
741  // Load the current input token and decoded values
742  $inChar = $byteClass[$pos];
743  if ( $inChar == '\\' ) {
744  if ( preg_match( '/x([0-9a-fA-F]{2})/A', $byteClass, $m, 0, $pos + 1 ) ) {
745  $x0 = $inChar . $m[0];
746  $d0 = chr( hexdec( $m[1] ) );
747  $pos += strlen( $m[0] );
748  } elseif ( preg_match( '/[0-7]{3}/A', $byteClass, $m, 0, $pos + 1 ) ) {
749  $x0 = $inChar . $m[0];
750  $d0 = chr( octdec( $m[0] ) );
751  $pos += strlen( $m[0] );
752  } elseif ( $pos + 1 >= $length ) {
753  $x0 = $d0 = '\\';
754  } else {
755  $d0 = $byteClass[$pos + 1];
756  $x0 = $inChar . $d0;
757  $pos += 1;
758  }
759  } else {
760  $x0 = $d0 = $inChar;
761  }
762  $ord0 = ord( $d0 );
763  // Load the current re-encoded value
764  if ( $ord0 < 32 || $ord0 == 0x7f ) {
765  $r0 = sprintf( '\x%02x', $ord0 );
766  } elseif ( $ord0 >= 0x80 ) {
767  // Allow unicode if a single high-bit character appears
768  $r0 = sprintf( '\x%02x', $ord0 );
769  $allowUnicode = true;
770  // @phan-suppress-next-line PhanParamSuspiciousOrder false positive
771  } elseif ( strpos( '-\\[]^', $d0 ) !== false ) {
772  $r0 = '\\' . $d0;
773  } else {
774  $r0 = $d0;
775  }
776  // Do the output
777  if ( $x0 !== '' && $x1 === '-' && $x2 !== '' ) {
778  // Range
779  if ( $ord2 > $ord0 ) {
780  // Empty range
781  } elseif ( $ord0 >= 0x80 ) {
782  // Unicode range
783  $allowUnicode = true;
784  if ( $ord2 < 0x80 ) {
785  // Keep the non-unicode section of the range
786  $out .= "$r2-\\x7F";
787  }
788  } else {
789  // Normal range
790  $out .= "$r2-$r0";
791  }
792  // Reset state to the initial value
793  $x0 = $x1 = $d0 = $d1 = $r0 = $r1 = '';
794  } elseif ( $ord2 < 0x80 ) {
795  // ASCII character
796  $out .= $r2;
797  }
798  }
799  if ( $ord1 < 0x80 ) {
800  $out .= $r1;
801  }
802  if ( $ord0 < 0x80 ) {
803  $out .= $r0;
804  }
805  if ( $allowUnicode ) {
806  $out .= '\u0080-\uFFFF';
807  }
808  return $out;
809  }
810 
822  public static function makeName( $ns, $title, $fragment = '', $interwiki = '',
823  $canonicalNamespace = false
824  ) {
825  if ( $canonicalNamespace ) {
826  $namespace = MediaWikiServices::getInstance()->getNamespaceInfo()->
827  getCanonicalName( $ns );
828  } else {
829  $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns );
830  }
831  $name = $namespace == '' ? $title : "$namespace:$title";
832  if ( strval( $interwiki ) != '' ) {
833  $name = "$interwiki:$name";
834  }
835  if ( strval( $fragment ) != '' ) {
836  $name .= '#' . $fragment;
837  }
838  return $name;
839  }
840 
849  public static function compare( LinkTarget $a, LinkTarget $b ) {
850  return $a->getNamespace() <=> $b->getNamespace()
851  ?: strcmp( $a->getText(), $b->getText() );
852  }
853 
870  public function isValid() {
871  if ( $this->mIsValid !== null ) {
872  return $this->mIsValid;
873  }
874 
875  try {
876  $text = $this->getFullText();
877  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
878 
879  '@phan-var MediaWikiTitleCodec $titleCodec';
880  $parts = $titleCodec->splitTitleString( $text, $this->mNamespace );
881 
882  // Check that nothing changed!
883  // This ensures that $text was already perperly normalized.
884  if ( $parts['fragment'] !== $this->mFragment
885  || $parts['interwiki'] !== $this->mInterwiki
886  || $parts['local_interwiki'] !== $this->mLocalInterwiki
887  || $parts['namespace'] !== $this->mNamespace
888  || $parts['dbkey'] !== $this->mDbkeyform
889  ) {
890  $this->mIsValid = false;
891  return $this->mIsValid;
892  }
893  } catch ( MalformedTitleException $ex ) {
894  $this->mIsValid = false;
895  return $this->mIsValid;
896  }
897 
898  $this->mIsValid = true;
899  return $this->mIsValid;
900  }
901 
909  public function isLocal() {
910  if ( $this->isExternal() ) {
911  $iw = self::getInterwikiLookup()->fetch( $this->mInterwiki );
912  if ( $iw ) {
913  return $iw->isLocal();
914  }
915  }
916  return true;
917  }
918 
924  public function isExternal() {
925  return $this->mInterwiki !== '';
926  }
927 
935  public function getInterwiki() {
936  return $this->mInterwiki;
937  }
938 
944  public function wasLocalInterwiki() {
945  return $this->mLocalInterwiki;
946  }
947 
954  public function isTrans() {
955  if ( !$this->isExternal() ) {
956  return false;
957  }
958 
959  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable();
960  }
961 
967  public function getTransWikiID() {
968  if ( !$this->isExternal() ) {
969  return false;
970  }
971 
972  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID();
973  }
974 
984  public function getTitleValue() {
985  if ( $this->mTitleValue === null ) {
986  try {
987  $this->mTitleValue = new TitleValue(
988  $this->mNamespace,
989  $this->mDbkeyform,
990  $this->mFragment,
991  $this->mInterwiki
992  );
993  } catch ( InvalidArgumentException $ex ) {
994  wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' .
995  $this->getPrefixedText() . ']]: ' . $ex->getMessage() . "\n" );
996  }
997  }
998 
999  return $this->mTitleValue;
1000  }
1001 
1007  public function getText() {
1008  return $this->mTextform;
1009  }
1010 
1016  public function getPartialURL() {
1017  return $this->mUrlform;
1018  }
1019 
1025  public function getDBkey() {
1026  return $this->mDbkeyform;
1027  }
1028 
1034  public function getNamespace() {
1035  return $this->mNamespace;
1036  }
1037 
1046  public function getContentModel( $flags = 0 ) {
1047  if ( $this->mForcedContentModel ) {
1048  if ( !$this->mContentModel ) {
1049  throw new RuntimeException( 'Got out of sync; an empty model is being forced' );
1050  }
1051  // Content model is locked to the currently loaded one
1052  return $this->mContentModel;
1053  }
1054 
1055  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
1056  $this->lazyFillContentModel( $this->loadFieldFromDB( 'page_content_model', $flags ) );
1057  } elseif (
1058  ( !$this->mContentModel || $flags & self::GAID_FOR_UPDATE ) &&
1059  $this->getArticleID( $flags )
1060  ) {
1061  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1062  $linkCache->addLinkObj( $this ); # in case we already had an article ID
1063  $this->lazyFillContentModel( $linkCache->getGoodLinkFieldObj( $this, 'model' ) );
1064  }
1065 
1066  if ( !$this->mContentModel ) {
1068  }
1069 
1070  return $this->mContentModel;
1071  }
1072 
1079  public function hasContentModel( $id ) {
1080  return $this->getContentModel() == $id;
1081  }
1082 
1096  public function setContentModel( $model ) {
1097  if ( (string)$model === '' ) {
1098  throw new InvalidArgumentException( "Missing CONTENT_MODEL_* constant" );
1099  }
1100 
1101  $this->mContentModel = $model;
1102  $this->mForcedContentModel = true;
1103  }
1104 
1110  private function lazyFillContentModel( $model ) {
1111  if ( !$this->mForcedContentModel ) {
1112  $this->mContentModel = ( $model === false ) ? false : (string)$model;
1113  }
1114  }
1115 
1121  public function getNsText() {
1122  if ( $this->isExternal() ) {
1123  // This probably shouldn't even happen, except for interwiki transclusion.
1124  // If possible, use the canonical name for the foreign namespace.
1125  $nsText = MediaWikiServices::getInstance()->getNamespaceInfo()->
1126  getCanonicalName( $this->mNamespace );
1127  if ( $nsText !== false ) {
1128  return $nsText;
1129  }
1130  }
1131 
1132  try {
1133  $formatter = self::getTitleFormatter();
1134  return $formatter->getNamespaceName( $this->mNamespace, $this->mDbkeyform );
1135  } catch ( InvalidArgumentException $ex ) {
1136  wfDebug( __METHOD__ . ': ' . $ex->getMessage() . "\n" );
1137  return false;
1138  }
1139  }
1140 
1146  public function getSubjectNsText() {
1147  $services = MediaWikiServices::getInstance();
1148  return $services->getContentLanguage()->
1149  getNsText( $services->getNamespaceInfo()->getSubject( $this->mNamespace ) );
1150  }
1151 
1157  public function getTalkNsText() {
1158  $services = MediaWikiServices::getInstance();
1159  return $services->getContentLanguage()->
1160  getNsText( $services->getNamespaceInfo()->getTalk( $this->mNamespace ) );
1161  }
1162 
1174  public function canHaveTalkPage() {
1175  return MediaWikiServices::getInstance()->getNamespaceInfo()->canHaveTalkPage( $this );
1176  }
1177 
1188  public function canExist() {
1189  // NOTE: Don't use getArticleID(), we don't want to
1190  // trigger a database query here. This check is supposed to
1191  // act as an optimization, not add extra cost.
1192  if ( $this->mArticleID > 0 ) {
1193  // It exists, so it can exist.
1194  return true;
1195  }
1196 
1197  // NOTE: we call the relatively expensive isValid() method further down,
1198  // but we can bail out early if we already know the title is invalid.
1199  if ( $this->mIsValid === false ) {
1200  // It's invalid, so it can't exist.
1201  return false;
1202  }
1203 
1204  if ( $this->getNamespace() < NS_MAIN ) {
1205  // It's a special page, so it can't exist in the database.
1206  return false;
1207  }
1208 
1209  if ( $this->isExternal() ) {
1210  // If it's external, it's not local, so it can't exist.
1211  return false;
1212  }
1213 
1214  if ( $this->getText() === '' ) {
1215  // The title has no text, so it can't exist in the database.
1216  // It's probably an on-page section link, like "#something".
1217  return false;
1218  }
1219 
1220  // Double check that the title is valid.
1221  return $this->isValid();
1222  }
1223 
1232  public function isWatchable() {
1233  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
1234  return $this->getText() !== '' && !$this->isExternal() &&
1235  $nsInfo->isWatchable( $this->mNamespace );
1236  }
1237 
1243  public function isSpecialPage() {
1244  return $this->mNamespace == NS_SPECIAL;
1245  }
1246 
1253  public function isSpecial( $name ) {
1254  if ( $this->isSpecialPage() ) {
1255  list( $thisName, /* $subpage */ ) =
1256  MediaWikiServices::getInstance()->getSpecialPageFactory()->
1257  resolveAlias( $this->mDbkeyform );
1258  if ( $name == $thisName ) {
1259  return true;
1260  }
1261  }
1262  return false;
1263  }
1264 
1271  public function fixSpecialName() {
1272  if ( $this->isSpecialPage() ) {
1273  $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory();
1274  list( $canonicalName, $par ) = $spFactory->resolveAlias( $this->mDbkeyform );
1275  if ( $canonicalName ) {
1276  $localName = $spFactory->getLocalNameFor( $canonicalName, $par );
1277  if ( $localName != $this->mDbkeyform ) {
1278  return self::makeTitle( NS_SPECIAL, $localName );
1279  }
1280  }
1281  }
1282  return $this;
1283  }
1284 
1295  public function inNamespace( $ns ) {
1296  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1297  equals( $this->mNamespace, $ns );
1298  }
1299 
1307  public function inNamespaces( ...$namespaces ) {
1308  if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) {
1309  $namespaces = $namespaces[0];
1310  }
1311 
1312  foreach ( $namespaces as $ns ) {
1313  if ( $this->inNamespace( $ns ) ) {
1314  return true;
1315  }
1316  }
1317 
1318  return false;
1319  }
1320 
1334  public function hasSubjectNamespace( $ns ) {
1335  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1336  subjectEquals( $this->mNamespace, $ns );
1337  }
1338 
1346  public function isContentPage() {
1347  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1348  isContent( $this->mNamespace );
1349  }
1350 
1357  public function isMovable() {
1358  if (
1359  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1360  isMovable( $this->mNamespace ) || $this->isExternal()
1361  ) {
1362  // Interwiki title or immovable namespace. Hooks don't get to override here
1363  return false;
1364  }
1365 
1366  $result = true;
1367  Hooks::run( 'TitleIsMovable', [ $this, &$result ] );
1368  return $result;
1369  }
1370 
1381  public function isMainPage() {
1382  return $this->equals( self::newMainPage() );
1383  }
1384 
1390  public function isSubpage() {
1391  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1392  hasSubpages( $this->mNamespace )
1393  ? strpos( $this->getText(), '/' ) !== false
1394  : false;
1395  }
1396 
1402  public function isConversionTable() {
1403  // @todo ConversionTable should become a separate content model.
1404 
1405  return $this->mNamespace == NS_MEDIAWIKI &&
1406  strpos( $this->getText(), 'Conversiontable/' ) === 0;
1407  }
1408 
1414  public function isWikitextPage() {
1415  return $this->hasContentModel( CONTENT_MODEL_WIKITEXT );
1416  }
1417 
1432  public function isSiteConfigPage() {
1433  return (
1434  $this->isSiteCssConfigPage()
1435  || $this->isSiteJsonConfigPage()
1436  || $this->isSiteJsConfigPage()
1437  );
1438  }
1439 
1446  public function isUserConfigPage() {
1447  return (
1448  $this->isUserCssConfigPage()
1449  || $this->isUserJsonConfigPage()
1450  || $this->isUserJsConfigPage()
1451  );
1452  }
1453 
1460  public function getSkinFromConfigSubpage() {
1461  $subpage = explode( '/', $this->mTextform );
1462  $subpage = $subpage[count( $subpage ) - 1];
1463  $lastdot = strrpos( $subpage, '.' );
1464  if ( $lastdot === false ) {
1465  return $subpage; # Never happens: only called for names ending in '.css'/'.json'/'.js'
1466  }
1467  return substr( $subpage, 0, $lastdot );
1468  }
1469 
1476  public function isUserCssConfigPage() {
1477  return (
1478  NS_USER == $this->mNamespace
1479  && $this->isSubpage()
1480  && $this->hasContentModel( CONTENT_MODEL_CSS )
1481  );
1482  }
1483 
1490  public function isUserJsonConfigPage() {
1491  return (
1492  NS_USER == $this->mNamespace
1493  && $this->isSubpage()
1494  && $this->hasContentModel( CONTENT_MODEL_JSON )
1495  );
1496  }
1497 
1504  public function isUserJsConfigPage() {
1505  return (
1506  NS_USER == $this->mNamespace
1507  && $this->isSubpage()
1509  );
1510  }
1511 
1518  public function isSiteCssConfigPage() {
1519  return (
1520  NS_MEDIAWIKI == $this->mNamespace
1521  && (
1523  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1524  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1525  || substr( $this->mDbkeyform, -4 ) === '.css'
1526  )
1527  );
1528  }
1529 
1536  public function isSiteJsonConfigPage() {
1537  return (
1538  NS_MEDIAWIKI == $this->mNamespace
1539  && (
1541  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1542  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1543  || substr( $this->mDbkeyform, -5 ) === '.json'
1544  )
1545  );
1546  }
1547 
1554  public function isSiteJsConfigPage() {
1555  return (
1556  NS_MEDIAWIKI == $this->mNamespace
1557  && (
1559  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1560  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1561  || substr( $this->mDbkeyform, -3 ) === '.js'
1562  )
1563  );
1564  }
1565 
1572  public function isRawHtmlMessage() {
1573  global $wgRawHtmlMessages;
1574 
1575  if ( !$this->inNamespace( NS_MEDIAWIKI ) ) {
1576  return false;
1577  }
1578  $message = lcfirst( $this->getRootTitle()->getDBkey() );
1579  return in_array( $message, $wgRawHtmlMessages, true );
1580  }
1581 
1587  public function isTalkPage() {
1588  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1589  isTalk( $this->mNamespace );
1590  }
1591 
1603  public function getTalkPage() {
1604  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1605  // Instead of failing on invalid titles, let's just log the issue for now.
1606  // See the discussion on T227817.
1607 
1608  // Is this the same title?
1609  $talkNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $this->mNamespace );
1610  if ( $this->mNamespace == $talkNS ) {
1611  return $this;
1612  }
1613 
1614  $title = self::makeTitle( $talkNS, $this->mDbkeyform );
1615 
1616  $this->warnIfPageCannotExist( $title, __METHOD__ );
1617 
1618  return $title;
1619  // TODO: replace the above with the code below:
1620  // return self::castFromLinkTarget(
1621  // MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) );
1622  }
1623 
1633  public function getTalkPageIfDefined() {
1634  if ( !$this->canHaveTalkPage() ) {
1635  return null;
1636  }
1637 
1638  return $this->getTalkPage();
1639  }
1640 
1648  public function getSubjectPage() {
1649  // Is this the same title?
1650  $subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo()
1651  ->getSubject( $this->mNamespace );
1652  if ( $this->mNamespace == $subjectNS ) {
1653  return $this;
1654  }
1655  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1656  // Instead of failing on invalid titles, let's just log the issue for now.
1657  // See the discussion on T227817.
1658  $title = self::makeTitle( $subjectNS, $this->mDbkeyform );
1659 
1660  $this->warnIfPageCannotExist( $title, __METHOD__ );
1661 
1662  return $title;
1663  // TODO: replace the above with the code below:
1664  // return self::castFromLinkTarget(
1665  // MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
1666  }
1667 
1674  private function warnIfPageCannotExist( Title $title, $method ) {
1675  if ( $this->getText() == '' ) {
1676  wfLogWarning(
1677  $method . ': called on empty title ' . $this->getFullText() . ', returning '
1678  . $title->getFullText()
1679  );
1680 
1681  return true;
1682  }
1683 
1684  if ( $this->getInterwiki() !== '' ) {
1685  wfLogWarning(
1686  $method . ': called on interwiki title ' . $this->getFullText() . ', returning '
1687  . $title->getFullText()
1688  );
1689 
1690  return true;
1691  }
1692 
1693  return false;
1694  }
1695 
1705  public function getOtherPage() {
1706  // NOTE: Depend on the methods in this class instead of their equivalent in NamespaceInfo,
1707  // until their semantics has become exactly the same.
1708  // See the discussion on T227817.
1709  if ( $this->isSpecialPage() ) {
1710  throw new MWException( 'Special pages cannot have other pages' );
1711  }
1712  if ( $this->isTalkPage() ) {
1713  return $this->getSubjectPage();
1714  } else {
1715  if ( !$this->canHaveTalkPage() ) {
1716  throw new MWException( "{$this->getPrefixedText()} does not have an other page" );
1717  }
1718  return $this->getTalkPage();
1719  }
1720  // TODO: replace the above with the code below:
1721  // return self::castFromLinkTarget(
1722  // MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) );
1723  }
1724 
1730  public function getDefaultNamespace() {
1731  return $this->mDefaultNamespace;
1732  }
1733 
1741  public function getFragment() {
1742  return $this->mFragment;
1743  }
1744 
1751  public function hasFragment() {
1752  return $this->mFragment !== '';
1753  }
1754 
1760  public function getFragmentForURL() {
1761  if ( !$this->hasFragment() ) {
1762  return '';
1763  } elseif ( $this->isExternal() ) {
1764  // Note: If the interwiki is unknown, it's treated as a namespace on the local wiki,
1765  // so we treat it like a local interwiki.
1766  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
1767  if ( $interwiki && !$interwiki->isLocal() ) {
1768  return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment );
1769  }
1770  }
1771 
1772  return '#' . Sanitizer::escapeIdForLink( $this->mFragment );
1773  }
1774 
1787  public function setFragment( $fragment ) {
1788  $this->mFragment = strtr( substr( $fragment, 1 ), '_', ' ' );
1789  }
1790 
1798  public function createFragmentTarget( $fragment ) {
1799  return self::makeTitle(
1800  $this->mNamespace,
1801  $this->getText(),
1802  $fragment,
1803  $this->mInterwiki
1804  );
1805  }
1806 
1814  private function prefix( $name ) {
1815  $p = '';
1816  if ( $this->isExternal() ) {
1817  $p = $this->mInterwiki . ':';
1818  }
1819 
1820  if ( $this->mNamespace != 0 ) {
1821  $nsText = $this->getNsText();
1822 
1823  if ( $nsText === false ) {
1824  // See T165149. Awkward, but better than erroneously linking to the main namespace.
1825  $nsText = MediaWikiServices::getInstance()->getContentLanguage()->
1826  getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
1827  }
1828 
1829  $p .= $nsText . ':';
1830  }
1831  return $p . $name;
1832  }
1833 
1841  public function getPrefixedDBkey() {
1842  $s = $this->prefix( $this->mDbkeyform );
1843  $s = strtr( $s, ' ', '_' );
1844  return $s;
1845  }
1846 
1854  public function getPrefixedText() {
1855  if ( $this->prefixedText === null ) {
1856  $s = $this->prefix( $this->mTextform );
1857  $s = strtr( $s, '_', ' ' );
1858  $this->prefixedText = $s;
1859  }
1860  return $this->prefixedText;
1861  }
1862 
1868  public function __toString() {
1869  return $this->getPrefixedText();
1870  }
1871 
1878  public function getFullText() {
1879  $text = $this->getPrefixedText();
1880  if ( $this->hasFragment() ) {
1881  $text .= '#' . $this->mFragment;
1882  }
1883  return $text;
1884  }
1885 
1901  public function getRootText() {
1902  if (
1903  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1904  hasSubpages( $this->mNamespace )
1905  || strtok( $this->getText(), '/' ) === false
1906  ) {
1907  return $this->getText();
1908  }
1909 
1910  return strtok( $this->getText(), '/' );
1911  }
1912 
1925  public function getRootTitle() {
1926  $title = self::makeTitleSafe( $this->mNamespace, $this->getRootText() );
1927  Assert::postcondition(
1928  $title !== null,
1929  'makeTitleSafe() should always return a Title for the text returned by getRootText().'
1930  );
1931  return $title;
1932  }
1933 
1948  public function getBaseText() {
1949  $text = $this->getText();
1950  if (
1951  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1952  hasSubpages( $this->mNamespace )
1953  ) {
1954  return $text;
1955  }
1956 
1957  $lastSlashPos = strrpos( $text, '/' );
1958  // Don't discard the real title if there's no subpage involved
1959  if ( $lastSlashPos === false ) {
1960  return $text;
1961  }
1962 
1963  return substr( $text, 0, $lastSlashPos );
1964  }
1965 
1978  public function getBaseTitle() {
1979  $title = self::makeTitleSafe( $this->mNamespace, $this->getBaseText() );
1980  Assert::postcondition(
1981  $title !== null,
1982  'makeTitleSafe() should always return a Title for the text returned by getBaseText().'
1983  );
1984  return $title;
1985  }
1986 
1998  public function getSubpageText() {
1999  if (
2000  !MediaWikiServices::getInstance()->getNamespaceInfo()->
2001  hasSubpages( $this->mNamespace )
2002  ) {
2003  return $this->mTextform;
2004  }
2005  $parts = explode( '/', $this->mTextform );
2006  return $parts[count( $parts ) - 1];
2007  }
2008 
2022  public function getSubpage( $text ) {
2023  return self::makeTitleSafe(
2024  $this->mNamespace,
2025  $this->getText() . '/' . $text,
2026  '',
2027  $this->mInterwiki
2028  );
2029  }
2030 
2036  public function getSubpageUrlForm() {
2037  $text = $this->getSubpageText();
2038  $text = wfUrlencode( strtr( $text, ' ', '_' ) );
2039  return $text;
2040  }
2041 
2047  public function getPrefixedURL() {
2048  $s = $this->prefix( $this->mDbkeyform );
2049  $s = wfUrlencode( strtr( $s, ' ', '_' ) );
2050  return $s;
2051  }
2052 
2066  private static function fixUrlQueryArgs( $query, $query2 = false ) {
2067  if ( $query2 !== false ) {
2068  wfDeprecated( "Title::get{Canonical,Full,Link,Local,Internal}URL " .
2069  "method called with a second parameter is deprecated. Add your " .
2070  "parameter to an array passed as the first parameter.", "1.19" );
2071  }
2072  if ( is_array( $query ) ) {
2073  $query = wfArrayToCgi( $query );
2074  }
2075  if ( $query2 ) {
2076  if ( is_string( $query2 ) ) {
2077  // $query2 is a string, we will consider this to be
2078  // a deprecated $variant argument and add it to the query
2079  $query2 = wfArrayToCgi( [ 'variant' => $query2 ] );
2080  } else {
2081  $query2 = wfArrayToCgi( $query2 );
2082  }
2083  // If we have $query content add a & to it first
2084  if ( $query ) {
2085  $query .= '&';
2086  }
2087  // Now append the queries together
2088  $query .= $query2;
2089  }
2090  return $query;
2091  }
2092 
2104  public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
2105  $query = self::fixUrlQueryArgs( $query, $query2 );
2106 
2107  # Hand off all the decisions on urls to getLocalURL
2108  $url = $this->getLocalURL( $query );
2109 
2110  # Expand the url to make it a full url. Note that getLocalURL has the
2111  # potential to output full urls for a variety of reasons, so we use
2112  # wfExpandUrl instead of simply prepending $wgServer
2113  $url = wfExpandUrl( $url, $proto );
2114 
2115  # Finally, add the fragment.
2116  $url .= $this->getFragmentForURL();
2117  // Avoid PHP 7.1 warning from passing $this by reference
2118  $titleRef = $this;
2119  Hooks::run( 'GetFullURL', [ &$titleRef, &$url, $query ] );
2120  return $url;
2121  }
2122 
2139  public function getFullUrlForRedirect( $query = '', $proto = PROTO_CURRENT ) {
2140  $target = $this;
2141  if ( $this->isExternal() ) {
2142  $target = SpecialPage::getTitleFor(
2143  'GoToInterwiki',
2144  $this->getPrefixedDBkey()
2145  );
2146  }
2147  return $target->getFullURL( $query, false, $proto );
2148  }
2149 
2173  public function getLocalURL( $query = '', $query2 = false ) {
2175 
2176  $query = self::fixUrlQueryArgs( $query, $query2 );
2177 
2178  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
2179  if ( $interwiki ) {
2180  $namespace = $this->getNsText();
2181  if ( $namespace != '' ) {
2182  # Can this actually happen? Interwikis shouldn't be parsed.
2183  # Yes! It can in interwiki transclusion. But... it probably shouldn't.
2184  $namespace .= ':';
2185  }
2186  $url = $interwiki->getURL( $namespace . $this->mDbkeyform );
2187  $url = wfAppendQuery( $url, $query );
2188  } else {
2189  $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
2190  if ( $query == '' ) {
2191  $url = str_replace( '$1', $dbkey, $wgArticlePath );
2192  // Avoid PHP 7.1 warning from passing $this by reference
2193  $titleRef = $this;
2194  Hooks::run( 'GetLocalURL::Article', [ &$titleRef, &$url ] );
2195  } else {
2197  $url = false;
2198  $matches = [];
2199 
2201 
2202  if ( $articlePaths
2203  && preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
2204  ) {
2205  $action = urldecode( $matches[2] );
2206  if ( isset( $articlePaths[$action] ) ) {
2207  $query = $matches[1];
2208  if ( isset( $matches[4] ) ) {
2209  $query .= $matches[4];
2210  }
2211  $url = str_replace( '$1', $dbkey, $articlePaths[$action] );
2212  if ( $query != '' ) {
2213  $url = wfAppendQuery( $url, $query );
2214  }
2215  }
2216  }
2217 
2218  if ( $url === false
2220  && preg_match( '/^variant=([^&]*)$/', $query, $matches )
2221  && $this->getPageLanguage()->equals(
2222  MediaWikiServices::getInstance()->getContentLanguage() )
2223  && $this->getPageLanguageConverter()->hasVariants()
2224  ) {
2225  $variant = urldecode( $matches[1] );
2226  if ( $this->getPageLanguageConverter()->hasVariant( $variant ) ) {
2227  // Only do the variant replacement if the given variant is a valid
2228  // variant for the page's language.
2229  $url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath );
2230  $url = str_replace( '$1', $dbkey, $url );
2231  }
2232  }
2233 
2234  if ( $url === false ) {
2235  if ( $query == '-' ) {
2236  $query = '';
2237  }
2238  $url = "{$wgScript}?title={$dbkey}&{$query}";
2239  }
2240  }
2241  // Avoid PHP 7.1 warning from passing $this by reference
2242  $titleRef = $this;
2243  Hooks::run( 'GetLocalURL::Internal', [ &$titleRef, &$url, $query ] );
2244 
2245  // @todo FIXME: This causes breakage in various places when we
2246  // actually expected a local URL and end up with dupe prefixes.
2247  if ( $wgRequest->getVal( 'action' ) == 'render' ) {
2248  $url = $wgServer . $url;
2249  }
2250  }
2251 
2252  if ( $wgMainPageIsDomainRoot && $this->isMainPage() && $query === '' ) {
2253  return '/';
2254  }
2255 
2256  // Avoid PHP 7.1 warning from passing $this by reference
2257  $titleRef = $this;
2258  Hooks::run( 'GetLocalURL', [ &$titleRef, &$url, $query ] );
2259  return $url;
2260  }
2261 
2279  public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
2280  if ( $this->isExternal() || $proto !== false ) {
2281  $ret = $this->getFullURL( $query, $query2, $proto );
2282  } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
2283  $ret = $this->getFragmentForURL();
2284  } else {
2285  $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
2286  }
2287  return $ret;
2288  }
2289 
2304  public function getInternalURL( $query = '', $query2 = false ) {
2305  global $wgInternalServer, $wgServer;
2306  $query = self::fixUrlQueryArgs( $query, $query2 );
2307  $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
2308  $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP );
2309  // Avoid PHP 7.1 warning from passing $this by reference
2310  $titleRef = $this;
2311  Hooks::run( 'GetInternalURL', [ &$titleRef, &$url, $query ] );
2312  return $url;
2313  }
2314 
2328  public function getCanonicalURL( $query = '', $query2 = false ) {
2329  $query = self::fixUrlQueryArgs( $query, $query2 );
2330  $url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL );
2331  // Avoid PHP 7.1 warning from passing $this by reference
2332  $titleRef = $this;
2333  Hooks::run( 'GetCanonicalURL', [ &$titleRef, &$url, $query ] );
2334  return $url;
2335  }
2336 
2342  public function getEditURL() {
2343  if ( $this->isExternal() ) {
2344  return '';
2345  }
2346  $s = $this->getLocalURL( 'action=edit' );
2347 
2348  return $s;
2349  }
2350 
2371  public function quickUserCan( $action, $user = null ) {
2372  wfDeprecated( __METHOD__, '1.33' );
2373  if ( !$user instanceof User ) {
2374  global $wgUser;
2375  $user = $wgUser;
2376  }
2377  return MediaWikiServices::getInstance()->getPermissionManager()
2378  ->quickUserCan( $action, $user, $this );
2379  }
2380 
2396  public function userCan( $action, $user = null, $rigor = PermissionManager::RIGOR_SECURE ) {
2397  wfDeprecated( __METHOD__, '1.33' );
2398  if ( !$user instanceof User ) {
2399  global $wgUser;
2400  $user = $wgUser;
2401  }
2402 
2403  // TODO: this is for b/c, eventually will be removed
2404  if ( $rigor === true ) {
2405  $rigor = PermissionManager::RIGOR_SECURE; // b/c
2406  } elseif ( $rigor === false ) {
2407  $rigor = PermissionManager::RIGOR_QUICK; // b/c
2408  }
2409 
2410  return MediaWikiServices::getInstance()->getPermissionManager()
2411  ->userCan( $action, $user, $this, $rigor );
2412  }
2413 
2435  public function getUserPermissionsErrors(
2436  $action, $user, $rigor = PermissionManager::RIGOR_SECURE, $ignoreErrors = []
2437  ) {
2438  wfDeprecated( __METHOD__, '1.33' );
2439 
2440  // TODO: this is for b/c, eventually will be removed
2441  if ( $rigor === true ) {
2442  $rigor = PermissionManager::RIGOR_SECURE; // b/c
2443  } elseif ( $rigor === false ) {
2444  $rigor = PermissionManager::RIGOR_QUICK; // b/c
2445  }
2446 
2447  return MediaWikiServices::getInstance()->getPermissionManager()
2448  ->getPermissionErrors( $action, $user, $this, $rigor, $ignoreErrors );
2449  }
2450 
2458  public static function getFilteredRestrictionTypes( $exists = true ) {
2459  global $wgRestrictionTypes;
2460  $types = $wgRestrictionTypes;
2461  if ( $exists ) {
2462  # Remove the create restriction for existing titles
2463  $types = array_diff( $types, [ 'create' ] );
2464  } else {
2465  # Only the create and upload restrictions apply to non-existing titles
2466  $types = array_intersect( $types, [ 'create', 'upload' ] );
2467  }
2468  return $types;
2469  }
2470 
2476  public function getRestrictionTypes() {
2477  if ( $this->isSpecialPage() ) {
2478  return [];
2479  }
2480 
2481  $types = self::getFilteredRestrictionTypes( $this->exists() );
2482 
2483  if ( $this->mNamespace != NS_FILE ) {
2484  # Remove the upload restriction for non-file titles
2485  $types = array_diff( $types, [ 'upload' ] );
2486  }
2487 
2488  Hooks::run( 'TitleGetRestrictionTypes', [ $this, &$types ] );
2489 
2490  wfDebug( __METHOD__ . ': applicable restrictions to [[' .
2491  $this->getPrefixedText() . ']] are {' . implode( ',', $types ) . "}\n" );
2492 
2493  return $types;
2494  }
2495 
2503  public function getTitleProtection() {
2504  $protection = $this->getTitleProtectionInternal();
2505  if ( $protection ) {
2506  if ( $protection['permission'] == 'sysop' ) {
2507  $protection['permission'] = 'editprotected'; // B/C
2508  }
2509  if ( $protection['permission'] == 'autoconfirmed' ) {
2510  $protection['permission'] = 'editsemiprotected'; // B/C
2511  }
2512  }
2513  return $protection;
2514  }
2515 
2526  protected function getTitleProtectionInternal() {
2527  // Can't protect pages in special namespaces
2528  if ( $this->mNamespace < 0 ) {
2529  return false;
2530  }
2531 
2532  // Can't protect pages that exist.
2533  if ( $this->exists() ) {
2534  return false;
2535  }
2536 
2537  if ( $this->mTitleProtection === null ) {
2538  $dbr = wfGetDB( DB_REPLICA );
2539  $commentStore = CommentStore::getStore();
2540  $commentQuery = $commentStore->getJoin( 'pt_reason' );
2541  $res = $dbr->select(
2542  [ 'protected_titles' ] + $commentQuery['tables'],
2543  [
2544  'user' => 'pt_user',
2545  'expiry' => 'pt_expiry',
2546  'permission' => 'pt_create_perm'
2547  ] + $commentQuery['fields'],
2548  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2549  __METHOD__,
2550  [],
2551  $commentQuery['joins']
2552  );
2553 
2554  // fetchRow returns false if there are no rows.
2555  $row = $dbr->fetchRow( $res );
2556  if ( $row ) {
2557  $this->mTitleProtection = [
2558  'user' => $row['user'],
2559  'expiry' => $dbr->decodeExpiry( $row['expiry'] ),
2560  'permission' => $row['permission'],
2561  'reason' => $commentStore->getComment( 'pt_reason', $row )->text,
2562  ];
2563  } else {
2564  $this->mTitleProtection = false;
2565  }
2566  }
2567  return $this->mTitleProtection;
2568  }
2569 
2573  public function deleteTitleProtection() {
2574  $dbw = wfGetDB( DB_MASTER );
2575 
2576  $dbw->delete(
2577  'protected_titles',
2578  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2579  __METHOD__
2580  );
2581  $this->mTitleProtection = false;
2582  }
2583 
2591  public function isSemiProtected( $action = 'edit' ) {
2593 
2594  $restrictions = $this->getRestrictions( $action );
2596  if ( !$restrictions || !$semi ) {
2597  // Not protected, or all protection is full protection
2598  return false;
2599  }
2600 
2601  // Remap autoconfirmed to editsemiprotected for BC
2602  foreach ( array_keys( $semi, 'autoconfirmed' ) as $key ) {
2603  $semi[$key] = 'editsemiprotected';
2604  }
2605  foreach ( array_keys( $restrictions, 'autoconfirmed' ) as $key ) {
2606  $restrictions[$key] = 'editsemiprotected';
2607  }
2608 
2609  return !array_diff( $restrictions, $semi );
2610  }
2611 
2619  public function isProtected( $action = '' ) {
2620  global $wgRestrictionLevels;
2621 
2622  $restrictionTypes = $this->getRestrictionTypes();
2623 
2624  # Special pages have inherent protection
2625  if ( $this->isSpecialPage() ) {
2626  return true;
2627  }
2628 
2629  # Check regular protection levels
2630  foreach ( $restrictionTypes as $type ) {
2631  if ( $action == $type || $action == '' ) {
2632  $r = $this->getRestrictions( $type );
2633  foreach ( $wgRestrictionLevels as $level ) {
2634  if ( in_array( $level, $r ) && $level != '' ) {
2635  return true;
2636  }
2637  }
2638  }
2639  }
2640 
2641  return false;
2642  }
2643 
2652  public function isNamespaceProtected( User $user ) {
2653  global $wgNamespaceProtection;
2654 
2655  if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
2656  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2657  foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
2658  if ( !$permissionManager->userHasRight( $user, $right ) ) {
2659  return true;
2660  }
2661  }
2662  }
2663  return false;
2664  }
2665 
2671  public function isCascadeProtected() {
2672  list( $isCascadeProtected, ) = $this->getCascadeProtectionSources( false );
2673  return $isCascadeProtected;
2674  }
2675 
2685  public function areCascadeProtectionSourcesLoaded( $getPages = true ) {
2686  return $getPages ? $this->mCascadeSources !== null : $this->mHasCascadingRestrictions !== null;
2687  }
2688 
2702  public function getCascadeProtectionSources( $getPages = true ) {
2703  $pagerestrictions = [];
2704 
2705  if ( $this->mCascadeSources !== null && $getPages ) {
2707  } elseif ( $this->mHasCascadingRestrictions !== null && !$getPages ) {
2708  return [ $this->mHasCascadingRestrictions, $pagerestrictions ];
2709  }
2710 
2711  $dbr = wfGetDB( DB_REPLICA );
2712 
2713  if ( $this->mNamespace == NS_FILE ) {
2714  $tables = [ 'imagelinks', 'page_restrictions' ];
2715  $where_clauses = [
2716  'il_to' => $this->mDbkeyform,
2717  'il_from=pr_page',
2718  'pr_cascade' => 1
2719  ];
2720  } else {
2721  $tables = [ 'templatelinks', 'page_restrictions' ];
2722  $where_clauses = [
2723  'tl_namespace' => $this->mNamespace,
2724  'tl_title' => $this->mDbkeyform,
2725  'tl_from=pr_page',
2726  'pr_cascade' => 1
2727  ];
2728  }
2729 
2730  if ( $getPages ) {
2731  $cols = [ 'pr_page', 'page_namespace', 'page_title',
2732  'pr_expiry', 'pr_type', 'pr_level' ];
2733  $where_clauses[] = 'page_id=pr_page';
2734  $tables[] = 'page';
2735  } else {
2736  $cols = [ 'pr_expiry' ];
2737  }
2738 
2739  $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__ );
2740 
2741  $sources = $getPages ? [] : false;
2742  $now = wfTimestampNow();
2743 
2744  foreach ( $res as $row ) {
2745  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2746  if ( $expiry > $now ) {
2747  if ( $getPages ) {
2748  $page_id = $row->pr_page;
2749  $page_ns = $row->page_namespace;
2750  $page_title = $row->page_title;
2751  $sources[$page_id] = self::makeTitle( $page_ns, $page_title );
2752  # Add groups needed for each restriction type if its not already there
2753  # Make sure this restriction type still exists
2754 
2755  if ( !isset( $pagerestrictions[$row->pr_type] ) ) {
2756  $pagerestrictions[$row->pr_type] = [];
2757  }
2758 
2759  if (
2760  isset( $pagerestrictions[$row->pr_type] )
2761  && !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] )
2762  ) {
2763  $pagerestrictions[$row->pr_type][] = $row->pr_level;
2764  }
2765  } else {
2766  $sources = true;
2767  }
2768  }
2769  }
2770 
2771  if ( $getPages ) {
2772  $this->mCascadeSources = $sources;
2773  $this->mCascadingRestrictions = $pagerestrictions;
2774  } else {
2775  $this->mHasCascadingRestrictions = $sources;
2776  }
2777 
2778  return [ $sources, $pagerestrictions ];
2779  }
2780 
2788  public function areRestrictionsLoaded() {
2790  }
2791 
2801  public function getRestrictions( $action ) {
2802  if ( !$this->mRestrictionsLoaded ) {
2803  $this->loadRestrictions();
2804  }
2805  return $this->mRestrictions[$action] ?? [];
2806  }
2807 
2815  public function getAllRestrictions() {
2816  if ( !$this->mRestrictionsLoaded ) {
2817  $this->loadRestrictions();
2818  }
2819  return $this->mRestrictions;
2820  }
2821 
2829  public function getRestrictionExpiry( $action ) {
2830  if ( !$this->mRestrictionsLoaded ) {
2831  $this->loadRestrictions();
2832  }
2833  return $this->mRestrictionsExpiry[$action] ?? false;
2834  }
2835 
2841  public function areRestrictionsCascading() {
2842  if ( !$this->mRestrictionsLoaded ) {
2843  $this->loadRestrictions();
2844  }
2845 
2847  }
2848 
2860  public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
2861  // This function will only read rows from a table that we migrated away
2862  // from before adding READ_LATEST support to loadRestrictions, so we
2863  // don't need to support reading from DB_MASTER here.
2864  $dbr = wfGetDB( DB_REPLICA );
2865 
2866  $restrictionTypes = $this->getRestrictionTypes();
2867 
2868  foreach ( $restrictionTypes as $type ) {
2869  $this->mRestrictions[$type] = [];
2870  $this->mRestrictionsExpiry[$type] = 'infinity';
2871  }
2872 
2873  $this->mCascadeRestriction = false;
2874 
2875  # Backwards-compatibility: also load the restrictions from the page record (old format).
2876  if ( $oldFashionedRestrictions !== null ) {
2877  $this->mOldRestrictions = $oldFashionedRestrictions;
2878  }
2879 
2880  if ( $this->mOldRestrictions === false ) {
2881  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2882  $linkCache->addLinkObj( $this ); # in case we already had an article ID
2883  $this->mOldRestrictions = $linkCache->getGoodLinkFieldObj( $this, 'restrictions' );
2884  }
2885 
2886  if ( $this->mOldRestrictions != '' ) {
2887  foreach ( explode( ':', trim( $this->mOldRestrictions ) ) as $restrict ) {
2888  $temp = explode( '=', trim( $restrict ) );
2889  if ( count( $temp ) == 1 ) {
2890  // old old format should be treated as edit/move restriction
2891  $this->mRestrictions['edit'] = explode( ',', trim( $temp[0] ) );
2892  $this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) );
2893  } else {
2894  $restriction = trim( $temp[1] );
2895  if ( $restriction != '' ) { // some old entries are empty
2896  $this->mRestrictions[$temp[0]] = explode( ',', $restriction );
2897  }
2898  }
2899  }
2900  }
2901 
2902  if ( count( $rows ) ) {
2903  # Current system - load second to make them override.
2904  $now = wfTimestampNow();
2905 
2906  # Cycle through all the restrictions.
2907  foreach ( $rows as $row ) {
2908  // Don't take care of restrictions types that aren't allowed
2909  if ( !in_array( $row->pr_type, $restrictionTypes ) ) {
2910  continue;
2911  }
2912 
2913  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2914 
2915  // Only apply the restrictions if they haven't expired!
2916  if ( !$expiry || $expiry > $now ) {
2917  $this->mRestrictionsExpiry[$row->pr_type] = $expiry;
2918  $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) );
2919 
2920  $this->mCascadeRestriction |= $row->pr_cascade;
2921  }
2922  }
2923  }
2924 
2925  $this->mRestrictionsLoaded = true;
2926  }
2927 
2938  public function loadRestrictions( $oldFashionedRestrictions = null, $flags = 0 ) {
2939  $readLatest = DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST );
2940  if ( $this->mRestrictionsLoaded && !$readLatest ) {
2941  return;
2942  }
2943 
2944  $id = $this->getArticleID( $flags );
2945  if ( $id ) {
2946  $fname = __METHOD__;
2947  $loadRestrictionsFromDb = function ( IDatabase $dbr ) use ( $fname, $id ) {
2948  return iterator_to_array(
2949  $dbr->select(
2950  'page_restrictions',
2951  [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
2952  [ 'pr_page' => $id ],
2953  $fname
2954  )
2955  );
2956  };
2957 
2958  if ( $readLatest ) {
2959  $dbr = wfGetDB( DB_MASTER );
2960  $rows = $loadRestrictionsFromDb( $dbr );
2961  } else {
2962  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
2963  $rows = $cache->getWithSetCallback(
2964  // Page protections always leave a new null revision
2965  $cache->makeKey( 'page-restrictions', 'v1', $id, $this->getLatestRevID() ),
2966  $cache::TTL_DAY,
2967  function ( $curValue, &$ttl, array &$setOpts ) use ( $loadRestrictionsFromDb ) {
2968  $dbr = wfGetDB( DB_REPLICA );
2969 
2970  $setOpts += Database::getCacheSetOptions( $dbr );
2971  $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
2972  if ( $lb->hasOrMadeRecentMasterChanges() ) {
2973  // @TODO: cleanup Title cache and caller assumption mess in general
2974  $ttl = WANObjectCache::TTL_UNCACHEABLE;
2975  }
2976 
2977  return $loadRestrictionsFromDb( $dbr );
2978  }
2979  );
2980  }
2981 
2982  $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
2983  } else {
2984  $title_protection = $this->getTitleProtectionInternal();
2985 
2986  if ( $title_protection ) {
2987  $now = wfTimestampNow();
2988  $expiry = wfGetDB( DB_REPLICA )->decodeExpiry( $title_protection['expiry'] );
2989 
2990  if ( !$expiry || $expiry > $now ) {
2991  // Apply the restrictions
2992  $this->mRestrictionsExpiry['create'] = $expiry;
2993  $this->mRestrictions['create'] =
2994  explode( ',', trim( $title_protection['permission'] ) );
2995  } else { // Get rid of the old restrictions
2996  $this->mTitleProtection = false;
2997  }
2998  } else {
2999  $this->mRestrictionsExpiry['create'] = 'infinity';
3000  }
3001  $this->mRestrictionsLoaded = true;
3002  }
3003  }
3004 
3009  public function flushRestrictions() {
3010  $this->mRestrictionsLoaded = false;
3011  $this->mTitleProtection = null;
3012  }
3013 
3019  public static function purgeExpiredRestrictions() {
3020  if ( wfReadOnly() ) {
3021  return;
3022  }
3023 
3025  wfGetDB( DB_MASTER ),
3026  __METHOD__,
3027  function ( IDatabase $dbw, $fname ) {
3028  $config = MediaWikiServices::getInstance()->getMainConfig();
3029  $ids = $dbw->selectFieldValues(
3030  'page_restrictions',
3031  'pr_id',
3032  [ 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3033  $fname,
3034  [ 'LIMIT' => $config->get( 'UpdateRowsPerQuery' ) ] // T135470
3035  );
3036  if ( $ids ) {
3037  $dbw->delete( 'page_restrictions', [ 'pr_id' => $ids ], $fname );
3038  }
3039  }
3040  ) );
3041 
3043  wfGetDB( DB_MASTER ),
3044  __METHOD__,
3045  function ( IDatabase $dbw, $fname ) {
3046  $dbw->delete(
3047  'protected_titles',
3048  [ 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3049  $fname
3050  );
3051  }
3052  ) );
3053  }
3054 
3060  public function hasSubpages() {
3061  if (
3062  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3063  hasSubpages( $this->mNamespace )
3064  ) {
3065  # Duh
3066  return false;
3067  }
3068 
3069  # We dynamically add a member variable for the purpose of this method
3070  # alone to cache the result. There's no point in having it hanging
3071  # around uninitialized in every Title object; therefore we only add it
3072  # if needed and don't declare it statically.
3073  if ( $this->mHasSubpages === null ) {
3074  $this->mHasSubpages = false;
3075  $subpages = $this->getSubpages( 1 );
3076  if ( $subpages instanceof TitleArray ) {
3077  $this->mHasSubpages = (bool)$subpages->current();
3078  }
3079  }
3080 
3081  return $this->mHasSubpages;
3082  }
3083 
3091  public function getSubpages( $limit = -1 ) {
3092  if (
3093  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3094  hasSubpages( $this->mNamespace )
3095  ) {
3096  return [];
3097  }
3098 
3099  $dbr = wfGetDB( DB_REPLICA );
3100  $conds = [ 'page_namespace' => $this->mNamespace ];
3101  $conds[] = 'page_title ' . $dbr->buildLike( $this->mDbkeyform . '/', $dbr->anyString() );
3102  $options = [];
3103  if ( $limit > -1 ) {
3104  $options['LIMIT'] = $limit;
3105  }
3107  $dbr->select( 'page',
3108  [ 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ],
3109  $conds,
3110  __METHOD__,
3111  $options
3112  )
3113  );
3114  }
3115 
3121  public function isDeleted() {
3122  if ( $this->mNamespace < 0 ) {
3123  $n = 0;
3124  } else {
3125  $dbr = wfGetDB( DB_REPLICA );
3126 
3127  $n = $dbr->selectField( 'archive', 'COUNT(*)',
3128  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3129  __METHOD__
3130  );
3131  if ( $this->mNamespace == NS_FILE ) {
3132  $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
3133  [ 'fa_name' => $this->mDbkeyform ],
3134  __METHOD__
3135  );
3136  }
3137  }
3138  return (int)$n;
3139  }
3140 
3146  public function isDeletedQuick() {
3147  if ( $this->mNamespace < 0 ) {
3148  return false;
3149  }
3150  $dbr = wfGetDB( DB_REPLICA );
3151  $deleted = (bool)$dbr->selectField( 'archive', '1',
3152  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3153  __METHOD__
3154  );
3155  if ( !$deleted && $this->mNamespace == NS_FILE ) {
3156  $deleted = (bool)$dbr->selectField( 'filearchive', '1',
3157  [ 'fa_name' => $this->mDbkeyform ],
3158  __METHOD__
3159  );
3160  }
3161  return $deleted;
3162  }
3163 
3171  public function getArticleID( $flags = 0 ) {
3172  if ( $this->mNamespace < 0 ) {
3173  $this->mArticleID = 0;
3174 
3175  return $this->mArticleID;
3176  }
3177 
3178  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3179  if ( $flags & self::GAID_FOR_UPDATE ) {
3180  $oldUpdate = $linkCache->forUpdate( true );
3181  $linkCache->clearLink( $this );
3182  $this->mArticleID = $linkCache->addLinkObj( $this );
3183  $linkCache->forUpdate( $oldUpdate );
3184  } elseif ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3185  // If mArticleID is >0, pageCond() will use it, making it impossible
3186  // for the call below to return a different result, e.g. after a
3187  // page move.
3188  $this->mArticleID = -1;
3189  $this->mArticleID = (int)$this->loadFieldFromDB( 'page_id', $flags );
3190  } elseif ( $this->mArticleID == -1 ) {
3191  $this->mArticleID = $linkCache->addLinkObj( $this );
3192  }
3193 
3194  return $this->mArticleID;
3195  }
3196 
3204  public function isRedirect( $flags = 0 ) {
3205  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3206  $this->mRedirect = (bool)$this->loadFieldFromDB( 'page_is_redirect', $flags );
3207  } elseif ( $this->mRedirect === null ) {
3208  if ( $this->getArticleID( $flags ) ) {
3209  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3210  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3211  // Note that LinkCache returns null if it thinks the page does not exist;
3212  // always trust the state of LinkCache over that of this Title instance.
3213  $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
3214  } else {
3215  $this->mRedirect = false;
3216  }
3217  }
3218 
3219  return $this->mRedirect;
3220  }
3221 
3229  public function getLength( $flags = 0 ) {
3230  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3231  $this->mLength = (int)$this->loadFieldFromDB( 'page_len', $flags );
3232  } else {
3233  if ( $this->mLength != -1 ) {
3234  return $this->mLength;
3235  } elseif ( !$this->getArticleID( $flags ) ) {
3236  $this->mLength = 0;
3237  return $this->mLength;
3238  }
3239 
3240  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3241  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3242  // Note that LinkCache returns null if it thinks the page does not exist;
3243  // always trust the state of LinkCache over that of this Title instance.
3244  $this->mLength = (int)$linkCache->getGoodLinkFieldObj( $this, 'length' );
3245  }
3246 
3247  return $this->mLength;
3248  }
3249 
3256  public function getLatestRevID( $flags = 0 ) {
3257  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3258  $this->mLatestID = (int)$this->loadFieldFromDB( 'page_latest', $flags );
3259  } else {
3260  if ( $this->mLatestID !== false ) {
3261  return (int)$this->mLatestID;
3262  } elseif ( !$this->getArticleID( $flags ) ) {
3263  $this->mLatestID = 0;
3264 
3265  return $this->mLatestID;
3266  }
3267 
3268  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3269  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3270  // Note that LinkCache returns null if it thinks the page does not exist;
3271  // always trust the state of LinkCache over that of this Title instance.
3272  $this->mLatestID = (int)$linkCache->getGoodLinkFieldObj( $this, 'revision' );
3273  }
3274 
3275  return $this->mLatestID;
3276  }
3277 
3291  public function resetArticleID( $id ) {
3292  if ( $id === false ) {
3293  $this->mArticleID = -1;
3294  } else {
3295  $this->mArticleID = (int)$id;
3296  }
3297  $this->mRestrictionsLoaded = false;
3298  $this->mRestrictions = [];
3299  $this->mOldRestrictions = false;
3300  $this->mRedirect = null;
3301  $this->mLength = -1;
3302  $this->mLatestID = false;
3303  $this->mContentModel = false;
3304  $this->mForcedContentModel = false;
3305  $this->mEstimateRevisions = null;
3306  $this->mPageLanguage = null;
3307  $this->mDbPageLanguage = false;
3308  $this->mIsBigDeletion = null;
3309 
3310  MediaWikiServices::getInstance()->getLinkCache()->clearLink( $this );
3311  }
3312 
3313  public static function clearCaches() {
3314  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3315  $linkCache->clear();
3316 
3318  $titleCache->clear();
3319  }
3320 
3328  public static function capitalize( $text, $ns = NS_MAIN ) {
3329  $services = MediaWikiServices::getInstance();
3330  if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) {
3331  return $services->getContentLanguage()->ucfirst( $text );
3332  } else {
3333  return $text;
3334  }
3335  }
3336 
3353  private function secureAndSplit( $text, $defaultNamespace = null ) {
3354  if ( $defaultNamespace === null ) {
3355  $defaultNamespace = $this->mDefaultNamespace;
3356  }
3357 
3358  // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
3359  // the parsing code with Title, while avoiding massive refactoring.
3360  // @todo: get rid of secureAndSplit, refactor parsing code.
3361  // @note: getTitleParser() returns a TitleParser implementation which does not have a
3362  // splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
3364  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
3365  '@phan-var MediaWikiTitleCodec $titleCodec';
3366  // MalformedTitleException can be thrown here
3367  $parts = $titleCodec->splitTitleString( $text, $defaultNamespace );
3368 
3369  # Fill fields
3370  $this->setFragment( '#' . $parts['fragment'] );
3371  $this->mInterwiki = $parts['interwiki'];
3372  $this->mLocalInterwiki = $parts['local_interwiki'];
3373  $this->mNamespace = $parts['namespace'];
3374  $this->mDefaultNamespace = $defaultNamespace;
3375 
3376  $this->mDbkeyform = $parts['dbkey'];
3377  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
3378  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
3379 
3380  // splitTitleString() guarantees that this title is valid.
3381  $this->mIsValid = true;
3382 
3383  # We already know that some pages won't be in the database!
3384  if ( $this->isExternal() || $this->isSpecialPage() || $this->mTextform === '' ) {
3385  $this->mArticleID = 0;
3386  }
3387  }
3388 
3401  public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3402  if ( count( $options ) > 0 ) {
3403  $db = wfGetDB( DB_MASTER );
3404  } else {
3405  $db = wfGetDB( DB_REPLICA );
3406  }
3407 
3408  $res = $db->select(
3409  [ 'page', $table ],
3410  self::getSelectFields(),
3411  [
3412  "{$prefix}_from=page_id",
3413  "{$prefix}_namespace" => $this->mNamespace,
3414  "{$prefix}_title" => $this->mDbkeyform ],
3415  __METHOD__,
3416  $options
3417  );
3418 
3419  $retVal = [];
3420  if ( $res->numRows() ) {
3421  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3422  foreach ( $res as $row ) {
3423  $titleObj = self::makeTitle( $row->page_namespace, $row->page_title );
3424  if ( $titleObj ) {
3425  $linkCache->addGoodLinkObjFromRow( $titleObj, $row );
3426  $retVal[] = $titleObj;
3427  }
3428  }
3429  }
3430  return $retVal;
3431  }
3432 
3443  public function getTemplateLinksTo( $options = [] ) {
3444  return $this->getLinksTo( $options, 'templatelinks', 'tl' );
3445  }
3446 
3459  public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3460  $id = $this->getArticleID();
3461 
3462  # If the page doesn't exist; there can't be any link from this page
3463  if ( !$id ) {
3464  return [];
3465  }
3466 
3467  $db = wfGetDB( DB_REPLICA );
3468 
3469  $blNamespace = "{$prefix}_namespace";
3470  $blTitle = "{$prefix}_title";
3471 
3472  $pageQuery = WikiPage::getQueryInfo();
3473  $res = $db->select(
3474  [ $table, 'nestpage' => $pageQuery['tables'] ],
3475  array_merge(
3476  [ $blNamespace, $blTitle ],
3477  $pageQuery['fields']
3478  ),
3479  [ "{$prefix}_from" => $id ],
3480  __METHOD__,
3481  $options,
3482  [ 'nestpage' => [
3483  'LEFT JOIN',
3484  [ "page_namespace=$blNamespace", "page_title=$blTitle" ]
3485  ] ] + $pageQuery['joins']
3486  );
3487 
3488  $retVal = [];
3489  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3490  foreach ( $res as $row ) {
3491  if ( $row->page_id ) {
3492  $titleObj = self::newFromRow( $row );
3493  } else {
3494  $titleObj = self::makeTitle( $row->$blNamespace, $row->$blTitle );
3495  $linkCache->addBadLinkObj( $titleObj );
3496  }
3497  $retVal[] = $titleObj;
3498  }
3499 
3500  return $retVal;
3501  }
3502 
3513  public function getTemplateLinksFrom( $options = [] ) {
3514  return $this->getLinksFrom( $options, 'templatelinks', 'tl' );
3515  }
3516 
3525  public function getBrokenLinksFrom() {
3526  if ( $this->getArticleID() == 0 ) {
3527  # All links from article ID 0 are false positives
3528  return [];
3529  }
3530 
3531  $dbr = wfGetDB( DB_REPLICA );
3532  $res = $dbr->select(
3533  [ 'page', 'pagelinks' ],
3534  [ 'pl_namespace', 'pl_title' ],
3535  [
3536  'pl_from' => $this->getArticleID(),
3537  'page_namespace IS NULL'
3538  ],
3539  __METHOD__, [],
3540  [
3541  'page' => [
3542  'LEFT JOIN',
3543  [ 'pl_namespace=page_namespace', 'pl_title=page_title' ]
3544  ]
3545  ]
3546  );
3547 
3548  $retVal = [];
3549  foreach ( $res as $row ) {
3550  $retVal[] = self::makeTitle( $row->pl_namespace, $row->pl_title );
3551  }
3552  return $retVal;
3553  }
3554 
3561  public function getCdnUrls() {
3562  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3563  return $htmlCache->getUrls( $this );
3564  }
3565 
3570  public function purgeSquid() {
3571  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3572  $htmlCache->purgeTitleUrls( $this, $htmlCache::PURGE_INTENT_TXROUND_REFLECTED );
3573  }
3574 
3582  public function isSingleRevRedirect() {
3583  $dbw = wfGetDB( DB_MASTER );
3584  $dbw->startAtomic( __METHOD__ );
3585 
3586  $row = $dbw->selectRow(
3587  'page',
3588  self::getSelectFields(),
3589  $this->pageCond(),
3590  __METHOD__,
3591  [ 'FOR UPDATE' ]
3592  );
3593  // Update the cached fields
3594  $this->loadFromRow( $row );
3595 
3596  if ( $this->mRedirect && $this->mLatestID ) {
3597  $isSingleRevRedirect = !$dbw->selectField(
3598  'revision',
3599  '1',
3600  [ 'rev_page' => $this->mArticleID, 'rev_id != ' . (int)$this->mLatestID ],
3601  __METHOD__,
3602  [ 'FOR UPDATE' ]
3603  );
3604  } else {
3605  $isSingleRevRedirect = false;
3606  }
3607 
3608  $dbw->endAtomic( __METHOD__ );
3609 
3610  return $isSingleRevRedirect;
3611  }
3612 
3620  public function getParentCategories() {
3621  $data = [];
3622 
3623  $titleKey = $this->getArticleID();
3624 
3625  if ( $titleKey === 0 ) {
3626  return $data;
3627  }
3628 
3629  $dbr = wfGetDB( DB_REPLICA );
3630 
3631  $res = $dbr->select(
3632  'categorylinks',
3633  'cl_to',
3634  [ 'cl_from' => $titleKey ],
3635  __METHOD__
3636  );
3637 
3638  if ( $res->numRows() > 0 ) {
3639  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
3640  foreach ( $res as $row ) {
3641  // $data[] = Title::newFromText( $contLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
3642  $data[$contLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] =
3643  $this->getFullText();
3644  }
3645  }
3646  return $data;
3647  }
3648 
3655  public function getParentCategoryTree( $children = [] ) {
3656  $stack = [];
3657  $parents = $this->getParentCategories();
3658 
3659  if ( $parents ) {
3660  foreach ( $parents as $parent => $current ) {
3661  if ( array_key_exists( $parent, $children ) ) {
3662  # Circular reference
3663  $stack[$parent] = [];
3664  } else {
3665  $nt = self::newFromText( $parent );
3666  if ( $nt ) {
3667  $stack[$parent] = $nt->getParentCategoryTree( $children + [ $parent => 1 ] );
3668  }
3669  }
3670  }
3671  }
3672 
3673  return $stack;
3674  }
3675 
3682  public function pageCond() {
3683  if ( $this->mArticleID > 0 ) {
3684  // PK avoids secondary lookups in InnoDB, shouldn't hurt other DBs
3685  return [ 'page_id' => $this->mArticleID ];
3686  } else {
3687  return [ 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform ];
3688  }
3689  }
3690 
3698  private function getRelativeRevisionID( $revId, $flags, $dir ) {
3699  $rl = MediaWikiServices::getInstance()->getRevisionLookup();
3700  $rev = $rl->getRevisionById( $revId, $flags );
3701  if ( !$rev ) {
3702  return false;
3703  }
3704 
3705  $oldRev = ( $dir === 'next' )
3706  ? $rl->getNextRevision( $rev, $flags )
3707  : $rl->getPreviousRevision( $rev, $flags );
3708 
3709  return $oldRev ? $oldRev->getId() : false;
3710  }
3711 
3720  public function getPreviousRevisionID( $revId, $flags = 0 ) {
3721  return $this->getRelativeRevisionID( $revId, $flags, 'prev' );
3722  }
3723 
3732  public function getNextRevisionID( $revId, $flags = 0 ) {
3733  return $this->getRelativeRevisionID( $revId, $flags, 'next' );
3734  }
3735 
3743  public function getFirstRevision( $flags = 0 ) {
3744  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
3745  $rev = MediaWikiServices::getInstance()
3746  ->getRevisionLookup()
3747  ->getFirstRevision( $this, $flags );
3748  return $rev ? new Revision( $rev ) : null;
3749  }
3750 
3758  public function getEarliestRevTime( $flags = 0 ) {
3759  $rev = MediaWikiServices::getInstance()
3760  ->getRevisionLookup()
3761  ->getFirstRevision( $this, $flags );
3762  return $rev ? $rev->getTimestamp() : null;
3763  }
3764 
3770  public function isNewPage() {
3771  $dbr = wfGetDB( DB_REPLICA );
3772  return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ );
3773  }
3774 
3780  public function isBigDeletion() {
3781  global $wgDeleteRevisionsLimit;
3782 
3783  if ( !$wgDeleteRevisionsLimit ) {
3784  return false;
3785  }
3786 
3787  if ( $this->mIsBigDeletion === null ) {
3788  $dbr = wfGetDB( DB_REPLICA );
3789 
3790  $revCount = $dbr->selectRowCount(
3791  'revision',
3792  '1',
3793  [ 'rev_page' => $this->getArticleID() ],
3794  __METHOD__,
3795  [ 'LIMIT' => $wgDeleteRevisionsLimit + 1 ]
3796  );
3797 
3798  $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit;
3799  }
3800 
3801  return $this->mIsBigDeletion;
3802  }
3803 
3809  public function estimateRevisionCount() {
3810  if ( !$this->exists() ) {
3811  return 0;
3812  }
3813 
3814  if ( $this->mEstimateRevisions === null ) {
3815  $dbr = wfGetDB( DB_REPLICA );
3816  $this->mEstimateRevisions = $dbr->estimateRowCount( 'revision', '*',
3817  [ 'rev_page' => $this->getArticleID() ], __METHOD__ );
3818  }
3819 
3821  }
3822 
3834  public function countRevisionsBetween( $old, $new, $max = null ) {
3835  wfDeprecated( __METHOD__, '1.35' );
3836  if ( !( $old instanceof Revision ) ) {
3837  $old = Revision::newFromTitle( $this, (int)$old );
3838  }
3839  if ( !( $new instanceof Revision ) ) {
3840  $new = Revision::newFromTitle( $this, (int)$new );
3841  }
3842  if ( !$old || !$new ) {
3843  return 0; // nothing to compare
3844  }
3845  return MediaWikiServices::getInstance()
3846  ->getRevisionStore()
3847  ->countRevisionsBetween(
3848  $this->getArticleID(),
3849  $old->getRevisionRecord(),
3850  $new->getRevisionRecord(),
3851  $max
3852  );
3853  }
3854 
3872  public function getAuthorsBetween( $old, $new, $limit, $options = [] ) {
3873  wfDeprecated( __METHOD__, '1.35' );
3874  if ( !( $old instanceof Revision ) ) {
3875  $old = Revision::newFromTitle( $this, (int)$old );
3876  }
3877  if ( !( $new instanceof Revision ) ) {
3878  $new = Revision::newFromTitle( $this, (int)$new );
3879  }
3880  try {
3881  $users = MediaWikiServices::getInstance()
3882  ->getRevisionStore()
3883  ->getAuthorsBetween(
3884  $this->getArticleID(),
3885  $old->getRevisionRecord(),
3886  $new->getRevisionRecord(),
3887  null,
3888  $limit,
3889  $options
3890  );
3891  return array_map( function ( UserIdentity $user ) {
3892  return $user->getName();
3893  }, $users );
3894  } catch ( InvalidArgumentException $e ) {
3895  return null; // b/c
3896  }
3897  }
3898 
3915  public function countAuthorsBetween( $old, $new, $limit, $options = [] ) {
3916  wfDeprecated( __METHOD__, '1.35' );
3917  $authors = $this->getAuthorsBetween( $old, $new, $limit, $options );
3918  return $authors ? count( $authors ) : 0;
3919  }
3920 
3927  public function equals( LinkTarget $title ) {
3928  // Note: === is necessary for proper matching of number-like titles.
3929  return $this->mInterwiki === $title->getInterwiki()
3930  && $this->mNamespace == $title->getNamespace()
3931  && $this->mDbkeyform === $title->getDBkey();
3932  }
3933 
3940  public function isSubpageOf( Title $title ) {
3941  return $this->mInterwiki === $title->mInterwiki
3942  && $this->mNamespace == $title->mNamespace
3943  && strpos( $this->mDbkeyform, $title->mDbkeyform . '/' ) === 0;
3944  }
3945 
3956  public function exists( $flags = 0 ) {
3957  $exists = $this->getArticleID( $flags ) != 0;
3958  Hooks::run( 'TitleExists', [ $this, &$exists ] );
3959  return $exists;
3960  }
3961 
3978  public function isAlwaysKnown() {
3979  $isKnown = null;
3980 
3991  Hooks::run( 'TitleIsAlwaysKnown', [ $this, &$isKnown ] );
3992 
3993  if ( $isKnown !== null ) {
3994  return $isKnown;
3995  }
3996 
3997  if ( $this->isExternal() ) {
3998  return true; // any interwiki link might be viewable, for all we know
3999  }
4000 
4001  $services = MediaWikiServices::getInstance();
4002  switch ( $this->mNamespace ) {
4003  case NS_MEDIA:
4004  case NS_FILE:
4005  // file exists, possibly in a foreign repo
4006  return (bool)$services->getRepoGroup()->findFile( $this );
4007  case NS_SPECIAL:
4008  // valid special page
4009  return $services->getSpecialPageFactory()->exists( $this->mDbkeyform );
4010  case NS_MAIN:
4011  // selflink, possibly with fragment
4012  return $this->mDbkeyform == '';
4013  case NS_MEDIAWIKI:
4014  // known system message
4015  return $this->hasSourceText() !== false;
4016  default:
4017  return false;
4018  }
4019  }
4020 
4032  public function isKnown() {
4033  return $this->isAlwaysKnown() || $this->exists();
4034  }
4035 
4041  public function hasSourceText() {
4042  if ( $this->exists() ) {
4043  return true;
4044  }
4045 
4046  if ( $this->mNamespace == NS_MEDIAWIKI ) {
4047  $services = MediaWikiServices::getInstance();
4048  // If the page doesn't exist but is a known system message, default
4049  // message content will be displayed, same for language subpages-
4050  // Use always content language to avoid loading hundreds of languages
4051  // to get the link color.
4052  $contLang = $services->getContentLanguage();
4053  list( $name, ) = $services->getMessageCache()->figureMessage(
4054  $contLang->lcfirst( $this->getText() )
4055  );
4056  $message = wfMessage( $name )->inLanguage( $contLang )->useDatabase( false );
4057  return $message->exists();
4058  }
4059 
4060  return false;
4061  }
4062 
4100  public function getDefaultMessageText() {
4101  if ( $this->mNamespace != NS_MEDIAWIKI ) { // Just in case
4102  return false;
4103  }
4104 
4105  list( $name, $lang ) = MediaWikiServices::getInstance()->getMessageCache()->figureMessage(
4106  MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $this->getText() )
4107  );
4108  $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
4109 
4110  if ( $message->exists() ) {
4111  return $message->plain();
4112  } else {
4113  return false;
4114  }
4115  }
4116 
4123  public function invalidateCache( $purgeTime = null ) {
4124  if ( wfReadOnly() ) {
4125  return false;
4126  }
4127  if ( $this->mArticleID === 0 ) {
4128  // avoid gap locking if we know it's not there
4129  return true;
4130  }
4131 
4132  $conds = $this->pageCond();
4134  new AutoCommitUpdate(
4135  wfGetDB( DB_MASTER ),
4136  __METHOD__,
4137  function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) {
4138  $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
4139  $dbw->update(
4140  'page',
4141  [ 'page_touched' => $dbTimestamp ],
4142  $conds + [ 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ],
4143  $fname
4144  );
4145 
4146  MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $this );
4147 
4149  $this, null, null, $dbw->getDomainID() );
4150  }
4151  ),
4153  );
4154 
4155  return true;
4156  }
4157 
4163  public function touchLinks() {
4164  $jobs = [];
4166  $this,
4167  'pagelinks',
4168  [ 'causeAction' => 'page-touch' ]
4169  );
4170  if ( $this->mNamespace == NS_CATEGORY ) {
4172  $this,
4173  'categorylinks',
4174  [ 'causeAction' => 'category-touch' ]
4175  );
4176  }
4177 
4178  JobQueueGroup::singleton()->lazyPush( $jobs );
4179  }
4180 
4187  public function getTouched( $db = null ) {
4188  if ( $db === null ) {
4189  $db = wfGetDB( DB_REPLICA );
4190  }
4191  $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ );
4192  return $touched;
4193  }
4194 
4201  public function getNotificationTimestamp( $user = null ) {
4202  // Assume current user if none given
4203  if ( !$user ) {
4204  wfDeprecated( __METHOD__ . ' without passing a $user parameter', '1.35' );
4205  global $wgUser;
4206  $user = $wgUser;
4207  }
4208  // Check cache first
4209  $uid = $user->getId();
4210  if ( !$uid ) {
4211  return false;
4212  }
4213  // avoid isset here, as it'll return false for null entries
4214  if ( array_key_exists( $uid, $this->mNotificationTimestamp ) ) {
4215  return $this->mNotificationTimestamp[$uid];
4216  }
4217  // Don't cache too much!
4218  if ( count( $this->mNotificationTimestamp ) >= self::CACHE_MAX ) {
4219  $this->mNotificationTimestamp = [];
4220  }
4221 
4222  $store = MediaWikiServices::getInstance()->getWatchedItemStore();
4223  $watchedItem = $store->getWatchedItem( $user, $this );
4224  if ( $watchedItem ) {
4225  $this->mNotificationTimestamp[$uid] = $watchedItem->getNotificationTimestamp();
4226  } else {
4227  $this->mNotificationTimestamp[$uid] = false;
4228  }
4229 
4230  return $this->mNotificationTimestamp[$uid];
4231  }
4232 
4239  public function getNamespaceKey( $prepend = 'nstab-' ) {
4240  // Gets the subject namespace of this title
4241  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
4242  $subjectNS = $nsInfo->getSubject( $this->mNamespace );
4243  // Prefer canonical namespace name for HTML IDs
4244  $namespaceKey = $nsInfo->getCanonicalName( $subjectNS );
4245  if ( $namespaceKey === false ) {
4246  // Fallback to localised text
4247  $namespaceKey = $this->getSubjectNsText();
4248  }
4249  // Makes namespace key lowercase
4250  $namespaceKey = MediaWikiServices::getInstance()->getContentLanguage()->lc( $namespaceKey );
4251  // Uses main
4252  if ( $namespaceKey == '' ) {
4253  $namespaceKey = 'main';
4254  }
4255  // Changes file to image for backwards compatibility
4256  if ( $namespaceKey == 'file' ) {
4257  $namespaceKey = 'image';
4258  }
4259  return $prepend . $namespaceKey;
4260  }
4261 
4268  public function getRedirectsHere( $ns = null ) {
4269  $redirs = [];
4270 
4271  $dbr = wfGetDB( DB_REPLICA );
4272  $where = [
4273  'rd_namespace' => $this->mNamespace,
4274  'rd_title' => $this->mDbkeyform,
4275  'rd_from = page_id'
4276  ];
4277  if ( $this->isExternal() ) {
4278  $where['rd_interwiki'] = $this->mInterwiki;
4279  } else {
4280  $where[] = 'rd_interwiki = ' . $dbr->addQuotes( '' ) . ' OR rd_interwiki IS NULL';
4281  }
4282  if ( $ns !== null ) {
4283  $where['page_namespace'] = $ns;
4284  }
4285 
4286  $res = $dbr->select(
4287  [ 'redirect', 'page' ],
4288  [ 'page_namespace', 'page_title' ],
4289  $where,
4290  __METHOD__
4291  );
4292 
4293  foreach ( $res as $row ) {
4294  $redirs[] = self::newFromRow( $row );
4295  }
4296  return $redirs;
4297  }
4298 
4304  public function isValidRedirectTarget() {
4306 
4307  if ( $this->isSpecialPage() ) {
4308  // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
4309  if ( $this->isSpecial( 'Userlogout' ) ) {
4310  return false;
4311  }
4312 
4313  foreach ( $wgInvalidRedirectTargets as $target ) {
4314  if ( $this->isSpecial( $target ) ) {
4315  return false;
4316  }
4317  }
4318  }
4319 
4320  return true;
4321  }
4322 
4328  public function getBacklinkCache() {
4329  return BacklinkCache::get( $this );
4330  }
4331 
4337  public function canUseNoindex() {
4339 
4340  $bannedNamespaces = $wgExemptFromUserRobotsControl ??
4341  MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
4342 
4343  return !in_array( $this->mNamespace, $bannedNamespaces );
4344  }
4345 
4356  public function getCategorySortkey( $prefix = '' ) {
4357  $unprefixed = $this->getText();
4358 
4359  // Anything that uses this hook should only depend
4360  // on the Title object passed in, and should probably
4361  // tell the users to run updateCollations.php --force
4362  // in order to re-sort existing category relations.
4363  Hooks::run( 'GetDefaultSortkey', [ $this, &$unprefixed ] );
4364  if ( $prefix !== '' ) {
4365  # Separate with a line feed, so the unprefixed part is only used as
4366  # a tiebreaker when two pages have the exact same prefix.
4367  # In UCA, tab is the only character that can sort above LF
4368  # so we strip both of them from the original prefix.
4369  $prefix = strtr( $prefix, "\n\t", ' ' );
4370  return "$prefix\n$unprefixed";
4371  }
4372  return $unprefixed;
4373  }
4374 
4382  private function getDbPageLanguageCode() {
4383  global $wgPageLanguageUseDB;
4384 
4385  // check, if the page language could be saved in the database, and if so and
4386  // the value is not requested already, lookup the page language using LinkCache
4387  if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) {
4388  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
4389  $linkCache->addLinkObj( $this );
4390  $this->mDbPageLanguage = $linkCache->getGoodLinkFieldObj( $this, 'lang' );
4391  }
4392 
4393  return $this->mDbPageLanguage;
4394  }
4395 
4404  public function getPageLanguage() {
4405  global $wgLang, $wgLanguageCode;
4406  if ( $this->isSpecialPage() ) {
4407  // special pages are in the user language
4408  return $wgLang;
4409  }
4410 
4411  // Checking if DB language is set
4412  $dbPageLanguage = $this->getDbPageLanguageCode();
4413  if ( $dbPageLanguage ) {
4414  return wfGetLangObj( $dbPageLanguage );
4415  }
4416 
4417  if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) {
4418  // Note that this may depend on user settings, so the cache should
4419  // be only per-request.
4420  // NOTE: ContentHandler::getPageLanguage() may need to load the
4421  // content to determine the page language!
4422  // Checking $wgLanguageCode hasn't changed for the benefit of unit
4423  // tests.
4424  $contentHandler = MediaWikiServices::getInstance()
4425  ->getContentHandlerFactory()
4426  ->getContentHandler( $this->getContentModel() );
4427  $langObj = $contentHandler->getPageLanguage( $this );
4428  $this->mPageLanguage = [ $langObj->getCode(), $wgLanguageCode ];
4429  } else {
4430  $langObj = MediaWikiServices::getInstance()->getLanguageFactory()
4431  ->getLanguage( $this->mPageLanguage[0] );
4432  }
4433 
4434  return $langObj;
4435  }
4436 
4445  public function getPageViewLanguage() {
4446  global $wgLang;
4447 
4448  if ( $this->isSpecialPage() ) {
4449  // If the user chooses a variant, the content is actually
4450  // in a language whose code is the variant code.
4451  $variant = $this->getLanguageConverter( $wgLang )->getPreferredVariant();
4452  if ( $wgLang->getCode() !== $variant ) {
4453  return MediaWikiServices::getInstance()->getLanguageFactory()
4454  ->getLanguage( $variant );
4455  }
4456 
4457  return $wgLang;
4458  }
4459 
4460  // Checking if DB language is set
4461  $dbPageLanguage = $this->getDbPageLanguageCode();
4462  if ( $dbPageLanguage ) {
4463  $pageLang = wfGetLangObj( $dbPageLanguage );
4464  $variant = $this->getLanguageConverter( $pageLang )->getPreferredVariant();
4465  if ( $pageLang->getCode() !== $variant ) {
4466  $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()
4467  ->getLanguage( $variant );
4468  }
4469 
4470  return $pageLang;
4471  }
4472 
4473  // @note Can't be cached persistently, depends on user settings.
4474  // @note ContentHandler::getPageViewLanguage() may need to load the
4475  // content to determine the page language!
4476  $contentHandler = MediaWikiServices::getInstance()
4477  ->getContentHandlerFactory()
4478  ->getContentHandler( $this->getContentModel() );
4479  $pageLang = $contentHandler->getPageViewLanguage( $this );
4480  return $pageLang;
4481  }
4482 
4493  public function getEditNotices( $oldid = 0 ) {
4494  $notices = [];
4495 
4496  // Optional notice for the entire namespace
4497  $editnotice_ns = 'editnotice-' . $this->mNamespace;
4498  $msg = wfMessage( $editnotice_ns );
4499  if ( $msg->exists() ) {
4500  $html = $msg->parseAsBlock();
4501  // Edit notices may have complex logic, but output nothing (T91715)
4502  if ( trim( $html ) !== '' ) {
4503  $notices[$editnotice_ns] = Html::rawElement(
4504  'div',
4505  [ 'class' => [
4506  'mw-editnotice',
4507  'mw-editnotice-namespace',
4508  Sanitizer::escapeClass( "mw-$editnotice_ns" )
4509  ] ],
4510  $html
4511  );
4512  }
4513  }
4514 
4515  if (
4516  MediaWikiServices::getInstance()->getNamespaceInfo()->
4517  hasSubpages( $this->mNamespace )
4518  ) {
4519  // Optional notice for page itself and any parent page
4520  $editnotice_base = $editnotice_ns;
4521  foreach ( explode( '/', $this->mDbkeyform ) as $part ) {
4522  $editnotice_base .= '-' . $part;
4523  $msg = wfMessage( $editnotice_base );
4524  if ( $msg->exists() ) {
4525  $html = $msg->parseAsBlock();
4526  if ( trim( $html ) !== '' ) {
4527  $notices[$editnotice_base] = Html::rawElement(
4528  'div',
4529  [ 'class' => [
4530  'mw-editnotice',
4531  'mw-editnotice-base',
4532  Sanitizer::escapeClass( "mw-$editnotice_base" )
4533  ] ],
4534  $html
4535  );
4536  }
4537  }
4538  }
4539  } else {
4540  // Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
4541  $editnoticeText = $editnotice_ns . '-' . strtr( $this->mDbkeyform, '/', '-' );
4542  $msg = wfMessage( $editnoticeText );
4543  if ( $msg->exists() ) {
4544  $html = $msg->parseAsBlock();
4545  if ( trim( $html ) !== '' ) {
4546  $notices[$editnoticeText] = Html::rawElement(
4547  'div',
4548  [ 'class' => [
4549  'mw-editnotice',
4550  'mw-editnotice-page',
4551  Sanitizer::escapeClass( "mw-$editnoticeText" )
4552  ] ],
4553  $html
4554  );
4555  }
4556  }
4557  }
4558 
4559  Hooks::run( 'TitleGetEditNotices', [ $this, $oldid, &$notices ] );
4560  return $notices;
4561  }
4562 
4568  private function loadFieldFromDB( $field, $flags ) {
4569  if ( !in_array( $field, self::getSelectFields(), true ) ) {
4570  return false; // field does not exist
4571  }
4572 
4573  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
4574  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
4575 
4576  return wfGetDB( $index )->selectField(
4577  'page',
4578  $field,
4579  $this->pageCond(),
4580  __METHOD__,
4581  $options
4582  );
4583  }
4584 
4588  public function __sleep() {
4589  return [
4590  'mNamespace',
4591  'mDbkeyform',
4592  'mFragment',
4593  'mInterwiki',
4594  'mLocalInterwiki',
4595  'mDefaultNamespace',
4596  ];
4597  }
4598 
4599  public function __wakeup() {
4600  $this->mArticleID = ( $this->mNamespace >= 0 ) ? -1 : 0;
4601  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
4602  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
4603  }
4604 
4605 }
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:1174
Title\getTitleProtection
getTitleProtection()
Is this title subject to title protection? Title protection is the one applied against creation of su...
Definition: Title.php:2503
Title\canUseNoindex
canUseNoindex()
Whether the magic words INDEX and NOINDEX function for this page.
Definition: Title.php:4337
Title\getLocalURL
getLocalURL( $query='', $query2=false)
Get a URL with no fragment or server name (relative URL) from a Title object.
Definition: Title.php:2173
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:2591
Title\$mHasCascadingRestrictions
bool $mHasCascadingRestrictions
Are cascading restrictions in effect on this page?
Definition: Title.php:133
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:49
Title\isNamespaceProtected
isNamespaceProtected(User $user)
Determines if $user is unable to edit this page because it has been protected by $wgNamespaceProtecti...
Definition: Title.php:2652
Title\getTalkNsText
getTalkNsText()
Get the namespace text of the talk page.
Definition: Title.php:1157
Title\getSubpageText
getSubpageText()
Get the lowest-level subpage name, i.e.
Definition: Title.php:1998
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:332
Title\isBigDeletion
isBigDeletion()
Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit.
Definition: Title.php:3780
Title\getNextRevisionID
getNextRevisionID( $revId, $flags=0)
Get the revision ID of the next revision.
Definition: Title.php:3732
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:2685
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:2458
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:822
Title\getInternalURL
getInternalURL( $query='', $query2=false)
Get the URL form for an internal link.
Definition: Title.php:2304
Title\getFragment
getFragment()
Get the Title fragment (i.e.
Definition: Title.php:1741
$wgExemptFromUserRobotsControl
$wgExemptFromUserRobotsControl
An array of namespace keys in which the INDEX/__NOINDEX__ magic words will not function,...
Definition: DefaultSettings.php:8426
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:1633
Title\inNamespace
inNamespace( $ns)
Returns true if the title is inside the specified namespace.
Definition: Title.php:1295
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:1357
Title\wasLocalInterwiki
wasLocalInterwiki()
Was this a local interwiki link?
Definition: Title.php:944
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:144
$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:1307
Title\isWikitextPage
isWikitextPage()
Does that page contain wikitext, or it is JS, CSS or whatever?
Definition: Title.php:1414
Title\isUserCssConfigPage
isUserCssConfigPage()
Is this a CSS "config" sub-page of a user page?
Definition: Title.php:1476
Title\getBacklinkCache
getBacklinkCache()
Get a backlink cache object.
Definition: Title.php:4328
Title\getPartialURL
getPartialURL()
Get the URL-encoded form of the main part.
Definition: Title.php:1016
$wgLegalTitleChars
$wgLegalTitleChars
Allowed title characters – regex character class Don't change this unless you know what you're doing.
Definition: DefaultSettings.php:4305
Title\clearCaches
static clearCaches()
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:3313
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:984
Title\estimateRevisionCount
estimateRevisionCount()
Get the approximate revision count of this page.
Definition: Title.php:3809
Title\countRevisionsBetween
countRevisionsBetween( $old, $new, $max=null)
Get the number of revisions between the given revision.
Definition: Title.php:3834
Title\getPrefixedDBkey
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1841
Title\getDbPageLanguageCode
getDbPageLanguageCode()
Returns the page language code saved in the database, if $wgPageLanguageUseDB is set to true in Local...
Definition: Title.php:4382
Title\getSkinFromConfigSubpage
getSkinFromConfigSubpage()
Trim down a .css, .json, or .js subpage title to get the corresponding skin name.
Definition: Title.php:1460
$wgScript
$wgScript
The URL path to index.php.
Definition: DefaultSettings.php:185
Title\$mHasSubpages
bool $mHasSubpages
Whether a page has any subpages.
Definition: Title.php:172
Title\getTalkPage
getTalkPage()
Get a Title object associated with the talk page of this article.
Definition: Title.php:1603
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:4201
Title\getParentCategoryTree
getParentCategoryTree( $children=[])
Get a tree of parent categories.
Definition: Title.php:3655
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:2066
Title\fixSpecialName
fixSpecialName()
If the Title refers to a special page alias which is not the local default, resolve the alias,...
Definition: Title.php:1271
Title\getInterwikiLookup
static getInterwikiLookup()
B/C kludge: provide an InterwikiLookup for use by Title.
Definition: Title.php:230
Title\isUserJsConfigPage
isUserJsConfigPage()
Is this a JS "config" sub-page of a user page?
Definition: Title.php:1504
Title\touchLinks
touchLinks()
Update page_touched timestamps and send CDN purge messages for pages linking to this title.
Definition: Title.php:4163
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:309
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1854
Title\getTransWikiID
getTransWikiID()
Returns the DB name of the distant wiki which owns the object.
Definition: Title.php:967
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:3171
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:2279
Title\$mTitleValue
TitleValue null $mTitleValue
A corresponding TitleValue object.
Definition: Title.php:183
Title\quickUserCan
quickUserCan( $action, $user=null)
Can $user perform $action on this page? This skips potentially expensive cascading permission checks ...
Definition: Title.php:2371
NS_FILE
const NS_FILE
Definition: Defines.php:75
Title\isTalkPage
isTalkPage()
Is this a talk page of some sort?
Definition: Title.php:1587
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1104
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1198
Sanitizer\decodeCharReferencesAndNormalize
static decodeCharReferencesAndNormalize( $text)
Decode any character references, numeric or named entities, in the next and normalize the resulting s...
Definition: Sanitizer.php:1528
$s
$s
Definition: mergeMessageFileList.php:185
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:83
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:1260
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1064
Title\isExternal
isExternal()
Is this Title interwiki?
Definition: Title.php:924
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:2860
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:657
Title\getDefaultMessageText
getDefaultMessageText()
Get the default (plain) message contents for an page that overrides an interface message key.
Definition: Title.php:4100
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:224
Title\hasSourceText
hasSourceText()
Does this page have source text?
Definition: Title.php:4041
Title\loadFromRow
loadFromRow( $row)
Load Title object fields from a DB row.
Definition: Title.php:539
Title\setFragment
setFragment( $fragment)
Set the fragment for this title.
Definition: Title.php:1787
$res
$res
Definition: testCompression.php:57
IDBAccessObject
Interface for database access objects.
Definition: IDBAccessObject.php:55
Title\equals
equals(LinkTarget $title)
Compare with another title.
Definition: Title.php:3927
Title\$mIsBigDeletion
bool null $mIsBigDeletion
Would deleting this page be a big deletion?
Definition: Title.php:186
Title\convertByteClassToUnicodeClass
static convertByteClassToUnicodeClass( $byteClass)
Utility method for converting a character sequence from bytes to Unicode.
Definition: Title.php:717
Title\__wakeup
__wakeup()
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:4599
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:3620
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:3401
Title\$mContentModel
bool string $mContentModel
ID of the page's content model, i.e.
Definition: Title.php:101
Title\getPageLanguageConverter
getPageLanguageConverter()
Shorthand for getting a Language Converter for page's language.
Definition: Title.php:206
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
Title\isSiteCssConfigPage
isSiteCssConfigPage()
Is this a sitewide CSS "config" page?
Definition: Title.php:1518
MessageLocalizer
Interface for localizing messages in MediaWiki.
Definition: MessageLocalizer.php:27
Title\getNsText
getNsText()
Get the namespace text.
Definition: Title.php:1121
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:3459
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:439
Revision
Definition: Revision.php:39
NS_MAIN
const NS_MAIN
Definition: Defines.php:69
Title\loadFieldFromDB
loadFieldFromDB( $field, $flags)
Definition: Title.php:4568
Title\isCascadeProtected
isCascadeProtected()
Cascading protection: Return true if cascading restrictions apply to this page, false if not.
Definition: Title.php:2671
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:139
Title\getCdnUrls
getCdnUrls()
Get a list of URLs to purge from the CDN cache when this page changes.
Definition: Title.php:3561
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:1705
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:1432
Title\isUserJsonConfigPage
isUserJsonConfigPage()
Is this a JSON "config" sub-page of a user page?
Definition: Title.php:1490
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:189
$wgRawHtmlMessages
string[] $wgRawHtmlMessages
List of messages which might contain raw HTML.
Definition: DefaultSettings.php:9242
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:1025
Title\nameOf
static nameOf( $id)
Get the prefixed DB key associated with an ID.
Definition: Title.php:682
Title\$mDbPageLanguage
string bool null $mDbPageLanguage
The page language code from the database, null if not saved in the database or false if not loaded,...
Definition: Title.php:180
Title\isSpecial
isSpecial( $name)
Returns true if this title resolves to the named special page.
Definition: Title.php:1253
MWException
MediaWiki exception.
Definition: MWException.php:26
Title\getTitleFormatter
static getTitleFormatter()
B/C kludge: provide a TitleParser for use by Title.
Definition: Title.php:218
Title\isMainPage
isMainPage()
Is this the mainpage?
Definition: Title.php:1381
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1030
Title\getSubpage
getSubpage( $text)
Get the title for a subpage of the current page.
Definition: Title.php:2022
Title\getBaseTitle
getBaseTitle()
Get the base page name title, i.e.
Definition: Title.php:1978
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1034
BacklinkCache\get
static get(Title $title)
Create a new BacklinkCache or reuse any existing one.
Definition: BacklinkCache.php:113
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:527
Title\isConversionTable
isConversionTable()
Is this a conversion table for the LanguageConverter?
Definition: Title.php:1402
Title\isProtected
isProtected( $action='')
Does the title correspond to a protected article?
Definition: Title.php:2619
Title\flushRestrictions
flushRestrictions()
Flush the protection cache in this object and force reload from the database.
Definition: Title.php:3009
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2463
Title\getCategorySortkey
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:4356
Title\getInterwiki
getInterwiki()
Get the interwiki prefix.
Definition: Title.php:935
Title\isSiteJsonConfigPage
isSiteJsonConfigPage()
Is this a sitewide JSON "config" page?
Definition: Title.php:1536
$matches
$matches
Definition: NoLocalSettings.php:24
Title\isValidRedirectTarget
isValidRedirectTarget()
Check if this Title is a valid redirect target.
Definition: Title.php:4304
Title\deleteTitleProtection
deleteTitleProtection()
Remove any title protection due to page existing.
Definition: Title.php:2573
Title\__construct
__construct()
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:234
$wgLang
$wgLang
Definition: Setup.php:774
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:2396
Title\getBrokenLinksFrom
getBrokenLinksFrom()
Get an array of Title objects referring to non-existent articles linked from this page.
Definition: Title.php:3525
Title\isUserConfigPage
isUserConfigPage()
Is this a "config" (.css, .json, or .js) sub-page of a user page?
Definition: Title.php:1446
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:197
Title\$mCascadeSources
array $mCascadeSources
Where are the cascading restrictions coming from on this page?
Definition: Title.php:136
Title\getSubjectPage
getSubjectPage()
Get a title object associated with the subject page of this talk page.
Definition: Title.php:1648
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:1148
Title\loadRestrictions
loadRestrictions( $oldFashionedRestrictions=null, $flags=0)
Load restrictions from the page_restrictions table.
Definition: Title.php:2938
$wgInvalidRedirectTargets
$wgInvalidRedirectTargets
Array of invalid page redirect targets.
Definition: DefaultSettings.php:4480
Title\getFullText
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
Definition: Title.php:1878
Title\getTitleCache
static getTitleCache()
Definition: Title.php:440
Title\hasFragment
hasFragment()
Check if a Title fragment is set.
Definition: Title.php:1751
Title\getRedirectsHere
getRedirectsHere( $ns=null)
Get all extant redirects to this Title.
Definition: Title.php:4268
MediaWiki\User\UserIdentity\getName
getName()
$title
$title
Definition: testCompression.php:38
Title\warnIfPageCannotExist
warnIfPageCannotExist(Title $title, $method)
Definition: Title.php:1674
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:595
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:1835
Title\getRootText
getRootText()
Get the root page name text without a namespace, i.e.
Definition: Title.php:1901
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:5717
Title\canExist
canExist()
Can this title represent a page in the wiki's database?
Definition: Title.php:1188
$wgDeleteRevisionsLimit
$wgDeleteRevisionsLimit
Optional to restrict deletion of pages with higher revision counts to users with the 'bigdelete' perm...
Definition: DefaultSettings.php:5894
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Title\$prefixedText
string null $prefixedText
Text form including namespace/interwiki, initialised on demand.
Definition: Title.php:149
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:913
Title\__sleep
__sleep()
Definition: Title.php:4588
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:2328
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:1798
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:1730
ResourceLoaderWikiModule\invalidateModuleCache
static invalidateModuleCache(Title $title, ?Revision $old, ?Revision $new, $domain)
Clear the preloadTitleInfo() cache for all wiki modules on this wiki on page change if it was a JS or...
Definition: ResourceLoaderWikiModule.php:543
Title\newFromTextThrow
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:367
$wgPageLanguageUseDB
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
Definition: DefaultSettings.php:9107
Title\$mPageLanguage
array null $mPageLanguage
The (string) language code of the page's language and content code.
Definition: Title.php:175
Title\isValid
isValid()
Returns true if the title is a valid link target, and that it has been properly normalized.
Definition: Title.php:870
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:2047
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:621
Title\__toString
__toString()
Return a string representation of this title.
Definition: Title.php:1868
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:48
ILanguageConverter
The shared interface for all language converters.
Definition: ILanguageConverter.php:28
DBAccessObjectUtils\hasFlags
static hasFlags( $bitfield, $flags)
Definition: DBAccessObjectUtils.php:35
Title\getTemplateLinksTo
getTemplateLinksTo( $options=[])
Get an array of Title objects using this Title as a template Also stores the IDs in the link cache.
Definition: Title.php:3443
$wgMainPageIsDomainRoot
bool $wgMainPageIsDomainRoot
Option to whether serve the main page as the domain root.
Definition: DefaultSettings.php:9502
Title\areRestrictionsCascading
areRestrictionsCascading()
Returns cascading restrictions for the current article.
Definition: Title.php:2841
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:3256
Title\areRestrictionsLoaded
areRestrictionsLoaded()
Accessor for mRestrictionsLoaded.
Definition: Title.php:2788
Title\getSubpages
getSubpages( $limit=-1)
Get all subpages of this page.
Definition: Title.php:3091
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:3582
$wgServer
$wgServer
URL of the server.
Definition: DefaultSettings.php:105
Title\GAID_FOR_UPDATE
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define().
Definition: Title.php:58
Title\getPageViewLanguage
getPageViewLanguage()
Get the language in which the content of this page is written when viewed by user.
Definition: Title.php:4445
Title\newFromDBkey
static newFromDBkey( $key)
Create a new Title from a prefixed DB key.
Definition: Title.php:245
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:1166
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:3064
Title\isSubpage
isSubpage()
Is this a subpage?
Definition: Title.php:1390
Title\hasContentModel
hasContentModel( $id)
Convenience method for checking a title's content model name.
Definition: Title.php:1079
Title\getRestrictionExpiry
getRestrictionExpiry( $action)
Get the expiry time for the restriction against a given action.
Definition: Title.php:2829
Title\newFromURL
static newFromURL( $url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:417
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:3291
Title\isSubpageOf
isSubpageOf(Title $title)
Check if this title is a subpage of another title.
Definition: Title.php:3940
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:909
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:1046
Title\$mNotificationTimestamp
array $mNotificationTimestamp
Associative array of user ID -> timestamp/false.
Definition: Title.php:169
Title\newFromIDs
static newFromIDs( $ids)
Make an array of titles from an array of IDs.
Definition: Title.php:501
WikiPage\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new page object.
Definition: WikiPage.php:359
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:284
Title\prefix
prefix( $name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object.
Definition: Title.php:1814
Title\getNamespaceKey
getNamespaceKey( $prepend='nstab-')
Generate strings used for xml 'id' names in monobook tabs.
Definition: Title.php:4239
Title\getEditURL
getEditURL()
Get the edit URL for this Title.
Definition: Title.php:2342
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:2104
Title\isKnown
isKnown()
Does this title refer to a page that can (or might) be meaningfully viewed? In particular,...
Definition: Title.php:4032
$wgArticlePath
$wgArticlePath
The URL path for primary article page views.
Definition: DefaultSettings.php:245
Title\$mIsValid
bool null $mIsValid
Is the title known to be valid?
Definition: Title.php:189
Title\getFirstRevision
getFirstRevision( $flags=0)
Get the first revision of the page.
Definition: Title.php:3743
Title\getAllRestrictions
getAllRestrictions()
Accessor/initialisation for mRestrictions.
Definition: Title.php:2815
Title\getEarliestRevTime
getEarliestRevTime( $flags=0)
Get the oldest revision timestamp of this page.
Definition: Title.php:3758
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:424
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:2702
$cache
$cache
Definition: mcc.php:33
$wgSemiprotectedRestrictionLevels
$wgSemiprotectedRestrictionLevels
Restriction levels that should be considered "semiprotected".
Definition: DefaultSettings.php:5708
Title\getRestrictionTypes
getRestrictionTypes()
Returns restriction types for the current Title.
Definition: Title.php:2476
MalformedTitleException
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Definition: MalformedTitleException.php:25
Title\getTitleProtectionInternal
getTitleProtectionInternal()
Fetch title protection settings.
Definition: Title.php:2526
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:3513
Title\isRedirect
isRedirect( $flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
Definition: Title.php:3204
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:3121
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:3328
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:1334
Title\isSpecialPage
isSpecialPage()
Returns true if this is a special page.
Definition: Title.php:1243
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:3570
Title\getPreviousRevisionID
getPreviousRevisionID( $revId, $flags=0)
Get the revision ID of the previous revision.
Definition: Title.php:3720
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:4404
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:4493
Title\getTouched
getTouched( $db=null)
Get the last touched timestamp.
Definition: Title.php:4187
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:5683
Title\getFragmentForURL
getFragmentForURL()
Get the fragment in URL form, including the "#" character if there is one.
Definition: Title.php:1760
Title\exists
exists( $flags=0)
Check if page exists.
Definition: Title.php:3956
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:1143
Title\isAlwaysKnown
isAlwaysKnown()
Should links to this title be shown as potentially viewable (i.e.
Definition: Title.php:3978
Title\secureAndSplit
secureAndSplit( $text, $defaultNamespace=null)
Secure and split - main initialisation function for this object.
Definition: Title.php:3353
Title\isDeletedQuick
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:3146
Title\getSubpageUrlForm
getSubpageUrlForm()
Get a URL-encoded form of the subpage text.
Definition: Title.php:2036
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:3770
$wgRestrictionTypes
$wgRestrictionTypes
Set of available actions that can be restricted via action=protect You probably shouldn't change this...
Definition: DefaultSettings.php:5670
Title\setContentModel
setContentModel( $model)
Set a proposed content model for the page for permissions checking.
Definition: Title.php:1096
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:849
Title\countAuthorsBetween
countAuthorsBetween( $old, $new, $limit, $options=[])
Get the number of authors between the given revisions or revision IDs.
Definition: Title.php:3915
$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:703
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:308
Title\isSiteJsConfigPage
isSiteJsConfigPage()
Is this a sitewide JS "config" page?
Definition: Title.php:1554
Title\invalidateCache
invalidateCache( $purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:4123
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:641
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:954
Title\getRestrictions
getRestrictions( $action)
Accessor/initialisation for mRestrictions.
Definition: Title.php:2801
CommentStore\getStore
static getStore()
Definition: CommentStore.php:109
Title\isContentPage
isContentPage()
Is this Title in a namespace which contains content? In other words, is this a content page,...
Definition: Title.php:1346
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:54
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:476
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:133
$wgVariantArticlePath
$wgVariantArticlePath
Like $wgArticlePath, but on multi-variant wikis, this provides a path format that describes which par...
Definition: DefaultSettings.php:3259
Title\isRawHtmlMessage
isRawHtmlMessage()
Is this a message which can contain raw HTML?
Definition: Title.php:1572
Title\getSelectFields
static getSelectFields()
Returns a list of fields that are to be selected for initializing Title objects or LinkCache entries.
Definition: Title.php:453
Title\hasSubpages
hasSubpages()
Does this have subpages? (Warning, usually requires an extra DB query.)
Definition: Title.php:3060
Title\getBaseText
getBaseText()
Get the base page name without a namespace, i.e.
Definition: Title.php:1948
Title\pageCond
pageCond()
Get an associative array for selecting this title from the "page" table.
Definition: Title.php:3682
Title\getText
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:1007
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:3019
$wgInternalServer
$wgInternalServer
Internal server name as known to CDN, if different.
Definition: DefaultSettings.php:2878
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:1110
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:491
Title\getSubjectNsText
getSubjectNsText()
Get the namespace text of the subject (rather than talk) page.
Definition: Title.php:1146
Title\getUserPermissionsErrors
getUserPermissionsErrors( $action, $user, $rigor=PermissionManager::RIGOR_SECURE, $ignoreErrors=[])
Can $user perform $action on this page?
Definition: Title.php:2435
Title\$mTitleProtection
mixed $mTitleProtection
Cached value for getTitleProtection (create protection)
Definition: Title.php:152
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:37
Title\newFromTitleValue
static newFromTitleValue(TitleValue $titleValue, $forceClone='')
Returns a Title given a TitleValue.
Definition: Title.php:269
Title\getRelativeRevisionID
getRelativeRevisionID( $revId, $flags, $dir)
Get next/previous revision ID relative to another revision ID.
Definition: Title.php:3698
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
Definition: GlobalFunctions.php:347
Title\getFullUrlForRedirect
getFullUrlForRedirect( $query='', $proto=PROTO_CURRENT)
Get a url appropriate for making redirects based on an untrusted url arg.
Definition: Title.php:2139
Title\getRootTitle
getRootTitle()
Get the root page name title, i.e.
Definition: Title.php:1925
$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:3229
Title\getAuthorsBetween
getAuthorsBetween( $old, $new, $limit, $options=[])
Get the authors between the given revisions or revision IDs.
Definition: Title.php:3872
Title\isWatchable
isWatchable()
Can this title be added to a user's watchlist?
Definition: Title.php:1232