Manual:Hooks/ParserBeforeStrip

Category:MediaWiki hooks#ParserBeforeStrip Category:Hooks added in MediaWiki 1.5.0#ParserBeforeStrip Category:MediaWiki deprecated or obsolete features#ParserBeforeStrip Category:Hooks removed in MediaWiki 1.36.0#ParserBeforeStrip Category:Hooks deprecated in MediaWiki 1.35.0#ParserBeforeStrip
ParserBeforeStrip
Available from version 1.5.0
Removed in version 1.36.0 (Gerrit change 622618)Category:Removed hooks#ParserBeforeStrip
Used to process the raw wiki code before any internal processing is applied
Define function:
public static function onParserBeforeStrip( &$parser, &$text, &$strip_state ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"ParserBeforeStrip": "MediaWiki\\Extension\\MyExtension\\Hooks::onParserBeforeStrip"
	}
}
Called from: File(s): parser/Parser.phpCategory:MediaWiki hooks included in Parser.php#ParserBeforeStrip
Interface: ParserBeforeStripHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:ParserBeforeStrip extensions.

Details

Note that this hook is not run on cached page content. And is also run when parsing system messages in addition to the page text.

$text will hold the text being parsed. To change the text being parsed, modify this value. E.g. to add the phrase "The mighty oracle gives forth this proclamation: " to the front of the text being parsed, you would use the following code:

$text = "The mighty oracle gives forth this proclamation: " . $text;
If you are just adding things to the start/end of a page's body and don't need it to actually be integrated into the parsing process you should consider using a separate hook to add/prepend that content instead.

History

Originally, the MediaWiki Parser performed a first pass which removed elements that shouldn't be processed as wiki text (e.g. <nowiki> tags, HTML comments, <pre> tags, etc.) from the page text, before processing the remaining wiki text. This process was known as 'stripping'; the stripped content (where relevant) was inserted back into the page at the end of the parse.

There were therefore three parser hooks related to the parsing process. ParserBeforeStrip was called before the stripping took place, ParserAfterStrip was called after the stripping took place, and ParserBeforeInternalParse was called just prior to the actual parse (and was intended to provide a mechanism to use an alternative parser instead of the standard MW wikitext parser).

In MW 1.14, the 'strip' stage was removed, which meant that there was no difference between ParserBeforeStrip and ParserAfterStrip, so the latter was deprecated. It also meant that the text passed into the hook now contains the full wikitext of the source page, including any <nowiki> tags, etc.

As of MW 1.36, both ParserBeforeStrip and ParserAfterStrip were completely removed, so you are now recommended to use ParserBeforeInternalParse instead of ParserBeforeStrip or InternalParseBeforeLinks instead of ParserAfterStrip, or possibly one of the other page rendering hooks if they more closely match your requirements.

See also

Category:Hooks added in MediaWiki 1.5.0 Category:Hooks deprecated in MediaWiki 1.35.0 Category:Hooks removed in MediaWiki 1.36.0 Category:MediaWiki deprecated or obsolete features Category:MediaWiki hooks Category:MediaWiki hooks included in Parser.php Category:Removed hooks