Manual talk:Hooks/ParserBeforeStrip

From MediaWiki.org

Jump to: navigation, search

[edit] Sanity Check

This hook runs twice (possibly more). To prevent this from happening, just add the following to fnMyHook:

static $hasRun = false;
if ($hasRun) return;
$hasRun = true;

-- Egingell 13:29, 16 August 2007 (UTC)

I believe this happens because certain user interface messages go through the parser. Therefore it is run once for the page content, and then however many more times for various UI messages. I am not 100% sure about this however, so perhaps a bit more investigation is required. Assuming I am right, then the above code will be useful for extensions where it is important that they only run once per page view, but for most other situations the standard behaviour will cause no problems. --HappyDog 15:03, 27 August 2007 (UTC)


[edit] ParserBeforeStrip hook is not always called before strip

I'm using the ParserBeforeStrip hook in a math extension (JsMath) to strip any <math> tags before the parser strips them. The problem I am having is that the parser sometimes calls the strip command without using this hook. For example, in the function Parser::braceSubstitution() there is

$text = $this->strip( $text, $this->mStripState );

instead of

wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
$text = $this->strip( $text, $this->mStripState );
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );

This means that content that is transcluded to another page is not subjected to the ParserBeforeStrip hook before stripping occurs. Is there a reason for the parser not to use this hook in these cases? — Tommy Ekola 09:29, 5 February 2008 (UTC)

Personal tools