mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-09-24 10:48:58 +00:00
Merge "Move some glue code from Cite to the Cite…Hooks classes"
This commit is contained in:
commit
3cac8643a6
|
@ -1120,15 +1120,8 @@ class Cite {
|
|||
/**
|
||||
* Gets run when Parser::clearState() gets run, since we don't
|
||||
* want the counts to transcend pages and other instances
|
||||
*
|
||||
* @param Parser $parser
|
||||
*/
|
||||
public function clearState( Parser $parser ) {
|
||||
if ( $parser->extCite !== $this ) {
|
||||
$parser->extCite->clearState( $parser );
|
||||
return;
|
||||
}
|
||||
|
||||
public function clearState() {
|
||||
# Don't clear state when we're in the middle of parsing
|
||||
# a <ref> tag
|
||||
if ( $this->mInCite || $this->mInReferences ) {
|
||||
|
@ -1143,27 +1136,6 @@ class Cite {
|
|||
$this->mRefCallStack = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets run when the parser is cloned.
|
||||
*
|
||||
* @param Parser $parser
|
||||
*/
|
||||
public function cloneState( Parser $parser ) {
|
||||
if ( $parser->extCite !== $this ) {
|
||||
$parser->extCite->cloneState( $parser );
|
||||
return;
|
||||
}
|
||||
|
||||
$parser->extCite = clone $this;
|
||||
$parser->setHook( 'ref', 'CiteParserTagHooks::ref' );
|
||||
$parser->setHook( 'references', 'CiteParserTagHooks::references' );
|
||||
|
||||
// Clear the state, making sure it will actually work.
|
||||
$parser->extCite->mInCite = false;
|
||||
$parser->extCite->mInReferences = false;
|
||||
$parser->extCite->clearState( $parser );
|
||||
}
|
||||
|
||||
/**
|
||||
* Called at the end of page processing to append a default references
|
||||
* section, if refs were used without a main references tag. If there are references
|
||||
|
@ -1173,18 +1145,11 @@ class Cite {
|
|||
* references tags and does not add the errors.
|
||||
*
|
||||
* @param bool $afterParse True if called from the ParserAfterParse hook
|
||||
* @param Parser $parser
|
||||
* @param ParserOptions $parserOptions
|
||||
* @param string &$text
|
||||
*/
|
||||
public function checkRefsNoReferences( $afterParse, $parser, &$text ) {
|
||||
public function checkRefsNoReferences( $afterParse, ParserOptions $parserOptions, &$text ) {
|
||||
global $wgCiteResponsiveReferences;
|
||||
if ( $parser->extCite === null ) {
|
||||
return;
|
||||
}
|
||||
if ( $parser->extCite !== $this ) {
|
||||
$parser->extCite->checkRefsNoReferences( $afterParse, $parser, $text );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $afterParse ) {
|
||||
$this->mHaveAfterParse = true;
|
||||
|
@ -1192,14 +1157,14 @@ class Cite {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( !$parser->getOptions()->getIsPreview() ) {
|
||||
if ( !$parserOptions->getIsPreview() ) {
|
||||
// save references data for later use by LinksUpdate hooks
|
||||
if ( $this->mRefs && isset( $this->mRefs[self::DEFAULT_GROUP] ) ) {
|
||||
$this->saveReferencesData();
|
||||
}
|
||||
$isSectionPreview = false;
|
||||
} else {
|
||||
$isSectionPreview = $parser->getOptions()->getIsSectionPreview();
|
||||
$isSectionPreview = $parserOptions->getIsSectionPreview();
|
||||
}
|
||||
|
||||
$s = '';
|
||||
|
|
|
@ -32,8 +32,7 @@ class CiteHooks {
|
|||
self::$hooksInstalled = true;
|
||||
}
|
||||
|
||||
$parser->setHook( 'ref', 'CiteParserTagHooks::ref' );
|
||||
$parser->setHook( 'references', 'CiteParserTagHooks::references' );
|
||||
CiteParserTagHooks::initialize( $parser );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,7 +10,7 @@ class CiteParserHooks {
|
|||
public static function onParserClearState( Parser $parser ) {
|
||||
/** @var Cite $cite */
|
||||
$cite = $parser->extCite;
|
||||
$cite->clearState( $parser );
|
||||
$cite->clearState();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,9 +19,16 @@ class CiteParserHooks {
|
|||
* @param Parser $parser
|
||||
*/
|
||||
public static function onParserCloned( Parser $parser ) {
|
||||
$parser->extCite = clone $parser->extCite;
|
||||
|
||||
/** @var Cite $cite */
|
||||
$cite = $parser->extCite;
|
||||
$cite->cloneState( $parser );
|
||||
// Clear the state, making sure it will actually work.
|
||||
$cite->mInCite = false;
|
||||
$cite->mInReferences = false;
|
||||
$cite->clearState();
|
||||
|
||||
CiteParserTagHooks::initialize( $parser );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,7 +41,7 @@ class CiteParserHooks {
|
|||
public static function onParserAfterParse( Parser $parser, &$text, $stripState ) {
|
||||
/** @var Cite $cite */
|
||||
$cite = $parser->extCite;
|
||||
$cite->checkRefsNoReferences( true, $parser, $text );
|
||||
$cite->checkRefsNoReferences( true, $parser->getOptions(), $text );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,7 +53,7 @@ class CiteParserHooks {
|
|||
public static function onParserBeforeTidy( Parser $parser, &$text ) {
|
||||
/** @var Cite $cite */
|
||||
$cite = $parser->extCite;
|
||||
$cite->checkRefsNoReferences( false, $parser, $text );
|
||||
$cite->checkRefsNoReferences( false, $parser->getOptions(), $text );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,16 @@
|
|||
|
||||
class CiteParserTagHooks {
|
||||
|
||||
/**
|
||||
* Enables the two <ref> and <references> tags.
|
||||
*
|
||||
* @param Parser $parser
|
||||
*/
|
||||
public static function initialize( Parser $parser ) {
|
||||
$parser->setHook( 'ref', 'CiteParserTagHooks::ref' );
|
||||
$parser->setHook( 'references', 'CiteParserTagHooks::references' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Parser hook for the <ref> tag.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue