MediaWiki  master
ParserOptions.php
Go to the documentation of this file.
1 <?php
25 use Wikimedia\ScopedCallback;
26 
43 
50 
56  private static $defaults = null;
57 
62  private static $lazyOptions = [
63  'dateformat' => [ __CLASS__, 'initDateFormat' ],
64  'speculativeRevId' => [ __CLASS__, 'initSpeculativeRevId' ],
65  'speculativePageId' => [ __CLASS__, 'initSpeculativePageId' ],
66  ];
67 
72  private static $inCacheKey = [
73  'dateformat' => true,
74  'numberheadings' => true,
75  'thumbsize' => true,
76  'stubthreshold' => true,
77  'printable' => true,
78  'userlang' => true,
79  ];
80 
85  private $options;
86 
92  private $mTimestamp;
93 
99  private $mUser;
100 
106  private $onAccessCallback = null;
107 
114  private $redirectTarget = null;
115 
119  private $mExtraKey = '';
120 
127  public function getOption( $name ) {
128  if ( !array_key_exists( $name, $this->options ) ) {
129  throw new InvalidArgumentException( "Unknown parser option $name" );
130  }
131 
132  $this->lazyLoadOption( $name );
133  if ( !empty( self::$inCacheKey[$name] ) ) {
134  $this->optionUsed( $name );
135  }
136  return $this->options[$name];
137  }
138 
142  private function lazyLoadOption( $name ) {
143  if ( isset( self::$lazyOptions[$name] ) && $this->options[$name] === null ) {
144  $this->options[$name] = call_user_func( self::$lazyOptions[$name], $this, $name );
145  }
146  }
147 
156  public function setOption( $name, $value ) {
157  if ( !array_key_exists( $name, $this->options ) ) {
158  throw new InvalidArgumentException( "Unknown parser option $name" );
159  }
160  $old = $this->options[$name];
161  $this->options[$name] = $value;
162  return $old;
163  }
164 
173  protected function setOptionLegacy( $name, $value ) {
174  if ( !array_key_exists( $name, $this->options ) ) {
175  throw new InvalidArgumentException( "Unknown parser option $name" );
176  }
177  return wfSetVar( $this->options[$name], $value );
178  }
179 
188  public function getInterwikiMagic() {
189  return $this->getOption( 'interwikiMagic' );
190  }
191 
197  public function setInterwikiMagic( $x ) {
198  return $this->setOptionLegacy( 'interwikiMagic', $x );
199  }
200 
205  public function getAllowExternalImages() {
206  return $this->getOption( 'allowExternalImages' );
207  }
208 
214  public function setAllowExternalImages( $x ) {
215  return $this->setOptionLegacy( 'allowExternalImages', $x );
216  }
217 
225  public function getAllowExternalImagesFrom() {
226  return $this->getOption( 'allowExternalImagesFrom' );
227  }
228 
237  public function setAllowExternalImagesFrom( $x ) {
238  return $this->setOptionLegacy( 'allowExternalImagesFrom', $x );
239  }
240 
245  public function getEnableImageWhitelist() {
246  return $this->getOption( 'enableImageWhitelist' );
247  }
248 
254  public function setEnableImageWhitelist( $x ) {
255  return $this->setOptionLegacy( 'enableImageWhitelist', $x );
256  }
257 
262  public function getNumberHeadings() {
263  return $this->getOption( 'numberheadings' );
264  }
265 
271  public function setNumberHeadings( $x ) {
272  return $this->setOptionLegacy( 'numberheadings', $x );
273  }
274 
279  public function getAllowSpecialInclusion() {
280  return $this->getOption( 'allowSpecialInclusion' );
281  }
282 
288  public function setAllowSpecialInclusion( $x ) {
289  return $this->setOptionLegacy( 'allowSpecialInclusion', $x );
290  }
291 
296  public function getTidy() {
297  return $this->getOption( 'tidy' );
298  }
299 
305  public function setTidy( $x ) {
306  return $this->setOptionLegacy( 'tidy', $x );
307  }
308 
313  public function getInterfaceMessage() {
314  return $this->getOption( 'interfaceMessage' );
315  }
316 
322  public function setInterfaceMessage( $x ) {
323  return $this->setOptionLegacy( 'interfaceMessage', $x );
324  }
325 
330  public function getTargetLanguage() {
331  return $this->getOption( 'targetLanguage' );
332  }
333 
339  public function setTargetLanguage( $x ) {
340  return $this->setOption( 'targetLanguage', $x );
341  }
342 
347  public function getMaxIncludeSize() {
348  return $this->getOption( 'maxIncludeSize' );
349  }
350 
356  public function setMaxIncludeSize( $x ) {
357  return $this->setOptionLegacy( 'maxIncludeSize', $x );
358  }
359 
364  public function getMaxPPNodeCount() {
365  return $this->getOption( 'maxPPNodeCount' );
366  }
367 
373  public function setMaxPPNodeCount( $x ) {
374  return $this->setOptionLegacy( 'maxPPNodeCount', $x );
375  }
376 
381  public function getMaxGeneratedPPNodeCount() {
382  return $this->getOption( 'maxGeneratedPPNodeCount' );
383  }
384 
390  public function setMaxGeneratedPPNodeCount( $x ) {
391  return $this->setOptionLegacy( 'maxGeneratedPPNodeCount', $x );
392  }
393 
398  public function getMaxPPExpandDepth() {
399  return $this->getOption( 'maxPPExpandDepth' );
400  }
401 
406  public function getMaxTemplateDepth() {
407  return $this->getOption( 'maxTemplateDepth' );
408  }
409 
415  public function setMaxTemplateDepth( $x ) {
416  return $this->setOptionLegacy( 'maxTemplateDepth', $x );
417  }
418 
425  return $this->getOption( 'expensiveParserFunctionLimit' );
426  }
427 
434  public function setExpensiveParserFunctionLimit( $x ) {
435  return $this->setOptionLegacy( 'expensiveParserFunctionLimit', $x );
436  }
437 
443  public function getRemoveComments() {
444  return $this->getOption( 'removeComments' );
445  }
446 
453  public function setRemoveComments( $x ) {
454  return $this->setOptionLegacy( 'removeComments', $x );
455  }
456 
461  public function getEnableLimitReport() {
462  return $this->getOption( 'enableLimitReport' );
463  }
464 
470  public function enableLimitReport( $x = true ) {
471  return $this->setOptionLegacy( 'enableLimitReport', $x );
472  }
473 
479  public function getCleanSignatures() {
480  return $this->getOption( 'cleanSignatures' );
481  }
482 
489  public function setCleanSignatures( $x ) {
490  return $this->setOptionLegacy( 'cleanSignatures', $x );
491  }
492 
497  public function getExternalLinkTarget() {
498  return $this->getOption( 'externalLinkTarget' );
499  }
500 
506  public function setExternalLinkTarget( $x ) {
507  return $this->setOptionLegacy( 'externalLinkTarget', $x );
508  }
509 
514  public function getDisableContentConversion() {
515  return $this->getOption( 'disableContentConversion' );
516  }
517 
523  public function disableContentConversion( $x = true ) {
524  return $this->setOptionLegacy( 'disableContentConversion', $x );
525  }
526 
531  public function getDisableTitleConversion() {
532  return $this->getOption( 'disableTitleConversion' );
533  }
534 
540  public function disableTitleConversion( $x = true ) {
541  return $this->setOptionLegacy( 'disableTitleConversion', $x );
542  }
543 
548  public function getThumbSize() {
549  return $this->getOption( 'thumbsize' );
550  }
551 
557  public function setThumbSize( $x ) {
558  return $this->setOptionLegacy( 'thumbsize', $x );
559  }
560 
565  public function getStubThreshold() {
566  return $this->getOption( 'stubthreshold' );
567  }
568 
574  public function setStubThreshold( $x ) {
575  return $this->setOptionLegacy( 'stubthreshold', $x );
576  }
577 
582  public function getIsPreview() {
583  return $this->getOption( 'isPreview' );
584  }
585 
591  public function setIsPreview( $x ) {
592  return $this->setOptionLegacy( 'isPreview', $x );
593  }
594 
599  public function getIsSectionPreview() {
600  return $this->getOption( 'isSectionPreview' );
601  }
602 
608  public function setIsSectionPreview( $x ) {
609  return $this->setOptionLegacy( 'isSectionPreview', $x );
610  }
611 
616  public function getIsPrintable() {
617  return $this->getOption( 'printable' );
618  }
619 
625  public function setIsPrintable( $x ) {
626  return $this->setOptionLegacy( 'printable', $x );
627  }
628 
633  public function getPreSaveTransform() {
634  return $this->getOption( 'preSaveTransform' );
635  }
636 
642  public function setPreSaveTransform( $x ) {
643  return $this->setOptionLegacy( 'preSaveTransform', $x );
644  }
645 
650  public function getDateFormat() {
651  return $this->getOption( 'dateformat' );
652  }
653 
659  private static function initDateFormat( ParserOptions $popt ) {
660  return $popt->mUser->getDatePreference();
661  }
662 
668  public function setDateFormat( $x ) {
669  return $this->setOptionLegacy( 'dateformat', $x );
670  }
671 
689  public function getUserLangObj() {
690  return $this->getOption( 'userlang' );
691  }
692 
705  public function getUserLang() {
706  return $this->getUserLangObj()->getCode();
707  }
708 
714  public function setUserLang( $x ) {
715  if ( is_string( $x ) ) {
716  $x = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $x );
717  }
718 
719  return $this->setOptionLegacy( 'userlang', $x );
720  }
721 
727  public function getMagicISBNLinks() {
728  return $this->getOption( 'magicISBNLinks' );
729  }
730 
736  public function getMagicPMIDLinks() {
737  return $this->getOption( 'magicPMIDLinks' );
738  }
739 
745  public function getMagicRFCLinks() {
746  return $this->getOption( 'magicRFCLinks' );
747  }
748 
763  public function getAllowUnsafeRawHtml() {
764  return $this->getOption( 'allowUnsafeRawHtml' );
765  }
766 
775  public function setAllowUnsafeRawHtml( $x ) {
776  return $this->setOptionLegacy( 'allowUnsafeRawHtml', $x );
777  }
778 
784  public function getWrapOutputClass() {
785  return $this->getOption( 'wrapclass' );
786  }
787 
795  public function setWrapOutputClass( $className ) {
796  if ( $className === true ) { // DWIM, they probably want the default class name
797  $className = 'mw-parser-output';
798  }
799  if ( $className === false ) {
800  wfDeprecated( __METHOD__ . '( false )', '1.31' );
801  }
802  return $this->setOption( 'wrapclass', $className );
803  }
804 
810  public function getCurrentRevisionCallback() {
811  return $this->getOption( 'currentRevisionCallback' );
812  }
813 
820  public function setCurrentRevisionCallback( $x ) {
821  return $this->setOptionLegacy( 'currentRevisionCallback', $x );
822  }
823 
828  public function getTemplateCallback() {
829  return $this->getOption( 'templateCallback' );
830  }
831 
837  public function setTemplateCallback( $x ) {
838  return $this->setOptionLegacy( 'templateCallback', $x );
839  }
840 
851  public function getSpeculativeRevId() {
852  return $this->getOption( 'speculativeRevId' );
853  }
854 
865  public function getSpeculativePageId() {
866  return $this->getOption( 'speculativePageId' );
867  }
868 
875  private static function initSpeculativeRevId( ParserOptions $popt ) {
876  $cb = $popt->getOption( 'speculativeRevIdCallback' );
877  $id = $cb ? $cb() : null;
878 
879  // returning null would result in this being re-called every access
880  return $id ?? false;
881  }
882 
889  private static function initSpeculativePageId( ParserOptions $popt ) {
890  $cb = $popt->getOption( 'speculativePageIdCallback' );
891  $id = $cb ? $cb() : null;
892 
893  // returning null would result in this being re-called every access
894  return $id ?? false;
895  }
896 
903  public function setSpeculativeRevIdCallback( $x ) {
904  $this->setOption( 'speculativeRevId', null ); // reset
905  return $this->setOption( 'speculativeRevIdCallback', $x );
906  }
907 
914  public function setSpeculativePageIdCallback( $x ) {
915  $this->setOption( 'speculativePageId', null ); // reset
916  return $this->setOption( 'speculativePageIdCallback', $x );
917  }
918 
923  public function getTimestamp() {
924  if ( !isset( $this->mTimestamp ) ) {
925  $this->mTimestamp = wfTimestampNow();
926  }
927  return $this->mTimestamp;
928  }
929 
935  public function setTimestamp( $x ) {
936  return wfSetVar( $this->mTimestamp, $x );
937  }
938 
949  function setRedirectTarget( $title ) {
950  $this->redirectTarget = $title;
951  }
952 
959  function getRedirectTarget() {
960  return $this->redirectTarget;
961  }
962 
969  public function addExtraKey( $key ) {
970  $this->mExtraKey .= '!' . $key;
971  }
972 
977  public function getUser() {
978  return $this->mUser;
979  }
980 
987  public function __construct( $user = null, $lang = null ) {
988  if ( $user === null ) {
989  global $wgUser;
990  if ( $wgUser === null ) {
991  $user = new User;
992  } else {
993  $user = $wgUser;
994  }
995  }
996  if ( $lang === null ) {
997  global $wgLang;
998  if ( !StubObject::isRealObject( $wgLang ) ) {
999  $wgLang->_unstub();
1000  }
1001  $lang = $wgLang;
1002  }
1003  $this->initialiseFromUser( $user, $lang );
1004  }
1005 
1013  public static function newFromAnon() {
1014  return new ParserOptions( new User,
1015  MediaWikiServices::getInstance()->getContentLanguage() );
1016  }
1017 
1027  public static function newFromUser( $user ) {
1028  return new ParserOptions( $user );
1029  }
1030 
1040  public static function newFromUserAndLang( User $user, Language $lang ) {
1041  return new ParserOptions( $user, $lang );
1042  }
1043 
1052  public static function newFromContext( IContextSource $context ) {
1053  return new ParserOptions( $context->getUser(), $context->getLanguage() );
1054  }
1055 
1073  public static function newCanonical( $context = null, $userLang = null ) {
1074  if ( $context instanceof IContextSource ) {
1075  $ret = self::newFromContext( $context );
1076  } elseif ( $context === 'canonical' ) {
1077  $ret = self::newFromAnon();
1078  } elseif ( $context instanceof User || $context === null ) {
1079  $ret = new self( $context, $userLang );
1080  } else {
1081  throw new InvalidArgumentException(
1082  '$context must be an IContextSource, the string "canonical", a User, or null'
1083  );
1084  }
1085 
1086  foreach ( self::getCanonicalOverrides() as $k => $v ) {
1087  $ret->setOption( $k, $v );
1088  }
1089  return $ret;
1090  }
1091 
1101  private static function getDefaults() {
1108 
1109  if ( self::$defaults === null ) {
1110  // *UPDATE* ParserOptions::matches() if any of this changes as needed
1111  self::$defaults = [
1112  'dateformat' => null,
1113  'tidy' => true,
1114  'interfaceMessage' => false,
1115  'targetLanguage' => null,
1116  'removeComments' => true,
1117  'enableLimitReport' => false,
1118  'preSaveTransform' => true,
1119  'isPreview' => false,
1120  'isSectionPreview' => false,
1121  'printable' => false,
1122  'allowUnsafeRawHtml' => true,
1123  'wrapclass' => 'mw-parser-output',
1124  'currentRevisionCallback' => [ Parser::class, 'statelessFetchRevision' ],
1125  'templateCallback' => [ Parser::class, 'statelessFetchTemplate' ],
1126  'speculativeRevIdCallback' => null,
1127  'speculativeRevId' => null,
1128  'speculativePageIdCallback' => null,
1129  'speculativePageId' => null,
1130  ];
1131 
1132  Hooks::run( 'ParserOptionsRegister', [
1133  &self::$defaults,
1134  &self::$inCacheKey,
1135  &self::$lazyOptions,
1136  ] );
1137 
1138  ksort( self::$inCacheKey );
1139  }
1140 
1141  // Unit tests depend on being able to modify the globals at will
1142  return self::$defaults + [
1143  'interwikiMagic' => $wgInterwikiMagic,
1144  'allowExternalImages' => $wgAllowExternalImages,
1145  'allowExternalImagesFrom' => $wgAllowExternalImagesFrom,
1146  'enableImageWhitelist' => $wgEnableImageWhitelist,
1147  'allowSpecialInclusion' => $wgAllowSpecialInclusion,
1148  'maxIncludeSize' => $wgMaxArticleSize * 1024,
1149  'maxPPNodeCount' => $wgMaxPPNodeCount,
1150  'maxGeneratedPPNodeCount' => $wgMaxGeneratedPPNodeCount,
1151  'maxPPExpandDepth' => $wgMaxPPExpandDepth,
1152  'maxTemplateDepth' => $wgMaxTemplateDepth,
1153  'expensiveParserFunctionLimit' => $wgExpensiveParserFunctionLimit,
1154  'externalLinkTarget' => $wgExternalLinkTarget,
1155  'cleanSignatures' => $wgCleanSignatures,
1156  'disableContentConversion' => $wgDisableLangConversion,
1157  'disableTitleConversion' => $wgDisableLangConversion || $wgDisableTitleConversion,
1158  'magicISBNLinks' => $wgEnableMagicLinks['ISBN'],
1159  'magicPMIDLinks' => $wgEnableMagicLinks['PMID'],
1160  'magicRFCLinks' => $wgEnableMagicLinks['RFC'],
1161  'numberheadings' => User::getDefaultOption( 'numberheadings' ),
1162  'thumbsize' => User::getDefaultOption( 'thumbsize' ),
1163  'stubthreshold' => 0,
1164  'userlang' => MediaWikiServices::getInstance()->getContentLanguage(),
1165  ];
1166  }
1167 
1177  private static function getCanonicalOverrides() {
1179 
1180  return [
1181  'enableLimitReport' => $wgEnableParserLimitReporting,
1182  ];
1183  }
1184 
1191  private function initialiseFromUser( $user, $lang ) {
1192  $this->options = self::getDefaults();
1193 
1194  $this->mUser = $user;
1195  $this->options['numberheadings'] = $user->getOption( 'numberheadings' );
1196  $this->options['thumbsize'] = $user->getOption( 'thumbsize' );
1197  $this->options['stubthreshold'] = $user->getStubThreshold();
1198  $this->options['userlang'] = $lang;
1199  }
1200 
1210  public function matches( ParserOptions $other ) {
1211  // Compare most options
1212  $options = array_keys( $this->options );
1213  $options = array_diff( $options, [
1214  'enableLimitReport', // only affects HTML comments
1215  ] );
1216  foreach ( $options as $option ) {
1217  // Resolve any lazy options
1218  $this->lazyLoadOption( $option );
1219  $other->lazyLoadOption( $option );
1220 
1221  $o1 = $this->optionToString( $this->options[$option] );
1222  $o2 = $this->optionToString( $other->options[$option] );
1223  if ( $o1 !== $o2 ) {
1224  return false;
1225  }
1226  }
1227 
1228  // Compare most other fields
1229  $fields = array_keys( get_class_vars( __CLASS__ ) );
1230  $fields = array_diff( $fields, [
1231  'defaults', // static
1232  'lazyOptions', // static
1233  'inCacheKey', // static
1234  'options', // Already checked above
1235  'onAccessCallback', // only used for ParserOutput option tracking
1236  ] );
1237  foreach ( $fields as $field ) {
1238  if ( !is_object( $this->$field ) && $this->$field !== $other->$field ) {
1239  return false;
1240  }
1241  }
1242 
1243  return true;
1244  }
1245 
1251  public function matchesForCacheKey( ParserOptions $other ) {
1252  foreach ( self::allCacheVaryingOptions() as $option ) {
1253  // Populate any lazy options
1254  $this->lazyLoadOption( $option );
1255  $other->lazyLoadOption( $option );
1256 
1257  $o1 = $this->optionToString( $this->options[$option] );
1258  $o2 = $this->optionToString( $other->options[$option] );
1259  if ( $o1 !== $o2 ) {
1260  return false;
1261  }
1262  }
1263 
1264  return true;
1265  }
1266 
1272  public function registerWatcher( $callback ) {
1273  $this->onAccessCallback = $callback;
1274  }
1275 
1284  public function optionUsed( $optionName ) {
1285  if ( $this->onAccessCallback ) {
1286  call_user_func( $this->onAccessCallback, $optionName );
1287  }
1288  }
1289 
1295  public static function allCacheVaryingOptions() {
1296  // Trigger a call to the 'ParserOptionsRegister' hook if it hasn't
1297  // already been called.
1298  if ( self::$defaults === null ) {
1300  }
1301  return array_keys( array_filter( self::$inCacheKey ) );
1302  }
1303 
1309  private function optionToString( $value ) {
1310  if ( $value === true ) {
1311  return '1';
1312  } elseif ( $value === false ) {
1313  return '0';
1314  } elseif ( $value === null ) {
1315  return '';
1316  } elseif ( $value instanceof Language ) {
1317  return $value->getCode();
1318  } elseif ( is_array( $value ) ) {
1319  return '[' . implode( ',', array_map( [ $this, 'optionToString' ], $value ) ) . ']';
1320  } else {
1321  return (string)$value;
1322  }
1323  }
1324 
1337  public function optionsHash( $forOptions, $title = null ) {
1338  global $wgRenderHashAppend;
1339 
1341 
1342  // Resolve any lazy options
1343  $lazyOpts = array_intersect( $forOptions, $inCacheKey, array_keys( self::$lazyOptions ) );
1344  foreach ( $lazyOpts as $k ) {
1345  $this->lazyLoadOption( $k );
1346  }
1347 
1350 
1351  // We only include used options with non-canonical values in the key
1352  // so adding a new option doesn't invalidate the entire parser cache.
1353  // The drawback to this is that changing the default value of an option
1354  // requires manual invalidation of existing cache entries, as mentioned
1355  // in the docs on the relevant methods and hooks.
1356  $values = [];
1357  foreach ( array_intersect( $inCacheKey, $forOptions ) as $option ) {
1358  $v = $this->optionToString( $options[$option] );
1359  $d = $this->optionToString( $defaults[$option] );
1360  if ( $v !== $d ) {
1361  $values[] = "$option=$v";
1362  }
1363  }
1364 
1365  $confstr = $values ? implode( '!', $values ) : 'canonical';
1366 
1367  // add in language specific options, if any
1368  // @todo FIXME: This is just a way of retrieving the url/user preferred variant
1369  if ( !is_null( $title ) ) {
1370  $confstr .= $title->getPageLanguage()->getExtraHashOptions();
1371  } else {
1372  $confstr .=
1373  MediaWikiServices::getInstance()->getContentLanguage()->getExtraHashOptions();
1374  }
1375 
1376  $confstr .= $wgRenderHashAppend;
1377 
1378  if ( $this->mExtraKey != '' ) {
1379  $confstr .= $this->mExtraKey;
1380  }
1381 
1382  // Give a chance for extensions to modify the hash, if they have
1383  // extra options or other effects on the parser cache.
1384  Hooks::run( 'PageRenderingHash', [ &$confstr, $this->getUser(), &$forOptions ] );
1385 
1386  // Make it a valid memcached key fragment
1387  $confstr = str_replace( ' ', '_', $confstr );
1388 
1389  return $confstr;
1390  }
1391 
1397  public function isSafeToCache() {
1399  foreach ( $this->options as $option => $value ) {
1400  if ( empty( self::$inCacheKey[$option] ) ) {
1401  $v = $this->optionToString( $value );
1402  $d = $this->optionToString( $defaults[$option] );
1403  if ( $v !== $d ) {
1404  return false;
1405  }
1406  }
1407  }
1408  return true;
1409  }
1410 
1421  public function setupFakeRevision( $title, $content, $user ) {
1422  $oldCallback = $this->setCurrentRevisionCallback(
1423  function (
1424  $titleToCheck, $parser = false ) use ( $title, $content, $user, &$oldCallback
1425  ) {
1426  if ( $titleToCheck->equals( $title ) ) {
1427  return new Revision( [
1428  'page' => $title->getArticleID(),
1429  'user_text' => $user->getName(),
1430  'user' => $user->getId(),
1431  'parent_id' => $title->getLatestRevID(),
1432  'title' => $title,
1433  'content' => $content
1434  ] );
1435  } else {
1436  return call_user_func( $oldCallback, $titleToCheck, $parser );
1437  }
1438  }
1439  );
1440 
1441  global $wgHooks;
1442  $wgHooks['TitleExists'][] =
1443  function ( $titleToCheck, &$exists ) use ( $title ) {
1444  if ( $titleToCheck->equals( $title ) ) {
1445  $exists = true;
1446  }
1447  };
1448  end( $wgHooks['TitleExists'] );
1449  $key = key( $wgHooks['TitleExists'] );
1450  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1451  $linkCache->clearBadLink( $title->getPrefixedDBkey() );
1452  return new ScopedCallback( function () use ( $title, $key, $linkCache ) {
1453  global $wgHooks;
1454  unset( $wgHooks['TitleExists'][$key] );
1455  $linkCache->clearLink( $title );
1456  } );
1457  }
1458 }
1459 
User\getDefaultOption
static getDefaultOption( $opt)
Get a given default option value.
Definition: User.php:1747
ParserOptions\setMaxIncludeSize
setMaxIncludeSize( $x)
Maximum size of template expansions, in bytes.
Definition: ParserOptions.php:356
ParserOptions\getMagicPMIDLinks
getMagicPMIDLinks()
Are magic PMID links enabled?
Definition: ParserOptions.php:736
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:42
ParserOptions\setOptionLegacy
setOptionLegacy( $name, $value)
Legacy implementation.
Definition: ParserOptions.php:173
ParserOptions\getAllowExternalImagesFrom
getAllowExternalImagesFrom()
External images to allow.
Definition: ParserOptions.php:225
ParserOptions\getWrapOutputClass
getWrapOutputClass()
Class to use to wrap output from Parser::parse()
Definition: ParserOptions.php:784
ParserOptions\getExpensiveParserFunctionLimit
getExpensiveParserFunctionLimit()
Maximum number of calls per parse to expensive parser functions.
Definition: ParserOptions.php:424
ParserOptions\setTidy
setTidy( $x)
Use tidy to cleanup output HTML?
Definition: ParserOptions.php:305
ParserOptions\getIsSectionPreview
getIsSectionPreview()
Parsing the page for a "preview" operation on a single section?
Definition: ParserOptions.php:599
$wgMaxArticleSize
$wgMaxArticleSize
Maximum article size in kilobytes.
Definition: DefaultSettings.php:2290
ParserOptions\getRemoveComments
getRemoveComments()
Remove HTML comments.
Definition: ParserOptions.php:443
ParserOptions\setAllowUnsafeRawHtml
setAllowUnsafeRawHtml( $x)
If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of...
Definition: ParserOptions.php:775
ParserOptions\disableContentConversion
disableContentConversion( $x=true)
Whether content conversion should be disabled.
Definition: ParserOptions.php:523
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:129
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:35
ParserOptions\initialiseFromUser
initialiseFromUser( $user, $lang)
Get user options.
Definition: ParserOptions.php:1191
wfSetVar
wfSetVar(&$dest, $source, $force=false)
Sets dest to source and returns the original value of dest If source is NULL, it just returns the val...
Definition: GlobalFunctions.php:1606
$wgMaxTemplateDepth
$wgMaxTemplateDepth
Maximum recursion depth for templates within templates.
Definition: DefaultSettings.php:4172
ParserOptions\getIsPreview
getIsPreview()
Parsing the page for a "preview" operation?
Definition: ParserOptions.php:582
ParserOptions\getDisableTitleConversion
getDisableTitleConversion()
Whether title conversion should be disabled.
Definition: ParserOptions.php:531
ParserOptions\setAllowExternalImages
setAllowExternalImages( $x)
Allow all external images inline?
Definition: ParserOptions.php:214
ParserOptions\setTemplateCallback
setTemplateCallback( $x)
Callback for template fetching; first argument to call_user_func().
Definition: ParserOptions.php:837
ParserOptions\setIsPreview
setIsPreview( $x)
Parsing the page for a "preview" operation?
Definition: ParserOptions.php:591
ParserOptions\setTargetLanguage
setTargetLanguage( $x)
Target language for the parse.
Definition: ParserOptions.php:339
ParserOptions\getInterfaceMessage
getInterfaceMessage()
Parsing an interface message?
Definition: ParserOptions.php:313
ParserOptions\setIsSectionPreview
setIsSectionPreview( $x)
Parsing the page for a "preview" operation on a single section?
Definition: ParserOptions.php:608
ParserOptions\getSpeculativeRevId
getSpeculativeRevId()
A guess for {{REVISIONID}}, calculated using the callback provided via setSpeculativeRevIdCallback().
Definition: ParserOptions.php:851
ParserOptions\newFromAnon
static newFromAnon()
Get a ParserOptions object for an anonymous user.
Definition: ParserOptions.php:1013
ParserOptions\setEnableImageWhitelist
setEnableImageWhitelist( $x)
Use the on-wiki external image whitelist?
Definition: ParserOptions.php:254
$wgDisableTitleConversion
$wgDisableTitleConversion
Whether to enable language variant conversion for links.
Definition: DefaultSettings.php:3131
ParserOptions\setWrapOutputClass
setWrapOutputClass( $className)
CSS class to use to wrap output from Parser::parse()
Definition: ParserOptions.php:795
ParserOptions\setSpeculativeRevIdCallback
setSpeculativeRevIdCallback( $x)
Callback to generate a guess for {{REVISIONID}}.
Definition: ParserOptions.php:903
ParserOptions\disableTitleConversion
disableTitleConversion( $x=true)
Whether title conversion should be disabled.
Definition: ParserOptions.php:540
ParserOptions\initDateFormat
static initDateFormat(ParserOptions $popt)
Lazy initializer for dateFormat.
Definition: ParserOptions.php:659
ParserOptions\getIsPrintable
getIsPrintable()
Parsing the printable version of the page?
Definition: ParserOptions.php:616
ParserOptions\setMaxGeneratedPPNodeCount
setMaxGeneratedPPNodeCount( $x)
Maximum number of nodes generated by Preprocessor::preprocessToObj()
Definition: ParserOptions.php:390
ParserOptions\setCurrentRevisionCallback
setCurrentRevisionCallback( $x)
Callback for current revision fetching; first argument to call_user_func().
Definition: ParserOptions.php:820
ParserOptions\$inCacheKey
static array $inCacheKey
Specify options that are included in the cache key.
Definition: ParserOptions.php:72
ParserOptions\setMaxTemplateDepth
setMaxTemplateDepth( $x)
Maximum recursion depth for templates within templates.
Definition: ParserOptions.php:415
ParserOptions\getMagicRFCLinks
getMagicRFCLinks()
Are magic RFC links enabled?
Definition: ParserOptions.php:745
ParserOptions\getUserLangObj
getUserLangObj()
Get the user language used by the parser for this page and split the parser cache.
Definition: ParserOptions.php:689
ParserOptions\registerWatcher
registerWatcher( $callback)
Registers a callback for tracking which ParserOptions which are used.
Definition: ParserOptions.php:1272
ParserOptions\setupFakeRevision
setupFakeRevision( $title, $content, $user)
Sets a hook to force that a page exists, and sets a current revision callback to return a revision wi...
Definition: ParserOptions.php:1421
ParserOptions\getDateFormat
getDateFormat()
Date format index.
Definition: ParserOptions.php:650
ParserOptions\HAS_NEWCANONICAL_FROM_CONTEXT
const HAS_NEWCANONICAL_FROM_CONTEXT
Flag indicating that newCanonical() accepts an IContextSource or the string 'canonical',...
Definition: ParserOptions.php:49
Revision
Definition: Revision.php:40
ParserOptions\setOption
setOption( $name, $value)
Set an option, generically.
Definition: ParserOptions.php:156
ParserOptions\initSpeculativeRevId
static initSpeculativeRevId(ParserOptions $popt)
Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativeRevId().
Definition: ParserOptions.php:875
ParserOptions\setNumberHeadings
setNumberHeadings( $x)
Automatically number headings?
Definition: ParserOptions.php:271
$wgHooks
$wgHooks
Global list of hooks.
Definition: DefaultSettings.php:7482
ParserOptions\getCanonicalOverrides
static getCanonicalOverrides()
Get "canonical" non-default option values.
Definition: ParserOptions.php:1177
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1044
ParserOptions\getRedirectTarget
getRedirectTarget()
Get the previously-set redirect target.
Definition: ParserOptions.php:959
ParserOptions\newFromUserAndLang
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
Definition: ParserOptions.php:1040
ParserOptions\setUserLang
setUserLang( $x)
Set the user language used by the parser for this page and split the parser cache.
Definition: ParserOptions.php:714
ParserOptions\getAllowSpecialInclusion
getAllowSpecialInclusion()
Allow inclusion of special pages?
Definition: ParserOptions.php:279
$wgAllowExternalImagesFrom
$wgAllowExternalImagesFrom
If the above is false, you can specify an exception here.
Definition: DefaultSettings.php:4218
ParserOptions\getTidy
getTidy()
Use tidy to cleanup output HTML?
Definition: ParserOptions.php:296
ParserOptions\getMaxIncludeSize
getMaxIncludeSize()
Maximum size of template expansions, in bytes.
Definition: ParserOptions.php:347
ParserOptions\$mTimestamp
string null $mTimestamp
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:92
$wgLang
$wgLang
Definition: Setup.php:858
$wgExpensiveParserFunctionLimit
$wgExpensiveParserFunctionLimit
Maximum number of calls per parse to expensive parser functions such as PAGESINCATEGORY.
Definition: DefaultSettings.php:4327
ParserOptions\setThumbSize
setThumbSize( $x)
Thumb size preferred by the user.
Definition: ParserOptions.php:557
ParserOptions\getEnableImageWhitelist
getEnableImageWhitelist()
Use the on-wiki external image whitelist?
Definition: ParserOptions.php:245
$wgInterwikiMagic
$wgInterwikiMagic
Treat language links as magic connectors, not inline links.
Definition: DefaultSettings.php:2971
ParserOptions\setExternalLinkTarget
setExternalLinkTarget( $x)
Target attribute for external links.
Definition: ParserOptions.php:506
ParserOptions\setDateFormat
setDateFormat( $x)
Date format index.
Definition: ParserOptions.php:668
ParserOptions\getTargetLanguage
getTargetLanguage()
Target language for the parse.
Definition: ParserOptions.php:330
$title
$title
Definition: testCompression.php:36
ParserOptions\initSpeculativePageId
static initSpeculativePageId(ParserOptions $popt)
Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativePageId().
Definition: ParserOptions.php:889
ParserOptions\setAllowSpecialInclusion
setAllowSpecialInclusion( $x)
Allow inclusion of special pages?
Definition: ParserOptions.php:288
$wgMaxPPExpandDepth
$wgMaxPPExpandDepth
Definition: DefaultSettings.php:4177
ParserOptions\getDefaults
static getDefaults()
Get default option values.
Definition: ParserOptions.php:1101
ParserOptions\getExternalLinkTarget
getExternalLinkTarget()
Target attribute for external links.
Definition: ParserOptions.php:497
ParserOptions\$onAccessCallback
callable null $onAccessCallback
Function to be called when an option is accessed.
Definition: ParserOptions.php:106
$wgEnableMagicLinks
$wgEnableMagicLinks
Enable the magic links feature of automatically turning ISBN xxx, PMID xxx, RFC xxx into links.
Definition: DefaultSettings.php:4352
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1900
ParserOptions\getStubThreshold
getStubThreshold()
Thumb size preferred by the user.
Definition: ParserOptions.php:565
$wgExternalLinkTarget
$wgExternalLinkTarget
Set a default target for external links, e.g.
Definition: DefaultSettings.php:4280
ParserOptions\$options
array $options
Current values for all options that are relevant for caching.
Definition: ParserOptions.php:85
ParserOptions\getUserLang
getUserLang()
Same as getUserLangObj() but returns a string instead.
Definition: ParserOptions.php:705
$wgDisableLangConversion
$wgDisableLangConversion
Whether to enable language variant conversion.
Definition: DefaultSettings.php:3126
ParserOptions\getPreSaveTransform
getPreSaveTransform()
Transform wiki markup when saving the page?
Definition: ParserOptions.php:633
ParserOptions\setStubThreshold
setStubThreshold( $x)
Thumb size preferred by the user.
Definition: ParserOptions.php:574
ParserOptions\getOption
getOption( $name)
Fetch an option and track that is was accessed.
Definition: ParserOptions.php:127
ParserOptions\$mExtraKey
$mExtraKey
Appended to the options hash.
Definition: ParserOptions.php:119
ParserOptions\getAllowUnsafeRawHtml
getAllowUnsafeRawHtml()
If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of...
Definition: ParserOptions.php:763
ParserOptions\getDisableContentConversion
getDisableContentConversion()
Whether content conversion should be disabled.
Definition: ParserOptions.php:514
ParserOptions\optionToString
optionToString( $value)
Convert an option to a string value.
Definition: ParserOptions.php:1309
ParserOptions\matchesForCacheKey
matchesForCacheKey(ParserOptions $other)
Definition: ParserOptions.php:1251
ParserOptions\optionUsed
optionUsed( $optionName)
Called when an option is accessed.
Definition: ParserOptions.php:1284
$content
$content
Definition: router.php:78
ParserOptions\getSpeculativePageId
getSpeculativePageId()
A guess for {{PAGEID}}, calculated using the callback provided via setSpeculativeRevPageCallback().
Definition: ParserOptions.php:865
ParserOptions\setTimestamp
setTimestamp( $x)
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:935
ParserOptions\setSpeculativePageIdCallback
setSpeculativePageIdCallback( $x)
Callback to generate a guess for {{PAGEID}}.
Definition: ParserOptions.php:914
ParserOptions\setCleanSignatures
setCleanSignatures( $x)
Clean up signature texts?
Definition: ParserOptions.php:489
ParserOptions\newFromContext
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
Definition: ParserOptions.php:1052
ParserOptions\getCurrentRevisionCallback
getCurrentRevisionCallback()
Callback for current revision fetching; first argument to call_user_func().
Definition: ParserOptions.php:810
$wgEnableParserLimitReporting
$wgEnableParserLimitReporting
Whether to include the NewPP limit report as a HTML comment.
Definition: DefaultSettings.php:7362
ParserOptions\getTemplateCallback
getTemplateCallback()
Callback for template fetching; first argument to call_user_func().
Definition: ParserOptions.php:828
ParserOptions\newCanonical
static newCanonical( $context=null, $userLang=null)
Creates a "canonical" ParserOptions object.
Definition: ParserOptions.php:1073
ParserOptions\setRemoveComments
setRemoveComments( $x)
Remove HTML comments.
Definition: ParserOptions.php:453
ParserOptions\setInterwikiMagic
setInterwikiMagic( $x)
Specify whether to extract interlanguage links.
Definition: ParserOptions.php:197
ParserOptions\lazyLoadOption
lazyLoadOption( $name)
Definition: ParserOptions.php:142
ParserOptions\setRedirectTarget
setRedirectTarget( $title)
Set the redirect target.
Definition: ParserOptions.php:949
ParserOptions\setExpensiveParserFunctionLimit
setExpensiveParserFunctionLimit( $x)
Maximum number of calls per parse to expensive parser functions.
Definition: ParserOptions.php:434
ParserOptions\getTimestamp
getTimestamp()
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:923
ParserOptions\setMaxPPNodeCount
setMaxPPNodeCount( $x)
Maximum number of nodes touched by PPFrame::expand()
Definition: ParserOptions.php:373
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:53
ParserOptions\getCleanSignatures
getCleanSignatures()
Clean up signature texts?
Definition: ParserOptions.php:479
$context
$context
Definition: load.php:40
ParserOptions\$redirectTarget
Title null $redirectTarget
If the page being parsed is a redirect, this should hold the redirect target.
Definition: ParserOptions.php:114
ParserOptions\setAllowExternalImagesFrom
setAllowExternalImagesFrom( $x)
External images to allow.
Definition: ParserOptions.php:237
ParserOptions\matches
matches(ParserOptions $other)
Check if these options match that of another options set.
Definition: ParserOptions.php:1210
ParserOptions\enableLimitReport
enableLimitReport( $x=true)
Enable limit report in an HTML comment on output.
Definition: ParserOptions.php:470
Title
Represents a title within MediaWiki.
Definition: Title.php:42
ParserOptions\__construct
__construct( $user=null, $lang=null)
Definition: ParserOptions.php:987
ParserOptions\getInterwikiMagic
getInterwikiMagic()
Whether to extract interlanguage links.
Definition: ParserOptions.php:188
ParserOptions\$lazyOptions
static callable[] $lazyOptions
Lazy-loaded options.
Definition: ParserOptions.php:62
ParserOptions\$mUser
User $mUser
Stored user object.
Definition: ParserOptions.php:99
ParserOptions\setInterfaceMessage
setInterfaceMessage( $x)
Parsing an interface message?
Definition: ParserOptions.php:322
ParserOptions\$defaults
static array null $defaults
Default values for all options that are relevant for caching.
Definition: ParserOptions.php:56
ParserOptions\allCacheVaryingOptions
static allCacheVaryingOptions()
Return all option keys that vary the options hash.
Definition: ParserOptions.php:1295
$wgCleanSignatures
$wgCleanSignatures
If true, removes (by substituting) templates in signatures.
Definition: DefaultSettings.php:4199
ParserOptions\getUser
getUser()
Current user.
Definition: ParserOptions.php:977
ParserOptions\getThumbSize
getThumbSize()
Thumb size preferred by the user.
Definition: ParserOptions.php:548
StubObject\isRealObject
static isRealObject( $obj)
Returns a bool value whenever $obj is a stub object.
Definition: StubObject.php:81
ParserOptions\getMagicISBNLinks
getMagicISBNLinks()
Are magic ISBN links enabled?
Definition: ParserOptions.php:727
ParserOptions\setIsPrintable
setIsPrintable( $x)
Parsing the printable version of the page?
Definition: ParserOptions.php:625
ParserOptions\getMaxPPNodeCount
getMaxPPNodeCount()
Maximum number of nodes touched by PPFrame::expand()
Definition: ParserOptions.php:364
$wgRenderHashAppend
$wgRenderHashAppend
Append a configured value to the parser cache and the sitenotice key so that they can be kept separat...
Definition: DefaultSettings.php:2666
$wgMaxGeneratedPPNodeCount
$wgMaxGeneratedPPNodeCount
A complexity limit on template expansion: the maximum number of elements generated by Preprocessor::p...
Definition: DefaultSettings.php:4164
ParserOptions\getMaxGeneratedPPNodeCount
getMaxGeneratedPPNodeCount()
Maximum number of nodes generated by Preprocessor::preprocessToObj()
Definition: ParserOptions.php:381
ParserOptions\getMaxPPExpandDepth
getMaxPPExpandDepth()
Maximum recursion depth in PPFrame::expand()
Definition: ParserOptions.php:398
ParserOptions\getEnableLimitReport
getEnableLimitReport()
Enable limit report in an HTML comment on output.
Definition: ParserOptions.php:461
ParserOptions\getNumberHeadings
getNumberHeadings()
Automatically number headings?
Definition: ParserOptions.php:262
ParserOptions\isSafeToCache
isSafeToCache()
Test whether these options are safe to cache.
Definition: ParserOptions.php:1397
ParserOptions\getMaxTemplateDepth
getMaxTemplateDepth()
Maximum recursion depth for templates within templates.
Definition: ParserOptions.php:406
ParserOptions\setPreSaveTransform
setPreSaveTransform( $x)
Transform wiki markup when saving the page?
Definition: ParserOptions.php:642
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
$wgMaxPPNodeCount
$wgMaxPPNodeCount
A complexity limit on template expansion: the maximum number of nodes visited by PPFrame::expand()
Definition: DefaultSettings.php:4153
Language
Internationalisation code.
Definition: Language.php:39
ParserOptions\optionsHash
optionsHash( $forOptions, $title=null)
Generate a hash string with the values set on these ParserOptions for the keys given in the array.
Definition: ParserOptions.php:1337
ParserOptions\getAllowExternalImages
getAllowExternalImages()
Allow all external images inline?
Definition: ParserOptions.php:205
ParserOptions\newFromUser
static newFromUser( $user)
Get a ParserOptions object from a given user.
Definition: ParserOptions.php:1027
$wgAllowExternalImages
$wgAllowExternalImages
Whether to allow inline image pointing to other websites.
Definition: DefaultSettings.php:4204
$wgEnableImageWhitelist
$wgEnableImageWhitelist
If $wgAllowExternalImages is false, you can allow an on-wiki whitelist of regular expression fragment...
Definition: DefaultSettings.php:4231
ParserOptions\addExtraKey
addExtraKey( $key)
Extra key that should be present in the parser cache key.
Definition: ParserOptions.php:969
$wgAllowSpecialInclusion
$wgAllowSpecialInclusion
Allow special page inclusions such as {{Special:Allpages}}.
Definition: DefaultSettings.php:7922