Legoktm has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/396476 )

Change subject: Drop symfony/process dependency, use Shell\Command instead
......................................................................

Drop symfony/process dependency, use Shell\Command instead

We originally started using symfony/process because kzykhys/pygments
depended upon it. But that library was unmaintained and became broken,
so we stopped using it, and just used symfony/process directly.

Today the only reason in favor of symfony/process is that it can pass
stdin to pygments, while Shell\Command can't (T182463). But there are
downsides, like not respecting the default MediaWiki shell limits,
cannot be used with core's firejail support, and requiring an external
composer dependency.

We can workaround the lack of stdin support for now by using a temporary
file. Note that because Shell::command() will enforce MediaWiki's normal
limits, it's possible that some large pages may no longer render with
syntax highlighting if they pass those limits.

Change-Id: Ie1cb72b7eb17d943f79ecae4d94a2110546ef039
---
M README
M SyntaxHighlight.class.php
M composer.json
M extension.json
4 files changed, 24 insertions(+), 31 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SyntaxHighlight_GeSHi 
refs/changes/76/396476/1

diff --git a/README b/README
index 61e774d..1384e9f 100644
--- a/README
+++ b/README
@@ -14,10 +14,7 @@
 
 == Installation ==
 
-First, you will need to ensure that this extension's Composer-managed
-dependencies are available. In the extension directory, run 'composer update'.
-
-Next, Add this line to your LocalSettings.php:
+Add this line to your LocalSettings.php:
 
     wfLoadExtension( 'SyntaxHighlight_GeSHi' );
 
diff --git a/SyntaxHighlight.class.php b/SyntaxHighlight.class.php
index 35f7db5..5859ff9 100644
--- a/SyntaxHighlight.class.php
+++ b/SyntaxHighlight.class.php
@@ -17,7 +17,6 @@
  */
 
 use MediaWiki\Shell\Shell;
-use Symfony\Component\Process\ProcessBuilder;
 
 // @codingStandardsIgnoreStart
 class SyntaxHighlight {
@@ -290,32 +289,33 @@
                        foreach ( $options as $k => $v ) {
                                $optionPairs[] = "{$k}={$v}";
                        }
-                       $builder = new ProcessBuilder();
-                       $builder->setPrefix( self::getPygmentizePath() );
-                       $process = $builder
-                               ->add( '-l' )->add( $lexer )
-                               ->add( '-f' )->add( 'html' )
-                               ->add( '-O' )->add( implode( ',', $optionPairs 
) )
-                               ->getProcess();
-
-                       $process->setInput( $code );
-
-                       /* Workaround for T151523 (buggy $process->getOutput()).
-                               If/when this issue is fixed in HHVM or Symfony,
-                               replace this with "$process->run(); $output = 
$process->getOutput();"
-                       */
-                       $output = '';
-                       $process->run( function ( $type, $capturedOutput ) use 
( &$output ) {
-                               $output .= $capturedOutput;
-                       } );
-
-                       if ( !$process->isSuccessful() ) {
+                       $tempName = tempnam( wfTempDir(), 'syntaxhighlight_' );
+                       $tempFile = fopen( $tempName, 'w' );
+                       if ( !$tempFile ) {
                                $status->warning( 
'syntaxhighlight-error-pygments-invocation-failure' );
-                               wfWarn( 'Failed to invoke Pygments: ' . 
$process->getErrorOutput() );
+                               wfWarn( 'Could not write to ' . $tempName );
+                               $status->value = self::highlight( $code, null, 
$args )->getValue();
+                               return $status;
+                       }
+                       fwrite( $tempFile, $code );
+                       fclose( $tempFile );
+                       $result = Shell::command( [
+                               self::getPygmentizePath(),
+                               '-l', $lexer,
+                               '-f', 'html',
+                               '-O', implode( ',', $optionPairs ),
+                               $tempName,
+                       ] )->execute();
+                       unlink( $tempName );
+
+                       if ( $result->getExitCode() != 0 ) {
+                               $status->warning( 
'syntaxhighlight-error-pygments-invocation-failure' );
+                               wfWarn( 'Failed to invoke Pygments: ' . 
$result->getStderr() );
                                $status->value = self::highlight( $code, null, 
$args )->getValue();
                                return $status;
                        }
 
+                       $output = $result->getStdout();
                        $cache->set( $cacheKey, $output );
                }
 
diff --git a/composer.json b/composer.json
index a566b40..047ac4e 100644
--- a/composer.json
+++ b/composer.json
@@ -1,9 +1,6 @@
 {
        "name": "mediawiki/syntax-highlight",
        "description": "Syntax highlighting extension for MediaWiki",
-       "require": {
-               "symfony/process": "~3.3"
-       },
        "require-dev": {
                "jakub-onderka/php-parallel-lint": "0.9.2",
                "mediawiki/mediawiki-codesniffer": "14.1.0",
diff --git a/extension.json b/extension.json
index dd753f3..618eebf 100644
--- a/extension.json
+++ b/extension.json
@@ -14,7 +14,7 @@
        "license-name": "GPL-2.0+",
        "type": "parserhook",
        "requires": {
-               "MediaWiki": ">= 1.27"
+               "MediaWiki": ">= 1.30"
        },
        "MessagesDirs": {
                "SyntaxHighlight_GeSHi": [
@@ -77,6 +77,5 @@
        "ParserTestFiles": [
                "tests/parserTests.txt"
        ],
-       "load_composer_autoloader": true,
        "manifest_version": 1
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/396476
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie1cb72b7eb17d943f79ecae4d94a2110546ef039
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SyntaxHighlight_GeSHi
Gerrit-Branch: master
Gerrit-Owner: Legoktm <lego...@member.fsf.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to