Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
CiteParserHooks
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onParserFirstCallInit
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onParserClearState
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onParserCloned
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onParserAfterParse
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Cite\Hooks;
4
5use Cite\Cite;
6use MediaWiki\Config\Config;
7use MediaWiki\Hook\ParserAfterParseHook;
8use MediaWiki\Hook\ParserClearStateHook;
9use MediaWiki\Hook\ParserClonedHook;
10use MediaWiki\Hook\ParserFirstCallInitHook;
11use MediaWiki\Parser\Parser;
12use MediaWiki\Parser\StripState;
13
14/**
15 * @license GPL-2.0-or-later
16 */
17class CiteParserHooks implements
18    ParserFirstCallInitHook,
19    ParserClearStateHook,
20    ParserClonedHook,
21    ParserAfterParseHook
22{
23
24    private CiteParserTagHooks $citeParserTagHooks;
25
26    public function __construct(
27        Config $config
28    ) {
29        $this->citeParserTagHooks = new CiteParserTagHooks( $config );
30    }
31
32    /**
33     * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit
34     *
35     * @param Parser $parser
36     */
37    public function onParserFirstCallInit( $parser ) {
38        $this->citeParserTagHooks->register( $parser );
39    }
40
41    /**
42     * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserClearState
43     *
44     * @param Parser $parser
45     */
46    public function onParserClearState( $parser ) {
47        $parser->extCite = null;
48    }
49
50    /**
51     * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserCloned
52     *
53     * @param Parser $parser
54     */
55    public function onParserCloned( $parser ) {
56        $parser->extCite = null;
57    }
58
59    /**
60     * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserAfterParse
61     *
62     * @param Parser $parser
63     * @param string &$text
64     * @param StripState $stripState
65     */
66    public function onParserAfterParse( $parser, &$text, $stripState ) {
67        if ( isset( $parser->extCite ) ) {
68            /** @var Cite $cite */
69            $cite = $parser->extCite;
70            $text .= $cite->checkRefsNoReferences( $parser, $parser->getOptions()->getIsSectionPreview() );
71        }
72    }
73
74}