Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ResourceLoaderPygmentsModule
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 supportsURLLoading
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getStyles
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getDefinitionSummary
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Copyright (C) 2021 Kunal Mehta <legoktm@debian.org>
4 *
5 * This program 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 2 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 */
20
21namespace MediaWiki\SyntaxHighlight;
22
23use MediaWiki\ResourceLoader as RL;
24
25/**
26 * At runtime switch between bundled CSS or dynamically generated
27 */
28class ResourceLoaderPygmentsModule extends RL\FileModule {
29
30    private bool $useBundled;
31
32    /** @inheritDoc */
33    public function __construct(
34        array $options = [],
35        $localBasePath = null,
36        $remoteBasePath = null
37    ) {
38        $this->useBundled = Pygmentize::useBundled();
39        if ( $this->useBundled ) {
40            // Generated styles before our overrides
41            array_unshift( $options['styles'], 'pygments.generated.css' );
42        }
43        parent::__construct( $options, $localBasePath, $remoteBasePath );
44    }
45
46    /**
47     * We sometimes have generated styles
48     *
49     * @return bool
50     */
51    public function supportsURLLoading() {
52        return false;
53    }
54
55    /** @inheritDoc */
56    public function getStyles( RL\Context $context ) {
57        $styles = parent::getStyles( $context );
58        if ( !$this->useBundled ) {
59            // Generated styles before our overrides
60            $styles['all'] = Pygmentize::getGeneratedCSS() . ( $styles['all'] ?? '' );
61        }
62
63        return $styles;
64    }
65
66    /** @inheritDoc */
67    public function getDefinitionSummary( RL\Context $context ) {
68        $summary = parent::getDefinitionSummary( $context );
69        if ( !$this->useBundled ) {
70            $summary[] = Pygmentize::getVersion();
71        }
72        return $summary;
73    }
74
75}