MediaWiki  master
Title.php
Go to the documentation of this file.
1 <?php
36 use Wikimedia\Assert\Assert;
37 use Wikimedia\Assert\PreconditionException;
40 
51 
53  private static $titleCache = null;
54 
60  private const CACHE_MAX = 1000;
61 
67  public const GAID_FOR_UPDATE = 512;
68 
76  public const NEW_CLONE = 'clone';
77 
78  /***************************************************************************/
79  // region Private member variables
87  public $mTextform = '';
89  public $mUrlform = '';
91  public $mDbkeyform = '';
93  public $mNamespace = NS_MAIN;
95  public $mInterwiki = '';
97  private $mLocalInterwiki = false;
99  public $mFragment = '';
100 
102  public $mArticleID = -1;
103 
105  protected $mLatestID = false;
106 
111  private $mContentModel = false;
112 
117  private $mForcedContentModel = false;
118 
121 
123  public $mRestrictions = [];
124 
131  protected $mOldRestrictions = false;
132 
135 
138 
140  protected $mRestrictionsExpiry = [];
141 
144 
147 
149  public $mRestrictionsLoaded = false;
150 
159  public $prefixedText = null;
160 
163 
171 
173  protected $mLength = -1;
174 
176  public $mRedirect = null;
177 
179  private $mHasSubpages;
180 
182  private $mPageLanguage;
183 
187  private $mDbPageLanguage = false;
188 
190  private $mTitleValue = null;
191 
193  private $mIsBigDeletion = null;
194 
196  private $mIsValid = null;
197 
199  private $mInstanceCacheKey = null;
200 
201  // endregion -- end of private member variables
203  /***************************************************************************/
204 
210  private function getLanguageConverter( $language ) : ILanguageConverter {
211  return MediaWikiServices::getInstance()->getLanguageConverterFactory()
212  ->getLanguageConverter( $language );
213  }
214 
220  return $this->getLanguageConverter( $this->getPageLanguage() );
221  }
222 
231  private static function getTitleFormatter() {
232  return MediaWikiServices::getInstance()->getTitleFormatter();
233  }
234 
243  private static function getInterwikiLookup() {
244  return MediaWikiServices::getInstance()->getInterwikiLookup();
245  }
246 
247  private function __construct() {
248  }
249 
258  public static function newFromDBkey( $key ) {
259  $t = new self();
260 
261  try {
262  $t->secureAndSplit( $key );
263  return $t;
264  } catch ( MalformedTitleException $ex ) {
265  return null;
266  }
267  }
268 
282  public static function newFromTitleValue( TitleValue $titleValue, $forceClone = '' ) {
283  return self::newFromLinkTarget( $titleValue, $forceClone );
284  }
285 
297  public static function newFromLinkTarget( LinkTarget $linkTarget, $forceClone = '' ) {
298  if ( $linkTarget instanceof Title ) {
299  // Special case if it's already a Title object
300  if ( $forceClone === self::NEW_CLONE ) {
301  return clone $linkTarget;
302  } else {
303  return $linkTarget;
304  }
305  }
306  return self::makeTitle(
307  $linkTarget->getNamespace(),
308  $linkTarget->getText(),
309  $linkTarget->getFragment(),
310  $linkTarget->getInterwiki()
311  );
312  }
313 
321  public static function castFromLinkTarget( $linkTarget ) {
322  return $linkTarget ? self::newFromLinkTarget( $linkTarget ) : null;
323  }
324 
334  public static function castFromPageIdentity( ?PageIdentity $pageIdentity ) : ?Title {
335  return self::castFromPageReference( $pageIdentity );
336  }
337 
347  public static function castFromPageReference( ?PageReference $pageReference ) : ?Title {
348  if ( !$pageReference ) {
349  return null;
350  }
351 
352  if ( $pageReference instanceof Title ) {
353  return $pageReference;
354  }
355 
356  $pageReference->assertWiki( self::LOCAL );
357  $title = self::makeTitle( $pageReference->getNamespace(), $pageReference->getDBkey() );
358 
359  if ( $pageReference instanceof PageIdentity ) {
360  $title->resetArticleID( $pageReference->getId() );
361  }
362  return $title;
363  }
364 
385  public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
386  // DWIM: Integers can be passed in here when page titles are used as array keys.
387  if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) {
388  throw new InvalidArgumentException( '$text must be a string.' );
389  }
390  if ( $text === null ) {
391  return null;
392  }
393 
394  try {
395  return self::newFromTextThrow( (string)$text, (int)$defaultNamespace );
396  } catch ( MalformedTitleException $ex ) {
397  return null;
398  }
399  }
400 
420  public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
421  if ( is_object( $text ) ) {
422  throw new MWException( '$text must be a string, given an object' );
423  } elseif ( $text === null ) {
424  // Legacy code relies on MalformedTitleException being thrown in this case
425  // (happens when URL with no title in it is parsed). TODO fix
426  throw new MalformedTitleException( 'title-invalid-empty' );
427  }
428 
430 
431  // Wiki pages often contain multiple links to the same page.
432  // Title normalization and parsing can become expensive on pages with many
433  // links, so we can save a little time by caching them.
434  if ( $defaultNamespace === NS_MAIN ) {
435  $t = $titleCache->get( $text );
436  if ( $t ) {
437  return $t;
438  }
439  }
440 
441  // Convert things like &eacute; &#257; or &#x3017; into normalized (T16952) text
442  $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
443 
444  $t = new Title();
445  $dbKeyForm = strtr( $filteredText, ' ', '_' );
446 
447  $t->secureAndSplit( $dbKeyForm, (int)$defaultNamespace );
448  if ( $defaultNamespace === NS_MAIN ) {
449  $t->mInstanceCacheKey = $text;
450  $titleCache->set( $text, $t );
451  }
452  return $t;
453  }
454 
459  private function uncache() {
460  if ( $this->mInstanceCacheKey !== null ) {
462  $titleCache->clear( $this->mInstanceCacheKey );
463  $this->mInstanceCacheKey = null;
464  }
465  }
466 
482  public static function newFromURL( $url ) {
483  $t = new Title();
484 
485  # For compatibility with old buggy URLs. "+" is usually not valid in titles,
486  # but some URLs used it as a space replacement and they still come
487  # from some external search tools.
488  if ( strpos( self::legalChars(), '+' ) === false ) {
489  $url = strtr( $url, '+', ' ' );
490  }
491 
492  $dbKeyForm = strtr( $url, ' ', '_' );
493 
494  try {
495  $t->secureAndSplit( $dbKeyForm );
496  return $t;
497  } catch ( MalformedTitleException $ex ) {
498  return null;
499  }
500  }
501 
505  private static function getTitleCache() {
506  if ( self::$titleCache === null ) {
507  self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
508  }
509  return self::$titleCache;
510  }
511 
520  protected static function getSelectFields() {
521  return MediaWikiServices::getInstance()->getPageStore()->getSelectFields();
522  }
523 
531  public static function newFromID( $id, $flags = 0 ) {
532  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
533  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
534  $row = wfGetDB( $index )->selectRow(
535  'page',
536  self::getSelectFields(),
537  [ 'page_id' => $id ],
538  __METHOD__,
539  $options
540  );
541  if ( $row !== false ) {
542  $title = self::newFromRow( $row );
543  } else {
544  $title = null;
545  }
546 
547  return $title;
548  }
549 
556  public static function newFromIDs( $ids ) {
557  if ( !count( $ids ) ) {
558  return [];
559  }
560  $dbr = wfGetDB( DB_REPLICA );
561 
562  $res = $dbr->select(
563  'page',
564  self::getSelectFields(),
565  [ 'page_id' => $ids ],
566  __METHOD__
567  );
568 
569  $titles = [];
570  foreach ( $res as $row ) {
571  $titles[] = self::newFromRow( $row );
572  }
573  return $titles;
574  }
575 
582  public static function newFromRow( $row ) {
583  $t = self::makeTitle( $row->page_namespace, $row->page_title );
584  $t->loadFromRow( $row );
585  return $t;
586  }
587 
594  public function loadFromRow( $row ) {
595  if ( $row ) { // page found
596  if ( isset( $row->page_id ) ) {
597  $this->mArticleID = (int)$row->page_id;
598  }
599  if ( isset( $row->page_len ) ) {
600  $this->mLength = (int)$row->page_len;
601  }
602  if ( isset( $row->page_is_redirect ) ) {
603  $this->mRedirect = (bool)$row->page_is_redirect;
604  }
605  if ( isset( $row->page_latest ) ) {
606  $this->mLatestID = (int)$row->page_latest;
607  }
608  if ( isset( $row->page_content_model ) ) {
609  $this->lazyFillContentModel( $row->page_content_model );
610  } else {
611  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
612  }
613  if ( isset( $row->page_lang ) ) {
614  $this->mDbPageLanguage = (string)$row->page_lang;
615  }
616  if ( isset( $row->page_restrictions ) ) {
617  $this->mOldRestrictions = $row->page_restrictions;
618  }
619  } else { // page not found
620  $this->mArticleID = 0;
621  $this->mLength = 0;
622  $this->mRedirect = false;
623  $this->mLatestID = 0;
624  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
625  }
626  }
627 
650  public static function makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
651  $t = new Title();
652  $t->mInterwiki = $interwiki;
653  $t->mFragment = $fragment;
654  $t->mNamespace = $ns = (int)$ns;
655  $t->mDbkeyform = strtr( $title, ' ', '_' );
656  $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
657  $t->mUrlform = wfUrlencode( $t->mDbkeyform );
658  $t->mTextform = strtr( $title, '_', ' ' );
659  return $t;
660  }
661 
676  public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
677  // NOTE: ideally, this would just call makeTitle() and then isValid(),
678  // but presently, that means more overhead on a potential performance hotspot.
679 
680  if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) {
681  return null;
682  }
683 
684  $t = new Title();
685  $dbKeyForm = self::makeName( $ns, $title, $fragment, $interwiki, true );
686 
687  try {
688  $t->secureAndSplit( $dbKeyForm );
689  return $t;
690  } catch ( MalformedTitleException $ex ) {
691  return null;
692  }
693  }
694 
712  public static function newMainPage( MessageLocalizer $localizer = null ) {
713  if ( $localizer ) {
714  $msg = $localizer->msg( 'mainpage' );
715  } else {
716  $msg = wfMessage( 'mainpage' );
717  }
718 
719  $title = self::newFromText( $msg->inContentLanguage()->text() );
720 
721  // Every page renders at least one link to the Main Page (e.g. sidebar).
722  // If the localised value is invalid, don't produce fatal errors that
723  // would make the wiki inaccessible (and hard to fix the invalid message).
724  // Gracefully fallback...
725  if ( !$title ) {
726  $title = self::newFromText( 'Main Page' );
727  }
728  return $title;
729  }
730 
736  public static function legalChars() {
737  global $wgLegalTitleChars;
738  return $wgLegalTitleChars;
739  }
740 
750  public static function convertByteClassToUnicodeClass( $byteClass ) {
751  $length = strlen( $byteClass );
752  // Input token queue
753  $x0 = $x1 = $x2 = '';
754  // Decoded queue
755  $d0 = $d1 = '';
756  // Decoded integer codepoints
757  $ord0 = $ord1 = $ord2 = 0;
758  // Re-encoded queue
759  $r0 = $r1 = $r2 = '';
760  // Output
761  $out = '';
762  // Flags
763  $allowUnicode = false;
764  for ( $pos = 0; $pos < $length; $pos++ ) {
765  // Shift the queues down
766  $x2 = $x1;
767  $x1 = $x0;
768  $d1 = $d0;
769  $ord2 = $ord1;
770  $ord1 = $ord0;
771  $r2 = $r1;
772  $r1 = $r0;
773  // Load the current input token and decoded values
774  $inChar = $byteClass[$pos];
775  if ( $inChar === '\\' ) {
776  if ( preg_match( '/x([0-9a-fA-F]{2})/A', $byteClass, $m, 0, $pos + 1 ) ) {
777  $x0 = $inChar . $m[0];
778  $d0 = chr( hexdec( $m[1] ) );
779  $pos += strlen( $m[0] );
780  } elseif ( preg_match( '/[0-7]{3}/A', $byteClass, $m, 0, $pos + 1 ) ) {
781  $x0 = $inChar . $m[0];
782  $d0 = chr( octdec( $m[0] ) );
783  $pos += strlen( $m[0] );
784  } elseif ( $pos + 1 >= $length ) {
785  $x0 = $d0 = '\\';
786  } else {
787  $d0 = $byteClass[$pos + 1];
788  $x0 = $inChar . $d0;
789  $pos++;
790  }
791  } else {
792  $x0 = $d0 = $inChar;
793  }
794  $ord0 = ord( $d0 );
795  // Load the current re-encoded value
796  if ( $ord0 < 32 || $ord0 == 0x7f ) {
797  $r0 = sprintf( '\x%02x', $ord0 );
798  } elseif ( $ord0 >= 0x80 ) {
799  // Allow unicode if a single high-bit character appears
800  $r0 = sprintf( '\x%02x', $ord0 );
801  $allowUnicode = true;
802  // @phan-suppress-next-line PhanParamSuspiciousOrder false positive
803  } elseif ( strpos( '-\\[]^', $d0 ) !== false ) {
804  $r0 = '\\' . $d0;
805  } else {
806  $r0 = $d0;
807  }
808  // Do the output
809  if ( $x0 !== '' && $x1 === '-' && $x2 !== '' ) {
810  // Range
811  if ( $ord2 > $ord0 ) {
812  // Empty range
813  } elseif ( $ord0 >= 0x80 ) {
814  // Unicode range
815  $allowUnicode = true;
816  if ( $ord2 < 0x80 ) {
817  // Keep the non-unicode section of the range
818  $out .= "$r2-\\x7F";
819  }
820  } else {
821  // Normal range
822  $out .= "$r2-$r0";
823  }
824  // Reset state to the initial value
825  $x0 = $x1 = $d0 = $d1 = $r0 = $r1 = '';
826  } elseif ( $ord2 < 0x80 ) {
827  // ASCII character
828  $out .= $r2;
829  }
830  }
831  // @phan-suppress-next-line PhanSuspiciousValueComparison
832  if ( $ord1 < 0x80 ) {
833  $out .= $r1;
834  }
835  if ( $ord0 < 0x80 ) {
836  $out .= $r0;
837  }
838  if ( $allowUnicode ) {
839  $out .= '\u0080-\uFFFF';
840  }
841  return $out;
842  }
843 
855  public static function makeName( $ns, $title, $fragment = '', $interwiki = '',
856  $canonicalNamespace = false
857  ) {
858  if ( $canonicalNamespace ) {
859  $namespace = MediaWikiServices::getInstance()->getNamespaceInfo()->
860  getCanonicalName( $ns );
861  } else {
862  $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns );
863  }
864  $name = $namespace == '' ? $title : "$namespace:$title";
865  if ( strval( $interwiki ) != '' ) {
866  $name = "$interwiki:$name";
867  }
868  if ( strval( $fragment ) != '' ) {
869  $name .= '#' . $fragment;
870  }
871  return $name;
872  }
873 
882  public static function compare( $a, $b ) {
883  return $a->getNamespace() <=> $b->getNamespace()
884  ?: strcmp( $a->getDBkey(), $b->getDBkey() );
885  }
886 
903  public function isValid() {
904  if ( $this->mIsValid !== null ) {
905  return $this->mIsValid;
906  }
907 
908  try {
909  $text = $this->getFullText();
910  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
911 
912  '@phan-var MediaWikiTitleCodec $titleCodec';
913  $parts = $titleCodec->splitTitleString( $text, $this->mNamespace );
914 
915  // Check that nothing changed!
916  // This ensures that $text was already properly normalized.
917  if ( $parts['fragment'] !== $this->mFragment
918  || $parts['interwiki'] !== $this->mInterwiki
919  || $parts['local_interwiki'] !== $this->mLocalInterwiki
920  || $parts['namespace'] !== $this->mNamespace
921  || $parts['dbkey'] !== $this->mDbkeyform
922  ) {
923  $this->mIsValid = false;
924  return $this->mIsValid;
925  }
926  } catch ( MalformedTitleException $ex ) {
927  $this->mIsValid = false;
928  return $this->mIsValid;
929  }
930 
931  $this->mIsValid = true;
932  return $this->mIsValid;
933  }
934 
942  public function isLocal() {
943  if ( $this->isExternal() ) {
944  $iw = self::getInterwikiLookup()->fetch( $this->mInterwiki );
945  if ( $iw ) {
946  return $iw->isLocal();
947  }
948  }
949  return true;
950  }
951 
957  public function isExternal() {
958  return $this->mInterwiki !== '';
959  }
960 
968  public function getInterwiki() {
969  return $this->mInterwiki;
970  }
971 
977  public function wasLocalInterwiki() {
978  return $this->mLocalInterwiki;
979  }
980 
987  public function isTrans() {
988  if ( !$this->isExternal() ) {
989  return false;
990  }
991 
992  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable();
993  }
994 
1000  public function getTransWikiID() {
1001  if ( !$this->isExternal() ) {
1002  return false;
1003  }
1004 
1005  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID();
1006  }
1007 
1017  public function getTitleValue() {
1018  if ( $this->mTitleValue === null ) {
1019  try {
1020  $this->mTitleValue = new TitleValue(
1021  $this->mNamespace,
1022  $this->mDbkeyform,
1023  $this->mFragment,
1024  $this->mInterwiki
1025  );
1026  } catch ( InvalidArgumentException $ex ) {
1027  wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' .
1028  $this->getPrefixedText() . ']]: ' . $ex->getMessage() );
1029  }
1030  }
1031 
1032  return $this->mTitleValue;
1033  }
1034 
1040  public function getText() {
1041  return $this->mTextform;
1042  }
1043 
1049  public function getPartialURL() {
1050  return $this->mUrlform;
1051  }
1052 
1058  public function getDBkey(): string {
1059  return $this->mDbkeyform;
1060  }
1061 
1067  public function getNamespace(): int {
1068  return $this->mNamespace;
1069  }
1070 
1079  public function getContentModel( $flags = 0 ) {
1080  if ( $this->mForcedContentModel ) {
1081  if ( !$this->mContentModel ) {
1082  throw new RuntimeException( 'Got out of sync; an empty model is being forced' );
1083  }
1084  // Content model is locked to the currently loaded one
1085  return $this->mContentModel;
1086  }
1087 
1088  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
1089  $this->lazyFillContentModel( $this->loadFieldFromDB( 'page_content_model', $flags ) );
1090  } elseif (
1091  ( !$this->mContentModel || $flags & self::GAID_FOR_UPDATE ) &&
1092  $this->getArticleID( $flags )
1093  ) {
1094  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1095  $linkCache->addLinkObj( $this ); # in case we already had an article ID
1096  $this->lazyFillContentModel( $linkCache->getGoodLinkFieldObj( $this, 'model' ) );
1097  }
1098 
1099  if ( !$this->mContentModel ) {
1101  }
1102 
1103  return $this->mContentModel;
1104  }
1105 
1112  public function hasContentModel( $id ) {
1113  return $this->getContentModel() == $id;
1114  }
1115 
1132  public function setContentModel( $model ) {
1133  if ( (string)$model === '' ) {
1134  throw new InvalidArgumentException( "Missing CONTENT_MODEL_* constant" );
1135  }
1136 
1137  $this->uncache();
1138  $this->mContentModel = $model;
1139  $this->mForcedContentModel = true;
1140  }
1141 
1147  private function lazyFillContentModel( $model ) {
1148  if ( !$this->mForcedContentModel ) {
1149  $this->mContentModel = ( $model === false ) ? false : (string)$model;
1150  }
1151  }
1152 
1158  public function getNsText() {
1159  if ( $this->isExternal() ) {
1160  // This probably shouldn't even happen, except for interwiki transclusion.
1161  // If possible, use the canonical name for the foreign namespace.
1162  $nsText = MediaWikiServices::getInstance()->getNamespaceInfo()->
1163  getCanonicalName( $this->mNamespace );
1164  if ( $nsText !== false ) {
1165  return $nsText;
1166  }
1167  }
1168 
1169  try {
1170  $formatter = self::getTitleFormatter();
1171  return $formatter->getNamespaceName( $this->mNamespace, $this->mDbkeyform );
1172  } catch ( InvalidArgumentException $ex ) {
1173  wfDebug( __METHOD__ . ': ' . $ex->getMessage() );
1174  return false;
1175  }
1176  }
1177 
1183  public function getSubjectNsText() {
1184  $services = MediaWikiServices::getInstance();
1185  return $services->getContentLanguage()->
1186  getNsText( $services->getNamespaceInfo()->getSubject( $this->mNamespace ) );
1187  }
1188 
1194  public function getTalkNsText() {
1195  $services = MediaWikiServices::getInstance();
1196  return $services->getContentLanguage()->
1197  getNsText( $services->getNamespaceInfo()->getTalk( $this->mNamespace ) );
1198  }
1199 
1211  public function canHaveTalkPage() {
1212  return MediaWikiServices::getInstance()->getNamespaceInfo()->canHaveTalkPage( $this );
1213  }
1214 
1225  public function canExist(): bool {
1226  // NOTE: Don't use getArticleID(), we don't want to
1227  // trigger a database query here. This check is supposed to
1228  // act as an optimization, not add extra cost.
1229  if ( $this->mArticleID > 0 ) {
1230  // It exists, so it can exist.
1231  return true;
1232  }
1233 
1234  // NOTE: we call the relatively expensive isValid() method further down,
1235  // but we can bail out early if we already know the title is invalid.
1236  if ( $this->mIsValid === false ) {
1237  // It's invalid, so it can't exist.
1238  return false;
1239  }
1240 
1241  if ( $this->getNamespace() < NS_MAIN ) {
1242  // It's a special page, so it can't exist in the database.
1243  return false;
1244  }
1245 
1246  if ( $this->isExternal() ) {
1247  // If it's external, it's not local, so it can't exist.
1248  return false;
1249  }
1250 
1251  if ( $this->getText() === '' ) {
1252  // The title has no text, so it can't exist in the database.
1253  // It's probably an on-page section link, like "#something".
1254  return false;
1255  }
1256 
1257  // Double check that the title is valid.
1258  return $this->isValid();
1259  }
1260 
1271  public function isWatchable() {
1272  wfDeprecated( __METHOD__, '1.37' );
1273  $watchlistManager = MediaWikiServices::getInstance()->getWatchlistManager();
1274  return $watchlistManager->isWatchable( $this );
1275  }
1276 
1282  public function isSpecialPage() {
1283  return $this->mNamespace === NS_SPECIAL;
1284  }
1285 
1292  public function isSpecial( $name ) {
1293  if ( $this->isSpecialPage() ) {
1294  list( $thisName, /* $subpage */ ) =
1295  MediaWikiServices::getInstance()->getSpecialPageFactory()->
1296  resolveAlias( $this->mDbkeyform );
1297  if ( $name == $thisName ) {
1298  return true;
1299  }
1300  }
1301  return false;
1302  }
1303 
1310  public function fixSpecialName() {
1311  if ( $this->isSpecialPage() ) {
1312  $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory();
1313  list( $canonicalName, $par ) = $spFactory->resolveAlias( $this->mDbkeyform );
1314  if ( $canonicalName ) {
1315  $localName = $spFactory->getLocalNameFor( $canonicalName, $par );
1316  if ( $localName != $this->mDbkeyform ) {
1317  return self::makeTitle( NS_SPECIAL, $localName );
1318  }
1319  }
1320  }
1321  return $this;
1322  }
1323 
1334  public function inNamespace( $ns ) {
1335  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1336  equals( $this->mNamespace, $ns );
1337  }
1338 
1346  public function inNamespaces( ...$namespaces ) {
1347  if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) {
1348  $namespaces = $namespaces[0];
1349  }
1350 
1351  foreach ( $namespaces as $ns ) {
1352  if ( $this->inNamespace( $ns ) ) {
1353  return true;
1354  }
1355  }
1356 
1357  return false;
1358  }
1359 
1373  public function hasSubjectNamespace( $ns ) {
1374  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1375  subjectEquals( $this->mNamespace, $ns );
1376  }
1377 
1385  public function isContentPage() {
1386  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1387  isContent( $this->mNamespace );
1388  }
1389 
1396  public function isMovable() {
1397  if (
1398  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1399  isMovable( $this->mNamespace ) || $this->isExternal()
1400  ) {
1401  // Interwiki title or immovable namespace. Hooks don't get to override here
1402  return false;
1403  }
1404 
1405  $result = true;
1406  Hooks::runner()->onTitleIsMovable( $this, $result );
1407  return $result;
1408  }
1409 
1420  public function isMainPage() {
1421  return $this->equals( self::newMainPage() );
1422  }
1423 
1429  public function isSubpage() {
1430  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1431  hasSubpages( $this->mNamespace )
1432  ? strpos( $this->getText(), '/' ) !== false
1433  : false;
1434  }
1435 
1441  public function isConversionTable() {
1442  // @todo ConversionTable should become a separate content model.
1443 
1444  return $this->mNamespace === NS_MEDIAWIKI &&
1445  strpos( $this->getText(), 'Conversiontable/' ) === 0;
1446  }
1447 
1453  public function isWikitextPage() {
1454  return $this->hasContentModel( CONTENT_MODEL_WIKITEXT );
1455  }
1456 
1471  public function isSiteConfigPage() {
1472  return (
1473  $this->isSiteCssConfigPage()
1474  || $this->isSiteJsonConfigPage()
1475  || $this->isSiteJsConfigPage()
1476  );
1477  }
1478 
1485  public function isUserConfigPage() {
1486  return (
1487  $this->isUserCssConfigPage()
1488  || $this->isUserJsonConfigPage()
1489  || $this->isUserJsConfigPage()
1490  );
1491  }
1492 
1499  public function getSkinFromConfigSubpage() {
1500  $text = $this->getText();
1501  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
1502  if ( $lastSlashPos === false ) {
1503  return '';
1504  }
1505 
1506  $lastDot = strrpos( $text, '.', $lastSlashPos );
1507  if ( $lastDot === false ) {
1508  return '';
1509  }
1510 
1511  return substr( $text, $lastSlashPos + 1, $lastDot - $lastSlashPos - 1 );
1512  }
1513 
1520  public function isUserCssConfigPage() {
1521  return (
1522  $this->mNamespace === NS_USER
1523  && $this->isSubpage()
1524  && $this->hasContentModel( CONTENT_MODEL_CSS )
1525  );
1526  }
1527 
1534  public function isUserJsonConfigPage() {
1535  return (
1536  $this->mNamespace === NS_USER
1537  && $this->isSubpage()
1538  && $this->hasContentModel( CONTENT_MODEL_JSON )
1539  );
1540  }
1541 
1548  public function isUserJsConfigPage() {
1549  return (
1550  $this->mNamespace === NS_USER
1551  && $this->isSubpage()
1553  );
1554  }
1555 
1562  public function isSiteCssConfigPage() {
1563  return (
1564  $this->mNamespace === NS_MEDIAWIKI
1565  && (
1567  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1568  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1569  || substr( $this->mDbkeyform, -4 ) === '.css'
1570  )
1571  );
1572  }
1573 
1580  public function isSiteJsonConfigPage() {
1581  return (
1582  $this->mNamespace === NS_MEDIAWIKI
1583  && (
1585  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1586  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1587  || substr( $this->mDbkeyform, -5 ) === '.json'
1588  )
1589  );
1590  }
1591 
1598  public function isSiteJsConfigPage() {
1599  return (
1600  $this->mNamespace === NS_MEDIAWIKI
1601  && (
1603  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1604  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1605  || substr( $this->mDbkeyform, -3 ) === '.js'
1606  )
1607  );
1608  }
1609 
1616  public function isRawHtmlMessage() {
1617  global $wgRawHtmlMessages;
1618 
1619  if ( !$this->inNamespace( NS_MEDIAWIKI ) ) {
1620  return false;
1621  }
1622  $message = lcfirst( $this->getRootTitle()->getDBkey() );
1623  return in_array( $message, $wgRawHtmlMessages, true );
1624  }
1625 
1631  public function isTalkPage() {
1632  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1633  isTalk( $this->mNamespace );
1634  }
1635 
1647  public function getTalkPage() {
1648  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1649  // Instead of failing on invalid titles, let's just log the issue for now.
1650  // See the discussion on T227817.
1651 
1652  // Is this the same title?
1653  $talkNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $this->mNamespace );
1654  if ( $this->mNamespace == $talkNS ) {
1655  return $this;
1656  }
1657 
1658  $title = self::makeTitle( $talkNS, $this->mDbkeyform );
1659 
1660  $this->warnIfPageCannotExist( $title, __METHOD__ );
1661 
1662  return $title;
1663  // TODO: replace the above with the code below:
1664  // return self::castFromLinkTarget(
1665  // MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) );
1666  }
1667 
1677  public function getTalkPageIfDefined() {
1678  if ( !$this->canHaveTalkPage() ) {
1679  return null;
1680  }
1681 
1682  return $this->getTalkPage();
1683  }
1684 
1692  public function getSubjectPage() {
1693  // Is this the same title?
1694  $subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo()
1695  ->getSubject( $this->mNamespace );
1696  if ( $this->mNamespace == $subjectNS ) {
1697  return $this;
1698  }
1699  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1700  // Instead of failing on invalid titles, let's just log the issue for now.
1701  // See the discussion on T227817.
1702  $title = self::makeTitle( $subjectNS, $this->mDbkeyform );
1703 
1704  $this->warnIfPageCannotExist( $title, __METHOD__ );
1705 
1706  return $title;
1707  // TODO: replace the above with the code below:
1708  // return self::castFromLinkTarget(
1709  // MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
1710  }
1711 
1718  private function warnIfPageCannotExist( Title $title, $method ) {
1719  if ( $this->getText() == '' ) {
1720  wfLogWarning(
1721  $method . ': called on empty title ' . $this->getFullText() . ', returning '
1722  . $title->getFullText()
1723  );
1724 
1725  return true;
1726  }
1727 
1728  if ( $this->getInterwiki() !== '' ) {
1729  wfLogWarning(
1730  $method . ': called on interwiki title ' . $this->getFullText() . ', returning '
1731  . $title->getFullText()
1732  );
1733 
1734  return true;
1735  }
1736 
1737  return false;
1738  }
1739 
1749  public function getOtherPage() {
1750  // NOTE: Depend on the methods in this class instead of their equivalent in NamespaceInfo,
1751  // until their semantics has become exactly the same.
1752  // See the discussion on T227817.
1753  if ( $this->isSpecialPage() ) {
1754  throw new MWException( 'Special pages cannot have other pages' );
1755  }
1756  if ( $this->isTalkPage() ) {
1757  return $this->getSubjectPage();
1758  } else {
1759  if ( !$this->canHaveTalkPage() ) {
1760  throw new MWException( "{$this->getPrefixedText()} does not have an other page" );
1761  }
1762  return $this->getTalkPage();
1763  }
1764  // TODO: replace the above with the code below:
1765  // return self::castFromLinkTarget(
1766  // MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) );
1767  }
1768 
1774  public function getDefaultNamespace() {
1775  return $this->mDefaultNamespace;
1776  }
1777 
1785  public function getFragment() {
1786  return $this->mFragment;
1787  }
1788 
1795  public function hasFragment() {
1796  return $this->mFragment !== '';
1797  }
1798 
1804  public function getFragmentForURL() {
1805  if ( !$this->hasFragment() ) {
1806  return '';
1807  } elseif ( $this->isExternal() ) {
1808  // Note: If the interwiki is unknown, it's treated as a namespace on the local wiki,
1809  // so we treat it like a local interwiki.
1810  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
1811  if ( $interwiki && !$interwiki->isLocal() ) {
1812  return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment );
1813  }
1814  }
1815 
1816  return '#' . Sanitizer::escapeIdForLink( $this->mFragment );
1817  }
1818 
1829  public function setFragment( $fragment ) {
1830  $this->uncache();
1831  $this->mFragment = strtr( substr( $fragment, 1 ), '_', ' ' );
1832  }
1833 
1841  public function createFragmentTarget( $fragment ) {
1842  return self::makeTitle(
1843  $this->mNamespace,
1844  $this->getText(),
1845  $fragment,
1846  $this->mInterwiki
1847  );
1848  }
1849 
1857  private function prefix( $name ) {
1858  $p = '';
1859  if ( $this->isExternal() ) {
1860  $p = $this->mInterwiki . ':';
1861  }
1862 
1863  if ( $this->mNamespace != 0 ) {
1864  $nsText = $this->getNsText();
1865 
1866  if ( $nsText === false ) {
1867  // See T165149. Awkward, but better than erroneously linking to the main namespace.
1868  $nsText = MediaWikiServices::getInstance()->getContentLanguage()->
1869  getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
1870  }
1871 
1872  $p .= $nsText . ':';
1873  }
1874  return $p . $name;
1875  }
1876 
1883  public function getPrefixedDBkey() {
1884  $s = $this->prefix( $this->mDbkeyform );
1885  $s = strtr( $s, ' ', '_' );
1886  return $s;
1887  }
1888 
1895  public function getPrefixedText() {
1896  if ( $this->prefixedText === null ) {
1897  $s = $this->prefix( $this->mTextform );
1898  $s = strtr( $s, '_', ' ' );
1899  $this->prefixedText = $s;
1900  }
1901  return $this->prefixedText;
1902  }
1903 
1909  public function __toString(): string {
1910  return $this->getPrefixedText();
1911  }
1912 
1919  public function getFullText() {
1920  $text = $this->getPrefixedText();
1921  if ( $this->hasFragment() ) {
1922  $text .= '#' . $this->mFragment;
1923  }
1924  return $text;
1925  }
1926 
1941  private function findSubpageDivider( $text, $dir ) {
1942  if ( $dir > 0 ) {
1943  // Skip leading slashes, but keep the last one when there is nothing but slashes
1944  $bottom = strspn( $text, '/', 0, -1 );
1945  $idx = strpos( $text, '/', $bottom );
1946  } else {
1947  // Any slash from the end can be a divider, as subpage names can be empty
1948  $idx = strrpos( $text, '/' );
1949  }
1950 
1951  // The first character can never be a divider, as that would result in an empty base
1952  return $idx === 0 ? false : $idx;
1953  }
1954 
1959  private function hasSubpagesEnabled() {
1960  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1961  hasSubpages( $this->mNamespace );
1962  }
1963 
1979  public function getRootText() {
1980  $text = $this->getText();
1981  if ( !$this->hasSubpagesEnabled() ) {
1982  return $text;
1983  }
1984 
1985  $firstSlashPos = $this->findSubpageDivider( $text, +1 );
1986  // Don't discard the real title if there's no subpage involved
1987  if ( $firstSlashPos === false ) {
1988  return $text;
1989  }
1990 
1991  return substr( $text, 0, $firstSlashPos );
1992  }
1993 
2006  public function getRootTitle() {
2007  $title = self::makeTitleSafe( $this->mNamespace, $this->getRootText() );
2008  Assert::postcondition(
2009  $title !== null,
2010  'makeTitleSafe() should always return a Title for the text returned by getRootText().'
2011  );
2012  return $title;
2013  }
2014 
2029  public function getBaseText() {
2030  $text = $this->getText();
2031  if ( !$this->hasSubpagesEnabled() ) {
2032  return $text;
2033  }
2034 
2035  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
2036  // Don't discard the real title if there's no subpage involved
2037  if ( $lastSlashPos === false ) {
2038  return $text;
2039  }
2040 
2041  return substr( $text, 0, $lastSlashPos );
2042  }
2043 
2056  public function getBaseTitle() {
2057  $title = self::makeTitleSafe( $this->mNamespace, $this->getBaseText() );
2058  Assert::postcondition(
2059  $title !== null,
2060  'makeTitleSafe() should always return a Title for the text returned by getBaseText().'
2061  );
2062  return $title;
2063  }
2064 
2076  public function getSubpageText() {
2077  $text = $this->getText();
2078  if ( !$this->hasSubpagesEnabled() ) {
2079  return $text;
2080  }
2081 
2082  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
2083  if ( $lastSlashPos === false ) {
2084  // T256922 - Return the title text if no subpages
2085  return $text;
2086  }
2087  return substr( $text, $lastSlashPos + 1 );
2088  }
2089 
2103  public function getSubpage( $text ) {
2104  return self::makeTitleSafe(
2105  $this->mNamespace,
2106  $this->getText() . '/' . $text,
2107  '',
2108  $this->mInterwiki
2109  );
2110  }
2111 
2117  public function getSubpageUrlForm() {
2118  $text = $this->getSubpageText();
2119  $text = wfUrlencode( strtr( $text, ' ', '_' ) );
2120  return $text;
2121  }
2122 
2128  public function getPrefixedURL() {
2129  $s = $this->prefix( $this->mDbkeyform );
2130  $s = wfUrlencode( strtr( $s, ' ', '_' ) );
2131  return $s;
2132  }
2133 
2147  private static function fixUrlQueryArgs( $query, $query2 = false ) {
2148  if ( $query2 !== false ) {
2149  wfDeprecatedMsg( "Title::get{Canonical,Full,Link,Local,Internal}URL " .
2150  "method called with a second parameter is deprecated since MediaWiki 1.19. " .
2151  "Add your parameter to an array passed as the first parameter.", "1.19" );
2152  }
2153  if ( is_array( $query ) ) {
2154  $query = wfArrayToCgi( $query );
2155  }
2156  if ( $query2 ) {
2157  if ( is_string( $query2 ) ) {
2158  // $query2 is a string, we will consider this to be
2159  // a deprecated $variant argument and add it to the query
2160  $query2 = wfArrayToCgi( [ 'variant' => $query2 ] );
2161  } else {
2162  $query2 = wfArrayToCgi( $query2 );
2163  }
2164  // If we have $query content add a & to it first
2165  if ( $query ) {
2166  $query .= '&';
2167  }
2168  // Now append the queries together
2169  $query .= $query2;
2170  }
2171  return $query;
2172  }
2173 
2185  public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
2186  $query = self::fixUrlQueryArgs( $query, $query2 );
2187 
2188  # Hand off all the decisions on urls to getLocalURL
2189  $url = $this->getLocalURL( $query );
2190 
2191  # Expand the url to make it a full url. Note that getLocalURL has the
2192  # potential to output full urls for a variety of reasons, so we use
2193  # wfExpandUrl instead of simply prepending $wgServer
2194  $url = wfExpandUrl( $url, $proto );
2195 
2196  # Finally, add the fragment.
2197  $url .= $this->getFragmentForURL();
2198  Hooks::runner()->onGetFullURL( $this, $url, $query );
2199  return $url;
2200  }
2201 
2218  public function getFullUrlForRedirect( $query = '', $proto = PROTO_CURRENT ) {
2219  $target = $this;
2220  if ( $this->isExternal() ) {
2221  $target = SpecialPage::getTitleFor(
2222  'GoToInterwiki',
2223  $this->getPrefixedDBkey()
2224  );
2225  }
2226  return $target->getFullURL( $query, false, $proto );
2227  }
2228 
2252  public function getLocalURL( $query = '', $query2 = false ) {
2254 
2255  $query = self::fixUrlQueryArgs( $query, $query2 );
2256 
2257  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
2258  if ( $interwiki ) {
2259  $namespace = $this->getNsText();
2260  if ( $namespace != '' ) {
2261  # Can this actually happen? Interwikis shouldn't be parsed.
2262  # Yes! It can in interwiki transclusion. But... it probably shouldn't.
2263  $namespace .= ':';
2264  }
2265  $url = $interwiki->getURL( $namespace . $this->mDbkeyform );
2266  $url = wfAppendQuery( $url, $query );
2267  } else {
2268  $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
2269  if ( $query == '' ) {
2270  if ( $wgMainPageIsDomainRoot && $this->isMainPage() ) {
2271  $url = '/';
2272  } else {
2273  $url = str_replace( '$1', $dbkey, $wgArticlePath );
2274  }
2275  Hooks::runner()->onGetLocalURL__Article( $this, $url );
2276  } else {
2278  $url = false;
2279  $matches = [];
2280 
2282 
2283  if ( $articlePaths
2284  && preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
2285  ) {
2286  $action = urldecode( $matches[2] );
2287  if ( isset( $articlePaths[$action] ) ) {
2288  $query = $matches[1];
2289  if ( isset( $matches[4] ) ) {
2290  $query .= $matches[4];
2291  }
2292  $url = str_replace( '$1', $dbkey, $articlePaths[$action] );
2293  if ( $query != '' ) {
2294  $url = wfAppendQuery( $url, $query );
2295  }
2296  }
2297  }
2298 
2299  if ( $url === false
2301  && preg_match( '/^variant=([^&]*)$/', $query, $matches )
2302  && $this->getPageLanguage()->equals(
2303  MediaWikiServices::getInstance()->getContentLanguage() )
2304  && $this->getPageLanguageConverter()->hasVariants()
2305  ) {
2306  $variant = urldecode( $matches[1] );
2307  if ( $this->getPageLanguageConverter()->hasVariant( $variant ) ) {
2308  // Only do the variant replacement if the given variant is a valid
2309  // variant for the page's language.
2310  $url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath );
2311  $url = str_replace( '$1', $dbkey, $url );
2312  }
2313  }
2314 
2315  if ( $url === false ) {
2316  if ( $query == '-' ) {
2317  $query = '';
2318  }
2319  $url = "{$wgScript}?title={$dbkey}&{$query}";
2320  }
2321  }
2322  Hooks::runner()->onGetLocalURL__Internal( $this, $url, $query );
2323 
2324  // @todo FIXME: This causes breakage in various places when we
2325  // actually expected a local URL and end up with dupe prefixes.
2326  if ( $wgRequest->getVal( 'action' ) == 'render' ) {
2327  LoggerFactory::getInstance( 'T263581' )
2328  ->debug(
2329  "Title::getLocalURL called from render action",
2330  [
2331  'title' => $this->getPrefixedDBkey(),
2332  'exception' => new Exception()
2333  ]
2334  );
2335  $url = $wgServer . $url;
2336  }
2337  }
2338 
2339  Hooks::runner()->onGetLocalURL( $this, $url, $query );
2340  return $url;
2341  }
2342 
2360  public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
2361  if ( $this->isExternal() || $proto !== false ) {
2362  $ret = $this->getFullURL( $query, $query2, $proto );
2363  } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
2364  $ret = $this->getFragmentForURL();
2365  } else {
2366  $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
2367  }
2368  return $ret;
2369  }
2370 
2385  public function getInternalURL( $query = '', $query2 = false ) {
2386  global $wgInternalServer, $wgServer;
2387  $query = self::fixUrlQueryArgs( $query, $query2 );
2388  $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
2389  $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP );
2390  Hooks::runner()->onGetInternalURL( $this, $url, $query );
2391  return $url;
2392  }
2393 
2407  public function getCanonicalURL( $query = '', $query2 = false ) {
2408  $query = self::fixUrlQueryArgs( $query, $query2 );
2409  $url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL );
2410  Hooks::runner()->onGetCanonicalURL( $this, $url, $query );
2411  return $url;
2412  }
2413 
2419  public function getEditURL() {
2420  if ( $this->isExternal() ) {
2421  return '';
2422  }
2423  $s = $this->getLocalURL( 'action=edit' );
2424 
2425  return $s;
2426  }
2427 
2435  public static function getFilteredRestrictionTypes( $exists = true ) {
2436  global $wgRestrictionTypes;
2437  $types = $wgRestrictionTypes;
2438  if ( $exists ) {
2439  # Remove the create restriction for existing titles
2440  $types = array_diff( $types, [ 'create' ] );
2441  } else {
2442  # Only the create and upload restrictions apply to non-existing titles
2443  $types = array_intersect( $types, [ 'create', 'upload' ] );
2444  }
2445  return $types;
2446  }
2447 
2453  public function getRestrictionTypes() {
2454  if ( $this->isSpecialPage() ) {
2455  return [];
2456  }
2457 
2458  $types = self::getFilteredRestrictionTypes( $this->exists() );
2459 
2460  if ( $this->mNamespace !== NS_FILE ) {
2461  # Remove the upload restriction for non-file titles
2462  $types = array_diff( $types, [ 'upload' ] );
2463  }
2464 
2465  Hooks::runner()->onTitleGetRestrictionTypes( $this, $types );
2466 
2467  wfDebug( __METHOD__ . ': applicable restrictions to [[' .
2468  $this->getPrefixedText() . ']] are {' . implode( ',', $types ) . "}" );
2469 
2470  return $types;
2471  }
2472 
2480  public function getTitleProtection() {
2481  $protection = $this->getTitleProtectionInternal();
2482  if ( $protection ) {
2483  if ( $protection['permission'] == 'sysop' ) {
2484  $protection['permission'] = 'editprotected'; // B/C
2485  }
2486  if ( $protection['permission'] == 'autoconfirmed' ) {
2487  $protection['permission'] = 'editsemiprotected'; // B/C
2488  }
2489  }
2490  return $protection;
2491  }
2492 
2503  protected function getTitleProtectionInternal() {
2504  // Can't protect pages in special namespaces
2505  if ( $this->mNamespace < 0 ) {
2506  return false;
2507  }
2508 
2509  // Can't protect pages that exist.
2510  if ( $this->exists() ) {
2511  return false;
2512  }
2513 
2514  if ( $this->mTitleProtection === null ) {
2515  $dbr = wfGetDB( DB_REPLICA );
2516  $commentStore = CommentStore::getStore();
2517  $commentQuery = $commentStore->getJoin( 'pt_reason' );
2518  $res = $dbr->select(
2519  [ 'protected_titles' ] + $commentQuery['tables'],
2520  [
2521  'user' => 'pt_user',
2522  'expiry' => 'pt_expiry',
2523  'permission' => 'pt_create_perm'
2524  ] + $commentQuery['fields'],
2525  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2526  __METHOD__,
2527  [],
2528  $commentQuery['joins']
2529  );
2530 
2531  // fetchRow returns false if there are no rows.
2532  $row = $dbr->fetchRow( $res );
2533  if ( $row ) {
2534  $this->mTitleProtection = [
2535  'user' => $row['user'],
2536  'expiry' => $dbr->decodeExpiry( $row['expiry'] ),
2537  'permission' => $row['permission'],
2538  'reason' => $commentStore->getComment( 'pt_reason', $row )->text,
2539  ];
2540  } else {
2541  $this->mTitleProtection = false;
2542  }
2543  }
2544  return $this->mTitleProtection;
2545  }
2546 
2550  public function deleteTitleProtection() {
2551  $dbw = wfGetDB( DB_PRIMARY );
2552 
2553  $dbw->delete(
2554  'protected_titles',
2555  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2556  __METHOD__
2557  );
2558  $this->mTitleProtection = false;
2559  }
2560 
2568  public function isSemiProtected( $action = 'edit' ) {
2570 
2571  $restrictions = $this->getRestrictions( $action );
2573  if ( !$restrictions || !$semi ) {
2574  // Not protected, or all protection is full protection
2575  return false;
2576  }
2577 
2578  // Remap autoconfirmed to editsemiprotected for BC
2579  foreach ( array_keys( $semi, 'autoconfirmed' ) as $key ) {
2580  $semi[$key] = 'editsemiprotected';
2581  }
2582  foreach ( array_keys( $restrictions, 'autoconfirmed' ) as $key ) {
2583  $restrictions[$key] = 'editsemiprotected';
2584  }
2585 
2586  return !array_diff( $restrictions, $semi );
2587  }
2588 
2596  public function isProtected( $action = '' ) {
2597  global $wgRestrictionLevels;
2598 
2599  $restrictionTypes = $this->getRestrictionTypes();
2600 
2601  # Special pages have inherent protection
2602  if ( $this->isSpecialPage() ) {
2603  return true;
2604  }
2605 
2606  # Check regular protection levels
2607  foreach ( $restrictionTypes as $type ) {
2608  if ( $action == $type || $action == '' ) {
2609  $r = $this->getRestrictions( $type );
2610  foreach ( $wgRestrictionLevels as $level ) {
2611  if ( in_array( $level, $r ) && $level != '' ) {
2612  return true;
2613  }
2614  }
2615  }
2616  }
2617 
2618  return false;
2619  }
2620 
2629  public function isNamespaceProtected( User $user ) {
2630  global $wgNamespaceProtection;
2631 
2632  if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
2633  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2634  foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
2635  if ( !$permissionManager->userHasRight( $user, $right ) ) {
2636  return true;
2637  }
2638  }
2639  }
2640  return false;
2641  }
2642 
2648  public function isCascadeProtected() {
2649  list( $isCascadeProtected, ) = $this->getCascadeProtectionSources( false );
2650  return $isCascadeProtected;
2651  }
2652 
2662  public function areCascadeProtectionSourcesLoaded( $getPages = true ) {
2663  return $getPages ? $this->mCascadeSources !== null : $this->mHasCascadingRestrictions !== null;
2664  }
2665 
2679  public function getCascadeProtectionSources( $getPages = true ) {
2680  $pagerestrictions = [];
2681 
2682  if ( $this->mCascadeSources !== null && $getPages ) {
2684  } elseif ( $this->mHasCascadingRestrictions !== null && !$getPages ) {
2685  return [ $this->mHasCascadingRestrictions, $pagerestrictions ];
2686  }
2687 
2688  $dbr = wfGetDB( DB_REPLICA );
2689 
2690  if ( $this->mNamespace === NS_FILE ) {
2691  $tables = [ 'imagelinks', 'page_restrictions' ];
2692  $where_clauses = [
2693  'il_to' => $this->mDbkeyform,
2694  'il_from=pr_page',
2695  'pr_cascade' => 1
2696  ];
2697  } else {
2698  $tables = [ 'templatelinks', 'page_restrictions' ];
2699  $where_clauses = [
2700  'tl_namespace' => $this->mNamespace,
2701  'tl_title' => $this->mDbkeyform,
2702  'tl_from=pr_page',
2703  'pr_cascade' => 1
2704  ];
2705  }
2706 
2707  if ( $getPages ) {
2708  $cols = [ 'pr_page', 'page_namespace', 'page_title',
2709  'pr_expiry', 'pr_type', 'pr_level' ];
2710  $where_clauses[] = 'page_id=pr_page';
2711  $tables[] = 'page';
2712  } else {
2713  $cols = [ 'pr_expiry' ];
2714  }
2715 
2716  $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__ );
2717 
2718  $sources = $getPages ? [] : false;
2719  $now = wfTimestampNow();
2720 
2721  foreach ( $res as $row ) {
2722  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2723  if ( $expiry > $now ) {
2724  if ( $getPages ) {
2725  $page_id = $row->pr_page;
2726  $page_ns = $row->page_namespace;
2727  $page_title = $row->page_title;
2728  $sources[$page_id] = self::makeTitle( $page_ns, $page_title );
2729  # Add groups needed for each restriction type if its not already there
2730  # Make sure this restriction type still exists
2731 
2732  if ( !isset( $pagerestrictions[$row->pr_type] ) ) {
2733  $pagerestrictions[$row->pr_type] = [];
2734  }
2735 
2736  if (
2737  isset( $pagerestrictions[$row->pr_type] )
2738  && !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] )
2739  ) {
2740  $pagerestrictions[$row->pr_type][] = $row->pr_level;
2741  }
2742  } else {
2743  $sources = true;
2744  }
2745  }
2746  }
2747 
2748  if ( $getPages ) {
2749  $this->mCascadeSources = $sources;
2750  $this->mCascadingRestrictions = $pagerestrictions;
2751  } else {
2752  $this->mHasCascadingRestrictions = $sources;
2753  }
2754 
2755  return [ $sources, $pagerestrictions ];
2756  }
2757 
2765  public function areRestrictionsLoaded() {
2767  }
2768 
2778  public function getRestrictions( $action ) {
2779  if ( !$this->mRestrictionsLoaded ) {
2780  $this->loadRestrictions();
2781  }
2782  return $this->mRestrictions[$action] ?? [];
2783  }
2784 
2792  public function getAllRestrictions() {
2793  if ( !$this->mRestrictionsLoaded ) {
2794  $this->loadRestrictions();
2795  }
2796  return $this->mRestrictions;
2797  }
2798 
2806  public function getRestrictionExpiry( $action ) {
2807  if ( !$this->mRestrictionsLoaded ) {
2808  $this->loadRestrictions();
2809  }
2810  return $this->mRestrictionsExpiry[$action] ?? false;
2811  }
2812 
2818  public function areRestrictionsCascading() {
2819  if ( !$this->mRestrictionsLoaded ) {
2820  $this->loadRestrictions();
2821  }
2822 
2824  }
2825 
2837  public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
2838  // This function will only read rows from a table that we migrated away
2839  // from before adding READ_LATEST support to loadRestrictions, so we
2840  // don't need to support reading from DB_PRIMARY here.
2841  $dbr = wfGetDB( DB_REPLICA );
2842 
2843  $restrictionTypes = $this->getRestrictionTypes();
2844 
2845  foreach ( $restrictionTypes as $type ) {
2846  $this->mRestrictions[$type] = [];
2847  $this->mRestrictionsExpiry[$type] = 'infinity';
2848  }
2849 
2850  $this->mCascadeRestriction = false;
2851 
2852  # Backwards-compatibility: also load the restrictions from the page record (old format).
2853  if ( $oldFashionedRestrictions !== null ) {
2854  $this->mOldRestrictions = $oldFashionedRestrictions;
2855  }
2856 
2857  if ( $this->mOldRestrictions === false ) {
2858  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2859  $linkCache->addLinkObj( $this ); # in case we already had an article ID
2860  $this->mOldRestrictions = $linkCache->getGoodLinkFieldObj( $this, 'restrictions' );
2861  }
2862 
2863  if ( $this->mOldRestrictions != '' ) {
2864  foreach ( explode( ':', trim( $this->mOldRestrictions ) ) as $restrict ) {
2865  $temp = explode( '=', trim( $restrict ) );
2866  if ( count( $temp ) == 1 ) {
2867  // old old format should be treated as edit/move restriction
2868  $this->mRestrictions['edit'] = explode( ',', trim( $temp[0] ) );
2869  $this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) );
2870  } else {
2871  $restriction = trim( $temp[1] );
2872  if ( $restriction != '' ) { // some old entries are empty
2873  $this->mRestrictions[$temp[0]] = explode( ',', $restriction );
2874  }
2875  }
2876  }
2877  }
2878 
2879  if ( count( $rows ) ) {
2880  # Current system - load second to make them override.
2881  $now = wfTimestampNow();
2882 
2883  # Cycle through all the restrictions.
2884  foreach ( $rows as $row ) {
2885  // Don't take care of restrictions types that aren't allowed
2886  if ( !in_array( $row->pr_type, $restrictionTypes ) ) {
2887  continue;
2888  }
2889 
2890  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2891 
2892  // Only apply the restrictions if they haven't expired!
2893  if ( !$expiry || $expiry > $now ) {
2894  $this->mRestrictionsExpiry[$row->pr_type] = $expiry;
2895  $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) );
2896 
2897  $this->mCascadeRestriction = $this->mCascadeRestriction || $row->pr_cascade;
2898  }
2899  }
2900  }
2901 
2902  $this->mRestrictionsLoaded = true;
2903  }
2904 
2915  public function loadRestrictions( $oldFashionedRestrictions = null, $flags = 0 ) {
2916  $readLatest = DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST );
2917  if ( $this->mRestrictionsLoaded && !$readLatest ) {
2918  return;
2919  }
2920 
2921  $id = $this->getArticleID( $flags );
2922  if ( $id ) {
2923  $fname = __METHOD__;
2924  $loadRestrictionsFromDb = static function ( IDatabase $dbr ) use ( $fname, $id ) {
2925  return iterator_to_array(
2926  $dbr->select(
2927  'page_restrictions',
2928  [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
2929  [ 'pr_page' => $id ],
2930  $fname
2931  )
2932  );
2933  };
2934 
2935  if ( $readLatest ) {
2936  $dbr = wfGetDB( DB_PRIMARY );
2937  $rows = $loadRestrictionsFromDb( $dbr );
2938  } else {
2939  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
2940  $rows = $cache->getWithSetCallback(
2941  // Page protections always leave a new null revision
2942  $cache->makeKey( 'page-restrictions', 'v1', $id, $this->getLatestRevID() ),
2943  $cache::TTL_DAY,
2944  static function ( $curValue, &$ttl, array &$setOpts ) use ( $loadRestrictionsFromDb ) {
2945  $dbr = wfGetDB( DB_REPLICA );
2946 
2947  $setOpts += Database::getCacheSetOptions( $dbr );
2948  $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
2949  if ( $lb->hasOrMadeRecentMasterChanges() ) {
2950  // @TODO: cleanup Title cache and caller assumption mess in general
2951  $ttl = WANObjectCache::TTL_UNCACHEABLE;
2952  }
2953 
2954  return $loadRestrictionsFromDb( $dbr );
2955  }
2956  );
2957  }
2958 
2959  $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
2960  } else {
2961  $title_protection = $this->getTitleProtectionInternal();
2962 
2963  if ( $title_protection ) {
2964  $now = wfTimestampNow();
2965  $expiry = wfGetDB( DB_REPLICA )->decodeExpiry( $title_protection['expiry'] );
2966 
2967  if ( !$expiry || $expiry > $now ) {
2968  // Apply the restrictions
2969  $this->mRestrictionsExpiry['create'] = $expiry;
2970  $this->mRestrictions['create'] =
2971  explode( ',', trim( $title_protection['permission'] ) );
2972  } else { // Get rid of the old restrictions
2973  $this->mTitleProtection = false;
2974  }
2975  } else {
2976  $this->mRestrictionsExpiry['create'] = 'infinity';
2977  }
2978  $this->mRestrictionsLoaded = true;
2979  }
2980  }
2981 
2986  public function flushRestrictions() {
2987  $this->mRestrictionsLoaded = false;
2988  $this->mTitleProtection = null;
2989  }
2990 
2996  public static function purgeExpiredRestrictions() {
2997  if ( wfReadOnly() ) {
2998  return;
2999  }
3000 
3002  wfGetDB( DB_PRIMARY ),
3003  __METHOD__,
3004  static function ( IDatabase $dbw, $fname ) {
3005  $config = MediaWikiServices::getInstance()->getMainConfig();
3006  $ids = $dbw->selectFieldValues(
3007  'page_restrictions',
3008  'pr_id',
3009  [ 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3010  $fname,
3011  [ 'LIMIT' => $config->get( 'UpdateRowsPerQuery' ) ] // T135470
3012  );
3013  if ( $ids ) {
3014  $dbw->delete( 'page_restrictions', [ 'pr_id' => $ids ], $fname );
3015  }
3016  }
3017  ) );
3018 
3020  wfGetDB( DB_PRIMARY ),
3021  __METHOD__,
3022  static function ( IDatabase $dbw, $fname ) {
3023  $dbw->delete(
3024  'protected_titles',
3025  [ 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3026  $fname
3027  );
3028  }
3029  ) );
3030  }
3031 
3037  public function hasSubpages() {
3038  if (
3039  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3040  hasSubpages( $this->mNamespace )
3041  ) {
3042  # Duh
3043  return false;
3044  }
3045 
3046  # We dynamically add a member variable for the purpose of this method
3047  # alone to cache the result. There's no point in having it hanging
3048  # around uninitialized in every Title object; therefore we only add it
3049  # if needed and don't declare it statically.
3050  if ( $this->mHasSubpages === null ) {
3051  $this->mHasSubpages = false;
3052  $subpages = $this->getSubpages( 1 );
3053  if ( $subpages instanceof TitleArray ) {
3054  $this->mHasSubpages = (bool)$subpages->current();
3055  }
3056  }
3057 
3058  return $this->mHasSubpages;
3059  }
3060 
3068  public function getSubpages( $limit = -1 ) {
3069  if (
3070  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3071  hasSubpages( $this->mNamespace )
3072  ) {
3073  return [];
3074  }
3075 
3076  $options = [];
3077  if ( $limit > -1 ) {
3078  $options['LIMIT'] = $limit;
3079  }
3080 
3081  $pageStore = MediaWikiServices::getInstance()->getPageStore();
3082  $query = $pageStore->newSelectQueryBuilder()
3083  ->fields( $pageStore->getSelectFields() )
3084  ->whereTitlePrefix( $this->getNamespace(), $this->getDBkey() . '/' )
3085  ->options( $options )
3086  ->caller( __METHOD__ );
3087 
3088  return TitleArray::newFromResult( $query->fetchResultSet() );
3089  }
3090 
3097  public function isDeleted() {
3098  return $this->getDeletedEditsCount();
3099  }
3100 
3107  public function getDeletedEditsCount() {
3108  if ( $this->mNamespace < 0 ) {
3109  $n = 0;
3110  } else {
3111  $dbr = wfGetDB( DB_REPLICA );
3112 
3113  $n = $dbr->selectField( 'archive', 'COUNT(*)',
3114  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3115  __METHOD__
3116  );
3117  if ( $this->mNamespace === NS_FILE ) {
3118  $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
3119  [ 'fa_name' => $this->mDbkeyform ],
3120  __METHOD__
3121  );
3122  }
3123  }
3124  return (int)$n;
3125  }
3126 
3133  public function isDeletedQuick() {
3134  return $this->hasDeletedEdits();
3135  }
3136 
3143  public function hasDeletedEdits() {
3144  if ( $this->mNamespace < 0 ) {
3145  return false;
3146  }
3147  $dbr = wfGetDB( DB_REPLICA );
3148  $deleted = (bool)$dbr->selectField( 'archive', '1',
3149  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3150  __METHOD__
3151  );
3152  if ( !$deleted && $this->mNamespace === NS_FILE ) {
3153  $deleted = (bool)$dbr->selectField( 'filearchive', '1',
3154  [ 'fa_name' => $this->mDbkeyform ],
3155  __METHOD__
3156  );
3157  }
3158  return $deleted;
3159  }
3160 
3168  public function getArticleID( $flags = 0 ) {
3169  if ( $this->mNamespace < 0 ) {
3170  $this->mArticleID = 0;
3171 
3172  return $this->mArticleID;
3173  }
3174 
3175  if ( $flags & self::GAID_FOR_UPDATE ) {
3176  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3177  $oldUpdate = $linkCache->forUpdate( true );
3178  $linkCache->clearLink( $this );
3179  $this->mArticleID = $linkCache->addLinkObj( $this );
3180  $linkCache->forUpdate( $oldUpdate );
3181  } elseif ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3182  // If mArticleID is >0, pageCond() will use it, making it impossible
3183  // for the call below to return a different result, e.g. after a
3184  // page move.
3185  $this->mArticleID = -1;
3186  $this->mArticleID = (int)$this->loadFieldFromDB( 'page_id', $flags );
3187  } elseif ( $this->mArticleID == -1 ) {
3188  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3189  $this->mArticleID = $linkCache->addLinkObj( $this );
3190  }
3191 
3192  return $this->mArticleID;
3193  }
3194 
3209  public function isRedirect( $flags = 0 ) {
3210  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3211  $this->mRedirect = (bool)$this->loadFieldFromDB( 'page_is_redirect', $flags );
3212  } elseif ( $this->mRedirect === null ) {
3213  if ( $this->getArticleID( $flags ) ) {
3214  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3215  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3216  // Note that LinkCache returns null if it thinks the page does not exist;
3217  // always trust the state of LinkCache over that of this Title instance.
3218  $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
3219  } else {
3220  $this->mRedirect = false;
3221  }
3222  }
3223 
3224  return $this->mRedirect;
3225  }
3226 
3234  public function getLength( $flags = 0 ) {
3235  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3236  $this->mLength = (int)$this->loadFieldFromDB( 'page_len', $flags );
3237  } else {
3238  if ( $this->mLength != -1 ) {
3239  return $this->mLength;
3240  } elseif ( !$this->getArticleID( $flags ) ) {
3241  $this->mLength = 0;
3242  return $this->mLength;
3243  }
3244 
3245  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3246  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3247  // Note that LinkCache returns null if it thinks the page does not exist;
3248  // always trust the state of LinkCache over that of this Title instance.
3249  $this->mLength = (int)$linkCache->getGoodLinkFieldObj( $this, 'length' );
3250  }
3251 
3252  return $this->mLength;
3253  }
3254 
3261  public function getLatestRevID( $flags = 0 ) {
3262  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3263  $this->mLatestID = (int)$this->loadFieldFromDB( 'page_latest', $flags );
3264  } else {
3265  if ( $this->mLatestID !== false ) {
3266  return (int)$this->mLatestID;
3267  } elseif ( !$this->getArticleID( $flags ) ) {
3268  $this->mLatestID = 0;
3269 
3270  return $this->mLatestID;
3271  }
3272 
3273  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3274  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3275  // Note that LinkCache returns null if it thinks the page does not exist;
3276  // always trust the state of LinkCache over that of this Title instance.
3277  $this->mLatestID = (int)$linkCache->getGoodLinkFieldObj( $this, 'revision' );
3278  }
3279 
3280  return $this->mLatestID;
3281  }
3282 
3296  public function resetArticleID( $id ) {
3297  if ( $id === false ) {
3298  $this->mArticleID = -1;
3299  } else {
3300  $this->mArticleID = (int)$id;
3301  }
3302  $this->mRestrictionsLoaded = false;
3303  $this->mRestrictions = [];
3304  $this->mOldRestrictions = false;
3305  $this->mRedirect = null;
3306  $this->mLength = -1;
3307  $this->mLatestID = false;
3308  $this->mContentModel = false;
3309  $this->mForcedContentModel = false;
3310  $this->mEstimateRevisions = null;
3311  $this->mPageLanguage = null;
3312  $this->mDbPageLanguage = false;
3313  $this->mIsBigDeletion = null;
3314 
3315  MediaWikiServices::getInstance()->getLinkCache()->clearLink( $this );
3316  }
3317 
3318  public static function clearCaches() {
3319  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3320  $linkCache->clear();
3321 
3323  $titleCache->clear();
3324  }
3325 
3333  public static function capitalize( $text, $ns = NS_MAIN ) {
3334  $services = MediaWikiServices::getInstance();
3335  if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) {
3336  return $services->getContentLanguage()->ucfirst( $text );
3337  } else {
3338  return $text;
3339  }
3340  }
3341 
3358  private function secureAndSplit( $text, $defaultNamespace = null ) {
3359  if ( $defaultNamespace === null ) {
3360  $defaultNamespace = $this->mDefaultNamespace;
3361  }
3362 
3363  // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
3364  // the parsing code with Title, while avoiding massive refactoring.
3365  // @todo: get rid of secureAndSplit, refactor parsing code.
3366  // @note: getTitleParser() returns a TitleParser implementation which does not have a
3367  // splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
3369  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
3370  '@phan-var MediaWikiTitleCodec $titleCodec';
3371  // MalformedTitleException can be thrown here
3372  $parts = $titleCodec->splitTitleString( $text, $defaultNamespace );
3373 
3374  # Fill fields
3375  $this->setFragment( '#' . $parts['fragment'] );
3376  $this->mInterwiki = $parts['interwiki'];
3377  $this->mLocalInterwiki = $parts['local_interwiki'];
3378  $this->mNamespace = $parts['namespace'];
3379  $this->mDefaultNamespace = $defaultNamespace;
3380 
3381  $this->mDbkeyform = $parts['dbkey'];
3382  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
3383  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
3384 
3385  // splitTitleString() guarantees that this title is valid.
3386  $this->mIsValid = true;
3387 
3388  # We already know that some pages won't be in the database!
3389  if ( $this->isExternal() || $this->isSpecialPage() || $this->mTextform === '' ) {
3390  $this->mArticleID = 0;
3391  }
3392  }
3393 
3406  public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3407  if ( count( $options ) > 0 ) {
3408  $db = wfGetDB( DB_PRIMARY );
3409  } else {
3410  $db = wfGetDB( DB_REPLICA );
3411  }
3412 
3413  $res = $db->select(
3414  [ 'page', $table ],
3415  self::getSelectFields(),
3416  [
3417  "{$prefix}_from=page_id",
3418  "{$prefix}_namespace" => $this->mNamespace,
3419  "{$prefix}_title" => $this->mDbkeyform ],
3420  __METHOD__,
3421  $options
3422  );
3423 
3424  $retVal = [];
3425  if ( $res->numRows() ) {
3426  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3427  foreach ( $res as $row ) {
3428  $titleObj = self::makeTitle( $row->page_namespace, $row->page_title );
3429  if ( $titleObj ) {
3430  $linkCache->addGoodLinkObjFromRow( $titleObj, $row );
3431  $retVal[] = $titleObj;
3432  }
3433  }
3434  }
3435  return $retVal;
3436  }
3437 
3448  public function getTemplateLinksTo( $options = [] ) {
3449  return $this->getLinksTo( $options, 'templatelinks', 'tl' );
3450  }
3451 
3464  public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3465  $id = $this->getArticleID();
3466 
3467  # If the page doesn't exist; there can't be any link from this page
3468  if ( !$id ) {
3469  return [];
3470  }
3471 
3472  $db = wfGetDB( DB_REPLICA );
3473 
3474  $blNamespace = "{$prefix}_namespace";
3475  $blTitle = "{$prefix}_title";
3476 
3477  $pageQuery = WikiPage::getQueryInfo();
3478  $res = $db->select(
3479  [ $table, 'nestpage' => $pageQuery['tables'] ],
3480  array_merge(
3481  [ $blNamespace, $blTitle ],
3482  $pageQuery['fields']
3483  ),
3484  [ "{$prefix}_from" => $id ],
3485  __METHOD__,
3486  $options,
3487  [ 'nestpage' => [
3488  'LEFT JOIN',
3489  [ "page_namespace=$blNamespace", "page_title=$blTitle" ]
3490  ] ] + $pageQuery['joins']
3491  );
3492 
3493  $retVal = [];
3494  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3495  foreach ( $res as $row ) {
3496  if ( $row->page_id ) {
3497  $titleObj = self::newFromRow( $row );
3498  } else {
3499  $titleObj = self::makeTitle( $row->$blNamespace, $row->$blTitle );
3500  $linkCache->addBadLinkObj( $titleObj );
3501  }
3502  $retVal[] = $titleObj;
3503  }
3504 
3505  return $retVal;
3506  }
3507 
3518  public function getTemplateLinksFrom( $options = [] ) {
3519  return $this->getLinksFrom( $options, 'templatelinks', 'tl' );
3520  }
3521 
3530  public function getBrokenLinksFrom() {
3531  if ( $this->getArticleID() == 0 ) {
3532  # All links from article ID 0 are false positives
3533  return [];
3534  }
3535 
3536  $dbr = wfGetDB( DB_REPLICA );
3537  $res = $dbr->select(
3538  [ 'page', 'pagelinks' ],
3539  [ 'pl_namespace', 'pl_title' ],
3540  [
3541  'pl_from' => $this->getArticleID(),
3542  'page_namespace IS NULL'
3543  ],
3544  __METHOD__, [],
3545  [
3546  'page' => [
3547  'LEFT JOIN',
3548  [ 'pl_namespace=page_namespace', 'pl_title=page_title' ]
3549  ]
3550  ]
3551  );
3552 
3553  $retVal = [];
3554  foreach ( $res as $row ) {
3555  $retVal[] = self::makeTitle( $row->pl_namespace, $row->pl_title );
3556  }
3557  return $retVal;
3558  }
3559 
3566  public function getCdnUrls() {
3567  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3568  return $htmlCache->getUrls( $this );
3569  }
3570 
3575  public function purgeSquid() {
3576  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3577  $htmlCache->purgeTitleUrls( $this, $htmlCache::PURGE_INTENT_TXROUND_REFLECTED );
3578  }
3579 
3587  public function isSingleRevRedirect() {
3588  $dbw = wfGetDB( DB_PRIMARY );
3589  $dbw->startAtomic( __METHOD__ );
3590 
3591  $row = $dbw->selectRow(
3592  'page',
3593  self::getSelectFields(),
3594  $this->pageCond(),
3595  __METHOD__,
3596  [ 'FOR UPDATE' ]
3597  );
3598  // Update the cached fields
3599  $this->loadFromRow( $row );
3600 
3601  if ( $this->mRedirect && $this->mLatestID ) {
3602  $isSingleRevRedirect = !$dbw->selectField(
3603  'revision',
3604  '1',
3605  [ 'rev_page' => $this->mArticleID, 'rev_id != ' . (int)$this->mLatestID ],
3606  __METHOD__,
3607  [ 'FOR UPDATE' ]
3608  );
3609  } else {
3610  $isSingleRevRedirect = false;
3611  }
3612 
3613  $dbw->endAtomic( __METHOD__ );
3614 
3615  return $isSingleRevRedirect;
3616  }
3617 
3625  public function getParentCategories() {
3626  $data = [];
3627 
3628  $titleKey = $this->getArticleID();
3629 
3630  if ( $titleKey === 0 ) {
3631  return $data;
3632  }
3633 
3634  $dbr = wfGetDB( DB_REPLICA );
3635 
3636  $res = $dbr->select(
3637  'categorylinks',
3638  'cl_to',
3639  [ 'cl_from' => $titleKey ],
3640  __METHOD__
3641  );
3642 
3643  if ( $res->numRows() > 0 ) {
3644  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
3645  foreach ( $res as $row ) {
3646  // $data[] = Title::newFromText( $contLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
3647  $data[$contLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] =
3648  $this->getFullText();
3649  }
3650  }
3651  return $data;
3652  }
3653 
3660  public function getParentCategoryTree( $children = [] ) {
3661  $stack = [];
3662  $parents = $this->getParentCategories();
3663 
3664  if ( $parents ) {
3665  foreach ( $parents as $parent => $current ) {
3666  if ( array_key_exists( $parent, $children ) ) {
3667  # Circular reference
3668  $stack[$parent] = [];
3669  } else {
3670  $nt = self::newFromText( $parent );
3671  if ( $nt ) {
3672  $stack[$parent] = $nt->getParentCategoryTree( $children + [ $parent => 1 ] );
3673  }
3674  }
3675  }
3676  }
3677 
3678  return $stack;
3679  }
3680 
3687  public function pageCond() {
3688  if ( $this->mArticleID > 0 ) {
3689  // PK avoids secondary lookups in InnoDB, shouldn't hurt other DBs
3690  return [ 'page_id' => $this->mArticleID ];
3691  } else {
3692  return [ 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform ];
3693  }
3694  }
3695 
3703  private function getRelativeRevisionID( $revId, $flags, $dir ) {
3704  $rl = MediaWikiServices::getInstance()->getRevisionLookup();
3705  $rev = $rl->getRevisionById( $revId, $flags );
3706  if ( !$rev ) {
3707  return false;
3708  }
3709 
3710  $oldRev = ( $dir === 'next' )
3711  ? $rl->getNextRevision( $rev, $flags )
3712  : $rl->getPreviousRevision( $rev, $flags );
3713 
3714  return $oldRev ? $oldRev->getId() : false;
3715  }
3716 
3722  public function isNewPage() {
3723  $dbr = wfGetDB( DB_REPLICA );
3724  return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ );
3725  }
3726 
3732  public function isBigDeletion() {
3733  global $wgDeleteRevisionsLimit;
3734 
3735  if ( !$wgDeleteRevisionsLimit ) {
3736  return false;
3737  }
3738 
3739  if ( $this->mIsBigDeletion === null ) {
3740  $dbr = wfGetDB( DB_REPLICA );
3741 
3742  $revCount = $dbr->selectRowCount(
3743  'revision',
3744  '1',
3745  [ 'rev_page' => $this->getArticleID() ],
3746  __METHOD__,
3747  [ 'LIMIT' => $wgDeleteRevisionsLimit + 1 ]
3748  );
3749 
3750  $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit;
3751  }
3752 
3753  return $this->mIsBigDeletion;
3754  }
3755 
3761  public function estimateRevisionCount() {
3762  if ( !$this->exists() ) {
3763  return 0;
3764  }
3765 
3766  if ( $this->mEstimateRevisions === null ) {
3767  $dbr = wfGetDB( DB_REPLICA );
3768  $this->mEstimateRevisions = $dbr->estimateRowCount( 'revision', '*',
3769  [ 'rev_page' => $this->getArticleID() ], __METHOD__ );
3770  }
3771 
3773  }
3774 
3789  public function equals( object $other ) {
3790  if ( $other instanceof Title ) {
3791  // NOTE: In contrast to isSameLinkAs(), this ignores the fragment part!
3792  // NOTE: In contrast to isSamePageAs(), this ignores the page ID!
3793  // NOTE: === is necessary for proper matching of number-like titles
3794  return $this->getInterwiki() === $other->getInterwiki()
3795  && $this->getNamespace() === $other->getNamespace()
3796  && $this->getDBkey() === $other->getDBkey();
3797  } else {
3798  return false;
3799  }
3800  }
3801 
3809  public function isSameLinkAs( LinkTarget $other ) {
3810  // NOTE: keep in sync with TitleValue::isSameLinkAs()!
3811  // NOTE: === is needed for number-like titles
3812  return ( $other->getInterwiki() === $this->getInterwiki() )
3813  && ( $other->getDBkey() === $this->getDBkey() )
3814  && ( $other->getNamespace() === $this->getNamespace() )
3815  && ( $other->getFragment() === $this->getFragment() );
3816  }
3817 
3825  public function isSamePageAs( PageReference $other ): bool {
3826  // NOTE: keep in sync with PageIdentityValue::isSamePageAs()!
3827 
3828  if ( $other->getWikiId() !== $this->getWikiId() ) {
3829  return false;
3830  }
3831 
3832  if ( $other->getNamespace() !== $this->getNamespace()
3833  || $other->getDBkey() !== $this->getDBkey() ) {
3834  return false;
3835  }
3836 
3837  return true;
3838  }
3839 
3846  public function isSubpageOf( Title $title ) {
3847  return $this->mInterwiki === $title->mInterwiki
3848  && $this->mNamespace == $title->mNamespace
3849  && strpos( $this->mDbkeyform, $title->mDbkeyform . '/' ) === 0;
3850  }
3851 
3862  public function exists( $flags = 0 ): bool {
3863  $exists = $this->getArticleID( $flags ) != 0;
3864  Hooks::runner()->onTitleExists( $this, $exists );
3865  return $exists;
3866  }
3867 
3884  public function isAlwaysKnown() {
3885  $isKnown = null;
3886 
3897  Hooks::runner()->onTitleIsAlwaysKnown( $this, $isKnown );
3898 
3899  if ( $isKnown !== null ) {
3900  return $isKnown;
3901  }
3902 
3903  if ( $this->isExternal() ) {
3904  return true; // any interwiki link might be viewable, for all we know
3905  }
3906 
3907  $services = MediaWikiServices::getInstance();
3908  switch ( $this->mNamespace ) {
3909  case NS_MEDIA:
3910  case NS_FILE:
3911  // file exists, possibly in a foreign repo
3912  return (bool)$services->getRepoGroup()->findFile( $this );
3913  case NS_SPECIAL:
3914  // valid special page
3915  return $services->getSpecialPageFactory()->exists( $this->mDbkeyform );
3916  case NS_MAIN:
3917  // selflink, possibly with fragment
3918  return $this->mDbkeyform == '';
3919  case NS_MEDIAWIKI:
3920  // known system message
3921  return $this->hasSourceText() !== false;
3922  default:
3923  return false;
3924  }
3925  }
3926 
3938  public function isKnown() {
3939  return $this->isAlwaysKnown() || $this->exists();
3940  }
3941 
3947  public function hasSourceText() {
3948  if ( $this->exists() ) {
3949  return true;
3950  }
3951 
3952  if ( $this->mNamespace === NS_MEDIAWIKI ) {
3953  $services = MediaWikiServices::getInstance();
3954  // If the page doesn't exist but is a known system message, default
3955  // message content will be displayed, same for language subpages-
3956  // Use always content language to avoid loading hundreds of languages
3957  // to get the link color.
3958  $contLang = $services->getContentLanguage();
3959  list( $name, ) = $services->getMessageCache()->figureMessage(
3960  $contLang->lcfirst( $this->getText() )
3961  );
3962  $message = wfMessage( $name )->inLanguage( $contLang )->useDatabase( false );
3963  return $message->exists();
3964  }
3965 
3966  return false;
3967  }
3968 
4006  public function getDefaultMessageText() {
4007  if ( $this->mNamespace !== NS_MEDIAWIKI ) { // Just in case
4008  return false;
4009  }
4010 
4011  list( $name, $lang ) = MediaWikiServices::getInstance()->getMessageCache()->figureMessage(
4012  MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $this->getText() )
4013  );
4014  $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
4015 
4016  if ( $message->exists() ) {
4017  return $message->plain();
4018  } else {
4019  return false;
4020  }
4021  }
4022 
4029  public function invalidateCache( $purgeTime = null ) {
4030  if ( wfReadOnly() ) {
4031  return false;
4032  }
4033  if ( $this->mArticleID === 0 ) {
4034  // avoid gap locking if we know it's not there
4035  return true;
4036  }
4037 
4038  $conds = $this->pageCond();
4040  new AutoCommitUpdate(
4041  wfGetDB( DB_PRIMARY ),
4042  __METHOD__,
4043  function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) {
4044  $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
4045  $dbw->update(
4046  'page',
4047  [ 'page_touched' => $dbTimestamp ],
4048  $conds + [ 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ],
4049  $fname
4050  );
4051 
4052  MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $this );
4053 
4055  $this, null, null, $dbw->getDomainID() );
4056  }
4057  ),
4058  DeferredUpdates::PRESEND
4059  );
4060 
4061  return true;
4062  }
4063 
4069  public function touchLinks() {
4070  $jobs = [];
4072  $this,
4073  'pagelinks',
4074  [ 'causeAction' => 'page-touch' ]
4075  );
4076  if ( $this->mNamespace === NS_CATEGORY ) {
4078  $this,
4079  'categorylinks',
4080  [ 'causeAction' => 'category-touch' ]
4081  );
4082  }
4083 
4084  JobQueueGroup::singleton()->lazyPush( $jobs );
4085  }
4086 
4093  public function getTouched( $db = null ) {
4094  if ( $db === null ) {
4095  $db = wfGetDB( DB_REPLICA );
4096  }
4097  $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ );
4098  return $touched;
4099  }
4100 
4109  public function getNotificationTimestamp( User $user ) {
4110  return MediaWikiServices::getInstance()
4111  ->getWatchlistManager()
4112  ->getTitleNotificationTimestamp( $user, $this );
4113  }
4114 
4121  public function getNamespaceKey( $prepend = 'nstab-' ) {
4122  // Gets the subject namespace of this title
4123  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
4124  $subjectNS = $nsInfo->getSubject( $this->mNamespace );
4125  // Prefer canonical namespace name for HTML IDs
4126  $namespaceKey = $nsInfo->getCanonicalName( $subjectNS );
4127  if ( $namespaceKey === false ) {
4128  // Fallback to localised text
4129  $namespaceKey = $this->getSubjectNsText();
4130  }
4131  // Makes namespace key lowercase
4132  $namespaceKey = MediaWikiServices::getInstance()->getContentLanguage()->lc( $namespaceKey );
4133  // Uses main
4134  if ( $namespaceKey == '' ) {
4135  $namespaceKey = 'main';
4136  }
4137  // Changes file to image for backwards compatibility
4138  if ( $namespaceKey == 'file' ) {
4139  $namespaceKey = 'image';
4140  }
4141  return $prepend . $namespaceKey;
4142  }
4143 
4150  public function getRedirectsHere( $ns = null ) {
4151  $redirs = [];
4152 
4153  $dbr = wfGetDB( DB_REPLICA );
4154  $where = [
4155  'rd_namespace' => $this->mNamespace,
4156  'rd_title' => $this->mDbkeyform,
4157  'rd_from = page_id'
4158  ];
4159  if ( $this->isExternal() ) {
4160  $where['rd_interwiki'] = $this->mInterwiki;
4161  } else {
4162  $where[] = 'rd_interwiki = ' . $dbr->addQuotes( '' ) . ' OR rd_interwiki IS NULL';
4163  }
4164  if ( $ns !== null ) {
4165  $where['page_namespace'] = $ns;
4166  }
4167 
4168  $res = $dbr->select(
4169  [ 'redirect', 'page' ],
4170  [ 'page_namespace', 'page_title' ],
4171  $where,
4172  __METHOD__
4173  );
4174 
4175  foreach ( $res as $row ) {
4176  $redirs[] = self::newFromRow( $row );
4177  }
4178  return $redirs;
4179  }
4180 
4186  public function isValidRedirectTarget() {
4188 
4189  if ( $this->isSpecialPage() ) {
4190  // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
4191  if ( $this->isSpecial( 'Userlogout' ) ) {
4192  return false;
4193  }
4194 
4195  foreach ( $wgInvalidRedirectTargets as $target ) {
4196  if ( $this->isSpecial( $target ) ) {
4197  return false;
4198  }
4199  }
4200 
4201  return true;
4202  } elseif ( $this->getDBkey() === '' ) {
4203  // relative section links are not valid redirect targets (T278367)
4204  return false;
4205  }
4206 
4207  return $this->isValid();
4208  }
4209 
4215  public function getBacklinkCache() {
4216  return BacklinkCache::get( $this );
4217  }
4218 
4224  public function canUseNoindex() {
4226 
4227  $bannedNamespaces = $wgExemptFromUserRobotsControl ??
4228  MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
4229 
4230  return !in_array( $this->mNamespace, $bannedNamespaces );
4231  }
4232 
4243  public function getCategorySortkey( $prefix = '' ) {
4244  $unprefixed = $this->getText();
4245 
4246  // Anything that uses this hook should only depend
4247  // on the Title object passed in, and should probably
4248  // tell the users to run updateCollations.php --force
4249  // in order to re-sort existing category relations.
4250  Hooks::runner()->onGetDefaultSortkey( $this, $unprefixed );
4251  if ( $prefix !== '' ) {
4252  # Separate with a line feed, so the unprefixed part is only used as
4253  # a tiebreaker when two pages have the exact same prefix.
4254  # In UCA, tab is the only character that can sort above LF
4255  # so we strip both of them from the original prefix.
4256  $prefix = strtr( $prefix, "\n\t", ' ' );
4257  return "$prefix\n$unprefixed";
4258  }
4259  return $unprefixed;
4260  }
4261 
4269  private function getDbPageLanguageCode() {
4270  global $wgPageLanguageUseDB;
4271 
4272  // check, if the page language could be saved in the database, and if so and
4273  // the value is not requested already, lookup the page language using LinkCache
4274  if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) {
4275  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
4276  $linkCache->addLinkObj( $this );
4277  $this->mDbPageLanguage = $linkCache->getGoodLinkFieldObj( $this, 'lang' );
4278  }
4279 
4280  return $this->mDbPageLanguage;
4281  }
4282 
4291  public function getPageLanguage() {
4292  global $wgLang, $wgLanguageCode;
4293  if ( $this->isSpecialPage() ) {
4294  // special pages are in the user language
4295  return $wgLang;
4296  }
4297 
4298  // Checking if DB language is set
4299  $dbPageLanguage = $this->getDbPageLanguageCode();
4300  if ( $dbPageLanguage ) {
4301  return wfGetLangObj( $dbPageLanguage );
4302  }
4303 
4304  if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) {
4305  // Note that this may depend on user settings, so the cache should
4306  // be only per-request.
4307  // NOTE: ContentHandler::getPageLanguage() may need to load the
4308  // content to determine the page language!
4309  // Checking $wgLanguageCode hasn't changed for the benefit of unit
4310  // tests.
4311  $contentHandler = MediaWikiServices::getInstance()
4312  ->getContentHandlerFactory()
4313  ->getContentHandler( $this->getContentModel() );
4314  $langObj = $contentHandler->getPageLanguage( $this );
4315  $this->mPageLanguage = [ $langObj->getCode(), $wgLanguageCode ];
4316  } else {
4317  $langObj = MediaWikiServices::getInstance()->getLanguageFactory()
4318  ->getLanguage( $this->mPageLanguage[0] );
4319  }
4320 
4321  return $langObj;
4322  }
4323 
4332  public function getPageViewLanguage() {
4333  global $wgLang;
4334 
4335  if ( $this->isSpecialPage() ) {
4336  // If the user chooses a variant, the content is actually
4337  // in a language whose code is the variant code.
4338  $variant = $this->getLanguageConverter( $wgLang )->getPreferredVariant();
4339  if ( $wgLang->getCode() !== $variant ) {
4340  return MediaWikiServices::getInstance()->getLanguageFactory()
4341  ->getLanguage( $variant );
4342  }
4343 
4344  return $wgLang;
4345  }
4346 
4347  // Checking if DB language is set
4348  $dbPageLanguage = $this->getDbPageLanguageCode();
4349  if ( $dbPageLanguage ) {
4350  $pageLang = wfGetLangObj( $dbPageLanguage );
4351  $variant = $this->getLanguageConverter( $pageLang )->getPreferredVariant();
4352  if ( $pageLang->getCode() !== $variant ) {
4353  $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()
4354  ->getLanguage( $variant );
4355  }
4356 
4357  return $pageLang;
4358  }
4359 
4360  // @note Can't be cached persistently, depends on user settings.
4361  // @note ContentHandler::getPageViewLanguage() may need to load the
4362  // content to determine the page language!
4363  $contentHandler = MediaWikiServices::getInstance()
4364  ->getContentHandlerFactory()
4365  ->getContentHandler( $this->getContentModel() );
4366  $pageLang = $contentHandler->getPageViewLanguage( $this );
4367  return $pageLang;
4368  }
4369 
4380  public function getEditNotices( $oldid = 0 ) {
4381  $notices = [];
4382 
4383  // Optional notice for the entire namespace
4384  $editnotice_ns = 'editnotice-' . $this->mNamespace;
4385  $msg = wfMessage( $editnotice_ns );
4386  if ( $msg->exists() ) {
4387  $html = $msg->parseAsBlock();
4388  // Edit notices may have complex logic, but output nothing (T91715)
4389  if ( trim( $html ) !== '' ) {
4390  $notices[$editnotice_ns] = Html::rawElement(
4391  'div',
4392  [ 'class' => [
4393  'mw-editnotice',
4394  'mw-editnotice-namespace',
4395  Sanitizer::escapeClass( "mw-$editnotice_ns" )
4396  ] ],
4397  $html
4398  );
4399  }
4400  }
4401 
4402  if (
4403  MediaWikiServices::getInstance()->getNamespaceInfo()->
4404  hasSubpages( $this->mNamespace )
4405  ) {
4406  // Optional notice for page itself and any parent page
4407  $editnotice_base = $editnotice_ns;
4408  foreach ( explode( '/', $this->mDbkeyform ) as $part ) {
4409  $editnotice_base .= '-' . $part;
4410  $msg = wfMessage( $editnotice_base );
4411  if ( $msg->exists() ) {
4412  $html = $msg->parseAsBlock();
4413  if ( trim( $html ) !== '' ) {
4414  $notices[$editnotice_base] = Html::rawElement(
4415  'div',
4416  [ 'class' => [
4417  'mw-editnotice',
4418  'mw-editnotice-base',
4419  Sanitizer::escapeClass( "mw-$editnotice_base" )
4420  ] ],
4421  $html
4422  );
4423  }
4424  }
4425  }
4426  } else {
4427  // Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
4428  $editnoticeText = $editnotice_ns . '-' . strtr( $this->mDbkeyform, '/', '-' );
4429  $msg = wfMessage( $editnoticeText );
4430  if ( $msg->exists() ) {
4431  $html = $msg->parseAsBlock();
4432  if ( trim( $html ) !== '' ) {
4433  $notices[$editnoticeText] = Html::rawElement(
4434  'div',
4435  [ 'class' => [
4436  'mw-editnotice',
4437  'mw-editnotice-page',
4438  Sanitizer::escapeClass( "mw-$editnoticeText" )
4439  ] ],
4440  $html
4441  );
4442  }
4443  }
4444  }
4445 
4446  Hooks::runner()->onTitleGetEditNotices( $this, $oldid, $notices );
4447  return $notices;
4448  }
4449 
4455  private function loadFieldFromDB( $field, $flags ) {
4456  if ( !in_array( $field, self::getSelectFields(), true ) ) {
4457  return false; // field does not exist
4458  }
4459 
4460  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
4461  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
4462 
4463  return wfGetDB( $index )->selectField(
4464  'page',
4465  $field,
4466  $this->pageCond(),
4467  __METHOD__,
4468  $options
4469  );
4470  }
4471 
4475  public function __sleep() {
4476  return [
4477  'mNamespace',
4478  'mDbkeyform',
4479  'mFragment',
4480  'mInterwiki',
4481  'mLocalInterwiki',
4482  'mDefaultNamespace',
4483  ];
4484  }
4485 
4486  public function __wakeup() {
4487  $this->mArticleID = ( $this->mNamespace >= 0 ) ? -1 : 0;
4488  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
4489  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
4490  }
4491 
4492  public function __clone() {
4493  $this->mInstanceCacheKey = null;
4494  }
4495 
4505  public function getWikiId() {
4506  return self::LOCAL;
4507  }
4508 
4525  public function getId( $wikiId = self::LOCAL ): int {
4526  $this->assertWiki( $wikiId );
4527  $this->assertProperPage();
4528  return $this->getArticleID();
4529  }
4530 
4543  private function assertProperPage() {
4544  Assert::precondition(
4545  $this->canExist(),
4546  'This Title instance does not represent a proper page, but merely a link target.'
4547  );
4548  }
4549 
4562  public function toPageIdentity() : ProperPageIdentity {
4563  // TODO: replace individual member fields with a PageIdentityValue that is always present
4564 
4565  $this->assertProperPage();
4566 
4567  return new PageIdentityValue(
4568  $this->getId(),
4569  $this->getNamespace(),
4570  $this->getDBkey(),
4571  self::LOCAL
4572  );
4573  }
4574 
4589  public function toPageRecord( $flags = 0 ): ExistingPageRecord {
4590  // TODO: Cache this? Construct is more efficiently?
4591 
4592  $this->assertProperPage();
4593 
4594  Assert::precondition(
4595  $this->exists(),
4596  'This Title instance does not represent an existing page: ' . $this
4597  );
4598 
4599  return new PageStoreRecord(
4600  (object)[
4601  'page_id' => $this->getArticleID( $flags ),
4602  'page_namespace' => $this->getNamespace(),
4603  'page_title' => $this->getDBkey(),
4604  'page_wiki_id' => $this->getWikiId(),
4605  'page_latest' => $this->getLatestRevID( $flags ),
4606  'page_is_new' => $this->isNewPage(), // no flags?
4607  'page_is_redirect' => $this->isRedirect( $flags ),
4608  'page_touched' => $this->getTouched(), // no flags?
4609  'page_lang' => $this->getDbPageLanguageCode() ?: null,
4610  ],
4611  PageIdentity::LOCAL
4612  );
4613  }
4614 
4615 }
Title\$mLocalInterwiki
bool $mLocalInterwiki
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:97
Title\$mRestrictions
array $mRestrictions
Array of groups allowed to edit this article.
Definition: Title.php:123
Title\canHaveTalkPage
canHaveTalkPage()
Can this title have a corresponding talk page?
Definition: Title.php:1211
Title\getTitleProtection
getTitleProtection()
Is this title subject to title protection? Title protection is the one applied against creation of su...
Definition: Title.php:2480
Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition: PageIdentity.php:64
Title\canUseNoindex
canUseNoindex()
Whether the magic words INDEX and NOINDEX function for this page.
Definition: Title.php:4224
Title\getLocalURL
getLocalURL( $query='', $query2=false)
Get a URL with no fragment or server name (relative URL) from a Title object.
Definition: Title.php:2252
Title\isSemiProtected
isSemiProtected( $action='edit')
Is this page "semi-protected" - the only protection levels are listed in $wgSemiprotectedRestrictionL...
Definition: Title.php:2568
MediaWiki\DAO\WikiAwareEntityTrait
trait WikiAwareEntityTrait
Definition: WikiAwareEntityTrait.php:32
Title\$mHasCascadingRestrictions
bool $mHasCascadingRestrictions
Are cascading restrictions in effect on this page?
Definition: Title.php:143
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:52
Title\isNamespaceProtected
isNamespaceProtected(User $user)
Determines if $user is unable to edit this page because it has been protected by $wgNamespaceProtecti...
Definition: Title.php:2629
Title\getTalkNsText
getTalkNsText()
Get the namespace text of the talk page.
Definition: Title.php:1194
Title\getSubpageText
getSubpageText()
Get the lowest-level subpage name, i.e.
Definition: Title.php:2076
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:385
Title\isBigDeletion
isBigDeletion()
Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit.
Definition: Title.php:3732
Title\areCascadeProtectionSourcesLoaded
areCascadeProtectionSourcesLoaded( $getPages=true)
Determines whether cascading protection sources have already been loaded from the database.
Definition: Title.php:2662
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:2435
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:855
Title\getInternalURL
getInternalURL( $query='', $query2=false)
Get the URL form for an internal link.
Definition: Title.php:2385
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
Title\getFragment
getFragment()
Get the Title fragment (i.e.
Definition: Title.php:1785
$wgExemptFromUserRobotsControl
$wgExemptFromUserRobotsControl
An array of namespace keys in which the INDEX/__NOINDEX__ magic words will not function,...
Definition: DefaultSettings.php:9238
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:1677
Title\inNamespace
inNamespace( $ns)
Returns true if the title is inside the specified namespace.
Definition: Title.php:1334
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:117
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:1396
Title\wasLocalInterwiki
wasLocalInterwiki()
Was this a local interwiki link?
Definition: Title.php:977
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:180
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
Title\inNamespaces
inNamespaces(... $namespaces)
Returns true if the title is inside one of the specified namespaces.
Definition: Title.php:1346
Title\isWikitextPage
isWikitextPage()
Does that page contain wikitext, or it is JS, CSS or whatever?
Definition: Title.php:1453
Title\isUserCssConfigPage
isUserCssConfigPage()
Is this a CSS "config" sub-page of a user page?
Definition: Title.php:1520
Title\getBacklinkCache
getBacklinkCache()
Get a backlink cache object.
Definition: Title.php:4215
Title\getPartialURL
getPartialURL()
Get the URL-encoded form of the main part.
Definition: Title.php:1049
$wgLegalTitleChars
$wgLegalTitleChars
Allowed title characters – regex character class Don't change this unless you know what you're doing.
Definition: DefaultSettings.php:4609
Title\clearCaches
static clearCaches()
Definition: Title.php:3318
AutoCommitUpdate
Deferrable Update for closure/callback updates that should use auto-commit mode.
Definition: AutoCommitUpdate.php:9
Title\getTitleValue
getTitleValue()
Get a TitleValue object representing this Title.
Definition: Title.php:1017
Title\estimateRevisionCount
estimateRevisionCount()
Get the approximate revision count of this page.
Definition: Title.php:3761
Title\getPrefixedDBkey
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1883
Title\getDbPageLanguageCode
getDbPageLanguageCode()
Returns the page language code saved in the database, if $wgPageLanguageUseDB is set to true in Local...
Definition: Title.php:4269
Title\getSkinFromConfigSubpage
getSkinFromConfigSubpage()
Trim down a .css, .json, or .js subpage title to get the corresponding skin name.
Definition: Title.php:1499
$wgScript
$wgScript
The URL path to index.php.
Definition: DefaultSettings.php:204
Title\$mHasSubpages
bool $mHasSubpages
Whether a page has any subpages.
Definition: Title.php:179
Title\getTalkPage
getTalkPage()
Get a Title object associated with the talk page of this article.
Definition: Title.php:1647
Title\NEW_CLONE
const NEW_CLONE
Flag for use with factory methods like newFromLinkTarget() that have a $forceClone parameter.
Definition: Title.php:76
Title\getParentCategoryTree
getParentCategoryTree( $children=[])
Get a tree of parent categories.
Definition: Title.php:3660
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:2147
Title\fixSpecialName
fixSpecialName()
If the Title refers to a special page alias which is not the local default, resolve the alias,...
Definition: Title.php:1310
Title\getInterwikiLookup
static getInterwikiLookup()
B/C kludge: provide an InterwikiLookup for use by Title.
Definition: Title.php:243
Title\isUserJsConfigPage
isUserJsConfigPage()
Is this a JS "config" sub-page of a user page?
Definition: Title.php:1548
Title\touchLinks
touchLinks()
Update page_touched timestamps and send CDN purge messages for pages linking to this title.
Definition: Title.php:4069
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:292
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1895
Title\getTransWikiID
getTransWikiID()
Returns the DB name of the distant wiki which owns the object.
Definition: Title.php:1000
DeferredUpdates\addUpdate
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the pending update queue for execution at the appropriate time.
Definition: DeferredUpdates.php:119
Title\getArticleID
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:3168
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:2360
Title\$mTitleValue
TitleValue null $mTitleValue
A corresponding TitleValue object.
Definition: Title.php:190
Title\isTalkPage
isTalkPage()
Is this a talk page of some sort?
Definition: Title.php:1631
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1099
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1182
Sanitizer\decodeCharReferencesAndNormalize
static decodeCharReferencesAndNormalize( $text)
Decode any character references, numeric or named entities, in the next and normalize the resulting s...
Definition: Sanitizer.php:1245
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:107
Sanitizer\escapeClass
static escapeClass( $class)
Given a value, escape it so that it can be used as a CSS class and return it.
Definition: Sanitizer.php:972
Title\getNotificationTimestamp
getNotificationTimestamp(User $user)
Get the timestamp when this page was updated since the user last saw it.
Definition: Title.php:4109
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1056
Title\isExternal
isExternal()
Is this Title interwiki?
Definition: Title.php:957
DBAccessObjectUtils\getDBOptions
static getDBOptions( $bitfield)
Get an appropriate DB index, options, and fallback DB index for a query.
Definition: DBAccessObjectUtils.php:52
Title\$mInstanceCacheKey
string null $mInstanceCacheKey
The key of this instance in the internal Title instance cache.
Definition: Title.php:199
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:2837
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:712
Title\getDefaultMessageText
getDefaultMessageText()
Get the default (plain) message contents for an page that overrides an interface message key.
Definition: Title.php:4006
Title\hasSourceText
hasSourceText()
Does this page have source text?
Definition: Title.php:3947
Title\loadFromRow
loadFromRow( $row)
Load Title object fields from a DB row.
Definition: Title.php:594
Title\setFragment
setFragment( $fragment)
Set the fragment for this title.
Definition: Title.php:1829
$res
$res
Definition: testCompression.php:57
IDBAccessObject
Interface for database access objects.
Definition: IDBAccessObject.php:57
Title\$mIsBigDeletion
bool null $mIsBigDeletion
Would deleting this page be a big deletion?
Definition: Title.php:193
Title\convertByteClassToUnicodeClass
static convertByteClassToUnicodeClass( $byteClass)
Utility method for converting a character sequence from bytes to Unicode.
Definition: Title.php:750
Title\hasSubpagesEnabled
hasSubpagesEnabled()
Whether this Title's namespace has subpages enabled.
Definition: Title.php:1959
Title\__wakeup
__wakeup()
Definition: Title.php:4486
$wgLang
$wgLang
Definition: Setup.php:796
Page\PageReference
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
Definition: PageReference.php:49
Title\getParentCategories
getParentCategories()
Get categories to which this Title belongs and return an array of categories' names.
Definition: Title.php:3625
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:3406
Title\$mContentModel
bool string $mContentModel
ID of the page's content model, i.e.
Definition: Title.php:111
Title\getPageLanguageConverter
getPageLanguageConverter()
Shorthand for getting a Language Converter for page's language.
Definition: Title.php:219
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:1562
MessageLocalizer
Interface for localizing messages in MediaWiki.
Definition: MessageLocalizer.php:29
Title\getNsText
getNsText()
Get the namespace text.
Definition: Title.php:1158
Page\PageStoreRecord
Immutable data record representing an editable page on a wiki.
Definition: PageStoreRecord.php:33
Title\$mRedirect
null bool $mRedirect
Is the article at this title a redirect?
Definition: Title.php:176
Title\$mDbkeyform
string $mDbkeyform
Main part with underscores.
Definition: Title.php:91
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
Title\castFromPageIdentity
static castFromPageIdentity(?PageIdentity $pageIdentity)
Return a Title for a given PageIdentity.
Definition: Title.php:334
Title\$mUrlform
string $mUrlform
URL-encoded form of the main part.
Definition: Title.php:89
$dbr
$dbr
Definition: testCompression.php:54
Title\getLinksFrom
getLinksFrom( $options=[], $table='pagelinks', $prefix='pl')
Get an array of Title objects linked from this Title Also stores the IDs in the link cache.
Definition: Title.php:3464
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:131
PathRouter\getActionPaths
static getActionPaths(array $actionPaths, $articlePath)
Definition: PathRouter.php:430
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:53
Wikimedia\Rdbms\IDatabase\update
update( $table, $set, $conds, $fname=__METHOD__, $options=[])
Update all rows in a table that match a given condition.
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Definition: GlobalFunctions.php:422
Title\loadFieldFromDB
loadFieldFromDB( $field, $flags)
Definition: Title.php:4455
Title\isCascadeProtected
isCascadeProtected()
Cascading protection: Return true if cascading restrictions apply to this page, false if not.
Definition: Title.php:2648
Title\getCdnUrls
getCdnUrls()
Get a list of URLs to purge from the CDN cache when this page changes.
Definition: Title.php:3566
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:1749
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:1471
Title\isUserJsonConfigPage
isUserJsonConfigPage()
Is this a JSON "config" sub-page of a user page?
Definition: Title.php:1534
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:212
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:194
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:196
$wgRawHtmlMessages
string[] $wgRawHtmlMessages
List of messages which might contain raw HTML.
Definition: DefaultSettings.php:3639
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:1058
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
Definition: GlobalFunctions.php:1028
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:187
Title\isSpecial
isSpecial( $name)
Returns true if this title resolves to the named special page.
Definition: Title.php:1292
MWException
MediaWiki exception.
Definition: MWException.php:29
Title\getTitleFormatter
static getTitleFormatter()
B/C kludge: provide a TitleParser for use by Title.
Definition: Title.php:231
Title\isSamePageAs
isSamePageAs(PageReference $other)
Definition: Title.php:3825
Title\isMainPage
isMainPage()
Is this the mainpage?
Definition: Title.php:1420
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:996
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
Title\getSubpage
getSubpage( $text)
Get the title for a subpage of the current page.
Definition: Title.php:2103
Title\getBaseTitle
getBaseTitle()
Get the base page name title, i.e.
Definition: Title.php:2056
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1067
Page\PageReference\getNamespace
getNamespace()
Returns the page's namespace number.
BacklinkCache\get
static get(Title $title)
Create a new BacklinkCache or reuse any existing one.
Definition: BacklinkCache.php:116
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:582
Title\isConversionTable
isConversionTable()
Is this a conversion table for the LanguageConverter?
Definition: Title.php:1441
Title\isProtected
isProtected( $action='')
Does the title correspond to a protected article?
Definition: Title.php:2596
Title\flushRestrictions
flushRestrictions()
Flush the protection cache in this object and force reload from the database.
Definition: Title.php:2986
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2306
Title\getCategorySortkey
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:4243
Title\getInterwiki
getInterwiki()
Get the interwiki prefix.
Definition: Title.php:968
Title\isSiteJsonConfigPage
isSiteJsonConfigPage()
Is this a sitewide JSON "config" page?
Definition: Title.php:1580
$matches
$matches
Definition: NoLocalSettings.php:24
Title\isValidRedirectTarget
isValidRedirectTarget()
Check if this Title is a valid redirect target.
Definition: Title.php:4186
Title\deleteTitleProtection
deleteTitleProtection()
Remove any title protection due to page existing.
Definition: Title.php:2550
Title\__construct
__construct()
Definition: Title.php:247
MediaWiki\Interwiki\InterwikiLookup
Service interface for looking up Interwiki records.
Definition: InterwikiLookup.php:32
Title\getBrokenLinksFrom
getBrokenLinksFrom()
Get an array of Title objects referring to non-existent articles linked from this page.
Definition: Title.php:3530
Title\isUserConfigPage
isUserConfigPage()
Is this a "config" (.css, .json, or .js) sub-page of a user page?
Definition: Title.php:1485
Title\getLanguageConverter
getLanguageConverter( $language)
Shorthand for getting a Language Converter for specific language.
Definition: Title.php:210
Title\$mCascadeSources
array $mCascadeSources
Where are the cascading restrictions coming from on this page?
Definition: Title.php:146
Title\getSubjectPage
getSubjectPage()
Get a title object associated with the subject page of this talk page.
Definition: Title.php:1692
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:1132
Title\loadRestrictions
loadRestrictions( $oldFashionedRestrictions=null, $flags=0)
Load restrictions from the page_restrictions table.
Definition: Title.php:2915
$wgInvalidRedirectTargets
$wgInvalidRedirectTargets
Array of invalid page redirect targets.
Definition: DefaultSettings.php:4697
Title\getFullText
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
Definition: Title.php:1919
Title\getTitleCache
static getTitleCache()
Definition: Title.php:505
Title\hasFragment
hasFragment()
Check if a Title fragment is set.
Definition: Title.php:1795
Title\getRedirectsHere
getRedirectsHere( $ns=null)
Get all extant redirects to this Title.
Definition: Title.php:4150
$title
$title
Definition: testCompression.php:38
Title\warnIfPageCannotExist
warnIfPageCannotExist(Title $title, $method)
Definition: Title.php:1718
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:650
Title\$mInterwiki
string $mInterwiki
Interwiki prefix.
Definition: Title.php:95
Title\$mCascadeRestriction
bool $mCascadeRestriction
Cascade restrictions on this page to included templates and images?
Definition: Title.php:134
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1721
Title\getRootText
getRootText()
Get the root page name text without a namespace, i.e.
Definition: Title.php:1979
PROTO_CANONICAL
const PROTO_CANONICAL
Definition: Defines.php:196
$wgNamespaceProtection
$wgNamespaceProtection
Set the minimum permissions required to edit pages in each namespace.
Definition: DefaultSettings.php:6149
Title\canExist
canExist()
Can this title represent a page in the wiki's database?
Definition: Title.php:1225
$wgDeleteRevisionsLimit
$wgDeleteRevisionsLimit
Optional to restrict deletion of pages with higher revision counts to users with the 'bigdelete' perm...
Definition: DefaultSettings.php:6326
Title\$prefixedText
string null $prefixedText
Text form including namespace/interwiki, initialised on demand.
Definition: Title.php:159
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:894
Title\__sleep
__sleep()
Definition: Title.php:4475
Page\PageReference\getWikiId
getWikiId()
Get the ID of the wiki this page belongs to.
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:2407
Title\createFragmentTarget
createFragmentTarget( $fragment)
Creates a new Title for a different fragment of the same page.
Definition: Title.php:1841
Title\$mNamespace
int $mNamespace
Namespace index, i.e.
Definition: Title.php:93
Title\getDefaultNamespace
getDefaultNamespace()
Get the default namespace index, for when there is no namespace.
Definition: Title.php:1774
Title\newFromTextThrow
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:420
$wgPageLanguageUseDB
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
Definition: DefaultSettings.php:2512
Title\$mPageLanguage
array null $mPageLanguage
The (string) language code of the page's language and content code.
Definition: Title.php:182
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:195
Title\isValid
isValid()
Returns true if the title is a valid link target, and that it has been properly normalized.
Definition: Title.php:903
AtomicSectionUpdate
Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
Definition: AtomicSectionUpdate.php:9
Title\compare
static compare( $a, $b)
Callback for usort() to do title sorts by (namespace, title)
Definition: Title.php:882
Title\getPrefixedURL
getPrefixedURL()
Get a URL-encoded title (not an actual URL) including interwiki.
Definition: Title.php:2128
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:676
Page\ExistingPageRecord
Data record representing a page that currently exists as an editable page on a wiki.
Definition: ExistingPageRecord.php:15
Title\__toString
__toString()
Return a string representation of this title.
Definition: Title.php:1909
Page\ProperPageIdentity
Interface for objects representing a page that is (or could be, or used to be) an editable page on a ...
Definition: ProperPageIdentity.php:43
Title\getId
getId( $wikiId=self::LOCAL)
Returns the page ID.
Definition: Title.php:4525
MediaWiki\DAO\WikiAwareEntity\assertWiki
assertWiki( $wikiId)
Throws if $wikiId is different from the return value of getWikiId().
$s
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
Definition: mergeMessageFileList.php:206
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:52
ILanguageConverter
The shared interface for all language converters.
Definition: ILanguageConverter.php:29
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:3448
Page\PageReference\getDBkey
getDBkey()
Get the page title in DB key form.
$wgMainPageIsDomainRoot
bool $wgMainPageIsDomainRoot
Option to whether serve the main page as the domain root.
Definition: DefaultSettings.php:498
Title\areRestrictionsCascading
areRestrictionsCascading()
Returns cascading restrictions for the current article.
Definition: Title.php:2818
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
Title\getLatestRevID
getLatestRevID( $flags=0)
What is the page_latest field for this page?
Definition: Title.php:3261
Title\areRestrictionsLoaded
areRestrictionsLoaded()
Accessor for mRestrictionsLoaded.
Definition: Title.php:2765
Title\hasDeletedEdits
hasDeletedEdits()
Is there a version of this page in the deletion archive?
Definition: Title.php:3143
Title\getSubpages
getSubpages( $limit=-1)
Get all subpages of this page.
Definition: Title.php:3068
Title\assertProperPage
assertProperPage()
Code that requires this Title to be a "proper page" in the sense defined by PageIdentity should call ...
Definition: Title.php:4543
Wikimedia\Rdbms\IDatabase\getDomainID
getDomainID()
Return the currently selected domain ID.
Title\isSingleRevRedirect
isSingleRevRedirect()
Locks the page row and check if this page is single revision redirect.
Definition: Title.php:3587
$wgServer
$wgServer
URL of the server.
Definition: DefaultSettings.php:108
Title\GAID_FOR_UPDATE
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define().
Definition: Title.php:67
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:172
Title\getPageViewLanguage
getPageViewLanguage()
Get the language in which the content of this page is written when viewed by user.
Definition: Title.php:4332
HTMLCacheUpdateJob\newForBacklinks
static newForBacklinks(PageReference $page, $table, $params=[])
Definition: HTMLCacheUpdateJob.php:61
Title\newFromDBkey
static newFromDBkey( $key)
Create a new Title from a prefixed DB key.
Definition: Title.php:258
Sanitizer\escapeIdForExternalInterwiki
static escapeIdForExternalInterwiki( $id)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid URL...
Definition: Sanitizer.php:861
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:3403
Title\isSubpage
isSubpage()
Is this a subpage?
Definition: Title.php:1429
Title\hasContentModel
hasContentModel( $id)
Convenience method for checking a title's content model name.
Definition: Title.php:1112
Title\getRestrictionExpiry
getRestrictionExpiry( $action)
Get the expiry time for the restriction against a given action.
Definition: Title.php:2806
Title\newFromURL
static newFromURL( $url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:482
MediaWiki\Linker\LinkTarget\getDBkey
getDBkey()
Get the main part with underscores.
MediaWiki\Linker\LinkTarget\getFragment
getFragment()
Get the link fragment (i.e.
Title\$mRestrictionsExpiry
array $mRestrictionsExpiry
When do the restrictions on this page expire?
Definition: Title.php:140
MapCacheLRU\set
set( $key, $value, $rank=self::RANK_TOP)
Set a key/value pair.
Definition: MapCacheLRU.php:110
Title\resetArticleID
resetArticleID( $id)
Inject a page ID, reset DB-loaded fields, and clear the link cache for this title.
Definition: Title.php:3296
Title\isSubpageOf
isSubpageOf(Title $title)
Check if this title is a subpage of another title.
Definition: Title.php:3846
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:942
Title\$mFragment
string $mFragment
Title fragment (i.e.
Definition: Title.php:99
Title\getContentModel
getContentModel( $flags=0)
Get the page's content model id, see the CONTENT_MODEL_XXX constants.
Definition: Title.php:1079
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:208
Title\newFromIDs
static newFromIDs( $ids)
Make an array of titles from an array of IDs.
Definition: Title.php:556
NS_USER
const NS_USER
Definition: Defines.php:66
WikiPage\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new page object.
Definition: WikiPage.php:375
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:297
Title\prefix
prefix( $name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object.
Definition: Title.php:1857
Title\getNamespaceKey
getNamespaceKey( $prepend='nstab-')
Generate strings used for xml 'id' names in monobook tabs.
Definition: Title.php:4121
Title\getEditURL
getEditURL()
Get the edit URL for this Title.
Definition: Title.php:2419
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:2185
Title\isKnown
isKnown()
Does this title refer to a page that can (or might) be meaningfully viewed? In particular,...
Definition: Title.php:3938
$wgArticlePath
$wgArticlePath
The URL path for primary article page views.
Definition: DefaultSettings.php:264
Title\$mIsValid
bool null $mIsValid
Is the title known to be valid?
Definition: Title.php:196
Title\equals
equals(object $other)
Compares with another Title.
Definition: Title.php:3789
Title\getAllRestrictions
getAllRestrictions()
Accessor/initialisation for mRestrictions.
Definition: Title.php:2792
Title
Represents a title within MediaWiki.
Definition: Title.php:49
$wgActionPaths
$wgActionPaths
To set 'pretty' URL paths for actions other than plain page views, add to this array.
Definition: DefaultSettings.php:488
Title\$mCascadingRestrictions
$mCascadingRestrictions
Caching the results of getCascadeProtectionSources.
Definition: Title.php:137
Title\isSameLinkAs
isSameLinkAs(LinkTarget $other)
Definition: Title.php:3809
JobQueueGroup\singleton
static singleton( $domain=false)
Definition: JobQueueGroup.php:114
Title\getCascadeProtectionSources
getCascadeProtectionSources( $getPages=true)
Cascading protection: Get the source of any cascading restrictions on this page.
Definition: Title.php:2679
$cache
$cache
Definition: mcc.php:33
$wgSemiprotectedRestrictionLevels
$wgSemiprotectedRestrictionLevels
Restriction levels that should be considered "semiprotected".
Definition: DefaultSettings.php:6140
Title\getRestrictionTypes
getRestrictionTypes()
Returns restriction types for the current Title.
Definition: Title.php:2453
MalformedTitleException
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Definition: MalformedTitleException.php:26
Title\getTitleProtectionInternal
getTitleProtectionInternal()
Fetch title protection settings.
Definition: Title.php:2503
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:3518
Title\isRedirect
isRedirect( $flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
Definition: Title.php:3209
Title\$mArticleID
int $mArticleID
Article ID, fetched from the link cache on demand.
Definition: Title.php:102
Title\isDeleted
isDeleted()
Is there a version of this page in the deletion archive?
Definition: Title.php:3097
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:3333
Title\$mDefaultNamespace
int $mDefaultNamespace
Namespace index when there is no namespace.
Definition: Title.php:170
Title\$mLength
int $mLength
The page length, 0 for special pages.
Definition: Title.php:173
Title\$mEstimateRevisions
int $mEstimateRevisions
Estimated number of revisions; null of not loaded.
Definition: Title.php:120
Title\hasSubjectNamespace
hasSubjectNamespace( $ns)
Returns true if the title has the same subject namespace as the namespace specified.
Definition: Title.php:1373
Title\isSpecialPage
isSpecialPage()
Returns true if this is a special page.
Definition: Title.php:1282
MapCacheLRU\get
get( $key, $maxAge=INF, $default=null)
Get the value for a key.
Definition: MapCacheLRU.php:172
Title\purgeSquid
purgeSquid()
Purge all applicable CDN URLs.
Definition: Title.php:3575
Title\getDeletedEditsCount
getDeletedEditsCount()
Is there a version of this page in the deletion archive?
Definition: Title.php:3107
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:4291
Title\CACHE_MAX
const CACHE_MAX
Title::newFromText maintains a cache to avoid expensive re-normalization of commonly used titles.
Definition: Title.php:60
Title\getEditNotices
getEditNotices( $oldid=0)
Get a list of rendered edit notices for this page.
Definition: Title.php:4380
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:209
Title\getTouched
getTouched( $db=null)
Get the last touched timestamp.
Definition: Title.php:4093
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:212
Page\PageIdentity\exists
exists()
Checks if the page currently exists.
Wikimedia\Rdbms\IDatabase\selectFieldValues
selectFieldValues( $table, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[])
A SELECT wrapper which returns a list of single field values from result rows.
$wgRestrictionLevels
$wgRestrictionLevels
Rights which can be required for each protection level (via action=protect)
Definition: DefaultSettings.php:6115
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:78
Page\PageIdentityValue
Immutable value object representing a page identity.
Definition: PageIdentityValue.php:41
Title\getFragmentForURL
getFragmentForURL()
Get the fragment in URL form, including the "#" character if there is one.
Definition: Title.php:1804
Title\exists
exists( $flags=0)
Check if page exists.
Definition: Title.php:3862
Title\__clone
__clone()
Definition: Title.php:4492
Sanitizer\escapeIdForLink
static escapeIdForLink( $id)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid URL...
Definition: Sanitizer.php:838
Title\isAlwaysKnown
isAlwaysKnown()
Should links to this title be shown as potentially viewable (i.e.
Definition: Title.php:3884
Title\secureAndSplit
secureAndSplit( $text, $defaultNamespace=null)
Secure and split - main initialisation function for this object.
Definition: Title.php:3358
Title\isDeletedQuick
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:3133
Title\getSubpageUrlForm
getSubpageUrlForm()
Get a URL-encoded form of the subpage text.
Definition: Title.php:2117
MapCacheLRU\clear
clear( $keys=null)
Clear one or several cache entries, or all cache entries.
Definition: MapCacheLRU.php:289
Title\castFromPageReference
static castFromPageReference(?PageReference $pageReference)
Return a Title for a given Reference.
Definition: Title.php:347
Title\isNewPage
isNewPage()
Check if this is a new page.
Definition: Title.php:3722
$wgRestrictionTypes
$wgRestrictionTypes
Set of available actions that can be restricted via action=protect You probably shouldn't change this...
Definition: DefaultSettings.php:6102
Title\toPageIdentity
toPageIdentity()
Returns the page represented by this Title as a ProperPageIdentity.
Definition: Title.php:4562
Title\setContentModel
setContentModel( $model)
Set a proposed content model for the page for permissions checking.
Definition: Title.php:1132
$t
$t
Definition: testCompression.php:74
Title\legalChars
static legalChars()
Get a regex character class describing the legal characters in a link.
Definition: Title.php:736
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:321
Title\isSiteJsConfigPage
isSiteJsConfigPage()
Is this a sitewide JS "config" page?
Definition: Title.php:1598
Title\invalidateCache
invalidateCache( $purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:4029
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:680
NS_FILE
const NS_FILE
Definition: Defines.php:70
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
Title\isTrans
isTrans()
Determine whether the object refers to a page within this project and is transcludable.
Definition: Title.php:987
Title\getRestrictions
getRestrictions( $action)
Accessor/initialisation for mRestrictions.
Definition: Title.php:2778
CommentStore\getStore
static getStore()
Definition: CommentStore.php:120
Title\isContentPage
isContentPage()
Is this Title in a namespace which contains content? In other words, is this a content page,...
Definition: Title.php:1385
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:210
Title\uncache
uncache()
Removes this instance from the internal title cache, so it can be modified in-place without polluting...
Definition: Title.php:459
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:67
Title\$titleCache
static MapCacheLRU null $titleCache
Definition: Title.php:53
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:531
$wgVariantArticlePath
$wgVariantArticlePath
Like $wgArticlePath, but on multi-variant wikis, this provides a path format that describes which par...
Definition: DefaultSettings.php:3598
ResourceLoaderWikiModule\invalidateModuleCache
static invalidateModuleCache(PageIdentity $page, ?RevisionRecord $old, ?RevisionRecord $new, $domain)
Clear the preloadTitleInfo() cache for all wiki modules on this wiki on page change if it was a JS or...
Definition: ResourceLoaderWikiModule.php:561
Title\isRawHtmlMessage
isRawHtmlMessage()
Is this a message which can contain raw HTML?
Definition: Title.php:1616
Title\getSelectFields
static getSelectFields()
Returns a list of fields that are to be selected for initializing Title objects or LinkCache entries.
Definition: Title.php:520
Title\hasSubpages
hasSubpages()
Does this have subpages? (Warning, usually requires an extra DB query.)
Definition: Title.php:3037
Title\getBaseText
getBaseText()
Get the base page name without a namespace, i.e.
Definition: Title.php:2029
Title\pageCond
pageCond()
Get an associative array for selecting this title from the "page" table.
Definition: Title.php:3687
Title\getText
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:1040
Title\$mTextform
string $mTextform
Text form (spaces not underscores) of the main part.
Definition: Title.php:87
Title\toPageRecord
toPageRecord( $flags=0)
Returns the page represented by this Title as a ProperPageRecord.
Definition: Title.php:4589
Wikimedia\Rdbms\IDatabase\delete
delete( $table, $conds, $fname=__METHOD__)
Delete all rows in a table that match a condition.
Title\purgeExpiredRestrictions
static purgeExpiredRestrictions()
Purge expired restrictions from the page_restrictions table.
Definition: Title.php:2996
$wgInternalServer
$wgInternalServer
Internal server name as known to CDN, if different.
Definition: DefaultSettings.php:3210
Title\$mLatestID
bool int $mLatestID
ID of most recent revision.
Definition: Title.php:105
PROTO_HTTP
const PROTO_HTTP
Definition: Defines.php:192
Title\$mRestrictionsLoaded
bool $mRestrictionsLoaded
Boolean for initialisation on demand.
Definition: Title.php:149
Title\getWikiId
getWikiId()
Returns false to indicate that this Title belongs to the local wiki.
Definition: Title.php:4505
Title\lazyFillContentModel
lazyFillContentModel( $model)
If the content model field is not frozen then update it with a retreived value.
Definition: Title.php:1147
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:474
Title\getSubjectNsText
getSubjectNsText()
Get the namespace text of the subject (rather than talk) page.
Definition: Title.php:1183
Title\$mTitleProtection
mixed $mTitleProtection
Cached value for getTitleProtection (create protection)
Definition: Title.php:162
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:40
Title\newFromTitleValue
static newFromTitleValue(TitleValue $titleValue, $forceClone='')
Returns a Title given a TitleValue.
Definition: Title.php:282
Title\getRelativeRevisionID
getRelativeRevisionID( $revId, $flags, $dir)
Get next/previous revision ID relative to another revision ID.
Definition: Title.php:3703
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:330
Title\getFullUrlForRedirect
getFullUrlForRedirect( $query='', $proto=PROTO_CURRENT)
Get a url appropriate for making redirects based on an untrusted url arg.
Definition: Title.php:2218
Title\getRootTitle
getRootTitle()
Get the root page name title, i.e.
Definition: Title.php:2006
$type
$type
Definition: testCompression.php:52
Title\getLength
getLength( $flags=0)
What is the length of this page? Uses link cache, adding it if necessary.
Definition: Title.php:3234
Title\findSubpageDivider
findSubpageDivider( $text, $dir)
Finds the first or last subpage divider (slash) in the string.
Definition: Title.php:1941
Title\isWatchable
isWatchable()
Can this title be added to a user's watchlist?
Definition: Title.php:1271