MediaWiki  master
Title.php
Go to the documentation of this file.
1 <?php
33 use Wikimedia\Assert\Assert;
34 use Wikimedia\Assert\PreconditionException;
37 
48  private static $titleCache = null;
49 
55  private const CACHE_MAX = 1000;
56 
62  public const GAID_FOR_UPDATE = 512;
63 
71  public const NEW_CLONE = 'clone';
72 
73  /***************************************************************************/
74  // region Private member variables
82  public $mTextform = '';
84  public $mUrlform = '';
86  public $mDbkeyform = '';
88  public $mNamespace = NS_MAIN;
90  public $mInterwiki = '';
92  private $mLocalInterwiki = false;
94  public $mFragment = '';
95 
97  public $mArticleID = -1;
98 
100  protected $mLatestID = false;
101 
106  private $mContentModel = false;
107 
112  private $mForcedContentModel = false;
113 
116 
118  public $mRestrictions = [];
119 
126  protected $mOldRestrictions = false;
127 
130 
133 
135  protected $mRestrictionsExpiry = [];
136 
139 
142 
144  public $mRestrictionsLoaded = false;
145 
154  public $prefixedText = null;
155 
158 
166 
168  protected $mLength = -1;
169 
171  public $mRedirect = null;
172 
174  private $mHasSubpages;
175 
177  private $mPageLanguage;
178 
182  private $mDbPageLanguage = false;
183 
185  private $mTitleValue = null;
186 
188  private $mIsBigDeletion = null;
189 
191  private $mIsValid = null;
192 
193  // endregion -- end of private member variables
195  /***************************************************************************/
196 
202  private function getLanguageConverter( $language ) : ILanguageConverter {
203  return MediaWikiServices::getInstance()->getLanguageConverterFactory()
204  ->getLanguageConverter( $language );
205  }
206 
212  return $this->getLanguageConverter( $this->getPageLanguage() );
213  }
214 
223  private static function getTitleFormatter() {
224  return MediaWikiServices::getInstance()->getTitleFormatter();
225  }
226 
235  private static function getInterwikiLookup() {
236  return MediaWikiServices::getInstance()->getInterwikiLookup();
237  }
238 
239  private function __construct() {
240  }
241 
250  public static function newFromDBkey( $key ) {
251  $t = new self();
252 
253  try {
254  $t->secureAndSplit( $key );
255  return $t;
256  } catch ( MalformedTitleException $ex ) {
257  return null;
258  }
259  }
260 
274  public static function newFromTitleValue( TitleValue $titleValue, $forceClone = '' ) {
275  return self::newFromLinkTarget( $titleValue, $forceClone );
276  }
277 
289  public static function newFromLinkTarget( LinkTarget $linkTarget, $forceClone = '' ) {
290  if ( $linkTarget instanceof Title ) {
291  // Special case if it's already a Title object
292  if ( $forceClone === self::NEW_CLONE ) {
293  return clone $linkTarget;
294  } else {
295  return $linkTarget;
296  }
297  }
298  return self::makeTitle(
299  $linkTarget->getNamespace(),
300  $linkTarget->getText(),
301  $linkTarget->getFragment(),
302  $linkTarget->getInterwiki()
303  );
304  }
305 
313  public static function castFromLinkTarget( $linkTarget ) {
314  return $linkTarget ? self::newFromLinkTarget( $linkTarget ) : null;
315  }
316 
326  public static function castFromPageIdentity( ?PageIdentity $pageIdentity ) : ?Title {
327  if ( !$pageIdentity ) {
328  return null;
329  }
330 
331  if ( $pageIdentity instanceof Title ) {
332  return $pageIdentity;
333  }
334 
335  $pageIdentity->assertWiki( PageIdentity::LOCAL );
336  $title = self::makeTitle( $pageIdentity->getNamespace(), $pageIdentity->getDBkey() );
337  $title->resetArticleID( $pageIdentity->getId() );
338  return $title;
339  }
340 
361  public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
362  // DWIM: Integers can be passed in here when page titles are used as array keys.
363  if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) {
364  throw new InvalidArgumentException( '$text must be a string.' );
365  }
366  if ( $text === null ) {
367  return null;
368  }
369 
370  try {
371  return self::newFromTextThrow( (string)$text, (int)$defaultNamespace );
372  } catch ( MalformedTitleException $ex ) {
373  return null;
374  }
375  }
376 
396  public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
397  if ( is_object( $text ) ) {
398  throw new MWException( '$text must be a string, given an object' );
399  } elseif ( $text === null ) {
400  // Legacy code relies on MalformedTitleException being thrown in this case
401  // (happens when URL with no title in it is parsed). TODO fix
402  throw new MalformedTitleException( 'title-invalid-empty' );
403  }
404 
406 
407  // Wiki pages often contain multiple links to the same page.
408  // Title normalization and parsing can become expensive on pages with many
409  // links, so we can save a little time by caching them.
410  // In theory these are value objects and won't get changed...
411  if ( $defaultNamespace === NS_MAIN ) {
412  $t = $titleCache->get( $text );
413  if ( $t ) {
414  return $t;
415  }
416  }
417 
418  // Convert things like &eacute; &#257; or &#x3017; into normalized (T16952) text
419  $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
420 
421  $t = new Title();
422  $dbKeyForm = strtr( $filteredText, ' ', '_' );
423 
424  $t->secureAndSplit( $dbKeyForm, (int)$defaultNamespace );
425  if ( $defaultNamespace === NS_MAIN ) {
426  $titleCache->set( $text, $t );
427  }
428  return $t;
429  }
430 
446  public static function newFromURL( $url ) {
447  $t = new Title();
448 
449  # For compatibility with old buggy URLs. "+" is usually not valid in titles,
450  # but some URLs used it as a space replacement and they still come
451  # from some external search tools.
452  if ( strpos( self::legalChars(), '+' ) === false ) {
453  $url = strtr( $url, '+', ' ' );
454  }
455 
456  $dbKeyForm = strtr( $url, ' ', '_' );
457 
458  try {
459  $t->secureAndSplit( $dbKeyForm );
460  return $t;
461  } catch ( MalformedTitleException $ex ) {
462  return null;
463  }
464  }
465 
469  private static function getTitleCache() {
470  if ( self::$titleCache === null ) {
471  self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
472  }
473  return self::$titleCache;
474  }
475 
482  protected static function getSelectFields() {
483  global $wgPageLanguageUseDB;
484 
485  $fields = [
486  'page_namespace', 'page_title', 'page_id',
487  'page_len', 'page_is_redirect', 'page_latest',
488  'page_content_model',
489  ];
490 
491  if ( $wgPageLanguageUseDB ) {
492  $fields[] = 'page_lang';
493  }
494 
495  return $fields;
496  }
497 
505  public static function newFromID( $id, $flags = 0 ) {
506  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
507  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
508  $row = wfGetDB( $index )->selectRow(
509  'page',
510  self::getSelectFields(),
511  [ 'page_id' => $id ],
512  __METHOD__,
513  $options
514  );
515  if ( $row !== false ) {
516  $title = self::newFromRow( $row );
517  } else {
518  $title = null;
519  }
520 
521  return $title;
522  }
523 
530  public static function newFromIDs( $ids ) {
531  if ( !count( $ids ) ) {
532  return [];
533  }
534  $dbr = wfGetDB( DB_REPLICA );
535 
536  $res = $dbr->select(
537  'page',
538  self::getSelectFields(),
539  [ 'page_id' => $ids ],
540  __METHOD__
541  );
542 
543  $titles = [];
544  foreach ( $res as $row ) {
545  $titles[] = self::newFromRow( $row );
546  }
547  return $titles;
548  }
549 
556  public static function newFromRow( $row ) {
557  $t = self::makeTitle( $row->page_namespace, $row->page_title );
558  $t->loadFromRow( $row );
559  return $t;
560  }
561 
568  public function loadFromRow( $row ) {
569  if ( $row ) { // page found
570  if ( isset( $row->page_id ) ) {
571  $this->mArticleID = (int)$row->page_id;
572  }
573  if ( isset( $row->page_len ) ) {
574  $this->mLength = (int)$row->page_len;
575  }
576  if ( isset( $row->page_is_redirect ) ) {
577  $this->mRedirect = (bool)$row->page_is_redirect;
578  }
579  if ( isset( $row->page_latest ) ) {
580  $this->mLatestID = (int)$row->page_latest;
581  }
582  if ( isset( $row->page_content_model ) ) {
583  $this->lazyFillContentModel( $row->page_content_model );
584  } else {
585  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
586  }
587  if ( isset( $row->page_lang ) ) {
588  $this->mDbPageLanguage = (string)$row->page_lang;
589  }
590  if ( isset( $row->page_restrictions ) ) {
591  $this->mOldRestrictions = $row->page_restrictions;
592  }
593  } else { // page not found
594  $this->mArticleID = 0;
595  $this->mLength = 0;
596  $this->mRedirect = false;
597  $this->mLatestID = 0;
598  $this->lazyFillContentModel( false ); // lazily-load getContentModel()
599  }
600  }
601 
624  public static function makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
625  $t = new Title();
626  $t->mInterwiki = $interwiki;
627  $t->mFragment = $fragment;
628  $t->mNamespace = $ns = (int)$ns;
629  $t->mDbkeyform = strtr( $title, ' ', '_' );
630  $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
631  $t->mUrlform = wfUrlencode( $t->mDbkeyform );
632  $t->mTextform = strtr( $title, '_', ' ' );
633  return $t;
634  }
635 
650  public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
651  // NOTE: ideally, this would just call makeTitle() and then isValid(),
652  // but presently, that means more overhead on a potential performance hotspot.
653 
654  if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) {
655  return null;
656  }
657 
658  $t = new Title();
659  $dbKeyForm = self::makeName( $ns, $title, $fragment, $interwiki, true );
660 
661  try {
662  $t->secureAndSplit( $dbKeyForm );
663  return $t;
664  } catch ( MalformedTitleException $ex ) {
665  return null;
666  }
667  }
668 
686  public static function newMainPage( MessageLocalizer $localizer = null ) {
687  if ( $localizer ) {
688  $msg = $localizer->msg( 'mainpage' );
689  } else {
690  $msg = wfMessage( 'mainpage' );
691  }
692 
693  $title = self::newFromText( $msg->inContentLanguage()->text() );
694 
695  // Every page renders at least one link to the Main Page (e.g. sidebar).
696  // If the localised value is invalid, don't produce fatal errors that
697  // would make the wiki inaccessible (and hard to fix the invalid message).
698  // Gracefully fallback...
699  if ( !$title ) {
700  $title = self::newFromText( 'Main Page' );
701  }
702  return $title;
703  }
704 
712  public static function nameOf( $id ) {
713  wfDeprecated( __METHOD__, '1.36' );
714 
715  $dbr = wfGetDB( DB_REPLICA );
716 
717  $s = $dbr->selectRow(
718  'page',
719  [ 'page_namespace', 'page_title' ],
720  [ 'page_id' => $id ],
721  __METHOD__
722  );
723  if ( $s === false ) {
724  return null;
725  }
726 
727  return self::makeName( $s->page_namespace, $s->page_title );
728  }
729 
735  public static function legalChars() {
736  global $wgLegalTitleChars;
737  return $wgLegalTitleChars;
738  }
739 
749  public static function convertByteClassToUnicodeClass( $byteClass ) {
750  $length = strlen( $byteClass );
751  // Input token queue
752  $x0 = $x1 = $x2 = '';
753  // Decoded queue
754  $d0 = $d1 = '';
755  // Decoded integer codepoints
756  $ord0 = $ord1 = $ord2 = 0;
757  // Re-encoded queue
758  $r0 = $r1 = $r2 = '';
759  // Output
760  $out = '';
761  // Flags
762  $allowUnicode = false;
763  for ( $pos = 0; $pos < $length; $pos++ ) {
764  // Shift the queues down
765  $x2 = $x1;
766  $x1 = $x0;
767  $d1 = $d0;
768  $ord2 = $ord1;
769  $ord1 = $ord0;
770  $r2 = $r1;
771  $r1 = $r0;
772  // Load the current input token and decoded values
773  $inChar = $byteClass[$pos];
774  if ( $inChar === '\\' ) {
775  if ( preg_match( '/x([0-9a-fA-F]{2})/A', $byteClass, $m, 0, $pos + 1 ) ) {
776  $x0 = $inChar . $m[0];
777  $d0 = chr( hexdec( $m[1] ) );
778  $pos += strlen( $m[0] );
779  } elseif ( preg_match( '/[0-7]{3}/A', $byteClass, $m, 0, $pos + 1 ) ) {
780  $x0 = $inChar . $m[0];
781  $d0 = chr( octdec( $m[0] ) );
782  $pos += strlen( $m[0] );
783  } elseif ( $pos + 1 >= $length ) {
784  $x0 = $d0 = '\\';
785  } else {
786  $d0 = $byteClass[$pos + 1];
787  $x0 = $inChar . $d0;
788  $pos++;
789  }
790  } else {
791  $x0 = $d0 = $inChar;
792  }
793  $ord0 = ord( $d0 );
794  // Load the current re-encoded value
795  if ( $ord0 < 32 || $ord0 == 0x7f ) {
796  $r0 = sprintf( '\x%02x', $ord0 );
797  } elseif ( $ord0 >= 0x80 ) {
798  // Allow unicode if a single high-bit character appears
799  $r0 = sprintf( '\x%02x', $ord0 );
800  $allowUnicode = true;
801  // @phan-suppress-next-line PhanParamSuspiciousOrder false positive
802  } elseif ( strpos( '-\\[]^', $d0 ) !== false ) {
803  $r0 = '\\' . $d0;
804  } else {
805  $r0 = $d0;
806  }
807  // Do the output
808  if ( $x0 !== '' && $x1 === '-' && $x2 !== '' ) {
809  // Range
810  if ( $ord2 > $ord0 ) {
811  // Empty range
812  } elseif ( $ord0 >= 0x80 ) {
813  // Unicode range
814  $allowUnicode = true;
815  if ( $ord2 < 0x80 ) {
816  // Keep the non-unicode section of the range
817  $out .= "$r2-\\x7F";
818  }
819  } else {
820  // Normal range
821  $out .= "$r2-$r0";
822  }
823  // Reset state to the initial value
824  $x0 = $x1 = $d0 = $d1 = $r0 = $r1 = '';
825  } elseif ( $ord2 < 0x80 ) {
826  // ASCII character
827  $out .= $r2;
828  }
829  }
830  // @phan-suppress-next-line PhanSuspiciousValueComparison
831  if ( $ord1 < 0x80 ) {
832  $out .= $r1;
833  }
834  if ( $ord0 < 0x80 ) {
835  $out .= $r0;
836  }
837  if ( $allowUnicode ) {
838  $out .= '\u0080-\uFFFF';
839  }
840  return $out;
841  }
842 
854  public static function makeName( $ns, $title, $fragment = '', $interwiki = '',
855  $canonicalNamespace = false
856  ) {
857  if ( $canonicalNamespace ) {
858  $namespace = MediaWikiServices::getInstance()->getNamespaceInfo()->
859  getCanonicalName( $ns );
860  } else {
861  $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns );
862  }
863  $name = $namespace == '' ? $title : "$namespace:$title";
864  if ( strval( $interwiki ) != '' ) {
865  $name = "$interwiki:$name";
866  }
867  if ( strval( $fragment ) != '' ) {
868  $name .= '#' . $fragment;
869  }
870  return $name;
871  }
872 
881  public static function compare( LinkTarget $a, LinkTarget $b ) {
882  return $a->getNamespace() <=> $b->getNamespace()
883  ?: strcmp( $a->getText(), $b->getText() );
884  }
885 
902  public function isValid() {
903  if ( $this->mIsValid !== null ) {
904  return $this->mIsValid;
905  }
906 
907  try {
908  $text = $this->getFullText();
909  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
910 
911  '@phan-var MediaWikiTitleCodec $titleCodec';
912  $parts = $titleCodec->splitTitleString( $text, $this->mNamespace );
913 
914  // Check that nothing changed!
915  // This ensures that $text was already perperly normalized.
916  if ( $parts['fragment'] !== $this->mFragment
917  || $parts['interwiki'] !== $this->mInterwiki
918  || $parts['local_interwiki'] !== $this->mLocalInterwiki
919  || $parts['namespace'] !== $this->mNamespace
920  || $parts['dbkey'] !== $this->mDbkeyform
921  ) {
922  $this->mIsValid = false;
923  return $this->mIsValid;
924  }
925  } catch ( MalformedTitleException $ex ) {
926  $this->mIsValid = false;
927  return $this->mIsValid;
928  }
929 
930  $this->mIsValid = true;
931  return $this->mIsValid;
932  }
933 
941  public function isLocal() {
942  if ( $this->isExternal() ) {
943  $iw = self::getInterwikiLookup()->fetch( $this->mInterwiki );
944  if ( $iw ) {
945  return $iw->isLocal();
946  }
947  }
948  return true;
949  }
950 
956  public function isExternal() {
957  return $this->mInterwiki !== '';
958  }
959 
967  public function getInterwiki() {
968  return $this->mInterwiki;
969  }
970 
976  public function wasLocalInterwiki() {
977  return $this->mLocalInterwiki;
978  }
979 
986  public function isTrans() {
987  if ( !$this->isExternal() ) {
988  return false;
989  }
990 
991  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable();
992  }
993 
999  public function getTransWikiID() {
1000  if ( !$this->isExternal() ) {
1001  return false;
1002  }
1003 
1004  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID();
1005  }
1006 
1016  public function getTitleValue() {
1017  if ( $this->mTitleValue === null ) {
1018  try {
1019  $this->mTitleValue = new TitleValue(
1020  $this->mNamespace,
1021  $this->mDbkeyform,
1022  $this->mFragment,
1023  $this->mInterwiki
1024  );
1025  } catch ( InvalidArgumentException $ex ) {
1026  wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' .
1027  $this->getPrefixedText() . ']]: ' . $ex->getMessage() );
1028  }
1029  }
1030 
1031  return $this->mTitleValue;
1032  }
1033 
1039  public function getText() {
1040  return $this->mTextform;
1041  }
1042 
1048  public function getPartialURL() {
1049  return $this->mUrlform;
1050  }
1051 
1057  public function getDBkey() {
1058  return $this->mDbkeyform;
1059  }
1060 
1066  public function getNamespace() {
1067  return $this->mNamespace;
1068  }
1069 
1078  public function getContentModel( $flags = 0 ) {
1079  if ( $this->mForcedContentModel ) {
1080  if ( !$this->mContentModel ) {
1081  throw new RuntimeException( 'Got out of sync; an empty model is being forced' );
1082  }
1083  // Content model is locked to the currently loaded one
1084  return $this->mContentModel;
1085  }
1086 
1087  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
1088  $this->lazyFillContentModel( $this->loadFieldFromDB( 'page_content_model', $flags ) );
1089  } elseif (
1090  ( !$this->mContentModel || $flags & self::GAID_FOR_UPDATE ) &&
1091  $this->getArticleID( $flags )
1092  ) {
1093  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1094  $linkCache->addLinkObj( $this ); # in case we already had an article ID
1095  $this->lazyFillContentModel( $linkCache->getGoodLinkFieldObj( $this, 'model' ) );
1096  }
1097 
1098  if ( !$this->mContentModel ) {
1100  }
1101 
1102  return $this->mContentModel;
1103  }
1104 
1111  public function hasContentModel( $id ) {
1112  return $this->getContentModel() == $id;
1113  }
1114 
1128  public function setContentModel( $model ) {
1129  if ( (string)$model === '' ) {
1130  throw new InvalidArgumentException( "Missing CONTENT_MODEL_* constant" );
1131  }
1132 
1133  $this->mContentModel = $model;
1134  $this->mForcedContentModel = true;
1135  }
1136 
1142  private function lazyFillContentModel( $model ) {
1143  if ( !$this->mForcedContentModel ) {
1144  $this->mContentModel = ( $model === false ) ? false : (string)$model;
1145  }
1146  }
1147 
1153  public function getNsText() {
1154  if ( $this->isExternal() ) {
1155  // This probably shouldn't even happen, except for interwiki transclusion.
1156  // If possible, use the canonical name for the foreign namespace.
1157  $nsText = MediaWikiServices::getInstance()->getNamespaceInfo()->
1158  getCanonicalName( $this->mNamespace );
1159  if ( $nsText !== false ) {
1160  return $nsText;
1161  }
1162  }
1163 
1164  try {
1165  $formatter = self::getTitleFormatter();
1166  return $formatter->getNamespaceName( $this->mNamespace, $this->mDbkeyform );
1167  } catch ( InvalidArgumentException $ex ) {
1168  wfDebug( __METHOD__ . ': ' . $ex->getMessage() );
1169  return false;
1170  }
1171  }
1172 
1178  public function getSubjectNsText() {
1179  $services = MediaWikiServices::getInstance();
1180  return $services->getContentLanguage()->
1181  getNsText( $services->getNamespaceInfo()->getSubject( $this->mNamespace ) );
1182  }
1183 
1189  public function getTalkNsText() {
1190  $services = MediaWikiServices::getInstance();
1191  return $services->getContentLanguage()->
1192  getNsText( $services->getNamespaceInfo()->getTalk( $this->mNamespace ) );
1193  }
1194 
1206  public function canHaveTalkPage() {
1207  return MediaWikiServices::getInstance()->getNamespaceInfo()->canHaveTalkPage( $this );
1208  }
1209 
1220  public function canExist() {
1221  // NOTE: Don't use getArticleID(), we don't want to
1222  // trigger a database query here. This check is supposed to
1223  // act as an optimization, not add extra cost.
1224  if ( $this->mArticleID > 0 ) {
1225  // It exists, so it can exist.
1226  return true;
1227  }
1228 
1229  // NOTE: we call the relatively expensive isValid() method further down,
1230  // but we can bail out early if we already know the title is invalid.
1231  if ( $this->mIsValid === false ) {
1232  // It's invalid, so it can't exist.
1233  return false;
1234  }
1235 
1236  if ( $this->getNamespace() < NS_MAIN ) {
1237  // It's a special page, so it can't exist in the database.
1238  return false;
1239  }
1240 
1241  if ( $this->isExternal() ) {
1242  // If it's external, it's not local, so it can't exist.
1243  return false;
1244  }
1245 
1246  if ( $this->getText() === '' ) {
1247  // The title has no text, so it can't exist in the database.
1248  // It's probably an on-page section link, like "#something".
1249  return false;
1250  }
1251 
1252  // Double check that the title is valid.
1253  return $this->isValid();
1254  }
1255 
1264  public function isWatchable() {
1265  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
1266  return $this->getText() !== '' && !$this->isExternal() &&
1267  $nsInfo->isWatchable( $this->mNamespace );
1268  }
1269 
1275  public function isSpecialPage() {
1276  return $this->mNamespace === NS_SPECIAL;
1277  }
1278 
1285  public function isSpecial( $name ) {
1286  if ( $this->isSpecialPage() ) {
1287  list( $thisName, /* $subpage */ ) =
1288  MediaWikiServices::getInstance()->getSpecialPageFactory()->
1289  resolveAlias( $this->mDbkeyform );
1290  if ( $name == $thisName ) {
1291  return true;
1292  }
1293  }
1294  return false;
1295  }
1296 
1303  public function fixSpecialName() {
1304  if ( $this->isSpecialPage() ) {
1305  $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory();
1306  list( $canonicalName, $par ) = $spFactory->resolveAlias( $this->mDbkeyform );
1307  if ( $canonicalName ) {
1308  $localName = $spFactory->getLocalNameFor( $canonicalName, $par );
1309  if ( $localName != $this->mDbkeyform ) {
1310  return self::makeTitle( NS_SPECIAL, $localName );
1311  }
1312  }
1313  }
1314  return $this;
1315  }
1316 
1327  public function inNamespace( $ns ) {
1328  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1329  equals( $this->mNamespace, $ns );
1330  }
1331 
1339  public function inNamespaces( ...$namespaces ) {
1340  if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) {
1341  $namespaces = $namespaces[0];
1342  }
1343 
1344  foreach ( $namespaces as $ns ) {
1345  if ( $this->inNamespace( $ns ) ) {
1346  return true;
1347  }
1348  }
1349 
1350  return false;
1351  }
1352 
1366  public function hasSubjectNamespace( $ns ) {
1367  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1368  subjectEquals( $this->mNamespace, $ns );
1369  }
1370 
1378  public function isContentPage() {
1379  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1380  isContent( $this->mNamespace );
1381  }
1382 
1389  public function isMovable() {
1390  if (
1391  !MediaWikiServices::getInstance()->getNamespaceInfo()->
1392  isMovable( $this->mNamespace ) || $this->isExternal()
1393  ) {
1394  // Interwiki title or immovable namespace. Hooks don't get to override here
1395  return false;
1396  }
1397 
1398  $result = true;
1399  Hooks::runner()->onTitleIsMovable( $this, $result );
1400  return $result;
1401  }
1402 
1413  public function isMainPage() {
1414  return $this->equals( self::newMainPage() );
1415  }
1416 
1422  public function isSubpage() {
1423  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1424  hasSubpages( $this->mNamespace )
1425  ? strpos( $this->getText(), '/' ) !== false
1426  : false;
1427  }
1428 
1434  public function isConversionTable() {
1435  // @todo ConversionTable should become a separate content model.
1436 
1437  return $this->mNamespace === NS_MEDIAWIKI &&
1438  strpos( $this->getText(), 'Conversiontable/' ) === 0;
1439  }
1440 
1446  public function isWikitextPage() {
1447  return $this->hasContentModel( CONTENT_MODEL_WIKITEXT );
1448  }
1449 
1464  public function isSiteConfigPage() {
1465  return (
1466  $this->isSiteCssConfigPage()
1467  || $this->isSiteJsonConfigPage()
1468  || $this->isSiteJsConfigPage()
1469  );
1470  }
1471 
1478  public function isUserConfigPage() {
1479  return (
1480  $this->isUserCssConfigPage()
1481  || $this->isUserJsonConfigPage()
1482  || $this->isUserJsConfigPage()
1483  );
1484  }
1485 
1492  public function getSkinFromConfigSubpage() {
1493  $subpage = explode( '/', $this->mTextform );
1494  $subpage = $subpage[count( $subpage ) - 1];
1495  $lastdot = strrpos( $subpage, '.' );
1496  if ( $lastdot === false ) {
1497  return $subpage; # Never happens: only called for names ending in '.css'/'.json'/'.js'
1498  }
1499  return substr( $subpage, 0, $lastdot );
1500  }
1501 
1508  public function isUserCssConfigPage() {
1509  return (
1510  $this->mNamespace === NS_USER
1511  && $this->isSubpage()
1512  && $this->hasContentModel( CONTENT_MODEL_CSS )
1513  );
1514  }
1515 
1522  public function isUserJsonConfigPage() {
1523  return (
1524  $this->mNamespace === NS_USER
1525  && $this->isSubpage()
1526  && $this->hasContentModel( CONTENT_MODEL_JSON )
1527  );
1528  }
1529 
1536  public function isUserJsConfigPage() {
1537  return (
1538  $this->mNamespace === NS_USER
1539  && $this->isSubpage()
1541  );
1542  }
1543 
1550  public function isSiteCssConfigPage() {
1551  return (
1552  $this->mNamespace === NS_MEDIAWIKI
1553  && (
1555  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1556  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1557  || substr( $this->mDbkeyform, -4 ) === '.css'
1558  )
1559  );
1560  }
1561 
1568  public function isSiteJsonConfigPage() {
1569  return (
1570  $this->mNamespace === NS_MEDIAWIKI
1571  && (
1573  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1574  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1575  || substr( $this->mDbkeyform, -5 ) === '.json'
1576  )
1577  );
1578  }
1579 
1586  public function isSiteJsConfigPage() {
1587  return (
1588  $this->mNamespace === NS_MEDIAWIKI
1589  && (
1591  // paranoia - a MediaWiki: namespace page with mismatching extension and content
1592  // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
1593  || substr( $this->mDbkeyform, -3 ) === '.js'
1594  )
1595  );
1596  }
1597 
1604  public function isRawHtmlMessage() {
1605  global $wgRawHtmlMessages;
1606 
1607  if ( !$this->inNamespace( NS_MEDIAWIKI ) ) {
1608  return false;
1609  }
1610  $message = lcfirst( $this->getRootTitle()->getDBkey() );
1611  return in_array( $message, $wgRawHtmlMessages, true );
1612  }
1613 
1619  public function isTalkPage() {
1620  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1621  isTalk( $this->mNamespace );
1622  }
1623 
1635  public function getTalkPage() {
1636  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1637  // Instead of failing on invalid titles, let's just log the issue for now.
1638  // See the discussion on T227817.
1639 
1640  // Is this the same title?
1641  $talkNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $this->mNamespace );
1642  if ( $this->mNamespace == $talkNS ) {
1643  return $this;
1644  }
1645 
1646  $title = self::makeTitle( $talkNS, $this->mDbkeyform );
1647 
1648  $this->warnIfPageCannotExist( $title, __METHOD__ );
1649 
1650  return $title;
1651  // TODO: replace the above with the code below:
1652  // return self::castFromLinkTarget(
1653  // MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) );
1654  }
1655 
1665  public function getTalkPageIfDefined() {
1666  if ( !$this->canHaveTalkPage() ) {
1667  return null;
1668  }
1669 
1670  return $this->getTalkPage();
1671  }
1672 
1680  public function getSubjectPage() {
1681  // Is this the same title?
1682  $subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo()
1683  ->getSubject( $this->mNamespace );
1684  if ( $this->mNamespace == $subjectNS ) {
1685  return $this;
1686  }
1687  // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
1688  // Instead of failing on invalid titles, let's just log the issue for now.
1689  // See the discussion on T227817.
1690  $title = self::makeTitle( $subjectNS, $this->mDbkeyform );
1691 
1692  $this->warnIfPageCannotExist( $title, __METHOD__ );
1693 
1694  return $title;
1695  // TODO: replace the above with the code below:
1696  // return self::castFromLinkTarget(
1697  // MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
1698  }
1699 
1706  private function warnIfPageCannotExist( Title $title, $method ) {
1707  if ( $this->getText() == '' ) {
1708  wfLogWarning(
1709  $method . ': called on empty title ' . $this->getFullText() . ', returning '
1710  . $title->getFullText()
1711  );
1712 
1713  return true;
1714  }
1715 
1716  if ( $this->getInterwiki() !== '' ) {
1717  wfLogWarning(
1718  $method . ': called on interwiki title ' . $this->getFullText() . ', returning '
1719  . $title->getFullText()
1720  );
1721 
1722  return true;
1723  }
1724 
1725  return false;
1726  }
1727 
1737  public function getOtherPage() {
1738  // NOTE: Depend on the methods in this class instead of their equivalent in NamespaceInfo,
1739  // until their semantics has become exactly the same.
1740  // See the discussion on T227817.
1741  if ( $this->isSpecialPage() ) {
1742  throw new MWException( 'Special pages cannot have other pages' );
1743  }
1744  if ( $this->isTalkPage() ) {
1745  return $this->getSubjectPage();
1746  } else {
1747  if ( !$this->canHaveTalkPage() ) {
1748  throw new MWException( "{$this->getPrefixedText()} does not have an other page" );
1749  }
1750  return $this->getTalkPage();
1751  }
1752  // TODO: replace the above with the code below:
1753  // return self::castFromLinkTarget(
1754  // MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) );
1755  }
1756 
1762  public function getDefaultNamespace() {
1763  return $this->mDefaultNamespace;
1764  }
1765 
1773  public function getFragment() {
1774  return $this->mFragment;
1775  }
1776 
1783  public function hasFragment() {
1784  return $this->mFragment !== '';
1785  }
1786 
1792  public function getFragmentForURL() {
1793  if ( !$this->hasFragment() ) {
1794  return '';
1795  } elseif ( $this->isExternal() ) {
1796  // Note: If the interwiki is unknown, it's treated as a namespace on the local wiki,
1797  // so we treat it like a local interwiki.
1798  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
1799  if ( $interwiki && !$interwiki->isLocal() ) {
1800  return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment );
1801  }
1802  }
1803 
1804  return '#' . Sanitizer::escapeIdForLink( $this->mFragment );
1805  }
1806 
1819  public function setFragment( $fragment ) {
1820  $this->mFragment = strtr( substr( $fragment, 1 ), '_', ' ' );
1821  }
1822 
1830  public function createFragmentTarget( $fragment ) {
1831  return self::makeTitle(
1832  $this->mNamespace,
1833  $this->getText(),
1834  $fragment,
1835  $this->mInterwiki
1836  );
1837  }
1838 
1846  private function prefix( $name ) {
1847  $p = '';
1848  if ( $this->isExternal() ) {
1849  $p = $this->mInterwiki . ':';
1850  }
1851 
1852  if ( $this->mNamespace != 0 ) {
1853  $nsText = $this->getNsText();
1854 
1855  if ( $nsText === false ) {
1856  // See T165149. Awkward, but better than erroneously linking to the main namespace.
1857  $nsText = MediaWikiServices::getInstance()->getContentLanguage()->
1858  getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
1859  }
1860 
1861  $p .= $nsText . ':';
1862  }
1863  return $p . $name;
1864  }
1865 
1872  public function getPrefixedDBkey() {
1873  $s = $this->prefix( $this->mDbkeyform );
1874  $s = strtr( $s, ' ', '_' );
1875  return $s;
1876  }
1877 
1884  public function getPrefixedText() {
1885  if ( $this->prefixedText === null ) {
1886  $s = $this->prefix( $this->mTextform );
1887  $s = strtr( $s, '_', ' ' );
1888  $this->prefixedText = $s;
1889  }
1890  return $this->prefixedText;
1891  }
1892 
1898  public function __toString() {
1899  return $this->getPrefixedText();
1900  }
1901 
1908  public function getFullText() {
1909  $text = $this->getPrefixedText();
1910  if ( $this->hasFragment() ) {
1911  $text .= '#' . $this->mFragment;
1912  }
1913  return $text;
1914  }
1915 
1930  private function findSubpageDivider( $text, $dir ) {
1931  $top = strlen( $text ) - 1;
1932  $bottom = 0;
1933 
1934  while ( $bottom < $top && $text[$bottom] === '/' ) {
1935  $bottom++;
1936  }
1937 
1938  if ( $top < $bottom ) {
1939  return false;
1940  }
1941 
1942  if ( $dir > 0 ) {
1943  $idx = $bottom;
1944  while ( $idx <= $top && $text[$idx] !== '/' ) {
1945  $idx++;
1946  }
1947  } else {
1948  $idx = $top;
1949  while ( $idx > $bottom && $text[$idx] !== '/' ) {
1950  $idx--;
1951  }
1952  }
1953 
1954  if ( $idx < $bottom || $idx > $top ) {
1955  return false;
1956  }
1957 
1958  if ( $idx < 1 ) {
1959  return false;
1960  }
1961 
1962  return $idx;
1963  }
1964 
1969  private function hasSubpagesEnabled() {
1970  return MediaWikiServices::getInstance()->getNamespaceInfo()->
1971  hasSubpages( $this->mNamespace );
1972  }
1973 
1989  public function getRootText() {
1990  $text = $this->getText();
1991  if ( !$this->hasSubpagesEnabled() ) {
1992  return $text;
1993  }
1994 
1995  $firstSlashPos = $this->findSubpageDivider( $text, +1 );
1996  // Don't discard the real title if there's no subpage involved
1997  if ( $firstSlashPos === false ) {
1998  return $text;
1999  }
2000 
2001  return substr( $text, 0, $firstSlashPos );
2002  }
2003 
2016  public function getRootTitle() {
2017  $title = self::makeTitleSafe( $this->mNamespace, $this->getRootText() );
2018  Assert::postcondition(
2019  $title !== null,
2020  'makeTitleSafe() should always return a Title for the text returned by getRootText().'
2021  );
2022  return $title;
2023  }
2024 
2039  public function getBaseText() {
2040  $text = $this->getText();
2041  if ( !$this->hasSubpagesEnabled() ) {
2042  return $text;
2043  }
2044 
2045  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
2046  // Don't discard the real title if there's no subpage involved
2047  if ( $lastSlashPos === false ) {
2048  return $text;
2049  }
2050 
2051  return substr( $text, 0, $lastSlashPos );
2052  }
2053 
2066  public function getBaseTitle() {
2067  $title = self::makeTitleSafe( $this->mNamespace, $this->getBaseText() );
2068  Assert::postcondition(
2069  $title !== null,
2070  'makeTitleSafe() should always return a Title for the text returned by getBaseText().'
2071  );
2072  return $title;
2073  }
2074 
2086  public function getSubpageText() {
2087  $text = $this->getText();
2088  if ( !$this->hasSubpagesEnabled() ) {
2089  return $text;
2090  }
2091 
2092  $lastSlashPos = $this->findSubpageDivider( $text, -1 );
2093  if ( $lastSlashPos === false ) {
2094  // T256922 - Return the title text if no subpages
2095  return $text;
2096  }
2097  return substr( $text, $lastSlashPos + 1 );
2098  }
2099 
2113  public function getSubpage( $text ) {
2114  return self::makeTitleSafe(
2115  $this->mNamespace,
2116  $this->getText() . '/' . $text,
2117  '',
2118  $this->mInterwiki
2119  );
2120  }
2121 
2127  public function getSubpageUrlForm() {
2128  $text = $this->getSubpageText();
2129  $text = wfUrlencode( strtr( $text, ' ', '_' ) );
2130  return $text;
2131  }
2132 
2138  public function getPrefixedURL() {
2139  $s = $this->prefix( $this->mDbkeyform );
2140  $s = wfUrlencode( strtr( $s, ' ', '_' ) );
2141  return $s;
2142  }
2143 
2157  private static function fixUrlQueryArgs( $query, $query2 = false ) {
2158  if ( $query2 !== false ) {
2159  wfDeprecatedMsg( "Title::get{Canonical,Full,Link,Local,Internal}URL " .
2160  "method called with a second parameter is deprecated since MediaWiki 1.19. " .
2161  "Add your parameter to an array passed as the first parameter.", "1.19" );
2162  }
2163  if ( is_array( $query ) ) {
2164  $query = wfArrayToCgi( $query );
2165  }
2166  if ( $query2 ) {
2167  if ( is_string( $query2 ) ) {
2168  // $query2 is a string, we will consider this to be
2169  // a deprecated $variant argument and add it to the query
2170  $query2 = wfArrayToCgi( [ 'variant' => $query2 ] );
2171  } else {
2172  $query2 = wfArrayToCgi( $query2 );
2173  }
2174  // If we have $query content add a & to it first
2175  if ( $query ) {
2176  $query .= '&';
2177  }
2178  // Now append the queries together
2179  $query .= $query2;
2180  }
2181  return $query;
2182  }
2183 
2195  public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
2196  $query = self::fixUrlQueryArgs( $query, $query2 );
2197 
2198  # Hand off all the decisions on urls to getLocalURL
2199  $url = $this->getLocalURL( $query );
2200 
2201  # Expand the url to make it a full url. Note that getLocalURL has the
2202  # potential to output full urls for a variety of reasons, so we use
2203  # wfExpandUrl instead of simply prepending $wgServer
2204  $url = wfExpandUrl( $url, $proto );
2205 
2206  # Finally, add the fragment.
2207  $url .= $this->getFragmentForURL();
2208  Hooks::runner()->onGetFullURL( $this, $url, $query );
2209  return $url;
2210  }
2211 
2228  public function getFullUrlForRedirect( $query = '', $proto = PROTO_CURRENT ) {
2229  $target = $this;
2230  if ( $this->isExternal() ) {
2231  $target = SpecialPage::getTitleFor(
2232  'GoToInterwiki',
2233  $this->getPrefixedDBkey()
2234  );
2235  }
2236  return $target->getFullURL( $query, false, $proto );
2237  }
2238 
2262  public function getLocalURL( $query = '', $query2 = false ) {
2264 
2265  $query = self::fixUrlQueryArgs( $query, $query2 );
2266 
2267  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
2268  if ( $interwiki ) {
2269  $namespace = $this->getNsText();
2270  if ( $namespace != '' ) {
2271  # Can this actually happen? Interwikis shouldn't be parsed.
2272  # Yes! It can in interwiki transclusion. But... it probably shouldn't.
2273  $namespace .= ':';
2274  }
2275  $url = $interwiki->getURL( $namespace . $this->mDbkeyform );
2276  $url = wfAppendQuery( $url, $query );
2277  } else {
2278  $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
2279  if ( $query == '' ) {
2280  $url = str_replace( '$1', $dbkey, $wgArticlePath );
2281  Hooks::runner()->onGetLocalURL__Article( $this, $url );
2282  } else {
2284  $url = false;
2285  $matches = [];
2286 
2288 
2289  if ( $articlePaths
2290  && preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
2291  ) {
2292  $action = urldecode( $matches[2] );
2293  if ( isset( $articlePaths[$action] ) ) {
2294  $query = $matches[1];
2295  if ( isset( $matches[4] ) ) {
2296  $query .= $matches[4];
2297  }
2298  $url = str_replace( '$1', $dbkey, $articlePaths[$action] );
2299  if ( $query != '' ) {
2300  $url = wfAppendQuery( $url, $query );
2301  }
2302  }
2303  }
2304 
2305  if ( $url === false
2307  && preg_match( '/^variant=([^&]*)$/', $query, $matches )
2308  && $this->getPageLanguage()->equals(
2309  MediaWikiServices::getInstance()->getContentLanguage() )
2310  && $this->getPageLanguageConverter()->hasVariants()
2311  ) {
2312  $variant = urldecode( $matches[1] );
2313  if ( $this->getPageLanguageConverter()->hasVariant( $variant ) ) {
2314  // Only do the variant replacement if the given variant is a valid
2315  // variant for the page's language.
2316  $url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath );
2317  $url = str_replace( '$1', $dbkey, $url );
2318  }
2319  }
2320 
2321  if ( $url === false ) {
2322  if ( $query == '-' ) {
2323  $query = '';
2324  }
2325  $url = "{$wgScript}?title={$dbkey}&{$query}";
2326  }
2327  }
2328  Hooks::runner()->onGetLocalURL__Internal( $this, $url, $query );
2329 
2330  // @todo FIXME: This causes breakage in various places when we
2331  // actually expected a local URL and end up with dupe prefixes.
2332  if ( $wgRequest->getVal( 'action' ) == 'render' ) {
2333  LoggerFactory::getInstance( 'T263581' )
2334  ->debug(
2335  "Title::getLocalURL called from render action",
2336  [
2337  'title' => $this->getPrefixedDBkey(),
2338  'exception' => new Exception()
2339  ]
2340  );
2341  $url = $wgServer . $url;
2342  }
2343  }
2344 
2345  if ( $wgMainPageIsDomainRoot && $this->isMainPage() && $query === '' ) {
2346  return '/';
2347  }
2348 
2349  Hooks::runner()->onGetLocalURL( $this, $url, $query );
2350  return $url;
2351  }
2352 
2370  public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
2371  if ( $this->isExternal() || $proto !== false ) {
2372  $ret = $this->getFullURL( $query, $query2, $proto );
2373  } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
2374  $ret = $this->getFragmentForURL();
2375  } else {
2376  $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
2377  }
2378  return $ret;
2379  }
2380 
2395  public function getInternalURL( $query = '', $query2 = false ) {
2396  global $wgInternalServer, $wgServer;
2397  $query = self::fixUrlQueryArgs( $query, $query2 );
2398  $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
2399  $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP );
2400  Hooks::runner()->onGetInternalURL( $this, $url, $query );
2401  return $url;
2402  }
2403 
2417  public function getCanonicalURL( $query = '', $query2 = false ) {
2418  $query = self::fixUrlQueryArgs( $query, $query2 );
2419  $url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL );
2420  Hooks::runner()->onGetCanonicalURL( $this, $url, $query );
2421  return $url;
2422  }
2423 
2429  public function getEditURL() {
2430  if ( $this->isExternal() ) {
2431  return '';
2432  }
2433  $s = $this->getLocalURL( 'action=edit' );
2434 
2435  return $s;
2436  }
2437 
2445  public static function getFilteredRestrictionTypes( $exists = true ) {
2446  global $wgRestrictionTypes;
2447  $types = $wgRestrictionTypes;
2448  if ( $exists ) {
2449  # Remove the create restriction for existing titles
2450  $types = array_diff( $types, [ 'create' ] );
2451  } else {
2452  # Only the create and upload restrictions apply to non-existing titles
2453  $types = array_intersect( $types, [ 'create', 'upload' ] );
2454  }
2455  return $types;
2456  }
2457 
2463  public function getRestrictionTypes() {
2464  if ( $this->isSpecialPage() ) {
2465  return [];
2466  }
2467 
2468  $types = self::getFilteredRestrictionTypes( $this->exists() );
2469 
2470  if ( $this->mNamespace !== NS_FILE ) {
2471  # Remove the upload restriction for non-file titles
2472  $types = array_diff( $types, [ 'upload' ] );
2473  }
2474 
2475  Hooks::runner()->onTitleGetRestrictionTypes( $this, $types );
2476 
2477  wfDebug( __METHOD__ . ': applicable restrictions to [[' .
2478  $this->getPrefixedText() . ']] are {' . implode( ',', $types ) . "}" );
2479 
2480  return $types;
2481  }
2482 
2490  public function getTitleProtection() {
2491  $protection = $this->getTitleProtectionInternal();
2492  if ( $protection ) {
2493  if ( $protection['permission'] == 'sysop' ) {
2494  $protection['permission'] = 'editprotected'; // B/C
2495  }
2496  if ( $protection['permission'] == 'autoconfirmed' ) {
2497  $protection['permission'] = 'editsemiprotected'; // B/C
2498  }
2499  }
2500  return $protection;
2501  }
2502 
2513  protected function getTitleProtectionInternal() {
2514  // Can't protect pages in special namespaces
2515  if ( $this->mNamespace < 0 ) {
2516  return false;
2517  }
2518 
2519  // Can't protect pages that exist.
2520  if ( $this->exists() ) {
2521  return false;
2522  }
2523 
2524  if ( $this->mTitleProtection === null ) {
2525  $dbr = wfGetDB( DB_REPLICA );
2526  $commentStore = CommentStore::getStore();
2527  $commentQuery = $commentStore->getJoin( 'pt_reason' );
2528  $res = $dbr->select(
2529  [ 'protected_titles' ] + $commentQuery['tables'],
2530  [
2531  'user' => 'pt_user',
2532  'expiry' => 'pt_expiry',
2533  'permission' => 'pt_create_perm'
2534  ] + $commentQuery['fields'],
2535  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2536  __METHOD__,
2537  [],
2538  $commentQuery['joins']
2539  );
2540 
2541  // fetchRow returns false if there are no rows.
2542  $row = $dbr->fetchRow( $res );
2543  if ( $row ) {
2544  $this->mTitleProtection = [
2545  'user' => $row['user'],
2546  'expiry' => $dbr->decodeExpiry( $row['expiry'] ),
2547  'permission' => $row['permission'],
2548  'reason' => $commentStore->getComment( 'pt_reason', $row )->text,
2549  ];
2550  } else {
2551  $this->mTitleProtection = false;
2552  }
2553  }
2554  return $this->mTitleProtection;
2555  }
2556 
2560  public function deleteTitleProtection() {
2561  $dbw = wfGetDB( DB_MASTER );
2562 
2563  $dbw->delete(
2564  'protected_titles',
2565  [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
2566  __METHOD__
2567  );
2568  $this->mTitleProtection = false;
2569  }
2570 
2578  public function isSemiProtected( $action = 'edit' ) {
2580 
2581  $restrictions = $this->getRestrictions( $action );
2583  if ( !$restrictions || !$semi ) {
2584  // Not protected, or all protection is full protection
2585  return false;
2586  }
2587 
2588  // Remap autoconfirmed to editsemiprotected for BC
2589  foreach ( array_keys( $semi, 'autoconfirmed' ) as $key ) {
2590  $semi[$key] = 'editsemiprotected';
2591  }
2592  foreach ( array_keys( $restrictions, 'autoconfirmed' ) as $key ) {
2593  $restrictions[$key] = 'editsemiprotected';
2594  }
2595 
2596  return !array_diff( $restrictions, $semi );
2597  }
2598 
2606  public function isProtected( $action = '' ) {
2607  global $wgRestrictionLevels;
2608 
2609  $restrictionTypes = $this->getRestrictionTypes();
2610 
2611  # Special pages have inherent protection
2612  if ( $this->isSpecialPage() ) {
2613  return true;
2614  }
2615 
2616  # Check regular protection levels
2617  foreach ( $restrictionTypes as $type ) {
2618  if ( $action == $type || $action == '' ) {
2619  $r = $this->getRestrictions( $type );
2620  foreach ( $wgRestrictionLevels as $level ) {
2621  if ( in_array( $level, $r ) && $level != '' ) {
2622  return true;
2623  }
2624  }
2625  }
2626  }
2627 
2628  return false;
2629  }
2630 
2639  public function isNamespaceProtected( User $user ) {
2640  global $wgNamespaceProtection;
2641 
2642  if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
2643  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2644  foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
2645  if ( !$permissionManager->userHasRight( $user, $right ) ) {
2646  return true;
2647  }
2648  }
2649  }
2650  return false;
2651  }
2652 
2658  public function isCascadeProtected() {
2659  list( $isCascadeProtected, ) = $this->getCascadeProtectionSources( false );
2660  return $isCascadeProtected;
2661  }
2662 
2672  public function areCascadeProtectionSourcesLoaded( $getPages = true ) {
2673  return $getPages ? $this->mCascadeSources !== null : $this->mHasCascadingRestrictions !== null;
2674  }
2675 
2689  public function getCascadeProtectionSources( $getPages = true ) {
2690  $pagerestrictions = [];
2691 
2692  if ( $this->mCascadeSources !== null && $getPages ) {
2694  } elseif ( $this->mHasCascadingRestrictions !== null && !$getPages ) {
2695  return [ $this->mHasCascadingRestrictions, $pagerestrictions ];
2696  }
2697 
2698  $dbr = wfGetDB( DB_REPLICA );
2699 
2700  if ( $this->mNamespace === NS_FILE ) {
2701  $tables = [ 'imagelinks', 'page_restrictions' ];
2702  $where_clauses = [
2703  'il_to' => $this->mDbkeyform,
2704  'il_from=pr_page',
2705  'pr_cascade' => 1
2706  ];
2707  } else {
2708  $tables = [ 'templatelinks', 'page_restrictions' ];
2709  $where_clauses = [
2710  'tl_namespace' => $this->mNamespace,
2711  'tl_title' => $this->mDbkeyform,
2712  'tl_from=pr_page',
2713  'pr_cascade' => 1
2714  ];
2715  }
2716 
2717  if ( $getPages ) {
2718  $cols = [ 'pr_page', 'page_namespace', 'page_title',
2719  'pr_expiry', 'pr_type', 'pr_level' ];
2720  $where_clauses[] = 'page_id=pr_page';
2721  $tables[] = 'page';
2722  } else {
2723  $cols = [ 'pr_expiry' ];
2724  }
2725 
2726  $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__ );
2727 
2728  $sources = $getPages ? [] : false;
2729  $now = wfTimestampNow();
2730 
2731  foreach ( $res as $row ) {
2732  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2733  if ( $expiry > $now ) {
2734  if ( $getPages ) {
2735  $page_id = $row->pr_page;
2736  $page_ns = $row->page_namespace;
2737  $page_title = $row->page_title;
2738  $sources[$page_id] = self::makeTitle( $page_ns, $page_title );
2739  # Add groups needed for each restriction type if its not already there
2740  # Make sure this restriction type still exists
2741 
2742  if ( !isset( $pagerestrictions[$row->pr_type] ) ) {
2743  $pagerestrictions[$row->pr_type] = [];
2744  }
2745 
2746  if (
2747  isset( $pagerestrictions[$row->pr_type] )
2748  && !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] )
2749  ) {
2750  $pagerestrictions[$row->pr_type][] = $row->pr_level;
2751  }
2752  } else {
2753  $sources = true;
2754  }
2755  }
2756  }
2757 
2758  if ( $getPages ) {
2759  $this->mCascadeSources = $sources;
2760  $this->mCascadingRestrictions = $pagerestrictions;
2761  } else {
2762  $this->mHasCascadingRestrictions = $sources;
2763  }
2764 
2765  return [ $sources, $pagerestrictions ];
2766  }
2767 
2775  public function areRestrictionsLoaded() {
2777  }
2778 
2788  public function getRestrictions( $action ) {
2789  if ( !$this->mRestrictionsLoaded ) {
2790  $this->loadRestrictions();
2791  }
2792  return $this->mRestrictions[$action] ?? [];
2793  }
2794 
2802  public function getAllRestrictions() {
2803  if ( !$this->mRestrictionsLoaded ) {
2804  $this->loadRestrictions();
2805  }
2806  return $this->mRestrictions;
2807  }
2808 
2816  public function getRestrictionExpiry( $action ) {
2817  if ( !$this->mRestrictionsLoaded ) {
2818  $this->loadRestrictions();
2819  }
2820  return $this->mRestrictionsExpiry[$action] ?? false;
2821  }
2822 
2828  public function areRestrictionsCascading() {
2829  if ( !$this->mRestrictionsLoaded ) {
2830  $this->loadRestrictions();
2831  }
2832 
2834  }
2835 
2847  public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
2848  // This function will only read rows from a table that we migrated away
2849  // from before adding READ_LATEST support to loadRestrictions, so we
2850  // don't need to support reading from DB_MASTER here.
2851  $dbr = wfGetDB( DB_REPLICA );
2852 
2853  $restrictionTypes = $this->getRestrictionTypes();
2854 
2855  foreach ( $restrictionTypes as $type ) {
2856  $this->mRestrictions[$type] = [];
2857  $this->mRestrictionsExpiry[$type] = 'infinity';
2858  }
2859 
2860  $this->mCascadeRestriction = false;
2861 
2862  # Backwards-compatibility: also load the restrictions from the page record (old format).
2863  if ( $oldFashionedRestrictions !== null ) {
2864  $this->mOldRestrictions = $oldFashionedRestrictions;
2865  }
2866 
2867  if ( $this->mOldRestrictions === false ) {
2868  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
2869  $linkCache->addLinkObj( $this ); # in case we already had an article ID
2870  $this->mOldRestrictions = $linkCache->getGoodLinkFieldObj( $this, 'restrictions' );
2871  }
2872 
2873  if ( $this->mOldRestrictions != '' ) {
2874  foreach ( explode( ':', trim( $this->mOldRestrictions ) ) as $restrict ) {
2875  $temp = explode( '=', trim( $restrict ) );
2876  if ( count( $temp ) == 1 ) {
2877  // old old format should be treated as edit/move restriction
2878  $this->mRestrictions['edit'] = explode( ',', trim( $temp[0] ) );
2879  $this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) );
2880  } else {
2881  $restriction = trim( $temp[1] );
2882  if ( $restriction != '' ) { // some old entries are empty
2883  $this->mRestrictions[$temp[0]] = explode( ',', $restriction );
2884  }
2885  }
2886  }
2887  }
2888 
2889  if ( count( $rows ) ) {
2890  # Current system - load second to make them override.
2891  $now = wfTimestampNow();
2892 
2893  # Cycle through all the restrictions.
2894  foreach ( $rows as $row ) {
2895  // Don't take care of restrictions types that aren't allowed
2896  if ( !in_array( $row->pr_type, $restrictionTypes ) ) {
2897  continue;
2898  }
2899 
2900  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2901 
2902  // Only apply the restrictions if they haven't expired!
2903  if ( !$expiry || $expiry > $now ) {
2904  $this->mRestrictionsExpiry[$row->pr_type] = $expiry;
2905  $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) );
2906 
2907  $this->mCascadeRestriction = $this->mCascadeRestriction || $row->pr_cascade;
2908  }
2909  }
2910  }
2911 
2912  $this->mRestrictionsLoaded = true;
2913  }
2914 
2925  public function loadRestrictions( $oldFashionedRestrictions = null, $flags = 0 ) {
2926  $readLatest = DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST );
2927  if ( $this->mRestrictionsLoaded && !$readLatest ) {
2928  return;
2929  }
2930 
2931  $id = $this->getArticleID( $flags );
2932  if ( $id ) {
2933  $fname = __METHOD__;
2934  $loadRestrictionsFromDb = function ( IDatabase $dbr ) use ( $fname, $id ) {
2935  return iterator_to_array(
2936  $dbr->select(
2937  'page_restrictions',
2938  [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
2939  [ 'pr_page' => $id ],
2940  $fname
2941  )
2942  );
2943  };
2944 
2945  if ( $readLatest ) {
2946  $dbr = wfGetDB( DB_MASTER );
2947  $rows = $loadRestrictionsFromDb( $dbr );
2948  } else {
2949  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
2950  $rows = $cache->getWithSetCallback(
2951  // Page protections always leave a new null revision
2952  $cache->makeKey( 'page-restrictions', 'v1', $id, $this->getLatestRevID() ),
2953  $cache::TTL_DAY,
2954  function ( $curValue, &$ttl, array &$setOpts ) use ( $loadRestrictionsFromDb ) {
2955  $dbr = wfGetDB( DB_REPLICA );
2956 
2957  $setOpts += Database::getCacheSetOptions( $dbr );
2958  $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
2959  if ( $lb->hasOrMadeRecentMasterChanges() ) {
2960  // @TODO: cleanup Title cache and caller assumption mess in general
2961  $ttl = WANObjectCache::TTL_UNCACHEABLE;
2962  }
2963 
2964  return $loadRestrictionsFromDb( $dbr );
2965  }
2966  );
2967  }
2968 
2969  $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
2970  } else {
2971  $title_protection = $this->getTitleProtectionInternal();
2972 
2973  if ( $title_protection ) {
2974  $now = wfTimestampNow();
2975  $expiry = wfGetDB( DB_REPLICA )->decodeExpiry( $title_protection['expiry'] );
2976 
2977  if ( !$expiry || $expiry > $now ) {
2978  // Apply the restrictions
2979  $this->mRestrictionsExpiry['create'] = $expiry;
2980  $this->mRestrictions['create'] =
2981  explode( ',', trim( $title_protection['permission'] ) );
2982  } else { // Get rid of the old restrictions
2983  $this->mTitleProtection = false;
2984  }
2985  } else {
2986  $this->mRestrictionsExpiry['create'] = 'infinity';
2987  }
2988  $this->mRestrictionsLoaded = true;
2989  }
2990  }
2991 
2996  public function flushRestrictions() {
2997  $this->mRestrictionsLoaded = false;
2998  $this->mTitleProtection = null;
2999  }
3000 
3006  public static function purgeExpiredRestrictions() {
3007  if ( wfReadOnly() ) {
3008  return;
3009  }
3010 
3012  wfGetDB( DB_MASTER ),
3013  __METHOD__,
3014  function ( IDatabase $dbw, $fname ) {
3015  $config = MediaWikiServices::getInstance()->getMainConfig();
3016  $ids = $dbw->selectFieldValues(
3017  'page_restrictions',
3018  'pr_id',
3019  [ 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3020  $fname,
3021  [ 'LIMIT' => $config->get( 'UpdateRowsPerQuery' ) ] // T135470
3022  );
3023  if ( $ids ) {
3024  $dbw->delete( 'page_restrictions', [ 'pr_id' => $ids ], $fname );
3025  }
3026  }
3027  ) );
3028 
3030  wfGetDB( DB_MASTER ),
3031  __METHOD__,
3032  function ( IDatabase $dbw, $fname ) {
3033  $dbw->delete(
3034  'protected_titles',
3035  [ 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3036  $fname
3037  );
3038  }
3039  ) );
3040  }
3041 
3047  public function hasSubpages() {
3048  if (
3049  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3050  hasSubpages( $this->mNamespace )
3051  ) {
3052  # Duh
3053  return false;
3054  }
3055 
3056  # We dynamically add a member variable for the purpose of this method
3057  # alone to cache the result. There's no point in having it hanging
3058  # around uninitialized in every Title object; therefore we only add it
3059  # if needed and don't declare it statically.
3060  if ( $this->mHasSubpages === null ) {
3061  $this->mHasSubpages = false;
3062  $subpages = $this->getSubpages( 1 );
3063  if ( $subpages instanceof TitleArray ) {
3064  $this->mHasSubpages = (bool)$subpages->current();
3065  }
3066  }
3067 
3068  return $this->mHasSubpages;
3069  }
3070 
3078  public function getSubpages( $limit = -1 ) {
3079  if (
3080  !MediaWikiServices::getInstance()->getNamespaceInfo()->
3081  hasSubpages( $this->mNamespace )
3082  ) {
3083  return [];
3084  }
3085 
3086  $dbr = wfGetDB( DB_REPLICA );
3087  $conds = [ 'page_namespace' => $this->mNamespace ];
3088  $conds[] = 'page_title ' . $dbr->buildLike( $this->mDbkeyform . '/', $dbr->anyString() );
3089  $options = [];
3090  if ( $limit > -1 ) {
3091  $options['LIMIT'] = $limit;
3092  }
3094  $dbr->select( 'page',
3095  [ 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ],
3096  $conds,
3097  __METHOD__,
3098  $options
3099  )
3100  );
3101  }
3102 
3109  public function isDeleted() {
3110  return $this->getDeletedEditsCount();
3111  }
3112 
3119  public function getDeletedEditsCount() {
3120  if ( $this->mNamespace < 0 ) {
3121  $n = 0;
3122  } else {
3123  $dbr = wfGetDB( DB_REPLICA );
3124 
3125  $n = $dbr->selectField( 'archive', 'COUNT(*)',
3126  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3127  __METHOD__
3128  );
3129  if ( $this->mNamespace === NS_FILE ) {
3130  $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
3131  [ 'fa_name' => $this->mDbkeyform ],
3132  __METHOD__
3133  );
3134  }
3135  }
3136  return (int)$n;
3137  }
3138 
3145  public function isDeletedQuick() {
3146  return $this->hasDeletedEdits();
3147  }
3148 
3155  public function hasDeletedEdits() {
3156  if ( $this->mNamespace < 0 ) {
3157  return false;
3158  }
3159  $dbr = wfGetDB( DB_REPLICA );
3160  $deleted = (bool)$dbr->selectField( 'archive', '1',
3161  [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
3162  __METHOD__
3163  );
3164  if ( !$deleted && $this->mNamespace === NS_FILE ) {
3165  $deleted = (bool)$dbr->selectField( 'filearchive', '1',
3166  [ 'fa_name' => $this->mDbkeyform ],
3167  __METHOD__
3168  );
3169  }
3170  return $deleted;
3171  }
3172 
3180  public function getArticleID( $flags = 0 ) {
3181  if ( $this->mNamespace < 0 ) {
3182  $this->mArticleID = 0;
3183 
3184  return $this->mArticleID;
3185  }
3186 
3187  if ( $flags & self::GAID_FOR_UPDATE ) {
3188  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3189  $oldUpdate = $linkCache->forUpdate( true );
3190  $linkCache->clearLink( $this );
3191  $this->mArticleID = $linkCache->addLinkObj( $this );
3192  $linkCache->forUpdate( $oldUpdate );
3193  } elseif ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3194  // If mArticleID is >0, pageCond() will use it, making it impossible
3195  // for the call below to return a different result, e.g. after a
3196  // page move.
3197  $this->mArticleID = -1;
3198  $this->mArticleID = (int)$this->loadFieldFromDB( 'page_id', $flags );
3199  } elseif ( $this->mArticleID == -1 ) {
3200  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3201  $this->mArticleID = $linkCache->addLinkObj( $this );
3202  }
3203 
3204  return $this->mArticleID;
3205  }
3206 
3214  public function isRedirect( $flags = 0 ) {
3215  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3216  $this->mRedirect = (bool)$this->loadFieldFromDB( 'page_is_redirect', $flags );
3217  } elseif ( $this->mRedirect === null ) {
3218  if ( $this->getArticleID( $flags ) ) {
3219  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3220  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3221  // Note that LinkCache returns null if it thinks the page does not exist;
3222  // always trust the state of LinkCache over that of this Title instance.
3223  $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
3224  } else {
3225  $this->mRedirect = false;
3226  }
3227  }
3228 
3229  return $this->mRedirect;
3230  }
3231 
3239  public function getLength( $flags = 0 ) {
3240  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3241  $this->mLength = (int)$this->loadFieldFromDB( 'page_len', $flags );
3242  } else {
3243  if ( $this->mLength != -1 ) {
3244  return $this->mLength;
3245  } elseif ( !$this->getArticleID( $flags ) ) {
3246  $this->mLength = 0;
3247  return $this->mLength;
3248  }
3249 
3250  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3251  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3252  // Note that LinkCache returns null if it thinks the page does not exist;
3253  // always trust the state of LinkCache over that of this Title instance.
3254  $this->mLength = (int)$linkCache->getGoodLinkFieldObj( $this, 'length' );
3255  }
3256 
3257  return $this->mLength;
3258  }
3259 
3266  public function getLatestRevID( $flags = 0 ) {
3267  if ( DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ) ) {
3268  $this->mLatestID = (int)$this->loadFieldFromDB( 'page_latest', $flags );
3269  } else {
3270  if ( $this->mLatestID !== false ) {
3271  return (int)$this->mLatestID;
3272  } elseif ( !$this->getArticleID( $flags ) ) {
3273  $this->mLatestID = 0;
3274 
3275  return $this->mLatestID;
3276  }
3277 
3278  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3279  $linkCache->addLinkObj( $this ); // in case we already had an article ID
3280  // Note that LinkCache returns null if it thinks the page does not exist;
3281  // always trust the state of LinkCache over that of this Title instance.
3282  $this->mLatestID = (int)$linkCache->getGoodLinkFieldObj( $this, 'revision' );
3283  }
3284 
3285  return $this->mLatestID;
3286  }
3287 
3301  public function resetArticleID( $id ) {
3302  if ( $id === false ) {
3303  $this->mArticleID = -1;
3304  } else {
3305  $this->mArticleID = (int)$id;
3306  }
3307  $this->mRestrictionsLoaded = false;
3308  $this->mRestrictions = [];
3309  $this->mOldRestrictions = false;
3310  $this->mRedirect = null;
3311  $this->mLength = -1;
3312  $this->mLatestID = false;
3313  $this->mContentModel = false;
3314  $this->mForcedContentModel = false;
3315  $this->mEstimateRevisions = null;
3316  $this->mPageLanguage = null;
3317  $this->mDbPageLanguage = false;
3318  $this->mIsBigDeletion = null;
3319 
3320  MediaWikiServices::getInstance()->getLinkCache()->clearLink( $this );
3321  }
3322 
3323  public static function clearCaches() {
3324  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3325  $linkCache->clear();
3326 
3328  $titleCache->clear();
3329  }
3330 
3338  public static function capitalize( $text, $ns = NS_MAIN ) {
3339  $services = MediaWikiServices::getInstance();
3340  if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) {
3341  return $services->getContentLanguage()->ucfirst( $text );
3342  } else {
3343  return $text;
3344  }
3345  }
3346 
3363  private function secureAndSplit( $text, $defaultNamespace = null ) {
3364  if ( $defaultNamespace === null ) {
3365  $defaultNamespace = $this->mDefaultNamespace;
3366  }
3367 
3368  // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
3369  // the parsing code with Title, while avoiding massive refactoring.
3370  // @todo: get rid of secureAndSplit, refactor parsing code.
3371  // @note: getTitleParser() returns a TitleParser implementation which does not have a
3372  // splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
3374  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
3375  '@phan-var MediaWikiTitleCodec $titleCodec';
3376  // MalformedTitleException can be thrown here
3377  $parts = $titleCodec->splitTitleString( $text, $defaultNamespace );
3378 
3379  # Fill fields
3380  $this->setFragment( '#' . $parts['fragment'] );
3381  $this->mInterwiki = $parts['interwiki'];
3382  $this->mLocalInterwiki = $parts['local_interwiki'];
3383  $this->mNamespace = $parts['namespace'];
3384  $this->mDefaultNamespace = $defaultNamespace;
3385 
3386  $this->mDbkeyform = $parts['dbkey'];
3387  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
3388  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
3389 
3390  // splitTitleString() guarantees that this title is valid.
3391  $this->mIsValid = true;
3392 
3393  # We already know that some pages won't be in the database!
3394  if ( $this->isExternal() || $this->isSpecialPage() || $this->mTextform === '' ) {
3395  $this->mArticleID = 0;
3396  }
3397  }
3398 
3411  public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3412  if ( count( $options ) > 0 ) {
3413  $db = wfGetDB( DB_MASTER );
3414  } else {
3415  $db = wfGetDB( DB_REPLICA );
3416  }
3417 
3418  $res = $db->select(
3419  [ 'page', $table ],
3420  self::getSelectFields(),
3421  [
3422  "{$prefix}_from=page_id",
3423  "{$prefix}_namespace" => $this->mNamespace,
3424  "{$prefix}_title" => $this->mDbkeyform ],
3425  __METHOD__,
3426  $options
3427  );
3428 
3429  $retVal = [];
3430  if ( $res->numRows() ) {
3431  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3432  foreach ( $res as $row ) {
3433  $titleObj = self::makeTitle( $row->page_namespace, $row->page_title );
3434  if ( $titleObj ) {
3435  $linkCache->addGoodLinkObjFromRow( $titleObj, $row );
3436  $retVal[] = $titleObj;
3437  }
3438  }
3439  }
3440  return $retVal;
3441  }
3442 
3453  public function getTemplateLinksTo( $options = [] ) {
3454  return $this->getLinksTo( $options, 'templatelinks', 'tl' );
3455  }
3456 
3469  public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3470  $id = $this->getArticleID();
3471 
3472  # If the page doesn't exist; there can't be any link from this page
3473  if ( !$id ) {
3474  return [];
3475  }
3476 
3477  $db = wfGetDB( DB_REPLICA );
3478 
3479  $blNamespace = "{$prefix}_namespace";
3480  $blTitle = "{$prefix}_title";
3481 
3482  $pageQuery = WikiPage::getQueryInfo();
3483  $res = $db->select(
3484  [ $table, 'nestpage' => $pageQuery['tables'] ],
3485  array_merge(
3486  [ $blNamespace, $blTitle ],
3487  $pageQuery['fields']
3488  ),
3489  [ "{$prefix}_from" => $id ],
3490  __METHOD__,
3491  $options,
3492  [ 'nestpage' => [
3493  'LEFT JOIN',
3494  [ "page_namespace=$blNamespace", "page_title=$blTitle" ]
3495  ] ] + $pageQuery['joins']
3496  );
3497 
3498  $retVal = [];
3499  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3500  foreach ( $res as $row ) {
3501  if ( $row->page_id ) {
3502  $titleObj = self::newFromRow( $row );
3503  } else {
3504  $titleObj = self::makeTitle( $row->$blNamespace, $row->$blTitle );
3505  $linkCache->addBadLinkObj( $titleObj );
3506  }
3507  $retVal[] = $titleObj;
3508  }
3509 
3510  return $retVal;
3511  }
3512 
3523  public function getTemplateLinksFrom( $options = [] ) {
3524  return $this->getLinksFrom( $options, 'templatelinks', 'tl' );
3525  }
3526 
3535  public function getBrokenLinksFrom() {
3536  if ( $this->getArticleID() == 0 ) {
3537  # All links from article ID 0 are false positives
3538  return [];
3539  }
3540 
3541  $dbr = wfGetDB( DB_REPLICA );
3542  $res = $dbr->select(
3543  [ 'page', 'pagelinks' ],
3544  [ 'pl_namespace', 'pl_title' ],
3545  [
3546  'pl_from' => $this->getArticleID(),
3547  'page_namespace IS NULL'
3548  ],
3549  __METHOD__, [],
3550  [
3551  'page' => [
3552  'LEFT JOIN',
3553  [ 'pl_namespace=page_namespace', 'pl_title=page_title' ]
3554  ]
3555  ]
3556  );
3557 
3558  $retVal = [];
3559  foreach ( $res as $row ) {
3560  $retVal[] = self::makeTitle( $row->pl_namespace, $row->pl_title );
3561  }
3562  return $retVal;
3563  }
3564 
3571  public function getCdnUrls() {
3572  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3573  return $htmlCache->getUrls( $this );
3574  }
3575 
3580  public function purgeSquid() {
3581  $htmlCache = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
3582  $htmlCache->purgeTitleUrls( $this, $htmlCache::PURGE_INTENT_TXROUND_REFLECTED );
3583  }
3584 
3592  public function isSingleRevRedirect() {
3593  $dbw = wfGetDB( DB_MASTER );
3594  $dbw->startAtomic( __METHOD__ );
3595 
3596  $row = $dbw->selectRow(
3597  'page',
3598  self::getSelectFields(),
3599  $this->pageCond(),
3600  __METHOD__,
3601  [ 'FOR UPDATE' ]
3602  );
3603  // Update the cached fields
3604  $this->loadFromRow( $row );
3605 
3606  if ( $this->mRedirect && $this->mLatestID ) {
3607  $isSingleRevRedirect = !$dbw->selectField(
3608  'revision',
3609  '1',
3610  [ 'rev_page' => $this->mArticleID, 'rev_id != ' . (int)$this->mLatestID ],
3611  __METHOD__,
3612  [ 'FOR UPDATE' ]
3613  );
3614  } else {
3615  $isSingleRevRedirect = false;
3616  }
3617 
3618  $dbw->endAtomic( __METHOD__ );
3619 
3620  return $isSingleRevRedirect;
3621  }
3622 
3630  public function getParentCategories() {
3631  $data = [];
3632 
3633  $titleKey = $this->getArticleID();
3634 
3635  if ( $titleKey === 0 ) {
3636  return $data;
3637  }
3638 
3639  $dbr = wfGetDB( DB_REPLICA );
3640 
3641  $res = $dbr->select(
3642  'categorylinks',
3643  'cl_to',
3644  [ 'cl_from' => $titleKey ],
3645  __METHOD__
3646  );
3647 
3648  if ( $res->numRows() > 0 ) {
3649  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
3650  foreach ( $res as $row ) {
3651  // $data[] = Title::newFromText( $contLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
3652  $data[$contLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] =
3653  $this->getFullText();
3654  }
3655  }
3656  return $data;
3657  }
3658 
3665  public function getParentCategoryTree( $children = [] ) {
3666  $stack = [];
3667  $parents = $this->getParentCategories();
3668 
3669  if ( $parents ) {
3670  foreach ( $parents as $parent => $current ) {
3671  if ( array_key_exists( $parent, $children ) ) {
3672  # Circular reference
3673  $stack[$parent] = [];
3674  } else {
3675  $nt = self::newFromText( $parent );
3676  if ( $nt ) {
3677  $stack[$parent] = $nt->getParentCategoryTree( $children + [ $parent => 1 ] );
3678  }
3679  }
3680  }
3681  }
3682 
3683  return $stack;
3684  }
3685 
3692  public function pageCond() {
3693  if ( $this->mArticleID > 0 ) {
3694  // PK avoids secondary lookups in InnoDB, shouldn't hurt other DBs
3695  return [ 'page_id' => $this->mArticleID ];
3696  } else {
3697  return [ 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform ];
3698  }
3699  }
3700 
3708  private function getRelativeRevisionID( $revId, $flags, $dir ) {
3709  $rl = MediaWikiServices::getInstance()->getRevisionLookup();
3710  $rev = $rl->getRevisionById( $revId, $flags );
3711  if ( !$rev ) {
3712  return false;
3713  }
3714 
3715  $oldRev = ( $dir === 'next' )
3716  ? $rl->getNextRevision( $rev, $flags )
3717  : $rl->getPreviousRevision( $rev, $flags );
3718 
3719  return $oldRev ? $oldRev->getId() : false;
3720  }
3721 
3730  public function getPreviousRevisionID( $revId, $flags = 0 ) {
3731  return $this->getRelativeRevisionID( $revId, $flags, 'prev' );
3732  }
3733 
3742  public function getNextRevisionID( $revId, $flags = 0 ) {
3743  return $this->getRelativeRevisionID( $revId, $flags, 'next' );
3744  }
3745 
3753  public function getFirstRevision( $flags = 0 ) {
3754  wfDeprecated( __METHOD__, '1.35' );
3755  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
3756  $rev = MediaWikiServices::getInstance()
3757  ->getRevisionLookup()
3758  ->getFirstRevision( $this, $flags );
3759  return $rev ? new Revision( $rev ) : null;
3760  }
3761 
3769  public function getEarliestRevTime( $flags = 0 ) {
3770  $rev = MediaWikiServices::getInstance()
3771  ->getRevisionLookup()
3772  ->getFirstRevision( $this, $flags );
3773  return $rev ? $rev->getTimestamp() : null;
3774  }
3775 
3781  public function isNewPage() {
3782  $dbr = wfGetDB( DB_REPLICA );
3783  return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ );
3784  }
3785 
3791  public function isBigDeletion() {
3792  global $wgDeleteRevisionsLimit;
3793 
3794  if ( !$wgDeleteRevisionsLimit ) {
3795  return false;
3796  }
3797 
3798  if ( $this->mIsBigDeletion === null ) {
3799  $dbr = wfGetDB( DB_REPLICA );
3800 
3801  $revCount = $dbr->selectRowCount(
3802  'revision',
3803  '1',
3804  [ 'rev_page' => $this->getArticleID() ],
3805  __METHOD__,
3806  [ 'LIMIT' => $wgDeleteRevisionsLimit + 1 ]
3807  );
3808 
3809  $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit;
3810  }
3811 
3812  return $this->mIsBigDeletion;
3813  }
3814 
3820  public function estimateRevisionCount() {
3821  if ( !$this->exists() ) {
3822  return 0;
3823  }
3824 
3825  if ( $this->mEstimateRevisions === null ) {
3826  $dbr = wfGetDB( DB_REPLICA );
3827  $this->mEstimateRevisions = $dbr->estimateRowCount( 'revision', '*',
3828  [ 'rev_page' => $this->getArticleID() ], __METHOD__ );
3829  }
3830 
3832  }
3833 
3845  public function countRevisionsBetween( $old, $new, $max = null ) {
3846  wfDeprecated( __METHOD__, '1.35' );
3847  if ( !( $old instanceof Revision ) ) {
3848  $old = Revision::newFromTitle( $this, (int)$old );
3849  }
3850  if ( !( $new instanceof Revision ) ) {
3851  $new = Revision::newFromTitle( $this, (int)$new );
3852  }
3853  if ( !$old || !$new ) {
3854  return 0; // nothing to compare
3855  }
3856  return MediaWikiServices::getInstance()
3857  ->getRevisionStore()
3858  ->countRevisionsBetween(
3859  $this->getArticleID(),
3860  $old->getRevisionRecord(),
3861  $new->getRevisionRecord(),
3862  $max
3863  );
3864  }
3865 
3883  public function getAuthorsBetween( $old, $new, $limit, $options = [] ) {
3884  wfDeprecated( __METHOD__, '1.35' );
3885  if ( !( $old instanceof Revision ) ) {
3886  $old = Revision::newFromTitle( $this, (int)$old );
3887  }
3888  if ( !( $new instanceof Revision ) ) {
3889  $new = Revision::newFromTitle( $this, (int)$new );
3890  }
3891  try {
3892  $users = MediaWikiServices::getInstance()
3893  ->getRevisionStore()
3894  ->getAuthorsBetween(
3895  $this->getArticleID(),
3896  $old->getRevisionRecord(),
3897  $new->getRevisionRecord(),
3898  null,
3899  $limit,
3900  $options
3901  );
3902  return array_map( function ( UserIdentity $user ) {
3903  return $user->getName();
3904  }, $users );
3905  } catch ( InvalidArgumentException $e ) {
3906  return null; // b/c
3907  }
3908  }
3909 
3926  public function countAuthorsBetween( $old, $new, $limit, $options = [] ) {
3927  wfDeprecated( __METHOD__, '1.35' );
3928  $authors = $this->getAuthorsBetween( $old, $new, $limit, $options );
3929  return $authors ? count( $authors ) : 0;
3930  }
3931 
3938  public function equals( LinkTarget $title ) {
3939  // Note: === is necessary for proper matching of number-like titles.
3940  return $this->mInterwiki === $title->getInterwiki()
3941  && $this->mNamespace == $title->getNamespace()
3942  && $this->mDbkeyform === $title->getDBkey();
3943  }
3944 
3951  public function isSubpageOf( Title $title ) {
3952  return $this->mInterwiki === $title->mInterwiki
3953  && $this->mNamespace == $title->mNamespace
3954  && strpos( $this->mDbkeyform, $title->mDbkeyform . '/' ) === 0;
3955  }
3956 
3967  public function exists( $flags = 0 ) {
3968  $exists = $this->getArticleID( $flags ) != 0;
3969  Hooks::runner()->onTitleExists( $this, $exists );
3970  return $exists;
3971  }
3972 
3989  public function isAlwaysKnown() {
3990  $isKnown = null;
3991 
4002  Hooks::runner()->onTitleIsAlwaysKnown( $this, $isKnown );
4003 
4004  if ( $isKnown !== null ) {
4005  return $isKnown;
4006  }
4007 
4008  if ( $this->isExternal() ) {
4009  return true; // any interwiki link might be viewable, for all we know
4010  }
4011 
4012  $services = MediaWikiServices::getInstance();
4013  switch ( $this->mNamespace ) {
4014  case NS_MEDIA:
4015  case NS_FILE:
4016  // file exists, possibly in a foreign repo
4017  return (bool)$services->getRepoGroup()->findFile( $this );
4018  case NS_SPECIAL:
4019  // valid special page
4020  return $services->getSpecialPageFactory()->exists( $this->mDbkeyform );
4021  case NS_MAIN:
4022  // selflink, possibly with fragment
4023  return $this->mDbkeyform == '';
4024  case NS_MEDIAWIKI:
4025  // known system message
4026  return $this->hasSourceText() !== false;
4027  default:
4028  return false;
4029  }
4030  }
4031 
4043  public function isKnown() {
4044  return $this->isAlwaysKnown() || $this->exists();
4045  }
4046 
4052  public function hasSourceText() {
4053  if ( $this->exists() ) {
4054  return true;
4055  }
4056 
4057  if ( $this->mNamespace === NS_MEDIAWIKI ) {
4058  $services = MediaWikiServices::getInstance();
4059  // If the page doesn't exist but is a known system message, default
4060  // message content will be displayed, same for language subpages-
4061  // Use always content language to avoid loading hundreds of languages
4062  // to get the link color.
4063  $contLang = $services->getContentLanguage();
4064  list( $name, ) = $services->getMessageCache()->figureMessage(
4065  $contLang->lcfirst( $this->getText() )
4066  );
4067  $message = wfMessage( $name )->inLanguage( $contLang )->useDatabase( false );
4068  return $message->exists();
4069  }
4070 
4071  return false;
4072  }
4073 
4111  public function getDefaultMessageText() {
4112  if ( $this->mNamespace !== NS_MEDIAWIKI ) { // Just in case
4113  return false;
4114  }
4115 
4116  list( $name, $lang ) = MediaWikiServices::getInstance()->getMessageCache()->figureMessage(
4117  MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $this->getText() )
4118  );
4119  $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
4120 
4121  if ( $message->exists() ) {
4122  return $message->plain();
4123  } else {
4124  return false;
4125  }
4126  }
4127 
4134  public function invalidateCache( $purgeTime = null ) {
4135  if ( wfReadOnly() ) {
4136  return false;
4137  }
4138  if ( $this->mArticleID === 0 ) {
4139  // avoid gap locking if we know it's not there
4140  return true;
4141  }
4142 
4143  $conds = $this->pageCond();
4145  new AutoCommitUpdate(
4146  wfGetDB( DB_MASTER ),
4147  __METHOD__,
4148  function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) {
4149  $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
4150  $dbw->update(
4151  'page',
4152  [ 'page_touched' => $dbTimestamp ],
4153  $conds + [ 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ],
4154  $fname
4155  );
4156 
4157  MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $this );
4158 
4160  $this, null, null, $dbw->getDomainID() );
4161  }
4162  ),
4163  DeferredUpdates::PRESEND
4164  );
4165 
4166  return true;
4167  }
4168 
4174  public function touchLinks() {
4175  $jobs = [];
4177  $this,
4178  'pagelinks',
4179  [ 'causeAction' => 'page-touch' ]
4180  );
4181  if ( $this->mNamespace === NS_CATEGORY ) {
4183  $this,
4184  'categorylinks',
4185  [ 'causeAction' => 'category-touch' ]
4186  );
4187  }
4188 
4189  JobQueueGroup::singleton()->lazyPush( $jobs );
4190  }
4191 
4198  public function getTouched( $db = null ) {
4199  if ( $db === null ) {
4200  $db = wfGetDB( DB_REPLICA );
4201  }
4202  $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ );
4203  return $touched;
4204  }
4205 
4214  public function getNotificationTimestamp( User $user ) {
4215  return MediaWikiServices::getInstance()
4216  ->getWatchlistNotificationManager()
4217  ->getTitleNotificationTimestamp( $user, $this );
4218  }
4219 
4226  public function getNamespaceKey( $prepend = 'nstab-' ) {
4227  // Gets the subject namespace of this title
4228  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
4229  $subjectNS = $nsInfo->getSubject( $this->mNamespace );
4230  // Prefer canonical namespace name for HTML IDs
4231  $namespaceKey = $nsInfo->getCanonicalName( $subjectNS );
4232  if ( $namespaceKey === false ) {
4233  // Fallback to localised text
4234  $namespaceKey = $this->getSubjectNsText();
4235  }
4236  // Makes namespace key lowercase
4237  $namespaceKey = MediaWikiServices::getInstance()->getContentLanguage()->lc( $namespaceKey );
4238  // Uses main
4239  if ( $namespaceKey == '' ) {
4240  $namespaceKey = 'main';
4241  }
4242  // Changes file to image for backwards compatibility
4243  if ( $namespaceKey == 'file' ) {
4244  $namespaceKey = 'image';
4245  }
4246  return $prepend . $namespaceKey;
4247  }
4248 
4255  public function getRedirectsHere( $ns = null ) {
4256  $redirs = [];
4257 
4258  $dbr = wfGetDB( DB_REPLICA );
4259  $where = [
4260  'rd_namespace' => $this->mNamespace,
4261  'rd_title' => $this->mDbkeyform,
4262  'rd_from = page_id'
4263  ];
4264  if ( $this->isExternal() ) {
4265  $where['rd_interwiki'] = $this->mInterwiki;
4266  } else {
4267  $where[] = 'rd_interwiki = ' . $dbr->addQuotes( '' ) . ' OR rd_interwiki IS NULL';
4268  }
4269  if ( $ns !== null ) {
4270  $where['page_namespace'] = $ns;
4271  }
4272 
4273  $res = $dbr->select(
4274  [ 'redirect', 'page' ],
4275  [ 'page_namespace', 'page_title' ],
4276  $where,
4277  __METHOD__
4278  );
4279 
4280  foreach ( $res as $row ) {
4281  $redirs[] = self::newFromRow( $row );
4282  }
4283  return $redirs;
4284  }
4285 
4291  public function isValidRedirectTarget() {
4293 
4294  if ( $this->isSpecialPage() ) {
4295  // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
4296  if ( $this->isSpecial( 'Userlogout' ) ) {
4297  return false;
4298  }
4299 
4300  foreach ( $wgInvalidRedirectTargets as $target ) {
4301  if ( $this->isSpecial( $target ) ) {
4302  return false;
4303  }
4304  }
4305  }
4306 
4307  return true;
4308  }
4309 
4315  public function getBacklinkCache() {
4316  return BacklinkCache::get( $this );
4317  }
4318 
4324  public function canUseNoindex() {
4326 
4327  $bannedNamespaces = $wgExemptFromUserRobotsControl ??
4328  MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
4329 
4330  return !in_array( $this->mNamespace, $bannedNamespaces );
4331  }
4332 
4343  public function getCategorySortkey( $prefix = '' ) {
4344  $unprefixed = $this->getText();
4345 
4346  // Anything that uses this hook should only depend
4347  // on the Title object passed in, and should probably
4348  // tell the users to run updateCollations.php --force
4349  // in order to re-sort existing category relations.
4350  Hooks::runner()->onGetDefaultSortkey( $this, $unprefixed );
4351  if ( $prefix !== '' ) {
4352  # Separate with a line feed, so the unprefixed part is only used as
4353  # a tiebreaker when two pages have the exact same prefix.
4354  # In UCA, tab is the only character that can sort above LF
4355  # so we strip both of them from the original prefix.
4356  $prefix = strtr( $prefix, "\n\t", ' ' );
4357  return "$prefix\n$unprefixed";
4358  }
4359  return $unprefixed;
4360  }
4361 
4369  private function getDbPageLanguageCode() {
4370  global $wgPageLanguageUseDB;
4371 
4372  // check, if the page language could be saved in the database, and if so and
4373  // the value is not requested already, lookup the page language using LinkCache
4374  if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) {
4375  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
4376  $linkCache->addLinkObj( $this );
4377  $this->mDbPageLanguage = $linkCache->getGoodLinkFieldObj( $this, 'lang' );
4378  }
4379 
4380  return $this->mDbPageLanguage;
4381  }
4382 
4391  public function getPageLanguage() {
4392  global $wgLang, $wgLanguageCode;
4393  if ( $this->isSpecialPage() ) {
4394  // special pages are in the user language
4395  return $wgLang;
4396  }
4397 
4398  // Checking if DB language is set
4399  $dbPageLanguage = $this->getDbPageLanguageCode();
4400  if ( $dbPageLanguage ) {
4401  return wfGetLangObj( $dbPageLanguage );
4402  }
4403 
4404  if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) {
4405  // Note that this may depend on user settings, so the cache should
4406  // be only per-request.
4407  // NOTE: ContentHandler::getPageLanguage() may need to load the
4408  // content to determine the page language!
4409  // Checking $wgLanguageCode hasn't changed for the benefit of unit
4410  // tests.
4411  $contentHandler = MediaWikiServices::getInstance()
4412  ->getContentHandlerFactory()
4413  ->getContentHandler( $this->getContentModel() );
4414  $langObj = $contentHandler->getPageLanguage( $this );
4415  $this->mPageLanguage = [ $langObj->getCode(), $wgLanguageCode ];
4416  } else {
4417  $langObj = MediaWikiServices::getInstance()->getLanguageFactory()
4418  ->getLanguage( $this->mPageLanguage[0] );
4419  }
4420 
4421  return $langObj;
4422  }
4423 
4432  public function getPageViewLanguage() {
4433  global $wgLang;
4434 
4435  if ( $this->isSpecialPage() ) {
4436  // If the user chooses a variant, the content is actually
4437  // in a language whose code is the variant code.
4438  $variant = $this->getLanguageConverter( $wgLang )->getPreferredVariant();
4439  if ( $wgLang->getCode() !== $variant ) {
4440  return MediaWikiServices::getInstance()->getLanguageFactory()
4441  ->getLanguage( $variant );
4442  }
4443 
4444  return $wgLang;
4445  }
4446 
4447  // Checking if DB language is set
4448  $dbPageLanguage = $this->getDbPageLanguageCode();
4449  if ( $dbPageLanguage ) {
4450  $pageLang = wfGetLangObj( $dbPageLanguage );
4451  $variant = $this->getLanguageConverter( $pageLang )->getPreferredVariant();
4452  if ( $pageLang->getCode() !== $variant ) {
4453  $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()
4454  ->getLanguage( $variant );
4455  }
4456 
4457  return $pageLang;
4458  }
4459 
4460  // @note Can't be cached persistently, depends on user settings.
4461  // @note ContentHandler::getPageViewLanguage() may need to load the
4462  // content to determine the page language!
4463  $contentHandler = MediaWikiServices::getInstance()
4464  ->getContentHandlerFactory()
4465  ->getContentHandler( $this->getContentModel() );
4466  $pageLang = $contentHandler->getPageViewLanguage( $this );
4467  return $pageLang;
4468  }
4469 
4480  public function getEditNotices( $oldid = 0 ) {
4481  $notices = [];
4482 
4483  // Optional notice for the entire namespace
4484  $editnotice_ns = 'editnotice-' . $this->mNamespace;
4485  $msg = wfMessage( $editnotice_ns );
4486  if ( $msg->exists() ) {
4487  $html = $msg->parseAsBlock();
4488  // Edit notices may have complex logic, but output nothing (T91715)
4489  if ( trim( $html ) !== '' ) {
4490  $notices[$editnotice_ns] = Html::rawElement(
4491  'div',
4492  [ 'class' => [
4493  'mw-editnotice',
4494  'mw-editnotice-namespace',
4495  Sanitizer::escapeClass( "mw-$editnotice_ns" )
4496  ] ],
4497  $html
4498  );
4499  }
4500  }
4501 
4502  if (
4503  MediaWikiServices::getInstance()->getNamespaceInfo()->
4504  hasSubpages( $this->mNamespace )
4505  ) {
4506  // Optional notice for page itself and any parent page
4507  $editnotice_base = $editnotice_ns;
4508  foreach ( explode( '/', $this->mDbkeyform ) as $part ) {
4509  $editnotice_base .= '-' . $part;
4510  $msg = wfMessage( $editnotice_base );
4511  if ( $msg->exists() ) {
4512  $html = $msg->parseAsBlock();
4513  if ( trim( $html ) !== '' ) {
4514  $notices[$editnotice_base] = Html::rawElement(
4515  'div',
4516  [ 'class' => [
4517  'mw-editnotice',
4518  'mw-editnotice-base',
4519  Sanitizer::escapeClass( "mw-$editnotice_base" )
4520  ] ],
4521  $html
4522  );
4523  }
4524  }
4525  }
4526  } else {
4527  // Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
4528  $editnoticeText = $editnotice_ns . '-' . strtr( $this->mDbkeyform, '/', '-' );
4529  $msg = wfMessage( $editnoticeText );
4530  if ( $msg->exists() ) {
4531  $html = $msg->parseAsBlock();
4532  if ( trim( $html ) !== '' ) {
4533  $notices[$editnoticeText] = Html::rawElement(
4534  'div',
4535  [ 'class' => [
4536  'mw-editnotice',
4537  'mw-editnotice-page',
4538  Sanitizer::escapeClass( "mw-$editnoticeText" )
4539  ] ],
4540  $html
4541  );
4542  }
4543  }
4544  }
4545 
4546  Hooks::runner()->onTitleGetEditNotices( $this, $oldid, $notices );
4547  return $notices;
4548  }
4549 
4555  private function loadFieldFromDB( $field, $flags ) {
4556  if ( !in_array( $field, self::getSelectFields(), true ) ) {
4557  return false; // field does not exist
4558  }
4559 
4560  $flags |= ( $flags & self::GAID_FOR_UPDATE ) ? self::READ_LATEST : 0; // b/c
4561  list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
4562 
4563  return wfGetDB( $index )->selectField(
4564  'page',
4565  $field,
4566  $this->pageCond(),
4567  __METHOD__,
4568  $options
4569  );
4570  }
4571 
4575  public function __sleep() {
4576  return [
4577  'mNamespace',
4578  'mDbkeyform',
4579  'mFragment',
4580  'mInterwiki',
4581  'mLocalInterwiki',
4582  'mDefaultNamespace',
4583  ];
4584  }
4585 
4586  public function __wakeup() {
4587  $this->mArticleID = ( $this->mNamespace >= 0 ) ? -1 : 0;
4588  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
4589  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
4590  }
4591 
4601  public function getWikiId() {
4602  return PageIdentity::LOCAL;
4603  }
4604 
4612  public function assertWiki( $wikiId ) {
4613  if ( $wikiId !== PageIdentity::LOCAL ) {
4614  throw new PreconditionException(
4615  "Expected this PageIdentity to belong to $wikiId, "
4616  . 'but it belongs to the local wiki'
4617  );
4618  }
4619  }
4620 
4637  public function getId( $wikiId = PageIdentity::LOCAL ) {
4638  $this->assertWiki( $wikiId );
4639  $this->assertProperPage();
4640  return $this->getArticleID();
4641  }
4642 
4655  private function assertProperPage() {
4656  Assert::precondition(
4657  $this->canExist(),
4658  'This Title instance does not represent a proper page, but merely a link target.'
4659  );
4660 
4661  Assert::precondition(
4662  $this->getFragment() === '',
4663  'This Title instance represents a fragment link.'
4664  );
4665  }
4666 
4679  public function toPageIdentity() : ProperPageIdentity {
4680  // TODO: replace individual member fields with a PageIdentityValue that is always present
4681 
4682  $this->assertProperPage();
4683 
4684  return new PageIdentityValue(
4685  $this->getId(),
4686  $this->getNamespace(),
4687  $this->getDBkey(),
4688  PageIdentity::LOCAL
4689  );
4690  }
4691 
4692 }
Title\$mLocalInterwiki
bool $mLocalInterwiki
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:92
Title\$mRestrictions
array $mRestrictions
Array of groups allowed to edit this article.
Definition: Title.php:118
Title\canHaveTalkPage
canHaveTalkPage()
Can this title have a corresponding talk page?
Definition: Title.php:1206
Title\getTitleProtection
getTitleProtection()
Is this title subject to title protection? Title protection is the one applied against creation of su...
Definition: Title.php:2490
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:4324
Title\getLocalURL
getLocalURL( $query='', $query2=false)
Get a URL with no fragment or server name (relative URL) from a Title object.
Definition: Title.php:2262
Title\isSemiProtected
isSemiProtected( $action='edit')
Is this page "semi-protected" - the only protection levels are listed in $wgSemiprotectedRestrictionL...
Definition: Title.php:2578
Title\$mHasCascadingRestrictions
bool $mHasCascadingRestrictions
Are cascading restrictions in effect on this page?
Definition: Title.php:138
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:50
Title\isNamespaceProtected
isNamespaceProtected(User $user)
Determines if $user is unable to edit this page because it has been protected by $wgNamespaceProtecti...
Definition: Title.php:2639
Title\getTalkNsText
getTalkNsText()
Get the namespace text of the talk page.
Definition: Title.php:1189
Title\getSubpageText
getSubpageText()
Get the lowest-level subpage name, i.e.
Definition: Title.php:2086
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:361
Page\PageIdentity\assertWiki
assertWiki( $wikiId)
Throws if $wikiId is different from the return value of getWikiId().
Title\isBigDeletion
isBigDeletion()
Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit.
Definition: Title.php:3791
Title\getNextRevisionID
getNextRevisionID( $revId, $flags=0)
Get the revision ID of the next revision.
Definition: Title.php:3742
Page\PageIdentity\getDBkey
getDBkey()
Get the page title in DB key form.
Title\areCascadeProtectionSourcesLoaded
areCascadeProtectionSourcesLoaded( $getPages=true)
Determines whether cascading protection sources have already been loaded from the database.
Definition: Title.php:2672
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:2445
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:854
Title\getInternalURL
getInternalURL( $query='', $query2=false)
Get the URL form for an internal link.
Definition: Title.php:2395
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:71
Title\getFragment
getFragment()
Get the Title fragment (i.e.
Definition: Title.php:1773
$wgExemptFromUserRobotsControl
$wgExemptFromUserRobotsControl
An array of namespace keys in which the INDEX/__NOINDEX__ magic words will not function,...
Definition: DefaultSettings.php:8506
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:1665
Title\inNamespace
inNamespace( $ns)
Returns true if the title is inside the specified namespace.
Definition: Title.php:1327
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:112
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:1389
Title\wasLocalInterwiki
wasLocalInterwiki()
Was this a local interwiki link?
Definition: Title.php:976
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:166
$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:1339
Title\isWikitextPage
isWikitextPage()
Does that page contain wikitext, or it is JS, CSS or whatever?
Definition: Title.php:1446
Title\isUserCssConfigPage
isUserCssConfigPage()
Is this a CSS "config" sub-page of a user page?
Definition: Title.php:1508
Title\getBacklinkCache
getBacklinkCache()
Get a backlink cache object.
Definition: Title.php:4315
Title\getPartialURL
getPartialURL()
Get the URL-encoded form of the main part.
Definition: Title.php:1048
$wgLegalTitleChars
$wgLegalTitleChars
Allowed title characters – regex character class Don't change this unless you know what you're doing.
Definition: DefaultSettings.php:4353
Title\clearCaches
static clearCaches()
Definition: Title.php:3323
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:1016
Title\estimateRevisionCount
estimateRevisionCount()
Get the approximate revision count of this page.
Definition: Title.php:3820
ResourceLoaderWikiModule\invalidateModuleCache
static invalidateModuleCache(Title $title, ?RevisionRecord $old, ?RevisionRecord $new, $domain)
Clear the preloadTitleInfo() cache for all wiki modules on this wiki on page change if it was a JS or...
Definition: ResourceLoaderWikiModule.php:546
Title\countRevisionsBetween
countRevisionsBetween( $old, $new, $max=null)
Get the number of revisions between the given revision.
Definition: Title.php:3845
Title\getPrefixedDBkey
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1872
Title\getDbPageLanguageCode
getDbPageLanguageCode()
Returns the page language code saved in the database, if $wgPageLanguageUseDB is set to true in Local...
Definition: Title.php:4369
Title\getSkinFromConfigSubpage
getSkinFromConfigSubpage()
Trim down a .css, .json, or .js subpage title to get the corresponding skin name.
Definition: Title.php:1492
$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:174
Title\getTalkPage
getTalkPage()
Get a Title object associated with the talk page of this article.
Definition: Title.php:1635
Title\assertWiki
assertWiki( $wikiId)
Throws if $wikiId is not the.
Definition: Title.php:4612
Title\NEW_CLONE
const NEW_CLONE
Flag for use with factory methods like newFromLinkTarget() that have a $forceClone parameter.
Definition: Title.php:71
Title\getParentCategoryTree
getParentCategoryTree( $children=[])
Get a tree of parent categories.
Definition: Title.php:3665
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:2157
Title\fixSpecialName
fixSpecialName()
If the Title refers to a special page alias which is not the local default, resolve the alias,...
Definition: Title.php:1303
Title\getInterwikiLookup
static getInterwikiLookup()
B/C kludge: provide an InterwikiLookup for use by Title.
Definition: Title.php:235
Title\isUserJsConfigPage
isUserJsConfigPage()
Is this a JS "config" sub-page of a user page?
Definition: Title.php:1536
Title\touchLinks
touchLinks()
Update page_touched timestamps and send CDN purge messages for pages linking to this title.
Definition: Title.php:4174
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:312
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1884
Title\getTransWikiID
getTransWikiID()
Returns the DB name of the distant wiki which owns the object.
Definition: Title.php:999
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:3180
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:2370
Title\$mTitleValue
TitleValue null $mTitleValue
A corresponding TitleValue object.
Definition: Title.php:185
Title\isTalkPage
isTalkPage()
Is this a talk page of some sort?
Definition: Title.php:1619
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1134
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1230
Sanitizer\decodeCharReferencesAndNormalize
static decodeCharReferencesAndNormalize( $text)
Decode any character references, numeric or named entities, in the next and normalize the resulting s...
Definition: Sanitizer.php:1249
$s
$s
Definition: mergeMessageFileList.php:186
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:106
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:976
Title\getNotificationTimestamp
getNotificationTimestamp(User $user)
Get the timestamp when this page was updated since the user last saw it.
Definition: Title.php:4214
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1093
Title\isExternal
isExternal()
Is this Title interwiki?
Definition: Title.php:956
DBAccessObjectUtils\getDBOptions
static getDBOptions( $bitfield)
Get an appropriate DB index, options, and fallback DB index for a query.
Definition: DBAccessObjectUtils.php:52
Title\loadRestrictionsFromRows
loadRestrictionsFromRows( $rows, $oldFashionedRestrictions=null)
Compiles list of active page restrictions from both page table (pre 1.10) and page_restrictions table...
Definition: Title.php:2847
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:686
Title\getDefaultMessageText
getDefaultMessageText()
Get the default (plain) message contents for an page that overrides an interface message key.
Definition: Title.php:4111
Title\hasSourceText
hasSourceText()
Does this page have source text?
Definition: Title.php:4052
Title\loadFromRow
loadFromRow( $row)
Load Title object fields from a DB row.
Definition: Title.php:568
Title\setFragment
setFragment( $fragment)
Set the fragment for this title.
Definition: Title.php:1819
$res
$res
Definition: testCompression.php:57
IDBAccessObject
Interface for database access objects.
Definition: IDBAccessObject.php:57
Title\equals
equals(LinkTarget $title)
Compare with another title.
Definition: Title.php:3938
Title\$mIsBigDeletion
bool null $mIsBigDeletion
Would deleting this page be a big deletion?
Definition: Title.php:188
Title\convertByteClassToUnicodeClass
static convertByteClassToUnicodeClass( $byteClass)
Utility method for converting a character sequence from bytes to Unicode.
Definition: Title.php:749
Title\hasSubpagesEnabled
hasSubpagesEnabled()
Whether this Title's namespace has subpages enabled.
Definition: Title.php:1969
Title\__wakeup
__wakeup()
Definition: Title.php:4586
$wgLang
$wgLang
Definition: Setup.php:777
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
HTMLCacheUpdateJob\newForBacklinks
static newForBacklinks(Title $title, $table, $params=[])
Definition: HTMLCacheUpdateJob.php:59
Title\getParentCategories
getParentCategories()
Get categories to which this Title belongs and return an array of categories' names.
Definition: Title.php:3630
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:3411
Title\$mContentModel
bool string $mContentModel
ID of the page's content model, i.e.
Definition: Title.php:106
Title\getPageLanguageConverter
getPageLanguageConverter()
Shorthand for getting a Language Converter for page's language.
Definition: Title.php:211
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:1550
MessageLocalizer
Interface for localizing messages in MediaWiki.
Definition: MessageLocalizer.php:29
Title\getNsText
getNsText()
Get the namespace text.
Definition: Title.php:1153
Title\$mRedirect
null bool $mRedirect
Is the article at this title a redirect?
Definition: Title.php:171
Title\$mDbkeyform
string $mDbkeyform
Main part with underscores.
Definition: Title.php:86
NS_MAIN
const NS_MAIN
Definition: Defines.php:63
Title\castFromPageIdentity
static castFromPageIdentity(?PageIdentity $pageIdentity)
Return a Title for a given PageIdentity.
Definition: Title.php:326
Title\$mUrlform
string $mUrlform
URL-encoded form of the main part.
Definition: Title.php:84
$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:3469
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:126
PathRouter\getActionPaths
static getActionPaths(array $actionPaths, $articlePath)
Definition: PathRouter.php:430
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:52
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:442
Revision
Definition: Revision.php:40
Title\loadFieldFromDB
loadFieldFromDB( $field, $flags)
Definition: Title.php:4555
Title\isCascadeProtected
isCascadeProtected()
Cascading protection: Return true if cascading restrictions apply to this page, false if not.
Definition: Title.php:2658
Revision\newFromTitle
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
Definition: Revision.php:143
Title\getCdnUrls
getCdnUrls()
Get a list of URLs to purge from the CDN cache when this page changes.
Definition: Title.php:3571
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:1737
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:1464
Title\isUserJsonConfigPage
isUserJsonConfigPage()
Is this a JSON "config" sub-page of a user page?
Definition: Title.php:1522
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:222
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:204
Wikimedia\Rdbms\IDatabase\timestamp
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for ins...
ContentHandler\getDefaultModelFor
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title.
Definition: ContentHandler.php:194
$wgRawHtmlMessages
string[] $wgRawHtmlMessages
List of messages which might contain raw HTML.
Definition: DefaultSettings.php:9295
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:1057
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
Definition: GlobalFunctions.php:1065
Title\nameOf
static nameOf( $id)
Get the prefixed DB key associated with an ID.
Definition: Title.php:712
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:182
Title\isSpecial
isSpecial( $name)
Returns true if this title resolves to the named special page.
Definition: Title.php:1285
MWException
MediaWiki exception.
Definition: MWException.php:29
Title\getTitleFormatter
static getTitleFormatter()
B/C kludge: provide a TitleParser for use by Title.
Definition: Title.php:223
Title\isMainPage
isMainPage()
Is this the mainpage?
Definition: Title.php:1413
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1033
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:2113
Title\getBaseTitle
getBaseTitle()
Get the base page name title, i.e.
Definition: Title.php:2066
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1066
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:556
Title\isConversionTable
isConversionTable()
Is this a conversion table for the LanguageConverter?
Definition: Title.php:1434
Title\isProtected
isProtected( $action='')
Does the title correspond to a protected article?
Definition: Title.php:2606
Title\flushRestrictions
flushRestrictions()
Flush the protection cache in this object and force reload from the database.
Definition: Title.php:2996
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2466
Title\getCategorySortkey
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:4343
Title\getInterwiki
getInterwiki()
Get the interwiki prefix.
Definition: Title.php:967
Title\isSiteJsonConfigPage
isSiteJsonConfigPage()
Is this a sitewide JSON "config" page?
Definition: Title.php:1568
$matches
$matches
Definition: NoLocalSettings.php:24
Title\isValidRedirectTarget
isValidRedirectTarget()
Check if this Title is a valid redirect target.
Definition: Title.php:4291
Page\PageIdentity\getId
getId( $wikiId=PageIdentity::LOCAL)
Returns the page ID.
Title\deleteTitleProtection
deleteTitleProtection()
Remove any title protection due to page existing.
Definition: Title.php:2560
Title\__construct
__construct()
Definition: Title.php:239
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:3535
Title\isUserConfigPage
isUserConfigPage()
Is this a "config" (.css, .json, or .js) sub-page of a user page?
Definition: Title.php:1478
Title\getLanguageConverter
getLanguageConverter( $language)
Shorthand for getting a Language Converter for specific language.
Definition: Title.php:202
Title\$mCascadeSources
array $mCascadeSources
Where are the cascading restrictions coming from on this page?
Definition: Title.php:141
Title\getSubjectPage
getSubjectPage()
Get a title object associated with the subject page of this talk page.
Definition: Title.php:1680
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:1180
Title\loadRestrictions
loadRestrictions( $oldFashionedRestrictions=null, $flags=0)
Load restrictions from the page_restrictions table.
Definition: Title.php:2925
$wgInvalidRedirectTargets
$wgInvalidRedirectTargets
Array of invalid page redirect targets.
Definition: DefaultSettings.php:4526
Title\getFullText
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
Definition: Title.php:1908
Title\getTitleCache
static getTitleCache()
Definition: Title.php:469
Title\hasFragment
hasFragment()
Check if a Title fragment is set.
Definition: Title.php:1783
Title\getRedirectsHere
getRedirectsHere( $ns=null)
Get all extant redirects to this Title.
Definition: Title.php:4255
MediaWiki\User\UserIdentity\getName
getName()
$title
$title
Definition: testCompression.php:38
Title\warnIfPageCannotExist
warnIfPageCannotExist(Title $title, $method)
Definition: Title.php:1706
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:624
Title\$mInterwiki
string $mInterwiki
Interwiki prefix.
Definition: Title.php:90
Title\$mCascadeRestriction
bool $mCascadeRestriction
Cascade restrictions on this page to included templates and images?
Definition: Title.php:129
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1860
Title\getRootText
getRootText()
Get the root page name text without a namespace, i.e.
Definition: Title.php:1989
PROTO_CANONICAL
const PROTO_CANONICAL
Definition: Defines.php:206
$wgNamespaceProtection
$wgNamespaceProtection
Set the minimum permissions required to edit pages in each namespace.
Definition: DefaultSettings.php:5791
Title\canExist
canExist()
Can this title represent a page in the wiki's database?
Definition: Title.php:1220
$wgDeleteRevisionsLimit
$wgDeleteRevisionsLimit
Optional to restrict deletion of pages with higher revision counts to users with the 'bigdelete' perm...
Definition: DefaultSettings.php:5968
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Title\$prefixedText
string null $prefixedText
Text form including namespace/interwiki, initialised on demand.
Definition: Title.php:154
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:914
Title\__sleep
__sleep()
Definition: Title.php:4575
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:2417
Title\createFragmentTarget
createFragmentTarget( $fragment)
Creates a new Title for a different fragment of the same page.
Definition: Title.php:1830
Title\$mNamespace
int $mNamespace
Namespace index, i.e.
Definition: Title.php:88
Title\getDefaultNamespace
getDefaultNamespace()
Get the default namespace index, for when there is no namespace.
Definition: Title.php:1762
Title\newFromTextThrow
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:396
$wgPageLanguageUseDB
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
Definition: DefaultSettings.php:9174
Title\$mPageLanguage
array null $mPageLanguage
The (string) language code of the page's language and content code.
Definition: Title.php:177
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:205
Title\isValid
isValid()
Returns true if the title is a valid link target, and that it has been properly normalized.
Definition: Title.php:902
AtomicSectionUpdate
Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
Definition: AtomicSectionUpdate.php:9
Title\getPrefixedURL
getPrefixedURL()
Get a URL-encoded title (not an actual URL) including interwiki.
Definition: Title.php:2138
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:650
Title\__toString
__toString()
Return a string representation of this title.
Definition: Title.php:1898
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
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:51
ILanguageConverter
The shared interface for all language converters.
Definition: ILanguageConverter.php:28
DBAccessObjectUtils\hasFlags
static hasFlags( $bitfield, $flags)
Definition: DBAccessObjectUtils.php:35
Title\getTemplateLinksTo
getTemplateLinksTo( $options=[])
Get an array of Title objects using this Title as a template Also stores the IDs in the link cache.
Definition: Title.php:3453
$wgMainPageIsDomainRoot
bool $wgMainPageIsDomainRoot
Option to whether serve the main page as the domain root.
Definition: DefaultSettings.php:9559
Title\areRestrictionsCascading
areRestrictionsCascading()
Returns cascading restrictions for the current article.
Definition: Title.php:2828
Title\getLatestRevID
getLatestRevID( $flags=0)
What is the page_latest field for this page?
Definition: Title.php:3266
Title\areRestrictionsLoaded
areRestrictionsLoaded()
Accessor for mRestrictionsLoaded.
Definition: Title.php:2775
Title\hasDeletedEdits
hasDeletedEdits()
Is there a version of this page in the deletion archive?
Definition: Title.php:3155
Title\getSubpages
getSubpages( $limit=-1)
Get all subpages of this page.
Definition: Title.php:3078
Title\assertProperPage
assertProperPage()
Code that requires this Title to be a "proper page" in the sense defined by PageIdentity should call ...
Definition: Title.php:4655
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:3592
$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:62
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:4432
Title\newFromDBkey
static newFromDBkey( $key)
Create a new Title from a prefixed DB key.
Definition: Title.php:250
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:865
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:3105
Title\isSubpage
isSubpage()
Is this a subpage?
Definition: Title.php:1422
Title\hasContentModel
hasContentModel( $id)
Convenience method for checking a title's content model name.
Definition: Title.php:1111
Title\getRestrictionExpiry
getRestrictionExpiry( $action)
Get the expiry time for the restriction against a given action.
Definition: Title.php:2816
Title\newFromURL
static newFromURL( $url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:446
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:135
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:3301
Title\isSubpageOf
isSubpageOf(Title $title)
Check if this title is a subpage of another title.
Definition: Title.php:3951
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:941
Title\$mFragment
string $mFragment
Title fragment (i.e.
Definition: Title.php:94
Title\getContentModel
getContentModel( $flags=0)
Get the page's content model id, see the CONTENT_MODEL_XXX constants.
Definition: Title.php:1078
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:218
Title\newFromIDs
static newFromIDs( $ids)
Make an array of titles from an array of IDs.
Definition: Title.php:530
NS_USER
const NS_USER
Definition: Defines.php:65
WikiPage\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new page object.
Definition: WikiPage.php:337
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:289
Title\prefix
prefix( $name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object.
Definition: Title.php:1846
Title\getNamespaceKey
getNamespaceKey( $prepend='nstab-')
Generate strings used for xml 'id' names in monobook tabs.
Definition: Title.php:4226
Title\getEditURL
getEditURL()
Get the edit URL for this Title.
Definition: Title.php:2429
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:2195
Title\isKnown
isKnown()
Does this title refer to a page that can (or might) be meaningfully viewed? In particular,...
Definition: Title.php:4043
$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:191
Title\getFirstRevision
getFirstRevision( $flags=0)
Get the first revision of the page.
Definition: Title.php:3753
Title\getAllRestrictions
getAllRestrictions()
Accessor/initialisation for mRestrictions.
Definition: Title.php:2802
Title\getEarliestRevTime
getEarliestRevTime( $flags=0)
Get the oldest revision timestamp of this page.
Definition: Title.php:3769
Title
Represents a title within MediaWiki.
Definition: Title.php:46
$wgActionPaths
$wgActionPaths
To set 'pretty' URL paths for actions other than plain page views, add to this array.
Definition: DefaultSettings.php:451
Title\$mCascadingRestrictions
$mCascadingRestrictions
Caching the results of getCascadeProtectionSources.
Definition: Title.php:132
JobQueueGroup\singleton
static singleton( $domain=false)
Definition: JobQueueGroup.php:70
Title\getCascadeProtectionSources
getCascadeProtectionSources( $getPages=true)
Cascading protection: Get the source of any cascading restrictions on this page.
Definition: Title.php:2689
$cache
$cache
Definition: mcc.php:33
$wgSemiprotectedRestrictionLevels
$wgSemiprotectedRestrictionLevels
Restriction levels that should be considered "semiprotected".
Definition: DefaultSettings.php:5782
Title\getRestrictionTypes
getRestrictionTypes()
Returns restriction types for the current Title.
Definition: Title.php:2463
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:2513
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:3523
Title\isRedirect
isRedirect( $flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
Definition: Title.php:3214
Title\$mArticleID
int $mArticleID
Article ID, fetched from the link cache on demand.
Definition: Title.php:97
Title\isDeleted
isDeleted()
Is there a version of this page in the deletion archive?
Definition: Title.php:3109
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:3338
Title\$mDefaultNamespace
int $mDefaultNamespace
Namespace index when there is no namespace.
Definition: Title.php:165
Title\$mLength
int $mLength
The page length, 0 for special pages.
Definition: Title.php:168
Title\$mEstimateRevisions
int $mEstimateRevisions
Estimated number of revisions; null of not loaded.
Definition: Title.php:115
Title\hasSubjectNamespace
hasSubjectNamespace( $ns)
Returns true if the title has the same subject namespace as the namespace specified.
Definition: Title.php:1366
Title\isSpecialPage
isSpecialPage()
Returns true if this is a special page.
Definition: Title.php:1275
Title\getId
getId( $wikiId=PageIdentity::LOCAL)
Returns the page ID.
Definition: Title.php:4637
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:3580
Title\getDeletedEditsCount
getDeletedEditsCount()
Is there a version of this page in the deletion archive?
Definition: Title.php:3119
Title\getPreviousRevisionID
getPreviousRevisionID( $revId, $flags=0)
Get the revision ID of the previous revision.
Definition: Title.php:3730
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:4391
Title\CACHE_MAX
const CACHE_MAX
Title::newFromText maintains a cache to avoid expensive re-normalization of commonly used titles.
Definition: Title.php:55
Title\getEditNotices
getEditNotices( $oldid=0)
Get a list of rendered edit notices for this page.
Definition: Title.php:4480
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:219
Title\getTouched
getTouched( $db=null)
Get the last touched timestamp.
Definition: Title.php:4198
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:5757
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:77
Page\PageIdentityValue
Immutable value object representing a page identity.
Definition: PageIdentityValue.php:43
Title\getFragmentForURL
getFragmentForURL()
Get the fragment in URL form, including the "#" character if there is one.
Definition: Title.php:1792
Title\exists
exists( $flags=0)
Check if page exists.
Definition: Title.php:3967
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:842
Title\isAlwaysKnown
isAlwaysKnown()
Should links to this title be shown as potentially viewable (i.e.
Definition: Title.php:3989
Title\secureAndSplit
secureAndSplit( $text, $defaultNamespace=null)
Secure and split - main initialisation function for this object.
Definition: Title.php:3363
Title\isDeletedQuick
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:3145
Title\getSubpageUrlForm
getSubpageUrlForm()
Get a URL-encoded form of the subpage text.
Definition: Title.php:2127
MapCacheLRU\clear
clear( $keys=null)
Clear one or several cache entries, or all cache entries.
Definition: MapCacheLRU.php:289
Title\isNewPage
isNewPage()
Check if this is a new page.
Definition: Title.php:3781
$wgRestrictionTypes
$wgRestrictionTypes
Set of available actions that can be restricted via action=protect You probably shouldn't change this...
Definition: DefaultSettings.php:5744
Title\toPageIdentity
toPageIdentity()
Returns the page represented by this Title as a ProperPageIdentity.
Definition: Title.php:4679
Title\setContentModel
setContentModel( $model)
Set a proposed content model for the page for permissions checking.
Definition: Title.php:1128
Title\compare
static compare(LinkTarget $a, LinkTarget $b)
Callback for usort() to do title sorts by (namespace, title)
Definition: Title.php:881
Title\countAuthorsBetween
countAuthorsBetween( $old, $new, $limit, $options=[])
Get the number of authors between the given revisions or revision IDs.
Definition: Title.php:3926
$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:735
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:313
Title\isSiteJsConfigPage
isSiteJsConfigPage()
Is this a sitewide JS "config" page?
Definition: Title.php:1586
Title\invalidateCache
invalidateCache( $purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:4134
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:645
NS_FILE
const NS_FILE
Definition: Defines.php:69
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:986
Title\getRestrictions
getRestrictions( $action)
Accessor/initialisation for mRestrictions.
Definition: Title.php:2788
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:1378
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:220
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:56
Title\$titleCache
static MapCacheLRU null $titleCache
Definition: Title.php:48
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:505
$wgVariantArticlePath
$wgVariantArticlePath
Like $wgArticlePath, but on multi-variant wikis, this provides a path format that describes which par...
Definition: DefaultSettings.php:3300
Title\isRawHtmlMessage
isRawHtmlMessage()
Is this a message which can contain raw HTML?
Definition: Title.php:1604
Title\getSelectFields
static getSelectFields()
Returns a list of fields that are to be selected for initializing Title objects or LinkCache entries.
Definition: Title.php:482
Title\hasSubpages
hasSubpages()
Does this have subpages? (Warning, usually requires an extra DB query.)
Definition: Title.php:3047
Title\getBaseText
getBaseText()
Get the base page name without a namespace, i.e.
Definition: Title.php:2039
Title\pageCond
pageCond()
Get an associative array for selecting this title from the "page" table.
Definition: Title.php:3692
Title\getText
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:1039
Page\PageIdentity\getNamespace
getNamespace()
Returns the page's namespace number.
Title\$mTextform
string $mTextform
Text form (spaces not underscores) of the main part.
Definition: Title.php:82
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:3006
$wgInternalServer
$wgInternalServer
Internal server name as known to CDN, if different.
Definition: DefaultSettings.php:2912
Title\$mLatestID
bool int $mLatestID
ID of most recent revision.
Definition: Title.php:100
PROTO_HTTP
const PROTO_HTTP
Definition: Defines.php:202
Title\$mRestrictionsLoaded
bool $mRestrictionsLoaded
Boolean for initialisation on demand.
Definition: Title.php:144
Title\getWikiId
getWikiId()
Returns false to indicate that this Title belongs to the local wiki.
Definition: Title.php:4601
Title\lazyFillContentModel
lazyFillContentModel( $model)
If the content model field is not frozen then update it with a retreived value.
Definition: Title.php:1142
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:494
Title\getSubjectNsText
getSubjectNsText()
Get the namespace text of the subject (rather than talk) page.
Definition: Title.php:1178
Title\$mTitleProtection
mixed $mTitleProtection
Cached value for getTitleProtection (create protection)
Definition: Title.php:157
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:274
Title\getRelativeRevisionID
getRelativeRevisionID( $revId, $flags, $dir)
Get next/previous revision ID relative to another revision ID.
Definition: Title.php:3708
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:350
Title\getFullUrlForRedirect
getFullUrlForRedirect( $query='', $proto=PROTO_CURRENT)
Get a url appropriate for making redirects based on an untrusted url arg.
Definition: Title.php:2228
Title\getRootTitle
getRootTitle()
Get the root page name title, i.e.
Definition: Title.php:2016
$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:3239
Title\findSubpageDivider
findSubpageDivider( $text, $dir)
Finds the first or last subpage divider (slash) in the string.
Definition: Title.php:1930
Title\getAuthorsBetween
getAuthorsBetween( $old, $new, $limit, $options=[])
Get the authors between the given revisions or revision IDs.
Definition: Title.php:3883
Title\isWatchable
isWatchable()
Can this title be added to a user's watchlist?
Definition: Title.php:1264