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 
921  public function getEditSection() {
922  wfDeprecated( __METHOD__, '1.31' );
923  return true;
924  }
925 
932  public function setEditSection( $x ) {
933  wfDeprecated( __METHOD__, '1.31' );
934  return true;
935  }
936 
947  function setRedirectTarget( $title ) {
948  $this->redirectTarget = $title;
949  }
950 
957  function getRedirectTarget() {
958  return $this->redirectTarget;
959  }
960 
967  public function addExtraKey( $key ) {
968  $this->mExtraKey .= '!' . $key;
969  }
970 
975  public function getUser() {
976  return $this->mUser;
977  }
978 
985  public function __construct( $user = null, $lang = null ) {
986  if ( $user === null ) {
987  global $wgUser;
988  if ( $wgUser === null ) {
989  $user = new User;
990  } else {
991  $user = $wgUser;
992  }
993  }
994  if ( $lang === null ) {
995  global $wgLang;
996  if ( !StubObject::isRealObject( $wgLang ) ) {
997  $wgLang->_unstub();
998  }
999  $lang = $wgLang;
1000  }
1001  $this->initialiseFromUser( $user, $lang );
1002  }
1003 
1011  public static function newFromAnon() {
1012  return new ParserOptions( new User,
1013  MediaWikiServices::getInstance()->getContentLanguage() );
1014  }
1015 
1025  public static function newFromUser( $user ) {
1026  return new ParserOptions( $user );
1027  }
1028 
1038  public static function newFromUserAndLang( User $user, Language $lang ) {
1039  return new ParserOptions( $user, $lang );
1040  }
1041 
1050  public static function newFromContext( IContextSource $context ) {
1051  return new ParserOptions( $context->getUser(), $context->getLanguage() );
1052  }
1053 
1071  public static function newCanonical( $context = null, $userLang = null ) {
1072  if ( $context instanceof IContextSource ) {
1073  $ret = self::newFromContext( $context );
1074  } elseif ( $context === 'canonical' ) {
1075  $ret = self::newFromAnon();
1076  } elseif ( $context instanceof User || $context === null ) {
1077  $ret = new self( $context, $userLang );
1078  } else {
1079  throw new InvalidArgumentException(
1080  '$context must be an IContextSource, the string "canonical", a User, or null'
1081  );
1082  }
1083 
1084  foreach ( self::getCanonicalOverrides() as $k => $v ) {
1085  $ret->setOption( $k, $v );
1086  }
1087  return $ret;
1088  }
1089 
1099  private static function getDefaults() {
1106 
1107  if ( self::$defaults === null ) {
1108  // *UPDATE* ParserOptions::matches() if any of this changes as needed
1109  self::$defaults = [
1110  'dateformat' => null,
1111  'tidy' => true,
1112  'interfaceMessage' => false,
1113  'targetLanguage' => null,
1114  'removeComments' => true,
1115  'enableLimitReport' => false,
1116  'preSaveTransform' => true,
1117  'isPreview' => false,
1118  'isSectionPreview' => false,
1119  'printable' => false,
1120  'allowUnsafeRawHtml' => true,
1121  'wrapclass' => 'mw-parser-output',
1122  'currentRevisionCallback' => [ Parser::class, 'statelessFetchRevision' ],
1123  'templateCallback' => [ Parser::class, 'statelessFetchTemplate' ],
1124  'speculativeRevIdCallback' => null,
1125  'speculativeRevId' => null,
1126  ];
1127 
1128  Hooks::run( 'ParserOptionsRegister', [
1129  &self::$defaults,
1130  &self::$inCacheKey,
1131  &self::$lazyOptions,
1132  ] );
1133 
1134  ksort( self::$inCacheKey );
1135  }
1136 
1137  // Unit tests depend on being able to modify the globals at will
1138  return self::$defaults + [
1139  'interwikiMagic' => $wgInterwikiMagic,
1140  'allowExternalImages' => $wgAllowExternalImages,
1141  'allowExternalImagesFrom' => $wgAllowExternalImagesFrom,
1142  'enableImageWhitelist' => $wgEnableImageWhitelist,
1143  'allowSpecialInclusion' => $wgAllowSpecialInclusion,
1144  'maxIncludeSize' => $wgMaxArticleSize * 1024,
1145  'maxPPNodeCount' => $wgMaxPPNodeCount,
1146  'maxGeneratedPPNodeCount' => $wgMaxGeneratedPPNodeCount,
1147  'maxPPExpandDepth' => $wgMaxPPExpandDepth,
1148  'maxTemplateDepth' => $wgMaxTemplateDepth,
1149  'expensiveParserFunctionLimit' => $wgExpensiveParserFunctionLimit,
1150  'externalLinkTarget' => $wgExternalLinkTarget,
1151  'cleanSignatures' => $wgCleanSignatures,
1152  'disableContentConversion' => $wgDisableLangConversion,
1153  'disableTitleConversion' => $wgDisableLangConversion || $wgDisableTitleConversion,
1154  'magicISBNLinks' => $wgEnableMagicLinks['ISBN'],
1155  'magicPMIDLinks' => $wgEnableMagicLinks['PMID'],
1156  'magicRFCLinks' => $wgEnableMagicLinks['RFC'],
1157  'numberheadings' => User::getDefaultOption( 'numberheadings' ),
1158  'thumbsize' => User::getDefaultOption( 'thumbsize' ),
1159  'stubthreshold' => 0,
1160  'userlang' => MediaWikiServices::getInstance()->getContentLanguage(),
1161  ];
1162  }
1163 
1173  private static function getCanonicalOverrides() {
1175 
1176  return [
1177  'enableLimitReport' => $wgEnableParserLimitReporting,
1178  ];
1179  }
1180 
1187  private function initialiseFromUser( $user, $lang ) {
1188  $this->options = self::getDefaults();
1189 
1190  $this->mUser = $user;
1191  $this->options['numberheadings'] = $user->getOption( 'numberheadings' );
1192  $this->options['thumbsize'] = $user->getOption( 'thumbsize' );
1193  $this->options['stubthreshold'] = $user->getStubThreshold();
1194  $this->options['userlang'] = $lang;
1195  }
1196 
1206  public function matches( ParserOptions $other ) {
1207  // Compare most options
1208  $options = array_keys( $this->options );
1209  $options = array_diff( $options, [
1210  'enableLimitReport', // only affects HTML comments
1211  ] );
1212  foreach ( $options as $option ) {
1213  // Resolve any lazy options
1214  $this->lazyLoadOption( $option );
1215  $other->lazyLoadOption( $option );
1216 
1217  $o1 = $this->optionToString( $this->options[$option] );
1218  $o2 = $this->optionToString( $other->options[$option] );
1219  if ( $o1 !== $o2 ) {
1220  return false;
1221  }
1222  }
1223 
1224  // Compare most other fields
1225  $fields = array_keys( get_class_vars( __CLASS__ ) );
1226  $fields = array_diff( $fields, [
1227  'defaults', // static
1228  'lazyOptions', // static
1229  'inCacheKey', // static
1230  'options', // Already checked above
1231  'onAccessCallback', // only used for ParserOutput option tracking
1232  ] );
1233  foreach ( $fields as $field ) {
1234  if ( !is_object( $this->$field ) && $this->$field !== $other->$field ) {
1235  return false;
1236  }
1237  }
1238 
1239  return true;
1240  }
1241 
1247  public function matchesForCacheKey( ParserOptions $other ) {
1248  foreach ( self::allCacheVaryingOptions() as $option ) {
1249  // Populate any lazy options
1250  $this->lazyLoadOption( $option );
1251  $other->lazyLoadOption( $option );
1252 
1253  $o1 = $this->optionToString( $this->options[$option] );
1254  $o2 = $this->optionToString( $other->options[$option] );
1255  if ( $o1 !== $o2 ) {
1256  return false;
1257  }
1258  }
1259 
1260  return true;
1261  }
1262 
1268  public function registerWatcher( $callback ) {
1269  $this->onAccessCallback = $callback;
1270  }
1271 
1280  public function optionUsed( $optionName ) {
1281  if ( $this->onAccessCallback ) {
1282  call_user_func( $this->onAccessCallback, $optionName );
1283  }
1284  }
1285 
1291  public static function allCacheVaryingOptions() {
1292  // Trigger a call to the 'ParserOptionsRegister' hook if it hasn't
1293  // already been called.
1294  if ( self::$defaults === null ) {
1295  self::getDefaults();
1296  }
1297  return array_keys( array_filter( self::$inCacheKey ) );
1298  }
1299 
1305  private function optionToString( $value ) {
1306  if ( $value === true ) {
1307  return '1';
1308  } elseif ( $value === false ) {
1309  return '0';
1310  } elseif ( $value === null ) {
1311  return '';
1312  } elseif ( $value instanceof Language ) {
1313  return $value->getCode();
1314  } elseif ( is_array( $value ) ) {
1315  return '[' . implode( ',', array_map( [ $this, 'optionToString' ], $value ) ) . ']';
1316  } else {
1317  return (string)$value;
1318  }
1319  }
1320 
1333  public function optionsHash( $forOptions, $title = null ) {
1334  global $wgRenderHashAppend;
1335 
1336  $inCacheKey = self::allCacheVaryingOptions();
1337 
1338  // Resolve any lazy options
1339  $lazyOpts = array_intersect( $forOptions, $inCacheKey, array_keys( self::$lazyOptions ) );
1340  foreach ( $lazyOpts as $k ) {
1341  $this->lazyLoadOption( $k );
1342  }
1343 
1345  $defaults = self::getCanonicalOverrides() + self::getDefaults();
1346 
1347  // We only include used options with non-canonical values in the key
1348  // so adding a new option doesn't invalidate the entire parser cache.
1349  // The drawback to this is that changing the default value of an option
1350  // requires manual invalidation of existing cache entries, as mentioned
1351  // in the docs on the relevant methods and hooks.
1352  $values = [];
1353  foreach ( array_intersect( $inCacheKey, $forOptions ) as $option ) {
1354  $v = $this->optionToString( $options[$option] );
1355  $d = $this->optionToString( $defaults[$option] );
1356  if ( $v !== $d ) {
1357  $values[] = "$option=$v";
1358  }
1359  }
1360 
1361  $confstr = $values ? implode( '!', $values ) : 'canonical';
1362 
1363  // add in language specific options, if any
1364  // @todo FIXME: This is just a way of retrieving the url/user preferred variant
1365  if ( !is_null( $title ) ) {
1366  $confstr .= $title->getPageLanguage()->getExtraHashOptions();
1367  } else {
1368  $confstr .=
1369  MediaWikiServices::getInstance()->getContentLanguage()->getExtraHashOptions();
1370  }
1371 
1372  $confstr .= $wgRenderHashAppend;
1373 
1374  if ( $this->mExtraKey != '' ) {
1375  $confstr .= $this->mExtraKey;
1376  }
1377 
1378  // Give a chance for extensions to modify the hash, if they have
1379  // extra options or other effects on the parser cache.
1380  Hooks::run( 'PageRenderingHash', [ &$confstr, $this->getUser(), &$forOptions ] );
1381 
1382  // Make it a valid memcached key fragment
1383  $confstr = str_replace( ' ', '_', $confstr );
1384 
1385  return $confstr;
1386  }
1387 
1393  public function isSafeToCache() {
1394  $defaults = self::getCanonicalOverrides() + self::getDefaults();
1395  foreach ( $this->options as $option => $value ) {
1396  if ( empty( self::$inCacheKey[$option] ) ) {
1397  $v = $this->optionToString( $value );
1398  $d = $this->optionToString( $defaults[$option] );
1399  if ( $v !== $d ) {
1400  return false;
1401  }
1402  }
1403  }
1404  return true;
1405  }
1406 
1417  public function setupFakeRevision( $title, $content, $user ) {
1418  $oldCallback = $this->setCurrentRevisionCallback(
1419  function (
1420  $titleToCheck, $parser = false ) use ( $title, $content, $user, &$oldCallback
1421  ) {
1422  if ( $titleToCheck->equals( $title ) ) {
1423  return new Revision( [
1424  'page' => $title->getArticleID(),
1425  'user_text' => $user->getName(),
1426  'user' => $user->getId(),
1427  'parent_id' => $title->getLatestRevID(),
1428  'title' => $title,
1429  'content' => $content
1430  ] );
1431  } else {
1432  return call_user_func( $oldCallback, $titleToCheck, $parser );
1433  }
1434  }
1435  );
1436 
1437  global $wgHooks;
1438  $wgHooks['TitleExists'][] =
1439  function ( $titleToCheck, &$exists ) use ( $title ) {
1440  if ( $titleToCheck->equals( $title ) ) {
1441  $exists = true;
1442  }
1443  };
1444  end( $wgHooks['TitleExists'] );
1445  $key = key( $wgHooks['TitleExists'] );
1446  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1447  $linkCache->clearBadLink( $title->getPrefixedDBkey() );
1448  return new ScopedCallback( function () use ( $title, $key, $linkCache ) {
1449  global $wgHooks;
1450  unset( $wgHooks['TitleExists'][$key] );
1451  $linkCache->clearLink( $title );
1452  } );
1453  }
1454 }
1455 
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:48
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:875
$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:215
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.
getEditSection()
Create "edit section" links?
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:1809
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.
setEditSection( $x)
Create "edit section" links?
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()