mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-24 06:54:00 +00:00
Merge "Remove lazy registration of Parser related hooks"
This commit is contained in:
commit
59dba7e184
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
31
tests/phpunit/unit/CiteParserHooksTest.php
Normal file
31
tests/phpunit/unit/CiteParserHooksTest.php
Normal 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 );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue