Merge "Remove lazy registration of Parser related hooks"

This commit is contained in:
jenkins-bot 2019-11-12 11:20:57 +00:00 committed by Gerrit Code Review
commit 59dba7e184
5 changed files with 46 additions and 46 deletions

View file

@ -31,7 +31,11 @@
}
},
"Hooks": {
"ParserFirstCallInit": "CiteHooks::onParserFirstCallInit",
"ParserAfterParse": "CiteParserHooks::onParserAfterParse",
"ParserBeforeTidy": "CiteParserHooks::onParserBeforeTidy",
"ParserClearState": "CiteParserHooks::onParserClearState",
"ParserCloned": "CiteParserHooks::onParserCloned",
"ParserFirstCallInit": "CiteParserHooks::onParserFirstCallInit",
"ContentHandlerDefaultModelFor": "CiteHooks::onContentHandlerDefaultModelFor",
"ResourceLoaderTestModules": "CiteHooks::onResourceLoaderTestModules",
"ResourceLoaderRegisterModules": "CiteHooks::onResourceLoaderRegisterModules",

View file

@ -9,33 +9,6 @@ use MediaWiki\MediaWikiServices;
class CiteHooks {
/**
* Did we install us into $wgHooks yet?
* @var bool
*/
private static $hooksInstalled = false;
/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit
*
* @param Parser $parser
*/
public static function onParserFirstCallInit( Parser $parser ) {
global $wgHooks;
$parser->extCite = new Cite();
if ( !self::$hooksInstalled ) {
$wgHooks['ParserClearState'][] = 'CiteParserHooks::onParserClearState';
$wgHooks['ParserCloned'][] = 'CiteParserHooks::onParserCloned';
$wgHooks['ParserAfterParse'][] = 'CiteParserHooks::onParserAfterParse';
$wgHooks['ParserBeforeTidy'][] = 'CiteParserHooks::onParserBeforeTidy';
self::$hooksInstalled = true;
}
CiteParserTagHooks::initialize( $parser );
}
/**
* Convert the content model of a message that is actually JSON to JSON. This
* only affects validation and UI when saving and editing, not loading the

View file

@ -2,6 +2,16 @@
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
*

View file

@ -6,7 +6,6 @@ use Cite;
use CiteHooks;
use HashConfig;
use LinksUpdate;
use Parser;
use ParserOutput;
use ResourceLoader;
use Title;
@ -23,23 +22,6 @@ class CiteHooksTest extends \MediaWikiUnitTestCase {
$wgCiteStoreReferencesData = true;
}
/**
* @covers ::onParserFirstCallInit
*/
public function testOnParserFirstCallInit() {
$parser = $this->createMock( Parser::class );
$parser->expects( $this->exactly( 2 ) )
->method( 'setHook' )
->withConsecutive(
[ 'ref', $this->isType( 'callable' ) ],
[ 'references', $this->isType( 'callable' ) ]
);
CiteHooks::onParserFirstCallInit( $parser );
$this->assertInstanceOf( Cite::class, $parser->extCite );
}
/**
* @covers ::onContentHandlerDefaultModelFor
*/

View file

@ -0,0 +1,31 @@
<?php
namespace Cite\Test\Unit;
use Cite;
use CiteParserHooks;
use Parser;
/**
* @coversDefaultClass \CiteParserHooks
*/
class CiteParserHooksTest extends \MediaWikiUnitTestCase {
/**
* @covers ::onParserFirstCallInit
*/
public function testOnParserFirstCallInit() {
$parser = $this->createMock( Parser::class );
$parser->expects( $this->exactly( 2 ) )
->method( 'setHook' )
->withConsecutive(
[ 'ref', $this->isType( 'callable' ) ],
[ 'references', $this->isType( 'callable' ) ]
);
CiteParserHooks::onParserFirstCallInit( $parser );
$this->assertInstanceOf( Cite::class, $parser->extCite );
}
}