Remove obsolete ParserBeforeTidy hook handler

I was able to track this code down to I093d85d from 2012, which was done
right after the ParserAfterParse hook was introduced. I believe the
redundant code path was left to keep the Cite extension compatible with
old MediaWiki versions that did not had this hook yet.

I also noticed this code path is most probably entirely redundant with
the current version of MediaWiki. The *only* thing this code does is
blocking the ParserBeforeTidy hook from doing the same thing a second
time if the ParserAfterParse hook was called before. But it does *not*
block any other compination, e.g. if the two hooks are called the other
way around, or the same hook twice.

In core, it looks like it is impossible for the ParserBeforeTidy hook
being fired without the ParserAfterParse hook being fired before. If this
is true, this is in fact dead code.

Change-Id: Iacf8b600c7abdeaf89c22c2fc31e646f57245e47
This commit is contained in:
Thiemo Kreuz 2019-12-04 16:49:56 +01:00
parent 31bda4777b
commit a7c4e14f42
4 changed files with 2 additions and 33 deletions

View file

@ -28,7 +28,6 @@
"APIQuerySiteInfoGeneralInfo": "Cite\\Hooks\\CiteHooks::onAPIQuerySiteInfoGeneralInfo",
"ContentHandlerDefaultModelFor": "Cite\\Hooks\\CiteHooks::onContentHandlerDefaultModelFor",
"ParserAfterParse": "Cite\\Hooks\\CiteParserHooks::onParserAfterParse",
"ParserBeforeTidy": "Cite\\Hooks\\CiteParserHooks::onParserBeforeTidy",
"ParserClearState": "Cite\\Hooks\\CiteParserHooks::onParserClearState",
"ParserCloned": "Cite\\Hooks\\CiteParserHooks::onParserCloned",
"ParserFirstCallInit": "Cite\\Hooks\\CiteParserHooks::onParserFirstCallInit",

View file

@ -73,14 +73,6 @@ class Cite {
*/
private $errorReporter;
/**
* True when the ParserAfterParse hook has been called.
* Used to avoid doing anything in ParserBeforeTidy.
*
* @var bool
*/
private $mHaveAfterParse = false;
/**
* True when a <ref> tag is being processed.
* Used to avoid infinite recursion
@ -529,22 +521,14 @@ class Cite {
* If we are processing a section preview, this adds the missing
* references tags and does not add the errors.
*
* @param bool $afterParse True if called from the ParserAfterParse hook
* @param bool $isSectionPreview
* @return string
*/
public function checkRefsNoReferences(
bool $afterParse,
bool $isSectionPreview
) : string {
global $wgCiteResponsiveReferences;
if ( $afterParse ) {
$this->mHaveAfterParse = true;
} elseif ( $this->mHaveAfterParse ) {
return '';
}
$s = '';
if ( $this->referenceStack ) {
foreach ( $this->referenceStack->getGroups() as $group ) {

View file

@ -57,19 +57,7 @@ class CiteParserHooks {
public static function onParserAfterParse( Parser $parser, &$text, $stripState ) {
/** @var Cite $cite */
$cite = $parser->extCite;
$text .= $cite->checkRefsNoReferences( true, $parser->getOptions()->getIsSectionPreview() );
}
/**
* @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;
$text .= $cite->checkRefsNoReferences( false, $parser->getOptions()->getIsSectionPreview() );
$text .= $cite->checkRefsNoReferences( $parser->getOptions()->getIsSectionPreview() );
}
}

View file

@ -65,11 +65,10 @@ class CiteParserHooksTest extends \MediaWikiUnitTestCase {
/**
* @covers ::onParserAfterParse
* @covers ::onParserBeforeTidy
*/
public function testAfterParseHooks() {
$cite = $this->createMock( Cite::class );
$cite->expects( $this->exactly( 2 ) )
$cite->expects( $this->once() )
->method( 'checkRefsNoReferences' );
$parserOptions = $this->createMock( ParserOptions::class );
@ -85,7 +84,6 @@ class CiteParserHooksTest extends \MediaWikiUnitTestCase {
$text = '';
CiteParserHooks::onParserAfterParse( $parser, $text, $this->createMock( StripState::class ) );
CiteParserHooks::onParserBeforeTidy( $parser, $text );
}
}