From 987187935c531dfc11a022bdb33a548304bb8b7c Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Mon, 23 Jan 2017 13:34:06 -0800 Subject: [PATCH] Make sure $wgPygmentizePath is sane only when we need it This avoids having an extension function, which runs on every request, regardless of whether it uses syntax highlighting or not. Change-Id: I890348b73af956819300cce64d0672dcdb209c19 --- SyntaxHighlight.class.php | 27 +++++++++++++++------------ extension.json | 3 --- maintenance/updateCSS.php | 4 +--- maintenance/updateLexerList.php | 4 +--- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/SyntaxHighlight.class.php b/SyntaxHighlight.class.php index 0ab8f032..1c16d560 100644 --- a/SyntaxHighlight.class.php +++ b/SyntaxHighlight.class.php @@ -41,15 +41,6 @@ class SyntaxHighlight { 'text/xml' => 'xml', ]; - public static function onSetup() { - global $wgPygmentizePath; - - // If $wgPygmentizePath is unset, use the bundled copy. - if ( $wgPygmentizePath === false ) { - $wgPygmentizePath = __DIR__ . '/pygments/pygmentize'; - } - } - /** * Get the Pygments lexer name for a particular language. * @@ -187,6 +178,20 @@ class SyntaxHighlight { return $out; } + /** + * @return string + */ + public static function getPygmentizePath() { + global $wgPygmentizePath; + + // If $wgPygmentizePath is unset, use the bundled copy. + if ( $wgPygmentizePath === false ) { + $wgPygmentizePath = __DIR__ . '/pygments/pygmentize'; + } + + return $wgPygmentizePath; + } + /** * Highlight a code-block using a particular lexer. * @@ -203,8 +208,6 @@ class SyntaxHighlight { * code as its value. */ public static function highlight( $code, $lang = null, $args = [] ) { - global $wgPygmentizePath; - $status = new Status; $lexer = self::getLexer( $lang ); @@ -287,7 +290,7 @@ class SyntaxHighlight { $optionPairs[] = "{$k}={$v}"; } $builder = new ProcessBuilder(); - $builder->setPrefix( $wgPygmentizePath ); + $builder->setPrefix( self::getPygmentizePath() ); $process = $builder ->add( '-l' )->add( $lexer ) ->add( '-f' )->add( 'html' ) diff --git a/extension.json b/extension.json index c32c6cc7..dd753f36 100644 --- a/extension.json +++ b/extension.json @@ -30,9 +30,6 @@ "ResourceLoaderGeSHiVisualEditorModule": "ResourceLoaderSyntaxHighlightVisualEditorModule.php", "ResourceLoaderSyntaxHighlightVisualEditorModule": "ResourceLoaderSyntaxHighlightVisualEditorModule.php" }, - "ExtensionFunctions": [ - "SyntaxHighlight::onSetup" - ], "ResourceFileModulePaths": { "localBasePath": "modules", "remoteExtPath": "SyntaxHighlight_GeSHi/modules" diff --git a/maintenance/updateCSS.php b/maintenance/updateCSS.php index 95fc6fcf..ce953cb6 100644 --- a/maintenance/updateCSS.php +++ b/maintenance/updateCSS.php @@ -36,13 +36,11 @@ class UpdateCSS extends Maintenance { } public function execute() { - global $wgPygmentizePath; - $target = __DIR__ . '/../modules/pygments.generated.css'; $css = "/* Stylesheet generated by updateCSS.php */\n"; $builder = new ProcessBuilder(); - $builder->setPrefix( $wgPygmentizePath ); + $builder->setPrefix( SyntaxHighlight_GeSHi::getPygmentizePath() ); $process = $builder ->add( '-f' )->add( 'html' ) diff --git a/maintenance/updateLexerList.php b/maintenance/updateLexerList.php index 0b3e5e37..00ee8a43 100644 --- a/maintenance/updateLexerList.php +++ b/maintenance/updateLexerList.php @@ -35,8 +35,6 @@ class UpdateLanguageList extends Maintenance { } public function execute() { - global $wgPygmentizePath; - function lang_filter( $val ) { return preg_match( '/^[a-zA-Z0-9\-_]+$/', $val ); } @@ -46,7 +44,7 @@ class UpdateLanguageList extends Maintenance { $lexers = []; $builder = new ProcessBuilder(); - $builder->setPrefix( $wgPygmentizePath ); + $builder->setPrefix( SyntaxHighlight_GeSHi::getPygmentizePath() ); $process = $builder->add( '-L' )->add( 'lexer' )->getProcess(); $process->run();