Merge "Make sure $wgPygmentizePath is sane only when we need it"

This commit is contained in:
jenkins-bot 2017-07-07 23:16:25 +00:00 committed by Gerrit Code Review
commit 73618fa360
4 changed files with 17 additions and 21 deletions

View file

@ -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' )

View file

@ -30,9 +30,6 @@
"ResourceLoaderGeSHiVisualEditorModule": "ResourceLoaderSyntaxHighlightVisualEditorModule.php",
"ResourceLoaderSyntaxHighlightVisualEditorModule": "ResourceLoaderSyntaxHighlightVisualEditorModule.php"
},
"ExtensionFunctions": [
"SyntaxHighlight::onSetup"
],
"ResourceFileModulePaths": {
"localBasePath": "modules",
"remoteExtPath": "SyntaxHighlight_GeSHi/modules"

View file

@ -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' )

View file

@ -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();