mediawiki-extensions-Cite/includes/CiteParserHooks.php
Thiemo Kreuz 7ce10d7539 Remove lazy registration of Parser related hooks
To be honest I don't get why this lazy registration was done in the
first place. None of the 4 other hooks should ever be called before
the ParserFirstCallInit hook got called.

Also, under which circumstances can the ParserFirstCallInit hook be
called more than once?

Both scenarios would be wrong, as far as I'm concerned. Either I'm
missing something, or this code can indeed be simplified. Maybe it was
something to make it more compatible with older MediaWiki versions?

The only reason I can think of is: in all situations that do not
involve a parser, having the 4 extra hooks registered is pointless.
Does this waste space and/or runtime in the $wgHooks registry?

Change-Id: I5ef1495f4ce7bce940fa5f8e700af3d2c4851a01
2019-11-12 11:47:55 +01:00

70 lines
1.7 KiB
PHP

<?php
class CiteParserHooks {
/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit
*
* @param Parser $parser
*/
public static function onParserFirstCallInit( Parser $parser ) {
$parser->extCite = new Cite();
CiteParserTagHooks::initialize( $parser );
}
/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserClearState
*
* @param Parser $parser
*/
public static function onParserClearState( Parser $parser ) {
/** @var Cite $cite */
$cite = $parser->extCite;
$cite->clearState();
}
/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserCloned
*
* @param Parser $parser
*/
public static function onParserCloned( Parser $parser ) {
$parser->extCite = clone $parser->extCite;
/** @var Cite $cite */
$cite = $parser->extCite;
// Clear the state, making sure it will actually work.
$cite->mInCite = false;
$cite->mInReferences = false;
$cite->clearState();
CiteParserTagHooks::initialize( $parser );
}
/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserAfterParse
*
* @param Parser $parser
* @param string &$text
* @param StripState $stripState
*/
public static function onParserAfterParse( Parser $parser, &$text, $stripState ) {
/** @var Cite $cite */
$cite = $parser->extCite;
$cite->checkRefsNoReferences( true, $parser->getOptions(), $text );
}
/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserBeforeTidy
*
* @param Parser $parser
* @param string &$text
*/
public static function onParserBeforeTidy( Parser $parser, &$text ) {
/** @var Cite $cite */
$cite = $parser->extCite;
$cite->checkRefsNoReferences( false, $parser->getOptions(), $text );
}
}