Page MenuHomePhabricator

SyntaxHighlight fails to highlight code and adds 'Pages with syntax highlighting errors' category to page
Open, Needs TriagePublic

Description

SyntaxHighlight does not add the HTML to highlight code, simply adding a <pre> tag around the code block which is meant to be highlighted and erroneously adding the 'Pages with syntax highlighting errors' category to the page.

The Debug console reports a Warning : Failed to invoke Pygments: env: python: No such file or directory
The log shows the following stacktrace:

[error] [154a08a1] /wiki/FreeBSD_Mail_Server ErrorException from line 300 of /usr/local/www/mediawiki/includes/debug/MWDebug.php: PHP Notice: Failed to invoke Pygments: env: python: No such file or directory
[Called from SyntaxHighlight_GeSHi::highlight in /usr/local/www/mediawiki/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php at line 296][error-json]
{"id":"154a08a1","type":"ErrorException","file":"/usr/local/www/mediawiki/includes/debug/MWDebug.php","line":300,"message":"PHP Notice: Failed to invoke Pygments: env: python: No such file or directory\n [Called from SyntaxHighlight_GeSHi::highlight in /usr/local/www/mediawiki/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php at line 296]","code":0,"url":"/wiki/FreeBSD_Mail_Server","backtrace":[{"function":"handleError","class":"MWExceptionHandler","type":"::","args":["integer","string","string","integer","array"]},
{"file":"/usr/local/www/mediawiki/includes/debug/MWDebug.php","line":300,"function":"trigger_error","args":["string","integer"]},
{"file":"/usr/local/www/mediawiki/includes/debug/MWDebug.php","line":155,"function":"sendMessage","class":"MWDebug","type":"::","args":["string","array","string","integer"]},
{"file":"/usr/local/www/mediawiki/includes/GlobalFunctions.php","line":1209,"function":"warning","class":"MWDebug","type":"::","args":["string","integer","integer","string"]},
{"file":"/usr/local/www/mediawiki/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php","line":296,"function":"wfWarn","args":["string"]},
{"file":"/usr/local/www/mediawiki/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php","line":127,"function":"highlight","class":"SyntaxHighlight_GeSHi","type":"::","args":["string","string","array"]},
{"function":"parserHook","class":"SyntaxHighlight_GeSHi","type":"::","args":["string","array","Parser","PPFrame_DOM"]},
{"file":"/usr/local/www/mediawiki/includes/parser/Parser.php","line":4234,"function":"call_user_func_array","args":["array","array"]},
{"file":"/usr/local/www/mediawiki/includes/parser/Preprocessor_DOM.php","line":1262,"function":"extensionSubstitution","class":"Parser","type":"->","args":["array","PPFrame_DOM"]},
{"file":"/usr/local/www/mediawiki/includes/parser/Parser.php","line":3342,"function":"expand","class":"PPFrame_DOM","type":"->","args":["PPNode_DOM","integer"]},
{"file":"/usr/local/www/mediawiki/includes/parser/Parser.php","line":1239,"function":"replaceVariables","class":"Parser","type":"->","args":["string"]},
{"file":"/usr/local/www/mediawiki/includes/parser/Parser.php","line":439,"function":"internalParse","class":"Parser","type":"->","args":["string"]},
{"file":"/usr/local/www/mediawiki/includes/content/WikitextContent.php","line":331,"function":"parse","class":"Parser","type":"->","args["string","Title","ParserOptions","boolean","boolean","integer"]},
{"file":"/usr/local/www/mediawiki/includes/content/AbstractContent.php","line":497,"function":"fillParserOutput","class":"WikitextContent","type":"->","args":["Title","integer","ParserOptions","boolean","ParserOutput"]},
{"file":"/usr/local/www/mediawiki/includes/poolcounter/PoolWorkArticleView.php","line":140,"function":"getParserOutput","class":"AbstractContent","type":"->","args"["Title","integer","ParserOptions"]},
{"file":"/usr/local/www/mediawiki/includes/poolcounter/PoolCounterWork.php","line":123,"function":"doWork","class":"PoolWorkArticleView","type":"->","args":[]},
{"file":"/usr/local/www/mediawiki/includes/page/Article.php","line":676,"function":"execute","class":"PoolCounterWork","type":"->","args":[]},
{"file":"/usr/local/www/mediawiki/includes/actions/ViewAction.php","line":44,"function":"view","class":"Article","type":"->","args":[]},
{"file":"/usr/local/www/mediawiki/includes/MediaWiki.php","line":490,"function":"show","class":"ViewAction","type":"->","args":[]},
{"file":"/usr/local/www/mediawiki/includes/MediaWiki.php","line":287,"function":"performAction","class":"MediaWiki","type":"->","args":["Article","Title"]},
{"file":"/usr/local/www/mediawiki/includes/MediaWiki.php","line":714,"function":"performRequest","class":"MediaWiki","type":"->","args":[]},
{"file":"/usr/local/www/mediawiki/includes/MediaWiki.php","line":508,"function":"main","class":"MediaWiki","type":"->","args":[]},
{"file":"/usr/local/www/mediawiki/index.php","line":41,"function":"run","class":"MediaWiki","type":"->","args":[]}]}

This is on MediaWiki 1.26.2 with PHP 5.6.20

Invoking pygmentize from the commandline works and produces the correct output, as does invoking it with PHP proc_open() and via Symfony\Components\Process\ProcessBuilder.

Event Timeline

Setting $wgPygmentizePath to an external version of Pygments instead of the bundled version allows the syntax highlighting to function as expected.

Thanbks for investigating! Any external version, or a more recent one? Any version information to share?

Failed to invoke Pygments: env: python: No such file or directory

You don't have Python installed? Maybe it's called something else?

Thanbks for investigating! Any external version, or a more recent one? Any version information to share?

Both /usr/local/bin/pygmentize (working) and the internal pygments report that they are version 2.1. I have not tested any other versions.

Failed to invoke Pygments: env: python: No such file or directory

You don't have Python installed? Maybe it's called something else?

Python is installed (version 2.7.11) and the pygments binary installed with the extension is called 'pygmentize'

I have the same problem at my wiki:
Продукт Версия
MediaWiki 1.35.1
PHP 7.4.20 (cgi-fcgi)
MySQL 5.7.34
ICU 57.1

Once it was working fine with following settings:

Syntax highlight

wfLoadExtension( 'SyntaxHighlight_GeSHi' );
$wgPygmentizePath = "/usr/local/bin/pygmentize";

but then something happened. The pages that used this extension first shoed error page. I have re-uploaded the folder to extension's folder. Now I see that the code are not highlighted. And pages marked as syntax highlighting errors' category. How can I fix the problem?