Merge "wfTempDir try harder to get a tmp dir on Windows"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 12 May 2016 19:10:25 +0000 (19:10 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 12 May 2016 19:10:25 +0000 (19:10 +0000)
1  2 
includes/GlobalFunctions.php

@@@ -501,26 -501,12 +501,26 @@@ function wfAppendQuery( $url, $query ) 
                $query = wfArrayToCgi( $query );
        }
        if ( $query != '' ) {
 +              // Remove the fragment, if there is one
 +              $fragment = false;
 +              $hashPos = strpos( $url, '#' );
 +              if ( $hashPos !== false ) {
 +                      $fragment = substr( $url, $hashPos );
 +                      $url = substr( $url, 0, $hashPos );
 +              }
 +
 +              // Add parameter
                if ( false === strpos( $url, '?' ) ) {
                        $url .= '?';
                } else {
                        $url .= '&';
                }
                $url .= $query;
 +
 +              // Put the fragment back
 +              if ( $fragment !== false ) {
 +                      $url .= $fragment;
 +              }
        }
        return $url;
  }
@@@ -2134,6 -2120,24 +2134,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.' );
  }
@@@ -3123,9 -3127,6 +3141,9 @@@ function wfSplitWikiID( $wiki ) 
   * Note 2: use $this->getDB() in maintenance scripts that may be invoked by
   * updater to ensure that a proper database is being updated.
   *
 + * @todo Replace calls to wfGetDB with calls to LoadBalancer::getConnection()
 + *       on an injected instance of LoadBalancer.
 + *
   * @return DatabaseBase
   */
  function wfGetDB( $db, $groups = [], $wiki = false ) {
  /**
   * Get a load balancer object.
   *
 + * @deprecated since 1.27, use MediaWikiServices::getDBLoadBalancer()
 + *              or MediaWikiServices::getDBLoadBalancerFactory() instead.
 + *
   * @param string|bool $wiki Wiki ID, or false for the current wiki
   * @return LoadBalancer
   */
  function wfGetLB( $wiki = false ) {
 -      return wfGetLBFactory()->getMainLB( $wiki );
 +      if ( $wiki === false ) {
 +              return \MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancer();
 +      } else {
 +              $factory = \MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
 +              return $factory->getMainLB( $wiki );
 +      }
  }
  
  /**
   * Get the load balancer factory object
   *
 + * @deprecated since 1.27, use MediaWikiServices::getDBLoadBalancerFactory() instead.
 + *
   * @return LBFactory
   */
  function wfGetLBFactory() {
 -      return LBFactory::singleton();
 +      return \MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
  }
  
  /**