MediaWiki REL1_34
ParserOptions.php
Go to the documentation of this file.
1<?php
25use Wikimedia\ScopedCallback;
26
43
50
56 private static $defaults = null;
57
62 private static $lazyOptions = [
63 'dateformat' => [ __CLASS__, 'initDateFormat' ],
64 'speculativeRevId' => [ __CLASS__, 'initSpeculativeRevId' ],
65 'speculativePageId' => [ __CLASS__, 'initSpeculativePageId' ],
66 ];
67
72 private static $inCacheKey = [
73 'dateformat' => true,
74 'numberheadings' => true,
75 'thumbsize' => true,
76 'stubthreshold' => true,
77 'printable' => true,
78 'userlang' => true,
79 ];
80
85 private $options;
86
92 private $mTimestamp;
93
99 private $mUser;
100
106 private $onAccessCallback = null;
107
114 private $redirectTarget = null;
115
119 private $mExtraKey = '';
120
127 public function getOption( $name ) {
128 if ( !array_key_exists( $name, $this->options ) ) {
129 throw new InvalidArgumentException( "Unknown parser option $name" );
130 }
131
132 $this->lazyLoadOption( $name );
133 if ( !empty( self::$inCacheKey[$name] ) ) {
134 $this->optionUsed( $name );
135 }
136 return $this->options[$name];
137 }
138
142 private function lazyLoadOption( $name ) {
143 if ( isset( self::$lazyOptions[$name] ) && $this->options[$name] === null ) {
144 $this->options[$name] = call_user_func( self::$lazyOptions[$name], $this, $name );
145 }
146 }
147
156 public function setOption( $name, $value ) {
157 if ( !array_key_exists( $name, $this->options ) ) {
158 throw new InvalidArgumentException( "Unknown parser option $name" );
159 }
160 $old = $this->options[$name];
161 $this->options[$name] = $value;
162 return $old;
163 }
164
173 protected function setOptionLegacy( $name, $value ) {
174 if ( !array_key_exists( $name, $this->options ) ) {
175 throw new InvalidArgumentException( "Unknown parser option $name" );
176 }
177 return wfSetVar( $this->options[$name], $value );
178 }
179
188 public function getInterwikiMagic() {
189 return $this->getOption( 'interwikiMagic' );
190 }
191
197 public function setInterwikiMagic( $x ) {
198 return $this->setOptionLegacy( 'interwikiMagic', $x );
199 }
200
205 public function getAllowExternalImages() {
206 return $this->getOption( 'allowExternalImages' );
207 }
208
214 public function setAllowExternalImages( $x ) {
215 return $this->setOptionLegacy( 'allowExternalImages', $x );
216 }
217
225 public function getAllowExternalImagesFrom() {
226 return $this->getOption( 'allowExternalImagesFrom' );
227 }
228
237 public function setAllowExternalImagesFrom( $x ) {
238 return $this->setOptionLegacy( 'allowExternalImagesFrom', $x );
239 }
240
245 public function getEnableImageWhitelist() {
246 return $this->getOption( 'enableImageWhitelist' );
247 }
248
254 public function setEnableImageWhitelist( $x ) {
255 return $this->setOptionLegacy( 'enableImageWhitelist', $x );
256 }
257
262 public function getNumberHeadings() {
263 return $this->getOption( 'numberheadings' );
264 }
265
271 public function setNumberHeadings( $x ) {
272 return $this->setOptionLegacy( 'numberheadings', $x );
273 }
274
279 public function getAllowSpecialInclusion() {
280 return $this->getOption( 'allowSpecialInclusion' );
281 }
282
288 public function setAllowSpecialInclusion( $x ) {
289 return $this->setOptionLegacy( 'allowSpecialInclusion', $x );
290 }
291
296 public function getTidy() {
297 return $this->getOption( 'tidy' );
298 }
299
305 public function setTidy( $x ) {
306 return $this->setOptionLegacy( 'tidy', $x );
307 }
308
313 public function getInterfaceMessage() {
314 return $this->getOption( 'interfaceMessage' );
315 }
316
322 public function setInterfaceMessage( $x ) {
323 return $this->setOptionLegacy( 'interfaceMessage', $x );
324 }
325
330 public function getTargetLanguage() {
331 return $this->getOption( 'targetLanguage' );
332 }
333
339 public function setTargetLanguage( $x ) {
340 return $this->setOption( 'targetLanguage', $x );
341 }
342
347 public function getMaxIncludeSize() {
348 return $this->getOption( 'maxIncludeSize' );
349 }
350
356 public function setMaxIncludeSize( $x ) {
357 return $this->setOptionLegacy( 'maxIncludeSize', $x );
358 }
359
364 public function getMaxPPNodeCount() {
365 return $this->getOption( 'maxPPNodeCount' );
366 }
367
373 public function setMaxPPNodeCount( $x ) {
374 return $this->setOptionLegacy( 'maxPPNodeCount', $x );
375 }
376
381 public function getMaxGeneratedPPNodeCount() {
382 return $this->getOption( 'maxGeneratedPPNodeCount' );
383 }
384
390 public function setMaxGeneratedPPNodeCount( $x ) {
391 return $this->setOptionLegacy( 'maxGeneratedPPNodeCount', $x );
392 }
393
398 public function getMaxPPExpandDepth() {
399 return $this->getOption( 'maxPPExpandDepth' );
400 }
401
406 public function getMaxTemplateDepth() {
407 return $this->getOption( 'maxTemplateDepth' );
408 }
409
415 public function setMaxTemplateDepth( $x ) {
416 return $this->setOptionLegacy( 'maxTemplateDepth', $x );
417 }
418
425 return $this->getOption( 'expensiveParserFunctionLimit' );
426 }
427
434 public function setExpensiveParserFunctionLimit( $x ) {
435 return $this->setOptionLegacy( 'expensiveParserFunctionLimit', $x );
436 }
437
443 public function getRemoveComments() {
444 return $this->getOption( 'removeComments' );
445 }
446
453 public function setRemoveComments( $x ) {
454 return $this->setOptionLegacy( 'removeComments', $x );
455 }
456
461 public function getEnableLimitReport() {
462 return $this->getOption( 'enableLimitReport' );
463 }
464
470 public function enableLimitReport( $x = true ) {
471 return $this->setOptionLegacy( 'enableLimitReport', $x );
472 }
473
479 public function getCleanSignatures() {
480 return $this->getOption( 'cleanSignatures' );
481 }
482
489 public function setCleanSignatures( $x ) {
490 return $this->setOptionLegacy( 'cleanSignatures', $x );
491 }
492
497 public function getExternalLinkTarget() {
498 return $this->getOption( 'externalLinkTarget' );
499 }
500
506 public function setExternalLinkTarget( $x ) {
507 return $this->setOptionLegacy( 'externalLinkTarget', $x );
508 }
509
514 public function getDisableContentConversion() {
515 return $this->getOption( 'disableContentConversion' );
516 }
517
523 public function disableContentConversion( $x = true ) {
524 return $this->setOptionLegacy( 'disableContentConversion', $x );
525 }
526
531 public function getDisableTitleConversion() {
532 return $this->getOption( 'disableTitleConversion' );
533 }
534
540 public function disableTitleConversion( $x = true ) {
541 return $this->setOptionLegacy( 'disableTitleConversion', $x );
542 }
543
548 public function getThumbSize() {
549 return $this->getOption( 'thumbsize' );
550 }
551
557 public function setThumbSize( $x ) {
558 return $this->setOptionLegacy( 'thumbsize', $x );
559 }
560
565 public function getStubThreshold() {
566 return $this->getOption( 'stubthreshold' );
567 }
568
574 public function setStubThreshold( $x ) {
575 return $this->setOptionLegacy( 'stubthreshold', $x );
576 }
577
582 public function getIsPreview() {
583 return $this->getOption( 'isPreview' );
584 }
585
591 public function setIsPreview( $x ) {
592 return $this->setOptionLegacy( 'isPreview', $x );
593 }
594
599 public function getIsSectionPreview() {
600 return $this->getOption( 'isSectionPreview' );
601 }
602
608 public function setIsSectionPreview( $x ) {
609 return $this->setOptionLegacy( 'isSectionPreview', $x );
610 }
611
616 public function getIsPrintable() {
617 return $this->getOption( 'printable' );
618 }
619
625 public function setIsPrintable( $x ) {
626 return $this->setOptionLegacy( 'printable', $x );
627 }
628
633 public function getPreSaveTransform() {
634 return $this->getOption( 'preSaveTransform' );
635 }
636
642 public function setPreSaveTransform( $x ) {
643 return $this->setOptionLegacy( 'preSaveTransform', $x );
644 }
645
650 public function getDateFormat() {
651 return $this->getOption( 'dateformat' );
652 }
653
659 private static function initDateFormat( ParserOptions $popt ) {
660 return $popt->mUser->getDatePreference();
661 }
662
668 public function setDateFormat( $x ) {
669 return $this->setOptionLegacy( 'dateformat', $x );
670 }
671
689 public function getUserLangObj() {
690 return $this->getOption( 'userlang' );
691 }
692
705 public function getUserLang() {
706 return $this->getUserLangObj()->getCode();
707 }
708
714 public function setUserLang( $x ) {
715 if ( is_string( $x ) ) {
716 $x = Language::factory( $x );
717 }
718
719 return $this->setOptionLegacy( 'userlang', $x );
720 }
721
727 public function getMagicISBNLinks() {
728 return $this->getOption( 'magicISBNLinks' );
729 }
730
736 public function getMagicPMIDLinks() {
737 return $this->getOption( 'magicPMIDLinks' );
738 }
739
745 public function getMagicRFCLinks() {
746 return $this->getOption( 'magicRFCLinks' );
747 }
748
763 public function getAllowUnsafeRawHtml() {
764 return $this->getOption( 'allowUnsafeRawHtml' );
765 }
766
775 public function setAllowUnsafeRawHtml( $x ) {
776 return $this->setOptionLegacy( 'allowUnsafeRawHtml', $x );
777 }
778
784 public function getWrapOutputClass() {
785 return $this->getOption( 'wrapclass' );
786 }
787
795 public function setWrapOutputClass( $className ) {
796 if ( $className === true ) { // DWIM, they probably want the default class name
797 $className = 'mw-parser-output';
798 }
799 if ( $className === false ) {
800 wfDeprecated( __METHOD__ . '( false )', '1.31' );
801 }
802 return $this->setOption( 'wrapclass', $className );
803 }
804
810 public function getCurrentRevisionCallback() {
811 return $this->getOption( 'currentRevisionCallback' );
812 }
813
820 public function setCurrentRevisionCallback( $x ) {
821 return $this->setOptionLegacy( 'currentRevisionCallback', $x );
822 }
823
828 public function getTemplateCallback() {
829 return $this->getOption( 'templateCallback' );
830 }
831
837 public function setTemplateCallback( $x ) {
838 return $this->setOptionLegacy( 'templateCallback', $x );
839 }
840
851 public function getSpeculativeRevId() {
852 return $this->getOption( 'speculativeRevId' );
853 }
854
865 public function getSpeculativePageId() {
866 return $this->getOption( 'speculativePageId' );
867 }
868
875 private static function initSpeculativeRevId( ParserOptions $popt ) {
876 $cb = $popt->getOption( 'speculativeRevIdCallback' );
877 $id = $cb ? $cb() : null;
878
879 // returning null would result in this being re-called every access
880 return $id ?? false;
881 }
882
889 private static function initSpeculativePageId( ParserOptions $popt ) {
890 $cb = $popt->getOption( 'speculativePageIdCallback' );
891 $id = $cb ? $cb() : null;
892
893 // returning null would result in this being re-called every access
894 return $id ?? false;
895 }
896
903 public function setSpeculativeRevIdCallback( $x ) {
904 $this->setOption( 'speculativeRevId', null ); // reset
905 return $this->setOption( 'speculativeRevIdCallback', $x );
906 }
907
914 public function setSpeculativePageIdCallback( $x ) {
915 $this->setOption( 'speculativePageId', null ); // reset
916 return $this->setOption( 'speculativePageIdCallback', $x );
917 }
918
923 public function getTimestamp() {
924 if ( !isset( $this->mTimestamp ) ) {
925 $this->mTimestamp = wfTimestampNow();
926 }
927 return $this->mTimestamp;
928 }
929
935 public function setTimestamp( $x ) {
936 return wfSetVar( $this->mTimestamp, $x );
937 }
938
950 $this->redirectTarget = $title;
951 }
952
959 function getRedirectTarget() {
960 return $this->redirectTarget;
961 }
962
969 public function addExtraKey( $key ) {
970 $this->mExtraKey .= '!' . $key;
971 }
972
977 public function getUser() {
978 return $this->mUser;
979 }
980
987 public function __construct( $user = null, $lang = null ) {
988 if ( $user === null ) {
989 global $wgUser;
990 if ( $wgUser === null ) {
991 $user = new User;
992 } else {
993 $user = $wgUser;
994 }
995 }
996 if ( $lang === null ) {
997 global $wgLang;
998 if ( !StubObject::isRealObject( $wgLang ) ) {
999 $wgLang->_unstub();
1000 }
1001 $lang = $wgLang;
1002 }
1003 $this->initialiseFromUser( $user, $lang );
1004 }
1005
1013 public static function newFromAnon() {
1014 return new ParserOptions( new User,
1015 MediaWikiServices::getInstance()->getContentLanguage() );
1016 }
1017
1027 public static function newFromUser( $user ) {
1028 return new ParserOptions( $user );
1029 }
1030
1040 public static function newFromUserAndLang( User $user, Language $lang ) {
1041 return new ParserOptions( $user, $lang );
1042 }
1043
1052 public static function newFromContext( IContextSource $context ) {
1053 return new ParserOptions( $context->getUser(), $context->getLanguage() );
1054 }
1055
1073 public static function newCanonical( $context = null, $userLang = null ) {
1074 if ( $context instanceof IContextSource ) {
1075 $ret = self::newFromContext( $context );
1076 } elseif ( $context === 'canonical' ) {
1077 $ret = self::newFromAnon();
1078 } elseif ( $context instanceof User || $context === null ) {
1079 $ret = new self( $context, $userLang );
1080 } else {
1081 throw new InvalidArgumentException(
1082 '$context must be an IContextSource, the string "canonical", a User, or null'
1083 );
1084 }
1085
1086 foreach ( self::getCanonicalOverrides() as $k => $v ) {
1087 $ret->setOption( $k, $v );
1088 }
1089 return $ret;
1090 }
1091
1101 private static function getDefaults() {
1108
1109 if ( self::$defaults === null ) {
1110 // *UPDATE* ParserOptions::matches() if any of this changes as needed
1111 self::$defaults = [
1112 'dateformat' => null,
1113 'tidy' => true,
1114 'interfaceMessage' => false,
1115 'targetLanguage' => null,
1116 'removeComments' => true,
1117 'enableLimitReport' => false,
1118 'preSaveTransform' => true,
1119 'isPreview' => false,
1120 'isSectionPreview' => false,
1121 'printable' => false,
1122 'allowUnsafeRawHtml' => true,
1123 'wrapclass' => 'mw-parser-output',
1124 'currentRevisionCallback' => [ Parser::class, 'statelessFetchRevision' ],
1125 'templateCallback' => [ Parser::class, 'statelessFetchTemplate' ],
1126 'speculativeRevIdCallback' => null,
1127 'speculativeRevId' => null,
1128 'speculativePageIdCallback' => null,
1129 'speculativePageId' => null,
1130 ];
1131
1132 Hooks::run( 'ParserOptionsRegister', [
1133 &self::$defaults,
1134 &self::$inCacheKey,
1135 &self::$lazyOptions,
1136 ] );
1137
1138 ksort( self::$inCacheKey );
1139 }
1140
1141 // Unit tests depend on being able to modify the globals at will
1142 return self::$defaults + [
1143 'interwikiMagic' => $wgInterwikiMagic,
1144 'allowExternalImages' => $wgAllowExternalImages,
1145 'allowExternalImagesFrom' => $wgAllowExternalImagesFrom,
1146 'enableImageWhitelist' => $wgEnableImageWhitelist,
1147 'allowSpecialInclusion' => $wgAllowSpecialInclusion,
1148 'maxIncludeSize' => $wgMaxArticleSize * 1024,
1149 'maxPPNodeCount' => $wgMaxPPNodeCount,
1150 'maxGeneratedPPNodeCount' => $wgMaxGeneratedPPNodeCount,
1151 'maxPPExpandDepth' => $wgMaxPPExpandDepth,
1152 'maxTemplateDepth' => $wgMaxTemplateDepth,
1153 'expensiveParserFunctionLimit' => $wgExpensiveParserFunctionLimit,
1154 'externalLinkTarget' => $wgExternalLinkTarget,
1155 'cleanSignatures' => $wgCleanSignatures,
1156 'disableContentConversion' => $wgDisableLangConversion,
1157 'disableTitleConversion' => $wgDisableLangConversion || $wgDisableTitleConversion,
1158 'magicISBNLinks' => $wgEnableMagicLinks['ISBN'],
1159 'magicPMIDLinks' => $wgEnableMagicLinks['PMID'],
1160 'magicRFCLinks' => $wgEnableMagicLinks['RFC'],
1161 'numberheadings' => User::getDefaultOption( 'numberheadings' ),
1162 'thumbsize' => User::getDefaultOption( 'thumbsize' ),
1163 'stubthreshold' => 0,
1164 'userlang' => MediaWikiServices::getInstance()->getContentLanguage(),
1165 ];
1166 }
1167
1177 private static function getCanonicalOverrides() {
1179
1180 return [
1181 'enableLimitReport' => $wgEnableParserLimitReporting,
1182 ];
1183 }
1184
1191 private function initialiseFromUser( $user, $lang ) {
1192 $this->options = self::getDefaults();
1193
1194 $this->mUser = $user;
1195 $this->options['numberheadings'] = $user->getOption( 'numberheadings' );
1196 $this->options['thumbsize'] = $user->getOption( 'thumbsize' );
1197 $this->options['stubthreshold'] = $user->getStubThreshold();
1198 $this->options['userlang'] = $lang;
1199 }
1200
1210 public function matches( ParserOptions $other ) {
1211 // Compare most options
1212 $options = array_keys( $this->options );
1213 $options = array_diff( $options, [
1214 'enableLimitReport', // only affects HTML comments
1215 ] );
1216 foreach ( $options as $option ) {
1217 // Resolve any lazy options
1218 $this->lazyLoadOption( $option );
1219 $other->lazyLoadOption( $option );
1220
1221 $o1 = $this->optionToString( $this->options[$option] );
1222 $o2 = $this->optionToString( $other->options[$option] );
1223 if ( $o1 !== $o2 ) {
1224 return false;
1225 }
1226 }
1227
1228 // Compare most other fields
1229 $fields = array_keys( get_class_vars( __CLASS__ ) );
1230 $fields = array_diff( $fields, [
1231 'defaults', // static
1232 'lazyOptions', // static
1233 'inCacheKey', // static
1234 'options', // Already checked above
1235 'onAccessCallback', // only used for ParserOutput option tracking
1236 ] );
1237 foreach ( $fields as $field ) {
1238 if ( !is_object( $this->$field ) && $this->$field !== $other->$field ) {
1239 return false;
1240 }
1241 }
1242
1243 return true;
1244 }
1245
1251 public function matchesForCacheKey( ParserOptions $other ) {
1252 foreach ( self::allCacheVaryingOptions() as $option ) {
1253 // Populate any lazy options
1254 $this->lazyLoadOption( $option );
1255 $other->lazyLoadOption( $option );
1256
1257 $o1 = $this->optionToString( $this->options[$option] );
1258 $o2 = $this->optionToString( $other->options[$option] );
1259 if ( $o1 !== $o2 ) {
1260 return false;
1261 }
1262 }
1263
1264 return true;
1265 }
1266
1272 public function registerWatcher( $callback ) {
1273 $this->onAccessCallback = $callback;
1274 }
1275
1284 public function optionUsed( $optionName ) {
1285 if ( $this->onAccessCallback ) {
1286 call_user_func( $this->onAccessCallback, $optionName );
1287 }
1288 }
1289
1295 public static function allCacheVaryingOptions() {
1296 // Trigger a call to the 'ParserOptionsRegister' hook if it hasn't
1297 // already been called.
1298 if ( self::$defaults === null ) {
1299 self::getDefaults();
1300 }
1301 return array_keys( array_filter( self::$inCacheKey ) );
1302 }
1303
1309 private function optionToString( $value ) {
1310 if ( $value === true ) {
1311 return '1';
1312 } elseif ( $value === false ) {
1313 return '0';
1314 } elseif ( $value === null ) {
1315 return '';
1316 } elseif ( $value instanceof Language ) {
1317 return $value->getCode();
1318 } elseif ( is_array( $value ) ) {
1319 return '[' . implode( ',', array_map( [ $this, 'optionToString' ], $value ) ) . ']';
1320 } else {
1321 return (string)$value;
1322 }
1323 }
1324
1337 public function optionsHash( $forOptions, $title = null ) {
1338 global $wgRenderHashAppend;
1339
1340 $inCacheKey = self::allCacheVaryingOptions();
1341
1342 // Resolve any lazy options
1343 $lazyOpts = array_intersect( $forOptions, $inCacheKey, array_keys( self::$lazyOptions ) );
1344 foreach ( $lazyOpts as $k ) {
1345 $this->lazyLoadOption( $k );
1346 }
1347
1348 $options = $this->options;
1349 $defaults = self::getCanonicalOverrides() + self::getDefaults();
1350
1351 // We only include used options with non-canonical values in the key
1352 // so adding a new option doesn't invalidate the entire parser cache.
1353 // The drawback to this is that changing the default value of an option
1354 // requires manual invalidation of existing cache entries, as mentioned
1355 // in the docs on the relevant methods and hooks.
1356 $values = [];
1357 foreach ( array_intersect( $inCacheKey, $forOptions ) as $option ) {
1358 $v = $this->optionToString( $options[$option] );
1359 $d = $this->optionToString( $defaults[$option] );
1360 if ( $v !== $d ) {
1361 $values[] = "$option=$v";
1362 }
1363 }
1364
1365 $confstr = $values ? implode( '!', $values ) : 'canonical';
1366
1367 // add in language specific options, if any
1368 // @todo FIXME: This is just a way of retrieving the url/user preferred variant
1369 if ( !is_null( $title ) ) {
1370 $confstr .= $title->getPageLanguage()->getExtraHashOptions();
1371 } else {
1372 $confstr .=
1373 MediaWikiServices::getInstance()->getContentLanguage()->getExtraHashOptions();
1374 }
1375
1376 $confstr .= $wgRenderHashAppend;
1377
1378 if ( $this->mExtraKey != '' ) {
1379 $confstr .= $this->mExtraKey;
1380 }
1381
1382 // Give a chance for extensions to modify the hash, if they have
1383 // extra options or other effects on the parser cache.
1384 Hooks::run( 'PageRenderingHash', [ &$confstr, $this->getUser(), &$forOptions ] );
1385
1386 // Make it a valid memcached key fragment
1387 $confstr = str_replace( ' ', '_', $confstr );
1388
1389 return $confstr;
1390 }
1391
1397 public function isSafeToCache() {
1398 $defaults = self::getCanonicalOverrides() + self::getDefaults();
1399 foreach ( $this->options as $option => $value ) {
1400 if ( empty( self::$inCacheKey[$option] ) ) {
1401 $v = $this->optionToString( $value );
1402 $d = $this->optionToString( $defaults[$option] );
1403 if ( $v !== $d ) {
1404 return false;
1405 }
1406 }
1407 }
1408 return true;
1409 }
1410
1421 public function setupFakeRevision( $title, $content, $user ) {
1422 $oldCallback = $this->setCurrentRevisionCallback(
1423 function (
1424 $titleToCheck, $parser = false ) use ( $title, $content, $user, &$oldCallback
1425 ) {
1426 if ( $titleToCheck->equals( $title ) ) {
1427 return new Revision( [
1428 'page' => $title->getArticleID(),
1429 'user_text' => $user->getName(),
1430 'user' => $user->getId(),
1431 'parent_id' => $title->getLatestRevID(),
1432 'title' => $title,
1433 'content' => $content
1434 ] );
1435 } else {
1436 return call_user_func( $oldCallback, $titleToCheck, $parser );
1437 }
1438 }
1439 );
1440
1441 global $wgHooks;
1442 $wgHooks['TitleExists'][] =
1443 function ( $titleToCheck, &$exists ) use ( $title ) {
1444 if ( $titleToCheck->equals( $title ) ) {
1445 $exists = true;
1446 }
1447 };
1448 end( $wgHooks['TitleExists'] );
1449 $key = key( $wgHooks['TitleExists'] );
1450 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1451 $linkCache->clearBadLink( $title->getPrefixedDBkey() );
1452 return new ScopedCallback( function () use ( $title, $key, $linkCache ) {
1453 global $wgHooks;
1454 unset( $wgHooks['TitleExists'][$key] );
1455 $linkCache->clearLink( $title );
1456 } );
1457 }
1458}
1459
getUser()
$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.
$wgHooks['AdminLinks'][]
$wgLang
Definition Setup.php:880
Internationalisation code.
Definition Language.php:37
MediaWikiServices is the service locator for the application scope of MediaWiki.
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 callable[] $lazyOptions
Lazy-loaded options.
matchesForCacheKey(ParserOptions $other)
getTidy()
Use tidy to cleanup output HTML?
static initSpeculativeRevId(ParserOptions $popt)
Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativeRevId().
setIsPreview( $x)
Parsing the page for a "preview" operation?
setDateFormat( $x)
Date format index.
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?
static initDateFormat(ParserOptions $popt)
Lazy initializer for dateFormat.
setNumberHeadings( $x)
Automatically number headings?
static initSpeculativePageId(ParserOptions $popt)
Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativePageId().
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.
static newCanonical( $context=null, $userLang=null)
Creates a "canonical" ParserOptions object.
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.
getSpeculativePageId()
A guess for {{PAGEID}}, calculated using the callback provided via setSpeculativeRevPageCallback().
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.
const HAS_NEWCANONICAL_FROM_CONTEXT
Flag indicating that newCanonical() accepts an IContextSource or the string 'canonical',...
disableContentConversion( $x=true)
Whether content conversion should be disabled.
initialiseFromUser( $user, $lang)
Get user options.
getOption( $name)
Fetch an option and track that is was accessed.
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 array $inCacheKey
Specify options that are included in the cache key.
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
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()
lazyLoadOption( $name)
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)
getTimestamp()
Timestamp used for {{CURRENTDAY}} etc.
getTemplateCallback()
Callback for template fetching; first argument to call_user_func().
getSpeculativeRevId()
A guess for {{REVISIONID}}, calculated using the callback provided via setSpeculativeRevIdCallback().
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?
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?
setSpeculativePageIdCallback( $x)
Callback to generate a guess for {{PAGEID}}.
Represents a title within MediaWiki.
Definition Title.php:42
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
Interface for objects which can provide a MediaWiki context on request.
$context
Definition load.php:45
$content
Definition router.php:78
if(!isset( $args[0])) $lang