Topic on Project:Support desk

Jump to navigation Jump to search

Migrating from 1.9.3 to 1.34 - Geshi no longer available

14
46.232.228.6 (talkcontribs)

I was using the Geshi extension o 1.9.3 with content like


<code xml>

...

    <customcerts

dir="certs"

    />

...

</code>


Now the Geshi extension is gone and I could use Extension:SyntaxHighlight. However, I have hundreds of pages using the <code ''lang''> tag instead of <syntaxhighlight lang="''lang''">. Is there a solution to that apart from manually editing all of them?


Thanks and Regards, Christoph

AhmadF.Cheema (talkcontribs)
46.232.228.6 (talkcontribs)

Thanks for pointing me to Replace Text, @AhmadF.Cheema!

However, I do not get the extension to work on a Windows system:

syntaxhighlight uses Pygmentize directly (such as 'C:\...\SyntaxHighlight_GeSHi\includes/../pygments/pygmentize" "-l" "xml" "-f" "html" "-O" "cssclass"').

pygmentize is a script starting with "#!/usr/bin/env python3" which is going to work on *nix'ish systems fine but won't work on Windows. So I get an expection "PHP Notice: Failed to invoke Pygments" when the extensions tries to render a page.

I installed python 3.8 on the box which seems to run fine (at least, I can get a python prompt with now errors).

So as far as I am concerned, this won't ever work on Windows, does it?

Some googling yields a page saying you need to install ez_install.py and run it. I did so (downloading it from pypi.org) and it bails out saying "SSL required". So I edited it and changed the download URL from http to https.

Now it bails out saying "in self.chown(tarinfo, dirpath) TypeError: chown() missing 1 required positional argument: 'numeric_owner'".

It is frustrating :-|

Am I on the right track with getting ez_install to run?

Or is there a way to tell mediawiki to just call upon python.exe directly?

MarkAHershberger (talkcontribs)
46.232.228.6 (talkcontribs)

@MarkAHershberger you made my day - almost!

here it is in a nutshell:

      [ install python 3.8 ]

python -m ensurepip --default-pip

      python -m pip install --upgrade pip setuptools wheel

      easy_install Pygments

now there is a Windows pygmentize.exe in .../python/Scripts

set "$wgPygmentizePath = "C:/.../python/Scripts/pygmentize.exe"; in LocalSettings.php

I can run pygmentize from the shell.


But: although $wgPygmentizePath is set correctly, I keep getting

PHP Notice: fwrite(): write of 1597 bytes failed with errno=22 Invalid argument in C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\shell\Command.php on line 475

Apparently, proc_open in Command.php cannot start the executable.

Has anyone got SyntaxHighlight_GeSHi to work on a Windows/IIS system? (IIS 8.5, latest PHP 7) ?

MarkAHershberger (talkcontribs)

You seem to have stumbled upon a windows-only bug. Can you get a stacktrace of the error? Try the following:

  • $wgShowExceptionDetails Enable more details (like a stack trace) to be shown on the "Fatal error" page.
  • $wgShowDebug Adds the "log messages" part of wgDebugToolbar as a raw list to the page.
46.232.228.6 (talkcontribs)

@MarkAHershberger


Here is the trace:

PHP Notice:  fwrite(): write of 53 bytes failed with errno=22 Invalid argument in C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\shell\Command.php on line 474

PHP Stack trace:

PHP  17. PPFrame_Hash->expand() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\parser\Parser.php:3330

PHP  18. Parser->extensionSubstitution() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\parser\PPFrame_Hash.php:328

PHP  19. SyntaxHighlight::parserHook() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\parser\Parser.php:4293

PHP  20. SyntaxHighlight::highlight() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\extensions\SyntaxHighlight_GeSHi\includes\SyntaxHighlight.php:117

PHP  21. WANObjectCache->getWithSetCallback() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\extensions\SyntaxHighlight_GeSHi\includes\SyntaxHighlight.php:348

PHP  22. WANObjectCache->fetchOrRegenerate() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\libs\objectcache\wancache\WANObjectCache.php:1278

PHP  23. SyntaxHighlight::{closure:C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\extensions\SyntaxHighlight_GeSHi\includes\SyntaxHighlight.php:306-348}() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\libs\objectcache\wancache\WANObjectCache.php:1424

PHP  24. MediaWiki\Shell\Command->execute() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\extensions\SyntaxHighlight_GeSHi\includes\SyntaxHighlight.php:320

PHP  25. fwrite() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\shell\Command.php:474

PHP Notice:  Failed to invoke Pygments: Der Befehl "C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\extensions\SyntaxHighlight_GeSHi\python38\Scripts\pygmentize.exe" "-l" "xml" "-f" "html" "-O" "cssclass" ist entweder falsch geschrieben oder

konnte nicht gefunden werden.

[Called from SyntaxHighlight::highlight in C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\extensions\SyntaxHighlight_GeSHi\includes\SyntaxHighlight.php at line 353] in C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\debug\MWDebug.php on line 333

PHP  19. SyntaxHighlight::parserHook() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\parser\Parser.php:4293

PHP  20. SyntaxHighlight::highlight() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\extensions\SyntaxHighlight_GeSHi\includes\SyntaxHighlight.php:117

PHP  21. wfWarn() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\extensions\SyntaxHighlight_GeSHi\includes\SyntaxHighlight.php:353

PHP  22. MWDebug::warning() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\GlobalFunctions.php:1066

PHP  23. MWDebug::sendMessage() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\debug\MWDebug.php:188

PHP  24. trigger_error() C:\inetpub\wwwroot\wiki\mediawiki-1.34.0\includes\debug\MWDebug.php:334


[ I needed to shorten the trace cause mediwaiki was complaining about "Flow spam filter: large amount of consonant/vowel clusters" ]

I saw a note in PHP's doc for popen:

Example #2 proc_open() quirk on Windows

While one may expect the following program to search the file filename.txt for the text search and to print the results, it behaves rather differently.

<?php
$descriptorspec = [STDIN, STDOUT, STDOUT];
$cmd = '"findstr" "search" "filename.txt"';
$proc = proc_open($cmd, $descriptorspec, $pipes);
proc_close($proc);
?>

The above example will output:

'findstr" "search" "filename.txt' is not recognized as an internal or external command,
operable program or batch file.

To work around that behavior, it is usually sufficient to enclose the cmd in additional quotes:

$cmd = '""findstr" "search" "filename.txt""';


But I don't think its true. The symptom is exactly what I saw, however the solution doesn't work.

46.232.228.6 (talkcontribs)

I finally got tired of this and sort of "fixed" it by changing the code in mediawiki-1.34.0\extensions\SyntaxHighlight_GeSHi\includes\SyntaxHighlight.php from

311 				$result = Shell::command(
312 					self::getPygmentizePath(),
313 					'-l', $lexer,
314 					'-f', 'html',
315 					'-O', implode( ',', $optionPairs )
316 				)
317 					->input( $code )
318 					->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK )
319 					->execute();
320 
321 				if ( $result->getExitCode() != 0 ) {
322 					$ttl = WANObjectCache::TTL_UNCACHEABLE;
323 					$error = $result->getStderr();
324 					return null;
325 				}
326                                 
327 				return $result->getStdout();

to:

                                $cmd = '"' . self::getPygmentizePath() . '" ' . 
				                    	'-l ' . '"' . $lexer . '" ' .
			                       		'-f ' . 'html ' . 
		                    			'-O ' . implode( ',', $optionPairs );
                                $filebase = @tempnam(wfTempDir(), "geshi");
                                $ioi = "$filebase-i.txt";
                                file_put_contents($ioi, $code);
                                $pyg = shell_exec("$cmd < \"$ioi\"");
                                if (false) {
                                    // debug, keep in/out put
                                    $ioo = "$filebase-o.txt";
                                    file_put_contents($ioo, $pyg);
                                } else {
                                    unlink($ioi);
                                }
                                return $pyg;

This is of course ugly to say the least but it works somehow and should be fine until a fix is there.

Let me add that I felt the Shell:: code to be overly complicated. However, I was perhaps just not fair cause it refused to work for me for so long ;-)

MarkAHershberger (talkcontribs)

It looks like this might be task T193613. Four months later, I don't know why I wrote this. It must be a typo.

Berot3 (talkcontribs)

I have the same problem too... So what you are saying is that this error should disappear with mw 1.35?

MarkAHershberger (talkcontribs)

I'm not sure why I thought a stable interface policy would help. That must be a typo.

79.208.145.217 (talkcontribs)

I have exactly the same problem.

JGTompkins (talkcontribs)
Reply to "Migrating from 1.9.3 to 1.34 - Geshi no longer available"