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 getMaxPPExpandDepth() {
382  return $this->getOption( 'maxPPExpandDepth' );
383  }
384 
389  public function getMaxTemplateDepth() {
390  return $this->getOption( 'maxTemplateDepth' );
391  }
392 
398  public function setMaxTemplateDepth( $x ) {
399  return $this->setOptionLegacy( 'maxTemplateDepth', $x );
400  }
401 
408  return $this->getOption( 'expensiveParserFunctionLimit' );
409  }
410 
417  public function setExpensiveParserFunctionLimit( $x ) {
418  return $this->setOptionLegacy( 'expensiveParserFunctionLimit', $x );
419  }
420 
426  public function getRemoveComments() {
427  return $this->getOption( 'removeComments' );
428  }
429 
436  public function setRemoveComments( $x ) {
437  return $this->setOptionLegacy( 'removeComments', $x );
438  }
439 
444  public function getEnableLimitReport() {
445  return $this->getOption( 'enableLimitReport' );
446  }
447 
453  public function enableLimitReport( $x = true ) {
454  return $this->setOptionLegacy( 'enableLimitReport', $x );
455  }
456 
462  public function getCleanSignatures() {
463  return $this->getOption( 'cleanSignatures' );
464  }
465 
472  public function setCleanSignatures( $x ) {
473  return $this->setOptionLegacy( 'cleanSignatures', $x );
474  }
475 
480  public function getExternalLinkTarget() {
481  return $this->getOption( 'externalLinkTarget' );
482  }
483 
489  public function setExternalLinkTarget( $x ) {
490  return $this->setOptionLegacy( 'externalLinkTarget', $x );
491  }
492 
497  public function getDisableContentConversion() {
498  return $this->getOption( 'disableContentConversion' );
499  }
500 
506  public function disableContentConversion( $x = true ) {
507  return $this->setOptionLegacy( 'disableContentConversion', $x );
508  }
509 
514  public function getDisableTitleConversion() {
515  return $this->getOption( 'disableTitleConversion' );
516  }
517 
523  public function disableTitleConversion( $x = true ) {
524  return $this->setOptionLegacy( 'disableTitleConversion', $x );
525  }
526 
531  public function getThumbSize() {
532  return $this->getOption( 'thumbsize' );
533  }
534 
540  public function setThumbSize( $x ) {
541  return $this->setOptionLegacy( 'thumbsize', $x );
542  }
543 
548  public function getStubThreshold() {
549  return $this->getOption( 'stubthreshold' );
550  }
551 
557  public function setStubThreshold( $x ) {
558  return $this->setOptionLegacy( 'stubthreshold', $x );
559  }
560 
565  public function getIsPreview() {
566  return $this->getOption( 'isPreview' );
567  }
568 
574  public function setIsPreview( $x ) {
575  return $this->setOptionLegacy( 'isPreview', $x );
576  }
577 
582  public function getIsSectionPreview() {
583  return $this->getOption( 'isSectionPreview' );
584  }
585 
591  public function setIsSectionPreview( $x ) {
592  return $this->setOptionLegacy( 'isSectionPreview', $x );
593  }
594 
599  public function getIsPrintable() {
600  return $this->getOption( 'printable' );
601  }
602 
608  public function setIsPrintable( $x ) {
609  return $this->setOptionLegacy( 'printable', $x );
610  }
611 
616  public function getPreSaveTransform() {
617  return $this->getOption( 'preSaveTransform' );
618  }
619 
625  public function setPreSaveTransform( $x ) {
626  return $this->setOptionLegacy( 'preSaveTransform', $x );
627  }
628 
633  public function getDateFormat() {
634  return $this->getOption( 'dateformat' );
635  }
636 
642  private static function initDateFormat( ParserOptions $popt ) {
643  return $popt->mUser->getDatePreference();
644  }
645 
651  public function setDateFormat( $x ) {
652  return $this->setOptionLegacy( 'dateformat', $x );
653  }
654 
672  public function getUserLangObj() {
673  return $this->getOption( 'userlang' );
674  }
675 
688  public function getUserLang() {
689  return $this->getUserLangObj()->getCode();
690  }
691 
697  public function setUserLang( $x ) {
698  if ( is_string( $x ) ) {
699  $x = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $x );
700  }
701 
702  return $this->setOptionLegacy( 'userlang', $x );
703  }
704 
710  public function getMagicISBNLinks() {
711  return $this->getOption( 'magicISBNLinks' );
712  }
713 
719  public function getMagicPMIDLinks() {
720  return $this->getOption( 'magicPMIDLinks' );
721  }
722 
728  public function getMagicRFCLinks() {
729  return $this->getOption( 'magicRFCLinks' );
730  }
731 
746  public function getAllowUnsafeRawHtml() {
747  return $this->getOption( 'allowUnsafeRawHtml' );
748  }
749 
758  public function setAllowUnsafeRawHtml( $x ) {
759  return $this->setOptionLegacy( 'allowUnsafeRawHtml', $x );
760  }
761 
767  public function getWrapOutputClass() {
768  return $this->getOption( 'wrapclass' );
769  }
770 
778  public function setWrapOutputClass( $className ) {
779  if ( $className === true ) { // DWIM, they probably want the default class name
780  $className = 'mw-parser-output';
781  }
782  if ( $className === false ) {
783  wfDeprecated( __METHOD__ . '( false )', '1.31' );
784  }
785  return $this->setOption( 'wrapclass', $className );
786  }
787 
793  public function getCurrentRevisionCallback() {
794  return $this->getOption( 'currentRevisionCallback' );
795  }
796 
803  public function setCurrentRevisionCallback( $x ) {
804  return $this->setOptionLegacy( 'currentRevisionCallback', $x );
805  }
806 
811  public function getTemplateCallback() {
812  return $this->getOption( 'templateCallback' );
813  }
814 
820  public function setTemplateCallback( $x ) {
821  return $this->setOptionLegacy( 'templateCallback', $x );
822  }
823 
834  public function getSpeculativeRevId() {
835  return $this->getOption( 'speculativeRevId' );
836  }
837 
848  public function getSpeculativePageId() {
849  return $this->getOption( 'speculativePageId' );
850  }
851 
858  private static function initSpeculativeRevId( ParserOptions $popt ) {
859  $cb = $popt->getOption( 'speculativeRevIdCallback' );
860  $id = $cb ? $cb() : null;
861 
862  // returning null would result in this being re-called every access
863  return $id ?? false;
864  }
865 
872  private static function initSpeculativePageId( ParserOptions $popt ) {
873  $cb = $popt->getOption( 'speculativePageIdCallback' );
874  $id = $cb ? $cb() : null;
875 
876  // returning null would result in this being re-called every access
877  return $id ?? false;
878  }
879 
886  public function setSpeculativeRevIdCallback( $x ) {
887  $this->setOption( 'speculativeRevId', null ); // reset
888  return $this->setOption( 'speculativeRevIdCallback', $x );
889  }
890 
897  public function setSpeculativePageIdCallback( $x ) {
898  $this->setOption( 'speculativePageId', null ); // reset
899  return $this->setOption( 'speculativePageIdCallback', $x );
900  }
901 
906  public function getTimestamp() {
907  if ( !isset( $this->mTimestamp ) ) {
908  $this->mTimestamp = wfTimestampNow();
909  }
910  return $this->mTimestamp;
911  }
912 
918  public function setTimestamp( $x ) {
919  return wfSetVar( $this->mTimestamp, $x );
920  }
921 
932  function setRedirectTarget( $title ) {
933  $this->redirectTarget = $title;
934  }
935 
942  function getRedirectTarget() {
943  return $this->redirectTarget;
944  }
945 
952  public function addExtraKey( $key ) {
953  $this->mExtraKey .= '!' . $key;
954  }
955 
960  public function getUser() {
961  return $this->mUser;
962  }
963 
970  public function __construct( $user = null, $lang = null ) {
971  if ( $user === null ) {
972  global $wgUser;
973  if ( $wgUser === null ) {
974  $user = new User;
975  } else {
976  $user = $wgUser;
977  }
978  }
979  if ( $lang === null ) {
980  global $wgLang;
981  if ( !StubObject::isRealObject( $wgLang ) ) {
982  $wgLang->_unstub();
983  }
984  $lang = $wgLang;
985  }
986  $this->initialiseFromUser( $user, $lang );
987  }
988 
996  public static function newFromAnon() {
997  return new ParserOptions( new User,
998  MediaWikiServices::getInstance()->getContentLanguage() );
999  }
1000 
1010  public static function newFromUser( $user ) {
1011  return new ParserOptions( $user );
1012  }
1013 
1023  public static function newFromUserAndLang( User $user, Language $lang ) {
1024  return new ParserOptions( $user, $lang );
1025  }
1026 
1035  public static function newFromContext( IContextSource $context ) {
1036  return new ParserOptions( $context->getUser(), $context->getLanguage() );
1037  }
1038 
1056  public static function newCanonical( $context = null, $userLang = null ) {
1057  if ( $context instanceof IContextSource ) {
1058  $ret = self::newFromContext( $context );
1059  } elseif ( $context === 'canonical' ) {
1060  $ret = self::newFromAnon();
1061  } elseif ( $context instanceof User || $context === null ) {
1062  $ret = new self( $context, $userLang );
1063  } else {
1064  throw new InvalidArgumentException(
1065  '$context must be an IContextSource, the string "canonical", a User, or null'
1066  );
1067  }
1068 
1069  foreach ( self::getCanonicalOverrides() as $k => $v ) {
1070  $ret->setOption( $k, $v );
1071  }
1072  return $ret;
1073  }
1074 
1084  private static function getDefaults() {
1091 
1092  if ( self::$defaults === null ) {
1093  // *UPDATE* ParserOptions::matches() if any of this changes as needed
1094  self::$defaults = [
1095  'dateformat' => null,
1096  'tidy' => true,
1097  'interfaceMessage' => false,
1098  'targetLanguage' => null,
1099  'removeComments' => true,
1100  'enableLimitReport' => false,
1101  'preSaveTransform' => true,
1102  'isPreview' => false,
1103  'isSectionPreview' => false,
1104  'printable' => false,
1105  'allowUnsafeRawHtml' => true,
1106  'wrapclass' => 'mw-parser-output',
1107  'currentRevisionCallback' => [ Parser::class, 'statelessFetchRevision' ],
1108  'templateCallback' => [ Parser::class, 'statelessFetchTemplate' ],
1109  'speculativeRevIdCallback' => null,
1110  'speculativeRevId' => null,
1111  'speculativePageIdCallback' => null,
1112  'speculativePageId' => null,
1113  ];
1114 
1115  Hooks::run( 'ParserOptionsRegister', [
1116  &self::$defaults,
1117  &self::$inCacheKey,
1118  &self::$lazyOptions,
1119  ] );
1120 
1121  ksort( self::$inCacheKey );
1122  }
1123 
1124  // Unit tests depend on being able to modify the globals at will
1125  return self::$defaults + [
1126  'interwikiMagic' => $wgInterwikiMagic,
1127  'allowExternalImages' => $wgAllowExternalImages,
1128  'allowExternalImagesFrom' => $wgAllowExternalImagesFrom,
1129  'enableImageWhitelist' => $wgEnableImageWhitelist,
1130  'allowSpecialInclusion' => $wgAllowSpecialInclusion,
1131  'maxIncludeSize' => $wgMaxArticleSize * 1024,
1132  'maxPPNodeCount' => $wgMaxPPNodeCount,
1133  'maxPPExpandDepth' => $wgMaxPPExpandDepth,
1134  'maxTemplateDepth' => $wgMaxTemplateDepth,
1135  'expensiveParserFunctionLimit' => $wgExpensiveParserFunctionLimit,
1136  'externalLinkTarget' => $wgExternalLinkTarget,
1137  'cleanSignatures' => $wgCleanSignatures,
1138  'disableContentConversion' => $wgDisableLangConversion,
1139  'disableTitleConversion' => $wgDisableLangConversion || $wgDisableTitleConversion,
1140  'magicISBNLinks' => $wgEnableMagicLinks['ISBN'],
1141  'magicPMIDLinks' => $wgEnableMagicLinks['PMID'],
1142  'magicRFCLinks' => $wgEnableMagicLinks['RFC'],
1143  'numberheadings' => User::getDefaultOption( 'numberheadings' ),
1144  'thumbsize' => User::getDefaultOption( 'thumbsize' ),
1145  'stubthreshold' => 0,
1146  'userlang' => MediaWikiServices::getInstance()->getContentLanguage(),
1147  ];
1148  }
1149 
1159  private static function getCanonicalOverrides() {
1161 
1162  return [
1163  'enableLimitReport' => $wgEnableParserLimitReporting,
1164  ];
1165  }
1166 
1173  private function initialiseFromUser( $user, $lang ) {
1174  $this->options = self::getDefaults();
1175 
1176  $this->mUser = $user;
1177  $this->options['numberheadings'] = $user->getOption( 'numberheadings' );
1178  $this->options['thumbsize'] = $user->getOption( 'thumbsize' );
1179  $this->options['stubthreshold'] = $user->getStubThreshold();
1180  $this->options['userlang'] = $lang;
1181  }
1182 
1192  public function matches( ParserOptions $other ) {
1193  // Compare most options
1194  $options = array_keys( $this->options );
1195  $options = array_diff( $options, [
1196  'enableLimitReport', // only affects HTML comments
1197  ] );
1198  foreach ( $options as $option ) {
1199  // Resolve any lazy options
1200  $this->lazyLoadOption( $option );
1201  $other->lazyLoadOption( $option );
1202 
1203  $o1 = $this->optionToString( $this->options[$option] );
1204  $o2 = $this->optionToString( $other->options[$option] );
1205  if ( $o1 !== $o2 ) {
1206  return false;
1207  }
1208  }
1209 
1210  // Compare most other fields
1211  $fields = array_keys( get_class_vars( __CLASS__ ) );
1212  $fields = array_diff( $fields, [
1213  'defaults', // static
1214  'lazyOptions', // static
1215  'inCacheKey', // static
1216  'options', // Already checked above
1217  'onAccessCallback', // only used for ParserOutput option tracking
1218  ] );
1219  foreach ( $fields as $field ) {
1220  if ( !is_object( $this->$field ) && $this->$field !== $other->$field ) {
1221  return false;
1222  }
1223  }
1224 
1225  return true;
1226  }
1227 
1233  public function matchesForCacheKey( ParserOptions $other ) {
1234  foreach ( self::allCacheVaryingOptions() as $option ) {
1235  // Populate any lazy options
1236  $this->lazyLoadOption( $option );
1237  $other->lazyLoadOption( $option );
1238 
1239  $o1 = $this->optionToString( $this->options[$option] );
1240  $o2 = $this->optionToString( $other->options[$option] );
1241  if ( $o1 !== $o2 ) {
1242  return false;
1243  }
1244  }
1245 
1246  return true;
1247  }
1248 
1254  public function registerWatcher( $callback ) {
1255  $this->onAccessCallback = $callback;
1256  }
1257 
1266  public function optionUsed( $optionName ) {
1267  if ( $this->onAccessCallback ) {
1268  call_user_func( $this->onAccessCallback, $optionName );
1269  }
1270  }
1271 
1277  public static function allCacheVaryingOptions() {
1278  // Trigger a call to the 'ParserOptionsRegister' hook if it hasn't
1279  // already been called.
1280  if ( self::$defaults === null ) {
1282  }
1283  return array_keys( array_filter( self::$inCacheKey ) );
1284  }
1285 
1291  private function optionToString( $value ) {
1292  if ( $value === true ) {
1293  return '1';
1294  } elseif ( $value === false ) {
1295  return '0';
1296  } elseif ( $value === null ) {
1297  return '';
1298  } elseif ( $value instanceof Language ) {
1299  return $value->getCode();
1300  } elseif ( is_array( $value ) ) {
1301  return '[' . implode( ',', array_map( [ $this, 'optionToString' ], $value ) ) . ']';
1302  } else {
1303  return (string)$value;
1304  }
1305  }
1306 
1319  public function optionsHash( $forOptions, $title = null ) {
1320  global $wgRenderHashAppend;
1321 
1323 
1324  // Resolve any lazy options
1325  $lazyOpts = array_intersect( $forOptions, $inCacheKey, array_keys( self::$lazyOptions ) );
1326  foreach ( $lazyOpts as $k ) {
1327  $this->lazyLoadOption( $k );
1328  }
1329 
1332 
1333  // We only include used options with non-canonical values in the key
1334  // so adding a new option doesn't invalidate the entire parser cache.
1335  // The drawback to this is that changing the default value of an option
1336  // requires manual invalidation of existing cache entries, as mentioned
1337  // in the docs on the relevant methods and hooks.
1338  $values = [];
1339  foreach ( array_intersect( $inCacheKey, $forOptions ) as $option ) {
1340  $v = $this->optionToString( $options[$option] );
1341  $d = $this->optionToString( $defaults[$option] );
1342  if ( $v !== $d ) {
1343  $values[] = "$option=$v";
1344  }
1345  }
1346 
1347  $confstr = $values ? implode( '!', $values ) : 'canonical';
1348 
1349  // add in language specific options, if any
1350  // @todo FIXME: This is just a way of retrieving the url/user preferred variant
1351 
1352  $lang = $title ? $title->getPageLanguage() :
1353  MediaWikiServices::getInstance()->getContentLanguage();
1354  $converter = MediaWikiServices::getInstance()->getLanguageConverterFactory()
1355  ->getLanguageConverter( $lang );
1356  $confstr .= $converter->getExtraHashOptions();
1357 
1358  $confstr .= $wgRenderHashAppend;
1359 
1360  if ( $this->mExtraKey != '' ) {
1361  $confstr .= $this->mExtraKey;
1362  }
1363 
1364  // Give a chance for extensions to modify the hash, if they have
1365  // extra options or other effects on the parser cache.
1366  Hooks::run( 'PageRenderingHash', [ &$confstr, $this->getUser(), &$forOptions ] );
1367 
1368  // Make it a valid memcached key fragment
1369  $confstr = str_replace( ' ', '_', $confstr );
1370 
1371  return $confstr;
1372  }
1373 
1379  public function isSafeToCache() {
1381  foreach ( $this->options as $option => $value ) {
1382  if ( empty( self::$inCacheKey[$option] ) ) {
1383  $v = $this->optionToString( $value );
1384  $d = $this->optionToString( $defaults[$option] );
1385  if ( $v !== $d ) {
1386  return false;
1387  }
1388  }
1389  }
1390  return true;
1391  }
1392 
1403  public function setupFakeRevision( $title, $content, $user ) {
1404  $oldCallback = $this->setCurrentRevisionCallback(
1405  function (
1406  $titleToCheck, $parser = false ) use ( $title, $content, $user, &$oldCallback
1407  ) {
1408  if ( $titleToCheck->equals( $title ) ) {
1409  return new Revision( [
1410  'page' => $title->getArticleID(),
1411  'user_text' => $user->getName(),
1412  'user' => $user->getId(),
1413  'parent_id' => $title->getLatestRevID(),
1414  'title' => $title,
1415  'content' => $content
1416  ] );
1417  } else {
1418  return call_user_func( $oldCallback, $titleToCheck, $parser );
1419  }
1420  }
1421  );
1422 
1423  global $wgHooks;
1424  $wgHooks['TitleExists'][] =
1425  function ( $titleToCheck, &$exists ) use ( $title ) {
1426  if ( $titleToCheck->equals( $title ) ) {
1427  $exists = true;
1428  }
1429  };
1430  end( $wgHooks['TitleExists'] );
1431  $key = key( $wgHooks['TitleExists'] );
1432  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1433  $linkCache->clearBadLink( $title->getPrefixedDBkey() );
1434  return new ScopedCallback( function () use ( $title, $key, $linkCache ) {
1435  global $wgHooks;
1436  unset( $wgHooks['TitleExists'][$key] );
1437  $linkCache->clearLink( $title );
1438  } );
1439  }
1440 }
1441 
User\getDefaultOption
static getDefaultOption( $opt)
Get a given default option value.
Definition: User.php:1748
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:719
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:767
ParserOptions\getExpensiveParserFunctionLimit
getExpensiveParserFunctionLimit()
Maximum number of calls per parse to expensive parser functions.
Definition: ParserOptions.php:407
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:582
$wgMaxArticleSize
$wgMaxArticleSize
Maximum article size in kilobytes.
Definition: DefaultSettings.php:2330
ParserOptions\getRemoveComments
getRemoveComments()
Remove HTML comments.
Definition: ParserOptions.php:426
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:758
ParserOptions\disableContentConversion
disableContentConversion( $x=true)
Whether content conversion should be disabled.
Definition: ParserOptions.php:506
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:134
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:35
ParserOptions\initialiseFromUser
initialiseFromUser( $user, $lang)
Get user options.
Definition: ParserOptions.php:1173
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:1608
$wgMaxTemplateDepth
$wgMaxTemplateDepth
Maximum recursion depth for templates within templates.
Definition: DefaultSettings.php:4175
ParserOptions\getIsPreview
getIsPreview()
Parsing the page for a "preview" operation?
Definition: ParserOptions.php:565
ParserOptions\getDisableTitleConversion
getDisableTitleConversion()
Whether title conversion should be disabled.
Definition: ParserOptions.php:514
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:820
ParserOptions\setIsPreview
setIsPreview( $x)
Parsing the page for a "preview" operation?
Definition: ParserOptions.php:574
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:591
ParserOptions\getSpeculativeRevId
getSpeculativeRevId()
A guess for {{REVISIONID}}, calculated using the callback provided via setSpeculativeRevIdCallback().
Definition: ParserOptions.php:834
ParserOptions\newFromAnon
static newFromAnon()
Get a ParserOptions object for an anonymous user.
Definition: ParserOptions.php:996
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:3143
ParserOptions\setWrapOutputClass
setWrapOutputClass( $className)
CSS class to use to wrap output from Parser::parse()
Definition: ParserOptions.php:778
ParserOptions\setSpeculativeRevIdCallback
setSpeculativeRevIdCallback( $x)
Callback to generate a guess for {{REVISIONID}}.
Definition: ParserOptions.php:886
ParserOptions\disableTitleConversion
disableTitleConversion( $x=true)
Whether title conversion should be disabled.
Definition: ParserOptions.php:523
ParserOptions\initDateFormat
static initDateFormat(ParserOptions $popt)
Lazy initializer for dateFormat.
Definition: ParserOptions.php:642
ParserOptions\getIsPrintable
getIsPrintable()
Parsing the printable version of the page?
Definition: ParserOptions.php:599
ParserOptions\setCurrentRevisionCallback
setCurrentRevisionCallback( $x)
Callback for current revision fetching; first argument to call_user_func().
Definition: ParserOptions.php:803
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:398
ParserOptions\getMagicRFCLinks
getMagicRFCLinks()
Are magic RFC links enabled?
Definition: ParserOptions.php:728
ParserOptions\getUserLangObj
getUserLangObj()
Get the user language used by the parser for this page and split the parser cache.
Definition: ParserOptions.php:672
ParserOptions\registerWatcher
registerWatcher( $callback)
Registers a callback for tracking which ParserOptions which are used.
Definition: ParserOptions.php:1254
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:1403
ParserOptions\getDateFormat
getDateFormat()
Date format index.
Definition: ParserOptions.php:633
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:858
ParserOptions\setNumberHeadings
setNumberHeadings( $x)
Automatically number headings?
Definition: ParserOptions.php:271
$wgHooks
$wgHooks
Global list of hooks.
Definition: DefaultSettings.php:7485
ParserOptions\getCanonicalOverrides
static getCanonicalOverrides()
Get "canonical" non-default option values.
Definition: ParserOptions.php:1159
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1045
ParserOptions\getRedirectTarget
getRedirectTarget()
Get the previously-set redirect target.
Definition: ParserOptions.php:942
ParserOptions\newFromUserAndLang
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
Definition: ParserOptions.php:1023
ParserOptions\setUserLang
setUserLang( $x)
Set the user language used by the parser for this page and split the parser cache.
Definition: ParserOptions.php:697
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:4221
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:852
$wgExpensiveParserFunctionLimit
$wgExpensiveParserFunctionLimit
Maximum number of calls per parse to expensive parser functions such as PAGESINCATEGORY.
Definition: DefaultSettings.php:4330
ParserOptions\setThumbSize
setThumbSize( $x)
Thumb size preferred by the user.
Definition: ParserOptions.php:540
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:3011
ParserOptions\setExternalLinkTarget
setExternalLinkTarget( $x)
Target attribute for external links.
Definition: ParserOptions.php:489
ParserOptions\setDateFormat
setDateFormat( $x)
Date format index.
Definition: ParserOptions.php:651
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:872
ParserOptions\setAllowSpecialInclusion
setAllowSpecialInclusion( $x)
Allow inclusion of special pages?
Definition: ParserOptions.php:288
$wgMaxPPExpandDepth
$wgMaxPPExpandDepth
Definition: DefaultSettings.php:4180
ParserOptions\getDefaults
static getDefaults()
Get default option values.
Definition: ParserOptions.php:1084
ParserOptions\getExternalLinkTarget
getExternalLinkTarget()
Target attribute for external links.
Definition: ParserOptions.php:480
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:4355
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1902
ParserOptions\getStubThreshold
getStubThreshold()
Thumb size preferred by the user.
Definition: ParserOptions.php:548
$wgExternalLinkTarget
$wgExternalLinkTarget
Set a default target for external links, e.g.
Definition: DefaultSettings.php:4283
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:688
$wgDisableLangConversion
$wgDisableLangConversion
Whether to enable language variant conversion.
Definition: DefaultSettings.php:3138
ParserOptions\getPreSaveTransform
getPreSaveTransform()
Transform wiki markup when saving the page?
Definition: ParserOptions.php:616
ParserOptions\setStubThreshold
setStubThreshold( $x)
Thumb size preferred by the user.
Definition: ParserOptions.php:557
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:746
ParserOptions\getDisableContentConversion
getDisableContentConversion()
Whether content conversion should be disabled.
Definition: ParserOptions.php:497
ParserOptions\optionToString
optionToString( $value)
Convert an option to a string value.
Definition: ParserOptions.php:1291
ParserOptions\matchesForCacheKey
matchesForCacheKey(ParserOptions $other)
Definition: ParserOptions.php:1233
ParserOptions\optionUsed
optionUsed( $optionName)
Called when an option is accessed.
Definition: ParserOptions.php:1266
$content
$content
Definition: router.php:78
ParserOptions\getSpeculativePageId
getSpeculativePageId()
A guess for {{PAGEID}}, calculated using the callback provided via setSpeculativeRevPageCallback().
Definition: ParserOptions.php:848
ParserOptions\setTimestamp
setTimestamp( $x)
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:918
ParserOptions\setSpeculativePageIdCallback
setSpeculativePageIdCallback( $x)
Callback to generate a guess for {{PAGEID}}.
Definition: ParserOptions.php:897
ParserOptions\setCleanSignatures
setCleanSignatures( $x)
Clean up signature texts?
Definition: ParserOptions.php:472
ParserOptions\newFromContext
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
Definition: ParserOptions.php:1035
ParserOptions\getCurrentRevisionCallback
getCurrentRevisionCallback()
Callback for current revision fetching; first argument to call_user_func().
Definition: ParserOptions.php:793
$wgEnableParserLimitReporting
$wgEnableParserLimitReporting
Whether to include the NewPP limit report as a HTML comment.
Definition: DefaultSettings.php:7365
ParserOptions\getTemplateCallback
getTemplateCallback()
Callback for template fetching; first argument to call_user_func().
Definition: ParserOptions.php:811
ParserOptions\newCanonical
static newCanonical( $context=null, $userLang=null)
Creates a "canonical" ParserOptions object.
Definition: ParserOptions.php:1056
ParserOptions\setRemoveComments
setRemoveComments( $x)
Remove HTML comments.
Definition: ParserOptions.php:436
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:932
ParserOptions\setExpensiveParserFunctionLimit
setExpensiveParserFunctionLimit( $x)
Maximum number of calls per parse to expensive parser functions.
Definition: ParserOptions.php:417
ParserOptions\getTimestamp
getTimestamp()
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:906
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:462
$context
$context
Definition: load.php:43
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:1192
ParserOptions\enableLimitReport
enableLimitReport( $x=true)
Enable limit report in an HTML comment on output.
Definition: ParserOptions.php:453
Title
Represents a title within MediaWiki.
Definition: Title.php:42
ParserOptions\__construct
__construct( $user=null, $lang=null)
Definition: ParserOptions.php:970
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:1277
$wgCleanSignatures
$wgCleanSignatures
If true, removes (by substituting) templates in signatures.
Definition: DefaultSettings.php:4202
ParserOptions\getUser
getUser()
Current user.
Definition: ParserOptions.php:960
ParserOptions\getThumbSize
getThumbSize()
Thumb size preferred by the user.
Definition: ParserOptions.php:531
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:710
ParserOptions\setIsPrintable
setIsPrintable( $x)
Parsing the printable version of the page?
Definition: ParserOptions.php:608
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:2706
ParserOptions\getMaxPPExpandDepth
getMaxPPExpandDepth()
Maximum recursion depth in PPFrame::expand()
Definition: ParserOptions.php:381
ParserOptions\getEnableLimitReport
getEnableLimitReport()
Enable limit report in an HTML comment on output.
Definition: ParserOptions.php:444
ParserOptions\getNumberHeadings
getNumberHeadings()
Automatically number headings?
Definition: ParserOptions.php:262
ParserOptions\isSafeToCache
isSafeToCache()
Test whether these options are safe to cache.
Definition: ParserOptions.php:1379
ParserOptions\getMaxTemplateDepth
getMaxTemplateDepth()
Maximum recursion depth for templates within templates.
Definition: ParserOptions.php:389
ParserOptions\setPreSaveTransform
setPreSaveTransform( $x)
Transform wiki markup when saving the page?
Definition: ParserOptions.php:625
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:52
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:4167
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
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:1319
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:1010
$wgAllowExternalImages
$wgAllowExternalImages
Whether to allow inline image pointing to other websites.
Definition: DefaultSettings.php:4207
$wgEnableImageWhitelist
$wgEnableImageWhitelist
If $wgAllowExternalImages is false, you can allow an on-wiki whitelist of regular expression fragment...
Definition: DefaultSettings.php:4234
ParserOptions\addExtraKey
addExtraKey( $key)
Extra key that should be present in the parser cache key.
Definition: ParserOptions.php:952
$wgAllowSpecialInclusion
$wgAllowSpecialInclusion
Allow special page inclusions such as {{Special:Allpages}}.
Definition: DefaultSettings.php:7925