Merge "Clean up "bad parameter" error messages in Message handler"
[lhc/web/wiklou.git] / includes / diff / DifferenceEngine.php
index a9d6ad6..15506c8 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' );
@@ -181,13 +182,15 @@ class DifferenceEngine extends ContextSource {
        public function deletedLink( $id ) {
                if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
                        $dbr = wfGetDB( DB_REPLICA );
-                       $row = $dbr->selectRow( 'archive',
-                               array_merge(
-                                       Revision::selectArchiveFields(),
-                                       [ 'ar_namespace', 'ar_title' ]
-                               ),
+                       $arQuery = Revision::getArchiveQueryInfo();
+                       $row = $dbr->selectRow(
+                               $arQuery['tables'],
+                               array_merge( $arQuery['fields'], [ 'ar_namespace', 'ar_title' ] ),
                                [ 'ar_rev_id' => $id ],
-                               __METHOD__ );
+                               __METHOD__,
+                               [],
+                               $arQuery['joins']
+                       );
                        if ( $row ) {
                                $rev = Revision::newFromArchiveRow( $row );
                                $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
@@ -604,14 +607,15 @@ class DifferenceEngine extends ContextSource {
                $out->addHTML( "<hr class='diff-hr' id='mw-oldid' />
                <h2 class='diff-currentversion-title'>{$revHeader}</h2>\n" );
                # Page content may be handled by a hooked call instead...
-               # @codingStandardsIgnoreStart Ignoring long lines.
                if ( Hooks::run( 'ArticleContentOnDiff', [ $this, $out ] ) ) {
                        $this->loadNewText();
                        $out->setRevisionId( $this->mNewid );
                        $out->setRevisionTimestamp( $this->mNewRev->getTimestamp() );
                        $out->setArticleFlag( true );
 
-                       if ( !Hooks::run( 'ArticleContentViewCustom', [ $this->mNewContent, $this->mNewPage, $out ] ) ) {
+                       if ( !Hooks::run( 'ArticleContentViewCustom',
+                               [ $this->mNewContent, $this->mNewPage, $out ] )
+                       ) {
                                // Handled by extension
                        } else {
                                // Normal page
@@ -630,13 +634,14 @@ class DifferenceEngine extends ContextSource {
                                # WikiPage::getParserOutput() should not return false, but just in case
                                if ( $parserOutput ) {
                                        // Allow extensions to change parser output here
-                                       if ( Hooks::run( 'DifferenceEngineRenderRevisionAddParserOutput', [ $this, $out, $parserOutput, $wikiPage ] ) ) {
+                                       if ( Hooks::run( 'DifferenceEngineRenderRevisionAddParserOutput',
+                                               [ $this, $out, $parserOutput, $wikiPage ] )
+                                       ) {
                                                $out->addParserOutput( $parserOutput );
                                        }
                                }
                        }
                }
-               # @codingStandardsIgnoreEnd
 
                // Allow extensions to optionally not show the final patrolled link
                if ( Hooks::run( 'DifferenceEngineRenderRevisionShowFinalPatrolLink' ) ) {
@@ -922,7 +927,7 @@ class DifferenceEngine extends ContextSource {
                        $wikidiff2Version = phpversion( 'wikidiff2' );
                        if (
                                $wikidiff2Version !== false &&
-                               version_compare( $wikidiff2Version, '0.3', '>=' )
+                               version_compare( $wikidiff2Version, '1.5.0', '>=' )
                        ) {
                                $text = wikidiff2_do_diff(
                                        $otext,
@@ -966,8 +971,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 );