MediaWiki  1.30.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  'wrapclass' => true,
69  ];
70 
75  private $options;
76 
82  private $mTimestamp;
83 
89  private $mEditSection = true;
90 
96  private $mUser;
97 
103  private $onAccessCallback = null;
104 
111  private $redirectTarget = null;
112 
116  private $mExtraKey = '';
117 
129  public function getOption( $name ) {
130  if ( !array_key_exists( $name, $this->options ) ) {
131  throw new InvalidArgumentException( "Unknown parser option $name" );
132  }
133 
134  if ( isset( self::$lazyOptions[$name] ) && $this->options[$name] === null ) {
135  $this->options[$name] = call_user_func( self::$lazyOptions[$name], $this, $name );
136  }
137  if ( !empty( self::$inCacheKey[$name] ) ) {
138  $this->optionUsed( $name );
139  }
140  return $this->options[$name];
141  }
142 
151  public function setOption( $name, $value ) {
152  if ( !array_key_exists( $name, $this->options ) ) {
153  throw new InvalidArgumentException( "Unknown parser option $name" );
154  }
155  $old = $this->options[$name];
156  $this->options[$name] = $value;
157  return $old;
158  }
159 
168  protected function setOptionLegacy( $name, $value ) {
169  if ( !array_key_exists( $name, $this->options ) ) {
170  throw new InvalidArgumentException( "Unknown parser option $name" );
171  }
172  return wfSetVar( $this->options[$name], $value );
173  }
174 
183  public function getInterwikiMagic() {
184  return $this->getOption( 'interwikiMagic' );
185  }
186 
192  public function setInterwikiMagic( $x ) {
193  return $this->setOptionLegacy( 'interwikiMagic', $x );
194  }
195 
200  public function getAllowExternalImages() {
201  return $this->getOption( 'allowExternalImages' );
202  }
203 
209  public function setAllowExternalImages( $x ) {
210  return $this->setOptionLegacy( 'allowExternalImages', $x );
211  }
212 
220  public function getAllowExternalImagesFrom() {
221  return $this->getOption( 'allowExternalImagesFrom' );
222  }
223 
232  public function setAllowExternalImagesFrom( $x ) {
233  return $this->setOptionLegacy( 'allowExternalImagesFrom', $x );
234  }
235 
240  public function getEnableImageWhitelist() {
241  return $this->getOption( 'enableImageWhitelist' );
242  }
243 
249  public function setEnableImageWhitelist( $x ) {
250  return $this->setOptionLegacy( 'enableImageWhitelist', $x );
251  }
252 
257  public function getNumberHeadings() {
258  return $this->getOption( 'numberheadings' );
259  }
260 
266  public function setNumberHeadings( $x ) {
267  return $this->setOptionLegacy( 'numberheadings', $x );
268  }
269 
274  public function getAllowSpecialInclusion() {
275  return $this->getOption( 'allowSpecialInclusion' );
276  }
277 
283  public function setAllowSpecialInclusion( $x ) {
284  return $this->setOptionLegacy( 'allowSpecialInclusion', $x );
285  }
286 
291  public function getTidy() {
292  return $this->getOption( 'tidy' );
293  }
294 
300  public function setTidy( $x ) {
301  return $this->setOptionLegacy( 'tidy', $x );
302  }
303 
308  public function getInterfaceMessage() {
309  return $this->getOption( 'interfaceMessage' );
310  }
311 
317  public function setInterfaceMessage( $x ) {
318  return $this->setOptionLegacy( 'interfaceMessage', $x );
319  }
320 
325  public function getTargetLanguage() {
326  return $this->getOption( 'targetLanguage' );
327  }
328 
334  public function setTargetLanguage( $x ) {
335  return $this->setOption( 'targetLanguage', $x );
336  }
337 
342  public function getMaxIncludeSize() {
343  return $this->getOption( 'maxIncludeSize' );
344  }
345 
351  public function setMaxIncludeSize( $x ) {
352  return $this->setOptionLegacy( 'maxIncludeSize', $x );
353  }
354 
359  public function getMaxPPNodeCount() {
360  return $this->getOption( 'maxPPNodeCount' );
361  }
362 
368  public function setMaxPPNodeCount( $x ) {
369  return $this->setOptionLegacy( 'maxPPNodeCount', $x );
370  }
371 
376  public function getMaxGeneratedPPNodeCount() {
377  return $this->getOption( 'maxGeneratedPPNodeCount' );
378  }
379 
385  public function setMaxGeneratedPPNodeCount( $x ) {
386  return $this->setOptionLegacy( 'maxGeneratedPPNodeCount', $x );
387  }
388 
393  public function getMaxPPExpandDepth() {
394  return $this->getOption( 'maxPPExpandDepth' );
395  }
396 
401  public function getMaxTemplateDepth() {
402  return $this->getOption( 'maxTemplateDepth' );
403  }
404 
410  public function setMaxTemplateDepth( $x ) {
411  return $this->setOptionLegacy( 'maxTemplateDepth', $x );
412  }
413 
420  return $this->getOption( 'expensiveParserFunctionLimit' );
421  }
422 
429  public function setExpensiveParserFunctionLimit( $x ) {
430  return $this->setOptionLegacy( 'expensiveParserFunctionLimit', $x );
431  }
432 
438  public function getRemoveComments() {
439  return $this->getOption( 'removeComments' );
440  }
441 
448  public function setRemoveComments( $x ) {
449  return $this->setOptionLegacy( 'removeComments', $x );
450  }
451 
456  public function getEnableLimitReport() {
457  return $this->getOption( 'enableLimitReport' );
458  }
459 
465  public function enableLimitReport( $x = true ) {
466  return $this->setOptionLegacy( 'enableLimitReport', $x );
467  }
468 
474  public function getCleanSignatures() {
475  return $this->getOption( 'cleanSignatures' );
476  }
477 
484  public function setCleanSignatures( $x ) {
485  return $this->setOptionLegacy( 'cleanSignatures', $x );
486  }
487 
492  public function getExternalLinkTarget() {
493  return $this->getOption( 'externalLinkTarget' );
494  }
495 
501  public function setExternalLinkTarget( $x ) {
502  return $this->setOptionLegacy( 'externalLinkTarget', $x );
503  }
504 
509  public function getDisableContentConversion() {
510  return $this->getOption( 'disableContentConversion' );
511  }
512 
518  public function disableContentConversion( $x = true ) {
519  return $this->setOptionLegacy( 'disableContentConversion', $x );
520  }
521 
526  public function getDisableTitleConversion() {
527  return $this->getOption( 'disableTitleConversion' );
528  }
529 
535  public function disableTitleConversion( $x = true ) {
536  return $this->setOptionLegacy( 'disableTitleConversion', $x );
537  }
538 
543  public function getThumbSize() {
544  return $this->getOption( 'thumbsize' );
545  }
546 
552  public function setThumbSize( $x ) {
553  return $this->setOptionLegacy( 'thumbsize', $x );
554  }
555 
560  public function getStubThreshold() {
561  return $this->getOption( 'stubthreshold' );
562  }
563 
569  public function setStubThreshold( $x ) {
570  return $this->setOptionLegacy( 'stubthreshold', $x );
571  }
572 
577  public function getIsPreview() {
578  return $this->getOption( 'isPreview' );
579  }
580 
586  public function setIsPreview( $x ) {
587  return $this->setOptionLegacy( 'isPreview', $x );
588  }
589 
594  public function getIsSectionPreview() {
595  return $this->getOption( 'isSectionPreview' );
596  }
597 
603  public function setIsSectionPreview( $x ) {
604  return $this->setOptionLegacy( 'isSectionPreview', $x );
605  }
606 
611  public function getIsPrintable() {
612  return $this->getOption( 'printable' );
613  }
614 
620  public function setIsPrintable( $x ) {
621  return $this->setOptionLegacy( 'printable', $x );
622  }
623 
628  public function getPreSaveTransform() {
629  return $this->getOption( 'preSaveTransform' );
630  }
631 
637  public function setPreSaveTransform( $x ) {
638  return $this->setOptionLegacy( 'preSaveTransform', $x );
639  }
640 
645  public function getDateFormat() {
646  return $this->getOption( 'dateformat' );
647  }
648 
652  private static function initDateFormat( $popt ) {
653  return $popt->mUser->getDatePreference();
654  }
655 
661  public function setDateFormat( $x ) {
662  return $this->setOptionLegacy( 'dateformat', $x );
663  }
664 
682  public function getUserLangObj() {
683  return $this->getOption( 'userlang' );
684  }
685 
698  public function getUserLang() {
699  return $this->getUserLangObj()->getCode();
700  }
701 
707  public function setUserLang( $x ) {
708  if ( is_string( $x ) ) {
709  $x = Language::factory( $x );
710  }
711 
712  return $this->setOptionLegacy( 'userlang', $x );
713  }
714 
720  public function getMagicISBNLinks() {
721  return $this->getOption( 'magicISBNLinks' );
722  }
723 
729  public function getMagicPMIDLinks() {
730  return $this->getOption( 'magicPMIDLinks' );
731  }
737  public function getMagicRFCLinks() {
738  return $this->getOption( 'magicRFCLinks' );
739  }
740 
755  public function getAllowUnsafeRawHtml() {
756  return $this->getOption( 'allowUnsafeRawHtml' );
757  }
758 
767  public function setAllowUnsafeRawHtml( $x ) {
768  return $this->setOptionLegacy( 'allowUnsafeRawHtml', $x );
769  }
770 
776  public function getWrapOutputClass() {
777  return $this->getOption( 'wrapclass' );
778  }
779 
786  public function setWrapOutputClass( $className ) {
787  if ( $className === true ) { // DWIM, they probably want the default class name
788  $className = 'mw-parser-output';
789  }
790  return $this->setOption( 'wrapclass', $className );
791  }
792 
798  public function getCurrentRevisionCallback() {
799  return $this->getOption( 'currentRevisionCallback' );
800  }
801 
808  public function setCurrentRevisionCallback( $x ) {
809  return $this->setOptionLegacy( 'currentRevisionCallback', $x );
810  }
811 
816  public function getTemplateCallback() {
817  return $this->getOption( 'templateCallback' );
818  }
819 
825  public function setTemplateCallback( $x ) {
826  return $this->setOptionLegacy( 'templateCallback', $x );
827  }
828 
834  public function getSpeculativeRevIdCallback() {
835  return $this->getOption( 'speculativeRevIdCallback' );
836  }
837 
844  public function setSpeculativeRevIdCallback( $x ) {
845  return $this->setOptionLegacy( 'speculativeRevIdCallback', $x );
846  }
847 
854  public function getTimestamp() {
855  if ( !isset( $this->mTimestamp ) ) {
856  $this->mTimestamp = wfTimestampNow();
857  }
858  return $this->mTimestamp;
859  }
860 
866  public function setTimestamp( $x ) {
867  return wfSetVar( $this->mTimestamp, $x );
868  }
869 
874  public function getEditSection() {
875  return $this->mEditSection;
876  }
877 
883  public function setEditSection( $x ) {
884  return wfSetVar( $this->mEditSection, $x );
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', 'statelessFetchRevision' ],
1061  'templateCallback' => [ 'Parser', 'statelessFetchTemplate' ],
1062  'speculativeRevIdCallback' => null,
1063  ];
1064 
1065  // @codingStandardsIgnoreStart Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfterAmp
1066  Hooks::run( 'ParserOptionsRegister', [
1067  &self::$defaults,
1068  &self::$inCacheKey,
1069  &self::$lazyOptions,
1070  ] );
1071  // @codingStandardsIgnoreEnd
1072 
1073  ksort( self::$inCacheKey );
1074  }
1075 
1076  // Unit tests depend on being able to modify the globals at will
1077  return self::$defaults + [
1078  'interwikiMagic' => $wgInterwikiMagic,
1079  'allowExternalImages' => $wgAllowExternalImages,
1080  'allowExternalImagesFrom' => $wgAllowExternalImagesFrom,
1081  'enableImageWhitelist' => $wgEnableImageWhitelist,
1082  'allowSpecialInclusion' => $wgAllowSpecialInclusion,
1083  'maxIncludeSize' => $wgMaxArticleSize * 1024,
1084  'maxPPNodeCount' => $wgMaxPPNodeCount,
1085  'maxGeneratedPPNodeCount' => $wgMaxGeneratedPPNodeCount,
1086  'maxPPExpandDepth' => $wgMaxPPExpandDepth,
1087  'maxTemplateDepth' => $wgMaxTemplateDepth,
1088  'expensiveParserFunctionLimit' => $wgExpensiveParserFunctionLimit,
1089  'externalLinkTarget' => $wgExternalLinkTarget,
1090  'cleanSignatures' => $wgCleanSignatures,
1091  'disableContentConversion' => $wgDisableLangConversion,
1092  'disableTitleConversion' => $wgDisableLangConversion || $wgDisableTitleConversion,
1093  'magicISBNLinks' => $wgEnableMagicLinks['ISBN'],
1094  'magicPMIDLinks' => $wgEnableMagicLinks['PMID'],
1095  'magicRFCLinks' => $wgEnableMagicLinks['RFC'],
1096  'numberheadings' => User::getDefaultOption( 'numberheadings' ),
1097  'thumbsize' => User::getDefaultOption( 'thumbsize' ),
1098  'stubthreshold' => 0,
1099  'userlang' => $wgContLang,
1100  ];
1101  }
1102 
1112  private static function getCanonicalOverrides() {
1114 
1115  return [
1116  'tidy' => true,
1117  'enableLimitReport' => $wgEnableParserLimitReporting,
1118  ];
1119  }
1120 
1127  private function initialiseFromUser( $user, $lang ) {
1128  $this->options = self::getDefaults();
1129 
1130  $this->mUser = $user;
1131  $this->options['numberheadings'] = $user->getOption( 'numberheadings' );
1132  $this->options['thumbsize'] = $user->getOption( 'thumbsize' );
1133  $this->options['stubthreshold'] = $user->getStubThreshold();
1134  $this->options['userlang'] = $lang;
1135  }
1136 
1146  public function matches( ParserOptions $other ) {
1147  // Populate lazy options
1148  foreach ( self::$lazyOptions as $name => $callback ) {
1149  if ( $this->options[$name] === null ) {
1150  $this->options[$name] = call_user_func( $callback, $this, $name );
1151  }
1152  if ( $other->options[$name] === null ) {
1153  $other->options[$name] = call_user_func( $callback, $other, $name );
1154  }
1155  }
1156 
1157  // Compare most options
1158  $options = array_keys( $this->options );
1159  $options = array_diff( $options, [
1160  'enableLimitReport', // only affects HTML comments
1161  ] );
1162  foreach ( $options as $option ) {
1163  $o1 = $this->optionToString( $this->options[$option] );
1164  $o2 = $this->optionToString( $other->options[$option] );
1165  if ( $o1 !== $o2 ) {
1166  return false;
1167  }
1168  }
1169 
1170  // Compare most other fields
1171  $fields = array_keys( get_class_vars( __CLASS__ ) );
1172  $fields = array_diff( $fields, [
1173  'defaults', // static
1174  'lazyOptions', // static
1175  'inCacheKey', // static
1176  'options', // Already checked above
1177  'onAccessCallback', // only used for ParserOutput option tracking
1178  ] );
1179  foreach ( $fields as $field ) {
1180  if ( !is_object( $this->$field ) && $this->$field !== $other->$field ) {
1181  return false;
1182  }
1183  }
1184 
1185  return true;
1186  }
1187 
1193  public function registerWatcher( $callback ) {
1194  $this->onAccessCallback = $callback;
1195  }
1196 
1205  public function optionUsed( $optionName ) {
1206  if ( $this->onAccessCallback ) {
1207  call_user_func( $this->onAccessCallback, $optionName );
1208  }
1209  }
1210 
1218  public static function legacyOptions() {
1219  wfDeprecated( __METHOD__, '1.30' );
1220  return [
1221  'stubthreshold',
1222  'numberheadings',
1223  'userlang',
1224  'thumbsize',
1225  'editsection',
1226  'printable'
1227  ];
1228  }
1229 
1235  public static function allCacheVaryingOptions() {
1236  // Trigger a call to the 'ParserOptionsRegister' hook if it hasn't
1237  // already been called.
1238  if ( self::$defaults === null ) {
1240  }
1241  return array_keys( array_filter( self::$inCacheKey ) );
1242  }
1243 
1249  private function optionToString( $value ) {
1250  if ( $value === true ) {
1251  return '1';
1252  } elseif ( $value === false ) {
1253  return '0';
1254  } elseif ( $value === null ) {
1255  return '';
1256  } elseif ( $value instanceof Language ) {
1257  return $value->getCode();
1258  } elseif ( is_array( $value ) ) {
1259  return '[' . join( ',', array_map( [ $this, 'optionToString' ], $value ) ) . ']';
1260  } else {
1261  return (string)$value;
1262  }
1263  }
1264 
1277  public function optionsHash( $forOptions, $title = null ) {
1279 
1283 
1284  // Historical hack: 'editsection' hasn't been a true parser option since
1285  // Feb 2015 (instead the parser outputs a constant placeholder and post-parse
1286  // processing handles the option). But Wikibase forces it in $forOptions
1287  // and expects the cache key to still vary on it for T85252.
1288  // @deprecated since 1.30, Wikibase should use addExtraKey() or something instead.
1289  if ( in_array( 'editsection', $forOptions, true ) ) {
1290  $options['editsection'] = $this->mEditSection;
1291  $defaults['editsection'] = true;
1292  $inCacheKey['editsection'] = true;
1293  ksort( $inCacheKey );
1294  }
1295 
1296  // We only include used options with non-canonical values in the key
1297  // so adding a new option doesn't invalidate the entire parser cache.
1298  // The drawback to this is that changing the default value of an option
1299  // requires manual invalidation of existing cache entries, as mentioned
1300  // in the docs on the relevant methods and hooks.
1301  $values = [];
1302  foreach ( $inCacheKey as $option => $include ) {
1303  if ( $include && in_array( $option, $forOptions, true ) ) {
1304  $v = $this->optionToString( $options[$option] );
1305  $d = $this->optionToString( $defaults[$option] );
1306  if ( $v !== $d ) {
1307  $values[] = "$option=$v";
1308  }
1309  }
1310  }
1311 
1312  $confstr = $values ? join( '!', $values ) : 'canonical';
1313 
1314  // add in language specific options, if any
1315  // @todo FIXME: This is just a way of retrieving the url/user preferred variant
1316  if ( !is_null( $title ) ) {
1317  $confstr .= $title->getPageLanguage()->getExtraHashOptions();
1318  } else {
1320  $confstr .= $wgContLang->getExtraHashOptions();
1321  }
1322 
1323  $confstr .= $wgRenderHashAppend;
1324 
1325  if ( $this->mExtraKey != '' ) {
1326  $confstr .= $this->mExtraKey;
1327  }
1328 
1329  // Give a chance for extensions to modify the hash, if they have
1330  // extra options or other effects on the parser cache.
1331  Hooks::run( 'PageRenderingHash', [ &$confstr, $this->getUser(), &$forOptions ] );
1332 
1333  // Make it a valid memcached key fragment
1334  $confstr = str_replace( ' ', '_', $confstr );
1335 
1336  return $confstr;
1337  }
1338 
1344  public function isSafeToCache() {
1346  foreach ( $this->options as $option => $value ) {
1347  if ( empty( self::$inCacheKey[$option] ) ) {
1348  $v = $this->optionToString( $value );
1349  $d = $this->optionToString( $defaults[$option] );
1350  if ( $v !== $d ) {
1351  return false;
1352  }
1353  }
1354  }
1355  return true;
1356  }
1357 
1368  public function setupFakeRevision( $title, $content, $user ) {
1369  $oldCallback = $this->setCurrentRevisionCallback(
1370  function (
1371  $titleToCheck, $parser = false ) use ( $title, $content, $user, &$oldCallback
1372  ) {
1373  if ( $titleToCheck->equals( $title ) ) {
1374  return new Revision( [
1375  'page' => $title->getArticleID(),
1376  'user_text' => $user->getName(),
1377  'user' => $user->getId(),
1378  'parent_id' => $title->getLatestRevID(),
1379  'title' => $title,
1380  'content' => $content
1381  ] );
1382  } else {
1383  return call_user_func( $oldCallback, $titleToCheck, $parser );
1384  }
1385  }
1386  );
1387 
1388  global $wgHooks;
1389  $wgHooks['TitleExists'][] =
1390  function ( $titleToCheck, &$exists ) use ( $title ) {
1391  if ( $titleToCheck->equals( $title ) ) {
1392  $exists = true;
1393  }
1394  };
1395  end( $wgHooks['TitleExists'] );
1396  $key = key( $wgHooks['TitleExists'] );
1397  LinkCache::singleton()->clearBadLink( $title->getPrefixedDBkey() );
1398  return new ScopedCallback( function () use ( $title, $key ) {
1399  global $wgHooks;
1400  unset( $wgHooks['TitleExists'][$key] );
1401  LinkCache::singleton()->clearLink( $title );
1402  } );
1403  }
1404 }
1405 
User\getDefaultOption
static getDefaultOption( $opt)
Get a given default option value.
Definition: User.php:1619
ParserOptions\setMaxIncludeSize
setMaxIncludeSize( $x)
Maximum size of template expansions, in bytes.
Definition: ParserOptions.php:351
ParserOptions\getMagicPMIDLinks
getMagicPMIDLinks()
Are magic PMID links enabled?
Definition: ParserOptions.php:729
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:40
ParserOptions\setOptionLegacy
setOptionLegacy( $name, $value)
Legacy implementation.
Definition: ParserOptions.php:168
ParserOptions\getAllowExternalImagesFrom
getAllowExternalImagesFrom()
External images to allow.
Definition: ParserOptions.php:220
$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:809
ParserOptions\getWrapOutputClass
getWrapOutputClass()
Class to use to wrap output from Parser::parse()
Definition: ParserOptions.php:776
ParserOptions\getExpensiveParserFunctionLimit
getExpensiveParserFunctionLimit()
Maximum number of calls per parse to expensive parser functions.
Definition: ParserOptions.php:419
ParserOptions\setTidy
setTidy( $x)
Use tidy to cleanup output HTML?
Definition: ParserOptions.php:300
ParserOptions\getIsSectionPreview
getIsSectionPreview()
Parsing the page for a "preview" operation on a single section?
Definition: ParserOptions.php:594
$wgMaxArticleSize
$wgMaxArticleSize
Maximum article size in kilobytes.
Definition: DefaultSettings.php:2196
$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:2581
ParserOptions\getRemoveComments
getRemoveComments()
Remove HTML comments.
Definition: ParserOptions.php:438
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:767
ParserOptions\disableContentConversion
disableContentConversion( $x=true)
Whether content conversion should be disabled.
Definition: ParserOptions.php:518
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
ParserOptions\initialiseFromUser
initialiseFromUser( $user, $lang)
Get user options.
Definition: ParserOptions.php:1127
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:1759
$wgMaxTemplateDepth
$wgMaxTemplateDepth
Maximum recursion depth for templates within templates.
Definition: DefaultSettings.php:4211
ParserOptions\getIsPreview
getIsPreview()
Parsing the page for a "preview" operation?
Definition: ParserOptions.php:577
ParserOptions\getDisableTitleConversion
getDisableTitleConversion()
Whether title conversion should be disabled.
Definition: ParserOptions.php:526
ParserOptions\setAllowExternalImages
setAllowExternalImages( $x)
Allow all external images inline?
Definition: ParserOptions.php:209
ParserOptions\setTemplateCallback
setTemplateCallback( $x)
Callback for template fetching; first argument to call_user_func().
Definition: ParserOptions.php:825
ParserOptions\setIsPreview
setIsPreview( $x)
Parsing the page for a "preview" operation?
Definition: ParserOptions.php:586
ParserOptions\setTargetLanguage
setTargetLanguage( $x)
Target language for the parse.
Definition: ParserOptions.php:334
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:308
ParserOptions\setIsSectionPreview
setIsSectionPreview( $x)
Parsing the page for a "preview" operation on a single section?
Definition: ParserOptions.php:603
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:249
$wgDisableTitleConversion
$wgDisableTitleConversion
Whether to enable language variant conversion for links.
Definition: DefaultSettings.php:3037
ParserOptions\setWrapOutputClass
setWrapOutputClass( $className)
CSS class to use to wrap output from Parser::parse()
Definition: ParserOptions.php:786
ParserOptions\setSpeculativeRevIdCallback
setSpeculativeRevIdCallback( $x)
Callback to generate a guess for {{REVISIONID}}.
Definition: ParserOptions.php:844
ParserOptions\disableTitleConversion
disableTitleConversion( $x=true)
Whether title conversion should be disabled.
Definition: ParserOptions.php:535
$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:611
ParserOptions\setMaxGeneratedPPNodeCount
setMaxGeneratedPPNodeCount( $x)
Maximum number of nodes generated by Preprocessor::preprocessToObj()
Definition: ParserOptions.php:385
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:808
ParserOptions\initDateFormat
static initDateFormat( $popt)
Lazy initializer for dateFormat.
Definition: ParserOptions.php:652
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:410
ParserOptions\getMagicRFCLinks
getMagicRFCLinks()
Are magic RFC links enabled?
Definition: ParserOptions.php:737
ParserOptions\getUserLangObj
getUserLangObj()
Get the user language used by the parser for this page and split the parser cache.
Definition: ParserOptions.php:682
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:1193
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:1368
ParserOptions\getDateFormat
getDateFormat()
Date format index.
Definition: ParserOptions.php:645
ParserOptions\newCanonical
static newCanonical(User $user=null, $lang=null)
Creates a "canonical" ParserOptions object.
Definition: ParserOptions.php:1020
Revision
Definition: Revision.php:33
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\$mEditSection
bool $mEditSection
The edit section flag is in ParserOptions for historical reasons, but doesn't actually affect the par...
Definition: ParserOptions.php:89
ParserOptions\setOption
setOption( $name, $value)
Set an option, generically.
Definition: ParserOptions.php:151
ParserOptions\setNumberHeadings
setNumberHeadings( $x)
Automatically number headings?
Definition: ParserOptions.php:266
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
ParserOptions\getCanonicalOverrides
static getCanonicalOverrides()
Get "canonical" non-default option values.
Definition: ParserOptions.php:1112
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1176
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:707
ParserOptions\getAllowSpecialInclusion
getAllowSpecialInclusion()
Allow inclusion of special pages?
Definition: ParserOptions.php:274
$wgAllowExternalImagesFrom
$wgAllowExternalImagesFrom
If the above is false, you can specify an exception here.
Definition: DefaultSettings.php:4257
ParserOptions\getTidy
getTidy()
Use tidy to cleanup output HTML?
Definition: ParserOptions.php:291
ParserOptions\getMaxIncludeSize
getMaxIncludeSize()
Maximum size of template expansions, in bytes.
Definition: ParserOptions.php:342
ParserOptions\$mTimestamp
string null $mTimestamp
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:82
$wgExpensiveParserFunctionLimit
$wgExpensiveParserFunctionLimit
Maximum number of calls per parse to expensive parser functions such as PAGESINCATEGORY.
Definition: DefaultSettings.php:4405
ParserOptions\setThumbSize
setThumbSize( $x)
Thumb size preferred by the user.
Definition: ParserOptions.php:552
ParserOptions\getEnableImageWhitelist
getEnableImageWhitelist()
Use the on-wiki external image whitelist?
Definition: ParserOptions.php:240
$wgInterwikiMagic
$wgInterwikiMagic
Treat language links as magic connectors, not inline links.
Definition: DefaultSettings.php:2883
ParserOptions\setExternalLinkTarget
setExternalLinkTarget( $x)
Target attribute for external links.
Definition: ParserOptions.php:501
$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:2572
ParserOptions\setDateFormat
setDateFormat( $x)
Date format index.
Definition: ParserOptions.php:661
ParserOptions\getTargetLanguage
getTargetLanguage()
Target language for the parse.
Definition: ParserOptions.php:325
ParserOptions\setAllowSpecialInclusion
setAllowSpecialInclusion( $x)
Allow inclusion of special pages?
Definition: ParserOptions.php:283
$wgMaxPPExpandDepth
$wgMaxPPExpandDepth
Definition: DefaultSettings.php:4216
ParserOptions\getDefaults
static getDefaults()
Get default option values.
Definition: ParserOptions.php:1037
ParserOptions\getExternalLinkTarget
getExternalLinkTarget()
Target attribute for external links.
Definition: ParserOptions.php:492
ParserOptions\$onAccessCallback
callable null $onAccessCallback
Function to be called when an option is accessed.
Definition: ParserOptions.php:103
$wgEnableMagicLinks
$wgEnableMagicLinks
Enable the magic links feature of automatically turning ISBN xxx, PMID xxx, RFC xxx into links.
Definition: DefaultSettings.php:4430
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:2069
ParserOptions\getStubThreshold
getStubThreshold()
Thumb size preferred by the user.
Definition: ParserOptions.php:560
$wgExternalLinkTarget
$wgExternalLinkTarget
Set a default target for external links, e.g.
Definition: DefaultSettings.php:4358
ParserOptions\$options
array $options
Current values for all options that are relevant for caching.
Definition: ParserOptions.php:75
ParserOptions\getUserLang
getUserLang()
Same as getUserLangObj() but returns a string instead.
Definition: ParserOptions.php:698
$wgDisableLangConversion
$wgDisableLangConversion
Whether to enable language variant conversion.
Definition: DefaultSettings.php:3032
ParserOptions\getPreSaveTransform
getPreSaveTransform()
Transform wiki markup when saving the page?
Definition: ParserOptions.php:628
ParserOptions\setStubThreshold
setStubThreshold( $x)
Thumb size preferred by the user.
Definition: ParserOptions.php:569
ParserOptions\getOption
getOption( $name)
Fetch an option, generically.
Definition: ParserOptions.php:129
ParserOptions\$mExtraKey
$mExtraKey
Appended to the options hash.
Definition: ParserOptions.php:116
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:755
ParserOptions\getDisableContentConversion
getDisableContentConversion()
Whether content conversion should be disabled.
Definition: ParserOptions.php:509
ParserOptions\optionToString
optionToString( $value)
Convert an option to a string value.
Definition: ParserOptions.php:1249
ParserOptions\optionUsed
optionUsed( $optionName)
Called when an option is accessed.
Definition: ParserOptions.php:1205
ParserOptions\$lazyOptions
static callback[] $lazyOptions
Lazy-loaded options.
Definition: ParserOptions.php:53
ParserOptions\setTimestamp
setTimestamp( $x)
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:866
$value
$value
Definition: styleTest.css.php:45
ParserOptions\setCleanSignatures
setCleanSignatures( $x)
Clean up signature texts?
Definition: ParserOptions.php:484
ParserOptions\getSpeculativeRevIdCallback
getSpeculativeRevIdCallback()
Callback to generate a guess for {{REVISIONID}}.
Definition: ParserOptions.php:834
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:798
$wgEnableParserLimitReporting
$wgEnableParserLimitReporting
Whether to include the NewPP limit report as a HTML comment.
Definition: DefaultSettings.php:7246
ParserOptions\getTemplateCallback
getTemplateCallback()
Callback for template fetching; first argument to call_user_func().
Definition: ParserOptions.php:816
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:1965
ParserOptions\setRemoveComments
setRemoveComments( $x)
Remove HTML comments.
Definition: ParserOptions.php:448
ParserOptions\setInterwikiMagic
setInterwikiMagic( $x)
Specify whether to extract interlanguage links.
Definition: ParserOptions.php:192
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:429
ParserOptions\getTimestamp
getTimestamp()
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:854
ParserOptions\setMaxPPNodeCount
setMaxPPNodeCount( $x)
Maximum number of nodes touched by PPFrame::expand()
Definition: ParserOptions.php:368
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
ParserOptions\getCleanSignatures
getCleanSignatures()
Clean up signature texts?
Definition: ParserOptions.php:474
ParserOptions\$redirectTarget
Title null $redirectTarget
If the page being parsed is a redirect, this should hold the redirect target.
Definition: ParserOptions.php:111
ParserOptions\setAllowExternalImagesFrom
setAllowExternalImagesFrom( $x)
External images to allow.
Definition: ParserOptions.php:232
ParserOptions\matches
matches(ParserOptions $other)
Check if these options match that of another options set.
Definition: ParserOptions.php:1146
ParserOptions\enableLimitReport
enableLimitReport( $x=true)
Enable limit report in an HTML comment on output.
Definition: ParserOptions.php:465
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:183
ParserOptions\$mUser
User $mUser
Stored user object.
Definition: ParserOptions.php:96
ParserOptions\setInterfaceMessage
setInterfaceMessage( $x)
Parsing an interface message?
Definition: ParserOptions.php:317
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:1235
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:4238
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:543
StubObject\isRealObject
static isRealObject( $obj)
Returns a bool value whenever $obj is a stub object.
Definition: StubObject.php:80
ParserOptions\getMagicISBNLinks
getMagicISBNLinks()
Are magic ISBN links enabled?
Definition: ParserOptions.php:720
ParserOptions\setIsPrintable
setIsPrintable( $x)
Parsing the printable version of the page?
Definition: ParserOptions.php:620
ParserOptions\getMaxPPNodeCount
getMaxPPNodeCount()
Maximum number of nodes touched by PPFrame::expand()
Definition: ParserOptions.php:359
ParserOptions\legacyOptions
static legacyOptions()
Returns the full array of options that would have been used by in 1.16.
Definition: ParserOptions.php:1218
$wgRenderHashAppend
$wgRenderHashAppend
Append a configured value to the parser cache and the sitenotice key so that they can be kept separat...
Definition: DefaultSettings.php:2574
$wgMaxGeneratedPPNodeCount
$wgMaxGeneratedPPNodeCount
A complexity limit on template expansion: the maximum number of elements generated by Preprocessor::p...
Definition: DefaultSettings.php:4203
ParserOptions\setEditSection
setEditSection( $x)
Create "edit section" links?
Definition: ParserOptions.php:883
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:376
ParserOptions\getMaxPPExpandDepth
getMaxPPExpandDepth()
Maximum recursion depth in PPFrame::expand()
Definition: ParserOptions.php:393
ParserOptions\getEnableLimitReport
getEnableLimitReport()
Enable limit report in an HTML comment on output.
Definition: ParserOptions.php:456
ParserOptions\getNumberHeadings
getNumberHeadings()
Automatically number headings?
Definition: ParserOptions.php:257
ParserOptions\isSafeToCache
isSafeToCache()
Test whether these options are safe to cache.
Definition: ParserOptions.php:1344
ParserOptions\getMaxTemplateDepth
getMaxTemplateDepth()
Maximum recursion depth for templates within templates.
Definition: ParserOptions.php:401
ParserOptions\setPreSaveTransform
setPreSaveTransform( $x)
Transform wiki markup when saving the page?
Definition: ParserOptions.php:637
ParserOptions\getEditSection
getEditSection()
Create "edit section" links?
Definition: ParserOptions.php:874
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:203
$wgMaxPPNodeCount
$wgMaxPPNodeCount
A complexity limit on template expansion: the maximum number of nodes visited by PPFrame::expand()
Definition: DefaultSettings.php:4192
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:1277
array
the array() calling protocol came about after MediaWiki 1.4rc1.
ParserOptions\getAllowExternalImages
getAllowExternalImages()
Allow all external images inline?
Definition: ParserOptions.php:200
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:4243
$wgEnableImageWhitelist
$wgEnableImageWhitelist
If $wgAllowExternalImages is false, you can allow an on-wiki whitelist of regular expression fragment...
Definition: DefaultSettings.php:4268
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:7806