Debian Codegraph @

extensions/SyntaxHighlight_GeSHi/includes/ResourceLoaderPygmentsModule.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright (C) 2021 Kunal Mehta <[email protected]>
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
21 namespace MediaWiki\SyntaxHighlight;
22
23 use MediaWiki\ResourceLoader as RL;
24
25 /**
26 * At runtime switch between bundled CSS or dynamically generated
27 */
28 class 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 }