wfTempDir try harder to get a tmp dir on Windows
authoraddshore <addshorewiki@gmail.com>
Wed, 20 Apr 2016 20:39:04 +0000 (21:39 +0100)
committeraddshore <addshorewiki@gmail.com>
Wed, 4 May 2016 18:42:22 +0000 (19:42 +0100)
Bug: T44730
Change-Id: If6f93ed50dfd93a1ffe046218058674a2197a626

includes/GlobalFunctions.php

index 5c42bc2..0544c00 100644 (file)
@@ -2120,6 +2120,24 @@ function wfTempDir() {
                        return $tmp;
                }
        }
+
+       /**
+        * PHP on Windows will detect C:\Windows\Temp as not writable even though PHP can write to it
+        * so create a directory within that called 'mwtmp' with a suffix of the user running the
+        * current process.
+        * The user is included as if various scripts are run by different users they will likely
+        * not be able to access each others temporary files.
+        */
+       if ( wfIsWindows() ) {
+               $tmp = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mwtmp' . '-' . get_current_user();
+               if ( !file_exists( $tmp ) ) {
+                       mkdir( $tmp );
+               }
+               if ( file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
+                       return $tmp;
+               }
+       }
+
        throw new MWException( 'No writable temporary directory could be found. ' .
                'Please set $wgTmpDirectory to a writable directory.' );
 }