MediaWiki  1.28.0
Title.php
Go to the documentation of this file.
1 <?php
27 
36 class Title implements LinkTarget {
38  static private $titleCache = null;
39 
45  const CACHE_MAX = 1000;
46 
51  const GAID_FOR_UPDATE = 1;
52 
58  // @{
59 
61  public $mTextform = '';
62 
64  public $mUrlform = '';
65 
67  public $mDbkeyform = '';
68 
70  protected $mUserCaseDBKey;
71 
73  public $mNamespace = NS_MAIN;
74 
76  public $mInterwiki = '';
77 
79  private $mLocalInterwiki = false;
80 
82  public $mFragment = '';
83 
85  public $mArticleID = -1;
86 
88  protected $mLatestID = false;
89 
94  private $mContentModel = false;
95 
100  private $mForcedContentModel = false;
101 
104 
106  public $mRestrictions = [];
107 
109  protected $mOldRestrictions = false;
110 
113 
116 
118  protected $mRestrictionsExpiry = [];
119 
122 
125 
127  public $mRestrictionsLoaded = false;
128 
130  protected $mPrefixedText = null;
131 
134 
141 
143  protected $mLength = -1;
144 
146  public $mRedirect = null;
147 
150 
152  private $mHasSubpages;
153 
155  private $mPageLanguage = false;
156 
159  private $mDbPageLanguage = false;
160 
162  private $mTitleValue = null;
163 
165  private $mIsBigDeletion = null;
166  // @}
167 
176  private static function getTitleFormatter() {
177  return MediaWikiServices::getInstance()->getTitleFormatter();
178  }
179 
188  private static function getInterwikiLookup() {
189  return MediaWikiServices::getInstance()->getInterwikiLookup();
190  }
191 
195  function __construct() {
196  }
197 
206  public static function newFromDBkey( $key ) {
207  $t = new Title();
208  $t->mDbkeyform = $key;
209 
210  try {
211  $t->secureAndSplit();
212  return $t;
213  } catch ( MalformedTitleException $ex ) {
214  return null;
215  }
216  }
217 
225  public static function newFromTitleValue( TitleValue $titleValue ) {
226  return self::newFromLinkTarget( $titleValue );
227  }
228 
236  public static function newFromLinkTarget( LinkTarget $linkTarget ) {
237  if ( $linkTarget instanceof Title ) {
238  // Special case if it's already a Title object
239  return $linkTarget;
240  }
241  return self::makeTitle(
242  $linkTarget->getNamespace(),
243  $linkTarget->getText(),
244  $linkTarget->getFragment(),
245  $linkTarget->getInterwiki()
246  );
247  }
248 
262  public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
263  // DWIM: Integers can be passed in here when page titles are used as array keys.
264  if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) {
265  throw new InvalidArgumentException( '$text must be a string.' );
266  }
267  if ( $text === null ) {
268  return null;
269  }
270 
271  try {
272  return Title::newFromTextThrow( strval( $text ), $defaultNamespace );
273  } catch ( MalformedTitleException $ex ) {
274  return null;
275  }
276  }
277 
292  public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
293  if ( is_object( $text ) ) {
294  throw new MWException( '$text must be a string, given an object' );
295  }
296 
297  $titleCache = self::getTitleCache();
298 
299  // Wiki pages often contain multiple links to the same page.
300  // Title normalization and parsing can become expensive on pages with many
301  // links, so we can save a little time by caching them.
302  // In theory these are value objects and won't get changed...
303  if ( $defaultNamespace == NS_MAIN ) {
304  $t = $titleCache->get( $text );
305  if ( $t ) {
306  return $t;
307  }
308  }
309 
310  // Convert things like &eacute; &#257; or &#x3017; into normalized (bug 14952) text
311  $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
312 
313  $t = new Title();
314  $t->mDbkeyform = strtr( $filteredText, ' ', '_' );
315  $t->mDefaultNamespace = intval( $defaultNamespace );
316 
317  $t->secureAndSplit();
318  if ( $defaultNamespace == NS_MAIN ) {
319  $titleCache->set( $text, $t );
320  }
321  return $t;
322  }
323 
339  public static function newFromURL( $url ) {
340  $t = new Title();
341 
342  # For compatibility with old buggy URLs. "+" is usually not valid in titles,
343  # but some URLs used it as a space replacement and they still come
344  # from some external search tools.
345  if ( strpos( self::legalChars(), '+' ) === false ) {
346  $url = strtr( $url, '+', ' ' );
347  }
348 
349  $t->mDbkeyform = strtr( $url, ' ', '_' );
350 
351  try {
352  $t->secureAndSplit();
353  return $t;
354  } catch ( MalformedTitleException $ex ) {
355  return null;
356  }
357  }
358 
362  private static function getTitleCache() {
363  if ( self::$titleCache == null ) {
364  self::$titleCache = new HashBagOStuff( [ 'maxKeys' => self::CACHE_MAX ] );
365  }
366  return self::$titleCache;
367  }
368 
376  protected static function getSelectFields() {
377  global $wgContentHandlerUseDB, $wgPageLanguageUseDB;
378 
379  $fields = [
380  'page_namespace', 'page_title', 'page_id',
381  'page_len', 'page_is_redirect', 'page_latest',
382  ];
383 
384  if ( $wgContentHandlerUseDB ) {
385  $fields[] = 'page_content_model';
386  }
387 
388  if ( $wgPageLanguageUseDB ) {
389  $fields[] = 'page_lang';
390  }
391 
392  return $fields;
393  }
394 
402  public static function newFromID( $id, $flags = 0 ) {
403  $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_REPLICA );
404  $row = $db->selectRow(
405  'page',
406  self::getSelectFields(),
407  [ 'page_id' => $id ],
408  __METHOD__
409  );
410  if ( $row !== false ) {
411  $title = Title::newFromRow( $row );
412  } else {
413  $title = null;
414  }
415  return $title;
416  }
417 
424  public static function newFromIDs( $ids ) {
425  if ( !count( $ids ) ) {
426  return [];
427  }
428  $dbr = wfGetDB( DB_REPLICA );
429 
430  $res = $dbr->select(
431  'page',
432  self::getSelectFields(),
433  [ 'page_id' => $ids ],
434  __METHOD__
435  );
436 
437  $titles = [];
438  foreach ( $res as $row ) {
439  $titles[] = Title::newFromRow( $row );
440  }
441  return $titles;
442  }
443 
450  public static function newFromRow( $row ) {
451  $t = self::makeTitle( $row->page_namespace, $row->page_title );
452  $t->loadFromRow( $row );
453  return $t;
454  }
455 
462  public function loadFromRow( $row ) {
463  if ( $row ) { // page found
464  if ( isset( $row->page_id ) ) {
465  $this->mArticleID = (int)$row->page_id;
466  }
467  if ( isset( $row->page_len ) ) {
468  $this->mLength = (int)$row->page_len;
469  }
470  if ( isset( $row->page_is_redirect ) ) {
471  $this->mRedirect = (bool)$row->page_is_redirect;
472  }
473  if ( isset( $row->page_latest ) ) {
474  $this->mLatestID = (int)$row->page_latest;
475  }
476  if ( !$this->mForcedContentModel && isset( $row->page_content_model ) ) {
477  $this->mContentModel = strval( $row->page_content_model );
478  } elseif ( !$this->mForcedContentModel ) {
479  $this->mContentModel = false; # initialized lazily in getContentModel()
480  }
481  if ( isset( $row->page_lang ) ) {
482  $this->mDbPageLanguage = (string)$row->page_lang;
483  }
484  if ( isset( $row->page_restrictions ) ) {
485  $this->mOldRestrictions = $row->page_restrictions;
486  }
487  } else { // page not found
488  $this->mArticleID = 0;
489  $this->mLength = 0;
490  $this->mRedirect = false;
491  $this->mLatestID = 0;
492  if ( !$this->mForcedContentModel ) {
493  $this->mContentModel = false; # initialized lazily in getContentModel()
494  }
495  }
496  }
497 
511  public static function makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
512  $t = new Title();
513  $t->mInterwiki = $interwiki;
514  $t->mFragment = $fragment;
515  $t->mNamespace = $ns = intval( $ns );
516  $t->mDbkeyform = strtr( $title, ' ', '_' );
517  $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
518  $t->mUrlform = wfUrlencode( $t->mDbkeyform );
519  $t->mTextform = strtr( $title, '_', ' ' );
520  $t->mContentModel = false; # initialized lazily in getContentModel()
521  return $t;
522  }
523 
535  public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
536  if ( !MWNamespace::exists( $ns ) ) {
537  return null;
538  }
539 
540  $t = new Title();
541  $t->mDbkeyform = Title::makeName( $ns, $title, $fragment, $interwiki, true );
542 
543  try {
544  $t->secureAndSplit();
545  return $t;
546  } catch ( MalformedTitleException $ex ) {
547  return null;
548  }
549  }
550 
556  public static function newMainPage() {
557  $title = Title::newFromText( wfMessage( 'mainpage' )->inContentLanguage()->text() );
558  // Don't give fatal errors if the message is broken
559  if ( !$title ) {
560  $title = Title::newFromText( 'Main Page' );
561  }
562  return $title;
563  }
564 
571  public static function nameOf( $id ) {
572  $dbr = wfGetDB( DB_REPLICA );
573 
574  $s = $dbr->selectRow(
575  'page',
576  [ 'page_namespace', 'page_title' ],
577  [ 'page_id' => $id ],
578  __METHOD__
579  );
580  if ( $s === false ) {
581  return null;
582  }
583 
584  $n = self::makeName( $s->page_namespace, $s->page_title );
585  return $n;
586  }
587 
593  public static function legalChars() {
595  return $wgLegalTitleChars;
596  }
597 
607  static function getTitleInvalidRegex() {
608  wfDeprecated( __METHOD__, '1.25' );
610  }
611 
621  public static function convertByteClassToUnicodeClass( $byteClass ) {
622  $length = strlen( $byteClass );
623  // Input token queue
624  $x0 = $x1 = $x2 = '';
625  // Decoded queue
626  $d0 = $d1 = $d2 = '';
627  // Decoded integer codepoints
628  $ord0 = $ord1 = $ord2 = 0;
629  // Re-encoded queue
630  $r0 = $r1 = $r2 = '';
631  // Output
632  $out = '';
633  // Flags
634  $allowUnicode = false;
635  for ( $pos = 0; $pos < $length; $pos++ ) {
636  // Shift the queues down
637  $x2 = $x1;
638  $x1 = $x0;
639  $d2 = $d1;
640  $d1 = $d0;
641  $ord2 = $ord1;
642  $ord1 = $ord0;
643  $r2 = $r1;
644  $r1 = $r0;
645  // Load the current input token and decoded values
646  $inChar = $byteClass[$pos];
647  if ( $inChar == '\\' ) {
648  if ( preg_match( '/x([0-9a-fA-F]{2})/A', $byteClass, $m, 0, $pos + 1 ) ) {
649  $x0 = $inChar . $m[0];
650  $d0 = chr( hexdec( $m[1] ) );
651  $pos += strlen( $m[0] );
652  } elseif ( preg_match( '/[0-7]{3}/A', $byteClass, $m, 0, $pos + 1 ) ) {
653  $x0 = $inChar . $m[0];
654  $d0 = chr( octdec( $m[0] ) );
655  $pos += strlen( $m[0] );
656  } elseif ( $pos + 1 >= $length ) {
657  $x0 = $d0 = '\\';
658  } else {
659  $d0 = $byteClass[$pos + 1];
660  $x0 = $inChar . $d0;
661  $pos += 1;
662  }
663  } else {
664  $x0 = $d0 = $inChar;
665  }
666  $ord0 = ord( $d0 );
667  // Load the current re-encoded value
668  if ( $ord0 < 32 || $ord0 == 0x7f ) {
669  $r0 = sprintf( '\x%02x', $ord0 );
670  } elseif ( $ord0 >= 0x80 ) {
671  // Allow unicode if a single high-bit character appears
672  $r0 = sprintf( '\x%02x', $ord0 );
673  $allowUnicode = true;
674  } elseif ( strpos( '-\\[]^', $d0 ) !== false ) {
675  $r0 = '\\' . $d0;
676  } else {
677  $r0 = $d0;
678  }
679  // Do the output
680  if ( $x0 !== '' && $x1 === '-' && $x2 !== '' ) {
681  // Range
682  if ( $ord2 > $ord0 ) {
683  // Empty range
684  } elseif ( $ord0 >= 0x80 ) {
685  // Unicode range
686  $allowUnicode = true;
687  if ( $ord2 < 0x80 ) {
688  // Keep the non-unicode section of the range
689  $out .= "$r2-\\x7F";
690  }
691  } else {
692  // Normal range
693  $out .= "$r2-$r0";
694  }
695  // Reset state to the initial value
696  $x0 = $x1 = $d0 = $d1 = $r0 = $r1 = '';
697  } elseif ( $ord2 < 0x80 ) {
698  // ASCII character
699  $out .= $r2;
700  }
701  }
702  if ( $ord1 < 0x80 ) {
703  $out .= $r1;
704  }
705  if ( $ord0 < 0x80 ) {
706  $out .= $r0;
707  }
708  if ( $allowUnicode ) {
709  $out .= '\u0080-\uFFFF';
710  }
711  return $out;
712  }
713 
725  public static function makeName( $ns, $title, $fragment = '', $interwiki = '',
726  $canonicalNamespace = false
727  ) {
729 
730  if ( $canonicalNamespace ) {
731  $namespace = MWNamespace::getCanonicalName( $ns );
732  } else {
733  $namespace = $wgContLang->getNsText( $ns );
734  }
735  $name = $namespace == '' ? $title : "$namespace:$title";
736  if ( strval( $interwiki ) != '' ) {
737  $name = "$interwiki:$name";
738  }
739  if ( strval( $fragment ) != '' ) {
740  $name .= '#' . $fragment;
741  }
742  return $name;
743  }
744 
751  static function escapeFragmentForURL( $fragment ) {
752  # Note that we don't urlencode the fragment. urlencoded Unicode
753  # fragments appear not to work in IE (at least up to 7) or in at least
754  # one version of Opera 9.x. The W3C validator, for one, doesn't seem
755  # to care if they aren't encoded.
756  return Sanitizer::escapeId( $fragment, 'noninitial' );
757  }
758 
767  public static function compare( LinkTarget $a, LinkTarget $b ) {
768  if ( $a->getNamespace() == $b->getNamespace() ) {
769  return strcmp( $a->getText(), $b->getText() );
770  } else {
771  return $a->getNamespace() - $b->getNamespace();
772  }
773  }
774 
782  public function isLocal() {
783  if ( $this->isExternal() ) {
784  $iw = self::getInterwikiLookup()->fetch( $this->mInterwiki );
785  if ( $iw ) {
786  return $iw->isLocal();
787  }
788  }
789  return true;
790  }
791 
797  public function isExternal() {
798  return $this->mInterwiki !== '';
799  }
800 
808  public function getInterwiki() {
809  return $this->mInterwiki;
810  }
811 
817  public function wasLocalInterwiki() {
818  return $this->mLocalInterwiki;
819  }
820 
827  public function isTrans() {
828  if ( !$this->isExternal() ) {
829  return false;
830  }
831 
832  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->isTranscludable();
833  }
834 
840  public function getTransWikiID() {
841  if ( !$this->isExternal() ) {
842  return false;
843  }
844 
845  return self::getInterwikiLookup()->fetch( $this->mInterwiki )->getWikiID();
846  }
847 
857  public function getTitleValue() {
858  if ( $this->mTitleValue === null ) {
859  try {
860  $this->mTitleValue = new TitleValue(
861  $this->getNamespace(),
862  $this->getDBkey(),
863  $this->getFragment(),
864  $this->getInterwiki()
865  );
866  } catch ( InvalidArgumentException $ex ) {
867  wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' .
868  $this->getPrefixedText() . ']]: ' . $ex->getMessage() . "\n" );
869  }
870  }
871 
872  return $this->mTitleValue;
873  }
874 
880  public function getText() {
881  return $this->mTextform;
882  }
883 
889  public function getPartialURL() {
890  return $this->mUrlform;
891  }
892 
898  public function getDBkey() {
899  return $this->mDbkeyform;
900  }
901 
907  function getUserCaseDBKey() {
908  if ( !is_null( $this->mUserCaseDBKey ) ) {
909  return $this->mUserCaseDBKey;
910  } else {
911  // If created via makeTitle(), $this->mUserCaseDBKey is not set.
912  return $this->mDbkeyform;
913  }
914  }
915 
921  public function getNamespace() {
922  return $this->mNamespace;
923  }
924 
931  public function getContentModel( $flags = 0 ) {
932  if ( !$this->mForcedContentModel
933  && ( !$this->mContentModel || $flags === Title::GAID_FOR_UPDATE )
934  && $this->getArticleID( $flags )
935  ) {
936  $linkCache = LinkCache::singleton();
937  $linkCache->addLinkObj( $this ); # in case we already had an article ID
938  $this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' );
939  }
940 
941  if ( !$this->mContentModel ) {
942  $this->mContentModel = ContentHandler::getDefaultModelFor( $this );
943  }
944 
945  return $this->mContentModel;
946  }
947 
954  public function hasContentModel( $id ) {
955  return $this->getContentModel() == $id;
956  }
957 
969  public function setContentModel( $model ) {
970  $this->mContentModel = $model;
971  $this->mForcedContentModel = true;
972  }
973 
979  public function getNsText() {
980  if ( $this->isExternal() ) {
981  // This probably shouldn't even happen,
982  // but for interwiki transclusion it sometimes does.
983  // Use the canonical namespaces if possible to try to
984  // resolve a foreign namespace.
985  if ( MWNamespace::exists( $this->mNamespace ) ) {
986  return MWNamespace::getCanonicalName( $this->mNamespace );
987  }
988  }
989 
990  try {
991  $formatter = self::getTitleFormatter();
992  return $formatter->getNamespaceName( $this->mNamespace, $this->mDbkeyform );
993  } catch ( InvalidArgumentException $ex ) {
994  wfDebug( __METHOD__ . ': ' . $ex->getMessage() . "\n" );
995  return false;
996  }
997  }
998 
1004  public function getSubjectNsText() {
1006  return $wgContLang->getNsText( MWNamespace::getSubject( $this->mNamespace ) );
1007  }
1008 
1014  public function getTalkNsText() {
1016  return $wgContLang->getNsText( MWNamespace::getTalk( $this->mNamespace ) );
1017  }
1018 
1024  public function canTalk() {
1025  return MWNamespace::canTalk( $this->mNamespace );
1026  }
1027 
1033  public function canExist() {
1034  return $this->mNamespace >= NS_MAIN;
1035  }
1036 
1042  public function isWatchable() {
1043  return !$this->isExternal() && MWNamespace::isWatchable( $this->getNamespace() );
1044  }
1045 
1051  public function isSpecialPage() {
1052  return $this->getNamespace() == NS_SPECIAL;
1053  }
1054 
1061  public function isSpecial( $name ) {
1062  if ( $this->isSpecialPage() ) {
1063  list( $thisName, /* $subpage */ ) = SpecialPageFactory::resolveAlias( $this->getDBkey() );
1064  if ( $name == $thisName ) {
1065  return true;
1066  }
1067  }
1068  return false;
1069  }
1070 
1077  public function fixSpecialName() {
1078  if ( $this->isSpecialPage() ) {
1079  list( $canonicalName, $par ) = SpecialPageFactory::resolveAlias( $this->mDbkeyform );
1080  if ( $canonicalName ) {
1081  $localName = SpecialPageFactory::getLocalNameFor( $canonicalName, $par );
1082  if ( $localName != $this->mDbkeyform ) {
1083  return Title::makeTitle( NS_SPECIAL, $localName );
1084  }
1085  }
1086  }
1087  return $this;
1088  }
1089 
1100  public function inNamespace( $ns ) {
1101  return MWNamespace::equals( $this->getNamespace(), $ns );
1102  }
1103 
1111  public function inNamespaces( /* ... */ ) {
1112  $namespaces = func_get_args();
1113  if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) {
1114  $namespaces = $namespaces[0];
1115  }
1116 
1117  foreach ( $namespaces as $ns ) {
1118  if ( $this->inNamespace( $ns ) ) {
1119  return true;
1120  }
1121  }
1122 
1123  return false;
1124  }
1125 
1139  public function hasSubjectNamespace( $ns ) {
1140  return MWNamespace::subjectEquals( $this->getNamespace(), $ns );
1141  }
1142 
1150  public function isContentPage() {
1151  return MWNamespace::isContent( $this->getNamespace() );
1152  }
1153 
1160  public function isMovable() {
1161  if ( !MWNamespace::isMovable( $this->getNamespace() ) || $this->isExternal() ) {
1162  // Interwiki title or immovable namespace. Hooks don't get to override here
1163  return false;
1164  }
1165 
1166  $result = true;
1167  Hooks::run( 'TitleIsMovable', [ $this, &$result ] );
1168  return $result;
1169  }
1170 
1181  public function isMainPage() {
1182  return $this->equals( Title::newMainPage() );
1183  }
1184 
1190  public function isSubpage() {
1191  return MWNamespace::hasSubpages( $this->mNamespace )
1192  ? strpos( $this->getText(), '/' ) !== false
1193  : false;
1194  }
1195 
1201  public function isConversionTable() {
1202  // @todo ConversionTable should become a separate content model.
1203 
1204  return $this->getNamespace() == NS_MEDIAWIKI &&
1205  strpos( $this->getText(), 'Conversiontable/' ) === 0;
1206  }
1207 
1213  public function isWikitextPage() {
1214  return $this->hasContentModel( CONTENT_MODEL_WIKITEXT );
1215  }
1216 
1231  public function isCssOrJsPage() {
1232  $isCssOrJsPage = NS_MEDIAWIKI == $this->mNamespace
1233  && ( $this->hasContentModel( CONTENT_MODEL_CSS )
1235 
1236  # @note This hook is also called in ContentHandler::getDefaultModel.
1237  # It's called here again to make sure hook functions can force this
1238  # method to return true even outside the MediaWiki namespace.
1239 
1240  Hooks::run( 'TitleIsCssOrJsPage', [ $this, &$isCssOrJsPage ], '1.25' );
1241 
1242  return $isCssOrJsPage;
1243  }
1244 
1250  public function isCssJsSubpage() {
1251  return ( NS_USER == $this->mNamespace && $this->isSubpage()
1252  && ( $this->hasContentModel( CONTENT_MODEL_CSS )
1253  || $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) ) );
1254  }
1255 
1261  public function getSkinFromCssJsSubpage() {
1262  $subpage = explode( '/', $this->mTextform );
1263  $subpage = $subpage[count( $subpage ) - 1];
1264  $lastdot = strrpos( $subpage, '.' );
1265  if ( $lastdot === false ) {
1266  return $subpage; # Never happens: only called for names ending in '.css' or '.js'
1267  }
1268  return substr( $subpage, 0, $lastdot );
1269  }
1270 
1276  public function isCssSubpage() {
1277  return ( NS_USER == $this->mNamespace && $this->isSubpage()
1278  && $this->hasContentModel( CONTENT_MODEL_CSS ) );
1279  }
1280 
1286  public function isJsSubpage() {
1287  return ( NS_USER == $this->mNamespace && $this->isSubpage()
1289  }
1290 
1296  public function isTalkPage() {
1297  return MWNamespace::isTalk( $this->getNamespace() );
1298  }
1299 
1305  public function getTalkPage() {
1306  return Title::makeTitle( MWNamespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
1307  }
1308 
1315  public function getSubjectPage() {
1316  // Is this the same title?
1317  $subjectNS = MWNamespace::getSubject( $this->getNamespace() );
1318  if ( $this->getNamespace() == $subjectNS ) {
1319  return $this;
1320  }
1321  return Title::makeTitle( $subjectNS, $this->getDBkey() );
1322  }
1323 
1332  public function getOtherPage() {
1333  if ( $this->isSpecialPage() ) {
1334  throw new MWException( 'Special pages cannot have other pages' );
1335  }
1336  if ( $this->isTalkPage() ) {
1337  return $this->getSubjectPage();
1338  } else {
1339  return $this->getTalkPage();
1340  }
1341  }
1342 
1348  public function getDefaultNamespace() {
1349  return $this->mDefaultNamespace;
1350  }
1351 
1359  public function getFragment() {
1360  return $this->mFragment;
1361  }
1362 
1369  public function hasFragment() {
1370  return $this->mFragment !== '';
1371  }
1372 
1377  public function getFragmentForURL() {
1378  if ( !$this->hasFragment() ) {
1379  return '';
1380  } else {
1381  return '#' . Title::escapeFragmentForURL( $this->getFragment() );
1382  }
1383  }
1384 
1397  public function setFragment( $fragment ) {
1398  $this->mFragment = strtr( substr( $fragment, 1 ), '_', ' ' );
1399  }
1400 
1408  public function createFragmentTarget( $fragment ) {
1409  return self::makeTitle(
1410  $this->getNamespace(),
1411  $this->getText(),
1412  $fragment,
1413  $this->getInterwiki()
1414  );
1415 
1416  }
1417 
1425  private function prefix( $name ) {
1426  $p = '';
1427  if ( $this->isExternal() ) {
1428  $p = $this->mInterwiki . ':';
1429  }
1430 
1431  if ( 0 != $this->mNamespace ) {
1432  $p .= $this->getNsText() . ':';
1433  }
1434  return $p . $name;
1435  }
1436 
1443  public function getPrefixedDBkey() {
1444  $s = $this->prefix( $this->mDbkeyform );
1445  $s = strtr( $s, ' ', '_' );
1446  return $s;
1447  }
1448 
1455  public function getPrefixedText() {
1456  if ( $this->mPrefixedText === null ) {
1457  $s = $this->prefix( $this->mTextform );
1458  $s = strtr( $s, '_', ' ' );
1459  $this->mPrefixedText = $s;
1460  }
1461  return $this->mPrefixedText;
1462  }
1463 
1469  public function __toString() {
1470  return $this->getPrefixedText();
1471  }
1472 
1479  public function getFullText() {
1480  $text = $this->getPrefixedText();
1481  if ( $this->hasFragment() ) {
1482  $text .= '#' . $this->getFragment();
1483  }
1484  return $text;
1485  }
1486 
1499  public function getRootText() {
1500  if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
1501  return $this->getText();
1502  }
1503 
1504  return strtok( $this->getText(), '/' );
1505  }
1506 
1519  public function getRootTitle() {
1520  return Title::makeTitle( $this->getNamespace(), $this->getRootText() );
1521  }
1522 
1534  public function getBaseText() {
1535  if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
1536  return $this->getText();
1537  }
1538 
1539  $parts = explode( '/', $this->getText() );
1540  # Don't discard the real title if there's no subpage involved
1541  if ( count( $parts ) > 1 ) {
1542  unset( $parts[count( $parts ) - 1] );
1543  }
1544  return implode( '/', $parts );
1545  }
1546 
1559  public function getBaseTitle() {
1560  return Title::makeTitle( $this->getNamespace(), $this->getBaseText() );
1561  }
1562 
1574  public function getSubpageText() {
1575  if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
1576  return $this->mTextform;
1577  }
1578  $parts = explode( '/', $this->mTextform );
1579  return $parts[count( $parts ) - 1];
1580  }
1581 
1595  public function getSubpage( $text ) {
1596  return Title::makeTitleSafe( $this->getNamespace(), $this->getText() . '/' . $text );
1597  }
1598 
1604  public function getSubpageUrlForm() {
1605  $text = $this->getSubpageText();
1606  $text = wfUrlencode( strtr( $text, ' ', '_' ) );
1607  return $text;
1608  }
1609 
1615  public function getPrefixedURL() {
1616  $s = $this->prefix( $this->mDbkeyform );
1617  $s = wfUrlencode( strtr( $s, ' ', '_' ) );
1618  return $s;
1619  }
1620 
1634  private static function fixUrlQueryArgs( $query, $query2 = false ) {
1635  if ( $query2 !== false ) {
1636  wfDeprecated( "Title::get{Canonical,Full,Link,Local,Internal}URL " .
1637  "method called with a second parameter is deprecated. Add your " .
1638  "parameter to an array passed as the first parameter.", "1.19" );
1639  }
1640  if ( is_array( $query ) ) {
1641  $query = wfArrayToCgi( $query );
1642  }
1643  if ( $query2 ) {
1644  if ( is_string( $query2 ) ) {
1645  // $query2 is a string, we will consider this to be
1646  // a deprecated $variant argument and add it to the query
1647  $query2 = wfArrayToCgi( [ 'variant' => $query2 ] );
1648  } else {
1649  $query2 = wfArrayToCgi( $query2 );
1650  }
1651  // If we have $query content add a & to it first
1652  if ( $query ) {
1653  $query .= '&';
1654  }
1655  // Now append the queries together
1656  $query .= $query2;
1657  }
1658  return $query;
1659  }
1660 
1672  public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
1673  $query = self::fixUrlQueryArgs( $query, $query2 );
1674 
1675  # Hand off all the decisions on urls to getLocalURL
1676  $url = $this->getLocalURL( $query );
1677 
1678  # Expand the url to make it a full url. Note that getLocalURL has the
1679  # potential to output full urls for a variety of reasons, so we use
1680  # wfExpandUrl instead of simply prepending $wgServer
1681  $url = wfExpandUrl( $url, $proto );
1682 
1683  # Finally, add the fragment.
1684  $url .= $this->getFragmentForURL();
1685 
1686  Hooks::run( 'GetFullURL', [ &$this, &$url, $query ] );
1687  return $url;
1688  }
1689 
1713  public function getLocalURL( $query = '', $query2 = false ) {
1715 
1716  $query = self::fixUrlQueryArgs( $query, $query2 );
1717 
1718  $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
1719  if ( $interwiki ) {
1720  $namespace = $this->getNsText();
1721  if ( $namespace != '' ) {
1722  # Can this actually happen? Interwikis shouldn't be parsed.
1723  # Yes! It can in interwiki transclusion. But... it probably shouldn't.
1724  $namespace .= ':';
1725  }
1726  $url = $interwiki->getURL( $namespace . $this->getDBkey() );
1727  $url = wfAppendQuery( $url, $query );
1728  } else {
1729  $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
1730  if ( $query == '' ) {
1731  $url = str_replace( '$1', $dbkey, $wgArticlePath );
1732  Hooks::run( 'GetLocalURL::Article', [ &$this, &$url ] );
1733  } else {
1735  $url = false;
1736  $matches = [];
1737 
1738  if ( !empty( $wgActionPaths )
1739  && preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
1740  ) {
1741  $action = urldecode( $matches[2] );
1742  if ( isset( $wgActionPaths[$action] ) ) {
1743  $query = $matches[1];
1744  if ( isset( $matches[4] ) ) {
1745  $query .= $matches[4];
1746  }
1747  $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
1748  if ( $query != '' ) {
1749  $url = wfAppendQuery( $url, $query );
1750  }
1751  }
1752  }
1753 
1754  if ( $url === false
1755  && $wgVariantArticlePath
1756  && preg_match( '/^variant=([^&]*)$/', $query, $matches )
1757  && $this->getPageLanguage()->equals( $wgContLang )
1758  && $this->getPageLanguage()->hasVariants()
1759  ) {
1760  $variant = urldecode( $matches[1] );
1761  if ( $this->getPageLanguage()->hasVariant( $variant ) ) {
1762  // Only do the variant replacement if the given variant is a valid
1763  // variant for the page's language.
1764  $url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath );
1765  $url = str_replace( '$1', $dbkey, $url );
1766  }
1767  }
1768 
1769  if ( $url === false ) {
1770  if ( $query == '-' ) {
1771  $query = '';
1772  }
1773  $url = "{$wgScript}?title={$dbkey}&{$query}";
1774  }
1775  }
1776 
1777  Hooks::run( 'GetLocalURL::Internal', [ &$this, &$url, $query ] );
1778 
1779  // @todo FIXME: This causes breakage in various places when we
1780  // actually expected a local URL and end up with dupe prefixes.
1781  if ( $wgRequest->getVal( 'action' ) == 'render' ) {
1782  $url = $wgServer . $url;
1783  }
1784  }
1785  Hooks::run( 'GetLocalURL', [ &$this, &$url, $query ] );
1786  return $url;
1787  }
1788 
1806  public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
1807  if ( $this->isExternal() || $proto !== false ) {
1808  $ret = $this->getFullURL( $query, $query2, $proto );
1809  } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
1810  $ret = $this->getFragmentForURL();
1811  } else {
1812  $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
1813  }
1814  return $ret;
1815  }
1816 
1829  public function getInternalURL( $query = '', $query2 = false ) {
1831  $query = self::fixUrlQueryArgs( $query, $query2 );
1832  $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
1833  $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP );
1834  Hooks::run( 'GetInternalURL', [ &$this, &$url, $query ] );
1835  return $url;
1836  }
1837 
1849  public function getCanonicalURL( $query = '', $query2 = false ) {
1850  $query = self::fixUrlQueryArgs( $query, $query2 );
1851  $url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL );
1852  Hooks::run( 'GetCanonicalURL', [ &$this, &$url, $query ] );
1853  return $url;
1854  }
1855 
1861  public function getEditURL() {
1862  if ( $this->isExternal() ) {
1863  return '';
1864  }
1865  $s = $this->getLocalURL( 'action=edit' );
1866 
1867  return $s;
1868  }
1869 
1884  public function quickUserCan( $action, $user = null ) {
1885  return $this->userCan( $action, $user, false );
1886  }
1887 
1897  public function userCan( $action, $user = null, $rigor = 'secure' ) {
1898  if ( !$user instanceof User ) {
1899  global $wgUser;
1900  $user = $wgUser;
1901  }
1902 
1903  return !count( $this->getUserPermissionsErrorsInternal( $action, $user, $rigor, true ) );
1904  }
1905 
1921  public function getUserPermissionsErrors(
1922  $action, $user, $rigor = 'secure', $ignoreErrors = []
1923  ) {
1924  $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $rigor );
1925 
1926  // Remove the errors being ignored.
1927  foreach ( $errors as $index => $error ) {
1928  $errKey = is_array( $error ) ? $error[0] : $error;
1929 
1930  if ( in_array( $errKey, $ignoreErrors ) ) {
1931  unset( $errors[$index] );
1932  }
1933  if ( $errKey instanceof MessageSpecifier && in_array( $errKey->getKey(), $ignoreErrors ) ) {
1934  unset( $errors[$index] );
1935  }
1936  }
1937 
1938  return $errors;
1939  }
1940 
1952  private function checkQuickPermissions( $action, $user, $errors, $rigor, $short ) {
1953  if ( !Hooks::run( 'TitleQuickPermissions',
1954  [ $this, $user, $action, &$errors, ( $rigor !== 'quick' ), $short ] )
1955  ) {
1956  return $errors;
1957  }
1958 
1959  if ( $action == 'create' ) {
1960  if (
1961  ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
1962  ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) )
1963  ) {
1964  $errors[] = $user->isAnon() ? [ 'nocreatetext' ] : [ 'nocreate-loggedin' ];
1965  }
1966  } elseif ( $action == 'move' ) {
1967  if ( !$user->isAllowed( 'move-rootuserpages' )
1968  && $this->mNamespace == NS_USER && !$this->isSubpage() ) {
1969  // Show user page-specific message only if the user can move other pages
1970  $errors[] = [ 'cant-move-user-page' ];
1971  }
1972 
1973  // Check if user is allowed to move files if it's a file
1974  if ( $this->mNamespace == NS_FILE && !$user->isAllowed( 'movefile' ) ) {
1975  $errors[] = [ 'movenotallowedfile' ];
1976  }
1977 
1978  // Check if user is allowed to move category pages if it's a category page
1979  if ( $this->mNamespace == NS_CATEGORY && !$user->isAllowed( 'move-categorypages' ) ) {
1980  $errors[] = [ 'cant-move-category-page' ];
1981  }
1982 
1983  if ( !$user->isAllowed( 'move' ) ) {
1984  // User can't move anything
1985  $userCanMove = User::groupHasPermission( 'user', 'move' );
1986  $autoconfirmedCanMove = User::groupHasPermission( 'autoconfirmed', 'move' );
1987  if ( $user->isAnon() && ( $userCanMove || $autoconfirmedCanMove ) ) {
1988  // custom message if logged-in users without any special rights can move
1989  $errors[] = [ 'movenologintext' ];
1990  } else {
1991  $errors[] = [ 'movenotallowed' ];
1992  }
1993  }
1994  } elseif ( $action == 'move-target' ) {
1995  if ( !$user->isAllowed( 'move' ) ) {
1996  // User can't move anything
1997  $errors[] = [ 'movenotallowed' ];
1998  } elseif ( !$user->isAllowed( 'move-rootuserpages' )
1999  && $this->mNamespace == NS_USER && !$this->isSubpage() ) {
2000  // Show user page-specific message only if the user can move other pages
2001  $errors[] = [ 'cant-move-to-user-page' ];
2002  } elseif ( !$user->isAllowed( 'move-categorypages' )
2003  && $this->mNamespace == NS_CATEGORY ) {
2004  // Show category page-specific message only if the user can move other pages
2005  $errors[] = [ 'cant-move-to-category-page' ];
2006  }
2007  } elseif ( !$user->isAllowed( $action ) ) {
2008  $errors[] = $this->missingPermissionError( $action, $short );
2009  }
2010 
2011  return $errors;
2012  }
2013 
2022  private function resultToError( $errors, $result ) {
2023  if ( is_array( $result ) && count( $result ) && !is_array( $result[0] ) ) {
2024  // A single array representing an error
2025  $errors[] = $result;
2026  } elseif ( is_array( $result ) && is_array( $result[0] ) ) {
2027  // A nested array representing multiple errors
2028  $errors = array_merge( $errors, $result );
2029  } elseif ( $result !== '' && is_string( $result ) ) {
2030  // A string representing a message-id
2031  $errors[] = [ $result ];
2032  } elseif ( $result instanceof MessageSpecifier ) {
2033  // A message specifier representing an error
2034  $errors[] = [ $result ];
2035  } elseif ( $result === false ) {
2036  // a generic "We don't want them to do that"
2037  $errors[] = [ 'badaccess-group0' ];
2038  }
2039  return $errors;
2040  }
2041 
2053  private function checkPermissionHooks( $action, $user, $errors, $rigor, $short ) {
2054  // Use getUserPermissionsErrors instead
2055  $result = '';
2056  if ( !Hooks::run( 'userCan', [ &$this, &$user, $action, &$result ] ) ) {
2057  return $result ? [] : [ [ 'badaccess-group0' ] ];
2058  }
2059  // Check getUserPermissionsErrors hook
2060  if ( !Hooks::run( 'getUserPermissionsErrors', [ &$this, &$user, $action, &$result ] ) ) {
2061  $errors = $this->resultToError( $errors, $result );
2062  }
2063  // Check getUserPermissionsErrorsExpensive hook
2064  if (
2065  $rigor !== 'quick'
2066  && !( $short && count( $errors ) > 0 )
2067  && !Hooks::run( 'getUserPermissionsErrorsExpensive', [ &$this, &$user, $action, &$result ] )
2068  ) {
2069  $errors = $this->resultToError( $errors, $result );
2070  }
2071 
2072  return $errors;
2073  }
2074 
2086  private function checkSpecialsAndNSPermissions( $action, $user, $errors, $rigor, $short ) {
2087  # Only 'createaccount' can be performed on special pages,
2088  # which don't actually exist in the DB.
2089  if ( NS_SPECIAL == $this->mNamespace && $action !== 'createaccount' ) {
2090  $errors[] = [ 'ns-specialprotected' ];
2091  }
2092 
2093  # Check $wgNamespaceProtection for restricted namespaces
2094  if ( $this->isNamespaceProtected( $user ) ) {
2095  $ns = $this->mNamespace == NS_MAIN ?
2096  wfMessage( 'nstab-main' )->text() : $this->getNsText();
2097  $errors[] = $this->mNamespace == NS_MEDIAWIKI ?
2098  [ 'protectedinterface', $action ] : [ 'namespaceprotected', $ns, $action ];
2099  }
2100 
2101  return $errors;
2102  }
2103 
2115  private function checkCSSandJSPermissions( $action, $user, $errors, $rigor, $short ) {
2116  # Protect css/js subpages of user pages
2117  # XXX: this might be better using restrictions
2118  # XXX: right 'editusercssjs' is deprecated, for backward compatibility only
2119  if ( $action != 'patrol' && !$user->isAllowed( 'editusercssjs' ) ) {
2120  if ( preg_match( '/^' . preg_quote( $user->getName(), '/' ) . '\//', $this->mTextform ) ) {
2121  if ( $this->isCssSubpage() && !$user->isAllowedAny( 'editmyusercss', 'editusercss' ) ) {
2122  $errors[] = [ 'mycustomcssprotected', $action ];
2123  } elseif ( $this->isJsSubpage() && !$user->isAllowedAny( 'editmyuserjs', 'edituserjs' ) ) {
2124  $errors[] = [ 'mycustomjsprotected', $action ];
2125  }
2126  } else {
2127  if ( $this->isCssSubpage() && !$user->isAllowed( 'editusercss' ) ) {
2128  $errors[] = [ 'customcssprotected', $action ];
2129  } elseif ( $this->isJsSubpage() && !$user->isAllowed( 'edituserjs' ) ) {
2130  $errors[] = [ 'customjsprotected', $action ];
2131  }
2132  }
2133  }
2134 
2135  return $errors;
2136  }
2137 
2151  private function checkPageRestrictions( $action, $user, $errors, $rigor, $short ) {
2152  foreach ( $this->getRestrictions( $action ) as $right ) {
2153  // Backwards compatibility, rewrite sysop -> editprotected
2154  if ( $right == 'sysop' ) {
2155  $right = 'editprotected';
2156  }
2157  // Backwards compatibility, rewrite autoconfirmed -> editsemiprotected
2158  if ( $right == 'autoconfirmed' ) {
2159  $right = 'editsemiprotected';
2160  }
2161  if ( $right == '' ) {
2162  continue;
2163  }
2164  if ( !$user->isAllowed( $right ) ) {
2165  $errors[] = [ 'protectedpagetext', $right, $action ];
2166  } elseif ( $this->mCascadeRestriction && !$user->isAllowed( 'protect' ) ) {
2167  $errors[] = [ 'protectedpagetext', 'protect', $action ];
2168  }
2169  }
2170 
2171  return $errors;
2172  }
2173 
2185  private function checkCascadingSourcesRestrictions( $action, $user, $errors, $rigor, $short ) {
2186  if ( $rigor !== 'quick' && !$this->isCssJsSubpage() ) {
2187  # We /could/ use the protection level on the source page, but it's
2188  # fairly ugly as we have to establish a precedence hierarchy for pages
2189  # included by multiple cascade-protected pages. So just restrict
2190  # it to people with 'protect' permission, as they could remove the
2191  # protection anyway.
2192  list( $cascadingSources, $restrictions ) = $this->getCascadeProtectionSources();
2193  # Cascading protection depends on more than this page...
2194  # Several cascading protected pages may include this page...
2195  # Check each cascading level
2196  # This is only for protection restrictions, not for all actions
2197  if ( isset( $restrictions[$action] ) ) {
2198  foreach ( $restrictions[$action] as $right ) {
2199  // Backwards compatibility, rewrite sysop -> editprotected
2200  if ( $right == 'sysop' ) {
2201  $right = 'editprotected';
2202  }
2203  // Backwards compatibility, rewrite autoconfirmed -> editsemiprotected
2204  if ( $right == 'autoconfirmed' ) {
2205  $right = 'editsemiprotected';
2206  }
2207  if ( $right != '' && !$user->isAllowedAll( 'protect', $right ) ) {
2208  $pages = '';
2209  foreach ( $cascadingSources as $page ) {
2210  $pages .= '* [[:' . $page->getPrefixedText() . "]]\n";
2211  }
2212  $errors[] = [ 'cascadeprotected', count( $cascadingSources ), $pages, $action ];
2213  }
2214  }
2215  }
2216  }
2217 
2218  return $errors;
2219  }
2220 
2232  private function checkActionPermissions( $action, $user, $errors, $rigor, $short ) {
2233  global $wgDeleteRevisionsLimit, $wgLang;
2234 
2235  if ( $action == 'protect' ) {
2236  if ( count( $this->getUserPermissionsErrorsInternal( 'edit', $user, $rigor, true ) ) ) {
2237  // If they can't edit, they shouldn't protect.
2238  $errors[] = [ 'protect-cantedit' ];
2239  }
2240  } elseif ( $action == 'create' ) {
2241  $title_protection = $this->getTitleProtection();
2242  if ( $title_protection ) {
2243  if ( $title_protection['permission'] == ''
2244  || !$user->isAllowed( $title_protection['permission'] )
2245  ) {
2246  $errors[] = [
2247  'titleprotected',
2248  User::whoIs( $title_protection['user'] ),
2249  $title_protection['reason']
2250  ];
2251  }
2252  }
2253  } elseif ( $action == 'move' ) {
2254  // Check for immobile pages
2255  if ( !MWNamespace::isMovable( $this->mNamespace ) ) {
2256  // Specific message for this case
2257  $errors[] = [ 'immobile-source-namespace', $this->getNsText() ];
2258  } elseif ( !$this->isMovable() ) {
2259  // Less specific message for rarer cases
2260  $errors[] = [ 'immobile-source-page' ];
2261  }
2262  } elseif ( $action == 'move-target' ) {
2263  if ( !MWNamespace::isMovable( $this->mNamespace ) ) {
2264  $errors[] = [ 'immobile-target-namespace', $this->getNsText() ];
2265  } elseif ( !$this->isMovable() ) {
2266  $errors[] = [ 'immobile-target-page' ];
2267  }
2268  } elseif ( $action == 'delete' ) {
2269  $tempErrors = $this->checkPageRestrictions( 'edit', $user, [], $rigor, true );
2270  if ( !$tempErrors ) {
2271  $tempErrors = $this->checkCascadingSourcesRestrictions( 'edit',
2272  $user, $tempErrors, $rigor, true );
2273  }
2274  if ( $tempErrors ) {
2275  // If protection keeps them from editing, they shouldn't be able to delete.
2276  $errors[] = [ 'deleteprotected' ];
2277  }
2278  if ( $rigor !== 'quick' && $wgDeleteRevisionsLimit
2279  && !$this->userCan( 'bigdelete', $user ) && $this->isBigDeletion()
2280  ) {
2281  $errors[] = [ 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ];
2282  }
2283  }
2284  return $errors;
2285  }
2286 
2298  private function checkUserBlock( $action, $user, $errors, $rigor, $short ) {
2299  global $wgEmailConfirmToEdit, $wgBlockDisablesLogin;
2300  // Account creation blocks handled at userlogin.
2301  // Unblocking handled in SpecialUnblock
2302  if ( $rigor === 'quick' || in_array( $action, [ 'createaccount', 'unblock' ] ) ) {
2303  return $errors;
2304  }
2305 
2306  // Optimize for a very common case
2307  if ( $action === 'read' && !$wgBlockDisablesLogin ) {
2308  return $errors;
2309  }
2310 
2311  if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() ) {
2312  $errors[] = [ 'confirmedittext' ];
2313  }
2314 
2315  $useSlave = ( $rigor !== 'secure' );
2316  if ( ( $action == 'edit' || $action == 'create' )
2317  && !$user->isBlockedFrom( $this, $useSlave )
2318  ) {
2319  // Don't block the user from editing their own talk page unless they've been
2320  // explicitly blocked from that too.
2321  } elseif ( $user->isBlocked() && $user->getBlock()->prevents( $action ) !== false ) {
2322  // @todo FIXME: Pass the relevant context into this function.
2323  $errors[] = $user->getBlock()->getPermissionsError( RequestContext::getMain() );
2324  }
2325 
2326  return $errors;
2327  }
2328 
2340  private function checkReadPermissions( $action, $user, $errors, $rigor, $short ) {
2341  global $wgWhitelistRead, $wgWhitelistReadRegexp;
2342 
2343  $whitelisted = false;
2344  if ( User::isEveryoneAllowed( 'read' ) ) {
2345  # Shortcut for public wikis, allows skipping quite a bit of code
2346  $whitelisted = true;
2347  } elseif ( $user->isAllowed( 'read' ) ) {
2348  # If the user is allowed to read pages, he is allowed to read all pages
2349  $whitelisted = true;
2350  } elseif ( $this->isSpecial( 'Userlogin' )
2351  || $this->isSpecial( 'PasswordReset' )
2352  || $this->isSpecial( 'Userlogout' )
2353  ) {
2354  # Always grant access to the login page.
2355  # Even anons need to be able to log in.
2356  $whitelisted = true;
2357  } elseif ( is_array( $wgWhitelistRead ) && count( $wgWhitelistRead ) ) {
2358  # Time to check the whitelist
2359  # Only do these checks is there's something to check against
2360  $name = $this->getPrefixedText();
2361  $dbName = $this->getPrefixedDBkey();
2362 
2363  // Check for explicit whitelisting with and without underscores
2364  if ( in_array( $name, $wgWhitelistRead, true ) || in_array( $dbName, $wgWhitelistRead, true ) ) {
2365  $whitelisted = true;
2366  } elseif ( $this->getNamespace() == NS_MAIN ) {
2367  # Old settings might have the title prefixed with
2368  # a colon for main-namespace pages
2369  if ( in_array( ':' . $name, $wgWhitelistRead ) ) {
2370  $whitelisted = true;
2371  }
2372  } elseif ( $this->isSpecialPage() ) {
2373  # If it's a special page, ditch the subpage bit and check again
2374  $name = $this->getDBkey();
2375  list( $name, /* $subpage */ ) = SpecialPageFactory::resolveAlias( $name );
2376  if ( $name ) {
2377  $pure = SpecialPage::getTitleFor( $name )->getPrefixedText();
2378  if ( in_array( $pure, $wgWhitelistRead, true ) ) {
2379  $whitelisted = true;
2380  }
2381  }
2382  }
2383  }
2384 
2385  if ( !$whitelisted && is_array( $wgWhitelistReadRegexp ) && !empty( $wgWhitelistReadRegexp ) ) {
2386  $name = $this->getPrefixedText();
2387  // Check for regex whitelisting
2388  foreach ( $wgWhitelistReadRegexp as $listItem ) {
2389  if ( preg_match( $listItem, $name ) ) {
2390  $whitelisted = true;
2391  break;
2392  }
2393  }
2394  }
2395 
2396  if ( !$whitelisted ) {
2397  # If the title is not whitelisted, give extensions a chance to do so...
2398  Hooks::run( 'TitleReadWhitelist', [ $this, $user, &$whitelisted ] );
2399  if ( !$whitelisted ) {
2400  $errors[] = $this->missingPermissionError( $action, $short );
2401  }
2402  }
2403 
2404  return $errors;
2405  }
2406 
2415  private function missingPermissionError( $action, $short ) {
2416  // We avoid expensive display logic for quickUserCan's and such
2417  if ( $short ) {
2418  return [ 'badaccess-group0' ];
2419  }
2420 
2421  $groups = array_map( [ 'User', 'makeGroupLinkWiki' ],
2422  User::getGroupsWithPermission( $action ) );
2423 
2424  if ( count( $groups ) ) {
2425  global $wgLang;
2426  return [
2427  'badaccess-groups',
2428  $wgLang->commaList( $groups ),
2429  count( $groups )
2430  ];
2431  } else {
2432  return [ 'badaccess-group0' ];
2433  }
2434  }
2435 
2451  $action, $user, $rigor = 'secure', $short = false
2452  ) {
2453  if ( $rigor === true ) {
2454  $rigor = 'secure'; // b/c
2455  } elseif ( $rigor === false ) {
2456  $rigor = 'quick'; // b/c
2457  } elseif ( !in_array( $rigor, [ 'quick', 'full', 'secure' ] ) ) {
2458  throw new Exception( "Invalid rigor parameter '$rigor'." );
2459  }
2460 
2461  # Read has special handling
2462  if ( $action == 'read' ) {
2463  $checks = [
2464  'checkPermissionHooks',
2465  'checkReadPermissions',
2466  'checkUserBlock', // for wgBlockDisablesLogin
2467  ];
2468  # Don't call checkSpecialsAndNSPermissions or checkCSSandJSPermissions
2469  # here as it will lead to duplicate error messages. This is okay to do
2470  # since anywhere that checks for create will also check for edit, and
2471  # those checks are called for edit.
2472  } elseif ( $action == 'create' ) {
2473  $checks = [
2474  'checkQuickPermissions',
2475  'checkPermissionHooks',
2476  'checkPageRestrictions',
2477  'checkCascadingSourcesRestrictions',
2478  'checkActionPermissions',
2479  'checkUserBlock'
2480  ];
2481  } else {
2482  $checks = [
2483  'checkQuickPermissions',
2484  'checkPermissionHooks',
2485  'checkSpecialsAndNSPermissions',
2486  'checkCSSandJSPermissions',
2487  'checkPageRestrictions',
2488  'checkCascadingSourcesRestrictions',
2489  'checkActionPermissions',
2490  'checkUserBlock'
2491  ];
2492  }
2493 
2494  $errors = [];
2495  while ( count( $checks ) > 0 &&
2496  !( $short && count( $errors ) > 0 ) ) {
2497  $method = array_shift( $checks );
2498  $errors = $this->$method( $action, $user, $errors, $rigor, $short );
2499  }
2500 
2501  return $errors;
2502  }
2503 
2511  public static function getFilteredRestrictionTypes( $exists = true ) {
2512  global $wgRestrictionTypes;
2513  $types = $wgRestrictionTypes;
2514  if ( $exists ) {
2515  # Remove the create restriction for existing titles
2516  $types = array_diff( $types, [ 'create' ] );
2517  } else {
2518  # Only the create and upload restrictions apply to non-existing titles
2519  $types = array_intersect( $types, [ 'create', 'upload' ] );
2520  }
2521  return $types;
2522  }
2523 
2529  public function getRestrictionTypes() {
2530  if ( $this->isSpecialPage() ) {
2531  return [];
2532  }
2533 
2534  $types = self::getFilteredRestrictionTypes( $this->exists() );
2535 
2536  if ( $this->getNamespace() != NS_FILE ) {
2537  # Remove the upload restriction for non-file titles
2538  $types = array_diff( $types, [ 'upload' ] );
2539  }
2540 
2541  Hooks::run( 'TitleGetRestrictionTypes', [ $this, &$types ] );
2542 
2543  wfDebug( __METHOD__ . ': applicable restrictions to [[' .
2544  $this->getPrefixedText() . ']] are {' . implode( ',', $types ) . "}\n" );
2545 
2546  return $types;
2547  }
2548 
2556  public function getTitleProtection() {
2557  // Can't protect pages in special namespaces
2558  if ( $this->getNamespace() < 0 ) {
2559  return false;
2560  }
2561 
2562  // Can't protect pages that exist.
2563  if ( $this->exists() ) {
2564  return false;
2565  }
2566 
2567  if ( $this->mTitleProtection === null ) {
2568  $dbr = wfGetDB( DB_REPLICA );
2569  $res = $dbr->select(
2570  'protected_titles',
2571  [
2572  'user' => 'pt_user',
2573  'reason' => 'pt_reason',
2574  'expiry' => 'pt_expiry',
2575  'permission' => 'pt_create_perm'
2576  ],
2577  [ 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ],
2578  __METHOD__
2579  );
2580 
2581  // fetchRow returns false if there are no rows.
2582  $row = $dbr->fetchRow( $res );
2583  if ( $row ) {
2584  if ( $row['permission'] == 'sysop' ) {
2585  $row['permission'] = 'editprotected'; // B/C
2586  }
2587  if ( $row['permission'] == 'autoconfirmed' ) {
2588  $row['permission'] = 'editsemiprotected'; // B/C
2589  }
2590  $row['expiry'] = $dbr->decodeExpiry( $row['expiry'] );
2591  }
2592  $this->mTitleProtection = $row;
2593  }
2594  return $this->mTitleProtection;
2595  }
2596 
2600  public function deleteTitleProtection() {
2601  $dbw = wfGetDB( DB_MASTER );
2602 
2603  $dbw->delete(
2604  'protected_titles',
2605  [ 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ],
2606  __METHOD__
2607  );
2608  $this->mTitleProtection = false;
2609  }
2610 
2618  public function isSemiProtected( $action = 'edit' ) {
2619  global $wgSemiprotectedRestrictionLevels;
2620 
2621  $restrictions = $this->getRestrictions( $action );
2622  $semi = $wgSemiprotectedRestrictionLevels;
2623  if ( !$restrictions || !$semi ) {
2624  // Not protected, or all protection is full protection
2625  return false;
2626  }
2627 
2628  // Remap autoconfirmed to editsemiprotected for BC
2629  foreach ( array_keys( $semi, 'autoconfirmed' ) as $key ) {
2630  $semi[$key] = 'editsemiprotected';
2631  }
2632  foreach ( array_keys( $restrictions, 'autoconfirmed' ) as $key ) {
2633  $restrictions[$key] = 'editsemiprotected';
2634  }
2635 
2636  return !array_diff( $restrictions, $semi );
2637  }
2638 
2646  public function isProtected( $action = '' ) {
2647  global $wgRestrictionLevels;
2648 
2649  $restrictionTypes = $this->getRestrictionTypes();
2650 
2651  # Special pages have inherent protection
2652  if ( $this->isSpecialPage() ) {
2653  return true;
2654  }
2655 
2656  # Check regular protection levels
2657  foreach ( $restrictionTypes as $type ) {
2658  if ( $action == $type || $action == '' ) {
2659  $r = $this->getRestrictions( $type );
2660  foreach ( $wgRestrictionLevels as $level ) {
2661  if ( in_array( $level, $r ) && $level != '' ) {
2662  return true;
2663  }
2664  }
2665  }
2666  }
2667 
2668  return false;
2669  }
2670 
2678  public function isNamespaceProtected( User $user ) {
2680 
2681  if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
2682  foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
2683  if ( $right != '' && !$user->isAllowed( $right ) ) {
2684  return true;
2685  }
2686  }
2687  }
2688  return false;
2689  }
2690 
2696  public function isCascadeProtected() {
2697  list( $sources, /* $restrictions */ ) = $this->getCascadeProtectionSources( false );
2698  return ( $sources > 0 );
2699  }
2700 
2710  public function areCascadeProtectionSourcesLoaded( $getPages = true ) {
2711  return $getPages ? $this->mCascadeSources !== null : $this->mHasCascadingRestrictions !== null;
2712  }
2713 
2727  public function getCascadeProtectionSources( $getPages = true ) {
2728  $pagerestrictions = [];
2729 
2730  if ( $this->mCascadeSources !== null && $getPages ) {
2732  } elseif ( $this->mHasCascadingRestrictions !== null && !$getPages ) {
2733  return [ $this->mHasCascadingRestrictions, $pagerestrictions ];
2734  }
2735 
2736  $dbr = wfGetDB( DB_REPLICA );
2737 
2738  if ( $this->getNamespace() == NS_FILE ) {
2739  $tables = [ 'imagelinks', 'page_restrictions' ];
2740  $where_clauses = [
2741  'il_to' => $this->getDBkey(),
2742  'il_from=pr_page',
2743  'pr_cascade' => 1
2744  ];
2745  } else {
2746  $tables = [ 'templatelinks', 'page_restrictions' ];
2747  $where_clauses = [
2748  'tl_namespace' => $this->getNamespace(),
2749  'tl_title' => $this->getDBkey(),
2750  'tl_from=pr_page',
2751  'pr_cascade' => 1
2752  ];
2753  }
2754 
2755  if ( $getPages ) {
2756  $cols = [ 'pr_page', 'page_namespace', 'page_title',
2757  'pr_expiry', 'pr_type', 'pr_level' ];
2758  $where_clauses[] = 'page_id=pr_page';
2759  $tables[] = 'page';
2760  } else {
2761  $cols = [ 'pr_expiry' ];
2762  }
2763 
2764  $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__ );
2765 
2766  $sources = $getPages ? [] : false;
2767  $now = wfTimestampNow();
2768 
2769  foreach ( $res as $row ) {
2770  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2771  if ( $expiry > $now ) {
2772  if ( $getPages ) {
2773  $page_id = $row->pr_page;
2774  $page_ns = $row->page_namespace;
2775  $page_title = $row->page_title;
2776  $sources[$page_id] = Title::makeTitle( $page_ns, $page_title );
2777  # Add groups needed for each restriction type if its not already there
2778  # Make sure this restriction type still exists
2779 
2780  if ( !isset( $pagerestrictions[$row->pr_type] ) ) {
2781  $pagerestrictions[$row->pr_type] = [];
2782  }
2783 
2784  if (
2785  isset( $pagerestrictions[$row->pr_type] )
2786  && !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] )
2787  ) {
2788  $pagerestrictions[$row->pr_type][] = $row->pr_level;
2789  }
2790  } else {
2791  $sources = true;
2792  }
2793  }
2794  }
2795 
2796  if ( $getPages ) {
2797  $this->mCascadeSources = $sources;
2798  $this->mCascadingRestrictions = $pagerestrictions;
2799  } else {
2800  $this->mHasCascadingRestrictions = $sources;
2801  }
2802 
2803  return [ $sources, $pagerestrictions ];
2804  }
2805 
2813  public function areRestrictionsLoaded() {
2815  }
2816 
2826  public function getRestrictions( $action ) {
2827  if ( !$this->mRestrictionsLoaded ) {
2828  $this->loadRestrictions();
2829  }
2830  return isset( $this->mRestrictions[$action] )
2831  ? $this->mRestrictions[$action]
2832  : [];
2833  }
2834 
2842  public function getAllRestrictions() {
2843  if ( !$this->mRestrictionsLoaded ) {
2844  $this->loadRestrictions();
2845  }
2846  return $this->mRestrictions;
2847  }
2848 
2856  public function getRestrictionExpiry( $action ) {
2857  if ( !$this->mRestrictionsLoaded ) {
2858  $this->loadRestrictions();
2859  }
2860  return isset( $this->mRestrictionsExpiry[$action] ) ? $this->mRestrictionsExpiry[$action] : false;
2861  }
2862 
2869  if ( !$this->mRestrictionsLoaded ) {
2870  $this->loadRestrictions();
2871  }
2872 
2874  }
2875 
2885  public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
2886  $dbr = wfGetDB( DB_REPLICA );
2887 
2888  $restrictionTypes = $this->getRestrictionTypes();
2889 
2890  foreach ( $restrictionTypes as $type ) {
2891  $this->mRestrictions[$type] = [];
2892  $this->mRestrictionsExpiry[$type] = 'infinity';
2893  }
2894 
2895  $this->mCascadeRestriction = false;
2896 
2897  # Backwards-compatibility: also load the restrictions from the page record (old format).
2898  if ( $oldFashionedRestrictions !== null ) {
2899  $this->mOldRestrictions = $oldFashionedRestrictions;
2900  }
2901 
2902  if ( $this->mOldRestrictions === false ) {
2903  $this->mOldRestrictions = $dbr->selectField( 'page', 'page_restrictions',
2904  [ 'page_id' => $this->getArticleID() ], __METHOD__ );
2905  }
2906 
2907  if ( $this->mOldRestrictions != '' ) {
2908  foreach ( explode( ':', trim( $this->mOldRestrictions ) ) as $restrict ) {
2909  $temp = explode( '=', trim( $restrict ) );
2910  if ( count( $temp ) == 1 ) {
2911  // old old format should be treated as edit/move restriction
2912  $this->mRestrictions['edit'] = explode( ',', trim( $temp[0] ) );
2913  $this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) );
2914  } else {
2915  $restriction = trim( $temp[1] );
2916  if ( $restriction != '' ) { // some old entries are empty
2917  $this->mRestrictions[$temp[0]] = explode( ',', $restriction );
2918  }
2919  }
2920  }
2921  }
2922 
2923  if ( count( $rows ) ) {
2924  # Current system - load second to make them override.
2925  $now = wfTimestampNow();
2926 
2927  # Cycle through all the restrictions.
2928  foreach ( $rows as $row ) {
2929 
2930  // Don't take care of restrictions types that aren't allowed
2931  if ( !in_array( $row->pr_type, $restrictionTypes ) ) {
2932  continue;
2933  }
2934 
2935  // This code should be refactored, now that it's being used more generally,
2936  // But I don't really see any harm in leaving it in Block for now -werdna
2937  $expiry = $dbr->decodeExpiry( $row->pr_expiry );
2938 
2939  // Only apply the restrictions if they haven't expired!
2940  if ( !$expiry || $expiry > $now ) {
2941  $this->mRestrictionsExpiry[$row->pr_type] = $expiry;
2942  $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) );
2943 
2944  $this->mCascadeRestriction |= $row->pr_cascade;
2945  }
2946  }
2947  }
2948 
2949  $this->mRestrictionsLoaded = true;
2950  }
2951 
2958  public function loadRestrictions( $oldFashionedRestrictions = null ) {
2959  if ( $this->mRestrictionsLoaded ) {
2960  return;
2961  }
2962 
2963  $id = $this->getArticleID();
2964  if ( $id ) {
2966  $rows = $cache->getWithSetCallback(
2967  // Page protections always leave a new null revision
2968  $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ),
2969  $cache::TTL_DAY,
2970  function ( $curValue, &$ttl, array &$setOpts ) {
2971  $dbr = wfGetDB( DB_REPLICA );
2972 
2973  $setOpts += Database::getCacheSetOptions( $dbr );
2974 
2975  return iterator_to_array(
2976  $dbr->select(
2977  'page_restrictions',
2978  [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
2979  [ 'pr_page' => $this->getArticleID() ],
2980  __METHOD__
2981  )
2982  );
2983  }
2984  );
2985 
2986  $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
2987  } else {
2988  $title_protection = $this->getTitleProtection();
2989 
2990  if ( $title_protection ) {
2991  $now = wfTimestampNow();
2992  $expiry = wfGetDB( DB_REPLICA )->decodeExpiry( $title_protection['expiry'] );
2993 
2994  if ( !$expiry || $expiry > $now ) {
2995  // Apply the restrictions
2996  $this->mRestrictionsExpiry['create'] = $expiry;
2997  $this->mRestrictions['create'] =
2998  explode( ',', trim( $title_protection['permission'] ) );
2999  } else { // Get rid of the old restrictions
3000  $this->mTitleProtection = false;
3001  }
3002  } else {
3003  $this->mRestrictionsExpiry['create'] = 'infinity';
3004  }
3005  $this->mRestrictionsLoaded = true;
3006  }
3007  }
3008 
3013  public function flushRestrictions() {
3014  $this->mRestrictionsLoaded = false;
3015  $this->mTitleProtection = null;
3016  }
3017 
3023  static function purgeExpiredRestrictions() {
3024  if ( wfReadOnly() ) {
3025  return;
3026  }
3027 
3029  wfGetDB( DB_MASTER ),
3030  __METHOD__,
3031  function ( IDatabase $dbw, $fname ) {
3032  $config = MediaWikiServices::getInstance()->getMainConfig();
3033  $ids = $dbw->selectFieldValues(
3034  'page_restrictions',
3035  'pr_id',
3036  [ 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3037  $fname,
3038  [ 'LIMIT' => $config->get( 'UpdateRowsPerQuery' ) ] // T135470
3039  );
3040  if ( $ids ) {
3041  $dbw->delete( 'page_restrictions', [ 'pr_id' => $ids ], $fname );
3042  }
3043  }
3044  ) );
3045 
3047  wfGetDB( DB_MASTER ),
3048  __METHOD__,
3049  function ( IDatabase $dbw, $fname ) {
3050  $dbw->delete(
3051  'protected_titles',
3052  [ 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
3053  $fname
3054  );
3055  }
3056  ) );
3057  }
3058 
3064  public function hasSubpages() {
3065  if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
3066  # Duh
3067  return false;
3068  }
3069 
3070  # We dynamically add a member variable for the purpose of this method
3071  # alone to cache the result. There's no point in having it hanging
3072  # around uninitialized in every Title object; therefore we only add it
3073  # if needed and don't declare it statically.
3074  if ( $this->mHasSubpages === null ) {
3075  $this->mHasSubpages = false;
3076  $subpages = $this->getSubpages( 1 );
3077  if ( $subpages instanceof TitleArray ) {
3078  $this->mHasSubpages = (bool)$subpages->count();
3079  }
3080  }
3081 
3082  return $this->mHasSubpages;
3083  }
3084 
3092  public function getSubpages( $limit = -1 ) {
3093  if ( !MWNamespace::hasSubpages( $this->getNamespace() ) ) {
3094  return [];
3095  }
3096 
3097  $dbr = wfGetDB( DB_REPLICA );
3098  $conds['page_namespace'] = $this->getNamespace();
3099  $conds[] = 'page_title ' . $dbr->buildLike( $this->getDBkey() . '/', $dbr->anyString() );
3100  $options = [];
3101  if ( $limit > -1 ) {
3102  $options['LIMIT'] = $limit;
3103  }
3104  $this->mSubpages = TitleArray::newFromResult(
3105  $dbr->select( 'page',
3106  [ 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ],
3107  $conds,
3108  __METHOD__,
3109  $options
3110  )
3111  );
3112  return $this->mSubpages;
3113  }
3114 
3120  public function isDeleted() {
3121  if ( $this->getNamespace() < 0 ) {
3122  $n = 0;
3123  } else {
3124  $dbr = wfGetDB( DB_REPLICA );
3125 
3126  $n = $dbr->selectField( 'archive', 'COUNT(*)',
3127  [ 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ],
3128  __METHOD__
3129  );
3130  if ( $this->getNamespace() == NS_FILE ) {
3131  $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
3132  [ 'fa_name' => $this->getDBkey() ],
3133  __METHOD__
3134  );
3135  }
3136  }
3137  return (int)$n;
3138  }
3139 
3145  public function isDeletedQuick() {
3146  if ( $this->getNamespace() < 0 ) {
3147  return false;
3148  }
3149  $dbr = wfGetDB( DB_REPLICA );
3150  $deleted = (bool)$dbr->selectField( 'archive', '1',
3151  [ 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ],
3152  __METHOD__
3153  );
3154  if ( !$deleted && $this->getNamespace() == NS_FILE ) {
3155  $deleted = (bool)$dbr->selectField( 'filearchive', '1',
3156  [ 'fa_name' => $this->getDBkey() ],
3157  __METHOD__
3158  );
3159  }
3160  return $deleted;
3161  }
3162 
3171  public function getArticleID( $flags = 0 ) {
3172  if ( $this->getNamespace() < 0 ) {
3173  $this->mArticleID = 0;
3174  return $this->mArticleID;
3175  }
3176  $linkCache = LinkCache::singleton();
3177  if ( $flags & self::GAID_FOR_UPDATE ) {
3178  $oldUpdate = $linkCache->forUpdate( true );
3179  $linkCache->clearLink( $this );
3180  $this->mArticleID = $linkCache->addLinkObj( $this );
3181  $linkCache->forUpdate( $oldUpdate );
3182  } else {
3183  if ( -1 == $this->mArticleID ) {
3184  $this->mArticleID = $linkCache->addLinkObj( $this );
3185  }
3186  }
3187  return $this->mArticleID;
3188  }
3189 
3197  public function isRedirect( $flags = 0 ) {
3198  if ( !is_null( $this->mRedirect ) ) {
3199  return $this->mRedirect;
3200  }
3201  if ( !$this->getArticleID( $flags ) ) {
3202  $this->mRedirect = false;
3203  return $this->mRedirect;
3204  }
3205 
3206  $linkCache = LinkCache::singleton();
3207  $linkCache->addLinkObj( $this ); # in case we already had an article ID
3208  $cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' );
3209  if ( $cached === null ) {
3210  # Trust LinkCache's state over our own
3211  # LinkCache is telling us that the page doesn't exist, despite there being cached
3212  # data relating to an existing page in $this->mArticleID. Updaters should clear
3213  # LinkCache as appropriate, or use $flags = Title::GAID_FOR_UPDATE. If that flag is
3214  # set, then LinkCache will definitely be up to date here, since getArticleID() forces
3215  # LinkCache to refresh its data from the master.
3216  $this->mRedirect = false;
3217  return $this->mRedirect;
3218  }
3219 
3220  $this->mRedirect = (bool)$cached;
3221 
3222  return $this->mRedirect;
3223  }
3224 
3232  public function getLength( $flags = 0 ) {
3233  if ( $this->mLength != -1 ) {
3234  return $this->mLength;
3235  }
3236  if ( !$this->getArticleID( $flags ) ) {
3237  $this->mLength = 0;
3238  return $this->mLength;
3239  }
3240  $linkCache = LinkCache::singleton();
3241  $linkCache->addLinkObj( $this ); # in case we already had an article ID
3242  $cached = $linkCache->getGoodLinkFieldObj( $this, 'length' );
3243  if ( $cached === null ) {
3244  # Trust LinkCache's state over our own, as for isRedirect()
3245  $this->mLength = 0;
3246  return $this->mLength;
3247  }
3248 
3249  $this->mLength = intval( $cached );
3250 
3251  return $this->mLength;
3252  }
3253 
3260  public function getLatestRevID( $flags = 0 ) {
3261  if ( !( $flags & Title::GAID_FOR_UPDATE ) && $this->mLatestID !== false ) {
3262  return intval( $this->mLatestID );
3263  }
3264  if ( !$this->getArticleID( $flags ) ) {
3265  $this->mLatestID = 0;
3266  return $this->mLatestID;
3267  }
3268  $linkCache = LinkCache::singleton();
3269  $linkCache->addLinkObj( $this ); # in case we already had an article ID
3270  $cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' );
3271  if ( $cached === null ) {
3272  # Trust LinkCache's state over our own, as for isRedirect()
3273  $this->mLatestID = 0;
3274  return $this->mLatestID;
3275  }
3276 
3277  $this->mLatestID = intval( $cached );
3278 
3279  return $this->mLatestID;
3280  }
3281 
3292  public function resetArticleID( $newid ) {
3293  $linkCache = LinkCache::singleton();
3294  $linkCache->clearLink( $this );
3295 
3296  if ( $newid === false ) {
3297  $this->mArticleID = -1;
3298  } else {
3299  $this->mArticleID = intval( $newid );
3300  }
3301  $this->mRestrictionsLoaded = false;
3302  $this->mRestrictions = [];
3303  $this->mOldRestrictions = false;
3304  $this->mRedirect = null;
3305  $this->mLength = -1;
3306  $this->mLatestID = false;
3307  $this->mContentModel = false;
3308  $this->mEstimateRevisions = null;
3309  $this->mPageLanguage = false;
3310  $this->mDbPageLanguage = false;
3311  $this->mIsBigDeletion = null;
3312  }
3313 
3314  public static function clearCaches() {
3315  $linkCache = LinkCache::singleton();
3316  $linkCache->clear();
3317 
3318  $titleCache = self::getTitleCache();
3319  $titleCache->clear();
3320  }
3321 
3329  public static function capitalize( $text, $ns = NS_MAIN ) {
3331 
3332  if ( MWNamespace::isCapitalized( $ns ) ) {
3333  return $wgContLang->ucfirst( $text );
3334  } else {
3335  return $text;
3336  }
3337  }
3338 
3351  private function secureAndSplit() {
3352  # Initialisation
3353  $this->mInterwiki = '';
3354  $this->mFragment = '';
3355  $this->mNamespace = $this->mDefaultNamespace; # Usually NS_MAIN
3356 
3357  $dbkey = $this->mDbkeyform;
3358 
3359  // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
3360  // the parsing code with Title, while avoiding massive refactoring.
3361  // @todo: get rid of secureAndSplit, refactor parsing code.
3362  // @note: getTitleParser() returns a TitleParser implementation which does not have a
3363  // splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
3364  $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
3365  // MalformedTitleException can be thrown here
3366  $parts = $titleCodec->splitTitleString( $dbkey, $this->getDefaultNamespace() );
3367 
3368  # Fill fields
3369  $this->setFragment( '#' . $parts['fragment'] );
3370  $this->mInterwiki = $parts['interwiki'];
3371  $this->mLocalInterwiki = $parts['local_interwiki'];
3372  $this->mNamespace = $parts['namespace'];
3373  $this->mUserCaseDBKey = $parts['user_case_dbkey'];
3374 
3375  $this->mDbkeyform = $parts['dbkey'];
3376  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
3377  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
3378 
3379  # We already know that some pages won't be in the database!
3380  if ( $this->isExternal() || $this->mNamespace == NS_SPECIAL ) {
3381  $this->mArticleID = 0;
3382  }
3383 
3384  return true;
3385  }
3386 
3399  public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3400  if ( count( $options ) > 0 ) {
3401  $db = wfGetDB( DB_MASTER );
3402  } else {
3403  $db = wfGetDB( DB_REPLICA );
3404  }
3405 
3406  $res = $db->select(
3407  [ 'page', $table ],
3408  self::getSelectFields(),
3409  [
3410  "{$prefix}_from=page_id",
3411  "{$prefix}_namespace" => $this->getNamespace(),
3412  "{$prefix}_title" => $this->getDBkey() ],
3413  __METHOD__,
3414  $options
3415  );
3416 
3417  $retVal = [];
3418  if ( $res->numRows() ) {
3419  $linkCache = LinkCache::singleton();
3420  foreach ( $res as $row ) {
3421  $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title );
3422  if ( $titleObj ) {
3423  $linkCache->addGoodLinkObjFromRow( $titleObj, $row );
3424  $retVal[] = $titleObj;
3425  }
3426  }
3427  }
3428  return $retVal;
3429  }
3430 
3441  public function getTemplateLinksTo( $options = [] ) {
3442  return $this->getLinksTo( $options, 'templatelinks', 'tl' );
3443  }
3444 
3457  public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
3458  $id = $this->getArticleID();
3459 
3460  # If the page doesn't exist; there can't be any link from this page
3461  if ( !$id ) {
3462  return [];
3463  }
3464 
3465  $db = wfGetDB( DB_REPLICA );
3466 
3467  $blNamespace = "{$prefix}_namespace";
3468  $blTitle = "{$prefix}_title";
3469 
3470  $res = $db->select(
3471  [ $table, 'page' ],
3472  array_merge(
3473  [ $blNamespace, $blTitle ],
3475  ),
3476  [ "{$prefix}_from" => $id ],
3477  __METHOD__,
3478  $options,
3479  [ 'page' => [
3480  'LEFT JOIN',
3481  [ "page_namespace=$blNamespace", "page_title=$blTitle" ]
3482  ] ]
3483  );
3484 
3485  $retVal = [];
3486  $linkCache = LinkCache::singleton();
3487  foreach ( $res as $row ) {
3488  if ( $row->page_id ) {
3489  $titleObj = Title::newFromRow( $row );
3490  } else {
3491  $titleObj = Title::makeTitle( $row->$blNamespace, $row->$blTitle );
3492  $linkCache->addBadLinkObj( $titleObj );
3493  }
3494  $retVal[] = $titleObj;
3495  }
3496 
3497  return $retVal;
3498  }
3499 
3510  public function getTemplateLinksFrom( $options = [] ) {
3511  return $this->getLinksFrom( $options, 'templatelinks', 'tl' );
3512  }
3513 
3522  public function getBrokenLinksFrom() {
3523  if ( $this->getArticleID() == 0 ) {
3524  # All links from article ID 0 are false positives
3525  return [];
3526  }
3527 
3528  $dbr = wfGetDB( DB_REPLICA );
3529  $res = $dbr->select(
3530  [ 'page', 'pagelinks' ],
3531  [ 'pl_namespace', 'pl_title' ],
3532  [
3533  'pl_from' => $this->getArticleID(),
3534  'page_namespace IS NULL'
3535  ],
3536  __METHOD__, [],
3537  [
3538  'page' => [
3539  'LEFT JOIN',
3540  [ 'pl_namespace=page_namespace', 'pl_title=page_title' ]
3541  ]
3542  ]
3543  );
3544 
3545  $retVal = [];
3546  foreach ( $res as $row ) {
3547  $retVal[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
3548  }
3549  return $retVal;
3550  }
3551 
3558  public function getCdnUrls() {
3559  $urls = [
3560  $this->getInternalURL(),
3561  $this->getInternalURL( 'action=history' )
3562  ];
3563 
3564  $pageLang = $this->getPageLanguage();
3565  if ( $pageLang->hasVariants() ) {
3566  $variants = $pageLang->getVariants();
3567  foreach ( $variants as $vCode ) {
3568  $urls[] = $this->getInternalURL( $vCode );
3569  }
3570  }
3571 
3572  // If we are looking at a css/js user subpage, purge the action=raw.
3573  if ( $this->isJsSubpage() ) {
3574  $urls[] = $this->getInternalURL( 'action=raw&ctype=text/javascript' );
3575  } elseif ( $this->isCssSubpage() ) {
3576  $urls[] = $this->getInternalURL( 'action=raw&ctype=text/css' );
3577  }
3578 
3579  Hooks::run( 'TitleSquidURLs', [ $this, &$urls ] );
3580  return $urls;
3581  }
3582 
3586  public function getSquidURLs() {
3587  return $this->getCdnUrls();
3588  }
3589 
3593  public function purgeSquid() {
3595  new CdnCacheUpdate( $this->getCdnUrls() ),
3597  );
3598  }
3599 
3607  public function moveNoAuth( &$nt ) {
3608  wfDeprecated( __METHOD__, '1.25' );
3609  return $this->moveTo( $nt, false );
3610  }
3611 
3622  public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) {
3623  global $wgUser;
3624 
3625  if ( !( $nt instanceof Title ) ) {
3626  // Normally we'd add this to $errors, but we'll get
3627  // lots of syntax errors if $nt is not an object
3628  return [ [ 'badtitletext' ] ];
3629  }
3630 
3631  $mp = new MovePage( $this, $nt );
3632  $errors = $mp->isValidMove()->getErrorsArray();
3633  if ( $auth ) {
3634  $errors = wfMergeErrorArrays(
3635  $errors,
3636  $mp->checkPermissions( $wgUser, $reason )->getErrorsArray()
3637  );
3638  }
3639 
3640  return $errors ?: true;
3641  }
3642 
3649  protected function validateFileMoveOperation( $nt ) {
3650  global $wgUser;
3651 
3652  $errors = [];
3653 
3654  $destFile = wfLocalFile( $nt );
3655  $destFile->load( File::READ_LATEST );
3656  if ( !$wgUser->isAllowed( 'reupload-shared' )
3657  && !$destFile->exists() && wfFindFile( $nt )
3658  ) {
3659  $errors[] = [ 'file-exists-sharedrepo' ];
3660  }
3661 
3662  return $errors;
3663  }
3664 
3677  public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
3678  global $wgUser;
3679  $err = $this->isValidMoveOperation( $nt, $auth, $reason );
3680  if ( is_array( $err ) ) {
3681  // Auto-block user's IP if the account was "hard" blocked
3682  $wgUser->spreadAnyEditBlock();
3683  return $err;
3684  }
3685  // Check suppressredirect permission
3686  if ( $auth && !$wgUser->isAllowed( 'suppressredirect' ) ) {
3687  $createRedirect = true;
3688  }
3689 
3690  $mp = new MovePage( $this, $nt );
3691  $status = $mp->move( $wgUser, $reason, $createRedirect );
3692  if ( $status->isOK() ) {
3693  return true;
3694  } else {
3695  return $status->getErrorsArray();
3696  }
3697  }
3698 
3711  public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true ) {
3712  global $wgMaximumMovedPages;
3713  // Check permissions
3714  if ( !$this->userCan( 'move-subpages' ) ) {
3715  return [ 'cant-move-subpages' ];
3716  }
3717  // Do the source and target namespaces support subpages?
3718  if ( !MWNamespace::hasSubpages( $this->getNamespace() ) ) {
3719  return [ 'namespace-nosubpages',
3721  }
3722  if ( !MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
3723  return [ 'namespace-nosubpages',
3724  MWNamespace::getCanonicalName( $nt->getNamespace() ) ];
3725  }
3726 
3727  $subpages = $this->getSubpages( $wgMaximumMovedPages + 1 );
3728  $retval = [];
3729  $count = 0;
3730  foreach ( $subpages as $oldSubpage ) {
3731  $count++;
3732  if ( $count > $wgMaximumMovedPages ) {
3733  $retval[$oldSubpage->getPrefixedText()] =
3734  [ 'movepage-max-pages',
3735  $wgMaximumMovedPages ];
3736  break;
3737  }
3738 
3739  // We don't know whether this function was called before
3740  // or after moving the root page, so check both
3741  // $this and $nt
3742  if ( $oldSubpage->getArticleID() == $this->getArticleID()
3743  || $oldSubpage->getArticleID() == $nt->getArticleID()
3744  ) {
3745  // When moving a page to a subpage of itself,
3746  // don't move it twice
3747  continue;
3748  }
3749  $newPageName = preg_replace(
3750  '#^' . preg_quote( $this->getDBkey(), '#' ) . '#',
3751  StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
3752  $oldSubpage->getDBkey() );
3753  if ( $oldSubpage->isTalkPage() ) {
3754  $newNs = $nt->getTalkPage()->getNamespace();
3755  } else {
3756  $newNs = $nt->getSubjectPage()->getNamespace();
3757  }
3758  # Bug 14385: we need makeTitleSafe because the new page names may
3759  # be longer than 255 characters.
3760  $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
3761 
3762  $success = $oldSubpage->moveTo( $newSubpage, $auth, $reason, $createRedirect );
3763  if ( $success === true ) {
3764  $retval[$oldSubpage->getPrefixedText()] = $newSubpage->getPrefixedText();
3765  } else {
3766  $retval[$oldSubpage->getPrefixedText()] = $success;
3767  }
3768  }
3769  return $retval;
3770  }
3771 
3778  public function isSingleRevRedirect() {
3779  global $wgContentHandlerUseDB;
3780 
3781  $dbw = wfGetDB( DB_MASTER );
3782 
3783  # Is it a redirect?
3784  $fields = [ 'page_is_redirect', 'page_latest', 'page_id' ];
3785  if ( $wgContentHandlerUseDB ) {
3786  $fields[] = 'page_content_model';
3787  }
3788 
3789  $row = $dbw->selectRow( 'page',
3790  $fields,
3791  $this->pageCond(),
3792  __METHOD__,
3793  [ 'FOR UPDATE' ]
3794  );
3795  # Cache some fields we may want
3796  $this->mArticleID = $row ? intval( $row->page_id ) : 0;
3797  $this->mRedirect = $row ? (bool)$row->page_is_redirect : false;
3798  $this->mLatestID = $row ? intval( $row->page_latest ) : false;
3799  $this->mContentModel = $row && isset( $row->page_content_model )
3800  ? strval( $row->page_content_model )
3801  : false;
3802 
3803  if ( !$this->mRedirect ) {
3804  return false;
3805  }
3806  # Does the article have a history?
3807  $row = $dbw->selectField( [ 'page', 'revision' ],
3808  'rev_id',
3809  [ 'page_namespace' => $this->getNamespace(),
3810  'page_title' => $this->getDBkey(),
3811  'page_id=rev_page',
3812  'page_latest != rev_id'
3813  ],
3814  __METHOD__,
3815  [ 'FOR UPDATE' ]
3816  );
3817  # Return true if there was no history
3818  return ( $row === false );
3819  }
3820 
3829  public function isValidMoveTarget( $nt ) {
3830  # Is it an existing file?
3831  if ( $nt->getNamespace() == NS_FILE ) {
3832  $file = wfLocalFile( $nt );
3833  $file->load( File::READ_LATEST );
3834  if ( $file->exists() ) {
3835  wfDebug( __METHOD__ . ": file exists\n" );
3836  return false;
3837  }
3838  }
3839  # Is it a redirect with no history?
3840  if ( !$nt->isSingleRevRedirect() ) {
3841  wfDebug( __METHOD__ . ": not a one-rev redirect\n" );
3842  return false;
3843  }
3844  # Get the article text
3845  $rev = Revision::newFromTitle( $nt, false, Revision::READ_LATEST );
3846  if ( !is_object( $rev ) ) {
3847  return false;
3848  }
3849  $content = $rev->getContent();
3850  # Does the redirect point to the source?
3851  # Or is it a broken self-redirect, usually caused by namespace collisions?
3852  $redirTitle = $content ? $content->getRedirectTarget() : null;
3853 
3854  if ( $redirTitle ) {
3855  if ( $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() &&
3856  $redirTitle->getPrefixedDBkey() != $nt->getPrefixedDBkey() ) {
3857  wfDebug( __METHOD__ . ": redirect points to other page\n" );
3858  return false;
3859  } else {
3860  return true;
3861  }
3862  } else {
3863  # Fail safe (not a redirect after all. strange.)
3864  wfDebug( __METHOD__ . ": failsafe: database sais " . $nt->getPrefixedDBkey() .
3865  " is a redirect, but it doesn't contain a valid redirect.\n" );
3866  return false;
3867  }
3868  }
3869 
3877  public function getParentCategories() {
3879 
3880  $data = [];
3881 
3882  $titleKey = $this->getArticleID();
3883 
3884  if ( $titleKey === 0 ) {
3885  return $data;
3886  }
3887 
3888  $dbr = wfGetDB( DB_REPLICA );
3889 
3890  $res = $dbr->select(
3891  'categorylinks',
3892  'cl_to',
3893  [ 'cl_from' => $titleKey ],
3894  __METHOD__
3895  );
3896 
3897  if ( $res->numRows() > 0 ) {
3898  foreach ( $res as $row ) {
3899  // $data[] = Title::newFromText($wgContLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
3900  $data[$wgContLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] = $this->getFullText();
3901  }
3902  }
3903  return $data;
3904  }
3905 
3912  public function getParentCategoryTree( $children = [] ) {
3913  $stack = [];
3914  $parents = $this->getParentCategories();
3915 
3916  if ( $parents ) {
3917  foreach ( $parents as $parent => $current ) {
3918  if ( array_key_exists( $parent, $children ) ) {
3919  # Circular reference
3920  $stack[$parent] = [];
3921  } else {
3922  $nt = Title::newFromText( $parent );
3923  if ( $nt ) {
3924  $stack[$parent] = $nt->getParentCategoryTree( $children + [ $parent => 1 ] );
3925  }
3926  }
3927  }
3928  }
3929 
3930  return $stack;
3931  }
3932 
3939  public function pageCond() {
3940  if ( $this->mArticleID > 0 ) {
3941  // PK avoids secondary lookups in InnoDB, shouldn't hurt other DBs
3942  return [ 'page_id' => $this->mArticleID ];
3943  } else {
3944  return [ 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform ];
3945  }
3946  }
3947 
3955  public function getPreviousRevisionID( $revId, $flags = 0 ) {
3956  $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_REPLICA );
3957  $revId = $db->selectField( 'revision', 'rev_id',
3958  [
3959  'rev_page' => $this->getArticleID( $flags ),
3960  'rev_id < ' . intval( $revId )
3961  ],
3962  __METHOD__,
3963  [ 'ORDER BY' => 'rev_id DESC' ]
3964  );
3965 
3966  if ( $revId === false ) {
3967  return false;
3968  } else {
3969  return intval( $revId );
3970  }
3971  }
3972 
3980  public function getNextRevisionID( $revId, $flags = 0 ) {
3981  $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_REPLICA );
3982  $revId = $db->selectField( 'revision', 'rev_id',
3983  [
3984  'rev_page' => $this->getArticleID( $flags ),
3985  'rev_id > ' . intval( $revId )
3986  ],
3987  __METHOD__,
3988  [ 'ORDER BY' => 'rev_id' ]
3989  );
3990 
3991  if ( $revId === false ) {
3992  return false;
3993  } else {
3994  return intval( $revId );
3995  }
3996  }
3997 
4004  public function getFirstRevision( $flags = 0 ) {
4005  $pageId = $this->getArticleID( $flags );
4006  if ( $pageId ) {
4007  $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_REPLICA );
4008  $row = $db->selectRow( 'revision', Revision::selectFields(),
4009  [ 'rev_page' => $pageId ],
4010  __METHOD__,
4011  [ 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 1 ]
4012  );
4013  if ( $row ) {
4014  return new Revision( $row );
4015  }
4016  }
4017  return null;
4018  }
4019 
4026  public function getEarliestRevTime( $flags = 0 ) {
4027  $rev = $this->getFirstRevision( $flags );
4028  return $rev ? $rev->getTimestamp() : null;
4029  }
4030 
4036  public function isNewPage() {
4037  $dbr = wfGetDB( DB_REPLICA );
4038  return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ );
4039  }
4040 
4046  public function isBigDeletion() {
4047  global $wgDeleteRevisionsLimit;
4048 
4049  if ( !$wgDeleteRevisionsLimit ) {
4050  return false;
4051  }
4052 
4053  if ( $this->mIsBigDeletion === null ) {
4054  $dbr = wfGetDB( DB_REPLICA );
4055 
4056  $revCount = $dbr->selectRowCount(
4057  'revision',
4058  '1',
4059  [ 'rev_page' => $this->getArticleID() ],
4060  __METHOD__,
4061  [ 'LIMIT' => $wgDeleteRevisionsLimit + 1 ]
4062  );
4063 
4064  $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit;
4065  }
4066 
4067  return $this->mIsBigDeletion;
4068  }
4069 
4075  public function estimateRevisionCount() {
4076  if ( !$this->exists() ) {
4077  return 0;
4078  }
4079 
4080  if ( $this->mEstimateRevisions === null ) {
4081  $dbr = wfGetDB( DB_REPLICA );
4082  $this->mEstimateRevisions = $dbr->estimateRowCount( 'revision', '*',
4083  [ 'rev_page' => $this->getArticleID() ], __METHOD__ );
4084  }
4085 
4087  }
4088 
4098  public function countRevisionsBetween( $old, $new, $max = null ) {
4099  if ( !( $old instanceof Revision ) ) {
4100  $old = Revision::newFromTitle( $this, (int)$old );
4101  }
4102  if ( !( $new instanceof Revision ) ) {
4103  $new = Revision::newFromTitle( $this, (int)$new );
4104  }
4105  if ( !$old || !$new ) {
4106  return 0; // nothing to compare
4107  }
4108  $dbr = wfGetDB( DB_REPLICA );
4109  $conds = [
4110  'rev_page' => $this->getArticleID(),
4111  'rev_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $old->getTimestamp() ) ),
4112  'rev_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( $new->getTimestamp() ) )
4113  ];
4114  if ( $max !== null ) {
4115  return $dbr->selectRowCount( 'revision', '1',
4116  $conds,
4117  __METHOD__,
4118  [ 'LIMIT' => $max + 1 ] // extra to detect truncation
4119  );
4120  } else {
4121  return (int)$dbr->selectField( 'revision', 'count(*)', $conds, __METHOD__ );
4122  }
4123  }
4124 
4141  public function getAuthorsBetween( $old, $new, $limit, $options = [] ) {
4142  if ( !( $old instanceof Revision ) ) {
4143  $old = Revision::newFromTitle( $this, (int)$old );
4144  }
4145  if ( !( $new instanceof Revision ) ) {
4146  $new = Revision::newFromTitle( $this, (int)$new );
4147  }
4148  // XXX: what if Revision objects are passed in, but they don't refer to this title?
4149  // Add $old->getPage() != $new->getPage() || $old->getPage() != $this->getArticleID()
4150  // in the sanity check below?
4151  if ( !$old || !$new ) {
4152  return null; // nothing to compare
4153  }
4154  $authors = [];
4155  $old_cmp = '>';
4156  $new_cmp = '<';
4157  $options = (array)$options;
4158  if ( in_array( 'include_old', $options ) ) {
4159  $old_cmp = '>=';
4160  }
4161  if ( in_array( 'include_new', $options ) ) {
4162  $new_cmp = '<=';
4163  }
4164  if ( in_array( 'include_both', $options ) ) {
4165  $old_cmp = '>=';
4166  $new_cmp = '<=';
4167  }
4168  // No DB query needed if $old and $new are the same or successive revisions:
4169  if ( $old->getId() === $new->getId() ) {
4170  return ( $old_cmp === '>' && $new_cmp === '<' ) ?
4171  [] :
4172  [ $old->getUserText( Revision::RAW ) ];
4173  } elseif ( $old->getId() === $new->getParentId() ) {
4174  if ( $old_cmp === '>=' && $new_cmp === '<=' ) {
4175  $authors[] = $old->getUserText( Revision::RAW );
4176  if ( $old->getUserText( Revision::RAW ) != $new->getUserText( Revision::RAW ) ) {
4177  $authors[] = $new->getUserText( Revision::RAW );
4178  }
4179  } elseif ( $old_cmp === '>=' ) {
4180  $authors[] = $old->getUserText( Revision::RAW );
4181  } elseif ( $new_cmp === '<=' ) {
4182  $authors[] = $new->getUserText( Revision::RAW );
4183  }
4184  return $authors;
4185  }
4186  $dbr = wfGetDB( DB_REPLICA );
4187  $res = $dbr->select( 'revision', 'DISTINCT rev_user_text',
4188  [
4189  'rev_page' => $this->getArticleID(),
4190  "rev_timestamp $old_cmp " . $dbr->addQuotes( $dbr->timestamp( $old->getTimestamp() ) ),
4191  "rev_timestamp $new_cmp " . $dbr->addQuotes( $dbr->timestamp( $new->getTimestamp() ) )
4192  ], __METHOD__,
4193  [ 'LIMIT' => $limit + 1 ] // add one so caller knows it was truncated
4194  );
4195  foreach ( $res as $row ) {
4196  $authors[] = $row->rev_user_text;
4197  }
4198  return $authors;
4199  }
4200 
4215  public function countAuthorsBetween( $old, $new, $limit, $options = [] ) {
4216  $authors = $this->getAuthorsBetween( $old, $new, $limit, $options );
4217  return $authors ? count( $authors ) : 0;
4218  }
4219 
4226  public function equals( Title $title ) {
4227  // Note: === is necessary for proper matching of number-like titles.
4228  return $this->getInterwiki() === $title->getInterwiki()
4229  && $this->getNamespace() == $title->getNamespace()
4230  && $this->getDBkey() === $title->getDBkey();
4231  }
4232 
4239  public function isSubpageOf( Title $title ) {
4240  return $this->getInterwiki() === $title->getInterwiki()
4241  && $this->getNamespace() == $title->getNamespace()
4242  && strpos( $this->getDBkey(), $title->getDBkey() . '/' ) === 0;
4243  }
4244 
4256  public function exists( $flags = 0 ) {
4257  $exists = $this->getArticleID( $flags ) != 0;
4258  Hooks::run( 'TitleExists', [ $this, &$exists ] );
4259  return $exists;
4260  }
4261 
4278  public function isAlwaysKnown() {
4279  $isKnown = null;
4280 
4291  Hooks::run( 'TitleIsAlwaysKnown', [ $this, &$isKnown ] );
4292 
4293  if ( !is_null( $isKnown ) ) {
4294  return $isKnown;
4295  }
4296 
4297  if ( $this->isExternal() ) {
4298  return true; // any interwiki link might be viewable, for all we know
4299  }
4300 
4301  switch ( $this->mNamespace ) {
4302  case NS_MEDIA:
4303  case NS_FILE:
4304  // file exists, possibly in a foreign repo
4305  return (bool)wfFindFile( $this );
4306  case NS_SPECIAL:
4307  // valid special page
4308  return SpecialPageFactory::exists( $this->getDBkey() );
4309  case NS_MAIN:
4310  // selflink, possibly with fragment
4311  return $this->mDbkeyform == '';
4312  case NS_MEDIAWIKI:
4313  // known system message
4314  return $this->hasSourceText() !== false;
4315  default:
4316  return false;
4317  }
4318  }
4319 
4331  public function isKnown() {
4332  return $this->isAlwaysKnown() || $this->exists();
4333  }
4334 
4340  public function hasSourceText() {
4341  if ( $this->exists() ) {
4342  return true;
4343  }
4344 
4345  if ( $this->mNamespace == NS_MEDIAWIKI ) {
4346  // If the page doesn't exist but is a known system message, default
4347  // message content will be displayed, same for language subpages-
4348  // Use always content language to avoid loading hundreds of languages
4349  // to get the link color.
4351  list( $name, ) = MessageCache::singleton()->figureMessage(
4352  $wgContLang->lcfirst( $this->getText() )
4353  );
4354  $message = wfMessage( $name )->inLanguage( $wgContLang )->useDatabase( false );
4355  return $message->exists();
4356  }
4357 
4358  return false;
4359  }
4360 
4366  public function getDefaultMessageText() {
4368 
4369  if ( $this->getNamespace() != NS_MEDIAWIKI ) { // Just in case
4370  return false;
4371  }
4372 
4373  list( $name, $lang ) = MessageCache::singleton()->figureMessage(
4374  $wgContLang->lcfirst( $this->getText() )
4375  );
4376  $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
4377 
4378  if ( $message->exists() ) {
4379  return $message->plain();
4380  } else {
4381  return false;
4382  }
4383  }
4384 
4391  public function invalidateCache( $purgeTime = null ) {
4392  if ( wfReadOnly() ) {
4393  return false;
4394  } elseif ( $this->mArticleID === 0 ) {
4395  return true; // avoid gap locking if we know it's not there
4396  }
4397 
4398  $dbw = wfGetDB( DB_MASTER );
4399  $dbw->onTransactionPreCommitOrIdle( function () {
4401  } );
4402 
4403  $conds = $this->pageCond();
4405  new AutoCommitUpdate(
4406  $dbw,
4407  __METHOD__,
4408  function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) {
4409  $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
4410  $dbw->update(
4411  'page',
4412  [ 'page_touched' => $dbTimestamp ],
4413  $conds + [ 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ],
4414  $fname
4415  );
4416  MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $this );
4417  }
4418  ),
4420  );
4421 
4422  return true;
4423  }
4424 
4430  public function touchLinks() {
4431  DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this, 'pagelinks' ) );
4432  if ( $this->getNamespace() == NS_CATEGORY ) {
4433  DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this, 'categorylinks' ) );
4434  }
4435  }
4436 
4443  public function getTouched( $db = null ) {
4444  if ( $db === null ) {
4445  $db = wfGetDB( DB_REPLICA );
4446  }
4447  $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ );
4448  return $touched;
4449  }
4450 
4457  public function getNotificationTimestamp( $user = null ) {
4458  global $wgUser;
4459 
4460  // Assume current user if none given
4461  if ( !$user ) {
4462  $user = $wgUser;
4463  }
4464  // Check cache first
4465  $uid = $user->getId();
4466  if ( !$uid ) {
4467  return false;
4468  }
4469  // avoid isset here, as it'll return false for null entries
4470  if ( array_key_exists( $uid, $this->mNotificationTimestamp ) ) {
4471  return $this->mNotificationTimestamp[$uid];
4472  }
4473  // Don't cache too much!
4474  if ( count( $this->mNotificationTimestamp ) >= self::CACHE_MAX ) {
4475  $this->mNotificationTimestamp = [];
4476  }
4477 
4478  $store = MediaWikiServices::getInstance()->getWatchedItemStore();
4479  $watchedItem = $store->getWatchedItem( $user, $this );
4480  if ( $watchedItem ) {
4481  $this->mNotificationTimestamp[$uid] = $watchedItem->getNotificationTimestamp();
4482  } else {
4483  $this->mNotificationTimestamp[$uid] = false;
4484  }
4485 
4486  return $this->mNotificationTimestamp[$uid];
4487  }
4488 
4495  public function getNamespaceKey( $prepend = 'nstab-' ) {
4497  // Gets the subject namespace if this title
4498  $namespace = MWNamespace::getSubject( $this->getNamespace() );
4499  // Checks if canonical namespace name exists for namespace
4500  if ( MWNamespace::exists( $this->getNamespace() ) ) {
4501  // Uses canonical namespace name
4502  $namespaceKey = MWNamespace::getCanonicalName( $namespace );
4503  } else {
4504  // Uses text of namespace
4505  $namespaceKey = $this->getSubjectNsText();
4506  }
4507  // Makes namespace key lowercase
4508  $namespaceKey = $wgContLang->lc( $namespaceKey );
4509  // Uses main
4510  if ( $namespaceKey == '' ) {
4511  $namespaceKey = 'main';
4512  }
4513  // Changes file to image for backwards compatibility
4514  if ( $namespaceKey == 'file' ) {
4515  $namespaceKey = 'image';
4516  }
4517  return $prepend . $namespaceKey;
4518  }
4519 
4526  public function getRedirectsHere( $ns = null ) {
4527  $redirs = [];
4528 
4529  $dbr = wfGetDB( DB_REPLICA );
4530  $where = [
4531  'rd_namespace' => $this->getNamespace(),
4532  'rd_title' => $this->getDBkey(),
4533  'rd_from = page_id'
4534  ];
4535  if ( $this->isExternal() ) {
4536  $where['rd_interwiki'] = $this->getInterwiki();
4537  } else {
4538  $where[] = 'rd_interwiki = ' . $dbr->addQuotes( '' ) . ' OR rd_interwiki IS NULL';
4539  }
4540  if ( !is_null( $ns ) ) {
4541  $where['page_namespace'] = $ns;
4542  }
4543 
4544  $res = $dbr->select(
4545  [ 'redirect', 'page' ],
4546  [ 'page_namespace', 'page_title' ],
4547  $where,
4548  __METHOD__
4549  );
4550 
4551  foreach ( $res as $row ) {
4552  $redirs[] = self::newFromRow( $row );
4553  }
4554  return $redirs;
4555  }
4556 
4562  public function isValidRedirectTarget() {
4563  global $wgInvalidRedirectTargets;
4564 
4565  if ( $this->isSpecialPage() ) {
4566  // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
4567  if ( $this->isSpecial( 'Userlogout' ) ) {
4568  return false;
4569  }
4570 
4571  foreach ( $wgInvalidRedirectTargets as $target ) {
4572  if ( $this->isSpecial( $target ) ) {
4573  return false;
4574  }
4575  }
4576  }
4577 
4578  return true;
4579  }
4580 
4586  public function getBacklinkCache() {
4587  return BacklinkCache::get( $this );
4588  }
4589 
4595  public function canUseNoindex() {
4596  global $wgExemptFromUserRobotsControl;
4597 
4598  $bannedNamespaces = is_null( $wgExemptFromUserRobotsControl )
4600  : $wgExemptFromUserRobotsControl;
4601 
4602  return !in_array( $this->mNamespace, $bannedNamespaces );
4603 
4604  }
4605 
4616  public function getCategorySortkey( $prefix = '' ) {
4617  $unprefixed = $this->getText();
4618 
4619  // Anything that uses this hook should only depend
4620  // on the Title object passed in, and should probably
4621  // tell the users to run updateCollations.php --force
4622  // in order to re-sort existing category relations.
4623  Hooks::run( 'GetDefaultSortkey', [ $this, &$unprefixed ] );
4624  if ( $prefix !== '' ) {
4625  # Separate with a line feed, so the unprefixed part is only used as
4626  # a tiebreaker when two pages have the exact same prefix.
4627  # In UCA, tab is the only character that can sort above LF
4628  # so we strip both of them from the original prefix.
4629  $prefix = strtr( $prefix, "\n\t", ' ' );
4630  return "$prefix\n$unprefixed";
4631  }
4632  return $unprefixed;
4633  }
4634 
4642  private function getDbPageLanguageCode() {
4643  global $wgPageLanguageUseDB;
4644 
4645  // check, if the page language could be saved in the database, and if so and
4646  // the value is not requested already, lookup the page language using LinkCache
4647  if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) {
4648  $linkCache = LinkCache::singleton();
4649  $linkCache->addLinkObj( $this );
4650  $this->mDbPageLanguage = $linkCache->getGoodLinkFieldObj( $this, 'lang' );
4651  }
4652 
4653  return $this->mDbPageLanguage;
4654  }
4655 
4664  public function getPageLanguage() {
4666  if ( $this->isSpecialPage() ) {
4667  // special pages are in the user language
4668  return $wgLang;
4669  }
4670 
4671  // Checking if DB language is set
4672  $dbPageLanguage = $this->getDbPageLanguageCode();
4673  if ( $dbPageLanguage ) {
4674  return wfGetLangObj( $dbPageLanguage );
4675  }
4676 
4677  if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) {
4678  // Note that this may depend on user settings, so the cache should
4679  // be only per-request.
4680  // NOTE: ContentHandler::getPageLanguage() may need to load the
4681  // content to determine the page language!
4682  // Checking $wgLanguageCode hasn't changed for the benefit of unit
4683  // tests.
4684  $contentHandler = ContentHandler::getForTitle( $this );
4685  $langObj = $contentHandler->getPageLanguage( $this );
4686  $this->mPageLanguage = [ $langObj->getCode(), $wgLanguageCode ];
4687  } else {
4688  $langObj = wfGetLangObj( $this->mPageLanguage[0] );
4689  }
4690 
4691  return $langObj;
4692  }
4693 
4702  public function getPageViewLanguage() {
4703  global $wgLang;
4704 
4705  if ( $this->isSpecialPage() ) {
4706  // If the user chooses a variant, the content is actually
4707  // in a language whose code is the variant code.
4708  $variant = $wgLang->getPreferredVariant();
4709  if ( $wgLang->getCode() !== $variant ) {
4710  return Language::factory( $variant );
4711  }
4712 
4713  return $wgLang;
4714  }
4715 
4716  // Checking if DB language is set
4717  $dbPageLanguage = $this->getDbPageLanguageCode();
4718  if ( $dbPageLanguage ) {
4719  $pageLang = wfGetLangObj( $dbPageLanguage );
4720  $variant = $pageLang->getPreferredVariant();
4721  if ( $pageLang->getCode() !== $variant ) {
4722  $pageLang = Language::factory( $variant );
4723  }
4724 
4725  return $pageLang;
4726  }
4727 
4728  // @note Can't be cached persistently, depends on user settings.
4729  // @note ContentHandler::getPageViewLanguage() may need to load the
4730  // content to determine the page language!
4731  $contentHandler = ContentHandler::getForTitle( $this );
4732  $pageLang = $contentHandler->getPageViewLanguage( $this );
4733  return $pageLang;
4734  }
4735 
4746  public function getEditNotices( $oldid = 0 ) {
4747  $notices = [];
4748 
4749  // Optional notice for the entire namespace
4750  $editnotice_ns = 'editnotice-' . $this->getNamespace();
4751  $msg = wfMessage( $editnotice_ns );
4752  if ( $msg->exists() ) {
4753  $html = $msg->parseAsBlock();
4754  // Edit notices may have complex logic, but output nothing (T91715)
4755  if ( trim( $html ) !== '' ) {
4756  $notices[$editnotice_ns] = Html::rawElement(
4757  'div',
4758  [ 'class' => [
4759  'mw-editnotice',
4760  'mw-editnotice-namespace',
4761  Sanitizer::escapeClass( "mw-$editnotice_ns" )
4762  ] ],
4763  $html
4764  );
4765  }
4766  }
4767 
4768  if ( MWNamespace::hasSubpages( $this->getNamespace() ) ) {
4769  // Optional notice for page itself and any parent page
4770  $parts = explode( '/', $this->getDBkey() );
4771  $editnotice_base = $editnotice_ns;
4772  while ( count( $parts ) > 0 ) {
4773  $editnotice_base .= '-' . array_shift( $parts );
4774  $msg = wfMessage( $editnotice_base );
4775  if ( $msg->exists() ) {
4776  $html = $msg->parseAsBlock();
4777  if ( trim( $html ) !== '' ) {
4778  $notices[$editnotice_base] = Html::rawElement(
4779  'div',
4780  [ 'class' => [
4781  'mw-editnotice',
4782  'mw-editnotice-base',
4783  Sanitizer::escapeClass( "mw-$editnotice_base" )
4784  ] ],
4785  $html
4786  );
4787  }
4788  }
4789  }
4790  } else {
4791  // Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
4792  $editnoticeText = $editnotice_ns . '-' . strtr( $this->getDBkey(), '/', '-' );
4793  $msg = wfMessage( $editnoticeText );
4794  if ( $msg->exists() ) {
4795  $html = $msg->parseAsBlock();
4796  if ( trim( $html ) !== '' ) {
4797  $notices[$editnoticeText] = Html::rawElement(
4798  'div',
4799  [ 'class' => [
4800  'mw-editnotice',
4801  'mw-editnotice-page',
4802  Sanitizer::escapeClass( "mw-$editnoticeText" )
4803  ] ],
4804  $html
4805  );
4806  }
4807  }
4808  }
4809 
4810  Hooks::run( 'TitleGetEditNotices', [ $this, $oldid, &$notices ] );
4811  return $notices;
4812  }
4813 
4817  public function __sleep() {
4818  return [
4819  'mNamespace',
4820  'mDbkeyform',
4821  'mFragment',
4822  'mInterwiki',
4823  'mLocalInterwiki',
4824  'mUserCaseDBKey',
4825  'mDefaultNamespace',
4826  ];
4827  }
4828 
4829  public function __wakeup() {
4830  $this->mArticleID = ( $this->mNamespace >= 0 ) ? -1 : 0;
4831  $this->mUrlform = wfUrlencode( $this->mDbkeyform );
4832  $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
4833  }
4834 
4835 }
getEarliestRevTime($flags=0)
Get the oldest revision timestamp of this page.
Definition: Title.php:4026
bool $mHasSubpages
Whether a page has any subpages.
Definition: Title.php:152
isAlwaysKnown()
Should links to this title be shown as potentially viewable (i.e.
Definition: Title.php:4278
static newFromRow($row)
Make a Title object from a DB row.
Definition: Title.php:450
static purgeExpiredRestrictions()
Purge expired restrictions from the page_restrictions table.
Definition: Title.php:3023
getLatestRevID($flags=0)
What is the page_latest field for this page?
Definition: Title.php:3260
setFragment($fragment)
Set the fragment for this title.
Definition: Title.php:1397
static newFromID($id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:402
static getTitleInvalidRegex()
Returns a simple regex that will match on characters and sequences invalid in titles.
Definition: Title.php:607
static whoIs($id)
Get the username corresponding to a given user ID.
Definition: User.php:708
static isMovable($index)
Can pages in the given namespace be moved?
Definition: MWNamespace.php:67
touchLinks()
Update page_touched timestamps and send CDN purge messages for pages linking to this title...
Definition: Title.php:4430
getFragment()
Get the Title fragment (i.e.
Definition: Title.php:1359
static getMainWANInstance()
Get the main WAN cache object.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1936
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
mixed $mTitleProtection
Cached value for getTitleProtection (create protection)
Definition: Title.php:133
exists($flags=0)
Check if page exists.
Definition: Title.php:4256
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
isMovable()
Would anybody with sufficient privileges be able to move this page? Some pages just aren't movable...
Definition: Title.php:1160
getInternalURL($query= '', $query2=false)
Get the URL form for an internal link.
Definition: Title.php:1829
getRootTitle()
Get the root page name title, i.e.
Definition: Title.php:1519
static getLocalNameFor($name, $subpage=false)
Get the local name for a specified canonical name.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:802
the array() calling protocol came about after MediaWiki 1.4rc1.
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1555
canUseNoindex()
Whether the magic words INDEX and NOINDEX function for this page.
Definition: Title.php:4595
isJsSubpage()
Is this a .js subpage of a user page?
Definition: Title.php:1286
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:239
wasLocalInterwiki()
Was this a local interwiki link?
Definition: Title.php:817
getSquidURLs()
Definition: Title.php:3586
$wgScript
The URL path to index.php.
isContentPage()
Is this Title in a namespace which contains content? In other words, is this a content page...
Definition: Title.php:1150
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
static getTitleInvalidRegex()
Returns a simple regex that will match on characters and sequences invalid in titles.
getUserCaseDBKey()
Get the DB key with the initial letter case as specified by the user.
Definition: Title.php:907
Handles the backend logic of moving a page from one title to another.
Definition: MovePage.php:30
isNamespaceProtected(User $user)
Determines if $user is unable to edit this page because it has been protected by $wgNamespaceProtecti...
Definition: Title.php:2678
isSpecial($name)
Returns true if this title resolves to the named special page.
Definition: Title.php:1061
static clearCaches()
Definition: Title.php:3314
getArticleID($flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:3171
hasSubpages()
Does this have subpages? (Warning, usually requires an extra DB query.)
Definition: Title.php:3064
const NS_MAIN
Definition: Defines.php:56
$success
static nameOf($id)
Get the prefixed DB key associated with an ID.
Definition: Title.php:571
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:880
getSubpageText()
Get the lowest-level subpage name, i.e.
Definition: Title.php:1574
getBaseText()
Get the base page name without a namespace, i.e.
Definition: Title.php:1534
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
static newMainPage()
Create a new Title for the Main Page.
Definition: Title.php:556
moveSubpages($nt, $auth=true, $reason= '', $createRedirect=true)
Move this page's subpages to be subpages of $nt.
Definition: Title.php:3711
getDefaultMessageText()
Get the default message text or false if the message doesn't exist.
Definition: Title.php:4366
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1936
getEditNotices($oldid=0)
Get a list of rendered edit notices for this page.
Definition: Title.php:4746
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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:82
getSubjectNsText()
Get the namespace text of the subject (rather than talk) page.
Definition: Title.php:1004
if(!$wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:664
static getCacheSetOptions(IDatabase $db1)
Merge the result of getSessionLagStatus() for several DBs using the most pessimistic values to estima...
Definition: Database.php:3025
__wakeup()
Definition: Title.php:4829
getUserPermissionsErrorsInternal($action, $user, $rigor= 'secure', $short=false)
Can $user perform $action on this page? This is an internal function, with multiple levels of checks ...
Definition: Title.php:2450
getTransWikiID()
Returns the DB name of the distant wiki which owns the object.
Definition: Title.php:840
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:209
bool $mForcedContentModel
If a content model was forced via setContentModel() this will be true to avoid having other code path...
Definition: Title.php:100
$wgActionPaths
Definition: img_auth.php:46
isCssJsSubpage()
Is this a .css or .js subpage of a user page?
Definition: Title.php:1250
static canTalk($index)
Can this namespace ever have a talk namespace?
$wgInternalServer
Internal server name as known to CDN, if different.
isWatchable()
Can this title be added to a user's watchlist?
Definition: Title.php:1042
checkUserBlock($action, $user, $errors, $rigor, $short)
Check that the user isn't blocked from editing.
Definition: Title.php:2298
if(!isset($args[0])) $lang
static isTalk($index)
Is the given namespace a talk namespace?
Definition: MWNamespace.php:97
hasSubjectNamespace($ns)
Returns true if the title has the same subject namespace as the namespace specified.
Definition: Title.php:1139
secureAndSplit()
Secure and split - main initialisation function for this object.
Definition: Title.php:3351
bool $mIsBigDeletion
Would deleting this page be a big deletion?
Definition: Title.php:165
inNamespaces()
Returns true if the title is inside one of the specified namespaces.
Definition: Title.php:1111
moveNoAuth(&$nt)
Move this page without authentication.
Definition: Title.php:3607
isTalkPage()
Is this a talk page of some sort?
Definition: Title.php:1296
Handles purging appropriate CDN URLs given a title (or titles)
string $mUrlform
URL-encoded form of the main part.
Definition: Title.php:64
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title...
getDbPageLanguageCode()
Returns the page language code saved in the database, if $wgPageLanguageUseDB is set to true in Local...
Definition: Title.php:4642
null for the local wiki Added in
Definition: hooks.txt:1555
isRedirect($flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
Definition: Title.php:3197
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:36
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition: hooks.txt:177
isBigDeletion()
Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit.
Definition: Title.php:4046
set($key, $value, $exptime=0, $flags=0)
const NS_SPECIAL
Definition: Defines.php:45
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context $revId
Definition: hooks.txt:1046
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:3510
prefix($name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object. ...
Definition: Title.php:1425
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:1332
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
static escapeFragmentForURL($fragment)
Escape a text fragment, say from a link, for a URL.
Definition: Title.php:751
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2703
static getInterwikiLookup()
B/C kludge: provide an InterwikiLookup for use by Title.
Definition: Title.php:188
isValidMoveTarget($nt)
Checks if $this can be moved to a given Title.
Definition: Title.php:3829
static escapeClass($class)
Given a value, escape it so that it can be used as a CSS class and return it.
Definition: Sanitizer.php:1247
static escapeRegexReplacement($string)
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter...
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1455
static exists($index)
Returns whether the specified namespace exists.
wfUrlencode($s)
We want some things to be included as literal characters in our title URLs for prettiness, which urlencode encodes by default.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:262
getBaseTitle()
Get the base page name title, i.e.
Definition: Title.php:1559
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
wfExpandUrl($url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
getParentCategories()
Get categories to which this Title belongs and return an array of categories' names.
Definition: Title.php:3877
getBacklinkCache()
Get a backlink cache object.
Definition: Title.php:4586
$wgArticlePath
Definition: img_auth.php:45
timestamp($ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
static newFromLinkTarget(LinkTarget $linkTarget)
Create a new Title from a LinkTarget.
Definition: Title.php:236
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:128
wfLocalFile($title)
Get an object referring to a locally registered file.
The TitleArray class only exists to provide the newFromResult method at pre- sent.
Definition: TitleArray.php:31
checkQuickPermissions($action, $user, $errors, $rigor, $short)
Permissions checks that fail most often, and which are easiest to test.
Definition: Title.php:1952
getSkinFromCssJsSubpage()
Trim down a .css or .js subpage title to get the corresponding skin name.
Definition: Title.php:1261
const DB_MASTER
Definition: defines.php:23
static getFilteredRestrictionTypes($exists=true)
Get a filtered list of all restriction types supported by this wiki.
Definition: Title.php:2511
getTalkPage()
Get a Title object associated with the talk page of this article.
Definition: Title.php:1305
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:1007
getNamespace()
Get the namespace index.
array $mCascadeSources
Where are the cascading restrictions coming from on this page?
Definition: Title.php:124
getNotificationTimestamp($user=null)
Get the timestamp when this page was updated since the user last saw it.
Definition: Title.php:4457
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
fixSpecialName()
If the Title refers to a special page alias which is not the local default, resolve the alias...
Definition: Title.php:1077
static isEveryoneAllowed($right)
Check if all users may be assumed to have the given permission.
Definition: User.php:4645
getSubpages($limit=-1)
Get all subpages of this page.
Definition: Title.php:3092
userCan($action, $user=null, $rigor= 'secure')
Can $user perform $action on this page?
Definition: Title.php:1897
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1934
getFragment()
Get the link fragment (i.e.
Deferrable Update for closure/callback updates that should use auto-commit mode.
static isCapitalized($index)
Is the namespace first-letter capitalized?
static get(Title $title)
Create a new BacklinkCache or reuse any existing one.
$wgLanguageCode
Site language code.
bool $mCascadeRestriction
Cascade restrictions on this page to included templates and images?
Definition: Title.php:112
inNamespace($ns)
Returns true if the title is inside the specified namespace.
Definition: Title.php:1100
flushRestrictions()
Flush the protection cache in this object and force reload from the database.
Definition: Title.php:3013
getContentModel($flags=0)
Get the page's content model id, see the CONTENT_MODEL_XXX constants.
Definition: Title.php:931
getLength($flags=0)
What is the length of this page? Uses link cache, adding it if necessary.
Definition: Title.php:3232
static HashBagOStuff $titleCache
Definition: Title.php:38
string $mDbkeyform
Main part with underscores.
Definition: Title.php:67
getNsText()
Get the namespace text.
Definition: Title.php:979
delete($table, $conds, $fname=__METHOD__)
DELETE query wrapper.
isValidMoveOperation(&$nt, $auth=true, $reason= '')
Check whether a given move operation would be valid.
Definition: Title.php:3622
if($wgScript===false) if($wgLoadScript===false) if($wgArticlePath===false) if(!empty($wgActionPaths)&&!isset($wgActionPaths['view'])) if($wgResourceBasePath===null) if($wgStylePath===false) if($wgLocalStylePath===false) if($wgExtensionAssetsPath===false) if($wgLogo===false) if($wgUploadPath===false) if($wgUploadDirectory===false) if($wgReadOnlyFile===false) if($wgFileCacheDirectory===false) if($wgDeletedDirectory===false) if($wgGitInfoCacheDirectory===false &&$wgCacheDirectory!==false) if($wgEnableParserCache===false) if($wgRightsIcon) if(isset($wgFooterIcons['copyright']['copyright'])&&$wgFooterIcons['copyright']['copyright']===[]) if(isset($wgFooterIcons['poweredby'])&&isset($wgFooterIcons['poweredby']['mediawiki'])&&$wgFooterIcons['poweredby']['mediawiki']['src']===null) $wgNamespaceProtection[NS_MEDIAWIKI]
Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a sysadmin to set $wgName...
Definition: Setup.php:155
createFragmentTarget($fragment)
Creates a new Title for a different fragment of the same page.
Definition: Title.php:1408
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an article
Definition: design.txt:25
getNextRevisionID($revId, $flags=0)
Get the revision ID of the next revision.
Definition: Title.php:3980
__sleep()
Definition: Title.php:4817
string bool $mOldRestrictions
Text form (spaces not underscores) of the main part.
Definition: Title.php:109
__construct()
Definition: Title.php:195
wfReadOnly()
Check whether the wiki is in read-only mode.
isExternal()
Is this Title interwiki?
Definition: Title.php:797
static fixUrlQueryArgs($query, $query2=false)
Helper to fix up the get{Canonical,Full,Link,Local,Internal}URL args get{Canonical,Full,Link,Local,Internal}URL methods accepted an optional second argument named variant.
Definition: Title.php:1634
deleteTitleProtection()
Remove any title protection due to page existing.
Definition: Title.php:2600
static getMain()
Static methods.
int $mNamespace
Namespace index, i.e.
Definition: Title.php:73
static groupHasPermission($group, $role)
Check, if the given group has the given permission.
Definition: User.php:4625
static singleton()
Get an instance of this class.
Definition: LinkCache.php:64
wfMergeErrorArrays()
Merge arrays in the style of getUserPermissionsErrors, with duplicate removal e.g.
static getCanonicalName($index)
Returns the canonical (English) name for a given index.
hasSourceText()
Does this page have source text?
Definition: Title.php:4340
static newFromIDs($ids)
Make an array of titles from an array of IDs.
Definition: Title.php:424
wfAppendQuery($url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
static getTitleCache()
Definition: Title.php:362
static getTitleFormatter()
B/C kludge: provide a TitleParser for use by Title.
Definition: Title.php:176
isAllowed($action= '')
Internal mechanics of testing a permission.
Definition: User.php:3443
Class to invalidate the HTML cache of all the pages linking to a given title.
getDBkey()
Get the main part with underscores.
Definition: Title.php:898
__toString()
Return a string representation of this title.
Definition: Title.php:1469
getPrefixedURL()
Get a URL-encoded title (not an actual URL) including interwiki.
Definition: Title.php:1615
hasFragment()
Check if a Title fragment is set.
Definition: Title.php:1369
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"&lt
hasContentModel($id)
Convenience method for checking a title's content model name.
Definition: Title.php:954
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1046
selectFieldValues($table, $var, $cond= '', $fname=__METHOD__, $options=[])
A SELECT wrapper which returns a list of single field values from result rows.
areRestrictionsCascading()
Returns cascading restrictions for the current article.
Definition: Title.php:2868
isConversionTable()
Is this a conversion table for the LanguageConverter?
Definition: Title.php:1201
const NS_MEDIA
Definition: Defines.php:44
static newFromDBkey($key)
Create a new Title from a prefixed DB key.
Definition: Title.php:206
getRootText()
Get the root page name text without a namespace, i.e.
Definition: Title.php:1499
getTouched($db=null)
Get the last touched timestamp.
Definition: Title.php:4443
getLocalURL($query= '', $query2=false)
Get a URL with no fragment or server name (relative URL) from a Title object.
Definition: Title.php:1713
$res
Definition: database.txt:21
checkCSSandJSPermissions($action, $user, $errors, $rigor, $short)
Check CSS/JS sub-page permissions.
Definition: Title.php:2115
bool string $mContentModel
ID of the page's content model, i.e.
Definition: Title.php:94
canExist()
Is this in a namespace that allows actual pages?
Definition: Title.php:1033
getSubpage($text)
Get the title for a subpage of the current page.
Definition: Title.php:1595
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define.
Definition: Title.php:51
null $mRedirect
Is the article at this title a redirect?
Definition: Title.php:146
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
isValidRedirectTarget()
Check if this Title is a valid redirect target.
Definition: Title.php:4562
isCascadeProtected()
Cascading protection: Return true if cascading restrictions apply to this page, false if not...
Definition: Title.php:2696
invalidateCache($purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:4391
getCdnUrls()
Get a list of URLs to purge from the CDN cache when this page changes.
Definition: Title.php:3558
Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
getUserPermissionsErrors($action, $user, $rigor= 'secure', $ignoreErrors=[])
Can $user perform $action on this page?
Definition: Title.php:1921
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:3457
$cache
Definition: mcc.php:33
getDefaultNamespace()
Get the default namespace index, for when there is no namespace.
Definition: Title.php:1348
const NS_CATEGORY
Definition: Defines.php:70
moveTo(&$nt, $auth=true, $reason= '', $createRedirect=true)
Move a title to a new location.
Definition: Title.php:3677
getRedirectsHere($ns=null)
Get all extant redirects to this Title.
Definition: Title.php:4526
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition: Revision.php:442
checkSpecialsAndNSPermissions($action, $user, $errors, $rigor, $short)
Check permissions on special pages & namespaces.
Definition: Title.php:2086
wfDeprecated($function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
getCanonicalURL($query= '', $query2=false)
Get the URL for a canonical link, for use in things like IRC and e-mail notifications.
Definition: Title.php:1849
isSubpageOf(Title $title)
Check if this title is a subpage of another title.
Definition: Title.php:4239
array $mNotificationTimestamp
Associative array of user ID -> timestamp/false.
Definition: Title.php:149
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:535
static getContentNamespaces()
Get a list of all namespace indices which are considered to contain content.
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
Definition: Title.php:1479
static subjectEquals($ns1, $ns2)
Returns whether the specified namespaces share the same subject.
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:159
validateFileMoveOperation($nt)
Check if the requested move target is a valid file move target.
Definition: Title.php:3649
isCssSubpage()
Is this a .css subpage of a user page?
Definition: Title.php:1276
isMainPage()
Is this the mainpage?
Definition: Title.php:1181
static decodeCharReferencesAndNormalize($text)
Decode any character references, numeric or named entities, in the next and normalize the resulting s...
Definition: Sanitizer.php:1517
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
getAuthorsBetween($old, $new, $limit, $options=[])
Get the authors between the given revisions or revision IDs.
Definition: Title.php:4141
static hasSubpages($index)
Does the namespace allow subpages?
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:921
const PROTO_RELATIVE
Definition: Defines.php:225
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
string $mInterwiki
Interwiki prefix.
Definition: Title.php:76
equals(Title $title)
Compare with another title.
Definition: Title.php:4226
isKnown()
Does this title refer to a page that can (or might) be meaningfully viewed? In particular, this function may be used to determine if links to the title should be rendered as "bluelinks" (as opposed to "redlinks" to non-existent pages).
Definition: Title.php:4331
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:3441
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
const NS_FILE
Definition: Defines.php:62
static newFromResult($res)
Definition: TitleArray.php:38
areRestrictionsLoaded()
Accessor for mRestrictionsLoaded.
Definition: Title.php:2813
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1721
checkCascadingSourcesRestrictions($action, $user, $errors, $rigor, $short)
Check restrictions on cascading pages.
Definition: Title.php:2185
static equals($ns1, $ns2)
Returns whether the specified namespaces are the same namespace.
isSubpage()
Is this a subpage?
Definition: Title.php:1190
getInterwiki()
Get the interwiki prefix.
Definition: Title.php:808
const RAW
Definition: Revision.php:94
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
loadFromRow($row)
Load Title object fields from a DB row.
Definition: Title.php:462
areCascadeProtectionSourcesLoaded($getPages=true)
Determines whether cascading protection sources have already been loaded from the database...
Definition: Title.php:2710
namespace and then decline to actually register it & $namespaces
Definition: hooks.txt:953
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
getBrokenLinksFrom()
Get an array of Title objects referring to non-existent articles linked from this page...
Definition: Title.php:3522
const NS_MEDIAWIKI
Definition: Defines.php:64
const PROTO_HTTP
Definition: Defines.php:223
getNamespaceKey($prepend= 'nstab-')
Generate strings used for xml 'id' names in monobook tabs.
Definition: Title.php:4495
countRevisionsBetween($old, $new, $max=null)
Get the number of revisions between the given revision.
Definition: Title.php:4098
array $mRestrictionsExpiry
When do the restrictions on this page expire?
Definition: Title.php:118
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
static newFromTitleValue(TitleValue $titleValue)
Create a new Title from a TitleValue.
Definition: Title.php:225
getRestrictions($action)
Accessor/initialisation for mRestrictions.
Definition: Title.php:2826
CONTENT_MODEL_JAVASCRIPT
Uploads have to be specially set up to be secure.
getSubjectPage()
Get a title object associated with the subject page of this talk page.
Definition: Title.php:1315
int $mLength
The page length, 0 for special pages.
Definition: Title.php:143
getFirstRevision($flags=0)
Get the first revision of the page.
Definition: Title.php:4004
static escapeId($id, $options=[])
Given a value, escape it so that it can be used in an id attribute and return it. ...
Definition: Sanitizer.php:1170
static newFromTextThrow($text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid, rather than returning null.
Definition: Title.php:292
isSpecialPage()
Returns true if this is a special page.
Definition: Title.php:1051
quickUserCan($action, $user=null)
Can $user perform $action on this page? This skips potentially expensive cascading permission checks ...
Definition: Title.php:1884
getEditURL()
Get the edit URL for this Title.
Definition: Title.php:1861
$wgLegalTitleChars
Allowed title characters – regex character class Don't change this unless you know what you're doing...
loadRestrictions($oldFashionedRestrictions=null)
Load restrictions from the page_restrictions table.
Definition: Title.php:2958
static getTalk($index)
Get the talk namespace index for a given namespace.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static convertByteClassToUnicodeClass($byteClass)
Utility method for converting a character sequence from bytes to Unicode.
Definition: Title.php:621
isSingleRevRedirect()
Checks if this page is just a one-rev redirect.
Definition: Title.php:3778
const PROTO_CANONICAL
Definition: Defines.php:227
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred list to be run later by execute()
getPageViewLanguage()
Get the language in which the content of this page is written when viewed by user.
Definition: Title.php:4702
getSubpageUrlForm()
Get a URL-encoded form of the subpage text.
Definition: Title.php:1604
$mCascadingRestrictions
Caching the results of getCascadeProtectionSources.
Definition: Title.php:115
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined...
Definition: Setup.php:36
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
static resolveAlias($alias)
Given a special page name with a possible subpage, return an array where the first element is the spe...
getRestrictionTypes()
Returns restriction types for the current Title.
Definition: Title.php:2529
static exists($name)
Check if a given name exist as a special page or as a special page alias.
static isContent($index)
Does this namespace contain content, for the purposes of calculating statistics, etc?
TitleValue $mTitleValue
A corresponding TitleValue object.
Definition: Title.php:162
bool $mPageLanguage
The (string) language code of the page's language and content code.
Definition: Title.php:155
isTrans()
Determine whether the object refers to a page within this project and is transcludable.
Definition: Title.php:827
string $mFragment
Title fragment (i.e.
Definition: Title.php:82
int $mArticleID
Article ID, fetched from the link cache on demand.
Definition: Title.php:85
int $mDefaultNamespace
Namespace index when there is no namespace.
Definition: Title.php:140
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition: hooks.txt:1046
getCategorySortkey($prefix= '')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:4616
wfArrayToCgi($array1, $array2=null, $prefix= '')
This function takes one or two arrays as input, and returns a CGI-style string, e.g.
static makeName($ns, $title, $fragment= '', $interwiki= '', $canonicalNamespace=false)
Make a prefixed DB key from a DB key and a namespace index.
Definition: Title.php:725
static newFromURL($url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:339
getPageLanguage()
Get the language in which the content of this page is written in wikitext.
Definition: Title.php:4664
const CACHE_MAX
Title::newFromText maintains a cache to avoid expensive re-normalization of commonly used titles...
Definition: Title.php:45
checkReadPermissions($action, $user, $errors, $rigor, $short)
Check that the user is allowed to read this page.
Definition: Title.php:2340
isCssOrJsPage()
Could this page contain custom CSS or JavaScript for the global UI.
Definition: Title.php:1231
getCascadeProtectionSources($getPages=true)
Cascading protection: Get the source of any cascading restrictions on this page.
Definition: Title.php:2727
getFragmentForURL()
Get the fragment in URL form, including the "#" character if there is one.
Definition: Title.php:1377
get($key, $flags=0, $oldFlags=null)
Get an item with the given key.
Definition: BagOStuff.php:179
pageCond()
Get an associative array for selecting this title from the "page" table.
Definition: Title.php:3939
static invalidateModuleCache(Title $title, Revision $old=null, Revision $new=null, $wikiId)
Clear the preloadTitleInfo() cache for all wiki modules on this wiki on page change if it was a JS or...
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
Definition: hooks.txt:1046
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition: design.txt:56
getInterwiki()
The interwiki component of this LinkTarget.
const CONTENT_MODEL_CSS
Definition: Defines.php:241
string $mPrefixedText
Text form including namespace/interwiki, initialised on demand.
Definition: Title.php:130
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:3145
isNewPage()
Check if this is a new page.
Definition: Title.php:4036
getText()
Returns the link in text form, without namespace prefix or fragment.
missingPermissionError($action, $short)
Get a description array when the user doesn't have the right to perform $action (i.e.
Definition: Title.php:2415
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1046
isProtected($action= '')
Does the title correspond to a protected article?
Definition: Title.php:2646
static compare(LinkTarget $a, LinkTarget $b)
Callback for usort() to do title sorts by (namespace, title)
Definition: Title.php:767
canTalk()
Could this title have a corresponding talk page?
Definition: Title.php:1024
$count
checkActionPermissions($action, $user, $errors, $rigor, $short)
Check action permissions not already checked in checkQuickPermissions.
Definition: Title.php:2232
bool $mRestrictionsLoaded
Boolean for initialisation on demand.
Definition: Title.php:127
static legalChars()
Get a regex character class describing the legal characters in a link.
Definition: Title.php:593
$wgServer
URL of the server.
isDeleted()
Is there a version of this page in the deletion archive?
Definition: Title.php:3120
isLocal()
Determine whether the object refers to a page within this project (either this wiki or a wiki with a ...
Definition: Title.php:782
loadRestrictionsFromRows($rows, $oldFashionedRestrictions=null)
Compiles list of active page restrictions from both page table (pre 1.10) and page_restrictions table...
Definition: Title.php:2885
array $mRestrictions
Array of groups allowed to edit this article.
Definition: Title.php:106
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:1806
const DB_REPLICA
Definition: defines.php:22
getTitleProtection()
Is this title subject to title protection? Title protection is the one applied against creation of su...
Definition: Title.php:2556
bool $mLocalInterwiki
Was this Title created from a string with a local interwiki prefix?
Definition: Title.php:79
addQuotes($s)
Adds quotes and backslashes.
int $mEstimateRevisions
Estimated number of revisions; null of not loaded.
Definition: Title.php:103
countAuthorsBetween($old, $new, $limit, $options=[])
Get the number of authors between the given revisions or revision IDs.
Definition: Title.php:4215
getTalkNsText()
Get the namespace text of the talk page.
Definition: Title.php:1014
checkPageRestrictions($action, $user, $errors, $rigor, $short)
Check against page_restrictions table requirements on this page.
Definition: Title.php:2151
static getSelectFields()
Returns a list of fields that are to be selected for initializing Title objects or LinkCache entries...
Definition: Title.php:376
checkPermissionHooks($action, $user, $errors, $rigor, $short)
Check various permission hooks.
Definition: Title.php:2053
static factory($code)
Get a cached or new language object for a given language code.
Definition: Language.php:181
getParentCategoryTree($children=[])
Get a tree of parent categories.
Definition: Title.php:3912
string $mTextform
Text form (spaces not underscores) of the main part.
Definition: Title.php:61
static selectFields()
Return the list of revision fields that should be selected to create a new page.
Definition: WikiPage.php:281
getAllRestrictions()
Accessor/initialisation for mRestrictions.
Definition: Title.php:2842
isSemiProtected($action= 'edit')
Is this page "semi-protected" - the only protection levels are listed in $wgSemiprotectedRestrictionL...
Definition: Title.php:2618
static getSubject($index)
Get the subject namespace index for a given namespace Special namespaces (NS_MEDIA, NS_SPECIAL) are always the subject.
bool int $mLatestID
ID of most recent revision.
Definition: Title.php:88
resultToError($errors, $result)
Add the resulting error code to the errors array.
Definition: Title.php:2022
getRestrictionExpiry($action)
Get the expiry time for the restriction against a given action.
Definition: Title.php:2856
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
Definition: hooks.txt:242
wfFindFile($title, $options=[])
Find a file.
getPreviousRevisionID($revId, $flags=0)
Get the revision ID of the previous revision.
Definition: Title.php:3955
$wgVariantArticlePath
Like $wgArticlePath, but on multi-variant wikis, this provides a path format that describes which par...
within a display generated by the Derivative if and wherever such third party notices normally appear The contents of the NOTICE file are for informational purposes only and do not modify the License You may add Your own attribution notices within Derivative Works that You alongside or as an addendum to the NOTICE text from the provided that such additional attribution notices cannot be construed as modifying the License You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for or distribution of Your or for any such Derivative Works as a provided Your and distribution of the Work otherwise complies with the conditions stated in this License Submission of Contributions Unless You explicitly state any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this without any additional terms or conditions Notwithstanding the nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions Trademarks This License does not grant permission to use the trade names
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2491
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:511
static isWatchable($index)
Can pages in a namespace be watched?
static capitalize($text, $ns=NS_MAIN)
Capitalize a text string for a title if it belongs to a namespace that capitalizes.
Definition: Title.php:3329
isWikitextPage()
Does that page contain wikitext, or it is JS, CSS or whatever?
Definition: Title.php:1213
static singleton()
Get the signleton instance of this class.
purgeSquid()
Purge all applicable CDN URLs.
Definition: Title.php:3593
static getGroupsWithPermission($role)
Get all the groups who have a given permission.
Definition: User.php:4602
update($table, $values, $conds, $fname=__METHOD__, $options=[])
UPDATE wrapper.
resetArticleID($newid)
This clears some fields in this object, and clears any associated keys in the "bad links" section of ...
Definition: Title.php:3292
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:34
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2491
getTitleValue()
Get a TitleValue object representing this Title.
Definition: Title.php:857
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:3399
bool $mHasCascadingRestrictions
Are cascading restrictions in effect on this page?
Definition: Title.php:121
getPartialURL()
Get the URL-encoded form of the main part.
Definition: Title.php:889
wfGetLangObj($langcode=false)
Return a Language object from $langcode.
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1443
getFullURL($query= '', $query2=false, $proto=PROTO_RELATIVE)
Get a real URL referring to this title, with interwiki link and fragment.
Definition: Title.php:1672
estimateRevisionCount()
Get the approximate revision count of this page.
Definition: Title.php:4075
setContentModel($model)
Set a proposed content model for the page for permissions checking.
Definition: Title.php:969
$wgUser
Definition: Setup.php:806
$matches
string $mUserCaseDBKey
Database key with the initial letter in the case specified by the user.
Definition: Title.php:70
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300