From 782b20762121d2a8070df71213da4676dcfad081 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Mon, 16 Oct 2017 23:53:50 -0700 Subject: [PATCH] Switch DifferenceEngine to the new shell framework Change-Id: Iad8718e5f54ed829efded8efbb0f3496c119e6ad --- includes/diff/DifferenceEngine.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index a9d6ad69d4..899054d6c4 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -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 ); -- 2.20.1