Go to the documentation of this file.
25 use Wikimedia\ScopedCallback;
63 'dateformat' => [ __CLASS__,
'initDateFormat' ],
64 'speculativeRevId' => [ __CLASS__,
'initSpeculativeRevId' ],
65 'speculativePageId' => [ __CLASS__,
'initSpeculativePageId' ],
74 'numberheadings' =>
true,
76 'stubthreshold' =>
true,
128 if ( !array_key_exists( $name, $this->options ) ) {
129 throw new InvalidArgumentException(
"Unknown parser option $name" );
133 if ( !empty( self::$inCacheKey[$name] ) ) {
136 return $this->options[$name];
143 if ( isset( self::$lazyOptions[$name] ) && $this->options[$name] ===
null ) {
144 $this->options[$name] = call_user_func( self::$lazyOptions[$name], $this, $name );
157 if ( !array_key_exists( $name, $this->options ) ) {
158 throw new InvalidArgumentException(
"Unknown parser option $name" );
160 $old = $this->options[$name];
161 $this->options[$name] = $value;
174 if ( !array_key_exists( $name, $this->options ) ) {
175 throw new InvalidArgumentException(
"Unknown parser option $name" );
177 return wfSetVar( $this->options[$name], $value );
189 return $this->
getOption(
'interwikiMagic' );
206 return $this->
getOption(
'allowExternalImages' );
226 return $this->
getOption(
'allowExternalImagesFrom' );
246 return $this->
getOption(
'enableImageWhitelist' );
263 return $this->
getOption(
'numberheadings' );
280 return $this->
getOption(
'allowSpecialInclusion' );
314 return $this->
getOption(
'interfaceMessage' );
331 return $this->
getOption(
'targetLanguage' );
340 return $this->
setOption(
'targetLanguage', $x );
348 return $this->
getOption(
'maxIncludeSize' );
365 return $this->
getOption(
'maxPPNodeCount' );
382 return $this->
getOption(
'maxGeneratedPPNodeCount' );
399 return $this->
getOption(
'maxPPExpandDepth' );
407 return $this->
getOption(
'maxTemplateDepth' );
425 return $this->
getOption(
'expensiveParserFunctionLimit' );
444 return $this->
getOption(
'removeComments' );
462 return $this->
getOption(
'enableLimitReport' );
480 return $this->
getOption(
'cleanSignatures' );
498 return $this->
getOption(
'externalLinkTarget' );
515 return $this->
getOption(
'disableContentConversion' );
532 return $this->
getOption(
'disableTitleConversion' );
566 return $this->
getOption(
'stubthreshold' );
600 return $this->
getOption(
'isSectionPreview' );
634 return $this->
getOption(
'preSaveTransform' );
660 return $popt->mUser->getDatePreference();
715 if ( is_string( $x ) ) {
728 return $this->
getOption(
'magicISBNLinks' );
737 return $this->
getOption(
'magicPMIDLinks' );
746 return $this->
getOption(
'magicRFCLinks' );
764 return $this->
getOption(
'allowUnsafeRawHtml' );
796 if ( $className ===
true ) {
797 $className =
'mw-parser-output';
799 if ( $className ===
false ) {
802 return $this->
setOption(
'wrapclass', $className );
811 return $this->
getOption(
'currentRevisionCallback' );
829 return $this->
getOption(
'templateCallback' );
852 return $this->
getOption(
'speculativeRevId' );
866 return $this->
getOption(
'speculativePageId' );
876 $cb = $popt->
getOption(
'speculativeRevIdCallback' );
877 $id = $cb ? $cb() :
null;
890 $cb = $popt->
getOption(
'speculativePageIdCallback' );
891 $id = $cb ? $cb() :
null;
904 $this->
setOption(
'speculativeRevId',
null );
905 return $this->
setOption(
'speculativeRevIdCallback', $x );
915 $this->
setOption(
'speculativePageId',
null );
916 return $this->
setOption(
'speculativePageIdCallback', $x );
924 if ( !isset( $this->mTimestamp ) ) {
936 return wfSetVar( $this->mTimestamp, $x );
950 $this->redirectTarget =
$title;
970 $this->mExtraKey .=
'!' . $key;
988 if ( $user ===
null ) {
990 if ( $wgUser ===
null ) {
996 if (
$lang ===
null ) {
1015 MediaWikiServices::getInstance()->getContentLanguage() );
1076 } elseif (
$context ===
'canonical' ) {
1079 $ret =
new self(
$context, $userLang );
1081 throw new InvalidArgumentException(
1082 '$context must be an IContextSource, the string "canonical", a User, or null'
1086 foreach ( self::getCanonicalOverrides() as $k => $v ) {
1087 $ret->setOption( $k, $v );
1109 if ( self::$defaults ===
null ) {
1112 'dateformat' =>
null,
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,
1135 &self::$lazyOptions,
1138 ksort( self::$inCacheKey );
1142 return self::$defaults + [
1163 'stubthreshold' => 0,
1164 'userlang' => MediaWikiServices::getInstance()->getContentLanguage(),
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;
1212 $options = array_keys( $this->options );
1214 'enableLimitReport',
1223 if ( $o1 !== $o2 ) {
1229 $fields = array_keys( get_class_vars( __CLASS__ ) );
1230 $fields = array_diff( $fields, [
1237 foreach ( $fields as $field ) {
1238 if ( !is_object( $this->$field ) && $this->$field !== $other->$field ) {
1252 foreach ( self::allCacheVaryingOptions() as $option ) {
1259 if ( $o1 !== $o2 ) {
1273 $this->onAccessCallback = $callback;
1285 if ( $this->onAccessCallback ) {
1286 call_user_func( $this->onAccessCallback, $optionName );
1298 if ( self::$defaults ===
null ) {
1301 return array_keys( array_filter( self::$inCacheKey ) );
1310 if ( $value ===
true ) {
1312 } elseif ( $value ===
false ) {
1314 } elseif ( $value ===
null ) {
1316 } elseif ( $value instanceof
Language ) {
1317 return $value->getCode();
1318 } elseif ( is_array( $value ) ) {
1319 return '[' . implode(
',', array_map( [ $this,
'optionToString' ], $value ) ) .
']';
1321 return (
string)$value;
1343 $lazyOpts = array_intersect( $forOptions,
$inCacheKey, array_keys( self::$lazyOptions ) );
1344 foreach ( $lazyOpts as $k ) {
1357 foreach ( array_intersect(
$inCacheKey, $forOptions ) as $option ) {
1361 $values[] =
"$option=$v";
1365 $confstr = $values ? implode(
'!', $values ) :
'canonical';
1369 if ( !is_null(
$title ) ) {
1370 $confstr .=
$title->getPageLanguage()->getExtraHashOptions();
1373 MediaWikiServices::getInstance()->getContentLanguage()->getExtraHashOptions();
1378 if ( $this->mExtraKey !=
'' ) {
1384 Hooks::run(
'PageRenderingHash', [ &$confstr, $this->
getUser(), &$forOptions ] );
1387 $confstr = str_replace(
' ',
'_', $confstr );
1399 foreach ( $this->options as $option => $value ) {
1400 if ( empty( self::$inCacheKey[$option] ) ) {
1424 $titleToCheck, $parser =
false ) use (
$title,
$content, $user, &$oldCallback
1426 if ( $titleToCheck->equals(
$title ) ) {
1428 'page' =>
$title->getArticleID(),
1429 'user_text' => $user->getName(),
1430 'user' => $user->getId(),
1431 'parent_id' =>
$title->getLatestRevID(),
1436 return call_user_func( $oldCallback, $titleToCheck, $parser );
1443 function ( $titleToCheck, &$exists ) use (
$title ) {
1444 if ( $titleToCheck->equals(
$title ) ) {
1449 $key = key(
$wgHooks[
'TitleExists'] );
1450 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1451 $linkCache->clearBadLink(
$title->getPrefixedDBkey() );
1452 return new ScopedCallback(
function () use (
$title, $key, $linkCache ) {
1454 unset(
$wgHooks[
'TitleExists'][$key] );
1455 $linkCache->clearLink(
$title );
static getDefaultOption( $opt)
Get a given default option value.
setMaxIncludeSize( $x)
Maximum size of template expansions, in bytes.
getMagicPMIDLinks()
Are magic PMID links enabled?
Set options of the Parser.
setOptionLegacy( $name, $value)
Legacy implementation.
getAllowExternalImagesFrom()
External images to allow.
getWrapOutputClass()
Class to use to wrap output from Parser::parse()
getExpensiveParserFunctionLimit()
Maximum number of calls per parse to expensive parser functions.
setTidy( $x)
Use tidy to cleanup output HTML?
getIsSectionPreview()
Parsing the page for a "preview" operation on a single section?
$wgMaxArticleSize
Maximum article size in kilobytes.
getRemoveComments()
Remove HTML comments.
setAllowUnsafeRawHtml( $x)
If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of...
disableContentConversion( $x=true)
Whether content conversion should be disabled.
if(!isset( $args[0])) $lang
initialiseFromUser( $user, $lang)
Get user options.
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...
$wgMaxTemplateDepth
Maximum recursion depth for templates within templates.
getIsPreview()
Parsing the page for a "preview" operation?
getDisableTitleConversion()
Whether title conversion should be disabled.
setAllowExternalImages( $x)
Allow all external images inline?
setTemplateCallback( $x)
Callback for template fetching; first argument to call_user_func().
setIsPreview( $x)
Parsing the page for a "preview" operation?
setTargetLanguage( $x)
Target language for the parse.
getInterfaceMessage()
Parsing an interface message?
setIsSectionPreview( $x)
Parsing the page for a "preview" operation on a single section?
getSpeculativeRevId()
A guess for {{REVISIONID}}, calculated using the callback provided via setSpeculativeRevIdCallback().
static newFromAnon()
Get a ParserOptions object for an anonymous user.
setEnableImageWhitelist( $x)
Use the on-wiki external image whitelist?
$wgDisableTitleConversion
Whether to enable language variant conversion for links.
setWrapOutputClass( $className)
CSS class to use to wrap output from Parser::parse()
setSpeculativeRevIdCallback( $x)
Callback to generate a guess for {{REVISIONID}}.
disableTitleConversion( $x=true)
Whether title conversion should be disabled.
static initDateFormat(ParserOptions $popt)
Lazy initializer for dateFormat.
getIsPrintable()
Parsing the printable version of the page?
setMaxGeneratedPPNodeCount( $x)
Maximum number of nodes generated by Preprocessor::preprocessToObj()
setCurrentRevisionCallback( $x)
Callback for current revision fetching; first argument to call_user_func().
static array $inCacheKey
Specify options that are included in the cache key.
setMaxTemplateDepth( $x)
Maximum recursion depth for templates within templates.
getMagicRFCLinks()
Are magic RFC links enabled?
getUserLangObj()
Get the user language used by the parser for this page and split the parser cache.
registerWatcher( $callback)
Registers a callback for tracking which ParserOptions which are used.
setupFakeRevision( $title, $content, $user)
Sets a hook to force that a page exists, and sets a current revision callback to return a revision wi...
getDateFormat()
Date format index.
const HAS_NEWCANONICAL_FROM_CONTEXT
Flag indicating that newCanonical() accepts an IContextSource or the string 'canonical',...
setOption( $name, $value)
Set an option, generically.
static initSpeculativeRevId(ParserOptions $popt)
Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativeRevId().
setNumberHeadings( $x)
Automatically number headings?
static getCanonicalOverrides()
Get "canonical" non-default option values.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
getRedirectTarget()
Get the previously-set redirect target.
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
setUserLang( $x)
Set the user language used by the parser for this page and split the parser cache.
getAllowSpecialInclusion()
Allow inclusion of special pages?
$wgAllowExternalImagesFrom
If the above is false, you can specify an exception here.
getTidy()
Use tidy to cleanup output HTML?
getMaxIncludeSize()
Maximum size of template expansions, in bytes.
string null $mTimestamp
Timestamp used for {{CURRENTDAY}} etc.
$wgExpensiveParserFunctionLimit
Maximum number of calls per parse to expensive parser functions such as PAGESINCATEGORY.
setThumbSize( $x)
Thumb size preferred by the user.
getEnableImageWhitelist()
Use the on-wiki external image whitelist?
$wgInterwikiMagic
Treat language links as magic connectors, not inline links.
setExternalLinkTarget( $x)
Target attribute for external links.
setDateFormat( $x)
Date format index.
getTargetLanguage()
Target language for the parse.
static initSpeculativePageId(ParserOptions $popt)
Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativePageId().
setAllowSpecialInclusion( $x)
Allow inclusion of special pages?
static getDefaults()
Get default option values.
getExternalLinkTarget()
Target attribute for external links.
callable null $onAccessCallback
Function to be called when an option is accessed.
$wgEnableMagicLinks
Enable the magic links feature of automatically turning ISBN xxx, PMID xxx, RFC xxx into links.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
getStubThreshold()
Thumb size preferred by the user.
$wgExternalLinkTarget
Set a default target for external links, e.g.
array $options
Current values for all options that are relevant for caching.
getUserLang()
Same as getUserLangObj() but returns a string instead.
$wgDisableLangConversion
Whether to enable language variant conversion.
getPreSaveTransform()
Transform wiki markup when saving the page?
setStubThreshold( $x)
Thumb size preferred by the user.
getOption( $name)
Fetch an option and track that is was accessed.
$mExtraKey
Appended to the options hash.
getAllowUnsafeRawHtml()
If the wiki is configured to allow raw html ($wgRawHtml = true) is it allowed in the specific case of...
getDisableContentConversion()
Whether content conversion should be disabled.
optionToString( $value)
Convert an option to a string value.
matchesForCacheKey(ParserOptions $other)
optionUsed( $optionName)
Called when an option is accessed.
getSpeculativePageId()
A guess for {{PAGEID}}, calculated using the callback provided via setSpeculativeRevPageCallback().
setTimestamp( $x)
Timestamp used for {{CURRENTDAY}} etc.
setSpeculativePageIdCallback( $x)
Callback to generate a guess for {{PAGEID}}.
setCleanSignatures( $x)
Clean up signature texts?
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
getCurrentRevisionCallback()
Callback for current revision fetching; first argument to call_user_func().
$wgEnableParserLimitReporting
Whether to include the NewPP limit report as a HTML comment.
getTemplateCallback()
Callback for template fetching; first argument to call_user_func().
static newCanonical( $context=null, $userLang=null)
Creates a "canonical" ParserOptions object.
setRemoveComments( $x)
Remove HTML comments.
setInterwikiMagic( $x)
Specify whether to extract interlanguage links.
setRedirectTarget( $title)
Set the redirect target.
setExpensiveParserFunctionLimit( $x)
Maximum number of calls per parse to expensive parser functions.
getTimestamp()
Timestamp used for {{CURRENTDAY}} etc.
setMaxPPNodeCount( $x)
Maximum number of nodes touched by PPFrame::expand()
Interface for objects which can provide a MediaWiki context on request.
getCleanSignatures()
Clean up signature texts?
Title null $redirectTarget
If the page being parsed is a redirect, this should hold the redirect target.
setAllowExternalImagesFrom( $x)
External images to allow.
matches(ParserOptions $other)
Check if these options match that of another options set.
enableLimitReport( $x=true)
Enable limit report in an HTML comment on output.
Represents a title within MediaWiki.
__construct( $user=null, $lang=null)
getInterwikiMagic()
Whether to extract interlanguage links.
static callable[] $lazyOptions
Lazy-loaded options.
User $mUser
Stored user object.
setInterfaceMessage( $x)
Parsing an interface message?
static array null $defaults
Default values for all options that are relevant for caching.
static allCacheVaryingOptions()
Return all option keys that vary the options hash.
$wgCleanSignatures
If true, removes (by substituting) templates in signatures.
getThumbSize()
Thumb size preferred by the user.
static isRealObject( $obj)
Returns a bool value whenever $obj is a stub object.
getMagicISBNLinks()
Are magic ISBN links enabled?
setIsPrintable( $x)
Parsing the printable version of the page?
getMaxPPNodeCount()
Maximum number of nodes touched by PPFrame::expand()
$wgRenderHashAppend
Append a configured value to the parser cache and the sitenotice key so that they can be kept separat...
$wgMaxGeneratedPPNodeCount
A complexity limit on template expansion: the maximum number of elements generated by Preprocessor::p...
static factory( $code)
Get a cached or new language object for a given language code.
getMaxGeneratedPPNodeCount()
Maximum number of nodes generated by Preprocessor::preprocessToObj()
getMaxPPExpandDepth()
Maximum recursion depth in PPFrame::expand()
getEnableLimitReport()
Enable limit report in an HTML comment on output.
getNumberHeadings()
Automatically number headings?
isSafeToCache()
Test whether these options are safe to cache.
getMaxTemplateDepth()
Maximum recursion depth for templates within templates.
setPreSaveTransform( $x)
Transform wiki markup when saving the page?
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
$wgMaxPPNodeCount
A complexity limit on template expansion: the maximum number of nodes visited by PPFrame::expand()
Internationalisation code.
optionsHash( $forOptions, $title=null)
Generate a hash string with the values set on these ParserOptions for the keys given in the array.
getAllowExternalImages()
Allow all external images inline?
static newFromUser( $user)
Get a ParserOptions object from a given user.
$wgAllowExternalImages
Whether to allow inline image pointing to other websites.
$wgEnableImageWhitelist
If $wgAllowExternalImages is false, you can allow an on-wiki whitelist of regular expression fragment...
addExtraKey( $key)
Extra key that should be present in the parser cache key.
$wgAllowSpecialInclusion
Allow special page inclusions such as {{Special:Allpages}}.