Merge "Do not raise a PHP warning when session write fails"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 21 Jan 2016 15:12:18 +0000 (15:12 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 21 Jan 2016 15:12:18 +0000 (15:12 +0000)
includes/GlobalFunctions.php
maintenance/updateCollation.php
tests/phpunit/structure/ApiDocumentationTest.php [new file with mode: 0644]

index f797e5b..928066b 100644 (file)
@@ -2162,8 +2162,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.
@@ -2178,13 +2178,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.' );
 }
 
 /**
index bb75314..bd75b3b 100644 (file)
@@ -86,7 +86,7 @@ TEXT;
 
                $options = array(
                        'LIMIT' => self::BATCH_SIZE,
-                       'ORDER BY' => 'cl_to, cl_type, cl_from',
+                       'ORDER BY' => 'cl_from, cl_to',
                        'STRAIGHT_JOIN',
                );
 
@@ -132,7 +132,7 @@ TEXT;
                        $res = $dbw->select(
                                array( 'categorylinks', 'page' ),
                                array( 'cl_from', 'cl_to', 'cl_sortkey_prefix', 'cl_collation',
-                                       'cl_sortkey', 'cl_type', 'page_namespace', 'page_title'
+                                       'cl_sortkey', 'page_namespace', 'page_title'
                                ),
                                array_merge( $collationConds, $batchConds, array( 'cl_from = page_id' ) ),
                                __METHOD__,
@@ -216,13 +216,13 @@ TEXT;
 
        /**
         * Return an SQL expression selecting rows which sort above the given row,
-        * assuming an ordering of cl_to, cl_type, cl_from
+        * assuming an ordering of cl_from, cl_to
         * @param stdClass $row
         * @param DatabaseBase $dbw
         * @return string
         */
        function getBatchCondition( $row, $dbw ) {
-               $fields = array( 'cl_to', 'cl_type', 'cl_from' );
+               $fields = array( 'cl_from', 'cl_to' );
                $first = true;
                $cond = false;
                $prefix = false;
diff --git a/tests/phpunit/structure/ApiDocumentationTest.php b/tests/phpunit/structure/ApiDocumentationTest.php
new file mode 100644 (file)
index 0000000..d2f96dc
--- /dev/null
@@ -0,0 +1,177 @@
+<?php
+
+/**
+ * Checks that all API modules, core and extensions, have documentation i18n messages
+ *
+ * It won't catch everything since i18n messages can vary based on the wiki
+ * configuration, but it should catch many cases for forgotten i18n.
+ *
+ * @group API
+ */
+class ApiDocumentationTest extends MediaWikiTestCase {
+
+       /** @var ApiMain */
+       private static $main;
+
+       /** @var array Sets of globals to test. Each array element is input to HashConfig */
+       private static $testGlobals = array(
+               array(
+                       'MiserMode' => false,
+                       'AllowCategorizedRecentChanges' => false,
+               ),
+               array(
+                       'MiserMode' => true,
+                       'AllowCategorizedRecentChanges' => true,
+               ),
+       );
+
+       /**
+        * Initialize/fetch the ApiMain instance for testing
+        * @return ApiMain
+        */
+       private static function getMain() {
+               if ( !self::$main ) {
+                       self::$main = new ApiMain( RequestContext::getMain() );
+                       self::$main->getContext()->setLanguage( 'en' );
+               }
+               return self::$main;
+       }
+
+       /**
+        * Test a message
+        * @param Message $msg
+        * @param string $what Which message is being checked
+        */
+       private function checkMessage( $msg, $what ) {
+               $msg = ApiBase::makeMessage( $msg, self::getMain()->getContext() );
+               $this->assertInstanceOf( 'Message', $msg, "$what message" );
+               $this->assertTrue( $msg->exists(), "$what message {$msg->getKey()} exists" );
+       }
+
+       /**
+        * @dataProvider provideDocumentationExists
+        * @param string $path Module path
+        * @param array $globals Globals to set
+        */
+       public function testDocumentationExists( $path, array $globals ) {
+               $main = self::getMain();
+
+               // Set configuration variables
+               $main->getContext()->setConfig( new MultiConfig( array(
+                       new HashConfig( $globals ),
+                       RequestContext::getMain()->getConfig(),
+               ) ) );
+               foreach ( $globals as $k => $v ) {
+                       $this->setMWGlobals( "wg$k", $v );
+               }
+
+               // Fetch module.
+               $module = TestingAccessWrapper::newFromObject( $main->getModuleFromPath( $path ) );
+
+               // Test messages for flags.
+               foreach ( $module->getHelpFlags() as $flag ) {
+                       $this->checkMessage( "api-help-flag-$flag", "Flag $flag" );
+               }
+
+               // Module description messages.
+               $this->checkMessage( $module->getDescriptionMessage(), 'Module description' );
+
+               // Parameters. Lots of messages in here.
+               $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
+               $tags = array();
+               foreach ( $params as $name => $settings ) {
+                       if ( !is_array( $settings ) ) {
+                               $settings = array();
+                       }
+
+                       // Basic description message
+                       if ( isset( $settings[ApiBase::PARAM_HELP_MSG] ) ) {
+                               $msg = $settings[ApiBase::PARAM_HELP_MSG];
+                       } else {
+                               $msg = "apihelp-{$path}-param-{$name}";
+                       }
+                       $this->checkMessage( $msg, "Parameter $name description" );
+
+                       // If param-per-value is in use, each value's message
+                       if ( isset( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) {
+                               $this->assertInternalType( 'array', $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE],
+                                       "Parameter $name PARAM_HELP_MSG_PER_VALUE is array" );
+                               $this->assertInternalType( 'array', $settings[ApiBase::PARAM_TYPE],
+                                       "Parameter $name PARAM_TYPE is array for msg-per-value mode" );
+                               $valueMsgs = $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE];
+                               foreach ( $settings[ApiBase::PARAM_TYPE] as $value ) {
+                                       if ( isset( $valueMsgs[$value] ) ) {
+                                               $msg = $valueMsgs[$value];
+                                       } else {
+                                               $msg = "apihelp-{$path}-paramvalue-{$name}-{$value}";
+                                       }
+                                       $this->checkMessage( $msg, "Parameter $name value $value" );
+                               }
+                       }
+
+                       // Appended messages (e.g. "disabled in miser mode")
+                       if ( isset( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) {
+                               $this->assertInternalType( 'array', $settings[ApiBase::PARAM_HELP_MSG_APPEND],
+                                       "Parameter $name PARAM_HELP_MSG_APPEND is array" );
+                               foreach ( $settings[ApiBase::PARAM_HELP_MSG_APPEND] as $i => $msg ) {
+                                       $this->checkMessage( $msg, "Parameter $name HELP_MSG_APPEND #$i" );
+                               }
+                       }
+
+                       // Info tags (e.g. "only usable in mode 1") are typically shared by
+                       // several parameters, so accumulate them and test them later.
+                       if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
+                               foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
+                                       $tags[array_shift( $i )] = 1;
+                               }
+                       }
+               }
+
+               // Info tags (e.g. "only usable in mode 1") accumulated above
+               foreach ( $tags as $tag => $dummy ) {
+                       $this->checkMessage( "apihelp-{$path}-paraminfo-{$tag}", "HELP_MSG_INFO tag $tag" );
+               }
+
+               // Messages for examples.
+               foreach ( $module->getExamplesMessages() as $qs => $msg ) {
+                       $this->checkMessage( $msg, "Example $qs" );
+               }
+       }
+
+       public static function provideDocumentationExists() {
+               $main = self::getMain();
+               $paths = self::getSubModulePaths( $main->getModuleManager() );
+               array_unshift( $paths, $main->getModulePath() );
+
+               $ret = array();
+               foreach ( $paths as $path ) {
+                       foreach ( self::$testGlobals as $globals ) {
+                               $g = array();
+                               foreach ( $globals as $k => $v ) {
+                                       $g[] = "$k=" . var_export( $v, 1 );
+                               }
+                               $k = "Module $path with " . join( ', ', $g );
+                               $ret[$k] = array( $path, $globals );
+                       }
+               }
+               return $ret;
+       }
+
+       /**
+        * Return paths of all submodules in an ApiModuleManager, recursively
+        * @param ApiModuleManager $manager
+        * @return string[]
+        */
+       protected static function getSubModulePaths( ApiModuleManager $manager ) {
+               $paths = array();
+               foreach ( $manager->getNames() as $name ) {
+                       $module = $manager->getModule( $name );
+                       $paths[] = $module->getModulePath();
+                       $subManager = $module->getModuleManager();
+                       if ( $subManager ) {
+                               $paths = array_merge( $paths, self::getSubModulePaths( $subManager ) );
+                       }
+               }
+               return $paths;
+       }
+}