Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ChessBrowserHooks
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 onParserFirstCallInit
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 onOutputPageParserOutput
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2/**
3 * This file is a part of ChessBrowser.
4 *
5 * ChessBrowser is free software: you can redistribute it and/or modify
6 *  it under the terms of the GNU General Public License as published by
7 *  the Free Software Foundation, either version 3 of the License, or
8 *  (at your option) any later version.
9 *
10 *  This program is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 *  GNU General Public License for more details.
14 *
15 *  You should have received a copy of the GNU General Public License
16 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 *
18 * @file ChessBrowserHooks
19 * @ingroup ChessBrowser
20 * @author Wugapodes
21 */
22
23namespace MediaWiki\Extension\ChessBrowser;
24
25use MediaWiki\Hook\OutputPageParserOutputHook;
26use MediaWiki\Hook\ParserFirstCallInitHook;
27use MediaWiki\Output\OutputPage;
28use Parser;
29use ParserOutput;
30
31class ChessBrowserHooks implements
32    ParserFirstCallInitHook,
33    OutputPageParserOutputHook
34{
35
36    /**
37     * Register parser hooks
38     *
39     * @param Parser $parser
40     */
41    public function onParserFirstCallInit( $parser ) {
42        $parser->setHook( 'pgn', [ ChessBrowser::class, 'newGame' ] );
43        $parser->setHook( 'fen', [ ChessBrowser::class, 'newPosition' ] );
44    }
45
46    /**
47     * Update OutputPage after ParserOutput is added, if it includes a chess board
48     *
49     * @param OutputPage $out
50     * @param ParserOutput $parserOutput
51     */
52    public function onOutputPageParserOutput( $out, $parserOutput ): void {
53        if ( $parserOutput->getExtensionData( 'ChessViewerFEN' ) ) {
54            $out->addModuleStyles( 'ext.chessViewer.styles' );
55        }
56        if ( $parserOutput->getExtensionData( 'ChessViewerTrigger' ) ) {
57            $out->addModuleStyles( [ 'ext.chessViewer.styles', 'jquery.makeCollapsible.styles' ] );
58            $out->addModules( [ 'ext.chessViewer', 'jquery.makeCollapsible' ] );
59        }
60    }
61}