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