Switch DifferenceEngine to the new shell framework
authorMax Semenik <maxsem.wiki@gmail.com>
Tue, 17 Oct 2017 06:53:50 +0000 (23:53 -0700)
committerMax Semenik <maxsem.wiki@gmail.com>
Fri, 20 Oct 2017 23:03:04 +0000 (16:03 -0700)
Change-Id: Iad8718e5f54ed829efded8efbb0f3496c119e6ad

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