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