r57728 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57727‎ | r57728 | r57729 >
Date:21:39, 14 October 2009
Author:dale
Status:reverted (Comments)
Tags:
Comment:
* (bug 21140) Fixed Upload Form for using an Antivirus Program on Windows
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadBase.php
@@ -814,11 +814,12 @@
815815 # Ask me (Duesentrieb) about it if it's ever needed.
816816 $output = array();
817817 if ( wfIsWindows() ) {
818 - exec( "$command", $output, $exitCode );
 818+ $output = wfRunExternal($command, $exitCode);
819819 } else {
820820 exec( "$command 2>&1", $output, $exitCode );
821821 }
822822
 823+
823824 # map exit code to AV_xxx constants.
824825 $mappedCode = $exitCode;
825826 if ( $exitCodeMap ) {
@@ -829,6 +830,7 @@
830831 }
831832 }
832833
 834+
833835 if ( $mappedCode === AV_SCAN_FAILED ) {
834836 # scan failed (code was mapped to false by $exitCodeMap)
835837 wfDebug( __METHOD__ . ": failed to scan $file (code $exitCode).\n" );
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -3346,3 +3346,55 @@
33473347 $langCode = implode ( '-' , $codeBCP );
33483348 return $langCode;
33493349 }
 3350+
 3351+/* Fixes shell_exec problems on Windows
 3352+ * From http://www.php.net/manual/de/function.shell-exec.php#52826 via bug 21140
 3353+ */
 3354+function wfRunExternal($cmd,&$code) {
 3355+ $descriptorspec = array(
 3356+ 0 => array("pipe", "r"), // stdin is a pipe that the child will read from
 3357+ 1 => array("pipe", "w"), // stdout is a pipe that the child will write to
 3358+ 2 => array("pipe", "w") // stderr is a file to write to
 3359+ );
 3360+
 3361+ $pipes= array();
 3362+ $process = proc_open($cmd, $descriptorspec, $pipes);
 3363+
 3364+ $output= "";
 3365+
 3366+ if (!is_resource($process)) return false;
 3367+
 3368+ #close child's input imidiately
 3369+ fclose($pipes[0]);
 3370+
 3371+ stream_set_blocking($pipes[1],false);
 3372+ stream_set_blocking($pipes[2],false);
 3373+
 3374+ $todo= array($pipes[1],$pipes[2]);
 3375+
 3376+ while( true ) {
 3377+ $read= array();
 3378+ if( !feof($pipes[1]) ) $read[]= $pipes[1];
 3379+ if( !feof($pipes[2]) ) $read[]= $pipes[2];
 3380+
 3381+ if (!$read) break;
 3382+
 3383+ $ready= stream_select($read, $write=NULL, $ex= NULL, 2);
 3384+
 3385+ if ($ready === false) {
 3386+ break; #should never happen - something died
 3387+ }
 3388+
 3389+ foreach ($read as $r) {
 3390+ $s= fread($r,1024);
 3391+ $output.= $s;
 3392+ }
 3393+ }
 3394+
 3395+ fclose($pipes[1]);
 3396+ fclose($pipes[2]);
 3397+
 3398+ $code= proc_close($process);
 3399+
 3400+ return $output;
 3401+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r57729* follow-up to r57728 switched to use global wfShellExec functiondale21:51, 14 October 2009

Comments

#Comment by Simetrical (talk | contribs)   20:01, 9 December 2009

Is this code appropriately licensed?

#Comment by Simetrical (talk | contribs)   20:02, 9 December 2009

Never mind, looks like it was removed in r57729.

Status & tagging log