MediaWiki  1.33.0
ParserOptions.php
Go to the documentation of this file.
1 <?php
25 use Wikimedia\ScopedCallback;
26 
43 
50 
56  private static $defaults = null;
57 
62  private static $lazyOptions = [
63  'dateformat' => [ __CLASS__, 'initDateFormat' ],
64  'speculativeRevId' => [ __CLASS__, 'initSpeculativeRevId' ],
65  ];
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 
105  private $onAccessCallback = null;
106 
113  private $redirectTarget = null;
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  if ( isset( self::$lazyOptions[$name] ) && $this->options[$name] === null ) {
137  $this->options[$name] = call_user_func( self::$lazyOptions[$name], $this, $name );
138  }
139  if ( !empty( self::$inCacheKey[$name] ) ) {
140  $this->optionUsed( $name );
141  }
142  return $this->options[$name];
143  }
144 
153  public function setOption( $name, $value ) {
154  if ( !array_key_exists( $name, $this->options ) ) {
155  throw new InvalidArgumentException( "Unknown parser option $name" );
156  }
157  $old = $this->options[$name];
158  $this->options[$name] = $value;
159  return $old;
160  }
161 
170  protected function setOptionLegacy( $name, $value ) {
171  if ( !array_key_exists( $name, $this->options ) ) {
172  throw new InvalidArgumentException( "Unknown parser option $name" );
173  }
174  return wfSetVar( $this->options[$name], $value );
175  }
176 
185  public function getInterwikiMagic() {
186  return $this->getOption( 'interwikiMagic' );
187  }
188 
194  public function setInterwikiMagic( $x ) {
195  return $this->setOptionLegacy( 'interwikiMagic', $x );
196  }
197 
202  public function getAllowExternalImages() {
203  return $this->getOption( 'allowExternalImages' );
204  }
205 
211  public function setAllowExternalImages( $x ) {
212  return $this->setOptionLegacy( 'allowExternalImages', $x );
213  }
214 
222  public function getAllowExternalImagesFrom() {
223  return $this->getOption( 'allowExternalImagesFrom' );
224  }
225 
234  public function setAllowExternalImagesFrom( $x ) {
235  return $this->setOptionLegacy( 'allowExternalImagesFrom', $x );
236  }
237 
242  public function getEnableImageWhitelist() {
243  return $this->getOption( 'enableImageWhitelist' );
244  }
245 
251  public function setEnableImageWhitelist( $x ) {
252  return $this->setOptionLegacy( 'enableImageWhitelist', $x );
253  }
254 
259  public function getNumberHeadings() {
260  return $this->getOption( 'numberheadings' );
261  }
262 
268  public function setNumberHeadings( $x ) {
269  return $this->setOptionLegacy( 'numberheadings', $x );
270  }
271 
276  public function getAllowSpecialInclusion() {
277  return $this->getOption( 'allowSpecialInclusion' );
278  }
279 
285  public function setAllowSpecialInclusion( $x ) {
286  return $this->setOptionLegacy( 'allowSpecialInclusion', $x );
287  }
288 
293  public function getTidy() {
294  return $this->getOption( 'tidy' );
295  }
296 
302  public function setTidy( $x ) {
303  return $this->setOptionLegacy( 'tidy', $x );
304  }
305 
310  public function getInterfaceMessage() {
311  return $this->getOption( 'interfaceMessage' );
312  }
313 
319  public function setInterfaceMessage( $x ) {
320  return $this->setOptionLegacy( 'interfaceMessage', $x );
321  }
322 
327  public function getTargetLanguage() {
328  return $this->getOption( 'targetLanguage' );
329  }
330 
336  public function setTargetLanguage( $x ) {
337  return $this->setOption( 'targetLanguage', $x );
338  }
339 
344  public function getMaxIncludeSize() {
345  return $this->getOption( 'maxIncludeSize' );
346  }
347 
353  public function setMaxIncludeSize( $x ) {
354  return $this->setOptionLegacy( 'maxIncludeSize', $x );
355  }
356 
361  public function getMaxPPNodeCount() {
362  return $this->getOption( 'maxPPNodeCount' );
363  }
364 
370  public function setMaxPPNodeCount( $x ) {
371  return $this->setOptionLegacy( 'maxPPNodeCount', $x );
372  }
373 
378  public function getMaxGeneratedPPNodeCount() {
379  return $this->getOption( 'maxGeneratedPPNodeCount' );
380  }
381 
387  public function setMaxGeneratedPPNodeCount( $x ) {
388  return $this->setOptionLegacy( 'maxGeneratedPPNodeCount', $x );
389  }
390 
395  public function getMaxPPExpandDepth() {
396  return $this->getOption( 'maxPPExpandDepth' );
397  }
398 
403  public function getMaxTemplateDepth() {
404  return $this->getOption( 'maxTemplateDepth' );
405  }
406 
412  public function setMaxTemplateDepth( $x ) {
413  return $this->setOptionLegacy( 'maxTemplateDepth', $x );
414  }
415 
422  return $this->getOption( 'expensiveParserFunctionLimit' );
423  }
424 
431  public function setExpensiveParserFunctionLimit( $x ) {
432  return $this->setOptionLegacy( 'expensiveParserFunctionLimit', $x );
433  }
434 
440  public function getRemoveComments() {
441  return $this->getOption( 'removeComments' );
442  }
443 
450  public function setRemoveComments( $x ) {
451  return $this->setOptionLegacy( 'removeComments', $x );
452  }
453 
458  public function getEnableLimitReport() {
459  return $this->getOption( 'enableLimitReport' );
460  }
461 
467  public function enableLimitReport( $x = true ) {
468  return $this->setOptionLegacy( 'enableLimitReport', $x );
469  }
470 
476  public function getCleanSignatures() {
477  return $this->getOption( 'cleanSignatures' );
478  }
479 
486  public function setCleanSignatures( $x ) {
487  return $this->setOptionLegacy( 'cleanSignatures', $x );
488  }
489 
494  public function getExternalLinkTarget() {
495  return $this->getOption( 'externalLinkTarget' );
496  }
497 
503  public function setExternalLinkTarget( $x ) {
504  return $this->setOptionLegacy( 'externalLinkTarget', $x );
505  }
506 
511  public function getDisableContentConversion() {
512  return $this->getOption( 'disableContentConversion' );
513  }
514 
520  public function disableContentConversion( $x = true ) {
521  return $this->setOptionLegacy( 'disableContentConversion', $x );
522  }
523 
528  public function getDisableTitleConversion() {
529  return $this->getOption( 'disableTitleConversion' );
530  }
531 
537  public function disableTitleConversion( $x = true ) {
538  return $this->setOptionLegacy( 'disableTitleConversion', $x );
539  }
540 
545  public function getThumbSize() {
546  return $this->getOption( 'thumbsize' );
547  }
548 
554  public function setThumbSize( $x ) {
555  return $this->setOptionLegacy( 'thumbsize', $x );
556  }
557 
562  public function getStubThreshold() {
563  return $this->getOption( 'stubthreshold' );
564  }
565 
571  public function setStubThreshold( $x ) {
572  return $this->setOptionLegacy( 'stubthreshold', $x );
573  }
574 
579  public function getIsPreview() {
580  return $this->getOption( 'isPreview' );
581  }
582 
588  public function setIsPreview( $x ) {
589  return $this->setOptionLegacy( 'isPreview', $x );
590  }
591 
596  public function getIsSectionPreview() {
597  return $this->getOption( 'isSectionPreview' );
598  }
599 
605  public function setIsSectionPreview( $x ) {
606  return $this->setOptionLegacy( 'isSectionPreview', $x );
607  }
608 
613  public function getIsPrintable() {
614  return $this->getOption( 'printable' );
615  }
616 
622  public function setIsPrintable( $x ) {
623  return $this->setOptionLegacy( 'printable', $x );
624  }
625 
630  public function getPreSaveTransform() {
631  return $this->getOption( 'preSaveTransform' );
632  }
633 
639  public function setPreSaveTransform( $x ) {
640  return $this->setOptionLegacy( 'preSaveTransform', $x );
641  }
642 
647  public function getDateFormat() {
648  return $this->getOption( 'dateformat' );
649  }
650 
656  private static function initDateFormat( ParserOptions $popt ) {
657  return $popt->mUser->getDatePreference();
658  }
659 
665  public function setDateFormat( $x ) {
666  return $this->setOptionLegacy( 'dateformat', $x );
667  }
668 
686  public function getUserLangObj() {
687  return $this->getOption( 'userlang' );
688  }
689 
702  public function getUserLang() {
703  return $this->getUserLangObj()->getCode();
704  }
705 
711  public function setUserLang( $x ) {
712  if ( is_string( $x ) ) {
713  $x = Language::factory( $x );
714  }
715 
716  return $this->setOptionLegacy( 'userlang', $x );
717  }
718 
724  public function getMagicISBNLinks() {
725  return $this->getOption( 'magicISBNLinks' );
726  }
727 
733  public function getMagicPMIDLinks() {
734  return $this->getOption( 'magicPMIDLinks' );
735  }
736 
742  public function getMagicRFCLinks() {
743  return $this->getOption( 'magicRFCLinks' );
744  }
745 
760  public function getAllowUnsafeRawHtml() {
761  return $this->getOption( 'allowUnsafeRawHtml' );
762  }
763 
772  public function setAllowUnsafeRawHtml( $x ) {
773  return $this->setOptionLegacy( 'allowUnsafeRawHtml', $x );
774  }
775 
781  public function getWrapOutputClass() {
782  return $this->getOption( 'wrapclass' );
783  }
784 
792  public function setWrapOutputClass( $className ) {
793  if ( $className === true ) { // DWIM, they probably want the default class name
794  $className = 'mw-parser-output';
795  }
796  if ( $className === false ) {
797  wfDeprecated( __METHOD__ . '( false )', '1.31' );
798  }
799  return $this->setOption( 'wrapclass', $className );
800  }
801 
807  public function getCurrentRevisionCallback() {
808  return $this->getOption( 'currentRevisionCallback' );
809  }
810 
817  public function setCurrentRevisionCallback( $x ) {
818  return $this->setOptionLegacy( 'currentRevisionCallback', $x );
819  }
820 
825  public function getTemplateCallback() {
826  return $this->getOption( 'templateCallback' );
827  }
828 
834  public function setTemplateCallback( $x ) {
835  return $this->setOptionLegacy( 'templateCallback', $x );
836  }
837 
848  public function getSpeculativeRevId() {
849  return $this->getOption( 'speculativeRevId' );
850  }
851 
858  private static function initSpeculativeRevId( ParserOptions $popt ) {
859  $cb = $popt->getOption( 'speculativeRevIdCallback' );
860  $id = $cb ? $cb() : null;
861 
862  // returning null would result in this being re-called every access
863  return $id ?? false;
864  }
865 
872  public function getSpeculativeRevIdCallback() {
873  return $this->getOption( 'speculativeRevIdCallback' );
874  }
875 
882  public function setSpeculativeRevIdCallback( $x ) {
883  $this->setOption( 'speculativeRevId', null ); // reset
884  return $this->setOptionLegacy( 'speculativeRevIdCallback', $x );
885  }
886 
893  public function getTimestamp() {
894  if ( !isset( $this->mTimestamp ) ) {
895  $this->mTimestamp = wfTimestampNow();
896  }
897  return $this->mTimestamp;
898  }
899 
905  public function setTimestamp( $x ) {
906  return wfSetVar( $this->mTimestamp, $x );
907  }
908 
914  public function getEditSection() {
915  wfDeprecated( __METHOD__, '1.31' );
916  return true;
917  }
918 
925  public function setEditSection( $x ) {
926  wfDeprecated( __METHOD__, '1.31' );
927  return true;
928  }
929 
940  function setRedirectTarget( $title ) {
941  $this->redirectTarget = $title;
942  }
943 
950  function getRedirectTarget() {
951  return $this->redirectTarget;
952  }
953 
960  public function addExtraKey( $key ) {
961  $this->mExtraKey .= '!' . $key;
962  }
963 
968  public function getUser() {
969  return $this->mUser;
970  }
971 
978  public function __construct( $user = null, $lang = null ) {
979  if ( $user === null ) {
980  global $wgUser;
981  if ( $wgUser === null ) {
982  $user = new User;
983  } else {
984  $user = $wgUser;
985  }
986  }
987  if ( $lang === null ) {
988  global $wgLang;
989  if ( !StubObject::isRealObject( $wgLang ) ) {
990  $wgLang->_unstub();
991  }
992  $lang = $wgLang;
993  }
994  $this->initialiseFromUser( $user, $lang );
995  }
996 
1004  public static function newFromAnon() {
1005  return new ParserOptions( new User,
1006  MediaWikiServices::getInstance()->getContentLanguage() );
1007  }
1008 
1018  public static function newFromUser( $user ) {
1019  return new ParserOptions( $user );
1020  }
1021 
1031  public static function newFromUserAndLang( User $user, Language $lang ) {
1032  return new ParserOptions( $user, $lang );
1033  }
1034 
1043  public static function newFromContext( IContextSource $context ) {
1044  return new ParserOptions( $context->getUser(), $context->getLanguage() );
1045  }
1046 
1064  public static function newCanonical( $context = null, $userLang = null ) {
1065  if ( $context instanceof IContextSource ) {
1067  } elseif ( $context === 'canonical' ) {
1068  $ret = self::newFromAnon();
1069  } elseif ( $context instanceof User || $context === null ) {
1070  $ret = new self( $context, $userLang );
1071  } else {
1072  throw new InvalidArgumentException(
1073  '$context must be an IContextSource, the string "canonical", a User, or null'
1074  );
1075  }
1076 
1077  foreach ( self::getCanonicalOverrides() as $k => $v ) {
1078  $ret->setOption( $k, $v );
1079  }
1080  return $ret;
1081  }
1082 
1092  private static function getDefaults() {
1099 
1100  if ( self::$defaults === null ) {
1101  // *UPDATE* ParserOptions::matches() if any of this changes as needed
1102  self::$defaults = [
1103  'dateformat' => null,
1104  'tidy' => true,
1105  'interfaceMessage' => false,
1106  'targetLanguage' => null,
1107  'removeComments' => true,
1108  'enableLimitReport' => false,
1109  'preSaveTransform' => true,
1110  'isPreview' => false,
1111  'isSectionPreview' => false,
1112  'printable' => false,
1113  'allowUnsafeRawHtml' => true,
1114  'wrapclass' => 'mw-parser-output',
1115  'currentRevisionCallback' => [ Parser::class, 'statelessFetchRevision' ],
1116  'templateCallback' => [ Parser::class, 'statelessFetchTemplate' ],
1117  'speculativeRevIdCallback' => null,
1118  'speculativeRevId' => null,
1119  ];
1120 
1121  Hooks::run( 'ParserOptionsRegister', [
1122  &self::$defaults,
1123  &self::$inCacheKey,
1124  &self::$lazyOptions,
1125  ] );
1126 
1127  ksort( self::$inCacheKey );
1128  }
1129 
1130  // Unit tests depend on being able to modify the globals at will
1131  return self::$defaults + [
1132  'interwikiMagic' => $wgInterwikiMagic,
1133  'allowExternalImages' => $wgAllowExternalImages,
1134  'allowExternalImagesFrom' => $wgAllowExternalImagesFrom,
1135  'enableImageWhitelist' => $wgEnableImageWhitelist,
1136  'allowSpecialInclusion' => $wgAllowSpecialInclusion,
1137  'maxIncludeSize' => $wgMaxArticleSize * 1024,
1138  'maxPPNodeCount' => $wgMaxPPNodeCount,
1139  'maxGeneratedPPNodeCount' => $wgMaxGeneratedPPNodeCount,
1140  'maxPPExpandDepth' => $wgMaxPPExpandDepth,
1141  'maxTemplateDepth' => $wgMaxTemplateDepth,
1142  'expensiveParserFunctionLimit' => $wgExpensiveParserFunctionLimit,
1143  'externalLinkTarget' => $wgExternalLinkTarget,
1144  'cleanSignatures' => $wgCleanSignatures,
1145  'disableContentConversion' => $wgDisableLangConversion,
1146  'disableTitleConversion' => $wgDisableLangConversion || $wgDisableTitleConversion,
1147  'magicISBNLinks' => $wgEnableMagicLinks['ISBN'],
1148  'magicPMIDLinks' => $wgEnableMagicLinks['PMID'],
1149  'magicRFCLinks' => $wgEnableMagicLinks['RFC'],
1150  'numberheadings' => User::getDefaultOption( 'numberheadings' ),
1151  'thumbsize' => User::getDefaultOption( 'thumbsize' ),
1152  'stubthreshold' => 0,
1153  'userlang' => MediaWikiServices::getInstance()->getContentLanguage(),
1154  ];
1155  }
1156 
1166  private static function getCanonicalOverrides() {
1168 
1169  return [
1170  'enableLimitReport' => $wgEnableParserLimitReporting,
1171  ];
1172  }
1173 
1180  private function initialiseFromUser( $user, $lang ) {
1181  $this->options = self::getDefaults();
1182 
1183  $this->mUser = $user;
1184  $this->options['numberheadings'] = $user->getOption( 'numberheadings' );
1185  $this->options['thumbsize'] = $user->getOption( 'thumbsize' );
1186  $this->options['stubthreshold'] = $user->getStubThreshold();
1187  $this->options['userlang'] = $lang;
1188  }
1189 
1199  public function matches( ParserOptions $other ) {
1200  // Populate lazy options
1201  foreach ( self::$lazyOptions as $name => $callback ) {
1202  if ( $this->options[$name] === null ) {
1203  $this->options[$name] = call_user_func( $callback, $this, $name );
1204  }
1205  if ( $other->options[$name] === null ) {
1206  $other->options[$name] = call_user_func( $callback, $other, $name );
1207  }
1208  }
1209 
1210  // Compare most options
1211  $options = array_keys( $this->options );
1212  $options = array_diff( $options, [
1213  'enableLimitReport', // only affects HTML comments
1214  ] );
1215  foreach ( $options as $option ) {
1216  $o1 = $this->optionToString( $this->options[$option] );
1217  $o2 = $this->optionToString( $other->options[$option] );
1218  if ( $o1 !== $o2 ) {
1219  return false;
1220  }
1221  }
1222 
1223  // Compare most other fields
1224  $fields = array_keys( get_class_vars( __CLASS__ ) );
1225  $fields = array_diff( $fields, [
1226  'defaults', // static
1227  'lazyOptions', // static
1228  'inCacheKey', // static
1229  'options', // Already checked above
1230  'onAccessCallback', // only used for ParserOutput option tracking
1231  ] );
1232  foreach ( $fields as $field ) {
1233  if ( !is_object( $this->$field ) && $this->$field !== $other->$field ) {
1234  return false;
1235  }
1236  }
1237 
1238  return true;
1239  }
1240 
1246  public function registerWatcher( $callback ) {
1247  $this->onAccessCallback = $callback;
1248  }
1249 
1258  public function optionUsed( $optionName ) {
1259  if ( $this->onAccessCallback ) {
1260  call_user_func( $this->onAccessCallback, $optionName );
1261  }
1262  }
1263 
1269  public static function allCacheVaryingOptions() {
1270  // Trigger a call to the 'ParserOptionsRegister' hook if it hasn't
1271  // already been called.
1272  if ( self::$defaults === null ) {
1274  }
1275  return array_keys( array_filter( self::$inCacheKey ) );
1276  }
1277 
1283  private function optionToString( $value ) {
1284  if ( $value === true ) {
1285  return '1';
1286  } elseif ( $value === false ) {
1287  return '0';
1288  } elseif ( $value === null ) {
1289  return '';
1290  } elseif ( $value instanceof Language ) {
1291  return $value->getCode();
1292  } elseif ( is_array( $value ) ) {
1293  return '[' . implode( ',', array_map( [ $this, 'optionToString' ], $value ) ) . ']';
1294  } else {
1295  return (string)$value;
1296  }
1297  }
1298 
1311  public function optionsHash( $forOptions, $title = null ) {
1312  global $wgRenderHashAppend;
1313 
1315 
1316  // Resolve any lazy options
1317  foreach ( array_intersect( $forOptions, $inCacheKey, array_keys( self::$lazyOptions ) ) as $k ) {
1318  if ( $this->options[$k] === null ) {
1319  $this->options[$k] = call_user_func( self::$lazyOptions[$k], $this, $k );
1320  }
1321  }
1322 
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() {
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 
User\getDefaultOption
static getDefaultOption( $opt)
Get a given default option value.
Definition: User.php:1818
ParserOptions\setMaxIncludeSize
setMaxIncludeSize( $x)
Maximum size of template expansions, in bytes.
Definition: ParserOptions.php:353
ParserOptions\getMagicPMIDLinks
getMagicPMIDLinks()
Are magic PMID links enabled?
Definition: ParserOptions.php:733
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:42
ParserOptions\setOptionLegacy
setOptionLegacy( $name, $value)
Legacy implementation.
Definition: ParserOptions.php:170
ParserOptions\getAllowExternalImagesFrom
getAllowExternalImagesFrom()
External images to allow.
Definition: ParserOptions.php:222
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
ParserOptions\getWrapOutputClass
getWrapOutputClass()
Class to use to wrap output from Parser::parse()
Definition: ParserOptions.php:781
ParserOptions\getExpensiveParserFunctionLimit
getExpensiveParserFunctionLimit()
Maximum number of calls per parse to expensive parser functions.
Definition: ParserOptions.php:421
ParserOptions\setTidy
setTidy( $x)
Use tidy to cleanup output HTML?
Definition: ParserOptions.php:302
ParserOptions\getIsSectionPreview
getIsSectionPreview()
Parsing the page for a "preview" operation on a single section?
Definition: ParserOptions.php:596
$wgMaxArticleSize
$wgMaxArticleSize
Maximum article size in kilobytes.
Definition: DefaultSettings.php:2286
$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:2636
ParserOptions\getRemoveComments
getRemoveComments()
Remove HTML comments.
Definition: ParserOptions.php:440
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:772
ParserOptions\disableContentConversion
disableContentConversion( $x=true)
Whether content conversion should be disabled.
Definition: ParserOptions.php:520
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
ParserOptions\initialiseFromUser
initialiseFromUser( $user, $lang)
Get user options.
Definition: ParserOptions.php:1180
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:1633
$wgMaxTemplateDepth
$wgMaxTemplateDepth
Maximum recursion depth for templates within templates.
Definition: DefaultSettings.php:4153
ParserOptions\getIsPreview
getIsPreview()
Parsing the page for a "preview" operation?
Definition: ParserOptions.php:579
ParserOptions\getDisableTitleConversion
getDisableTitleConversion()
Whether title conversion should be disabled.
Definition: ParserOptions.php:528
ParserOptions\setAllowExternalImages
setAllowExternalImages( $x)
Allow all external images inline?
Definition: ParserOptions.php:211
ParserOptions\setTemplateCallback
setTemplateCallback( $x)
Callback for template fetching; first argument to call_user_func().
Definition: ParserOptions.php:834
ParserOptions\setIsPreview
setIsPreview( $x)
Parsing the page for a "preview" operation?
Definition: ParserOptions.php:588
ParserOptions\setTargetLanguage
setTargetLanguage( $x)
Target language for the parse.
Definition: ParserOptions.php:336
ParserOptions\getInterfaceMessage
getInterfaceMessage()
Parsing an interface message?
Definition: ParserOptions.php:310
ParserOptions\setIsSectionPreview
setIsSectionPreview( $x)
Parsing the page for a "preview" operation on a single section?
Definition: ParserOptions.php:605
ParserOptions\getSpeculativeRevId
getSpeculativeRevId()
A guess for {{REVISIONID}}, calculated using the callback provided via setSpeculativeRevIdCallback().
Definition: ParserOptions.php:848
ParserOptions\newFromAnon
static newFromAnon()
Get a ParserOptions object for an anonymous user.
Definition: ParserOptions.php:1004
ParserOptions\setEnableImageWhitelist
setEnableImageWhitelist( $x)
Use the on-wiki external image whitelist?
Definition: ParserOptions.php:251
$wgDisableTitleConversion
$wgDisableTitleConversion
Whether to enable language variant conversion for links.
Definition: DefaultSettings.php:3090
ParserOptions\setWrapOutputClass
setWrapOutputClass( $className)
CSS class to use to wrap output from Parser::parse()
Definition: ParserOptions.php:792
ParserOptions\setSpeculativeRevIdCallback
setSpeculativeRevIdCallback( $x)
Callback to generate a guess for {{REVISIONID}}.
Definition: ParserOptions.php:882
ParserOptions\disableTitleConversion
disableTitleConversion( $x=true)
Whether title conversion should be disabled.
Definition: ParserOptions.php:537
ParserOptions\initDateFormat
static initDateFormat(ParserOptions $popt)
Lazy initializer for dateFormat.
Definition: ParserOptions.php:656
ParserOptions\getIsPrintable
getIsPrintable()
Parsing the printable version of the page?
Definition: ParserOptions.php:613
ParserOptions\setMaxGeneratedPPNodeCount
setMaxGeneratedPPNodeCount( $x)
Maximum number of nodes generated by Preprocessor::preprocessToObj()
Definition: ParserOptions.php:387
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:817
ParserOptions\$inCacheKey
static array $inCacheKey
Specify options that are included in the cache key.
Definition: ParserOptions.php:71
ParserOptions\setMaxTemplateDepth
setMaxTemplateDepth( $x)
Maximum recursion depth for templates within templates.
Definition: ParserOptions.php:412
ParserOptions\getMagicRFCLinks
getMagicRFCLinks()
Are magic RFC links enabled?
Definition: ParserOptions.php:742
ParserOptions\getUserLangObj
getUserLangObj()
Get the user language used by the parser for this page and split the parser cache.
Definition: ParserOptions.php:686
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:1246
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:1396
ParserOptions\getDateFormat
getDateFormat()
Date format index.
Definition: ParserOptions.php:647
ParserOptions\HAS_NEWCANONICAL_FROM_CONTEXT
const HAS_NEWCANONICAL_FROM_CONTEXT
Flag indicating that newCanonical() accepts an IContextSource or the string 'canonical',...
Definition: ParserOptions.php:49
Revision
Definition: Revision.php:40
ParserOptions\setOption
setOption( $name, $value)
Set an option, generically.
Definition: ParserOptions.php:153
ParserOptions\initSpeculativeRevId
static initSpeculativeRevId(ParserOptions $popt)
Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativeRevId().
Definition: ParserOptions.php:858
ParserOptions\setNumberHeadings
setNumberHeadings( $x)
Automatically number headings?
Definition: ParserOptions.php:268
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
ParserOptions\getCanonicalOverrides
static getCanonicalOverrides()
Get "canonical" non-default option values.
Definition: ParserOptions.php:1166
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1078
ParserOptions\getRedirectTarget
getRedirectTarget()
Get the previously-set redirect target.
Definition: ParserOptions.php:950
ParserOptions\newFromUserAndLang
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
Definition: ParserOptions.php:1031
ParserOptions\setUserLang
setUserLang( $x)
Set the user language used by the parser for this page and split the parser cache.
Definition: ParserOptions.php:711
ParserOptions\getAllowSpecialInclusion
getAllowSpecialInclusion()
Allow inclusion of special pages?
Definition: ParserOptions.php:276
$wgAllowExternalImagesFrom
$wgAllowExternalImagesFrom
If the above is false, you can specify an exception here.
Definition: DefaultSettings.php:4199
ParserOptions\getTidy
getTidy()
Use tidy to cleanup output HTML?
Definition: ParserOptions.php:293
ParserOptions\getMaxIncludeSize
getMaxIncludeSize()
Maximum size of template expansions, in bytes.
Definition: ParserOptions.php:344
ParserOptions\$mTimestamp
string null $mTimestamp
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:91
$wgLang
$wgLang
Definition: Setup.php:875
$wgExpensiveParserFunctionLimit
$wgExpensiveParserFunctionLimit
Maximum number of calls per parse to expensive parser functions such as PAGESINCATEGORY.
Definition: DefaultSettings.php:4308
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\setThumbSize
setThumbSize( $x)
Thumb size preferred by the user.
Definition: ParserOptions.php:554
ParserOptions\getEnableImageWhitelist
getEnableImageWhitelist()
Use the on-wiki external image whitelist?
Definition: ParserOptions.php:242
$wgInterwikiMagic
$wgInterwikiMagic
Treat language links as magic connectors, not inline links.
Definition: DefaultSettings.php:2934
ParserOptions\setExternalLinkTarget
setExternalLinkTarget( $x)
Target attribute for external links.
Definition: ParserOptions.php:503
$parser
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
Definition: hooks.txt:1802
ParserOptions\setDateFormat
setDateFormat( $x)
Date format index.
Definition: ParserOptions.php:665
ParserOptions\getTargetLanguage
getTargetLanguage()
Target language for the parse.
Definition: ParserOptions.php:327
ParserOptions\setAllowSpecialInclusion
setAllowSpecialInclusion( $x)
Allow inclusion of special pages?
Definition: ParserOptions.php:285
$wgMaxPPExpandDepth
$wgMaxPPExpandDepth
Definition: DefaultSettings.php:4158
ParserOptions\getDefaults
static getDefaults()
Get default option values.
Definition: ParserOptions.php:1092
ParserOptions\getExternalLinkTarget
getExternalLinkTarget()
Target attribute for external links.
Definition: ParserOptions.php:494
ParserOptions\$onAccessCallback
callable null $onAccessCallback
Function to be called when an option is accessed.
Definition: ParserOptions.php:105
$wgEnableMagicLinks
$wgEnableMagicLinks
Enable the magic links feature of automatically turning ISBN xxx, PMID xxx, RFC xxx into links.
Definition: DefaultSettings.php:4333
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1941
ParserOptions\getStubThreshold
getStubThreshold()
Thumb size preferred by the user.
Definition: ParserOptions.php:562
$wgExternalLinkTarget
$wgExternalLinkTarget
Set a default target for external links, e.g.
Definition: DefaultSettings.php:4261
ParserOptions\$options
array $options
Current values for all options that are relevant for caching.
Definition: ParserOptions.php:84
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
ParserOptions\getUserLang
getUserLang()
Same as getUserLangObj() but returns a string instead.
Definition: ParserOptions.php:702
$wgDisableLangConversion
$wgDisableLangConversion
Whether to enable language variant conversion.
Definition: DefaultSettings.php:3085
ParserOptions\getPreSaveTransform
getPreSaveTransform()
Transform wiki markup when saving the page?
Definition: ParserOptions.php:630
ParserOptions\setStubThreshold
setStubThreshold( $x)
Thumb size preferred by the user.
Definition: ParserOptions.php:571
ParserOptions\getOption
getOption( $name)
Fetch an option, generically.
Definition: ParserOptions.php:131
ParserOptions\$mExtraKey
$mExtraKey
Appended to the options hash.
Definition: ParserOptions.php:118
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:760
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
key
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:2154
ParserOptions\getDisableContentConversion
getDisableContentConversion()
Whether content conversion should be disabled.
Definition: ParserOptions.php:511
ParserOptions\optionToString
optionToString( $value)
Convert an option to a string value.
Definition: ParserOptions.php:1283
ParserOptions\optionUsed
optionUsed( $optionName)
Called when an option is accessed.
Definition: ParserOptions.php:1258
ParserOptions\setTimestamp
setTimestamp( $x)
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:905
$value
$value
Definition: styleTest.css.php:49
ParserOptions\setCleanSignatures
setCleanSignatures( $x)
Clean up signature texts?
Definition: ParserOptions.php:486
ParserOptions\getSpeculativeRevIdCallback
getSpeculativeRevIdCallback()
Callback to generate a guess for {{REVISIONID}}.
Definition: ParserOptions.php:872
ParserOptions\newFromContext
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
Definition: ParserOptions.php:1043
ParserOptions\getCurrentRevisionCallback
getCurrentRevisionCallback()
Callback for current revision fetching; first argument to call_user_func().
Definition: ParserOptions.php:807
$wgEnableParserLimitReporting
$wgEnableParserLimitReporting
Whether to include the NewPP limit report as a HTML comment.
Definition: DefaultSettings.php:7359
ParserOptions\getTemplateCallback
getTemplateCallback()
Callback for template fetching; first argument to call_user_func().
Definition: ParserOptions.php:825
ParserOptions\newCanonical
static newCanonical( $context=null, $userLang=null)
Creates a "canonical" ParserOptions object.
Definition: ParserOptions.php:1064
$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:1985
ParserOptions\setRemoveComments
setRemoveComments( $x)
Remove HTML comments.
Definition: ParserOptions.php:450
ParserOptions\setInterwikiMagic
setInterwikiMagic( $x)
Specify whether to extract interlanguage links.
Definition: ParserOptions.php:194
ParserOptions\setRedirectTarget
setRedirectTarget( $title)
Set the redirect target.
Definition: ParserOptions.php:940
ParserOptions\setExpensiveParserFunctionLimit
setExpensiveParserFunctionLimit( $x)
Maximum number of calls per parse to expensive parser functions.
Definition: ParserOptions.php:431
ParserOptions\getTimestamp
getTimestamp()
Timestamp used for {{CURRENTDAY}} etc.
Definition: ParserOptions.php:893
ParserOptions\setMaxPPNodeCount
setMaxPPNodeCount( $x)
Maximum number of nodes touched by PPFrame::expand()
Definition: ParserOptions.php:370
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:476
ParserOptions\$redirectTarget
Title null $redirectTarget
If the page being parsed is a redirect, this should hold the redirect target.
Definition: ParserOptions.php:113
ParserOptions\setAllowExternalImagesFrom
setAllowExternalImagesFrom( $x)
External images to allow.
Definition: ParserOptions.php:234
ParserOptions\matches
matches(ParserOptions $other)
Check if these options match that of another options set.
Definition: ParserOptions.php:1199
ParserOptions\enableLimitReport
enableLimitReport( $x=true)
Enable limit report in an HTML comment on output.
Definition: ParserOptions.php:467
Title
Represents a title within MediaWiki.
Definition: Title.php:40
ParserOptions\__construct
__construct( $user=null, $lang=null)
Definition: ParserOptions.php:978
ParserOptions\getInterwikiMagic
getInterwikiMagic()
Whether to extract interlanguage links.
Definition: ParserOptions.php:185
ParserOptions\$lazyOptions
static callable[] $lazyOptions
Lazy-loaded options.
Definition: ParserOptions.php:62
ParserOptions\$mUser
User $mUser
Stored user object.
Definition: ParserOptions.php:98
ParserOptions\setInterfaceMessage
setInterfaceMessage( $x)
Parsing an interface message?
Definition: ParserOptions.php:319
ParserOptions\$defaults
static array null $defaults
Default values for all options that are relevant for caching.
Definition: ParserOptions.php:56
$wgHooks
$wgHooks['ArticleShow'][]
Definition: hooks.txt:108
ParserOptions\allCacheVaryingOptions
static allCacheVaryingOptions()
Return all option keys that vary the options hash.
Definition: ParserOptions.php:1269
$wgCleanSignatures
$wgCleanSignatures
If true, removes (by substituting) templates in signatures.
Definition: DefaultSettings.php:4180
ParserOptions\getUser
getUser()
Current user.
Definition: ParserOptions.php:968
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:545
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:724
ParserOptions\setIsPrintable
setIsPrintable( $x)
Parsing the printable version of the page?
Definition: ParserOptions.php:622
ParserOptions\getMaxPPNodeCount
getMaxPPNodeCount()
Maximum number of nodes touched by PPFrame::expand()
Definition: ParserOptions.php:361
$wgRenderHashAppend
$wgRenderHashAppend
Append a configured value to the parser cache and the sitenotice key so that they can be kept separat...
Definition: DefaultSettings.php:2635
$wgMaxGeneratedPPNodeCount
$wgMaxGeneratedPPNodeCount
A complexity limit on template expansion: the maximum number of elements generated by Preprocessor::p...
Definition: DefaultSettings.php:4145
ParserOptions\setEditSection
setEditSection( $x)
Create "edit section" links?
Definition: ParserOptions.php:925
$content
$content
Definition: pageupdater.txt:72
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:215
ParserOptions\getMaxGeneratedPPNodeCount
getMaxGeneratedPPNodeCount()
Maximum number of nodes generated by Preprocessor::preprocessToObj()
Definition: ParserOptions.php:378
ParserOptions\getMaxPPExpandDepth
getMaxPPExpandDepth()
Maximum recursion depth in PPFrame::expand()
Definition: ParserOptions.php:395
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:458
ParserOptions\getNumberHeadings
getNumberHeadings()
Automatically number headings?
Definition: ParserOptions.php:259
ParserOptions\isSafeToCache
isSafeToCache()
Test whether these options are safe to cache.
Definition: ParserOptions.php:1372
MediaWikiServices
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
ParserOptions\getMaxTemplateDepth
getMaxTemplateDepth()
Maximum recursion depth for templates within templates.
Definition: ParserOptions.php:403
ParserOptions\setPreSaveTransform
setPreSaveTransform( $x)
Transform wiki markup when saving the page?
Definition: ParserOptions.php:639
ParserOptions\getEditSection
getEditSection()
Create "edit section" links?
Definition: ParserOptions.php:914
options
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
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:48
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
$wgMaxPPNodeCount
$wgMaxPPNodeCount
A complexity limit on template expansion: the maximum number of nodes visited by PPFrame::expand()
Definition: DefaultSettings.php:4134
Language
Internationalisation code.
Definition: Language.php:36
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:1311
ParserOptions\getAllowExternalImages
getAllowExternalImages()
Allow all external images inline?
Definition: ParserOptions.php:202
ParserOptions\newFromUser
static newFromUser( $user)
Get a ParserOptions object from a given user.
Definition: ParserOptions.php:1018
$wgAllowExternalImages
$wgAllowExternalImages
Whether to allow inline image pointing to other websites.
Definition: DefaultSettings.php:4185
$wgEnableImageWhitelist
$wgEnableImageWhitelist
If $wgAllowExternalImages is false, you can allow an on-wiki whitelist of regular expression fragment...
Definition: DefaultSettings.php:4212
ParserOptions\addExtraKey
addExtraKey( $key)
Extra key that should be present in the parser cache key.
Definition: ParserOptions.php:960
$wgAllowSpecialInclusion
$wgAllowSpecialInclusion
Allow special page inclusions such as {{Special:Allpages}}.
Definition: DefaultSettings.php:7917