Merge "New hook for filters on Special:Contributions form"
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 26fb223..1f9d14e 100644 (file)
@@ -1474,7 +1474,7 @@ function wfMsgReplaceArgs( $message, $args ) {
        $message = str_replace( "\r", '', $message );
 
        // Replace arguments
-       if ( count( $args ) ) {
+       if ( is_array( $args ) && $args ) {
                if ( is_array( $args[0] ) ) {
                        $args = array_values( $args[0] );
                }
@@ -2161,8 +2161,8 @@ function wfIsHHVM() {
 /**
  * Tries to get the system directory for temporary files. First
  * $wgTmpDirectory is checked, and then the TMPDIR, TMP, and TEMP
- * environment variables are then checked in sequence, and if none are
- * set try sys_get_temp_dir().
+ * environment variables are then checked in sequence, then
+ * sys_get_temp_dir(), then upload_tmp_dir from php.ini.
  *
  * NOTE: When possible, use instead the tmpfile() function to create
  * temporary files to avoid race conditions on file creation, etc.
@@ -2177,13 +2177,16 @@ function wfTempDir() {
        }
 
        $tmpDir = array_map( "getenv", array( 'TMPDIR', 'TMP', 'TEMP' ) );
+       $tmpDir[] = sys_get_temp_dir();
+       $tmpDir[] = ini_get( 'upload_tmp_dir' );
 
        foreach ( $tmpDir as $tmp ) {
                if ( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
                        return $tmp;
                }
        }
-       return sys_get_temp_dir();
+       throw new MWException( 'No writable temporary directory could be found. ' .
+               'Please set $wgTmpDirectory to a writable directory.' );
 }
 
 /**
@@ -3360,55 +3363,35 @@ function wfGetNull() {
  * @param string|bool $cluster Cluster name accepted by LBFactory. Default: false.
  * @param int|null $timeout Max wait time. Default: 1 day (cli), ~10 seconds (web)
  * @return bool Success (able to connect and no timeouts reached)
+ * @deprecated since 1.27 Use LBFactory::waitForReplication
  */
 function wfWaitForSlaves(
        $ifWritesSince = null, $wiki = false, $cluster = false, $timeout = null
 ) {
-       // B/C: first argument used to be "max seconds of lag"; ignore such values
-       $ifWritesSince = ( $ifWritesSince > 1e9 ) ? $ifWritesSince : null;
-
        if ( $timeout === null ) {
                $timeout = ( PHP_SAPI === 'cli' ) ? 86400 : 10;
        }
 
-       // Figure out which clusters need to be checked
-       /** @var LoadBalancer[] $lbs */
-       $lbs = array();
        if ( $cluster === '*' ) {
-               wfGetLBFactory()->forEachLB( function ( LoadBalancer $lb ) use ( &$lbs ) {
-                       $lbs[] = $lb;
-               } );
-       } elseif ( $cluster !== false ) {
-               $lbs[] = wfGetLBFactory()->getExternalLB( $cluster );
-       } else {
-               $lbs[] = wfGetLB( $wiki );
-       }
-
-       // Get all the master positions of applicable DBs right now.
-       // This can be faster since waiting on one cluster reduces the
-       // time needed to wait on the next clusters.
-       $masterPositions = array_fill( 0, count( $lbs ), false );
-       foreach ( $lbs as $i => $lb ) {
-               if ( $lb->getServerCount() <= 1 ) {
-                       // Bug 27975 - Don't try to wait for slaves if there are none
-                       // Prevents permission error when getting master position
-                       continue;
-               } elseif ( $ifWritesSince && $lb->lastMasterChangeTimestamp() < $ifWritesSince ) {
-                       continue; // no writes since the last wait
-               }
-               $masterPositions[$i] = $lb->getMasterPos();
+               $cluster = false;
+               $wiki = false;
+       } elseif ( $wiki === false ) {
+               $wiki = wfWikiID();
        }
 
-       $ok = true;
-       foreach ( $lbs as $i => $lb ) {
-               if ( $masterPositions[$i] ) {
-                       // The DBMS may not support getMasterPos() or the whole
-                       // load balancer might be fake (e.g. $wgAllDBsAreLocalhost).
-                       $ok = $lb->waitForAll( $masterPositions[$i], $timeout ) && $ok;
-               }
+       try {
+               wfGetLBFactory()->waitForReplication( array(
+                       'wiki' => $wiki,
+                       'cluster' => $cluster,
+                       'timeout' => $timeout,
+                       // B/C: first argument used to be "max seconds of lag"; ignore such values
+                       'ifWritesSince' => ( $ifWritesSince > 1e9 ) ? $ifWritesSince : null
+               ) );
+       } catch ( DBReplicationWaitError $e ) {
+               return false;
        }
 
-       return $ok;
+       return true;
 }
 
 /**