Merge "Do not call purgeExpiredRestrictions on simple page views"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 11 Feb 2015 18:48:41 +0000 (18:48 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 11 Feb 2015 18:48:41 +0000 (18:48 +0000)
15 files changed:
autoload.php
includes/DefaultSettings.php
includes/Import.php
includes/User.php
includes/UserRightsProxy.php
includes/media/FormatMetadata.php
includes/media/ImageHandler.php
includes/media/MediaTransformInvalidParametersException.php [new file with mode: 0644]
includes/registration/ExtensionProcessor.php
includes/registration/ExtensionRegistry.php
resources/src/mediawiki.api/mediawiki.api.login.js
resources/src/mediawiki/mediawiki.startUp.js
tests/phpunit/includes/registration/ExtensionProcessorTest.php
tests/phpunit/structure/AvailableRightsTest.php [deleted file]
thumb.php

index 9855e90..d0c313a 100644 (file)
@@ -726,6 +726,7 @@ $wgAutoloadLocalClasses = array(
        'MediaHandler' => __DIR__ . '/includes/media/MediaHandler.php',
        'MediaStatisticsPage' => __DIR__ . '/includes/specials/SpecialMediaStatistics.php',
        'MediaTransformError' => __DIR__ . '/includes/media/MediaTransformOutput.php',
+       'MediaTransformInvalidParametersException' => __DIR__ . '/includes/media/MediaTransformInvalidParametersException.php',
        'MediaTransformOutput' => __DIR__ . '/includes/media/MediaTransformOutput.php',
        'MediaWiki' => __DIR__ . '/includes/MediaWiki.php',
        'MediaWikiI18N' => __DIR__ . '/includes/skins/MediaWikiI18N.php',
index ab87425..3f7604d 100644 (file)
@@ -1320,9 +1320,11 @@ $wgDirectoryMode = 0777;
  * Generate and use thumbnails suitable for screens with 1.5 and 2.0 pixel densities.
  *
  * This means a 320x240 use of an image on the wiki will also generate 480x360 and 640x480
- * thumbnails, output via data-src-1-5 and data-src-2-0. Runtime JavaScript switches the
- * images in after loading the original low-resolution versions depending on the reported
- * window.devicePixelRatio.
+ * thumbnails, output via the srcset attribute.
+ *
+ * On older browsers, a JavaScript polyfill switches the appropriate images in after loading
+ * the original low-resolution versions depending on the reported window.devicePixelRatio.
+ * The polyfill can be found in the jquery.hidpi module.
  */
 $wgResponsiveImages = true;
 
index 36028ea..7eff5da 100644 (file)
@@ -497,36 +497,48 @@ class WikiImporter {
 
                $keepReading = $this->reader->read();
                $skip = false;
-               while ( $keepReading ) {
-                       $tag = $this->reader->name;
-                       $type = $this->reader->nodeType;
-
-                       if ( !Hooks::run( 'ImportHandleToplevelXMLTag', array( $this ) ) ) {
-                               // Do nothing
-                       } elseif ( $tag == 'mediawiki' && $type == XMLReader::END_ELEMENT ) {
-                               break;
-                       } elseif ( $tag == 'siteinfo' ) {
-                               $this->handleSiteInfo();
-                       } elseif ( $tag == 'page' ) {
-                               $this->handlePage();
-                       } elseif ( $tag == 'logitem' ) {
-                               $this->handleLogItem();
-                       } elseif ( $tag != '#text' ) {
-                               $this->warn( "Unhandled top-level XML tag $tag" );
-
-                               $skip = true;
-                       }
+               $rethrow = null;
+               try {
+                       while ( $keepReading ) {
+                               $tag = $this->reader->name;
+                               $type = $this->reader->nodeType;
+
+                               if ( !Hooks::run( 'ImportHandleToplevelXMLTag', array( $this ) ) ) {
+                                       // Do nothing
+                               } elseif ( $tag == 'mediawiki' && $type == XMLReader::END_ELEMENT ) {
+                                       break;
+                               } elseif ( $tag == 'siteinfo' ) {
+                                       $this->handleSiteInfo();
+                               } elseif ( $tag == 'page' ) {
+                                       $this->handlePage();
+                               } elseif ( $tag == 'logitem' ) {
+                                       $this->handleLogItem();
+                               } elseif ( $tag != '#text' ) {
+                                       $this->warn( "Unhandled top-level XML tag $tag" );
+
+                                       $skip = true;
+                               }
 
-                       if ( $skip ) {
-                               $keepReading = $this->reader->next();
-                               $skip = false;
-                               $this->debug( "Skip" );
-                       } else {
-                               $keepReading = $this->reader->read();
+                               if ( $skip ) {
+                                       $keepReading = $this->reader->next();
+                                       $skip = false;
+                                       $this->debug( "Skip" );
+                               } else {
+                                       $keepReading = $this->reader->read();
+                               }
                        }
+               } catch ( Exception $ex ) {
+                       $rethrow = $ex;
                }
 
+               // finally
                libxml_disable_entity_loader( $oldDisable );
+               $this->reader->close();
+
+               if ( $rethrow ) {
+                       throw $rethrow;
+               }
+
                return true;
        }
 
index 961c510..c2db67a 100644 (file)
@@ -4399,7 +4399,7 @@ class User implements IDBAccessObject {
 
        /**
         * Get a list of all available permissions.
-        * @return string[] Array of permission names
+        * @return array Array of permission names
         */
        public static function getAllRights() {
                if ( self::$mAllRights === false ) {
index 53c69d8..3be5847 100644 (file)
@@ -211,6 +211,8 @@ class UserRightsProxy {
        /**
         * Replaces User::addUserGroup()
         * @param string $group
+        *
+        * @return bool
         */
        function addGroup( $group ) {
                $this->db->insert( 'user_groups',
@@ -220,11 +222,15 @@ class UserRightsProxy {
                        ),
                        __METHOD__,
                        array( 'IGNORE' ) );
+
+               return true;
        }
 
        /**
         * Replaces User::removeUserGroup()
         * @param string $group
+        *
+        * @return bool
         */
        function removeGroup( $group ) {
                $this->db->delete( 'user_groups',
@@ -233,6 +239,8 @@ class UserRightsProxy {
                                'ug_group' => $group,
                        ),
                        __METHOD__ );
+
+               return true;
        }
 
        /**
index e8e73af..7246072 100644 (file)
@@ -1679,17 +1679,6 @@ class FormatMetadata extends ContextSource {
                        );
                }
 
-               $common = $file->getCommonMetaArray();
-
-               if ( $common !== false ) {
-                       foreach ( $common as $key => $value ) {
-                               $fileMetadata[$key] = array(
-                                       'value' => $value,
-                                       'source' => 'file-metadata',
-                               );
-                       }
-               }
-
                return $fileMetadata;
        }
 
index 6dd0453..787f21e 100644 (file)
@@ -57,7 +57,7 @@ abstract class ImageHandler extends MediaHandler {
                } elseif ( isset( $params['width'] ) ) {
                        $width = $params['width'];
                } else {
-                       throw new MWException( 'No width specified to ' . __METHOD__ );
+                       throw new MediaTransformInvalidParametersException( 'No width specified to ' . __METHOD__ );
                }
 
                # Removed for ProofreadPage
diff --git a/includes/media/MediaTransformInvalidParametersException.php b/includes/media/MediaTransformInvalidParametersException.php
new file mode 100644 (file)
index 0000000..15a2ca5
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * MediaWiki exception thrown by some methods when the transform parameter array is invalid
+ *
+ * @ingroup Exception
+ */
+class MediaTransformInvalidParametersException extends MWException {}
index bf42aba..a2dcd59 100644 (file)
@@ -197,7 +197,7 @@ class ExtensionProcessor implements Processor {
                                if ( isset( $data['localBasePath'] ) ) {
                                        $data['localBasePath'] = "$dir/{$data['localBasePath']}";
                                }
-                               if ( $defaultPaths && !isset( $data['class'] ) ) {
+                               if ( $defaultPaths ) {
                                        $data += $defaultPaths;
                                }
                                $this->globals['wgResourceModules'][$name] = $data;
index 44855d8..8541e31 100644 (file)
@@ -96,6 +96,9 @@ class ExtensionRegistry {
                        foreach ( $this->queued as $path => $mtime ) {
                                $json = file_get_contents( $path );
                                $info = json_decode( $json, /* $assoc = */ true );
+                               if ( !is_array( $info ) ) {
+                                       throw new Exception( "$path is not a valid JSON file." );
+                               }
                                $autoload = $this->processAutoLoader( dirname( $path ), $info );
                                // Set up the autoloader now so custom processors will work
                                $GLOBALS['wgAutoloadClasses'] += $autoload;
@@ -232,29 +235,4 @@ class ExtensionRegistry {
                        return array();
                }
        }
-
-       /**
-        * @param string $filename absolute path to the JSON file
-        * @param int $mtime modified time of the file
-        * @return array
-        */
-       protected function loadInfoFromFile( $filename, $mtime ) {
-               $key = wfMemcKey( 'registry', md5( $filename ) );
-               $cached = $this->cache->get( $key );
-               if ( isset( $cached['mtime'] ) && $cached['mtime'] === $mtime ) {
-                       return $cached['info'];
-               }
-
-               $contents = file_get_contents( $filename );
-               $json = json_decode( $contents, /* $assoc = */ true );
-               if ( is_array( $json ) ) {
-                       $this->cache->set( $key, array( 'mtime' => $mtime, 'info' => $json ) );
-               } else {
-                       // Don't throw an error here, but don't cache it either.
-                       // @todo log somewhere?
-                       $json = array();
-               }
-
-               return $json;
-       }
 }
index ccbae06..88c8caa 100644 (file)
@@ -14,8 +14,7 @@
                 * @return {jQuery.Promise} See mw.Api#post
                 */
                login: function ( username, password ) {
-                       var params, request,
-                               deferred = $.Deferred(),
+                       var params, apiPromise,
                                api = this;
 
                        params = {
                                lgpassword: password
                        };
 
-                       request = api.post( params );
-                       request.fail( deferred.reject );
-                       request.done( function ( data ) {
-                               params.lgtoken = data.login.token;
-                               api.post( params )
-                                       .fail( deferred.reject )
-                                       .done( function ( data ) {
-                                               var code;
-                                               if ( data.login && data.login.result === 'Success' ) {
-                                                       deferred.resolve( data );
-                                               } else {
-                                                       // Set proper error code whenever possible
-                                                       code = data.error && data.error.code || 'unknown';
-                                                       deferred.reject( code, data );
-                                               }
-                                       } );
-                       } );
-
-                       return deferred.promise( { abort: request.abort } );
+                       apiPromise = api.post( params );
+                       return apiPromise
+                               .then( function ( data ) {
+                                       params.lgtoken = data.login.token;
+                                       return api.post( params )
+                                               .then( function ( data ) {
+                                                       var code;
+                                                       if ( data.login.result !== 'Success' ) {
+                                                               // Set proper error code whenever possible
+                                                               code = data.error && data.error.code || 'unknown';
+                                                               return $.Deferred().reject( code, data );
+                                                       }
+                                                       return data;
+                                               } );
+                               } )
+                               .promise( { abort: apiPromise.abort } );
                }
        } );
 
index 8032aa2..028784c 100644 (file)
@@ -1,6 +1,5 @@
-/**
+/*!
  * Auto-register from pre-loaded startup scripts
- * @ignore (this line will make JSDuck happy)
  */
 ( function ( $ ) {
        'use strict';
index d2254df..b4c225c 100644 (file)
@@ -249,11 +249,14 @@ class ExtensionProcessorTest extends MediaWikiTestCase {
                                                'test.class' => array(
                                                        'class' => 'FooBarModule',
                                                        'extra' => 'argument',
+                                                       'localBasePath' => $dir,
+                                                       'remoteExtPath' => 'FooBar',
                                                ),
                                                'test.class.with.path' => array(
                                                        'class' => 'FooBarPathModule',
                                                        'extra' => 'argument',
                                                        'localBasePath' => $dir,
+                                                       'remoteExtPath' => 'FooBar',
                                                )
                                        ),
                                ),
diff --git a/tests/phpunit/structure/AvailableRightsTest.php b/tests/phpunit/structure/AvailableRightsTest.php
deleted file mode 100644 (file)
index 9737e82..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-
-/**
- * Try to make sure that extensions register all rights in $wgAvailableRights
- * or via the 'UserGetAllRights' hook.
- *
- * @author Marius Hoch < hoo@online.de >
- */
-class AvailableRightsTest extends PHPUnit_Framework_TestCase {
-
-       /**
-        * Returns all rights that should be in $wgAvailableRights + all rights
-        * registered via the 'UserGetAllRights' hook + all "core" rights.
-        *
-        * @return string[]
-        */
-       private function getAllVisibleRights() {
-               global $wgGroupPermissions, $wgRevokePermissions;
-
-               $rights = User::getAllRights();
-
-               foreach( $wgGroupPermissions as $permissions ) {
-                       $rights = array_merge( $rights, array_keys( $permissions ) );
-               }
-
-               foreach( $wgRevokePermissions as $permissions ) {
-                       $rights = array_merge( $rights, array_keys( $permissions ) );
-               }
-
-               $rights = array_unique( $rights );
-               sort( $rights );
-
-               return $rights;
-       }
-
-       public function testAvailableRights() {
-               $missingRights = array_diff( $this->getAllVisibleRights(), User::getAllRights() );
-
-               $this->assertEquals(
-                       array(),
-                       array_values( $missingRights ), // Re-Index to produce nicer output, keys are meaningless
-                       'Additional user rights need to be added to $wgAvailableRights or via the "UserGetAllRights" hook'
-               );
-       }
-}
index 28f22fd..70cd1e6 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -252,10 +252,12 @@ function wfStreamThumb( array $params ) {
        try {
                $thumbName = $img->thumbName( $params );
                if ( !strlen( $thumbName ) ) { // invalid params?
-                       wfThumbError( 400, 'The specified thumbnail parameters are not valid.' );
-                       return;
+                       throw new MediaTransformInvalidParametersException( 'Empty return from File::thumbName' );
                }
                $thumbName2 = $img->thumbName( $params, File::THUMB_FULL_NAME ); // b/c; "long" style
+       } catch ( MediaTransformInvalidParametersException $e ) {
+               wfThumbError( 400, 'The specified thumbnail parameters are not valid: ' . $e->getMessage() );
+               return;
        } catch ( MWException $e ) {
                wfThumbError( 500, $e->getHTML() );
                return;