Switch ServiceWiring to the new execution framework
authorMax Semenik <maxsem.wiki@gmail.com>
Wed, 25 Oct 2017 01:51:45 +0000 (18:51 -0700)
committerGergő Tisza <gtisza@wikimedia.org>
Wed, 4 Apr 2018 13:53:28 +0000 (13:53 +0000)
To test:

$wgMimeDetectorCommand = 'file -bi';
$services = \MediaWiki\MediaWikiServices::getInstance();
echo $services->getMimeAnalyzer()->guessMimeType('/vagrant/mediawiki/README');

Change-Id: Iaf124901c68292736e5588636f5ec746147f6a54

includes/ServiceWiring.php

index 5131917..dd837a8 100644 (file)
@@ -286,8 +286,14 @@ return [
 
                $detectorCmd = $mainConfig->get( 'MimeDetectorCommand' );
                if ( $detectorCmd ) {
-                       $params['detectCallback'] = function ( $file ) use ( $detectorCmd ) {
-                               return wfShellExec( "$detectorCmd " . wfEscapeShellArg( $file ) );
+                       $factory = $services->getShellCommandFactory();
+                       $params['detectCallback'] = function ( $file ) use ( $detectorCmd, $factory ) {
+                               $result = $factory->create()
+                                       // $wgMimeDetectorCommand can contain commands with parameters
+                                       ->unsafeParams( $detectorCmd )
+                                       ->params( $file )
+                                       ->execute();
+                               return $result->getStdout();
                        };
                }