MediaWiki  master
ParserOptions.php
Go to the documentation of this file.
1 <?php
26 
43 
50 
56  private static $defaults = null;
57 
62  private static $lazyOptions = [
63  'dateformat' => [ __CLASS__, 'initDateFormat' ],
64  'speculativeRevId' => [ __CLASS__, 'initSpeculativeRevId' ],
65  ];
66 
71  private static $inCacheKey = [
72  'dateformat' => true,
73  'numberheadings' => true,
74  'thumbsize' => true,
75  'stubthreshold' => true,
76  'printable' => true,
77  'userlang' => true,
78  ];
79 
84  private $options;
85 
91  private $mTimestamp;
92 
98  private $mUser;
99 
106 
114 
118  private $mExtraKey = '';
119 
131  public function getOption( $name ) {
132  if ( !array_key_exists( $name, $this->options ) ) {
133  throw new InvalidArgumentException( "Unknown parser option $name" );
134  }
135 
136  $this->lazyLoadOption( $name );
137  if ( !empty( self::$inCacheKey[$name] ) ) {
138  $this->optionUsed( $name );
139  }
140  return $this->options[$name];
141  }
142 
146  private function lazyLoadOption( $name ) {
147  if ( isset( self::$lazyOptions[$name] ) && $this->options[$name] === null ) {
148  $this->options[$name] = call_user_func( self::$lazyOptions[$name], $this, $name );
149  }
150  }
151 
160  public function setOption( $name, $value ) {
161  if ( !array_key_exists( $name, $this->options ) ) {
162  throw new InvalidArgumentException( "Unknown parser option $name" );
163  }
164  $old = $this->options[$name];
165  $this->options[$name] = $value;
166  return $old;
167  }
168 
177  protected function setOptionLegacy( $name, $value ) {
178  if ( !array_key_exists( $name, $this->options ) ) {
179  throw new InvalidArgumentException( "Unknown parser option $name" );
180  }
181  return wfSetVar( $this->options[$name], $value );
182  }
183 
192  public function getInterwikiMagic() {
193  return $this->getOption( 'interwikiMagic' );
194  }
195 
201  public function setInterwikiMagic( $x ) {
202  return $this->setOptionLegacy( 'interwikiMagic', $x );
203  }
204 
209  public function getAllowExternalImages() {
210  return $this->getOption( 'allowExternalImages' );
211  }
212 
218  public function setAllowExternalImages( $x ) {
219  return $this->setOptionLegacy( 'allowExternalImages', $x );
220  }
221 
229  public function getAllowExternalImagesFrom() {
230  return $this->getOption( 'allowExternalImagesFrom' );
231  }
232 
241  public function setAllowExternalImagesFrom( $x ) {
242  return $this->setOptionLegacy( 'allowExternalImagesFrom', $x );
243  }
244 
249  public function getEnableImageWhitelist() {
250  return $this->getOption( 'enableImageWhitelist' );
251  }
252 
258  public function setEnableImageWhitelist( $x ) {
259  return $this->setOptionLegacy( 'enableImageWhitelist', $x );
260  }
261 
266  public function getNumberHeadings() {
267  return $this->getOption( 'numberheadings' );
268  }
269 
275  public function setNumberHeadings( $x ) {
276  return $this->setOptionLegacy( 'numberheadings', $x );
277  }
278 
283  public function getAllowSpecialInclusion() {
284  return $this->getOption( 'allowSpecialInclusion' );
285  }
286 
292  public function setAllowSpecialInclusion( $x ) {
293  return $this->setOptionLegacy( 'allowSpecialInclusion', $x );
294  }
295 
300  public function getTidy() {
301  return $this->getOption( 'tidy' );
302  }
303 
309  public function setTidy( $x ) {
310  return $this->setOptionLegacy( 'tidy', $x );
311  }
312 
317  public function getInterfaceMessage() {
318  return $this->getOption( 'interfaceMessage' );
319  }
320 
326  public function setInterfaceMessage( $x ) {
327  return $this->setOptionLegacy( 'interfaceMessage', $x );
328  }
329 
334  public function getTargetLanguage() {
335  return $this->getOption( 'targetLanguage' );
336  }
337 
343  public function setTargetLanguage( $x ) {
344  return $this->setOption( 'targetLanguage', $x );
345  }
346 
351  public function getMaxIncludeSize() {
352  return $this->getOption( 'maxIncludeSize' );
353  }
354 
360  public function setMaxIncludeSize( $x ) {
361  return $this->setOptionLegacy( 'maxIncludeSize', $x );
362  }
363 
368  public function getMaxPPNodeCount() {
369  return $this->getOption( 'maxPPNodeCount' );
370  }
371 
377  public function setMaxPPNodeCount( $x ) {
378  return $this->setOptionLegacy( 'maxPPNodeCount', $x );
379  }
380 
385  public function getMaxGeneratedPPNodeCount() {
386  return $this->getOption( 'maxGeneratedPPNodeCount' );
387  }
388 
394  public function setMaxGeneratedPPNodeCount( $x ) {
395  return $this->setOptionLegacy( 'maxGeneratedPPNodeCount', $x );
396  }
397 
402  public function getMaxPPExpandDepth() {
403  return $this->getOption( 'maxPPExpandDepth' );
404  }
405 
410  public function getMaxTemplateDepth() {
411  return $this->getOption( 'maxTemplateDepth' );
412  }
413 
419  public function setMaxTemplateDepth( $x ) {
420  return $this->setOptionLegacy( 'maxTemplateDepth', $x );
421  }
422 
429  return $this->getOption( 'expensiveParserFunctionLimit' );
430  }
431 
438  public function setExpensiveParserFunctionLimit( $x ) {
439  return $this->setOptionLegacy( 'expensiveParserFunctionLimit', $x );
440  }
441 
447  public function getRemoveComments() {
448  return $this->getOption( 'removeComments' );
449  }
450 
457  public function setRemoveComments( $x ) {
458  return $this->setOptionLegacy( 'removeComments', $x );
459  }
460 
465  public function getEnableLimitReport() {
466  return $this->getOption( 'enableLimitReport' );
467  }
468 
474  public function enableLimitReport( $x = true ) {
475  return $this->setOptionLegacy( 'enableLimitReport', $x );
476  }
477 
483  public function getCleanSignatures() {
484  return $this->getOption( 'cleanSignatures' );
485  }
486 
493  public function setCleanSignatures( $x ) {
494  return $this->setOptionLegacy( 'cleanSignatures', $x );
495  }
496 
501  public function getExternalLinkTarget() {
502  return $this->getOption( 'externalLinkTarget' );
503  }
504 
510  public function setExternalLinkTarget( $x ) {
511  return $this->setOptionLegacy( 'externalLinkTarget', $x );
512  }
513 
518  public function getDisableContentConversion() {
519  return $this->getOption( 'disableContentConversion' );
520  }
521 
527  public function disableContentConversion( $x = true ) {
528  return $this->setOptionLegacy( 'disableContentConversion', $x );
529  }
530 
535  public function getDisableTitleConversion() {
536  return $this->getOption( 'disableTitleConversion' );
537  }
538 
544  public function disableTitleConversion( $x = true ) {
545  return $this->setOptionLegacy( 'disableTitleConversion', $x );
546  }
547 
552  public function getThumbSize() {
553  return $this->getOption( 'thumbsize' );
554  }
555 
561  public function setThumbSize( $x ) {
562  return $this->setOptionLegacy( 'thumbsize', $x );
563  }
564 
569  public function getStubThreshold() {
570  return $this->getOption( 'stubthreshold' );
571  }
572 
578  public function setStubThreshold( $x ) {
579  return $this->setOptionLegacy( 'stubthreshold', $x );
580  }
581 
586  public function getIsPreview() {
587  return $this->getOption( 'isPreview' );
588  }
589 
595  public function setIsPreview( $x ) {
596  return $this->setOptionLegacy( 'isPreview', $x );
597  }
598 
603  public function getIsSectionPreview() {
604  return $this->getOption( 'isSectionPreview' );
605  }
606 
612  public function setIsSectionPreview( $x ) {
613  return $this->setOptionLegacy( 'isSectionPreview', $x );
614  }
615 
620  public function getIsPrintable() {
621  return $this->getOption( 'printable' );
622  }
623 
629  public function setIsPrintable( $x ) {
630  return $this->setOptionLegacy( 'printable', $x );
631  }
632 
637  public function getPreSaveTransform() {
638  return $this->getOption( 'preSaveTransform' );
639  }
640 
646  public function setPreSaveTransform( $x ) {
647  return $this->setOptionLegacy( 'preSaveTransform', $x );
648  }
649 
654  public function getDateFormat() {
655  return $this->getOption( 'dateformat' );
656  }
657 
663  private static function initDateFormat( ParserOptions $popt ) {
664  return $popt->mUser->getDatePreference();
665  }
666 
672  public function setDateFormat( $x ) {
673  return $this->setOptionLegacy( 'dateformat', $x );
674  }
675 
693  public function getUserLangObj() {
694  return $this->getOption( 'userlang' );
695  }
696 
709  public function getUserLang() {
710  return $this->getUserLangObj()->getCode();
711  }
712 
718  public function setUserLang( $x ) {
719  if ( is_string( $x ) ) {
720  $x = Language::factory( $x );
721  }
722 
723  return $this->setOptionLegacy( 'userlang', $x );
724  }
725 
731  public function getMagicISBNLinks() {
732  return $this->getOption( 'magicISBNLinks' );
733  }
734 
740  public function getMagicPMIDLinks() {
741  return $this->getOption( 'magicPMIDLinks' );
742  }
743 
749  public function getMagicRFCLinks() {
750  return $this->getOption( 'magicRFCLinks' );
751  }
752 
767  public function getAllowUnsafeRawHtml() {
768  return $this->getOption( 'allowUnsafeRawHtml' );
769  }
770 
779  public function setAllowUnsafeRawHtml( $x ) {
780  return $this->setOptionLegacy( 'allowUnsafeRawHtml', $x );
781  }
782 
788  public function getWrapOutputClass() {
789  return $this->getOption( 'wrapclass' );
790  }
791 
799  public function setWrapOutputClass( $className ) {
800  if ( $className === true ) { // DWIM, they probably want the default class name
801  $className = 'mw-parser-output';
802  }
803  if ( $className === false ) {
804  wfDeprecated( __METHOD__ . '( false )', '1.31' );
805  }
806  return $this->setOption( 'wrapclass', $className );
807  }
808 
814  public function getCurrentRevisionCallback() {
815  return $this->getOption( 'currentRevisionCallback' );
816  }
817 
824  public function setCurrentRevisionCallback( $x ) {
825  return $this->setOptionLegacy( 'currentRevisionCallback', $x );
826  }
827 
832  public function getTemplateCallback() {
833  return $this->getOption( 'templateCallback' );
834  }
835 
841  public function setTemplateCallback( $x ) {
842  return $this->setOptionLegacy( 'templateCallback', $x );
843  }
844 
855  public function getSpeculativeRevId() {
856  return $this->getOption( 'speculativeRevId' );
857  }
858 
865  private static function initSpeculativeRevId( ParserOptions $popt ) {
866  $cb = $popt->getOption( 'speculativeRevIdCallback' );
867  $id = $cb ? $cb() : null;
868 
869  // returning null would result in this being re-called every access
870  return $id ?? false;
871  }
872 
879  public function getSpeculativeRevIdCallback() {
880  return $this->getOption( 'speculativeRevIdCallback' );
881  }
882 
889  public function setSpeculativeRevIdCallback( $x ) {
890  $this->setOption( 'speculativeRevId', null ); // reset
891  return $this->setOptionLegacy( 'speculativeRevIdCallback', $x );
892  }
893 
900  public function getTimestamp() {
901  if ( !isset( $this->mTimestamp ) ) {
902  $this->mTimestamp = wfTimestampNow();
903  }
904  return $this->mTimestamp;
905  }
906 
912  public function setTimestamp( $x ) {
913  return wfSetVar( $this->mTimestamp, $x );
914  }
915 
926  function setRedirectTarget( $title ) {
927  $this->redirectTarget = $title;
928  }
929 
936  function getRedirectTarget() {
937  return $this->redirectTarget;
938  }
939 
946  public function addExtraKey( $key ) {
947  $this->mExtraKey .= '!' . $key;
948  }
949 
954  public function getUser() {
955  return $this->mUser;
956  }
957 
964  public function __construct( $user = null, $lang = null ) {
965  if ( $user === null ) {
966  global $wgUser;
967  if ( $wgUser === null ) {
968  $user = new User;
969  } else {
970  $user = $wgUser;
971  }
972  }
973  if ( $lang === null ) {
974  global $wgLang;
975  if ( !StubObject::isRealObject( $wgLang ) ) {
976  $wgLang->_unstub();
977  }
978  $lang = $wgLang;
979  }
980  $this->initialiseFromUser( $user, $lang );
981  }
982 
990  public static function newFromAnon() {
991  return new ParserOptions( new User,
992  MediaWikiServices::getInstance()->getContentLanguage() );
993  }
994 
1004  public static function newFromUser( $user ) {
1005  return new ParserOptions( $user );
1006  }
1007 
1017  public static function newFromUserAndLang( User $user, Language $lang ) {
1018  return new ParserOptions( $user, $lang );
1019  }
1020 
1029  public static function newFromContext( IContextSource $context ) {
1030  return new ParserOptions( $context->getUser(), $context->getLanguage() );
1031  }
1032 
1050  public static function newCanonical( $context = null, $userLang = null ) {
1051  if ( $context instanceof IContextSource ) {
1052  $ret = self::newFromContext( $context );
1053  } elseif ( $context === 'canonical' ) {
1054  $ret = self::newFromAnon();
1055  } elseif ( $context instanceof User || $context === null ) {
1056  $ret = new self( $context, $userLang );
1057  } else {
1058  throw new InvalidArgumentException(
1059  '$context must be an IContextSource, the string "canonical", a User, or null'
1060  );
1061  }
1062 
1063  foreach ( self::getCanonicalOverrides() as $k => $v ) {
1064  $ret->setOption( $k, $v );
1065  }
1066  return $ret;
1067  }
1068 
1078  private static function getDefaults() {
1085 
1086  if ( self::$defaults === null ) {
1087  // *UPDATE* ParserOptions::matches() if any of this changes as needed
1088  self::$defaults = [
1089  'dateformat' => null,
1090  'tidy' => true,
1091  'interfaceMessage' => false,
1092  'targetLanguage' => null,
1093  'removeComments' => true,
1094  'enableLimitReport' => false,
1095  'preSaveTransform' => true,
1096  'isPreview' => false,
1097  'isSectionPreview' => false,
1098  'printable' => false,
1099  'allowUnsafeRawHtml' => true,
1100  'wrapclass' => 'mw-parser-output',
1101  'currentRevisionCallback' => [ Parser::class, 'statelessFetchRevision' ],
1102  'templateCallback' => [ Parser::class, 'statelessFetchTemplate' ],
1103  'speculativeRevIdCallback' => null,
1104  'speculativeRevId' => null,
1105  ];
1106 
1107  Hooks::run( 'ParserOptionsRegister', [
1108  &self::$defaults,
1109  &self::$inCacheKey,
1110  &self::$lazyOptions,
1111  ] );
1112 
1113  ksort( self::$inCacheKey );
1114  }
1115 
1116  // Unit tests depend on being able to modify the globals at will
1117  return self::$defaults + [
1118  'interwikiMagic' => $wgInterwikiMagic,
1119  'allowExternalImages' => $wgAllowExternalImages,
1120  'allowExternalImagesFrom' => $wgAllowExternalImagesFrom,
1121  'enableImageWhitelist' => $wgEnableImageWhitelist,
1122  'allowSpecialInclusion' => $wgAllowSpecialInclusion,
1123  'maxIncludeSize' => $wgMaxArticleSize * 1024,
1124  'maxPPNodeCount' => $wgMaxPPNodeCount,
1125  'maxGeneratedPPNodeCount' => $wgMaxGeneratedPPNodeCount,
1126  'maxPPExpandDepth' => $wgMaxPPExpandDepth,
1127  'maxTemplateDepth' => $wgMaxTemplateDepth,
1128  'expensiveParserFunctionLimit' => $wgExpensiveParserFunctionLimit,
1129  'externalLinkTarget' => $wgExternalLinkTarget,
1130  'cleanSignatures' => $wgCleanSignatures,
1131  'disableContentConversion' => $wgDisableLangConversion,
1132  'disableTitleConversion' => $wgDisableLangConversion || $wgDisableTitleConversion,
1133  'magicISBNLinks' => $wgEnableMagicLinks['ISBN'],
1134  'magicPMIDLinks' => $wgEnableMagicLinks['PMID'],
1135  'magicRFCLinks' => $wgEnableMagicLinks['RFC'],
1136  'numberheadings' => User::getDefaultOption( 'numberheadings' ),
1137  'thumbsize' => User::getDefaultOption( 'thumbsize' ),
1138  'stubthreshold' => 0,
1139  'userlang' => MediaWikiServices::getInstance()->getContentLanguage(),
1140  ];
1141  }
1142 
1152  private static function getCanonicalOverrides() {
1154 
1155  return [
1156  'enableLimitReport' => $wgEnableParserLimitReporting,
1157  ];
1158  }
1159 
1166  private function initialiseFromUser( $user, $lang ) {
1167  $this->options = self::getDefaults();
1168 
1169  $this->mUser = $user;
1170  $this->options['numberheadings'] = $user->getOption( 'numberheadings' );
1171  $this->options['thumbsize'] = $user->getOption( 'thumbsize' );
1172  $this->options['stubthreshold'] = $user->getStubThreshold();
1173  $this->options['userlang'] = $lang;
1174  }
1175 
1185  public function matches( ParserOptions $other ) {
1186  // Compare most options
1187  $options = array_keys( $this->options );
1188  $options = array_diff( $options, [
1189  'enableLimitReport', // only affects HTML comments
1190  ] );
1191  foreach ( $options as $option ) {
1192  // Resolve any lazy options
1193  $this->lazyLoadOption( $option );
1194  $other->lazyLoadOption( $option );
1195 
1196  $o1 = $this->optionToString( $this->options[$option] );
1197  $o2 = $this->optionToString( $other->options[$option] );
1198  if ( $o1 !== $o2 ) {
1199  return false;
1200  }
1201  }
1202 
1203  // Compare most other fields
1204  $fields = array_keys( get_class_vars( __CLASS__ ) );
1205  $fields = array_diff( $fields, [
1206  'defaults', // static
1207  'lazyOptions', // static
1208  'inCacheKey', // static
1209  'options', // Already checked above
1210  'onAccessCallback', // only used for ParserOutput option tracking
1211  ] );
1212  foreach ( $fields as $field ) {
1213  if ( !is_object( $this->$field ) && $this->$field !== $other->$field ) {
1214  return false;
1215  }
1216  }
1217 
1218  return true;
1219  }
1220 
1226  public function matchesForCacheKey( ParserOptions $other ) {
1227  foreach ( self::allCacheVaryingOptions() as $option ) {
1228  // Populate any lazy options
1229  $this->lazyLoadOption( $option );
1230  $other->lazyLoadOption( $option );
1231 
1232  $o1 = $this->optionToString( $this->options[$option] );
1233  $o2 = $this->optionToString( $other->options[$option] );
1234  if ( $o1 !== $o2 ) {
1235  return false;
1236  }
1237  }
1238 
1239  return true;
1240  }
1241 
1247  public function registerWatcher( $callback ) {
1248  $this->onAccessCallback = $callback;
1249  }
1250 
1259  public function optionUsed( $optionName ) {
1260  if ( $this->onAccessCallback ) {
1261  call_user_func( $this->onAccessCallback, $optionName );
1262  }
1263  }
1264 
1270  public static function allCacheVaryingOptions() {
1271  // Trigger a call to the 'ParserOptionsRegister' hook if it hasn't
1272  // already been called.
1273  if ( self::$defaults === null ) {
1274  self::getDefaults();
1275  }
1276  return array_keys( array_filter( self::$inCacheKey ) );
1277  }
1278 
1284  private function optionToString( $value ) {
1285  if ( $value === true ) {
1286  return '1';
1287  } elseif ( $value === false ) {
1288  return '0';
1289  } elseif ( $value === null ) {
1290  return '';
1291  } elseif ( $value instanceof Language ) {
1292  return $value->getCode();
1293  } elseif ( is_array( $value ) ) {
1294  return '[' . implode( ',', array_map( [ $this, 'optionToString' ], $value ) ) . ']';
1295  } else {
1296  return (string)$value;
1297  }
1298  }
1299 
1312  public function optionsHash( $forOptions, $title = null ) {
1313  global $wgRenderHashAppend;
1314 
1315  $inCacheKey = self::allCacheVaryingOptions();
1316 
1317  // Resolve any lazy options
1318  $lazyOpts = array_intersect( $forOptions, $inCacheKey, array_keys( self::$lazyOptions ) );
1319  foreach ( $lazyOpts as $k ) {
1320  $this->lazyLoadOption( $k );
1321  }
1322 
1324  $defaults = self::getCanonicalOverrides() + self::getDefaults();
1325 
1326  // We only include used options with non-canonical values in the key
1327  // so adding a new option doesn't invalidate the entire parser cache.
1328  // The drawback to this is that changing the default value of an option
1329  // requires manual invalidation of existing cache entries, as mentioned
1330  // in the docs on the relevant methods and hooks.
1331  $values = [];
1332  foreach ( array_intersect( $inCacheKey, $forOptions ) as $option ) {
1333  $v = $this->optionToString( $options[$option] );
1334  $d = $this->optionToString( $defaults[$option] );
1335  if ( $v !== $d ) {
1336  $values[] = "$option=$v";
1337  }
1338  }
1339 
1340  $confstr = $values ? implode( '!', $values ) : 'canonical';
1341 
1342  // add in language specific options, if any
1343  // @todo FIXME: This is just a way of retrieving the url/user preferred variant
1344  if ( !is_null( $title ) ) {
1345  $confstr .= $title->getPageLanguage()->getExtraHashOptions();
1346  } else {
1347  $confstr .=
1348  MediaWikiServices::getInstance()->getContentLanguage()->getExtraHashOptions();
1349  }
1350 
1351  $confstr .= $wgRenderHashAppend;
1352 
1353  if ( $this->mExtraKey != '' ) {
1354  $confstr .= $this->mExtraKey;
1355  }
1356 
1357  // Give a chance for extensions to modify the hash, if they have
1358  // extra options or other effects on the parser cache.
1359  Hooks::run( 'PageRenderingHash', [ &$confstr, $this->getUser(), &$forOptions ] );
1360 
1361  // Make it a valid memcached key fragment
1362  $confstr = str_replace( ' ', '_', $confstr );
1363 
1364  return $confstr;
1365  }
1366 
1372  public function isSafeToCache() {
1373  $defaults = self::getCanonicalOverrides() + self::getDefaults();
1374  foreach ( $this->options as $option => $value ) {
1375  if ( empty( self::$inCacheKey[$option] ) ) {
1376  $v = $this->optionToString( $value );
1377  $d = $this->optionToString( $defaults[$option] );
1378  if ( $v !== $d ) {
1379  return false;
1380  }
1381  }
1382  }
1383  return true;
1384  }
1385 
1396  public function setupFakeRevision( $title, $content, $user ) {
1397  $oldCallback = $this->setCurrentRevisionCallback(
1398  function (
1399  $titleToCheck, $parser = false ) use ( $title, $content, $user, &$oldCallback
1400  ) {
1401  if ( $titleToCheck->equals( $title ) ) {
1402  return new Revision( [
1403  'page' => $title->getArticleID(),
1404  'user_text' => $user->getName(),
1405  'user' => $user->getId(),
1406  'parent_id' => $title->getLatestRevID(),
1407  'title' => $title,
1408  'content' => $content
1409  ] );
1410  } else {
1411  return call_user_func( $oldCallback, $titleToCheck, $parser );
1412  }
1413  }
1414  );
1415 
1416  global $wgHooks;
1417  $wgHooks['TitleExists'][] =
1418  function ( $titleToCheck, &$exists ) use ( $title ) {
1419  if ( $titleToCheck->equals( $title ) ) {
1420  $exists = true;
1421  }
1422  };
1423  end( $wgHooks['TitleExists'] );
1424  $key = key( $wgHooks['TitleExists'] );
1425  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1426  $linkCache->clearBadLink( $title->getPrefixedDBkey() );
1427  return new ScopedCallback( function () use ( $title, $key, $linkCache ) {
1428  global $wgHooks;
1429  unset( $wgHooks['TitleExists'][$key] );
1430  $linkCache->clearLink( $title );
1431  } );
1432  }
1433 }
1434 
setDateFormat( $x)
Date format index.
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
$wgMaxArticleSize
Maximum article size in kilobytes.
$wgAllowSpecialInclusion
Allow special page inclusions such as {{Special:Allpages}}.
getInterfaceMessage()
Parsing an interface message?
static isRealObject( $obj)
Returns a bool value whenever $obj is a stub object.
Definition: StubObject.php:81
$wgAllowExternalImagesFrom
If the above is false, you can specify an exception here.
setInterwikiMagic( $x)
Specify whether to extract interlanguage links.
lazyLoadOption( $name)
getDateFormat()
Date format index.
setSpeculativeRevIdCallback( $x)
Callback to generate a guess for {{REVISIONID}}.
setMaxPPNodeCount( $x)
Maximum number of nodes touched by PPFrame::expand()
getIsPreview()
Parsing the page for a "preview" operation?
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:1982
disableTitleConversion( $x=true)
Whether title conversion should be disabled.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgExpensiveParserFunctionLimit
Maximum number of calls per parse to expensive parser functions such as PAGESINCATEGORY.
getMaxIncludeSize()
Maximum size of template expansions, in bytes.
setTemplateCallback( $x)
Callback for template fetching; first argument to call_user_func().
setOption( $name, $value)
Set an option, generically.
setIsPrintable( $x)
Parsing the printable version of the page?
if(!isset( $args[0])) $lang
getInterwikiMagic()
Whether to extract interlanguage links.
optionsHash( $forOptions, $title=null)
Generate a hash string with the values set on these ParserOptions for the keys given in the array...
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
getNumberHeadings()
Automatically number headings?
$wgEnableParserLimitReporting
Whether to include the NewPP limit report as a HTML comment.
$value
static initDateFormat(ParserOptions $popt)
Lazy initializer for dateFormat.
setAllowExternalImages( $x)
Allow all external images inline?
setMaxGeneratedPPNodeCount( $x)
Maximum number of nodes generated by Preprocessor::preprocessToObj()
getCurrentRevisionCallback()
Callback for current revision fetching; first argument to call_user_func().
getSpeculativeRevIdCallback()
Callback to generate a guess for {{REVISIONID}}.
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message key
Definition: hooks.txt:2151
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
static initSpeculativeRevId(ParserOptions $popt)
Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativeRevId().
getMaxPPNodeCount()
Maximum number of nodes touched by PPFrame::expand()
setAllowUnsafeRawHtml( $x)
If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of...
getMagicPMIDLinks()
Are magic PMID links enabled?
getMagicRFCLinks()
Are magic RFC links enabled?
static callable [] $lazyOptions
Lazy-loaded options.
setWrapOutputClass( $className)
CSS class to use to wrap output from Parser::parse()
getTimestamp()
Timestamp used for {{CURRENTDAY}} etc.
$wgMaxGeneratedPPNodeCount
A complexity limit on template expansion: the maximum number of elements generated by Preprocessor::p...
User $mUser
Stored user object.
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
Definition: hooks.txt:1799
getIsSectionPreview()
Parsing the page for a "preview" operation on a single section?
getThumbSize()
Thumb size preferred by the user.
getCleanSignatures()
Clean up signature texts?
getPreSaveTransform()
Transform wiki markup when saving the page?
Title null $redirectTarget
If the page being parsed is a redirect, this should hold the redirect target.
$wgEnableMagicLinks
Enable the magic links feature of automatically turning ISBN xxx, PMID xxx, RFC xxx into links...
static newCanonical( $context=null, $userLang=null)
Creates a "canonical" ParserOptions object.
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:51
getAllowSpecialInclusion()
Allow inclusion of special pages?
$wgRenderHashAppend
Append a configured value to the parser cache and the sitenotice key so that they can be kept separat...
setupFakeRevision( $title, $content, $user)
Sets a hook to force that a page exists, and sets a current revision callback to return a revision wi...
callable null $onAccessCallback
Function to be called when an option is accessed.
getAllowExternalImages()
Allow all external images inline?
setPreSaveTransform( $x)
Transform wiki markup when saving the page?
$wgLang
Definition: Setup.php:931
$wgHooks['ArticleShow'][]
Definition: hooks.txt:108
getOption( $name)
Fetch an option and track that is was accessed.
setThumbSize( $x)
Thumb size preferred by the user.
setNumberHeadings( $x)
Automatically number headings?
static getDefaults()
Get default option values.
optionToString( $value)
Convert an option to a string value.
getRedirectTarget()
Get the previously-set redirect target.
$wgMaxPPNodeCount
A complexity limit on template expansion: the maximum number of nodes visited by PPFrame::expand() ...
getMaxTemplateDepth()
Maximum recursion depth for templates within templates.
setTargetLanguage( $x)
Target language for the parse.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
setStubThreshold( $x)
Thumb size preferred by the user.
getTemplateCallback()
Callback for template fetching; first argument to call_user_func().
$wgMaxTemplateDepth
Maximum recursion depth for templates within templates.
getUserLangObj()
Get the user language used by the parser for this page and split the parser cache.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
$wgDisableTitleConversion
Whether to enable language variant conversion for links.
setInterfaceMessage( $x)
Parsing an interface message?
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
const HAS_NEWCANONICAL_FROM_CONTEXT
Flag indicating that newCanonical() accepts an IContextSource or the string &#39;canonical&#39;, for back-compat checks from extensions.
setRedirectTarget( $title)
Set the redirect target.
$wgInterwikiMagic
Treat language links as magic connectors, not inline links.
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:216
getTidy()
Use tidy to cleanup output HTML?
getUserLang()
Same as getUserLangObj() but returns a string instead.
string null $mTimestamp
Timestamp used for {{CURRENTDAY}} etc.
static callable [] static array array $options
Current values for all options that are relevant for caching.
setMaxIncludeSize( $x)
Maximum size of template expansions, in bytes.
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
$wgDisableLangConversion
Whether to enable language variant conversion.
static newFromAnon()
Get a ParserOptions object for an anonymous user.
$wgAllowExternalImages
Whether to allow inline image pointing to other websites.
setExternalLinkTarget( $x)
Target attribute for external links.
getWrapOutputClass()
Class to use to wrap output from Parser::parse()
getTargetLanguage()
Target language for the parse.
static getDefaultOption( $opt)
Get a given default option value.
Definition: User.php:1785
optionUsed( $optionName)
Called when an option is accessed.
getStubThreshold()
Thumb size preferred by the user.
static allCacheVaryingOptions()
Return all option keys that vary the options hash.
setCleanSignatures( $x)
Clean up signature texts?
getIsPrintable()
Parsing the printable version of the page?
addExtraKey( $key)
Extra key that should be present in the parser cache key.
getUser()
Current user.
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
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...
getMagicISBNLinks()
Are magic ISBN links enabled?
disableContentConversion( $x=true)
Whether content conversion should be disabled.
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function 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
setOptionLegacy( $name, $value)
Legacy implementation.
$mExtraKey
Appended to the options hash.
getEnableImageWhitelist()
Use the on-wiki external image whitelist?
initialiseFromUser( $user, $lang)
Get user options.
registerWatcher( $callback)
Registers a callback for tracking which ParserOptions which are used.
static callable [] static array $inCacheKey
Specify options that are included in the cache key.
matchesForCacheKey(ParserOptions $other)
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
setExpensiveParserFunctionLimit( $x)
Maximum number of calls per parse to expensive parser functions.
getExternalLinkTarget()
Target attribute for external links.
static array null $defaults
Default values for all options that are relevant for caching.
static newFromUser( $user)
Get a ParserOptions object from a given user.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
setCurrentRevisionCallback( $x)
Callback for current revision fetching; first argument to call_user_func().
getRemoveComments()
Remove HTML comments.
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:2633
getAllowUnsafeRawHtml()
If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of...
__construct( $user=null, $lang=null)
setRemoveComments( $x)
Remove HTML comments.
setAllowSpecialInclusion( $x)
Allow inclusion of special pages?
$wgCleanSignatures
If true, removes (by substituting) templates in signatures.
getMaxPPExpandDepth()
Maximum recursion depth in PPFrame::expand()
setTidy( $x)
Use tidy to cleanup output HTML?
getEnableLimitReport()
Enable limit report in an HTML comment on output.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
isSafeToCache()
Test whether these options are safe to cache.
setTimestamp( $x)
Timestamp used for {{CURRENTDAY}} etc.
getDisableTitleConversion()
Whether title conversion should be disabled.
setIsPreview( $x)
Parsing the page for a "preview" operation?
$wgMaxPPExpandDepth
$wgEnableImageWhitelist
If $wgAllowExternalImages is false, you can allow an on-wiki whitelist of regular expression fragment...
setMaxTemplateDepth( $x)
Maximum recursion depth for templates within templates.
setIsSectionPreview( $x)
Parsing the page for a "preview" operation on a single section?
$wgExternalLinkTarget
Set a default target for external links, e.g.
$content
Definition: pageupdater.txt:72
setUserLang( $x)
Set the user language used by the parser for this page and split the parser cache.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
setAllowExternalImagesFrom( $x)
External images to allow.
setEnableImageWhitelist( $x)
Use the on-wiki external image whitelist?
getSpeculativeRevId()
A guess for {{REVISIONID}}, calculated using the callback provided via setSpeculativeRevIdCallback()...
matches(ParserOptions $other)
Check if these options match that of another options set.
getAllowExternalImagesFrom()
External images to allow.
static getCanonicalOverrides()
Get "canonical" non-default option values.
enableLimitReport( $x=true)
Enable limit report in an HTML comment on output.
getDisableContentConversion()
Whether content conversion should be disabled.
getExpensiveParserFunctionLimit()
Maximum number of calls per parse to expensive parser functions.
getMaxGeneratedPPNodeCount()
Maximum number of nodes generated by Preprocessor::preprocessToObj()