mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-09-23 18:29:15 +00:00
Move misplaced ParserFirstCallInit hook handler to CiteHooks
All other hook handlers are in the dedicated CiteHooks class. Main motivation here is to make the huge Cite class smaller, especially by removing static code that does not rely on anything else the class does. Bug: T236260 Change-Id: If0b3f6c989e44283428cda4b2c4d8d5303385d22
This commit is contained in:
parent
a037f76317
commit
28dd373d24
|
@ -31,7 +31,7 @@
|
|||
}
|
||||
},
|
||||
"Hooks": {
|
||||
"ParserFirstCallInit": "Cite::setHooks",
|
||||
"ParserFirstCallInit": "CiteHooks::onParserFirstCallInit",
|
||||
"ContentHandlerDefaultModelFor": "CiteHooks::onContentHandlerDefaultModelFor",
|
||||
"ResourceLoaderTestModules": "CiteHooks::onResourceLoaderTestModules",
|
||||
"ResourceLoaderRegisterModules": "CiteHooks::onResourceLoaderRegisterModules",
|
||||
|
|
|
@ -145,7 +145,7 @@ class Cite {
|
|||
* True when the ParserAfterParse hook has been called.
|
||||
* Used to avoid doing anything in ParserBeforeTidy.
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
private $mHaveAfterParse = false;
|
||||
|
||||
|
@ -153,7 +153,7 @@ class Cite {
|
|||
* True when a <ref> tag is being processed.
|
||||
* Used to avoid infinite recursion
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $mInCite = false;
|
||||
|
||||
|
@ -161,7 +161,7 @@ class Cite {
|
|||
* True when a <references> tag is being processed.
|
||||
* Used to detect the use of <references> to define refs
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $mInReferences = false;
|
||||
|
||||
|
@ -193,12 +193,6 @@ class Cite {
|
|||
*/
|
||||
private $mBumpRefData = false;
|
||||
|
||||
/**
|
||||
* Did we install us into $wgHooks yet?
|
||||
* @var Boolean
|
||||
*/
|
||||
private static $hooksInstalled = false;
|
||||
|
||||
/**
|
||||
* Callback function for <ref>
|
||||
*
|
||||
|
@ -1292,27 +1286,6 @@ class Cite {
|
|||
$this->mParser->getOutput()->setExtensionData( self::EXT_DATA_KEY, $savedRefs );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the parser hooks
|
||||
*
|
||||
* @param Parser $parser
|
||||
*/
|
||||
public static function setHooks( Parser $parser ) {
|
||||
global $wgHooks;
|
||||
|
||||
$parser->extCite = new self();
|
||||
|
||||
if ( !self::$hooksInstalled ) {
|
||||
$wgHooks['ParserClearState'][] = [ $parser->extCite, 'clearState' ];
|
||||
$wgHooks['ParserCloned'][] = [ $parser->extCite, 'cloneState' ];
|
||||
$wgHooks['ParserAfterParse'][] = [ $parser->extCite, 'checkRefsNoReferences', true ];
|
||||
$wgHooks['ParserBeforeTidy'][] = [ $parser->extCite, 'checkRefsNoReferences', false ];
|
||||
self::$hooksInstalled = true;
|
||||
}
|
||||
$parser->setHook( 'ref', [ $parser->extCite, 'ref' ] );
|
||||
$parser->setHook( 'references', [ $parser->extCite, 'references' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an error message based on an error ID and parses it
|
||||
*
|
||||
|
|
|
@ -8,6 +8,34 @@ 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'][] = [ $parser->extCite, 'clearState' ];
|
||||
$wgHooks['ParserCloned'][] = [ $parser->extCite, 'cloneState' ];
|
||||
$wgHooks['ParserAfterParse'][] = [ $parser->extCite, 'checkRefsNoReferences', true ];
|
||||
$wgHooks['ParserBeforeTidy'][] = [ $parser->extCite, 'checkRefsNoReferences', false ];
|
||||
self::$hooksInstalled = true;
|
||||
}
|
||||
|
||||
$parser->setHook( 'ref', [ $parser->extCite, 'ref' ] );
|
||||
$parser->setHook( 'references', [ $parser->extCite, 'references' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
Loading…
Reference in a new issue