MediaWiki  master
Title.php
Go to the documentation of this file.
1 <?php
27 use Wikimedia\Assert\Assert;
33 
42 class Title implements LinkTarget, IDBAccessObject {
44  private static $titleCache = null;
45 
51  const CACHE_MAX = 1000;
52 
58  const GAID_FOR_UPDATE = 512;
59 
67  const NEW_CLONE = 'clone';
68 
74  // @{
75 
77  public $mTextform = '';
79  public $mUrlform = '';
81  public $mDbkeyform = '';
83  public $mNamespace = NS_MAIN;
85  public $mInterwiki = '';
87  private $mLocalInterwiki = false;
89  public $mFragment = '';
90 
92  public $mArticleID = -1;
93 
95  protected $mLatestID = false;
96 
101  private $mContentModel = false;
102 
107  private $mForcedContentModel = false;
108 
111 
113  public $mRestrictions = [];
114 
121  protected $mOldRestrictions = false;
122 
125 
128 
130  protected $mRestrictionsExpiry = [];
131 
134 
137 
139  public $mRestrictionsLoaded = false;
140 
149  public $prefixedText = null;
150 
153 
161 
163  protected $mLength = -1;
164 
166  public $mRedirect = null;
167 
170 
172  private $mHasSubpages;
173 
175  private $mPageLanguage;
176 
180  private $mDbPageLanguage = false;
181 
183  private $mTitleValue = null;
184 
186  private $mIsBigDeletion = null;
187 
189  private $mIsValid = null;
190  // @}
191 
200  private static function getTitleFormatter() {
201  return MediaWikiServices::getInstance()->getTitleFormatter();
202  }
203 
212  private static function getInterwikiLookup() {
213  return MediaWikiServices::getInstance()->getInterwikiLookup();
214  }
215 
219  function __construct() {
220  }
221 
230  public static function newFromDBkey( $key ) {
231  $t = new self();
232 
233  try {
234  $t->secureAndSplit( $key );
235  return $t;
236  } catch ( MalformedTitleException $ex ) {
237  return null;
238  }
239  }
240 
254  public static function newFromTitleValue( TitleValue $titleValue, $forceClone = '' ) {
255  return self::newFromLinkTarget( $titleValue, $forceClone );
256  }
257 
269  public static function newFromLinkTarget( LinkTarget $linkTarget, $forceClone = '' ) {
270  if ( $linkTarget instanceof Title ) {
271  // Special case if it's already a Title object
272  if ( $forceClone === self::NEW_CLONE ) {
273  return clone $linkTarget;
274  } else {
275  return $linkTarget;
276  }
277  }
278  return self::makeTitle(
279  $linkTarget->getNamespace(),
280  $linkTarget->getText(),
281  $linkTarget->getFragment(),
282  $linkTarget->getInterwiki()
283  );
284  }
285 
293  public static function castFromLinkTarget( $linkTarget ) {
294  return $linkTarget ? self::newFromLinkTarget( $linkTarget ) : null;
295  }
296 
317  public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
318  // DWIM: Integers can be passed in here when page titles are used as array keys.
319  if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) {
320  throw new InvalidArgumentException( '$text must be a string.' );
321  }
322  if ( $text === null ) {
323  return null;
324  }
325 
326  try {
327  return self::newFromTextThrow( (string)$text, (int)$defaultNamespace );
328  } catch ( MalformedTitleException $ex ) {
329  return null;
330  }
331  }
332 
352  public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
353  if ( is_object( $text ) ) {
354  throw new MWException( '$text must be a string, given an object' );
355  } elseif ( $text === null ) {
356  // Legacy code relies on MalformedTitleException being thrown in this case
357  // (happens when URL with no title in it is parsed). TODO fix
358  throw new MalformedTitleException( 'title-invalid-empty' );
359  }
360 
362 
363  // Wiki pages often contain multiple links to the same page.
364  // Title normalization and parsing can become expensive on pages with many
365  // links, so we can save a little time by caching them.
366  // In theory these are value objects and won't get changed...
367  if ( $defaultNamespace == NS_MAIN ) {
368  $t = $titleCache->get( $text );
369  if ( $t ) {
370  return $t;
371  }
372  }
373 
374  // Convert things like &eacute; &#257; or &#x3017; into normalized (T16952) text
375  $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
376 
377  $t = new Title();
378  $dbKeyForm = strtr( $filteredText, ' ', '_' );
379 
380  $t->secureAndSplit( $dbKeyForm, (int)$defaultNamespace );
381  if ( $defaultNamespace == NS_MAIN ) {
382  $titleCache->set( $text, $t );
383  }
384  return $t;
385  }
386 
402  public static function newFromURL( $url ) {
403  $t = new Title();
404 
405  # For compatibility with old buggy URLs. "+" is usually not valid in titles,
406  # but some URLs used it as a space replacement and they still come
407  # from some external search tools.
408  if ( strpos( self::legalChars(), '+' ) === false ) {
409  $url = strtr( $url, '+', ' ' );
410  }
411 
412  $dbKeyForm = strtr( $url, ' ', '_' );
413 
414  try {
415  $t->secureAndSplit( $dbKeyForm );
416  return $t;
417  } catch ( MalformedTitleException $ex ) {
418  return null;
419  }
420  }
421 
425  private static function getTitleCache() {
426  if ( self::$titleCache === null ) {
427  self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
428  }
429  return self::$titleCache;
430  }
431 
439  protected static function getSelectFields() {
441 
442  $fields = [
443  'page_namespace', 'page_title', 'page_id',
444  'page_len', 'page_is_redirect', 'page_latest',
445  ];
446 
447  if ( $wgContentHandlerUseDB ) {
448  $fields[] = 'page_content_model';
449  }
450 
451  if ( $wgPageLanguageUseDB ) {
452  $fields[] = 'page_lang';
453  }
454 
455  return $fields;
456  }
457 
465  public static function newFromID( $id, $flags = 0 ) {
466  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
467  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
468  $row = wfGetDB( $index )->selectRow(
469  'page',
470  self::getSelectFields(),
471  [ 'page_id' => $id ],
472  __METHOD__,
473  $options
474  );
475  if ( $row !== false ) {
476  $title = self::newFromRow( $row );
477  } else {
478  $title = null;
479  }
480 
481  return $title;
482  }
483 
490  public static function newFromIDs( $ids ) {
491  if ( !count( $ids ) ) {
492  return [];
493  }
494  $dbr = wfGetDB( DB_REPLICA );
495 
496  $res = $dbr->select(
497  'page',
498  self::getSelectFields(),
499  [ 'page_id' => $ids ],
500  __METHOD__
501  );
502 
503  $titles = [];
504  foreach ( $res as $row ) {
505  $titles[] = self::newFromRow( $row );
506  }
507  return $titles;
508  }
509 
516  public static function newFromRow( $row ) {
517  $t = self::makeTitle( $row->page_namespace, $row->page_title );
518  $t->loadFromRow( $row );
519  return $t;
520  }
521 
528  public function loadFromRow( $row ) {
529  if ( $row ) { // page found
530  if ( isset( $row->page_id ) ) {
531  $this->mArticleID = (int)$row->page_id;
532  }
533  if ( isset( $row->page_len ) ) {
534  $this->mLength = (int)$row->page_len;
535  }
536  if ( isset( $row->page_is_redirect ) ) {
537  $this->mRedirect = (bool)$row->page_is_redirect;
538  }
539  if ( isset( $row->page_latest ) ) {
540  $this->mLatestID = (int)$row->page_latest;
541  }
542  if ( isset( $row->page_content_model ) ) {
543  $this->lazyFillContentModel( $row->page_content_model );
544  } else {
545  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
546  }
547  if ( isset( $row->page_lang ) ) {
548  $this->mDbPageLanguage = (string)$row->page_lang;
549  }
550  if ( isset( $row->page_restrictions ) ) {
551  $this->mOldRestrictions = $row->page_restrictions;
552  }
553  } else { // page not found
554  $this->mArticleID = 0;
555  $this->mLength = 0;
556  $this->mRedirect = false;
557  $this->mLatestID = 0;
558  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
559  }
560  }
561 
584  public static function makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
585  $t = new Title();
586  $t->mInterwiki = $interwiki;
587  $t->mFragment = $fragment;
588  $t->mNamespace = $ns = (int)$ns;
589  $t->mDbkeyform = strtr( $title, ' ', '_' );
590  $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
591  $t->mUrlform = wfUrlencode( $t->mDbkeyform );
592  $t->mTextform = strtr( $title, '_', ' ' );
593  return $t;
594  }
595 
610  public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
611  // NOTE: ideally, this would just call makeTitle() and then isValid(),
612  // but presently, that means more overhead on a potential performance hotspot.
613 
614  if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) {
615  return null;
616  }
617 
618  $t = new Title();
619  $dbKeyForm = self::makeName( $ns, $title, $fragment, $interwiki, true );
620 
621  try {
622  $t->secureAndSplit( $dbKeyForm );
623  return $t;
624  } catch ( MalformedTitleException $ex ) {
625  return null;
626  }
627  }
628 
646  public static function newMainPage( MessageLocalizer $localizer = null ) {
647  if ( $localizer ) {
648  $msg = $localizer->msg( 'mainpage' );
649  } else {
650  $msg = wfMessage( 'mainpage' );
651  }
652 
653  $title = self::newFromText( $msg->inContentLanguage()->text() );
654 
655  // Every page renders at least one link to the Main Page (e.g. sidebar).
656  // If the localised value is invalid, don't produce fatal errors that
657  // would make the wiki inaccessible (and hard to fix the invalid message).
658  // Gracefully fallback...
659  if ( !$title ) {
660  $title = self::newFromText( 'Main Page' );
661  }
662  return $title;
663  }
664 
671  public static function nameOf( $id ) {
672  $dbr = wfGetDB( DB_REPLICA );
673 
674  $s = $dbr->selectRow(
675  'page',
676  [ 'page_namespace', 'page_title' ],
677  [ 'page_id' => $id ],
678  __METHOD__
679  );
680  if ( $s === false ) {
681  return null;
682  }
683 
684  return self::makeName( $s->page_namespace, $s->page_title );
685  }
686 
692  public static function legalChars() {
693  global $wgLegalTitleChars;
694  return $wgLegalTitleChars;
695  }
696 
706  public static function convertByteClassToUnicodeClass( $byteClass ) {
707  $length = strlen( $byteClass );
708  // Input token queue
709  $x0 = $x1 = $x2 = '';
710  // Decoded queue
711  $d0 = $d1 = $d2 = '';
712  // Decoded integer codepoints
713  $ord0 = $ord1 = $ord2 = 0;
714  // Re-encoded queue
715  $r0 = $r1 = $r2 = '';
716  // Output
717  $out = '';
718  // Flags
719  $allowUnicode = false;
720  for ( $pos = 0; $pos < $length; $pos++ ) {
721  // Shift the queues down
722  $x2 = $x1;
723  $x1 = $x0;
724  $d2 = $d1;
725  $d1 = $d0;
726  $ord2 = $ord1;
727  $ord1 = $ord0;
728  $r2 = $r1;
729  $r1 = $r0;
730  // Load the current input token and decoded values
731  $inChar = $byteClass[$pos];
732  if ( $inChar == '\\' ) {
733  if ( preg_match( '/x([0-9a-fA-F]{2})/A', $byteClass, $m, 0, $pos + 1 ) ) {
734  $x0 = $inChar . $m[0];
735  $d0 = chr( hexdec( $m[1] ) );
736  $pos += strlen( $m[0] );
737  } elseif ( preg_match( '/[0-7]{3}/A', $byteClass, $m, 0, $pos + 1 ) ) {
738  $x0 = $inChar . $m[0];
739  $d0 = chr( octdec( $m[0] ) );
740  $pos += strlen( $m[0] );
741  } elseif ( $pos + 1 >= $length ) {
742  $x0 = $d0 = '\\';
743  } else {
744  $d0 = $byteClass[$pos + 1];
745  $x0 = $inChar . $d0;
746  $pos += 1;
747  }
748  } else {
749  $x0 = $d0 = $inChar;
750  }
751  $ord0 = ord( $d0 );
752  // Load the current re-encoded value
753  if ( $ord0 < 32 || $ord0 == 0x7f ) {
754  $r0 = sprintf( '\x%02x', $ord0 );
755  } elseif ( $ord0 >= 0x80 ) {
756  // Allow unicode if a single high-bit character appears
757  $r0 = sprintf( '\x%02x', $ord0 );
758  $allowUnicode = true;
759  // @phan-suppress-next-line PhanParamSuspiciousOrder false positive
760  } elseif ( strpos( '-\\[]^', $d0 ) !== false ) {
761  $r0 = '\\' . $d0;
762  } else {
763  $r0 = $d0;
764  }
765  // Do the output
766  if ( $x0 !== '' && $x1 === '-' && $x2 !== '' ) {
767  // Range
768  if ( $ord2 > $ord0 ) {
769  // Empty range
770  } elseif ( $ord0 >= 0x80 ) {
771  // Unicode range
772  $allowUnicode = true;
773  if ( $ord2 < 0x80 ) {
774  // Keep the non-unicode section of the range
775  $out .= "$r2-\\x7F";
776  }
777  } else {
778  // Normal range
779  $out .= "$r2-$r0";
780  }
781  // Reset state to the initial value
782  $x0 = $x1 = $d0 = $d1 = $r0 = $r1 = '';
783  } elseif ( $ord2 < 0x80 ) {
784  // ASCII character
785  $out .= $r2;
786  }
787  }
788  if ( $ord1 < 0x80 ) {
789  $out .= $r1;
790  }
791  if ( $ord0 < 0x80 ) {
792  $out .= $r0;
793  }
794  if ( $allowUnicode ) {
795  $out .= '\u0080-\uFFFF';
796  }
797  return $out;
798  }
799 
811  public static function makeName( $ns, $title, $fragment = '', $interwiki = '',
812  $canonicalNamespace = false
813  ) {
814  if ( $canonicalNamespace ) {
815  $namespace = MediaWikiServices::getInstance()->getNamespaceInfo()->
816  getCanonicalName( $ns );
817  } else {
818  $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns );
819  }
820  $name = $namespace == '' ? $title : "$namespace:$title";
821  if ( strval( $interwiki ) != '' ) {
822  $name = "$interwiki:$name";
823  }
824  if ( strval( $fragment ) != '' ) {
825  $name .= '#' . $fragment;
826  }
827  return $name;
828  }
829 
838  public static function compare( LinkTarget $a, LinkTarget $b ) {
839  return $a->getNamespace() <=> $b->getNamespace()
840  ?: strcmp( $a->getText(), $b->getText() );
841  }
842 
859  public function isValid() {
860  if ( $this->mIsValid !== null ) {
861  return $this->mIsValid;
862  }
863 
864  try {
865  $text = $this->getFullText();
866  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
867 
868  '@phan-var MediaWikiTitleCodec $titleCodec';
869  $parts = $titleCodec->splitTitleString( $text, $this->mNamespace );
870 
871  // Check that nothing changed!
872  // This ensures that $text was already perperly normalized.
873  if ( $parts['fragment'] !== $this->mFragment
874  || $parts['interwiki'] !== $this->mInterwiki
875  || $parts['local_interwiki'] !== $this->mLocalInterwiki
876  || $parts['namespace'] !== $this->mNamespace
877  || $parts['dbkey'] !== $this->mDbkeyform
878  ) {
879  $this->mIsValid = false;
880  return $this->mIsValid;
881  }
882  } catch ( MalformedTitleException $ex ) {
883  $this->mIsValid = false;
884  return $this->mIsValid;
885  }
886 
887  $this->mIsValid = true;
888  return $this->mIsValid;
889  }
890 
898  public function isLocal() {
899  if ( $this->isExternal() ) {
900  $iw = self::getInterwikiLookup()->fetch( $this->mInterwiki );
901  if ( $iw ) {
902  return $iw->isLocal();
903  }
904  }
905  return true;
906  }
907 
913  public function isExternal() {
914  return $this->mInterwiki !== '';
915  }
916 
924  public function getInterwiki() {
925  return $this->mInterwiki;
926  }
927 
933  public function wasLocalInterwiki() {
934  return $this->mLocalInterwiki;
935  }
936 
943  public function isTrans() {
944  if ( !$this->isExternal() ) {
945  return false;
946  }
947 
948  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable();
949  }
950 
956  public function getTransWikiID() {
957  if ( !$this->isExternal() ) {
958  return false;
959  }
960 
961  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID();
962  }
963 
973  public function getTitleValue() {
974  if ( $this->mTitleValue === null ) {
975  try {
976  $this->mTitleValue = new TitleValue(
977  $this->mNamespace,
978  $this->mDbkeyform,
979  $this->mFragment,
980  $this->mInterwiki
981  );
982  } catch ( InvalidArgumentException $ex ) {
983  wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' .
984  $this->getPrefixedText() . ']]: ' . $ex->getMessage() . "\n" );
985  }
986  }
987 
988  return $this->mTitleValue;
989  }
990 
996  public function getText() {
997  return $this->mTextform;
998  }
999 
1005  public function getPartialURL() {
1006  return $this->mUrlform;
1007  }
1008 
1014  public function getDBkey() {
1015  return $this->mDbkeyform;
1016  }
1017 
1024  function getUserCaseDBKey() {
1025  wfDeprecated( __METHOD__, '1.33' );
1026 
1027  return $this->getDBkey();
1028  }
1029 
1035  public function getNamespace() {
1036  return $this->mNamespace;
1037  }
1038 
1047  public function getContentModel( $flags = 0 ) {
1048  if ( $this->mForcedContentModel ) {
1049  if ( !$this->mContentModel ) {
1050  throw new RuntimeException( 'Got out of sync; an empty model is being forced' );
1051  }
1052  // Content model is locked to the currently loaded one
1053  return $this->mContentModel;
1054  }
1055 
1056  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
1057  $this->lazyFillContentModel( $this->loadFieldFromDB( 'page_content_model', $flags ) );
1058  } elseif (
1059  ( !$this->mContentModel || $flags & self::GAID_FOR_UPDATE ) &&
1060  $this->getArticleID( $flags )
1061  ) {
1062  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1063  $linkCache->addLinkObj( $this ); # in case we already had an article ID
1064  $this->lazyFillContentModel( $linkCache->getGoodLinkFieldObj( $this, 'model' ) );
1065  }
1066 
1067  if ( !$this->mContentModel ) {
1069  }
1070 
1071  return $this->mContentModel;
1072  }
1073 
1080  public function hasContentModel( $id ) {
1081  return $this->getContentModel() == $id;
1082  }
1083 
1097  public function setContentModel( $model ) {
1098  if ( (string)$model === '' ) {
1099  throw new InvalidArgumentException( "Missing CONTENT_MODEL_* constant" );
1100  }
1101 
1102  $this->mContentModel = $model;
1103  $this->mForcedContentModel = true;
1104  }
1105 
1111  private function lazyFillContentModel( $model ) {
1112  if ( !$this->mForcedContentModel ) {
1113  $this->mContentModel = ( $model === false ) ? false : (string)$model;
1114  }
1115  }
1116 
1122  public function getNsText() {
1123  if ( $this->isExternal() ) {
1124  // This probably shouldn't even happen, except for interwiki transclusion.
1125  // If possible, use the canonical name for the foreign namespace.
1126  $nsText = MediaWikiServices::getInstance()->getNamespaceInfo()->
1127  getCanonicalName( $this->mNamespace );
1128  if ( $nsText !== false ) {
1129  return $nsText;
1130  }
1131  }
1132 
1133  try {
1134  $formatter = self::getTitleFormatter();
1135  return $formatter->getNamespaceName( $this->mNamespace, $this->mDbkeyform );
1136  } catch ( InvalidArgumentException $ex ) {
1137  wfDebug( __METHOD__ . ': ' . $ex->getMessage() . "\n" );
1138  return false;
1139  }
1140  }
1141 
1147  public function getSubjectNsText() {
1148  $services = MediaWikiServices::getInstance();
1149  return $services->getContentLanguage()->
1150  getNsText( $services->getNamespaceInfo()->getSubject( $this->mNamespace ) );
1151  }
1152 
1158  public function getTalkNsText() {
1159  $services = MediaWikiServices::getInstance();
1160  return $services->getContentLanguage()->
1161  getNsText( $services->getNamespaceInfo()->getTalk( $this->mNamespace ) );
1162  }
1163 
1175  public function canHaveTalkPage() {
1176  return MediaWikiServices::getInstance()->getNamespaceInfo()->canHaveTalkPage( $this );
1177  }
1178 
1189  public function canExist() {
1190  // NOTE: Don't use getArticleID(), we don't want to
1191  // trigger a database query here. This check is supposed to
1192  // act as an optimization, not add extra cost.
1193  if ( $this->mArticleID > 0 ) {
1194  // It exists, so it can exist.
1195  return true;
1196  }
1197 
1198  // NOTE: we call the relatively expensive isValid() method further down,
1199  // but we can bail out early if we already know the title is invalid.
1200  if ( $this->mIsValid === false ) {
1201  // It's invalid, so it can't exist.
1202  return false;
1203  }
1204 
1205  if ( $this->getNamespace() < NS_MAIN ) {
1206  // It's a special page, so it can't exist in the database.
1207  return false;
1208  }
1209 
1210  if ( $this->isExternal() ) {
1211  // If it's external, it's not local, so it can't exist.
1212  return false;
1213  }
1214 
1215  if ( $this->getText() === '' ) {
1216  // The title has no text, so it can't exist in the database.
1217  // It's probably an on-page section link, like "#something".
1218  return false;
1219  }
1220 
1221  // Double check that the title is valid.
1222  return $this->isValid();
1223  }
1224 
1233  public function isWatchable() {
1234  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
1235  return $this->getText() !== '' && !$this->isExternal() &&
1236  $nsInfo->isWatchable( $this->mNamespace );
1237  }
1238 
1244  public function isSpecialPage() {
1245  return $this->mNamespace == NS_SPECIAL;
1246  }
1247 
1254  public function isSpecial( $name ) {
1255  if ( $this->isSpecialPage() ) {
1256  list( $thisName, /* $subpage */ ) =
1257  MediaWikiServices::getInstance()->getSpecialPageFactory()->
1258  resolveAlias( $this->mDbkeyform );
1259  if ( $name == $thisName ) {
1260  return true;
1261  }
1262  }
1263  return false;
1264  }
1265 
1272  public function fixSpecialName() {
1273  if ( $this->isSpecialPage() ) {
1274  $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory();
1275  list( $canonicalName, $par ) = $spFactory->resolveAlias( $this->mDbkeyform );
1276  if ( $canonicalName ) {
1277  $localName = $spFactory->getLocalNameFor( $canonicalName, $par );
1278  if ( $localName != $this->mDbkeyform ) {
1279  return self::makeTitle( NS_SPECIAL, $localName );
1280  }
1281  }
1282  }
1283  return $this;
1284  }
1285 
1296  public function inNamespace( $ns ) {
1297  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1298  equals( $this->mNamespace, $ns );
1299  }
1300 
1308  public function inNamespaces( ...$namespaces ) {
1309  if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) {
1310  $namespaces = $namespaces[0];
1311  }
1312 
1313  foreach ( $namespaces as $ns ) {
1314  if ( $this->inNamespace( $ns ) ) {
1315  return true;
1316  }
1317  }
1318 
1319  return false;
1320  }
1321 
1335  public function hasSubjectNamespace( $ns ) {
1336  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1337  subjectEquals( $this->mNamespace, $ns );
1338  }
1339 
1347  public function isContentPage() {
1348  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1349  isContent( $this->mNamespace );
1350  }
1351 
1358  public function isMovable() {
1359  if (
1360  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1361  isMovable( $this->mNamespace ) || $this->isExternal()
1362  ) {
1363  // Interwiki title or immovable namespace. Hooks don't get to override here
1364  return false;
1365  }
1366 
1367  $result = true;
1368  Hooks::run( 'TitleIsMovable', [ $this, &$result ] );
1369  return $result;
1370  }
1371 
1382  public function isMainPage() {
1383  return $this->equals( self::newMainPage() );
1384  }
1385 
1391  public function isSubpage() {
1392  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1393  hasSubpages( $this->mNamespace )
1394  ? strpos( $this->getText(), '/' ) !== false
1395  : false;
1396  }
1397 
1403  public function isConversionTable() {
1404  // @todo ConversionTable should become a separate content model.
1405 
1406  return $this->mNamespace == NS_MEDIAWIKI &&
1407  strpos( $this->getText(), 'Conversiontable/' ) === 0;
1408  }
1409 
1415  public function isWikitextPage() {
1416  return $this->hasContentModel( CONTENT_MODEL_WIKITEXT );
1417  }
1418 
1433  public function isSiteConfigPage() {
1434  return (
1435  $this->isSiteCssConfigPage()
1436  || $this->isSiteJsonConfigPage()
1437  || $this->isSiteJsConfigPage()
1438  );
1439  }
1440 
1447  public function isUserConfigPage() {
1448  return (
1449  $this->isUserCssConfigPage()
1450  || $this->isUserJsonConfigPage()
1451  || $this->isUserJsConfigPage()
1452  );
1453  }
1454 
1461  public function getSkinFromConfigSubpage() {
1462  $subpage = explode( '/', $this->mTextform );
1463  $subpage = $subpage[count( $subpage ) - 1];
1464  $lastdot = strrpos( $subpage, '.' );
1465  if ( $lastdot === false ) {
1466  return $subpage; # Never happens: only called for names ending in '.css'/'.json'/'.js'
1467  }
1468  return substr( $subpage, 0, $lastdot );
1469  }
1470 
1477  public function isUserCssConfigPage() {
1478  return (
1479  NS_USER == $this->mNamespace
1480  && $this->isSubpage()
1481  && $this->hasContentModel( CONTENT_MODEL_CSS )
1482  );
1483  }
1484 
1491  public function isUserJsonConfigPage() {
1492  return (
1493  NS_USER == $this->mNamespace
1494  && $this->isSubpage()
1495  && $this->hasContentModel( CONTENT_MODEL_JSON )
1496  );
1497  }
1498 
1505  public function isUserJsConfigPage() {
1506  return (
1507  NS_USER == $this->mNamespace
1508  && $this->isSubpage()
1510  );
1511  }
1512 
1519  public function isSiteCssConfigPage() {
1520  return (
1521  NS_MEDIAWIKI == $this->mNamespace
1522  && (
1524  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1525  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1526  || substr( $this->mDbkeyform, -4 ) === '.css'
1527  )
1528  );
1529  }
1530 
1537  public function isSiteJsonConfigPage() {
1538  return (
1539  NS_MEDIAWIKI == $this->mNamespace
1540  && (
1542  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1543  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1544  || substr( $this->mDbkeyform, -5 ) === '.json'
1545  )
1546  );
1547  }
1548 
1555  public function isSiteJsConfigPage() {
1556  return (
1557  NS_MEDIAWIKI == $this->mNamespace
1558  && (
1560  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1561  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1562  || substr( $this->mDbkeyform, -3 ) === '.js'
1563  )
1564  );
1565  }
1566 
1573  public function isRawHtmlMessage() {
1574  global $wgRawHtmlMessages;
1575 
1576  if ( !$this->inNamespace( NS_MEDIAWIKI ) ) {
1577  return false;
1578  }
1579  $message = lcfirst( $this->getRootTitle()->getDBkey() );
1580  return in_array( $message, $wgRawHtmlMessages, true );
1581  }
1582 
1588  public function isTalkPage() {
1589  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1590  isTalk( $this->mNamespace );
1591  }
1592 
1604  public function getTalkPage() {
1605  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1606  // Instead of failing on invalid titles, let's just log the issue for now.
1607  // See the discussion on T227817.
1608 
1609  // Is this the same title?
1610  $talkNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $this->mNamespace );
1611  if ( $this->mNamespace == $talkNS ) {
1612  return $this;
1613  }
1614 
1615  $title = self::makeTitle( $talkNS, $this->mDbkeyform );
1616 
1617  $this->warnIfPageCannotExist( $title, __METHOD__ );
1618 
1619  return $title;
1620  // TODO: replace the above with the code below:
1621  // return self::castFromLinkTarget(
1622  // MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) );
1623  }
1624 
1634  public function getTalkPageIfDefined() {
1635  if ( !$this->canHaveTalkPage() ) {
1636  return null;
1637  }
1638 
1639  return $this->getTalkPage();
1640  }
1641 
1649  public function getSubjectPage() {
1650  // Is this the same title?
1651  $subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo()
1652  ->getSubject( $this->mNamespace );
1653  if ( $this->mNamespace == $subjectNS ) {
1654  return $this;
1655  }
1656  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1657  // Instead of failing on invalid titles, let's just log the issue for now.
1658  // See the discussion on T227817.
1659  $title = self::makeTitle( $subjectNS, $this->mDbkeyform );
1660 
1661  $this->warnIfPageCannotExist( $title, __METHOD__ );
1662 
1663  return $title;
1664  // TODO: replace the above with the code below:
1665  // return self::castFromLinkTarget(
1666  // MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
1667  }
1668 
1675  private function warnIfPageCannotExist( Title $title, $method ) {
1676  if ( $this->getText() == '' ) {
1677  wfLogWarning(
1678  $method . ': called on empty title ' . $this->getFullText() . ', returning '
1679  . $title->getFullText()
1680  );
1681 
1682  return true;
1683  }
1684 
1685  if ( $this->getInterwiki() !== '' ) {
1686  wfLogWarning(
1687  $method . ': called on interwiki title ' . $this->getFullText() . ', returning '
1688  . $title->getFullText()
1689  );
1690 
1691  return true;
1692  }
1693 
1694  return false;
1695  }
1696 
1706  public function getOtherPage() {
1707  // NOTE: Depend on the methods in this class instead of their equivalent in NamespaceInfo,
1708  // until their semantics has become exactly the same.
1709  // See the discussion on T227817.
1710  if ( $this->isSpecialPage() ) {
1711  throw new MWException( 'Special pages cannot have other pages' );
1712  }
1713  if ( $this->isTalkPage() ) {
1714  return $this->getSubjectPage();
1715  } else {
1716  if ( !$this->canHaveTalkPage() ) {
1717  throw new MWException( "{$this->getPrefixedText()} does not have an other page" );
1718  }
1719  return $this->getTalkPage();
1720  }
1721  // TODO: replace the above with the code below:
1722  // return self::castFromLinkTarget(
1723  // MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) );
1724  }
1725 
1731  public function getDefaultNamespace() {
1732  return $this->mDefaultNamespace;
1733  }
1734 
1742  public function getFragment() {
1743  return $this->mFragment;
1744  }
1745 
1752  public function hasFragment() {
1753  return $this->mFragment !== '';
1754  }
1755 
1761  public function getFragmentForURL() {
1762  if ( !$this->hasFragment() ) {
1763  return '';
1764  } elseif ( $this->isExternal() ) {
1765  // Note: If the interwiki is unknown, it's treated as a namespace on the local wiki,
1766  // so we treat it like a local interwiki.
1767  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
1768  if ( $interwiki && !$interwiki->isLocal() ) {
1769  return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment );
1770  }
1771  }
1772 
1773  return '#' . Sanitizer::escapeIdForLink( $this->mFragment );
1774  }
1775 
1788  public function setFragment( $fragment ) {
1789  $this->mFragment = strtr( substr( $fragment, 1 ), '_', ' ' );
1790  }
1791 
1799  public function createFragmentTarget( $fragment ) {
1800  return self::makeTitle(
1801  $this->mNamespace,
1802  $this->getText(),
1803  $fragment,
1804  $this->mInterwiki
1805  );
1806  }
1807 
1815  private function prefix( $name ) {
1816  $p = '';
1817  if ( $this->isExternal() ) {
1818  $p = $this->mInterwiki . ':';
1819  }
1820 
1821  if ( $this->mNamespace != 0 ) {
1822  $nsText = $this->getNsText();
1823 
1824  if ( $nsText === false ) {
1825  // See T165149. Awkward, but better than erroneously linking to the main namespace.
1826  $nsText = MediaWikiServices::getInstance()->getContentLanguage()->
1827  getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
1828  }
1829 
1830  $p .= $nsText . ':';
1831  }
1832  return $p . $name;
1833  }
1834 
1841  public function getPrefixedDBkey() {
1842  $s = $this->prefix( $this->mDbkeyform );
1843  $s = strtr( $s, ' ', '_' );
1844  return $s;
1845  }
1846 
1853  public function getPrefixedText() {
1854  if ( $this->prefixedText === null ) {
1855  $s = $this->prefix( $this->mTextform );
1856  $s = strtr( $s, '_', ' ' );
1857  $this->prefixedText = $s;
1858  }
1859  return $this->prefixedText;
1860  }
1861 
1867  public function __toString() {
1868  return $this->getPrefixedText();
1869  }
1870 
1877  public function getFullText() {
1878  $text = $this->getPrefixedText();
1879  if ( $this->hasFragment() ) {
1880  $text .= '#' . $this->mFragment;
1881  }
1882  return $text;
1883  }
1884 
1900  public function getRootText() {
1901  if (
1902  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1903  hasSubpages( $this->mNamespace )
1904  || strtok( $this->getText(), '/' ) === false
1905  ) {
1906  return $this->getText();
1907  }
1908 
1909  return strtok( $this->getText(), '/' );
1910  }
1911 
1924  public function getRootTitle() {
1925  $title = self::makeTitleSafe( $this->mNamespace, $this->getRootText() );
1926  Assert::postcondition(
1927  $title !== null,
1928  'makeTitleSafe() should always return a Title for the text returned by getRootText().'
1929  );
1930  return $title;
1931  }
1932 
1947  public function getBaseText() {
1948  $text = $this->getText();
1949  if (
1950  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1951  hasSubpages( $this->mNamespace )
1952  ) {
1953  return $text;
1954  }
1955 
1956  $lastSlashPos = strrpos( $text, '/' );
1957  // Don't discard the real title if there's no subpage involved
1958  if ( $lastSlashPos === false ) {
1959  return $text;
1960  }
1961 
1962  return substr( $text, 0, $lastSlashPos );
1963  }
1964 
1977  public function getBaseTitle() {
1978  $title = self::makeTitleSafe( $this->mNamespace, $this->getBaseText() );
1979  Assert::postcondition(
1980  $title !== null,
1981  'makeTitleSafe() should always return a Title for the text returned by getBaseText().'
1982  );
1983  return $title;
1984  }
1985 
1997  public function getSubpageText() {
1998  if (
1999  !MediaWikiServices::getInstance()->getNamespaceInfo()->
2000  hasSubpages( $this->mNamespace )
2001  ) {
2002  return $this->mTextform;
2003  }
2004  $parts = explode( '/', $this->mTextform );
2005  return $parts[count( $parts ) - 1];
2006  }
2007 
2021  public function getSubpage( $text ) {
2022  return self::makeTitleSafe(
2023  $this->mNamespace,
2024  $this->getText() . '/' . $text,
2025  '',
2026  $this->mInterwiki
2027  );
2028  }
2029 
2035  public function getSubpageUrlForm() {
2036  $text = $this->getSubpageText();
2037  $text = wfUrlencode( strtr( $text, ' ', '_' ) );
2038  return $text;
2039  }
2040 
2046  public function getPrefixedURL() {
2047  $s = $this->prefix( $this->mDbkeyform );
2048  $s = wfUrlencode( strtr( $s, ' ', '_' ) );
2049  return $s;
2050  }
2051 
2065  private static function fixUrlQueryArgs( $query, $query2 = false ) {
2066  if ( $query2 !== false ) {
2067  wfDeprecated( "Title::get{Canonical,Full,Link,Local,Internal}URL " .
2068  "method called with a second parameter is deprecated. Add your " .
2069  "parameter to an array passed as the first parameter.", "1.19" );
2070  }
2071  if ( is_array( $query ) ) {
2072  $query = wfArrayToCgi( $query );
2073  }
2074  if ( $query2 ) {
2075  if ( is_string( $query2 ) ) {
2076  // $query2 is a string, we will consider this to be
2077  // a deprecated $variant argument and add it to the query
2078  $query2 = wfArrayToCgi( [ 'variant' => $query2 ] );
2079  } else {
2080  $query2 = wfArrayToCgi( $query2 );
2081  }
2082  // If we have $query content add a & to it first
2083  if ( $query ) {
2084  $query .= '&';
2085  }
2086  // Now append the queries together
2087  $query .= $query2;
2088  }
2089  return $query;
2090  }
2091 
2103  public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
2104  $query = self::fixUrlQueryArgs( $query, $query2 );
2105 
2106  # Hand off all the decisions on urls to getLocalURL
2107  $url = $this->getLocalURL( $query );
2108 
2109  # Expand the url to make it a full url. Note that getLocalURL has the
2110  # potential to output full urls for a variety of reasons, so we use
2111  # wfExpandUrl instead of simply prepending $wgServer
2112  $url = wfExpandUrl( $url, $proto );
2113 
2114  # Finally, add the fragment.
2115  $url .= $this->getFragmentForURL();
2116  // Avoid PHP 7.1 warning from passing $this by reference
2117  $titleRef = $this;
2118  Hooks::run( 'GetFullURL', [ &$titleRef, &$url, $query ] );
2119  return $url;
2120  }
2121 
2138  public function getFullUrlForRedirect( $query = '', $proto = PROTO_CURRENT ) {
2139  $target = $this;
2140  if ( $this->isExternal() ) {
2141  $target = SpecialPage::getTitleFor(
2142  'GoToInterwiki',
2143  $this->getPrefixedDBkey()
2144  );
2145  }
2146  return $target->getFullURL( $query, false, $proto );
2147  }
2148 
2172  public function getLocalURL( $query = '', $query2 = false ) {
2174 
2175  $query = self::fixUrlQueryArgs( $query, $query2 );
2176 
2177  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
2178  if ( $interwiki ) {
2179  $namespace = $this->getNsText();
2180  if ( $namespace != '' ) {
2181  # Can this actually happen? Interwikis shouldn't be parsed.
2182  # Yes! It can in interwiki transclusion. But... it probably shouldn't.
2183  $namespace .= ':';
2184  }
2185  $url = $interwiki->getURL( $namespace . $this->mDbkeyform );
2186  $url = wfAppendQuery( $url, $query );
2187  } else {
2188  $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
2189  if ( $query == '' ) {
2190  $url = str_replace( '$1', $dbkey, $wgArticlePath );
2191  // Avoid PHP 7.1 warning from passing $this by reference
2192  $titleRef = $this;
2193  Hooks::run( 'GetLocalURL::Article', [ &$titleRef, &$url ] );
2194  } else {
2196  $url = false;
2197  $matches = [];
2198 
2200 
2201  if ( $articlePaths
2202  && preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
2203  ) {
2204  $action = urldecode( $matches[2] );
2205  if ( isset( $articlePaths[$action] ) ) {
2206  $query = $matches[1];
2207  if ( isset( $matches[4] ) ) {
2208  $query .= $matches[4];
2209  }
2210  $url = str_replace( '$1', $dbkey, $articlePaths[$action] );
2211  if ( $query != '' ) {
2212  $url = wfAppendQuery( $url, $query );
2213  }
2214  }
2215  }
2216 
2217  if ( $url === false
2219  && preg_match( '/^variant=([^&]*)$/', $query, $matches )
2220  && $this->getPageLanguage()->equals(
2221  MediaWikiServices::getInstance()->getContentLanguage() )
2222  && $this->getPageLanguage()->hasVariants()
2223  ) {
2224  $variant = urldecode( $matches[1] );
2225  if ( $this->getPageLanguage()->hasVariant( $variant ) ) {
2226  // Only do the variant replacement if the given variant is a valid
2227  // variant for the page's language.
2228  $url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath );
2229  $url = str_replace( '$1', $dbkey, $url );
2230  }
2231  }
2232 
2233  if ( $url === false ) {
2234  if ( $query == '-' ) {
2235  $query = '';
2236  }
2237  $url = "{$wgScript}?title={$dbkey}&{$query}";
2238  }
2239  }
2240  // Avoid PHP 7.1 warning from passing $this by reference
2241  $titleRef = $this;
2242  Hooks::run( 'GetLocalURL::Internal', [ &$titleRef, &$url, $query ] );
2243 
2244  // @todo FIXME: This causes breakage in various places when we
2245  // actually expected a local URL and end up with dupe prefixes.
2246  if ( $wgRequest->getVal( 'action' ) == 'render' ) {
2247  $url = $wgServer . $url;
2248  }
2249  }
2250 
2251  if ( $wgMainPageIsDomainRoot && $this->isMainPage() && $query === '' ) {
2252  return '/';
2253  }
2254 
2255  // Avoid PHP 7.1 warning from passing $this by reference
2256  $titleRef = $this;
2257  Hooks::run( 'GetLocalURL', [ &$titleRef, &$url, $query ] );
2258  return $url;
2259  }
2260 
2278  public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
2279  if ( $this->isExternal() || $proto !== false ) {
2280  $ret = $this->getFullURL( $query, $query2, $proto );
2281  } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
2282  $ret = $this->getFragmentForURL();
2283  } else {
2284  $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
2285  }
2286  return $ret;
2287  }
2288 
2303  public function getInternalURL( $query = '', $query2 = false ) {
2304  global $wgInternalServer, $wgServer;
2305  $query = self::fixUrlQueryArgs( $query, $query2 );
2306  $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
2307  $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP );
2308  // Avoid PHP 7.1 warning from passing $this by reference
2309  $titleRef = $this;
2310  Hooks::run( 'GetInternalURL', [ &$titleRef, &$url, $query ] );
2311  return $url;
2312  }
2313 
2327  public function getCanonicalURL( $query = '', $query2 = false ) {
2328  $query = self::fixUrlQueryArgs( $query, $query2 );
2329  $url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL );
2330  // Avoid PHP 7.1 warning from passing $this by reference
2331  $titleRef = $this;
2332  Hooks::run( 'GetCanonicalURL', [ &$titleRef, &$url, $query ] );
2333  return $url;
2334  }
2335 
2341  public function getEditURL() {
2342  if ( $this->isExternal() ) {
2343  return '';
2344  }
2345  $s = $this->getLocalURL( 'action=edit' );
2346 
2347  return $s;
2348  }
2349 
2370  public function quickUserCan( $action, $user = null ) {
2371  return $this->userCan( $action, $user, false );
2372  }
2373 
2389  public function userCan( $action, $user = null, $rigor = PermissionManager::RIGOR_SECURE ) {
2390  if ( !$user instanceof User ) {
2391  global $wgUser;
2392  $user = $wgUser;
2393  }
2394 
2395  // TODO: this is for b/c, eventually will be removed
2396  if ( $rigor === true ) {
2397  $rigor = PermissionManager::RIGOR_SECURE; // b/c
2398  } elseif ( $rigor === false ) {
2399  $rigor = PermissionManager::RIGOR_QUICK; // b/c
2400  }
2401 
2402  return MediaWikiServices::getInstance()->getPermissionManager()
2403  ->userCan( $action, $user, $this, $rigor );
2404  }
2405 
2427  public function getUserPermissionsErrors(
2428  $action, $user, $rigor = PermissionManager::RIGOR_SECURE, $ignoreErrors = []
2429  ) {
2430  // TODO: this is for b/c, eventually will be removed
2431  if ( $rigor === true ) {
2432  $rigor = PermissionManager::RIGOR_SECURE; // b/c
2433  } elseif ( $rigor === false ) {
2434  $rigor = PermissionManager::RIGOR_QUICK; // b/c
2435  }
2436 
2437  return MediaWikiServices::getInstance()->getPermissionManager()
2438  ->getPermissionErrors( $action, $user, $this, $rigor, $ignoreErrors );
2439  }
2440 
2448  public static function getFilteredRestrictionTypes( $exists = true ) {
2449  global $wgRestrictionTypes;
2450  $types = $wgRestrictionTypes;
2451  if ( $exists ) {
2452  # Remove the create restriction for existing titles
2453  $types = array_diff( $types, [ 'create' ] );
2454  } else {
2455  # Only the create and upload restrictions apply to non-existing titles
2456  $types = array_intersect( $types, [ 'create', 'upload' ] );
2457  }
2458  return $types;
2459  }
2460 
2466  public function getRestrictionTypes() {
2467  if ( $this->isSpecialPage() ) {
2468  return [];
2469  }
2470 
2471  $types = self::getFilteredRestrictionTypes( $this->exists() );
2472 
2473  if ( $this->mNamespace != NS_FILE ) {
2474  # Remove the upload restriction for non-file titles
2475  $types = array_diff( $types, [ 'upload' ] );
2476  }
2477 
2478  Hooks::run( 'TitleGetRestrictionTypes', [ $this, &$types ] );
2479 
2480  wfDebug( __METHOD__ . ': applicable restrictions to [[' .
2481  $this->getPrefixedText() . ']] are {' . implode( ',', $types ) . "}\n" );
2482 
2483  return $types;
2484  }
2485 
2493  public function getTitleProtection() {
2494  $protection = $this->getTitleProtectionInternal();
2495  if ( $protection ) {
2496  if ( $protection['permission'] == 'sysop' ) {
2497  $protection['permission'] = 'editprotected'; // B/C
2498  }
2499  if ( $protection['permission'] == 'autoconfirmed' ) {
2500  $protection['permission'] = 'editsemiprotected'; // B/C
2501  }
2502  }
2503  return $protection;
2504  }
2505 
2516  protected function getTitleProtectionInternal() {
2517  // Can't protect pages in special namespaces
2518  if ( $this->mNamespace < 0 ) {
2519  return false;
2520  }
2521 
2522  // Can't protect pages that exist.
2523  if ( $this->exists() ) {
2524  return false;
2525  }
2526 
2527  if ( $this->mTitleProtection === null ) {
2528  $dbr = wfGetDB( DB_REPLICA );
2529  $commentStore = CommentStore::getStore();
2530  $commentQuery = $commentStore->getJoin( 'pt_reason' );
2531  $res = $dbr->select(
2532  [ 'protected_titles' ] + $commentQuery['tables'],
2533  [
2534  'user' => 'pt_user',
2535  'expiry' => 'pt_expiry',
2536  'permission' => 'pt_create_perm'
2537  ] + $commentQuery['fields'],
2538  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2539  __METHOD__,
2540  [],
2541  $commentQuery['joins']
2542  );
2543 
2544  // fetchRow returns false if there are no rows.
2545  $row = $dbr->fetchRow( $res );
2546  if ( $row ) {
2547  $this->mTitleProtection = [
2548  'user' => $row['user'],
2549  'expiry' => $dbr->decodeExpiry( $row['expiry'] ),
2550  'permission' => $row['permission'],
2551  'reason' => $commentStore->getComment( 'pt_reason', $row )->text,
2552  ];
2553  } else {
2554  $this->mTitleProtection = false;
2555  }
2556  }
2557  return $this->mTitleProtection;
2558  }
2559 
2563  public function deleteTitleProtection() {
2564  $dbw = wfGetDB( DB_MASTER );
2565 
2566  $dbw->delete(
2567  'protected_titles',
2568  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2569  __METHOD__
2570  );
2571  $this->mTitleProtection = false;
2572  }
2573 
2581  public function isSemiProtected( $action = 'edit' ) {
2583 
2584  $restrictions = $this->getRestrictions( $action );
2586  if ( !$restrictions || !$semi ) {
2587  // Not protected, or all protection is full protection
2588  return false;
2589  }
2590 
2591  // Remap autoconfirmed to editsemiprotected for BC
2592  foreach ( array_keys( $semi, 'autoconfirmed' ) as $key ) {
2593  $semi[$key] = 'editsemiprotected';
2594  }
2595  foreach ( array_keys( $restrictions, 'autoconfirmed' ) as $key ) {
2596  $restrictions[$key] = 'editsemiprotected';
2597  }
2598 
2599  return !array_diff( $restrictions, $semi );
2600  }
2601 
2609  public function isProtected( $action = '' ) {
2610  global $wgRestrictionLevels;
2611 
2612  $restrictionTypes = $this->getRestrictionTypes();
2613 
2614  # Special pages have inherent protection
2615  if ( $this->isSpecialPage() ) {
2616  return true;
2617  }
2618 
2619  # Check regular protection levels
2620  foreach ( $restrictionTypes as $type ) {
2621  if ( $action == $type || $action == '' ) {
2622  $r = $this->getRestrictions( $type );
2623  foreach ( $wgRestrictionLevels as $level ) {
2624  if ( in_array( $level, $r ) && $level != '' ) {
2625  return true;
2626  }
2627  }
2628  }
2629  }
2630 
2631  return false;
2632  }
2633 
2642  public function isNamespaceProtected( User $user ) {
2643  global $wgNamespaceProtection;
2644 
2645  if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
2646  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2647  foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
2648  if ( !$permissionManager->userHasRight( $user, $right ) ) {
2649  return true;
2650  }
2651  }
2652  }
2653  return false;
2654  }
2655 
2661  public function isCascadeProtected() {
2662  list( $isCascadeProtected, ) = $this->getCascadeProtectionSources( false );
2663  return $isCascadeProtected;
2664  }
2665 
2675  public function areCascadeProtectionSourcesLoaded( $getPages = true ) {
2676  return $getPages ? $this->mCascadeSources !== null : $this->mHasCascadingRestrictions !== null;
2677  }
2678 
2692  public function getCascadeProtectionSources( $getPages = true ) {
2693  $pagerestrictions = [];
2694 
2695  if ( $this->mCascadeSources !== null && $getPages ) {
2697  } elseif ( $this->mHasCascadingRestrictions !== null && !$getPages ) {
2698  return [ $this->mHasCascadingRestrictions, $pagerestrictions ];
2699  }
2700 
2701  $dbr = wfGetDB( DB_REPLICA );
2702 
2703  if ( $this->mNamespace == NS_FILE ) {
2704  $tables = [ 'imagelinks', 'page_restrictions' ];
2705  $where_clauses = [
2706  'il_to' => $this->mDbkeyform,
2707  'il_from=pr_page',
2708  'pr_cascade' => 1
2709  ];
2710  } else {
2711  $tables = [ 'templatelinks', 'page_restrictions' ];
2712  $where_clauses = [
2713  'tl_namespace' => $this->mNamespace,
2714  'tl_title' => $this->mDbkeyform,
2715  'tl_from=pr_page',
2716  'pr_cascade' => 1
2717  ];
2718  }
2719 
2720  if ( $getPages ) {
2721  $cols = [ 'pr_page', 'page_namespace', 'page_title',
2722  'pr_expiry', 'pr_type', 'pr_level' ];
2723  $where_clauses[] = 'page_id=pr_page';
2724  $tables[] = 'page';
2725  } else {
2726  $cols = [ 'pr_expiry' ];
2727  }
2728 
2729  $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__ );
2730 
2731  $sources = $getPages ? [] : false;
2732  $now = wfTimestampNow();
2733 
2734  foreach ( $res as $row ) {
2735  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2736  if ( $expiry > $now ) {
2737  if ( $getPages ) {
2738  $page_id = $row->pr_page;
2739  $page_ns = $row->page_namespace;
2740  $page_title = $row->page_title;
2741  $sources[$page_id] = self::makeTitle( $page_ns, $page_title );
2742  # Add groups needed for each restriction type if its not already there
2743  # Make sure this restriction type still exists
2744 
2745  if ( !isset( $pagerestrictions[$row->pr_type] ) ) {
2746  $pagerestrictions[$row->pr_type] = [];
2747  }
2748 
2749  if (
2750  isset( $pagerestrictions[$row->pr_type] )
2751  && !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] )
2752  ) {
2753  $pagerestrictions[$row->pr_type][] = $row->pr_level;
2754  }
2755  } else {
2756  $sources = true;
2757  }
2758  }
2759  }
2760 
2761  if ( $getPages ) {
2762  $this->mCascadeSources = $sources;
2763  $this->mCascadingRestrictions = $pagerestrictions;
2764  } else {
2765  $this->mHasCascadingRestrictions = $sources;
2766  }
2767 
2768  return [ $sources, $pagerestrictions ];
2769  }
2770 
2778  public function areRestrictionsLoaded() {
2780  }
2781 
2791  public function getRestrictions( $action ) {
2792  if ( !$this->mRestrictionsLoaded ) {
2793  $this->loadRestrictions();
2794  }
2795  return $this->mRestrictions[$action] ?? [];
2796  }
2797 
2805  public function getAllRestrictions() {
2806  if ( !$this->mRestrictionsLoaded ) {
2807  $this->loadRestrictions();
2808  }
2809  return $this->mRestrictions;
2810  }
2811 
2819  public function getRestrictionExpiry( $action ) {
2820  if ( !$this->mRestrictionsLoaded ) {
2821  $this->loadRestrictions();
2822  }
2823  return $this->mRestrictionsExpiry[$action] ?? false;
2824  }
2825 
2832  if ( !$this->mRestrictionsLoaded ) {
2833  $this->loadRestrictions();
2834  }
2835 
2837  }
2838 
2850  public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
2851  // This function will only read rows from a table that we migrated away
2852  // from before adding READ_LATEST support to loadRestrictions, so we
2853  // don't need to support reading from DB_MASTER here.
2854  $dbr = wfGetDB( DB_REPLICA );
2855 
2856  $restrictionTypes = $this->getRestrictionTypes();
2857 
2858  foreach ( $restrictionTypes as $type ) {
2859  $this->mRestrictions[$type] = [];
2860  $this->mRestrictionsExpiry[$type] = 'infinity';
2861  }
2862 
2863  $this->mCascadeRestriction = false;
2864 
2865  # Backwards-compatibility: also load the restrictions from the page record (old format).
2866  if ( $oldFashionedRestrictions !== null ) {
2867  $this->mOldRestrictions = $oldFashionedRestrictions;
2868  }
2869 
2870  if ( $this->mOldRestrictions === false ) {
2871  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2872  $linkCache->addLinkObj( $this ); # in case we already had an article ID
2873  $this->mOldRestrictions = $linkCache->getGoodLinkFieldObj( $this, 'restrictions' );
2874  }
2875 
2876  if ( $this->mOldRestrictions != '' ) {
2877  foreach ( explode( ':', trim( $this->mOldRestrictions ) ) as $restrict ) {
2878  $temp = explode( '=', trim( $restrict ) );
2879  if ( count( $temp ) == 1 ) {
2880  // old old format should be treated as edit/move restriction
2881  $this->mRestrictions['edit'] = explode( ',', trim( $temp[0] ) );
2882  $this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) );
2883  } else {
2884  $restriction = trim( $temp[1] );
2885  if ( $restriction != '' ) { // some old entries are empty
2886  $this->mRestrictions[$temp[0]] = explode( ',', $restriction );
2887  }
2888  }
2889  }
2890  }
2891 
2892  if ( count( $rows ) ) {
2893  # Current system - load second to make them override.
2894  $now = wfTimestampNow();
2895 
2896  # Cycle through all the restrictions.
2897  foreach ( $rows as $row ) {
2898  // Don't take care of restrictions types that aren't allowed
2899  if ( !in_array( $row->pr_type, $restrictionTypes ) ) {
2900  continue;
2901  }
2902 
2903  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2904 
2905  // Only apply the restrictions if they haven't expired!
2906  if ( !$expiry || $expiry > $now ) {
2907  $this->mRestrictionsExpiry[$row->pr_type] = $expiry;
2908  $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) );
2909 
2910  $this->mCascadeRestriction |= $row->pr_cascade;
2911  }
2912  }
2913  }
2914 
2915  $this->mRestrictionsLoaded = true;
2916  }
2917 
2928  public function loadRestrictions( $oldFashionedRestrictions = null, $flags = 0 ) {
2929  $readLatest = DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST );
2930  if ( $this->mRestrictionsLoaded && !$readLatest ) {
2931  return;
2932  }
2933 
2934  $id = $this->getArticleID( $flags );
2935  if ( $id ) {
2936  $fname = __METHOD__;
2937  $loadRestrictionsFromDb = function ( IDatabase $dbr ) use ( $fname, $id ) {
2938  return iterator_to_array(
2939  $dbr->select(
2940  'page_restrictions',
2941  [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
2942  [ 'pr_page' => $id ],
2943  $fname
2944  )
2945  );
2946  };
2947 
2948  if ( $readLatest ) {
2949  $dbr = wfGetDB( DB_MASTER );
2950  $rows = $loadRestrictionsFromDb( $dbr );
2951  } else {
2952  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
2953  $rows = $cache->getWithSetCallback(
2954  // Page protections always leave a new null revision
2955  $cache->makeKey( 'page-restrictions', 'v1', $id, $this->getLatestRevID() ),
2956  $cache::TTL_DAY,
2957  function ( $curValue, &$ttl, array &$setOpts ) use ( $loadRestrictionsFromDb ) {
2958  $dbr = wfGetDB( DB_REPLICA );
2959 
2960  $setOpts += Database::getCacheSetOptions( $dbr );
2961  $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
2962  if ( $lb->hasOrMadeRecentMasterChanges() ) {
2963  // @TODO: cleanup Title cache and caller assumption mess in general
2964  $ttl = WANObjectCache::TTL_UNCACHEABLE;
2965  }
2966 
2967  return $loadRestrictionsFromDb( $dbr );
2968  }
2969  );
2970  }
2971 
2972  $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
2973  } else {
2974  $title_protection = $this->getTitleProtectionInternal();
2975 
2976  if ( $title_protection ) {
2977  $now = wfTimestampNow();
2978  $expiry = wfGetDB( DB_REPLICA )->decodeExpiry( $title_protection['expiry'] );
2979 
2980  if ( !$expiry || $expiry > $now ) {
2981  // Apply the restrictions
2982  $this->mRestrictionsExpiry['create'] = $expiry;
2983  $this->mRestrictions['create'] =
2984  explode( ',', trim( $title_protection['permission'] ) );
2985  } else { // Get rid of the old restrictions
2986  $this->mTitleProtection = false;
2987  }
2988  } else {
2989  $this->mRestrictionsExpiry['create'] = 'infinity';
2990  }
2991  $this->mRestrictionsLoaded = true;
2992  }
2993  }
2994 
2999  public function flushRestrictions() {
3000  $this->mRestrictionsLoaded = false;
3001  $this->mTitleProtection = null;
3002  }
3003 
3009  static function purgeExpiredRestrictions() {
3010  if ( wfReadOnly() ) {
3011  return;
3012  }
3013 
3015  wfGetDB( DB_MASTER ),
3016  __METHOD__,
3017  function ( IDatabase $dbw, $fname ) {
3018  $config = MediaWikiServices::getInstance()->getMainConfig();
3019  $ids = $dbw->selectFieldValues(
3020  'page_restrictions',
3021  'pr_id',
3022  [ 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3023  $fname,
3024  [ 'LIMIT' => $config->get( 'UpdateRowsPerQuery' ) ] // T135470
3025  );
3026  if ( $ids ) {
3027  $dbw->delete( 'page_restrictions', [ 'pr_id' => $ids ], $fname );
3028  }
3029  }
3030  ) );
3031 
3033  wfGetDB( DB_MASTER ),
3034  __METHOD__,
3035  function ( IDatabase $dbw, $fname ) {
3036  $dbw->delete(
3037  'protected_titles',
3038  [ 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3039  $fname
3040  );
3041  }
3042  ) );
3043  }
3044 
3050  public function hasSubpages() {
3051  if (
3052  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3053  hasSubpages( $this->mNamespace )
3054  ) {
3055  # Duh
3056  return false;
3057  }
3058 
3059  # We dynamically add a member variable for the purpose of this method
3060  # alone to cache the result. There's no point in having it hanging
3061  # around uninitialized in every Title object; therefore we only add it
3062  # if needed and don't declare it statically.
3063  if ( $this->mHasSubpages === null ) {
3064  $this->mHasSubpages = false;
3065  $subpages = $this->getSubpages( 1 );
3066  if ( $subpages instanceof TitleArray ) {
3067  $this->mHasSubpages = (bool)$subpages->current();
3068  }
3069  }
3070 
3071  return $this->mHasSubpages;
3072  }
3073 
3081  public function getSubpages( $limit = -1 ) {
3082  if (
3083  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3084  hasSubpages( $this->mNamespace )
3085  ) {
3086  return [];
3087  }
3088 
3089  $dbr = wfGetDB( DB_REPLICA );
3090  $conds = [ 'page_namespace' => $this->mNamespace ];
3091  $conds[] = 'page_title ' . $dbr->buildLike( $this->mDbkeyform . '/', $dbr->anyString() );
3092  $options = [];
3093  if ( $limit > -1 ) {
3094  $options['LIMIT'] = $limit;
3095  }
3097  $dbr->select( 'page',
3098  [ 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ],
3099  $conds,
3100  __METHOD__,
3101  $options
3102  )
3103  );
3104  }
3105 
3111  public function isDeleted() {
3112  if ( $this->mNamespace < 0 ) {
3113  $n = 0;
3114  } else {
3115  $dbr = wfGetDB( DB_REPLICA );
3116 
3117  $n = $dbr->selectField( 'archive', 'COUNT(*)',
3118  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3119  __METHOD__
3120  );
3121  if ( $this->mNamespace == NS_FILE ) {
3122  $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
3123  [ 'fa_name' => $this->mDbkeyform ],
3124  __METHOD__
3125  );
3126  }
3127  }
3128  return (int)$n;
3129  }
3130 
3136  public function isDeletedQuick() {
3137  if ( $this->mNamespace < 0 ) {
3138  return false;
3139  }
3140  $dbr = wfGetDB( DB_REPLICA );
3141  $deleted = (bool)$dbr->selectField( 'archive', '1',
3142  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3143  __METHOD__
3144  );
3145  if ( !$deleted && $this->mNamespace == NS_FILE ) {
3146  $deleted = (bool)$dbr->selectField( 'filearchive', '1',
3147  [ 'fa_name' => $this->mDbkeyform ],
3148  __METHOD__
3149  );
3150  }
3151  return $deleted;
3152  }
3153 
3161  public function getArticleID( $flags = 0 ) {
3162  if ( $this->mNamespace < 0 ) {
3163  $this->mArticleID = 0;
3164 
3165  return $this->mArticleID;
3166  }
3167 
3168  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3169  if ( $flags & self::GAID_FOR_UPDATE ) {
3170  $oldUpdate = $linkCache->forUpdate( true );
3171  $linkCache->clearLink( $this );
3172  $this->mArticleID = $linkCache->addLinkObj( $this );
3173  $linkCache->forUpdate( $oldUpdate );
3174  } elseif ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3175  $this->mArticleID = (int)$this->loadFieldFromDB( 'page_id', $flags );
3176  } elseif ( $this->mArticleID == -1 ) {
3177  $this->mArticleID = $linkCache->addLinkObj( $this );
3178  }
3179 
3180  return $this->mArticleID;
3181  }
3182 
3190  public function isRedirect( $flags = 0 ) {
3191  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3192  $this->mRedirect = (bool)$this->loadFieldFromDB( 'page_is_redirect', $flags );
3193  } elseif ( $this->mRedirect === null ) {
3194  if ( $this->getArticleID( $flags ) ) {
3195  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3196  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3197  // Note that LinkCache returns null if it thinks the page does not exist;
3198  // always trust the state of LinkCache over that of this Title instance.
3199  $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
3200  } else {
3201  $this->mRedirect = false;
3202  }
3203  }
3204 
3205  return $this->mRedirect;
3206  }
3207 
3215  public function getLength( $flags = 0 ) {
3216  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3217  $this->mLength = (int)$this->loadFieldFromDB( 'page_len', $flags );
3218  } else {
3219  if ( $this->mLength != -1 ) {
3220  return $this->mLength;
3221  } elseif ( !$this->getArticleID( $flags ) ) {
3222  $this->mLength = 0;
3223  return $this->mLength;
3224  }
3225 
3226  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3227  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3228  // Note that LinkCache returns null if it thinks the page does not exist;
3229  // always trust the state of LinkCache over that of this Title instance.
3230  $this->mLength = (int)$linkCache->getGoodLinkFieldObj( $this, 'length' );
3231  }
3232 
3233  return $this->mLength;
3234  }
3235 
3242  public function getLatestRevID( $flags = 0 ) {
3243  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3244  $this->mLatestID = (int)$this->loadFieldFromDB( 'page_latest', $flags );
3245  } else {
3246  if ( $this->mLatestID !== false ) {
3247  return (int)$this->mLatestID;
3248  } elseif ( !$this->getArticleID( $flags ) ) {
3249  $this->mLatestID = 0;
3250 
3251  return $this->mLatestID;
3252  }
3253 
3254  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3255  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3256  // Note that LinkCache returns null if it thinks the page does not exist;
3257  // always trust the state of LinkCache over that of this Title instance.
3258  $this->mLatestID = (int)$linkCache->getGoodLinkFieldObj( $this, 'revision' );
3259  }
3260 
3261  return $this->mLatestID;
3262  }
3263 
3274  public function resetArticleID( $id ) {
3275  if ( $id === false ) {
3276  $this->mArticleID = -1;
3277  } else {
3278  $this->mArticleID = (int)$id;
3279  }
3280  $this->mRestrictionsLoaded = false;
3281  $this->mRestrictions = [];
3282  $this->mOldRestrictions = false;
3283  $this->mRedirect = null;
3284  $this->mLength = -1;
3285  $this->mLatestID = false;
3286  $this->mContentModel = false;
3287  $this->mForcedContentModel = false;
3288  $this->mEstimateRevisions = null;
3289  $this->mPageLanguage = null;
3290  $this->mDbPageLanguage = false;
3291  $this->mIsBigDeletion = null;
3292 
3293  MediaWikiServices::getInstance()->getLinkCache()->clearLink( $this );
3294  }
3295 
3296  public static function clearCaches() {
3297  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3298  $linkCache->clear();
3299 
3301  $titleCache->clear();
3302  }
3303 
3311  public static function capitalize( $text, $ns = NS_MAIN ) {
3312  $services = MediaWikiServices::getInstance();
3313  if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) {
3314  return $services->getContentLanguage()->ucfirst( $text );
3315  } else {
3316  return $text;
3317  }
3318  }
3319 
3336  private function secureAndSplit( $text, $defaultNamespace = null ) {
3337  if ( $defaultNamespace === null ) {
3338  $defaultNamespace = $this->mDefaultNamespace;
3339  }
3340 
3341  // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
3342  // the parsing code with Title, while avoiding massive refactoring.
3343  // @todo: get rid of secureAndSplit, refactor parsing code.
3344  // @note: getTitleParser() returns a TitleParser implementation which does not have a
3345  // splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
3347  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
3348  '@phan-var MediaWikiTitleCodec $titleCodec';
3349  // MalformedTitleException can be thrown here
3350  $parts = $titleCodec->splitTitleString( $text, $defaultNamespace );
3351 
3352  # Fill fields
3353  $this->setFragment( '#' . $parts['fragment'] );
3354  $this->mInterwiki = $parts['interwiki'];
3355  $this->mLocalInterwiki = $parts['local_interwiki'];
3356  $this->mNamespace = $parts['namespace'];
3357  $this->mDefaultNamespace = $defaultNamespace;
3358 
3359  $this->mDbkeyform = $parts['dbkey'];
3360  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
3361  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
3362 
3363  // splitTitleString() guarantees that this title is valid.
3364  $this->mIsValid = true;
3365 
3366  # We already know that some pages won't be in the database!
3367  if ( $this->isExternal() || $this->isSpecialPage() || $this->mTextform === '' ) {
3368  $this->mArticleID = 0;
3369  }
3370  }
3371 
3384  public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3385  if ( count( $options ) > 0 ) {
3386  $db = wfGetDB( DB_MASTER );
3387  } else {
3388  $db = wfGetDB( DB_REPLICA );
3389  }
3390 
3391  $res = $db->select(
3392  [ 'page', $table ],
3393  self::getSelectFields(),
3394  [
3395  "{$prefix}_from=page_id",
3396  "{$prefix}_namespace" => $this->mNamespace,
3397  "{$prefix}_title" => $this->mDbkeyform ],
3398  __METHOD__,
3399  $options
3400  );
3401 
3402  $retVal = [];
3403  if ( $res->numRows() ) {
3404  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3405  foreach ( $res as $row ) {
3406  $titleObj = self::makeTitle( $row->page_namespace, $row->page_title );
3407  if ( $titleObj ) {
3408  $linkCache->addGoodLinkObjFromRow( $titleObj, $row );
3409  $retVal[] = $titleObj;
3410  }
3411  }
3412  }
3413  return $retVal;
3414  }
3415 
3426  public function getTemplateLinksTo( $options = [] ) {
3427  return $this->getLinksTo( $options, 'templatelinks', 'tl' );
3428  }
3429 
3442  public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3443  $id = $this->getArticleID();
3444 
3445  # If the page doesn't exist; there can't be any link from this page
3446  if ( !$id ) {
3447  return [];
3448  }
3449 
3450  $db = wfGetDB( DB_REPLICA );
3451 
3452  $blNamespace = "{$prefix}_namespace";
3453  $blTitle = "{$prefix}_title";
3454 
3455  $pageQuery = WikiPage::getQueryInfo();
3456  $res = $db->select(
3457  [ $table, 'nestpage' => $pageQuery['tables'] ],
3458  array_merge(
3459  [ $blNamespace, $blTitle ],
3460  $pageQuery['fields']
3461  ),
3462  [ "{$prefix}_from" => $id ],
3463  __METHOD__,
3464  $options,
3465  [ 'nestpage' => [
3466  'LEFT JOIN',
3467  [ "page_namespace=$blNamespace", "page_title=$blTitle" ]
3468  ] ] + $pageQuery['joins']
3469  );
3470 
3471  $retVal = [];
3472  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3473  foreach ( $res as $row ) {
3474  if ( $row->page_id ) {
3475  $titleObj = self::newFromRow( $row );
3476  } else {
3477  $titleObj = self::makeTitle( $row->$blNamespace, $row->$blTitle );
3478  $linkCache->addBadLinkObj( $titleObj );
3479  }
3480  $retVal[] = $titleObj;
3481  }
3482 
3483  return $retVal;
3484  }
3485 
3496  public function getTemplateLinksFrom( $options = [] ) {
3497  return $this->getLinksFrom( $options, 'templatelinks', 'tl' );
3498  }
3499 
3508  public function getBrokenLinksFrom() {
3509  if ( $this->getArticleID() == 0 ) {
3510  # All links from article ID 0 are false positives
3511  return [];
3512  }
3513 
3514  $dbr = wfGetDB( DB_REPLICA );
3515  $res = $dbr->select(
3516  [ 'page', 'pagelinks' ],
3517  [ 'pl_namespace', 'pl_title' ],
3518  [
3519  'pl_from' => $this->getArticleID(),
3520  'page_namespace IS NULL'
3521  ],
3522  __METHOD__, [],
3523  [
3524  'page' => [
3525  'LEFT JOIN',
3526  [ 'pl_namespace=page_namespace', 'pl_title=page_title' ]
3527  ]
3528  ]
3529  );
3530 
3531  $retVal = [];
3532  foreach ( $res as $row ) {
3533  $retVal[] = self::makeTitle( $row->pl_namespace, $row->pl_title );
3534  }
3535  return $retVal;
3536  }
3537 
3544  public function getCdnUrls() {
3545  $urls = [
3546  $this->getInternalURL(),
3547  $this->getInternalURL( 'action=history' )
3548  ];
3549 
3550  $pageLang = $this->getPageLanguage();
3551  if ( $pageLang->hasVariants() ) {
3552  $variants = $pageLang->getVariants();
3553  foreach ( $variants as $vCode ) {
3554  $urls[] = $this->getInternalURL( $vCode );
3555  }
3556  }
3557 
3558  // If we are looking at a css/js user subpage, purge the action=raw.
3559  if ( $this->isUserJsConfigPage() ) {
3560  $urls[] = $this->getInternalURL( 'action=raw&ctype=text/javascript' );
3561  } elseif ( $this->isUserJsonConfigPage() ) {
3562  $urls[] = $this->getInternalURL( 'action=raw&ctype=application/json' );
3563  } elseif ( $this->isUserCssConfigPage() ) {
3564  $urls[] = $this->getInternalURL( 'action=raw&ctype=text/css' );
3565  }
3566 
3567  Hooks::run( 'TitleSquidURLs', [ $this, &$urls ] );
3568  return $urls;
3569  }
3570 
3574  public function purgeSquid() {
3576  new CdnCacheUpdate( $this->getCdnUrls() ),
3578  );
3579  }
3580 
3591  public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) {
3592  wfDeprecated( __METHOD__, '1.25' );
3593 
3594  global $wgUser;
3595 
3596  if ( !( $nt instanceof Title ) ) {
3597  // Normally we'd add this to $errors, but we'll get
3598  // lots of syntax errors if $nt is not an object
3599  return [ [ 'badtitletext' ] ];
3600  }
3601 
3602  $mp = MediaWikiServices::getInstance()->getMovePageFactory()->newMovePage( $this, $nt );
3603  $errors = $mp->isValidMove()->getErrorsArray();
3604  if ( $auth ) {
3605  $errors = wfMergeErrorArrays(
3606  $errors,
3607  $mp->checkPermissions( $wgUser, $reason )->getErrorsArray()
3608  );
3609  }
3610 
3611  return $errors ?: true;
3612  }
3613 
3627  public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true,
3628  array $changeTags = []
3629  ) {
3630  wfDeprecated( __METHOD__, '1.25' );
3631 
3632  global $wgUser;
3633 
3634  $mp = MediaWikiServices::getInstance()->getMovePageFactory()->newMovePage( $this, $nt );
3635  $method = $auth ? 'moveIfAllowed' : 'move';
3637  $status = $mp->$method( $wgUser, $reason, $createRedirect, $changeTags );
3638  if ( $status->isOK() ) {
3639  return true;
3640  } else {
3641  return $status->getErrorsArray();
3642  }
3643  }
3644 
3660  public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true,
3661  array $changeTags = []
3662  ) {
3663  wfDeprecated( __METHOD__, '1.34' );
3664 
3665  global $wgUser;
3666 
3667  $mp = new MovePage( $this, $nt );
3668  $method = $auth ? 'moveSubpagesIfAllowed' : 'moveSubpages';
3670  $result = $mp->$method( $wgUser, $reason, $createRedirect, $changeTags );
3671 
3672  if ( !$result->isOK() ) {
3673  return $result->getErrorsArray();
3674  }
3675 
3676  $retval = [];
3677  foreach ( $result->getValue() as $key => $status ) {
3679  if ( $status->isOK() ) {
3680  $retval[$key] = $status->getValue();
3681  } else {
3682  $retval[$key] = $status->getErrorsArray();
3683  }
3684  }
3685  return $retval;
3686  }
3687 
3695  public function isSingleRevRedirect() {
3696  $dbw = wfGetDB( DB_MASTER );
3697  $dbw->startAtomic( __METHOD__ );
3698 
3699  $row = $dbw->selectRow(
3700  'page',
3701  self::getSelectFields(),
3702  $this->pageCond(),
3703  __METHOD__,
3704  [ 'FOR UPDATE' ]
3705  );
3706  // Update the cached fields
3707  $this->loadFromRow( $row );
3708 
3709  if ( $this->mRedirect && $this->mLatestID ) {
3710  $isSingleRevRedirect = !$dbw->selectField(
3711  'revision',
3712  '1',
3713  [ 'rev_page' => $this->mArticleID, 'rev_id != ' . (int)$this->mLatestID ],
3714  __METHOD__,
3715  [ 'FOR UPDATE' ]
3716  );
3717  } else {
3718  $isSingleRevRedirect = false;
3719  }
3720 
3721  $dbw->endAtomic( __METHOD__ );
3722 
3723  return $isSingleRevRedirect;
3724  }
3725 
3734  public function isValidMoveTarget( $nt ) {
3735  wfDeprecated( __METHOD__, '1.25' );
3736 
3737  # Is it an existing file?
3738  if ( $nt->getNamespace() == NS_FILE ) {
3739  $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
3740  ->newFile( $nt );
3741  $file->load( File::READ_LATEST );
3742  if ( $file->exists() ) {
3743  wfDebug( __METHOD__ . ": file exists\n" );
3744  return false;
3745  }
3746  }
3747  # Is it a redirect with no history?
3748  if ( !$nt->isSingleRevRedirect() ) {
3749  wfDebug( __METHOD__ . ": not a one-rev redirect\n" );
3750  return false;
3751  }
3752  # Get the article text
3753  $rev = Revision::newFromTitle( $nt, false, Revision::READ_LATEST );
3754  if ( !is_object( $rev ) ) {
3755  return false;
3756  }
3757  $content = $rev->getContent();
3758  # Does the redirect point to the source?
3759  # Or is it a broken self-redirect, usually caused by namespace collisions?
3760  $redirTitle = $content ? $content->getRedirectTarget() : null;
3761 
3762  if ( $redirTitle ) {
3763  if ( $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() &&
3764  $redirTitle->getPrefixedDBkey() != $nt->getPrefixedDBkey() ) {
3765  wfDebug( __METHOD__ . ": redirect points to other page\n" );
3766  return false;
3767  } else {
3768  return true;
3769  }
3770  } else {
3771  # Fail safe (not a redirect after all. strange.)
3772  wfDebug( __METHOD__ . ": failsafe: database sais " . $nt->getPrefixedDBkey() .
3773  " is a redirect, but it doesn't contain a valid redirect.\n" );
3774  return false;
3775  }
3776  }
3777 
3785  public function getParentCategories() {
3786  $data = [];
3787 
3788  $titleKey = $this->getArticleID();
3789 
3790  if ( $titleKey === 0 ) {
3791  return $data;
3792  }
3793 
3794  $dbr = wfGetDB( DB_REPLICA );
3795 
3796  $res = $dbr->select(
3797  'categorylinks',
3798  'cl_to',
3799  [ 'cl_from' => $titleKey ],
3800  __METHOD__
3801  );
3802 
3803  if ( $res->numRows() > 0 ) {
3804  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
3805  foreach ( $res as $row ) {
3806  // $data[] = Title::newFromText( $contLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
3807  $data[$contLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] =
3808  $this->getFullText();
3809  }
3810  }
3811  return $data;
3812  }
3813 
3820  public function getParentCategoryTree( $children = [] ) {
3821  $stack = [];
3822  $parents = $this->getParentCategories();
3823 
3824  if ( $parents ) {
3825  foreach ( $parents as $parent => $current ) {
3826  if ( array_key_exists( $parent, $children ) ) {
3827  # Circular reference
3828  $stack[$parent] = [];
3829  } else {
3830  $nt = self::newFromText( $parent );
3831  if ( $nt ) {
3832  $stack[$parent] = $nt->getParentCategoryTree( $children + [ $parent => 1 ] );
3833  }
3834  }
3835  }
3836  }
3837 
3838  return $stack;
3839  }
3840 
3847  public function pageCond() {
3848  if ( $this->mArticleID > 0 ) {
3849  // PK avoids secondary lookups in InnoDB, shouldn't hurt other DBs
3850  return [ 'page_id' => $this->mArticleID ];
3851  } else {
3852  return [ 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform ];
3853  }
3854  }
3855 
3863  private function getRelativeRevisionID( $revId, $flags, $dir ) {
3864  $rl = MediaWikiServices::getInstance()->getRevisionLookup();
3865  $rev = $rl->getRevisionById( $revId, $flags );
3866  if ( !$rev ) {
3867  return false;
3868  }
3869 
3870  $oldRev = ( $dir === 'next' )
3871  ? $rl->getNextRevision( $rev, $flags )
3872  : $rl->getPreviousRevision( $rev, $flags );
3873 
3874  return $oldRev ? $oldRev->getId() : false;
3875  }
3876 
3885  public function getPreviousRevisionID( $revId, $flags = 0 ) {
3886  return $this->getRelativeRevisionID( $revId, $flags, 'prev' );
3887  }
3888 
3897  public function getNextRevisionID( $revId, $flags = 0 ) {
3898  return $this->getRelativeRevisionID( $revId, $flags, 'next' );
3899  }
3900 
3907  public function getFirstRevision( $flags = 0 ) {
3908  $pageId = $this->getArticleID( $flags );
3909  if ( $pageId ) {
3910  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
3911  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
3913  $row = wfGetDB( $index )->selectRow(
3914  $revQuery['tables'], $revQuery['fields'],
3915  [ 'rev_page' => $pageId ],
3916  __METHOD__,
3917  array_merge(
3918  [
3919  'ORDER BY' => [ 'rev_timestamp ASC', 'rev_id ASC' ],
3920  'IGNORE INDEX' => [ 'revision' => 'rev_timestamp' ], // See T159319
3921  ],
3922  $options
3923  ),
3924  $revQuery['joins']
3925  );
3926  if ( $row ) {
3927  return new Revision( $row, 0, $this );
3928  }
3929  }
3930  return null;
3931  }
3932 
3939  public function getEarliestRevTime( $flags = 0 ) {
3940  $rev = $this->getFirstRevision( $flags );
3941  return $rev ? $rev->getTimestamp() : null;
3942  }
3943 
3949  public function isNewPage() {
3950  $dbr = wfGetDB( DB_REPLICA );
3951  return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ );
3952  }
3953 
3959  public function isBigDeletion() {
3960  global $wgDeleteRevisionsLimit;
3961 
3962  if ( !$wgDeleteRevisionsLimit ) {
3963  return false;
3964  }
3965 
3966  if ( $this->mIsBigDeletion === null ) {
3967  $dbr = wfGetDB( DB_REPLICA );
3968 
3969  $revCount = $dbr->selectRowCount(
3970  'revision',
3971  '1',
3972  [ 'rev_page' => $this->getArticleID() ],
3973  __METHOD__,
3974  [ 'LIMIT' => $wgDeleteRevisionsLimit + 1 ]
3975  );
3976 
3977  $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit;
3978  }
3979 
3980  return $this->mIsBigDeletion;
3981  }
3982 
3988  public function estimateRevisionCount() {
3989  if ( !$this->exists() ) {
3990  return 0;
3991  }
3992 
3993  if ( $this->mEstimateRevisions === null ) {
3994  $dbr = wfGetDB( DB_REPLICA );
3995  $this->mEstimateRevisions = $dbr->estimateRowCount( 'revision', '*',
3996  [ 'rev_page' => $this->getArticleID() ], __METHOD__ );
3997  }
3998 
4000  }
4001 
4013  public function countRevisionsBetween( $old, $new, $max = null ) {
4014  if ( !( $old instanceof Revision ) ) {
4015  $old = Revision::newFromTitle( $this, (int)$old );
4016  }
4017  if ( !( $new instanceof Revision ) ) {
4018  $new = Revision::newFromTitle( $this, (int)$new );
4019  }
4020  if ( !$old || !$new ) {
4021  return 0; // nothing to compare
4022  }
4023  return MediaWikiServices::getInstance()
4024  ->getRevisionStore()
4025  ->countRevisionsBetween(
4026  $this->getArticleID(),
4027  $old->getRevisionRecord(),
4028  $new->getRevisionRecord(),
4029  $max
4030  );
4031  }
4032 
4050  public function getAuthorsBetween( $old, $new, $limit, $options = [] ) {
4051  if ( !( $old instanceof Revision ) ) {
4052  $old = Revision::newFromTitle( $this, (int)$old );
4053  }
4054  if ( !( $new instanceof Revision ) ) {
4055  $new = Revision::newFromTitle( $this, (int)$new );
4056  }
4057  try {
4058  $users = MediaWikiServices::getInstance()
4059  ->getRevisionStore()
4060  ->getAuthorsBetween(
4061  $this->getArticleID(),
4062  $old->getRevisionRecord(),
4063  $new->getRevisionRecord(),
4064  null,
4065  $limit,
4066  $options
4067  );
4068  return array_map( function ( UserIdentity $user ) {
4069  return $user->getName();
4070  }, $users );
4071  } catch ( InvalidArgumentException $e ) {
4072  return null; // b/c
4073  }
4074  }
4075 
4092  public function countAuthorsBetween( $old, $new, $limit, $options = [] ) {
4093  $authors = $this->getAuthorsBetween( $old, $new, $limit, $options );
4094  return $authors ? count( $authors ) : 0;
4095  }
4096 
4103  public function equals( LinkTarget $title ) {
4104  // Note: === is necessary for proper matching of number-like titles.
4105  return $this->mInterwiki === $title->getInterwiki()
4106  && $this->mNamespace == $title->getNamespace()
4107  && $this->mDbkeyform === $title->getDBkey();
4108  }
4109 
4116  public function isSubpageOf( Title $title ) {
4117  return $this->mInterwiki === $title->mInterwiki
4118  && $this->mNamespace == $title->mNamespace
4119  && strpos( $this->mDbkeyform, $title->mDbkeyform . '/' ) === 0;
4120  }
4121 
4132  public function exists( $flags = 0 ) {
4133  $exists = $this->getArticleID( $flags ) != 0;
4134  Hooks::run( 'TitleExists', [ $this, &$exists ] );
4135  return $exists;
4136  }
4137 
4154  public function isAlwaysKnown() {
4155  $isKnown = null;
4156 
4167  Hooks::run( 'TitleIsAlwaysKnown', [ $this, &$isKnown ] );
4168 
4169  if ( !is_null( $isKnown ) ) {
4170  return $isKnown;
4171  }
4172 
4173  if ( $this->isExternal() ) {
4174  return true; // any interwiki link might be viewable, for all we know
4175  }
4176 
4177  $services = MediaWikiServices::getInstance();
4178  switch ( $this->mNamespace ) {
4179  case NS_MEDIA:
4180  case NS_FILE:
4181  // file exists, possibly in a foreign repo
4182  return (bool)$services->getRepoGroup()->findFile( $this );
4183  case NS_SPECIAL:
4184  // valid special page
4185  return $services->getSpecialPageFactory()->exists( $this->mDbkeyform );
4186  case NS_MAIN:
4187  // selflink, possibly with fragment
4188  return $this->mDbkeyform == '';
4189  case NS_MEDIAWIKI:
4190  // known system message
4191  return $this->hasSourceText() !== false;
4192  default:
4193  return false;
4194  }
4195  }
4196 
4208  public function isKnown() {
4209  return $this->isAlwaysKnown() || $this->exists();
4210  }
4211 
4217  public function hasSourceText() {
4218  if ( $this->exists() ) {
4219  return true;
4220  }
4221 
4222  if ( $this->mNamespace == NS_MEDIAWIKI ) {
4223  // If the page doesn't exist but is a known system message, default
4224  // message content will be displayed, same for language subpages-
4225  // Use always content language to avoid loading hundreds of languages
4226  // to get the link color.
4227  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
4228  list( $name, ) = MessageCache::singleton()->figureMessage(
4229  $contLang->lcfirst( $this->getText() )
4230  );
4231  $message = wfMessage( $name )->inLanguage( $contLang )->useDatabase( false );
4232  return $message->exists();
4233  }
4234 
4235  return false;
4236  }
4237 
4275  public function getDefaultMessageText() {
4276  if ( $this->mNamespace != NS_MEDIAWIKI ) { // Just in case
4277  return false;
4278  }
4279 
4280  list( $name, $lang ) = MessageCache::singleton()->figureMessage(
4281  MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $this->getText() )
4282  );
4283  $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
4284 
4285  if ( $message->exists() ) {
4286  return $message->plain();
4287  } else {
4288  return false;
4289  }
4290  }
4291 
4298  public function invalidateCache( $purgeTime = null ) {
4299  if ( wfReadOnly() ) {
4300  return false;
4301  } elseif ( $this->mArticleID === 0 ) {
4302  return true; // avoid gap locking if we know it's not there
4303  }
4304 
4305  $dbw = wfGetDB( DB_MASTER );
4306  $dbw->onTransactionPreCommitOrIdle(
4307  function () use ( $dbw ) {
4309  $this, null, null, $dbw->getDomainID() );
4310  },
4311  __METHOD__
4312  );
4313 
4314  $conds = $this->pageCond();
4316  new AutoCommitUpdate(
4317  $dbw,
4318  __METHOD__,
4319  function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) {
4320  $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
4321  $dbw->update(
4322  'page',
4323  [ 'page_touched' => $dbTimestamp ],
4324  $conds + [ 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ],
4325  $fname
4326  );
4327  MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $this );
4328  }
4329  ),
4331  );
4332 
4333  return true;
4334  }
4335 
4341  public function touchLinks() {
4342  $jobs = [];
4344  $this,
4345  'pagelinks',
4346  [ 'causeAction' => 'page-touch' ]
4347  );
4348  if ( $this->mNamespace == NS_CATEGORY ) {
4350  $this,
4351  'categorylinks',
4352  [ 'causeAction' => 'category-touch' ]
4353  );
4354  }
4355 
4356  JobQueueGroup::singleton()->lazyPush( $jobs );
4357  }
4358 
4365  public function getTouched( $db = null ) {
4366  if ( $db === null ) {
4367  $db = wfGetDB( DB_REPLICA );
4368  }
4369  $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ );
4370  return $touched;
4371  }
4372 
4379  public function getNotificationTimestamp( $user = null ) {
4380  global $wgUser;
4381 
4382  // Assume current user if none given
4383  if ( !$user ) {
4384  $user = $wgUser;
4385  }
4386  // Check cache first
4387  $uid = $user->getId();
4388  if ( !$uid ) {
4389  return false;
4390  }
4391  // avoid isset here, as it'll return false for null entries
4392  if ( array_key_exists( $uid, $this->mNotificationTimestamp ) ) {
4393  return $this->mNotificationTimestamp[$uid];
4394  }
4395  // Don't cache too much!
4396  if ( count( $this->mNotificationTimestamp ) >= self::CACHE_MAX ) {
4397  $this->mNotificationTimestamp = [];
4398  }
4399 
4400  $store = MediaWikiServices::getInstance()->getWatchedItemStore();
4401  $watchedItem = $store->getWatchedItem( $user, $this );
4402  if ( $watchedItem ) {
4403  $this->mNotificationTimestamp[$uid] = $watchedItem->getNotificationTimestamp();
4404  } else {
4405  $this->mNotificationTimestamp[$uid] = false;
4406  }
4407 
4408  return $this->mNotificationTimestamp[$uid];
4409  }
4410 
4417  public function getNamespaceKey( $prepend = 'nstab-' ) {
4418  // Gets the subject namespace of this title
4419  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
4420  $subjectNS = $nsInfo->getSubject( $this->mNamespace );
4421  // Prefer canonical namespace name for HTML IDs
4422  $namespaceKey = $nsInfo->getCanonicalName( $subjectNS );
4423  if ( $namespaceKey === false ) {
4424  // Fallback to localised text
4425  $namespaceKey = $this->getSubjectNsText();
4426  }
4427  // Makes namespace key lowercase
4428  $namespaceKey = MediaWikiServices::getInstance()->getContentLanguage()->lc( $namespaceKey );
4429  // Uses main
4430  if ( $namespaceKey == '' ) {
4431  $namespaceKey = 'main';
4432  }
4433  // Changes file to image for backwards compatibility
4434  if ( $namespaceKey == 'file' ) {
4435  $namespaceKey = 'image';
4436  }
4437  return $prepend . $namespaceKey;
4438  }
4439 
4446  public function getRedirectsHere( $ns = null ) {
4447  $redirs = [];
4448 
4449  $dbr = wfGetDB( DB_REPLICA );
4450  $where = [
4451  'rd_namespace' => $this->mNamespace,
4452  'rd_title' => $this->mDbkeyform,
4453  'rd_from = page_id'
4454  ];
4455  if ( $this->isExternal() ) {
4456  $where['rd_interwiki'] = $this->mInterwiki;
4457  } else {
4458  $where[] = 'rd_interwiki = ' . $dbr->addQuotes( '' ) . ' OR rd_interwiki IS NULL';
4459  }
4460  if ( !is_null( $ns ) ) {
4461  $where['page_namespace'] = $ns;
4462  }
4463 
4464  $res = $dbr->select(
4465  [ 'redirect', 'page' ],
4466  [ 'page_namespace', 'page_title' ],
4467  $where,
4468  __METHOD__
4469  );
4470 
4471  foreach ( $res as $row ) {
4472  $redirs[] = self::newFromRow( $row );
4473  }
4474  return $redirs;
4475  }
4476 
4482  public function isValidRedirectTarget() {
4484 
4485  if ( $this->isSpecialPage() ) {
4486  // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
4487  if ( $this->isSpecial( 'Userlogout' ) ) {
4488  return false;
4489  }
4490 
4491  foreach ( $wgInvalidRedirectTargets as $target ) {
4492  if ( $this->isSpecial( $target ) ) {
4493  return false;
4494  }
4495  }
4496  }
4497 
4498  return true;
4499  }
4500 
4506  public function getBacklinkCache() {
4507  return BacklinkCache::get( $this );
4508  }
4509 
4515  public function canUseNoindex() {
4517 
4518  $bannedNamespaces = $wgExemptFromUserRobotsControl ??
4519  MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
4520 
4521  return !in_array( $this->mNamespace, $bannedNamespaces );
4522  }
4523 
4534  public function getCategorySortkey( $prefix = '' ) {
4535  $unprefixed = $this->getText();
4536 
4537  // Anything that uses this hook should only depend
4538  // on the Title object passed in, and should probably
4539  // tell the users to run updateCollations.php --force
4540  // in order to re-sort existing category relations.
4541  Hooks::run( 'GetDefaultSortkey', [ $this, &$unprefixed ] );
4542  if ( $prefix !== '' ) {
4543  # Separate with a line feed, so the unprefixed part is only used as
4544  # a tiebreaker when two pages have the exact same prefix.
4545  # In UCA, tab is the only character that can sort above LF
4546  # so we strip both of them from the original prefix.
4547  $prefix = strtr( $prefix, "\n\t", ' ' );
4548  return "$prefix\n$unprefixed";
4549  }
4550  return $unprefixed;
4551  }
4552 
4560  private function getDbPageLanguageCode() {
4561  global $wgPageLanguageUseDB;
4562 
4563  // check, if the page language could be saved in the database, and if so and
4564  // the value is not requested already, lookup the page language using LinkCache
4565  if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) {
4566  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
4567  $linkCache->addLinkObj( $this );
4568  $this->mDbPageLanguage = $linkCache->getGoodLinkFieldObj( $this, 'lang' );
4569  }
4570 
4571  return $this->mDbPageLanguage;
4572  }
4573 
4582  public function getPageLanguage() {
4583  global $wgLang, $wgLanguageCode;
4584  if ( $this->isSpecialPage() ) {
4585  // special pages are in the user language
4586  return $wgLang;
4587  }
4588 
4589  // Checking if DB language is set
4590  $dbPageLanguage = $this->getDbPageLanguageCode();
4591  if ( $dbPageLanguage ) {
4592  return wfGetLangObj( $dbPageLanguage );
4593  }
4594 
4595  if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) {
4596  // Note that this may depend on user settings, so the cache should
4597  // be only per-request.
4598  // NOTE: ContentHandler::getPageLanguage() may need to load the
4599  // content to determine the page language!
4600  // Checking $wgLanguageCode hasn't changed for the benefit of unit
4601  // tests.
4602  $contentHandler = ContentHandler::getForTitle( $this );
4603  $langObj = $contentHandler->getPageLanguage( $this );
4604  $this->mPageLanguage = [ $langObj->getCode(), $wgLanguageCode ];
4605  } else {
4606  $langObj = MediaWikiServices::getInstance()->getLanguageFactory()
4607  ->getLanguage( $this->mPageLanguage[0] );
4608  }
4609 
4610  return $langObj;
4611  }
4612 
4621  public function getPageViewLanguage() {
4622  global $wgLang;
4623 
4624  if ( $this->isSpecialPage() ) {
4625  // If the user chooses a variant, the content is actually
4626  // in a language whose code is the variant code.
4627  $variant = $wgLang->getPreferredVariant();
4628  if ( $wgLang->getCode() !== $variant ) {
4629  return MediaWikiServices::getInstance()->getLanguageFactory()
4630  ->getLanguage( $variant );
4631  }
4632 
4633  return $wgLang;
4634  }
4635 
4636  // Checking if DB language is set
4637  $dbPageLanguage = $this->getDbPageLanguageCode();
4638  if ( $dbPageLanguage ) {
4639  $pageLang = wfGetLangObj( $dbPageLanguage );
4640  $variant = $pageLang->getPreferredVariant();
4641  if ( $pageLang->getCode() !== $variant ) {
4642  $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()
4643  ->getLanguage( $variant );
4644  }
4645 
4646  return $pageLang;
4647  }
4648 
4649  // @note Can't be cached persistently, depends on user settings.
4650  // @note ContentHandler::getPageViewLanguage() may need to load the
4651  // content to determine the page language!
4652  $contentHandler = ContentHandler::getForTitle( $this );
4653  $pageLang = $contentHandler->getPageViewLanguage( $this );
4654  return $pageLang;
4655  }
4656 
4667  public function getEditNotices( $oldid = 0 ) {
4668  $notices = [];
4669 
4670  // Optional notice for the entire namespace
4671  $editnotice_ns = 'editnotice-' . $this->mNamespace;
4672  $msg = wfMessage( $editnotice_ns );
4673  if ( $msg->exists() ) {
4674  $html = $msg->parseAsBlock();
4675  // Edit notices may have complex logic, but output nothing (T91715)
4676  if ( trim( $html ) !== '' ) {
4677  $notices[$editnotice_ns] = Html::rawElement(
4678  'div',
4679  [ 'class' => [
4680  'mw-editnotice',
4681  'mw-editnotice-namespace',
4682  Sanitizer::escapeClass( "mw-$editnotice_ns" )
4683  ] ],
4684  $html
4685  );
4686  }
4687  }
4688 
4689  if (
4690  MediaWikiServices::getInstance()->getNamespaceInfo()->
4691  hasSubpages( $this->mNamespace )
4692  ) {
4693  // Optional notice for page itself and any parent page
4694  $editnotice_base = $editnotice_ns;
4695  foreach ( explode( '/', $this->mDbkeyform ) as $part ) {
4696  $editnotice_base .= '-' . $part;
4697  $msg = wfMessage( $editnotice_base );
4698  if ( $msg->exists() ) {
4699  $html = $msg->parseAsBlock();
4700  if ( trim( $html ) !== '' ) {
4701  $notices[$editnotice_base] = Html::rawElement(
4702  'div',
4703  [ 'class' => [
4704  'mw-editnotice',
4705  'mw-editnotice-base',
4706  Sanitizer::escapeClass( "mw-$editnotice_base" )
4707  ] ],
4708  $html
4709  );
4710  }
4711  }
4712  }
4713  } else {
4714  // Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
4715  $editnoticeText = $editnotice_ns . '-' . strtr( $this->mDbkeyform, '/', '-' );
4716  $msg = wfMessage( $editnoticeText );
4717  if ( $msg->exists() ) {
4718  $html = $msg->parseAsBlock();
4719  if ( trim( $html ) !== '' ) {
4720  $notices[$editnoticeText] = Html::rawElement(
4721  'div',
4722  [ 'class' => [
4723  'mw-editnotice',
4724  'mw-editnotice-page',
4725  Sanitizer::escapeClass( "mw-$editnoticeText" )
4726  ] ],
4727  $html
4728  );
4729  }
4730  }
4731  }
4732 
4733  Hooks::run( 'TitleGetEditNotices', [ $this, $oldid, &$notices ] );
4734  return $notices;
4735  }
4736 
4742  private function loadFieldFromDB( $field, $flags ) {
4743  if ( !in_array( $field, self::getSelectFields(), true ) ) {
4744  return false; // field does not exist
4745  }
4746 
4747  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
4748  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
4749 
4750  return wfGetDB( $index )->selectField(
4751  'page',
4752  $field,
4753  $this->pageCond(),
4754  __METHOD__,
4755  $options
4756  );
4757  }
4758 
4762  public function __sleep() {
4763  return [
4764  'mNamespace',
4765  'mDbkeyform',
4766  'mFragment',
4767  'mInterwiki',
4768  'mLocalInterwiki',
4769  'mDefaultNamespace',
4770  ];
4771  }
4772 
4773  public function __wakeup() {
4774  $this->mArticleID = ( $this->mNamespace >= 0 ) ? -1 : 0;
4775  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
4776  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
4777  }
4778 
4779 }
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:1175
Title\getTitleProtection
getTitleProtection()
Is this title subject to title protection? Title protection is the one applied against creation of su...
Definition: Title.php:2493
Title\canUseNoindex
canUseNoindex()
Whether the magic words INDEX and NOINDEX function for this page.
Definition: Title.php:4515
Title\getLocalURL
getLocalURL( $query='', $query2=false)
Get a URL with no fragment or server name (relative URL) from a Title object.
Definition: Title.php:2172
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:219
Title\isSemiProtected
isSemiProtected( $action='edit')
Is this page "semi-protected" - the only protection levels are listed in $wgSemiprotectedRestrictionL...
Definition: Title.php:2581
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:2642
Title\getTalkNsText
getTalkNsText()
Get the namespace text of the talk page.
Definition: Title.php:1158
wfMergeErrorArrays
wfMergeErrorArrays(... $args)
Merge arrays in the style of getUserPermissionsErrors, with duplicate removal e.g.
Definition: GlobalFunctions.php:181
Title\getSubpageText
getSubpageText()
Get the lowest-level subpage name, i.e.
Definition: Title.php:1997
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:317
Title\isBigDeletion
isBigDeletion()
Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit.
Definition: Title.php:3959
Title\getNextRevisionID
getNextRevisionID( $revId, $flags=0)
Get the revision ID of the next revision.
Definition: Title.php:3897
PROTO_CANONICAL
const PROTO_CANONICAL
Definition: Defines.php:203
Title\areCascadeProtectionSourcesLoaded
areCascadeProtectionSourcesLoaded( $getPages=true)
Determines whether cascading protection sources have already been loaded from the database.
Definition: Title.php:2675
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:2448
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:811
Title\getInternalURL
getInternalURL( $query='', $query2=false)
Get the URL form for an internal link.
Definition: Title.php:2303
$wgActionPaths
$wgActionPaths
Definition: img_auth.php:48
Title\getFragment
getFragment()
Get the Title fragment (i.e.
Definition: Title.php:1742
$wgExemptFromUserRobotsControl
$wgExemptFromUserRobotsControl
An array of namespace keys in which the INDEX/__NOINDEX__ magic words will not function,...
Definition: DefaultSettings.php:8053
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:1634
Title\inNamespace
inNamespace( $ns)
Returns true if the title is inside the specified namespace.
Definition: Title.php:1296
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:1358
Title\wasLocalInterwiki
wasLocalInterwiki()
Was this a local interwiki link?
Definition: Title.php:933
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:129
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:35
Title\inNamespaces
inNamespaces(... $namespaces)
Returns true if the title is inside one of the specified namespaces.
Definition: Title.php:1308
Title\isWikitextPage
isWikitextPage()
Does that page contain wikitext, or it is JS, CSS or whatever?
Definition: Title.php:1415
Title\isUserCssConfigPage
isUserCssConfigPage()
Is this a CSS "config" sub-page of a user page?
Definition: Title.php:1477
Title\getBacklinkCache
getBacklinkCache()
Get a backlink cache object.
Definition: Title.php:4506
Title\getPartialURL
getPartialURL()
Get the URL-encoded form of the main part.
Definition: Title.php:1005
$wgLegalTitleChars
$wgLegalTitleChars
Allowed title characters – regex character class Don't change this unless you know what you're doing.
Definition: DefaultSettings.php:3922
Title\clearCaches
static clearCaches()
Text form (spaces not underscores) of the main part.
Definition: Title.php:3296
AutoCommitUpdate
Deferrable Update for closure/callback updates that should use auto-commit mode.
Definition: AutoCommitUpdate.php:9
Title\moveSubpages
moveSubpages( $nt, $auth=true, $reason='', $createRedirect=true, array $changeTags=[])
Move this page's subpages to be subpages of $nt.
Definition: Title.php:3660
Title\getTitleValue
getTitleValue()
Get a TitleValue object representing this Title.
Definition: Title.php:973
Title\estimateRevisionCount
estimateRevisionCount()
Get the approximate revision count of this page.
Definition: Title.php:3988
Title\countRevisionsBetween
countRevisionsBetween( $old, $new, $max=null)
Get the number of revisions between the given revision.
Definition: Title.php:4013
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:4560
Title\getSkinFromConfigSubpage
getSkinFromConfigSubpage()
Trim down a .css, .json, or .js subpage title to get the corresponding skin name.
Definition: Title.php:1461
$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:1604
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:4379
Title\getParentCategoryTree
getParentCategoryTree( $children=[])
Get a tree of parent categories.
Definition: Title.php:3820
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:217
Title\fixUrlQueryArgs
static fixUrlQueryArgs( $query, $query2=false)
Helper to fix up the get{Canonical,Full,Link,Local,Internal}URL args get{Canonical,...
Definition: Title.php:2065
Title\fixSpecialName
fixSpecialName()
If the Title refers to a special page alias which is not the local default, resolve the alias,...
Definition: Title.php:1272
Title\getInterwikiLookup
static getInterwikiLookup()
B/C kludge: provide an InterwikiLookup for use by Title.
Definition: Title.php:212
Title\isUserJsConfigPage
isUserJsConfigPage()
Is this a JS "config" sub-page of a user page?
Definition: Title.php:1505
Title\touchLinks
touchLinks()
Update page_touched timestamps and send CDN purge messages for pages linking to this title.
Definition: Title.php:4341
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:1853
Title\getTransWikiID
getTransWikiID()
Returns the DB name of the distant wiki which owns the object.
Definition: Title.php:956
DeferredUpdates\addUpdate
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred list to be run later by execute()
Definition: DeferredUpdates.php:85
Title\getArticleID
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:3161
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:2278
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:2370
NS_FILE
const NS_FILE
Definition: Defines.php:66
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
Title\isTalkPage
isTalkPage()
Is this a talk page of some sort?
Definition: Title.php:1588
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1170
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1263
$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
ContentHandler\getForTitle
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
Definition: ContentHandler.php:201
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1078
Title\isExternal
isExternal()
Is this Title interwiki?
Definition: Title.php:913
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:2850
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:646
Title\getDefaultMessageText
getDefaultMessageText()
Get the default (plain) message contents for an page that overrides an interface message key.
Definition: Title.php:4275
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:215
Title\hasSourceText
hasSourceText()
Does this page have source text?
Definition: Title.php:4217
Title\loadFromRow
loadFromRow( $row)
Load Title object fields from a DB row.
Definition: Title.php:528
Title\setFragment
setFragment( $fragment)
Set the fragment for this title.
Definition: Title.php:1788
$res
$res
Definition: testCompression.php:54
IDBAccessObject
Interface for database access objects.
Definition: IDBAccessObject.php:55
Title\equals
equals(LinkTarget $title)
Compare with another title.
Definition: Title.php:4103
$wgContentHandlerUseDB
$wgContentHandlerUseDB
Set to false to disable use of the database fields introduced by the ContentHandler facility.
Definition: DefaultSettings.php:8614
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:706
Title\__wakeup
__wakeup()
Text form (spaces not underscores) of the main part.
Definition: Title.php:4773
$revQuery
$revQuery
Definition: testCompression.php:53
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
HTMLCacheUpdateJob\newForBacklinks
static newForBacklinks(Title $title, $table, $params=[])
Definition: HTMLCacheUpdateJob.php:59
Title\getParentCategories
getParentCategories()
Get categories to which this Title belongs and return an array of categories' names.
Definition: Title.php:3785
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:3384
Title\$mContentModel
bool string $mContentModel
ID of the page's content model, i.e.
Definition: Title.php:101
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:1519
MessageLocalizer
Interface for localizing messages in MediaWiki.
Definition: MessageLocalizer.php:28
Title\getNsText
getNsText()
Get the namespace text.
Definition: Title.php:1122
Title\$mDbkeyform
string $mDbkeyform
Main part with underscores.
Definition: Title.php:81
Title\$mUrlform
string $mUrlform
URL-encoded form of the main part.
Definition: Title.php:79
$dbr
$dbr
Definition: testCompression.php:52
Title\getLinksFrom
getLinksFrom( $options=[], $table='pagelinks', $prefix='pl')
Get an array of Title objects linked from this Title Also stores the IDs in the link cache.
Definition: Title.php:3442
Title\$mOldRestrictions
string bool $mOldRestrictions
Comma-separated set of permission keys indicating who can move or edit the page from the page table,...
Definition: Title.php:121
PathRouter\getActionPaths
static getActionPaths(array $actionPaths, $articlePath)
Definition: PathRouter.php:430
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Definition: GlobalFunctions.php:439
Revision
Definition: Revision.php:40
NS_MAIN
const NS_MAIN
Definition: Defines.php:60
Title\loadFieldFromDB
loadFieldFromDB( $field, $flags)
Definition: Title.php:4742
Title\isCascadeProtected
isCascadeProtected()
Cascading protection: Return true if cascading restrictions apply to this page, false if not.
Definition: Title.php:2661
Revision\newFromTitle
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
Definition: Revision.php:138
Title\isValidMoveTarget
isValidMoveTarget( $nt)
Checks if $this can be moved to a given Title.
Definition: Title.php:3734
Title\getCdnUrls
getCdnUrls()
Get a list of URLs to purge from the CDN cache when this page changes.
Definition: Title.php:3544
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:49
Title\getOtherPage
getOtherPage()
Get the other title for this page, if this is a subject page get the talk page, if it is a subject pa...
Definition: Title.php:1706
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:1433
Title\isUserJsonConfigPage
isUserJsonConfigPage()
Is this a JSON "config" sub-page of a user page?
Definition: Title.php:1491
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:186
$wgRawHtmlMessages
string[] $wgRawHtmlMessages
List of messages which might contain raw HTML.
Definition: DefaultSettings.php:8834
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:1014
Revision\getQueryInfo
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
Definition: Revision.php:315
Title\nameOf
static nameOf( $id)
Get the prefixed DB key associated with an ID.
Definition: Title.php:671
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:1254
MWException
MediaWiki exception.
Definition: MWException.php:26
Title\getTitleFormatter
static getTitleFormatter()
B/C kludge: provide a TitleParser for use by Title.
Definition: Title.php:200
Title\isMainPage
isMainPage()
Is this the mainpage?
Definition: Title.php:1382
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1044
Title\moveTo
moveTo(&$nt, $auth=true, $reason='', $createRedirect=true, array $changeTags=[])
Move a title to a new location.
Definition: Title.php:3627
Title\getSubpage
getSubpage( $text)
Get the title for a subpage of the current page.
Definition: Title.php:2021
Title\getBaseTitle
getBaseTitle()
Get the base page name title, i.e.
Definition: Title.php:1977
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1035
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:516
Title\isConversionTable
isConversionTable()
Is this a conversion table for the LanguageConverter?
Definition: Title.php:1403
MovePage
Handles the backend logic of moving a page from one title to another.
Definition: MovePage.php:36
Title\isProtected
isProtected( $action='')
Does the title correspond to a protected article?
Definition: Title.php:2609
Title\flushRestrictions
flushRestrictions()
Flush the protection cache in this object and force reload from the database.
Definition: Title.php:2999
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2579
Title\getCategorySortkey
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:4534
Title\getInterwiki
getInterwiki()
Get the interwiki prefix.
Definition: Title.php:924
Title\isSiteJsonConfigPage
isSiteJsonConfigPage()
Is this a sitewide JSON "config" page?
Definition: Title.php:1537
$matches
$matches
Definition: NoLocalSettings.php:24
Title\isValidRedirectTarget
isValidRedirectTarget()
Check if this Title is a valid redirect target.
Definition: Title.php:4482
Title\deleteTitleProtection
deleteTitleProtection()
Remove any title protection due to page existing.
Definition: Title.php:2563
Title\__construct
__construct()
Definition: Title.php:219
$wgLang
$wgLang
Definition: Setup.php:858
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:2389
Title\getBrokenLinksFrom
getBrokenLinksFrom()
Get an array of Title objects referring to non-existent articles linked from this page.
Definition: Title.php:3508
Title\isUserConfigPage
isUserConfigPage()
Is this a "config" (.css, .json, or .js) sub-page of a user page?
Definition: Title.php:1447
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:202
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:1649
MapCacheLRU
Handles a simple LRU key/value map with a maximum number of entries.
Definition: MapCacheLRU.php:37
wfGetLangObj
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
Definition: GlobalFunctions.php:1214
Title\loadRestrictions
loadRestrictions( $oldFashionedRestrictions=null, $flags=0)
Load restrictions from the page_restrictions table.
Definition: Title.php:2928
$wgInvalidRedirectTargets
$wgInvalidRedirectTargets
Array of invalid page redirect targets.
Definition: DefaultSettings.php:4106
Title\getFullText
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
Definition: Title.php:1877
Title\getTitleCache
static getTitleCache()
Definition: Title.php:425
Title\hasFragment
hasFragment()
Check if a Title fragment is set.
Definition: Title.php:1752
Title\getRedirectsHere
getRedirectsHere( $ns=null)
Get all extant redirects to this Title.
Definition: Title.php:4446
MediaWiki\User\UserIdentity\getName
getName()
$title
$title
Definition: testCompression.php:36
Title\warnIfPageCannotExist
warnIfPageCannotExist(Title $title, $method)
Definition: Title.php:1675
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:584
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:1900
Title\getRootText
getRootText()
Get the root page name text without a namespace, i.e.
Definition: Title.php:1900
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:74
$wgNamespaceProtection
$wgNamespaceProtection
Set the minimum permissions required to edit pages in each namespace.
Definition: DefaultSettings.php:5354
Title\canExist
canExist()
Can this title represent a page in the wiki's database?
Definition: Title.php:1189
$wgDeleteRevisionsLimit
$wgDeleteRevisionsLimit
Optional to restrict deletion of pages with higher revision counts to users with the 'bigdelete' perm...
Definition: DefaultSettings.php:5531
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:4762
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:2327
MessageCache\singleton
static singleton()
Get the singleton instance of this class.
Definition: MessageCache.php:117
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:1799
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:1731
ResourceLoaderWikiModule\invalidateModuleCache
static invalidateModuleCache(Title $title, ?Revision $old, ?Revision $new, $domain)
Clear the preloadTitleInfo() cache for all wiki modules on this wiki on page change if it was a JS or...
Definition: ResourceLoaderWikiModule.php:540
Title\newFromTextThrow
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:352
$wgPageLanguageUseDB
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
Definition: DefaultSettings.php:8702
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:859
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:2046
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:610
Title\__toString
__toString()
Return a string representation of this title.
Definition: Title.php:1867
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:48
$content
$content
Definition: router.php:78
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:3426
$wgMainPageIsDomainRoot
bool $wgMainPageIsDomainRoot
Option to whether serve the main page as the domain root.
Definition: DefaultSettings.php:9105
Title\areRestrictionsCascading
areRestrictionsCascading()
Returns cascading restrictions for the current article.
Definition: Title.php:2831
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:48
CdnCacheUpdate
Handles purging the appropriate CDN objects given a list of URLs or Title instances.
Definition: CdnCacheUpdate.php:30
Title\getLatestRevID
getLatestRevID( $flags=0)
What is the page_latest field for this page?
Definition: Title.php:3242
Title\areRestrictionsLoaded
areRestrictionsLoaded()
Accessor for mRestrictionsLoaded.
Definition: Title.php:2778
Title\getSubpages
getSubpages( $limit=-1)
Get all subpages of this page.
Definition: Title.php:3081
Title\isSingleRevRedirect
isSingleRevRedirect()
Locks the page row and check if this page is single revision redirect.
Definition: Title.php:3695
$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:4621
Title\newFromDBkey
static newFromDBkey( $key)
Create a new Title from a prefixed DB key.
Definition: Title.php:230
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:2949
Title\isSubpage
isSubpage()
Is this a subpage?
Definition: Title.php:1391
Title\hasContentModel
hasContentModel( $id)
Convenience method for checking a title's content model name.
Definition: Title.php:1080
Title\getRestrictionExpiry
getRestrictionExpiry( $action)
Get the expiry time for the restriction against a given action.
Definition: Title.php:2819
Title\newFromURL
static newFromURL( $url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:402
Title\isValidMoveOperation
isValidMoveOperation(&$nt, $auth=true, $reason='')
Check whether a given move operation would be valid.
Definition: Title.php:3591
MediaWiki\Linker\LinkTarget\getFragment
getFragment()
Get the link fragment (i.e.
PROTO_HTTP
const PROTO_HTTP
Definition: Defines.php:199
Title\$mRestrictionsExpiry
array $mRestrictionsExpiry
When do the restrictions on this page expire?
Definition: Title.php:130
MapCacheLRU\set
set( $key, $value, $rank=self::RANK_TOP)
Set a key/value pair.
Definition: MapCacheLRU.php:110
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:201
Title\resetArticleID
resetArticleID( $id)
Inject a page ID, reset DB-loaded fields, and clear the link cache for this title.
Definition: Title.php:3274
Title\isSubpageOf
isSubpageOf(Title $title)
Check if this title is a subpage of another title.
Definition: Title.php:4116
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:898
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:1047
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:490
Wikimedia\Rdbms\IDatabase\update
update( $table, $values, $conds, $fname=__METHOD__, $options=[])
UPDATE wrapper.
WikiPage\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new page object.
Definition: WikiPage.php:385
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:269
Title\prefix
prefix( $name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object.
Definition: Title.php:1815
Title\getNamespaceKey
getNamespaceKey( $prepend='nstab-')
Generate strings used for xml 'id' names in monobook tabs.
Definition: Title.php:4417
Title\getEditURL
getEditURL()
Get the edit URL for this Title.
Definition: Title.php:2341
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:2103
Title\isKnown
isKnown()
Does this title refer to a page that can (or might) be meaningfully viewed? In particular,...
Definition: Title.php:4208
$wgArticlePath
$wgArticlePath
Definition: img_auth.php:47
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:3907
Title\getAllRestrictions
getAllRestrictions()
Accessor/initialisation for mRestrictions.
Definition: Title.php:2805
Title\getEarliestRevTime
getEarliestRevTime( $flags=0)
Get the oldest revision timestamp of this page.
Definition: Title.php:3939
Title
Represents a title within MediaWiki.
Definition: Title.php:42
Title\$mCascadingRestrictions
$mCascadingRestrictions
Caching the results of getCascadeProtectionSources.
Definition: Title.php:127
JobQueueGroup\singleton
static singleton( $domain=false)
Definition: JobQueueGroup.php:70
Title\getCascadeProtectionSources
getCascadeProtectionSources( $getPages=true)
Cascading protection: Get the source of any cascading restrictions on this page.
Definition: Title.php:2692
$cache
$cache
Definition: mcc.php:33
$wgSemiprotectedRestrictionLevels
$wgSemiprotectedRestrictionLevels
Restriction levels that should be considered "semiprotected".
Definition: DefaultSettings.php:5345
Title\getRestrictionTypes
getRestrictionTypes()
Returns restriction types for the current Title.
Definition: Title.php:2466
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:2516
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:3496
Title\isRedirect
isRedirect( $flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
Definition: Title.php:3190
DeferredUpdates\PRESEND
const PRESEND
Definition: DeferredUpdates.php:69
Title\$mArticleID
int $mArticleID
Article ID, fetched from the link cache on demand.
Definition: Title.php:92
Title\isDeleted
isDeleted()
Is there a version of this page in the deletion archive?
Definition: Title.php:3111
Title\capitalize
static capitalize( $text, $ns=NS_MAIN)
Capitalize a text string for a title if it belongs to a namespace that capitalizes.
Definition: Title.php:3311
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:1335
Title\isSpecialPage
isSpecialPage()
Returns true if this is a special page.
Definition: Title.php:1244
MapCacheLRU\get
get( $key, $maxAge=INF, $default=null)
Get the value for a key.
Definition: MapCacheLRU.php:168
Title\purgeSquid
purgeSquid()
Purge all applicable CDN URLs.
Definition: Title.php:3574
Title\getPreviousRevisionID
getPreviousRevisionID( $revId, $flags=0)
Get the revision ID of the previous revision.
Definition: Title.php:3885
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:4582
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:4667
Title\getTouched
getTouched( $db=null)
Get the last touched timestamp.
Definition: Title.php:4365
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:5320
Title\getFragmentForURL
getFragmentForURL()
Get the fragment in URL form, including the "#" character if there is one.
Definition: Title.php:1761
Title\exists
exists( $flags=0)
Check if page exists.
Definition: Title.php:4132
NS_USER
const NS_USER
Definition: Defines.php:62
Title\isAlwaysKnown
isAlwaysKnown()
Should links to this title be shown as potentially viewable (i.e.
Definition: Title.php:4154
Title\secureAndSplit
secureAndSplit( $text, $defaultNamespace=null)
Secure and split - main initialisation function for this object.
Definition: Title.php:3336
Title\isDeletedQuick
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:3136
Title\getSubpageUrlForm
getSubpageUrlForm()
Get a URL-encoded form of the subpage text.
Definition: Title.php:2035
MapCacheLRU\clear
clear( $keys=null)
Clear one or several cache entries, or all cache entries.
Definition: MapCacheLRU.php:285
Title\isNewPage
isNewPage()
Check if this is a new page.
Definition: Title.php:3949
$wgRestrictionTypes
$wgRestrictionTypes
Set of available actions that can be restricted via action=protect You probably shouldn't change this...
Definition: DefaultSettings.php:5307
Title\setContentModel
setContentModel( $model)
Set a proposed content model for the page for permissions checking.
Definition: Title.php:1097
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:68
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:216
Title\compare
static compare(LinkTarget $a, LinkTarget $b)
Callback for usort() to do title sorts by (namespace, title)
Definition: Title.php:838
Title\countAuthorsBetween
countAuthorsBetween( $old, $new, $limit, $options=[])
Get the number of authors between the given revisions or revision IDs.
Definition: Title.php:4092
$t
$t
Definition: testCompression.php:71
Title\legalChars
static legalChars()
Get a regex character class describing the legal characters in a link.
Definition: Title.php:692
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:293
Title\isSiteJsConfigPage
isSiteJsConfigPage()
Is this a sitewide JS "config" page?
Definition: Title.php:1555
Title\invalidateCache
invalidateCache( $purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:4298
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:729
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:943
Title\getRestrictions
getRestrictions( $action)
Accessor/initialisation for mRestrictions.
Definition: Title.php:2791
CommentStore\getStore
static getStore()
Definition: CommentStore.php:139
Title\isContentPage
isContentPage()
Is this Title in a namespace which contains content? In other words, is this a content page,...
Definition: Title.php:1347
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
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:465
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
$wgVariantArticlePath
$wgVariantArticlePath
Like $wgArticlePath, but on multi-variant wikis, this provides a path format that describes which par...
Definition: DefaultSettings.php:3172
Title\getUserCaseDBKey
getUserCaseDBKey()
Same as getDBkey()
Definition: Title.php:1024
Title\isRawHtmlMessage
isRawHtmlMessage()
Is this a message which can contain raw HTML?
Definition: Title.php:1573
Title\getSelectFields
static getSelectFields()
Returns a list of fields that are to be selected for initializing Title objects or LinkCache entries.
Definition: Title.php:439
Title\hasSubpages
hasSubpages()
Does this have subpages? (Warning, usually requires an extra DB query.)
Definition: Title.php:3050
Title\getBaseText
getBaseText()
Get the base page name without a namespace, i.e.
Definition: Title.php:1947
Title\pageCond
pageCond()
Get an associative array for selecting this title from the "page" table.
Definition: Title.php:3847
Title\getText
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:996
Title\$mTextform
string $mTextform
Text form (spaces not underscores) of the main part.
Definition: Title.php:77
Wikimedia\Rdbms\IDatabase\delete
delete( $table, $conds, $fname=__METHOD__)
DELETE query wrapper.
Title\purgeExpiredRestrictions
static purgeExpiredRestrictions()
Purge expired restrictions from the page_restrictions table.
Definition: Title.php:3009
$wgInternalServer
$wgInternalServer
Internal server name as known to CDN, if different.
Definition: DefaultSettings.php:2763
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:1111
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:1147
Title\getUserPermissionsErrors
getUserPermissionsErrors( $action, $user, $rigor=PermissionManager::RIGOR_SECURE, $ignoreErrors=[])
Can $user perform $action on this page?
Definition: Title.php:2427
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:254
Title\getRelativeRevisionID
getRelativeRevisionID( $revId, $flags, $dir)
Get next/previous revision ID relative to another revision ID.
Definition: Title.php:3863
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:2138
Title\getRootTitle
getRootTitle()
Get the root page name title, i.e.
Definition: Title.php:1924
$type
$type
Definition: testCompression.php:50
Title\getLength
getLength( $flags=0)
What is the length of this page? Uses link cache, adding it if necessary.
Definition: Title.php:3215
Title\getAuthorsBetween
getAuthorsBetween( $old, $new, $limit, $options=[])
Get the authors between the given revisions or revision IDs.
Definition: Title.php:4050
Title\isWatchable
isWatchable()
Can this title be added to a user's watchlist?
Definition: Title.php:1233