Merge "Switch DifferenceEngine to the new shell framework"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 21 Oct 2017 00:23:47 +0000 (00:23 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 21 Oct 2017 00:23:47 +0000 (00:23 +0000)
includes/diff/DifferenceEngine.php

index a9d6ad6..899054d 100644 (file)
@@ -21,6 +21,7 @@
  * @ingroup DifferenceEngine
  */
 use MediaWiki\MediaWikiServices;
+use MediaWiki\Shell\Shell;
 
 /** @deprecated use class constant instead */
 define( 'MW_DIFF_VERSION', '1.11a' );
@@ -966,8 +967,16 @@ class DifferenceEngine extends ContextSource {
                        fwrite( $tempFile2, $ntext );
                        fclose( $tempFile1 );
                        fclose( $tempFile2 );
-                       $cmd = wfEscapeShellArg( $wgExternalDiffEngine, $tempName1, $tempName2 );
-                       $difftext = wfShellExec( $cmd );
+                       $cmd = [ $wgExternalDiffEngine, $tempName1, $tempName2 ];
+                       $result = Shell::command( $cmd )
+                               ->execute();
+                       $exitCode = $result->getExitCode();
+                       if ( $exitCode !== 0 ) {
+                               throw new Exception( "External diff command returned code {$exitCode}. Stderr: "
+                                       . wfEscapeWikiText( $result->getStderr() )
+                               );
+                       }
+                       $difftext = $result->getStdout();
                        $difftext .= $this->debug( "external $wgExternalDiffEngine" );
                        unlink( $tempName1 );
                        unlink( $tempName2 );