MediaWiki  1.31.0
ParserOptions.php
Go to the documentation of this file.
1 <?php
23 use Wikimedia\ScopedCallback;
24 
41 
47  private static $defaults = null;
48 
53  private static $lazyOptions = [
54  'dateformat' => [ __CLASS__, 'initDateFormat' ],
55  ];
56 
61  private static $inCacheKey = [
62  'dateformat' => true,
63  'numberheadings' => true,
64  'thumbsize' => true,
65  'stubthreshold' => true,
66  'printable' => true,
67  'userlang' => true,
68  ];
69 
74  private $options;
75 
81  private $mTimestamp;
82 
88  private $mUser;
89 
95  private $onAccessCallback = null;
96 
103  private $redirectTarget = null;
104 
108  private $mExtraKey = '';
109 
121  public function getOption( $name ) {
122  if ( !array_key_exists( $name, $this->options ) ) {
123  throw new InvalidArgumentException( "Unknown parser option $name" );
124  }
125 
126  if ( isset( self::$lazyOptions[$name] ) && $this->options[$name] === null ) {
127  $this->options[$name] = call_user_func( self::$lazyOptions[$name], $this, $name );
128  }
129  if ( !empty( self::$inCacheKey[$name] ) ) {
130  $this->optionUsed( $name );
131  }
132  return $this->options[$name];
133  }
134 
143  public function setOption( $name, $value ) {
144  if ( !array_key_exists( $name, $this->options ) ) {
145  throw new InvalidArgumentException( "Unknown parser option $name" );
146  }
147  $old = $this->options[$name];
148  $this->options[$name] = $value;
149  return $old;
150  }
151 
160  protected function setOptionLegacy( $name, $value ) {
161  if ( !array_key_exists( $name, $this->options ) ) {
162  throw new InvalidArgumentException( "Unknown parser option $name" );
163  }
164  return wfSetVar( $this->options[$name], $value );
165  }
166 
175  public function getInterwikiMagic() {
176  return $this->getOption( 'interwikiMagic' );
177  }
178 
184  public function setInterwikiMagic( $x ) {
185  return $this->setOptionLegacy( 'interwikiMagic', $x );
186  }
187 
192  public function getAllowExternalImages() {
193  return $this->getOption( 'allowExternalImages' );
194  }
195 
201  public function setAllowExternalImages( $x ) {
202  return $this->setOptionLegacy( 'allowExternalImages', $x );
203  }
204 
212  public function getAllowExternalImagesFrom() {
213  return $this->getOption( 'allowExternalImagesFrom' );
214  }
215 
224  public function setAllowExternalImagesFrom( $x ) {
225  return $this->setOptionLegacy( 'allowExternalImagesFrom', $x );
226  }
227 
232  public function getEnableImageWhitelist() {
233  return $this->getOption( 'enableImageWhitelist' );
234  }
235 
241  public function setEnableImageWhitelist( $x ) {
242  return $this->setOptionLegacy( 'enableImageWhitelist', $x );
243  }
244 
249  public function getNumberHeadings() {
250  return $this->getOption( 'numberheadings' );
251  }
252 
258  public function setNumberHeadings( $x ) {
259  return $this->setOptionLegacy( 'numberheadings', $x );
260  }
261 
266  public function getAllowSpecialInclusion() {
267  return $this->getOption( 'allowSpecialInclusion' );
268  }
269 
275  public function setAllowSpecialInclusion( $x ) {
276  return $this->setOptionLegacy( 'allowSpecialInclusion', $x );
277  }
278 
283  public function getTidy() {
284  return $this->getOption( 'tidy' );
285  }
286 
292  public function setTidy( $x ) {
293  return $this->setOptionLegacy( 'tidy', $x );
294  }
295 
300  public function getInterfaceMessage() {
301  return $this->getOption( 'interfaceMessage' );
302  }
303 
309  public function setInterfaceMessage( $x ) {
310  return $this->setOptionLegacy( 'interfaceMessage', $x );
311  }
312 
317  public function getTargetLanguage() {
318  return $this->getOption( 'targetLanguage' );
319  }
320 
326  public function setTargetLanguage( $x ) {
327  return $this->setOption( 'targetLanguage', $x );
328  }
329 
334  public function getMaxIncludeSize() {
335  return $this->getOption( 'maxIncludeSize' );
336  }
337 
343  public function setMaxIncludeSize( $x ) {
344  return $this->setOptionLegacy( 'maxIncludeSize', $x );
345  }
346 
351  public function getMaxPPNodeCount() {
352  return $this->getOption( 'maxPPNodeCount' );
353  }
354 
360  public function setMaxPPNodeCount( $x ) {
361  return $this->setOptionLegacy( 'maxPPNodeCount', $x );
362  }
363 
368  public function getMaxGeneratedPPNodeCount() {
369  return $this->getOption( 'maxGeneratedPPNodeCount' );
370  }
371 
377  public function setMaxGeneratedPPNodeCount( $x ) {
378  return $this->setOptionLegacy( 'maxGeneratedPPNodeCount', $x );
379  }
380 
385  public function getMaxPPExpandDepth() {
386  return $this->getOption( 'maxPPExpandDepth' );
387  }
388 
393  public function getMaxTemplateDepth() {
394  return $this->getOption( 'maxTemplateDepth' );
395  }
396 
402  public function setMaxTemplateDepth( $x ) {
403  return $this->setOptionLegacy( 'maxTemplateDepth', $x );
404  }
405 
412  return $this->getOption( 'expensiveParserFunctionLimit' );
413  }
414 
421  public function setExpensiveParserFunctionLimit( $x ) {
422  return $this->setOptionLegacy( 'expensiveParserFunctionLimit', $x );
423  }
424 
430  public function getRemoveComments() {
431  return $this->getOption( 'removeComments' );
432  }
433 
440  public function setRemoveComments( $x ) {
441  return $this->setOptionLegacy( 'removeComments', $x );
442  }
443 
448  public function getEnableLimitReport() {
449  return $this->getOption( 'enableLimitReport' );
450  }
451 
457  public function enableLimitReport( $x = true ) {
458  return $this->setOptionLegacy( 'enableLimitReport', $x );
459  }
460 
466  public function getCleanSignatures() {
467  return $this->getOption( 'cleanSignatures' );
468  }
469 
476  public function setCleanSignatures( $x ) {
477  return $this->setOptionLegacy( 'cleanSignatures', $x );
478  }
479 
484  public function getExternalLinkTarget() {
485  return $this->getOption( 'externalLinkTarget' );
486  }
487 
493  public function setExternalLinkTarget( $x ) {
494  return $this->setOptionLegacy( 'externalLinkTarget', $x );
495  }
496 
501  public function getDisableContentConversion() {
502  return $this->getOption( 'disableContentConversion' );
503  }
504 
510  public function disableContentConversion( $x = true ) {
511  return $this->setOptionLegacy( 'disableContentConversion', $x );
512  }
513 
518  public function getDisableTitleConversion() {
519  return $this->getOption( 'disableTitleConversion' );
520  }
521 
527  public function disableTitleConversion( $x = true ) {
528  return $this->setOptionLegacy( 'disableTitleConversion', $x );
529  }
530 
535  public function getThumbSize() {
536  return $this->getOption( 'thumbsize' );
537  }
538 
544  public function setThumbSize( $x ) {
545  return $this->setOptionLegacy( 'thumbsize', $x );
546  }
547 
552  public function getStubThreshold() {
553  return $this->getOption( 'stubthreshold' );
554  }
555 
561  public function setStubThreshold( $x ) {
562  return $this->setOptionLegacy( 'stubthreshold', $x );
563  }
564 
569  public function getIsPreview() {
570  return $this->getOption( 'isPreview' );
571  }
572 
578  public function setIsPreview( $x ) {
579  return $this->setOptionLegacy( 'isPreview', $x );
580  }
581 
586  public function getIsSectionPreview() {
587  return $this->getOption( 'isSectionPreview' );
588  }
589 
595  public function setIsSectionPreview( $x ) {
596  return $this->setOptionLegacy( 'isSectionPreview', $x );
597  }
598 
603  public function getIsPrintable() {
604  return $this->getOption( 'printable' );
605  }
606 
612  public function setIsPrintable( $x ) {
613  return $this->setOptionLegacy( 'printable', $x );
614  }
615 
620  public function getPreSaveTransform() {
621  return $this->getOption( 'preSaveTransform' );
622  }
623 
629  public function setPreSaveTransform( $x ) {
630  return $this->setOptionLegacy( 'preSaveTransform', $x );
631  }
632 
637  public function getDateFormat() {
638  return $this->getOption( 'dateformat' );
639  }
640 
644  private static function initDateFormat( $popt ) {
645  return $popt->mUser->getDatePreference();
646  }
647 
653  public function setDateFormat( $x ) {
654  return $this->setOptionLegacy( 'dateformat', $x );
655  }
656 
674  public function getUserLangObj() {
675  return $this->getOption( 'userlang' );
676  }
677 
690  public function getUserLang() {
691  return $this->getUserLangObj()->getCode();
692  }
693 
699  public function setUserLang( $x ) {
700  if ( is_string( $x ) ) {
701  $x = Language::factory( $x );
702  }
703 
704  return $this->setOptionLegacy( 'userlang', $x );
705  }
706 
712  public function getMagicISBNLinks() {
713  return $this->getOption( 'magicISBNLinks' );
714  }
715 
721  public function getMagicPMIDLinks() {
722  return $this->getOption( 'magicPMIDLinks' );
723  }
729  public function getMagicRFCLinks() {
730  return $this->getOption( 'magicRFCLinks' );
731  }
732 
747  public function getAllowUnsafeRawHtml() {
748  return $this->getOption( 'allowUnsafeRawHtml' );
749  }
750 
759  public function setAllowUnsafeRawHtml( $x ) {
760  return $this->setOptionLegacy( 'allowUnsafeRawHtml', $x );
761  }
762 
768  public function getWrapOutputClass() {
769  return $this->getOption( 'wrapclass' );
770  }
771 
779  public function setWrapOutputClass( $className ) {
780  if ( $className === true ) { // DWIM, they probably want the default class name
781  $className = 'mw-parser-output';
782  }
783  if ( $className === false ) {
784  wfDeprecated( __METHOD__ . '( false )', '1.31' );
785  }
786  return $this->setOption( 'wrapclass', $className );
787  }
788 
794  public function getCurrentRevisionCallback() {
795  return $this->getOption( 'currentRevisionCallback' );
796  }
797 
804  public function setCurrentRevisionCallback( $x ) {
805  return $this->setOptionLegacy( 'currentRevisionCallback', $x );
806  }
807 
812  public function getTemplateCallback() {
813  return $this->getOption( 'templateCallback' );
814  }
815 
821  public function setTemplateCallback( $x ) {
822  return $this->setOptionLegacy( 'templateCallback', $x );
823  }
824 
830  public function getSpeculativeRevIdCallback() {
831  return $this->getOption( 'speculativeRevIdCallback' );
832  }
833 
840  public function setSpeculativeRevIdCallback( $x ) {
841  return $this->setOptionLegacy( 'speculativeRevIdCallback', $x );
842  }
843 
850  public function getTimestamp() {
851  if ( !isset( $this->mTimestamp ) ) {
852  $this->mTimestamp = wfTimestampNow();
853  }
854  return $this->mTimestamp;
855  }
856 
862  public function setTimestamp( $x ) {
863  return wfSetVar( $this->mTimestamp, $x );
864  }
865 
871  public function getEditSection() {
872  wfDeprecated( __METHOD__, '1.31' );
873  return true;
874  }
875 
882  public function setEditSection( $x ) {
883  wfDeprecated( __METHOD__, '1.31' );
884  return true;
885  }
886 
897  function setRedirectTarget( $title ) {
898  $this->redirectTarget = $title;
899  }
900 
907  function getRedirectTarget() {
908  return $this->redirectTarget;
909  }
910 
917  public function addExtraKey( $key ) {
918  $this->mExtraKey .= '!' . $key;
919  }
920 
925  public function getUser() {
926  return $this->mUser;
927  }
928 
936  public function __construct( $user = null, $lang = null ) {
937  if ( $user === null ) {
938  global $wgUser;
939  if ( $wgUser === null ) {
940  $user = new User;
941  } else {
942  $user = $wgUser;
943  }
944  }
945  if ( $lang === null ) {
946  global $wgLang;
947  if ( !StubObject::isRealObject( $wgLang ) ) {
948  $wgLang->_unstub();
949  }
950  $lang = $wgLang;
951  }
952  $this->initialiseFromUser( $user, $lang );
953  }
954 
963  public static function newFromAnon() {
965  return new ParserOptions( new User, $wgContLang );
966  }
967 
978  public static function newFromUser( $user ) {
979  return new ParserOptions( $user );
980  }
981 
992  public static function newFromUserAndLang( User $user, Language $lang ) {
993  return new ParserOptions( $user, $lang );
994  }
995 
1005  public static function newFromContext( IContextSource $context ) {
1006  return new ParserOptions( $context->getUser(), $context->getLanguage() );
1007  }
1008 
1020  public static function newCanonical( User $user = null, $lang = null ) {
1021  $ret = new ParserOptions( $user, $lang );
1022  foreach ( self::getCanonicalOverrides() as $k => $v ) {
1023  $ret->setOption( $k, $v );
1024  }
1025  return $ret;
1026  }
1027 
1037  private static function getDefaults() {
1044 
1045  if ( self::$defaults === null ) {
1046  // *UPDATE* ParserOptions::matches() if any of this changes as needed
1047  self::$defaults = [
1048  'dateformat' => null,
1049  'tidy' => false,
1050  'interfaceMessage' => false,
1051  'targetLanguage' => null,
1052  'removeComments' => true,
1053  'enableLimitReport' => false,
1054  'preSaveTransform' => true,
1055  'isPreview' => false,
1056  'isSectionPreview' => false,
1057  'printable' => false,
1058  'allowUnsafeRawHtml' => true,
1059  'wrapclass' => 'mw-parser-output',
1060  'currentRevisionCallback' => [ Parser::class, 'statelessFetchRevision' ],
1061  'templateCallback' => [ Parser::class, 'statelessFetchTemplate' ],
1062  'speculativeRevIdCallback' => null,
1063  ];
1064 
1065  Hooks::run( 'ParserOptionsRegister', [
1066  &self::$defaults,
1067  &self::$inCacheKey,
1068  &self::$lazyOptions,
1069  ] );
1070 
1071  ksort( self::$inCacheKey );
1072  }
1073 
1074  // Unit tests depend on being able to modify the globals at will
1075  return self::$defaults + [
1076  'interwikiMagic' => $wgInterwikiMagic,
1077  'allowExternalImages' => $wgAllowExternalImages,
1078  'allowExternalImagesFrom' => $wgAllowExternalImagesFrom,
1079  'enableImageWhitelist' => $wgEnableImageWhitelist,
1080  'allowSpecialInclusion' => $wgAllowSpecialInclusion,
1081  'maxIncludeSize' => $wgMaxArticleSize * 1024,
1082  'maxPPNodeCount' => $wgMaxPPNodeCount,
1083  'maxGeneratedPPNodeCount' => $wgMaxGeneratedPPNodeCount,
1084  'maxPPExpandDepth' => $wgMaxPPExpandDepth,
1085  'maxTemplateDepth' => $wgMaxTemplateDepth,
1086  'expensiveParserFunctionLimit' => $wgExpensiveParserFunctionLimit,
1087  'externalLinkTarget' => $wgExternalLinkTarget,
1088  'cleanSignatures' => $wgCleanSignatures,
1089  'disableContentConversion' => $wgDisableLangConversion,
1090  'disableTitleConversion' => $wgDisableLangConversion || $wgDisableTitleConversion,
1091  'magicISBNLinks' => $wgEnableMagicLinks['ISBN'],
1092  'magicPMIDLinks' => $wgEnableMagicLinks['PMID'],
1093  'magicRFCLinks' => $wgEnableMagicLinks['RFC'],
1094  'numberheadings' => User::getDefaultOption( 'numberheadings' ),
1095  'thumbsize' => User::getDefaultOption( 'thumbsize' ),
1096  'stubthreshold' => 0,
1097  'userlang' => $wgContLang,
1098  ];
1099  }
1100 
1110  private static function getCanonicalOverrides() {
1112 
1113  return [
1114  'tidy' => true,
1115  'enableLimitReport' => $wgEnableParserLimitReporting,
1116  ];
1117  }
1118 
1125  private function initialiseFromUser( $user, $lang ) {
1126  $this->options = self::getDefaults();
1127 
1128  $this->mUser = $user;
1129  $this->options['numberheadings'] = $user->getOption( 'numberheadings' );
1130  $this->options['thumbsize'] = $user->getOption( 'thumbsize' );
1131  $this->options['stubthreshold'] = $user->getStubThreshold();
1132  $this->options['userlang'] = $lang;
1133  }
1134 
1144  public function matches( ParserOptions $other ) {
1145  // Populate lazy options
1146  foreach ( self::$lazyOptions as $name => $callback ) {
1147  if ( $this->options[$name] === null ) {
1148  $this->options[$name] = call_user_func( $callback, $this, $name );
1149  }
1150  if ( $other->options[$name] === null ) {
1151  $other->options[$name] = call_user_func( $callback, $other, $name );
1152  }
1153  }
1154 
1155  // Compare most options
1156  $options = array_keys( $this->options );
1157  $options = array_diff( $options, [
1158  'enableLimitReport', // only affects HTML comments
1159  ] );
1160  foreach ( $options as $option ) {
1161  $o1 = $this->optionToString( $this->options[$option] );
1162  $o2 = $this->optionToString( $other->options[$option] );
1163  if ( $o1 !== $o2 ) {
1164  return false;
1165  }
1166  }
1167 
1168  // Compare most other fields
1169  $fields = array_keys( get_class_vars( __CLASS__ ) );
1170  $fields = array_diff( $fields, [
1171  'defaults', // static
1172  'lazyOptions', // static
1173  'inCacheKey', // static
1174  'options', // Already checked above
1175  'onAccessCallback', // only used for ParserOutput option tracking
1176  ] );
1177  foreach ( $fields as $field ) {
1178  if ( !is_object( $this->$field ) && $this->$field !== $other->$field ) {
1179  return false;
1180  }
1181  }
1182 
1183  return true;
1184  }
1185 
1191  public function registerWatcher( $callback ) {
1192  $this->onAccessCallback = $callback;
1193  }
1194 
1203  public function optionUsed( $optionName ) {
1204  if ( $this->onAccessCallback ) {
1205  call_user_func( $this->onAccessCallback, $optionName );
1206  }
1207  }
1208 
1216  public static function legacyOptions() {
1217  wfDeprecated( __METHOD__, '1.30' );
1218  return [
1219  'stubthreshold',
1220  'numberheadings',
1221  'userlang',
1222  'thumbsize',
1223  'editsection',
1224  'printable'
1225  ];
1226  }
1227 
1233  public static function allCacheVaryingOptions() {
1234  // Trigger a call to the 'ParserOptionsRegister' hook if it hasn't
1235  // already been called.
1236  if ( self::$defaults === null ) {
1238  }
1239  return array_keys( array_filter( self::$inCacheKey ) );
1240  }
1241 
1247  private function optionToString( $value ) {
1248  if ( $value === true ) {
1249  return '1';
1250  } elseif ( $value === false ) {
1251  return '0';
1252  } elseif ( $value === null ) {
1253  return '';
1254  } elseif ( $value instanceof Language ) {
1255  return $value->getCode();
1256  } elseif ( is_array( $value ) ) {
1257  return '[' . implode( ',', array_map( [ $this, 'optionToString' ], $value ) ) . ']';
1258  } else {
1259  return (string)$value;
1260  }
1261  }
1262 
1275  public function optionsHash( $forOptions, $title = null ) {
1277 
1281 
1282  // We only include used options with non-canonical values in the key
1283  // so adding a new option doesn't invalidate the entire parser cache.
1284  // The drawback to this is that changing the default value of an option
1285  // requires manual invalidation of existing cache entries, as mentioned
1286  // in the docs on the relevant methods and hooks.
1287  $values = [];
1288  foreach ( $inCacheKey as $option => $include ) {
1289  if ( $include && in_array( $option, $forOptions, true ) ) {
1290  $v = $this->optionToString( $options[$option] );
1291  $d = $this->optionToString( $defaults[$option] );
1292  if ( $v !== $d ) {
1293  $values[] = "$option=$v";
1294  }
1295  }
1296  }
1297 
1298  $confstr = $values ? implode( '!', $values ) : 'canonical';
1299 
1300  // add in language specific options, if any
1301  // @todo FIXME: This is just a way of retrieving the url/user preferred variant
1302  if ( !is_null( $title ) ) {
1303  $confstr .= $title->getPageLanguage()->getExtraHashOptions();
1304  } else {
1306  $confstr .= $wgContLang->getExtraHashOptions();
1307  }
1308 
1309  $confstr .= $wgRenderHashAppend;
1310 
1311  if ( $this->mExtraKey != '' ) {
1312  $confstr .= $this->mExtraKey;
1313  }
1314 
1315  // Give a chance for extensions to modify the hash, if they have
1316  // extra options or other effects on the parser cache.
1317  Hooks::run( 'PageRenderingHash', [ &$confstr, $this->getUser(), &$forOptions ] );
1318 
1319  // Make it a valid memcached key fragment
1320  $confstr = str_replace( ' ', '_', $confstr );
1321 
1322  return $confstr;
1323  }
1324 
1330  public function isSafeToCache() {
1332  foreach ( $this->options as $option => $value ) {
1333  if ( empty( self::$inCacheKey[$option] ) ) {
1334  $v = $this->optionToString( $value );
1335  $d = $this->optionToString( $defaults[$option] );
1336  if ( $v !== $d ) {
1337  return false;
1338  }
1339  }
1340  }
1341  return true;
1342  }
1343 
1354  public function setupFakeRevision( $title, $content, $user ) {
1355  $oldCallback = $this->setCurrentRevisionCallback(
1356  function (
1357  $titleToCheck, $parser = false ) use ( $title, $content, $user, &$oldCallback
1358  ) {
1359  if ( $titleToCheck->equals( $title ) ) {
1360  return new Revision( [
1361  'page' => $title->getArticleID(),
1362  'user_text' => $user->getName(),
1363  'user' => $user->getId(),
1364  'parent_id' => $title->getLatestRevID(),
1365  'title' => $title,
1366  'content' => $content
1367  ] );
1368  } else {
1369  return call_user_func( $oldCallback, $titleToCheck, $parser );
1370  }
1371  }
1372  );
1373 
1374  global $wgHooks;
1375  $wgHooks['TitleExists'][] =
1376  function ( $titleToCheck, &$exists ) use ( $title ) {
1377  if ( $titleToCheck->equals( $title ) ) {
1378  $exists = true;
1379  }
1380  };
1381  end( $wgHooks['TitleExists'] );
1382  $key = key( $wgHooks['TitleExists'] );
1383  LinkCache::singleton()->clearBadLink( $title->getPrefixedDBkey() );
1384  return new ScopedCallback( function () use ( $title, $key ) {
1385  global $wgHooks;
1386  unset( $wgHooks['TitleExists'][$key] );
1387  LinkCache::singleton()->clearLink( $title );
1388  } );
1389  }
1390 }
1391 
User\getDefaultOption
static getDefaultOption( $opt)
Get a given default option value.
Definition: User.php:1762
ParserOptions\setMaxIncludeSize
setMaxIncludeSize( $x)
Maximum size of template expansions, in bytes.
Definition: ParserOptions.php:343
ParserOptions\getMagicPMIDLinks
getMagicPMIDLinks()
Are magic PMID links enabled?
Definition: ParserOptions.php:721
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:40
ParserOptions\setOptionLegacy
setOptionLegacy( $name, $value)
Legacy implementation.
Definition: ParserOptions.php:160
ParserOptions\getAllowExternalImagesFrom
getAllowExternalImagesFrom()
External images to allow.
Definition: ParserOptions.php:212
$user
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 account $user
Definition: hooks.txt:244
$wgUser
$wgUser
Definition: Setup.php:894
ParserOptions\getWrapOutputClass
getWrapOutputClass()
Class to use to wrap output from Parser::parse()
Definition: ParserOptions.php:768
ParserOptions\getExpensiveParserFunctionLimit
getExpensiveParserFunctionLimit()
Maximum number of calls per parse to expensive parser functions.
Definition: ParserOptions.php:411
ParserOptions\setTidy
setTidy( $x)
Use tidy to cleanup output HTML?
Definition: ParserOptions.php:292
ParserOptions\getIsSectionPreview
getIsSectionPreview()
Parsing the page for a "preview" operation on a single section?
Definition: ParserOptions.php:586
$wgMaxArticleSize
$wgMaxArticleSize
Maximum article size in kilobytes.
Definition: DefaultSettings.php:2200
$context
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2604
ParserOptions\getRemoveComments
getRemoveComments()
Remove HTML comments.
Definition: ParserOptions.php:430
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:759
ParserOptions\disableContentConversion
disableContentConversion( $x=true)
Whether content conversion should be disabled.
Definition: ParserOptions.php:510
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
ParserOptions\initialiseFromUser
initialiseFromUser( $user, $lang)
Get user options.
Definition: ParserOptions.php:1125
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:1687
$wgMaxTemplateDepth
$wgMaxTemplateDepth
Maximum recursion depth for templates within templates.
Definition: DefaultSettings.php:4182
ParserOptions\getIsPreview
getIsPreview()
Parsing the page for a "preview" operation?
Definition: ParserOptions.php:569
ParserOptions\getDisableTitleConversion
getDisableTitleConversion()
Whether title conversion should be disabled.
Definition: ParserOptions.php:518
ParserOptions\setAllowExternalImages
setAllowExternalImages( $x)
Allow all external images inline?
Definition: ParserOptions.php:201
ParserOptions\setTemplateCallback
setTemplateCallback( $x)
Callback for template fetching; first argument to call_user_func().
Definition: ParserOptions.php:821
ParserOptions\setIsPreview
setIsPreview( $x)
Parsing the page for a "preview" operation?
Definition: ParserOptions.php:578
ParserOptions\setTargetLanguage
setTargetLanguage( $x)
Target language for the parse.
Definition: ParserOptions.php:326
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ParserOptions\getInterfaceMessage
getInterfaceMessage()
Parsing an interface message?
Definition: ParserOptions.php:300
ParserOptions\setIsSectionPreview
setIsSectionPreview( $x)
Parsing the page for a "preview" operation on a single section?
Definition: ParserOptions.php:595
ParserOptions\newFromAnon
static newFromAnon()
Get a ParserOptions object for an anonymous user.
Definition: ParserOptions.php:963
ParserOptions\setEnableImageWhitelist
setEnableImageWhitelist( $x)
Use the on-wiki external image whitelist?
Definition: ParserOptions.php:241
$wgDisableTitleConversion
$wgDisableTitleConversion
Whether to enable language variant conversion for links.
Definition: DefaultSettings.php:3042
ParserOptions\setWrapOutputClass
setWrapOutputClass( $className)
CSS class to use to wrap output from Parser::parse()
Definition: ParserOptions.php:779
ParserOptions\setSpeculativeRevIdCallback
setSpeculativeRevIdCallback( $x)
Callback to generate a guess for {{REVISIONID}}.
Definition: ParserOptions.php:840
ParserOptions\disableTitleConversion
disableTitleConversion( $x=true)
Whether title conversion should be disabled.
Definition: ParserOptions.php:527
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
ParserOptions\getIsPrintable
getIsPrintable()
Parsing the printable version of the page?
Definition: ParserOptions.php:603
ParserOptions\setMaxGeneratedPPNodeCount
setMaxGeneratedPPNodeCount( $x)
Maximum number of nodes generated by Preprocessor::preprocessToObj()
Definition: ParserOptions.php:377
User
User
Definition: All_system_messages.txt:425
ParserOptions\setCurrentRevisionCallback
setCurrentRevisionCallback( $x)
Callback for current revision fetching; first argument to call_user_func().
Definition: ParserOptions.php:804
ParserOptions\initDateFormat
static initDateFormat( $popt)
Lazy initializer for dateFormat.
Definition: ParserOptions.php:644
ParserOptions\$inCacheKey
static array $inCacheKey
Specify options that are included in the cache key.
Definition: ParserOptions.php:61
ParserOptions\setMaxTemplateDepth
setMaxTemplateDepth( $x)
Maximum recursion depth for templates within templates.
Definition: ParserOptions.php:402
ParserOptions\getMagicRFCLinks
getMagicRFCLinks()
Are magic RFC links enabled?
Definition: ParserOptions.php:729
ParserOptions\getUserLangObj
getUserLangObj()
Get the user language used by the parser for this page and split the parser cache.
Definition: ParserOptions.php:674
php
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
ParserOptions\registerWatcher
registerWatcher( $callback)
Registers a callback for tracking which ParserOptions which are used.
Definition: ParserOptions.php:1191
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:1354
ParserOptions\getDateFormat
getDateFormat()
Date format index.
Definition: ParserOptions.php:637
ParserOptions\newCanonical
static newCanonical(User $user=null, $lang=null)
Creates a "canonical" ParserOptions object.
Definition: ParserOptions.php:1020
Revision
Definition: Revision.php:41
key
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 and does all the work of translating among various forms such as plain database key
Definition: design.txt:25
ParserOptions\setOption
setOption( $name, $value)
Set an option, generically.
Definition: ParserOptions.php:143
ParserOptions\setNumberHeadings
setNumberHeadings( $x)
Automatically number headings?
Definition: ParserOptions.php:258
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
ParserOptions\getCanonicalOverrides
static getCanonicalOverrides()
Get "canonical" non-default option values.
Definition: ParserOptions.php:1110
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1111
ParserOptions\getRedirectTarget
getRedirectTarget()
Get the previously-set redirect target.
Definition: ParserOptions.php:907
ParserOptions\newFromUserAndLang
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
Definition: ParserOptions.php:992
ParserOptions\setUserLang
setUserLang( $x)
Set the user language used by the parser for this page and split the parser cache.
Definition: ParserOptions.php:699
ParserOptions\getAllowSpecialInclusion
getAllowSpecialInclusion()
Allow inclusion of special pages?
Definition: ParserOptions.php:266
$wgAllowExternalImagesFrom
$wgAllowExternalImagesFrom
If the above is false, you can specify an exception here.
Definition: DefaultSettings.php:4228
ParserOptions\getTidy
getTidy()
Use tidy to cleanup output HTML?
Definition: ParserOptions.php:283
ParserOptions\getMaxIncludeSize
getMaxIncludeSize()
Maximum size of template expansions, in bytes.
Definition: ParserOptions.php:334
ParserOptions\$mTimestamp
string null $mTimestamp
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:81
$wgExpensiveParserFunctionLimit
$wgExpensiveParserFunctionLimit
Maximum number of calls per parse to expensive parser functions such as PAGESINCATEGORY.
Definition: DefaultSettings.php:4377
ParserOptions\setThumbSize
setThumbSize( $x)
Thumb size preferred by the user.
Definition: ParserOptions.php:544
ParserOptions\getEnableImageWhitelist
getEnableImageWhitelist()
Use the on-wiki external image whitelist?
Definition: ParserOptions.php:232
$wgInterwikiMagic
$wgInterwikiMagic
Treat language links as magic connectors, not inline links.
Definition: DefaultSettings.php:2888
ParserOptions\setExternalLinkTarget
setExternalLinkTarget( $x)
Target attribute for external links.
Definition: ParserOptions.php:493
$wgLang
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
$parser
do that in ParserLimitReportFormat instead $parser
Definition: hooks.txt:2595
ParserOptions\setDateFormat
setDateFormat( $x)
Date format index.
Definition: ParserOptions.php:653
ParserOptions\getTargetLanguage
getTargetLanguage()
Target language for the parse.
Definition: ParserOptions.php:317
ParserOptions\setAllowSpecialInclusion
setAllowSpecialInclusion( $x)
Allow inclusion of special pages?
Definition: ParserOptions.php:275
$wgMaxPPExpandDepth
$wgMaxPPExpandDepth
Definition: DefaultSettings.php:4187
ParserOptions\getDefaults
static getDefaults()
Get default option values.
Definition: ParserOptions.php:1037
ParserOptions\getExternalLinkTarget
getExternalLinkTarget()
Target attribute for external links.
Definition: ParserOptions.php:484
ParserOptions\$onAccessCallback
callable null $onAccessCallback
Function to be called when an option is accessed.
Definition: ParserOptions.php:95
$wgEnableMagicLinks
$wgEnableMagicLinks
Enable the magic links feature of automatically turning ISBN xxx, PMID xxx, RFC xxx into links.
Definition: DefaultSettings.php:4402
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1997
ParserOptions\getStubThreshold
getStubThreshold()
Thumb size preferred by the user.
Definition: ParserOptions.php:552
$wgExternalLinkTarget
$wgExternalLinkTarget
Set a default target for external links, e.g.
Definition: DefaultSettings.php:4330
ParserOptions\$options
array $options
Current values for all options that are relevant for caching.
Definition: ParserOptions.php:74
ParserOptions\getUserLang
getUserLang()
Same as getUserLangObj() but returns a string instead.
Definition: ParserOptions.php:690
$wgDisableLangConversion
$wgDisableLangConversion
Whether to enable language variant conversion.
Definition: DefaultSettings.php:3037
ParserOptions\getPreSaveTransform
getPreSaveTransform()
Transform wiki markup when saving the page?
Definition: ParserOptions.php:620
ParserOptions\setStubThreshold
setStubThreshold( $x)
Thumb size preferred by the user.
Definition: ParserOptions.php:561
ParserOptions\getOption
getOption( $name)
Fetch an option, generically.
Definition: ParserOptions.php:121
ParserOptions\$mExtraKey
$mExtraKey
Appended to the options hash.
Definition: ParserOptions.php:108
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:747
ParserOptions\getDisableContentConversion
getDisableContentConversion()
Whether content conversion should be disabled.
Definition: ParserOptions.php:501
ParserOptions\optionToString
optionToString( $value)
Convert an option to a string value.
Definition: ParserOptions.php:1247
ParserOptions\optionUsed
optionUsed( $optionName)
Called when an option is accessed.
Definition: ParserOptions.php:1203
ParserOptions\$lazyOptions
static callback[] $lazyOptions
Lazy-loaded options.
Definition: ParserOptions.php:53
ParserOptions\setTimestamp
setTimestamp( $x)
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:862
$value
$value
Definition: styleTest.css.php:45
ParserOptions\setCleanSignatures
setCleanSignatures( $x)
Clean up signature texts?
Definition: ParserOptions.php:476
ParserOptions\getSpeculativeRevIdCallback
getSpeculativeRevIdCallback()
Callback to generate a guess for {{REVISIONID}}.
Definition: ParserOptions.php:830
ParserOptions\newFromContext
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
Definition: ParserOptions.php:1005
ParserOptions\getCurrentRevisionCallback
getCurrentRevisionCallback()
Callback for current revision fetching; first argument to call_user_func().
Definition: ParserOptions.php:794
$wgEnableParserLimitReporting
$wgEnableParserLimitReporting
Whether to include the NewPP limit report as a HTML comment.
Definition: DefaultSettings.php:7271
ParserOptions\getTemplateCallback
getTemplateCallback()
Callback for template fetching; first argument to call_user_func().
Definition: ParserOptions.php:812
options
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing options(say) and put it in one place. Instead of having little title-reversing if-blocks spread all over the codebase in showAnArticle
$ret
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:1987
ParserOptions\setRemoveComments
setRemoveComments( $x)
Remove HTML comments.
Definition: ParserOptions.php:440
ParserOptions\setInterwikiMagic
setInterwikiMagic( $x)
Specify whether to extract interlanguage links.
Definition: ParserOptions.php:184
ParserOptions\setRedirectTarget
setRedirectTarget( $title)
Set the redirect target.
Definition: ParserOptions.php:897
ParserOptions\setExpensiveParserFunctionLimit
setExpensiveParserFunctionLimit( $x)
Maximum number of calls per parse to expensive parser functions.
Definition: ParserOptions.php:421
ParserOptions\getTimestamp
getTimestamp()
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:850
ParserOptions\setMaxPPNodeCount
setMaxPPNodeCount( $x)
Maximum number of nodes touched by PPFrame::expand()
Definition: ParserOptions.php:360
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:466
ParserOptions\$redirectTarget
Title null $redirectTarget
If the page being parsed is a redirect, this should hold the redirect target.
Definition: ParserOptions.php:103
ParserOptions\setAllowExternalImagesFrom
setAllowExternalImagesFrom( $x)
External images to allow.
Definition: ParserOptions.php:224
ParserOptions\matches
matches(ParserOptions $other)
Check if these options match that of another options set.
Definition: ParserOptions.php:1144
ParserOptions\enableLimitReport
enableLimitReport( $x=true)
Enable limit report in an HTML comment on output.
Definition: ParserOptions.php:457
Title
Represents a title within MediaWiki.
Definition: Title.php:39
ParserOptions\__construct
__construct( $user=null, $lang=null)
Definition: ParserOptions.php:936
ParserOptions\getInterwikiMagic
getInterwikiMagic()
Whether to extract interlanguage links.
Definition: ParserOptions.php:175
ParserOptions\$mUser
User $mUser
Stored user object.
Definition: ParserOptions.php:88
ParserOptions\setInterfaceMessage
setInterfaceMessage( $x)
Parsing an interface message?
Definition: ParserOptions.php:309
ParserOptions\$defaults
static array null $defaults
Default values for all options that are relevant for caching.
Definition: ParserOptions.php:47
$wgHooks
$wgHooks['ArticleShow'][]
Definition: hooks.txt:108
ParserOptions\allCacheVaryingOptions
static allCacheVaryingOptions()
Return all option keys that vary the options hash.
Definition: ParserOptions.php:1233
LinkCache\singleton
static singleton()
Get an instance of this class.
Definition: LinkCache.php:67
$wgCleanSignatures
$wgCleanSignatures
If true, removes (by substituting) templates in signatures.
Definition: DefaultSettings.php:4209
ParserOptions\getUser
getUser()
Current user.
Definition: ParserOptions.php:925
as
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
ParserOptions\getThumbSize
getThumbSize()
Thumb size preferred by the user.
Definition: ParserOptions.php:535
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:712
ParserOptions\setIsPrintable
setIsPrintable( $x)
Parsing the printable version of the page?
Definition: ParserOptions.php:612
ParserOptions\getMaxPPNodeCount
getMaxPPNodeCount()
Maximum number of nodes touched by PPFrame::expand()
Definition: ParserOptions.php:351
ParserOptions\legacyOptions
static legacyOptions()
Returns the full array of options that would have been used by in 1.16.
Definition: ParserOptions.php:1216
$wgRenderHashAppend
$wgRenderHashAppend
Append a configured value to the parser cache and the sitenotice key so that they can be kept separat...
Definition: DefaultSettings.php:2579
$wgMaxGeneratedPPNodeCount
$wgMaxGeneratedPPNodeCount
A complexity limit on template expansion: the maximum number of elements generated by Preprocessor::p...
Definition: DefaultSettings.php:4174
ParserOptions\setEditSection
setEditSection( $x)
Create "edit section" links?
Definition: ParserOptions.php:882
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:183
ParserOptions\getMaxGeneratedPPNodeCount
getMaxGeneratedPPNodeCount()
Maximum number of nodes generated by Preprocessor::preprocessToObj()
Definition: ParserOptions.php:368
ParserOptions\getMaxPPExpandDepth
getMaxPPExpandDepth()
Maximum recursion depth in PPFrame::expand()
Definition: ParserOptions.php:385
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
ParserOptions\getEnableLimitReport
getEnableLimitReport()
Enable limit report in an HTML comment on output.
Definition: ParserOptions.php:448
ParserOptions\getNumberHeadings
getNumberHeadings()
Automatically number headings?
Definition: ParserOptions.php:249
ParserOptions\isSafeToCache
isSafeToCache()
Test whether these options are safe to cache.
Definition: ParserOptions.php:1330
ParserOptions\getMaxTemplateDepth
getMaxTemplateDepth()
Maximum recursion depth for templates within templates.
Definition: ParserOptions.php:393
ParserOptions\setPreSaveTransform
setPreSaveTransform( $x)
Transform wiki markup when saving the page?
Definition: ParserOptions.php:629
ParserOptions\getEditSection
getEditSection()
Create "edit section" links?
Definition: ParserOptions.php:871
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:53
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
$wgMaxPPNodeCount
$wgMaxPPNodeCount
A complexity limit on template expansion: the maximum number of nodes visited by PPFrame::expand()
Definition: DefaultSettings.php:4163
Language
Internationalisation code.
Definition: Language.php:35
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:1275
array
the array() calling protocol came about after MediaWiki 1.4rc1.
ParserOptions\getAllowExternalImages
getAllowExternalImages()
Allow all external images inline?
Definition: ParserOptions.php:192
ParserOptions\newFromUser
static newFromUser( $user)
Get a ParserOptions object from a given user.
Definition: ParserOptions.php:978
$wgAllowExternalImages
$wgAllowExternalImages
Whether to allow inline image pointing to other websites.
Definition: DefaultSettings.php:4214
$wgEnableImageWhitelist
$wgEnableImageWhitelist
If $wgAllowExternalImages is false, you can allow an on-wiki whitelist of regular expression fragment...
Definition: DefaultSettings.php:4239
ParserOptions\addExtraKey
addExtraKey( $key)
Extra key that should be present in the parser cache key.
Definition: ParserOptions.php:917
$wgContLang
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 content language as $wgContLang
Definition: design.txt:56
$wgAllowSpecialInclusion
$wgAllowSpecialInclusion
Allow special page inclusions such as {{Special:Allpages}}.
Definition: DefaultSettings.php:7834