Merge "Fixed detection of unsigned mysql column in updater"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 5 Mar 2015 18:58:14 +0000 (18:58 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 5 Mar 2015 18:58:14 +0000 (18:58 +0000)
includes/GlobalFunctions.php
includes/api/ApiMain.php
includes/libs/virtualrest/ParsoidVirtualRESTService.php
tests/phpunit/includes/GlobalFunctions/wfEscapeShellArgTest.php [new file with mode: 0644]

index c0b8913..dfced1c 100644 (file)
@@ -2660,13 +2660,19 @@ function wfIniGetBool( $setting ) {
  * Also fixes the locale problems on Linux in PHP 5.2.6+ (bug backported to
  * earlier distro releases of PHP)
  *
- * @param string $args,...
+ * @param string ... strings to escape and glue together, or a single array of strings parameter
  * @return string
  */
 function wfEscapeShellArg( /*...*/ ) {
        wfInitShellLocale();
 
        $args = func_get_args();
+       if ( count( $args ) === 1 && is_array( reset( $args ) ) ) {
+               // If only one argument has been passed, and that argument is an array,
+               // treat it as a list of arguments
+               $args = reset( $args );
+       }
+
        $first = true;
        $retVal = '';
        foreach ( $args as $arg ) {
@@ -2799,12 +2805,7 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
                }
        }
        if ( is_array( $cmd ) ) {
-               // Command line may be given as an array, escape each value and glue them together with a space
-               $cmdVals = array();
-               foreach ( $cmd as $val ) {
-                       $cmdVals[] = wfEscapeShellArg( $val );
-               }
-               $cmd = implode( ' ', $cmdVals );
+               $cmd = wfEscapeShellArg( $cmd );
        }
 
        $cmd = $envcmd . $cmd;
@@ -3047,7 +3048,7 @@ function wfShellWikiCmd( $script, array $parameters = array(), array $options =
        }
        $cmd[] = $script;
        // Escape each parameter for shell
-       return implode( " ", array_map( 'wfEscapeShellArg', array_merge( $cmd, $parameters ) ) );
+       return wfEscapeShellArg( array_merge( $cmd, $parameters ) );
 }
 
 /**
@@ -3092,10 +3093,7 @@ function wfMerge( $old, $mine, $yours, &$result ) {
        fclose( $yourtextFile );
 
        # Check for a conflict
-       $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a --overlap-only ' .
-               wfEscapeShellArg( $mytextName ) . ' ' .
-               wfEscapeShellArg( $oldtextName ) . ' ' .
-               wfEscapeShellArg( $yourtextName );
+       $cmd = wfEscapeShellArg( $wgDiff3, '-a', '--overlap-only', $mytextName, $oldtextName, $yourtextName );
        $handle = popen( $cmd, 'r' );
 
        if ( fgets( $handle, 1024 ) ) {
@@ -3106,8 +3104,7 @@ function wfMerge( $old, $mine, $yours, &$result ) {
        pclose( $handle );
 
        # Merge differences
-       $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a -e --merge ' .
-               wfEscapeShellArg( $mytextName, $oldtextName, $yourtextName );
+       $cmd = wfEscapeShellArg( $wgDiff3, '-a', '-e', '--merge', $mytextName, $oldtextName, $yourtextName );
        $handle = popen( $cmd, 'r' );
        $result = '';
        do {
index d5cd475..9dc2411 100644 (file)
@@ -658,8 +658,24 @@ class ApiMain extends ApiBase {
                        $out->addVaryHeader( 'X-Forwarded-Proto' );
                }
 
+               // The logic should be:
+               // $this->mCacheControl['max-age'] is set?
+               //    Use it, the module knows better than our guess.
+               // !$this->mModule || $this->mModule->isWriteMode(), and mCacheMode is private?
+               //    Use 0 because we can guess caching is probably the wrong thing to do.
+               // Use $this->getParameter( 'maxage' ), which already defaults to 0.
+               $maxage = 0;
+               if ( isset( $this->mCacheControl['max-age'] ) ) {
+                       $maxage = $this->mCacheControl['max-age'];
+               } elseif ( ( $this->mModule && !$this->mModule->isWriteMode() ) ||
+                       $this->mCacheMode !== 'private'
+               ) {
+                       $maxage = $this->getParameter( 'maxage' );
+               }
+               $privateCache = 'private, must-revalidate, max-age=' . $maxage;
+
                if ( $this->mCacheMode == 'private' ) {
-                       $response->header( 'Cache-Control: private' );
+                       $response->header( "Cache-Control: $privateCache" );
                        return;
                }
 
@@ -671,14 +687,14 @@ class ApiMain extends ApiBase {
                                $response->header( $out->getXVO() );
                                if ( $out->haveCacheVaryCookies() ) {
                                        // Logged in, mark this request private
-                                       $response->header( 'Cache-Control: private' );
+                                       $response->header( "Cache-Control: $privateCache" );
                                        return;
                                }
                                // Logged out, send normal public headers below
                        } elseif ( session_id() != '' ) {
                                // Logged in or otherwise has session (e.g. anonymous users who have edited)
                                // Mark request private
-                               $response->header( 'Cache-Control: private' );
+                               $response->header( "Cache-Control: $privateCache" );
 
                                return;
                        } // else no XVO and anonymous, send public headers below
@@ -702,7 +718,7 @@ class ApiMain extends ApiBase {
                        // Public cache not requested
                        // Sending a Vary header in this case is harmless, and protects us
                        // against conditional calls of setCacheMaxAge().
-                       $response->header( 'Cache-Control: private' );
+                       $response->header( "Cache-Control: $privateCache" );
 
                        return;
                }
index 03bdf0d..769cecf 100644 (file)
@@ -59,7 +59,7 @@ class ParsoidVirtualRESTService extends VirtualRESTService {
                                throw new Exception( "Only 'local' target wiki is currently supported" );
                        } elseif ( $version !== 'v1' ) {
                                throw new Exception( "Only version 1 exists" );
-                       } else if ( $reqType !== 'page' && $reqType !== 'transform' ) {
+                       } elseif ( $reqType !== 'page' && $reqType !== 'transform' ) {
                                throw new Exception( "Request type must be either 'page' or 'transform'" );
                        }
 
diff --git a/tests/phpunit/includes/GlobalFunctions/wfEscapeShellArgTest.php b/tests/phpunit/includes/GlobalFunctions/wfEscapeShellArgTest.php
new file mode 100644 (file)
index 0000000..cb334d2
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * @group GlobalFunctions
+ * @covers ::wfEscapeShellArg
+ */
+class wfEscapeShellArgTest extends MediaWikiTestCase {
+       public function testSingleInput() {
+               if ( wfIsWindows() ) {
+                       $expected = '"blah"';
+               } else {
+                       $expected = "'blah'";
+               }
+
+               $actual = wfEscapeShellArg( 'blah' );
+
+               $this->assertEquals( $expected, $actual );
+       }
+
+       public function testMultipleArgs() {
+               if ( wfIsWindows() ) {
+                       $expected = '"foo" "bar" "baz"';
+               } else {
+                       $expected = "'foo' 'bar' 'baz'";
+               }
+
+               $actual = wfEscapeShellArg( 'foo', 'bar', 'baz' );
+
+               $this->assertEquals( $expected, $actual );
+       }
+
+       public function testMultipleArgsAsArray() {
+               if ( wfIsWindows() ) {
+                       $expected = '"foo" "bar" "baz"';
+               } else {
+                       $expected = "'foo' 'bar' 'baz'";
+               }
+
+               $actual = wfEscapeShellArg( array( 'foo', 'bar', 'baz' ) );
+
+               $this->assertEquals( $expected, $actual );
+       }
+}