Manual:Hooks/ParserBeforeStrip/zh
![]() | 在1.35.0版本起弃用后,此功能已在版本1.36.0中完全移除。 The most appropriate hook to migrate to is ParserBeforeInternalParse. |
ParserBeforeStrip | |
---|---|
自version 1.5.0 版可用 在version 1.36.0 (Gerrit change 622618)版被移除 用于在其他任何内部处理之前处理原始wiki代码 | |
定义函数: | public static function onParserBeforeStrip( &$parser, &$text, &$strip_state ) { ... }
|
附加钩子: | 在extension.json中:
{
"Hooks": {
"ParserBeforeStrip": "MediaWiki\\Extension\\MyExtension\\Hooks::onParserBeforeStrip"
}
}
|
调用自: | 文件: parser/Parser.php |
介面: | ParserBeforeStripHook.php |
更多有关附加钩子的信息,请参见Manual:函数钩 。
有关使用此钩子的扩展示例,请参见Category:ParserBeforeStrip extensions/zh。
详情
请注意此钩子不会运行于已缓存的页面内容。 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;
历史
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.