Merge "Guard against non-object returns from File::getHander()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 17 Sep 2013 17:22:44 +0000 (17:22 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 17 Sep 2013 17:22:44 +0000 (17:22 +0000)
RELEASE-NOTES-1.22
docs/hooks.txt
includes/Title.php
includes/diff/DifferenceEngine.php
languages/messages/MessagesEn.php
resources/mediawiki/mediawiki.user.js

index 8570646..d0c9d1d 100644 (file)
@@ -212,6 +212,7 @@ production.
 * IPv6 addresses in X-Forwarded-For headers are now normalised before checking
   against allowed proxy lists.
 * Add deferrable update support for callback/closure
+* Add TitleMove hook before page renames
 
 === Bug fixes in 1.22 ===
 * Disable Special:PasswordReset when $wgEnableEmail is false. Previously one
index 02413b3..5d6a6e4 100644 (file)
@@ -2419,6 +2419,11 @@ $result: Boolean; whether MediaWiki currently thinks this is a wikitext page.
   Hooks may change this value to override the return value of
   Title::isWikitextPage()
 
+'TitleMove': Before moving an article (title).
+$old: old title
+$nt: new title
+$user: user who does the move
+
 'TitleMoveComplete': After moving an article (title).
 $old: old title
 $nt: new title
index 3ad76b9..13350cf 100644 (file)
@@ -3620,6 +3620,8 @@ class Title {
                        $createRedirect = true;
                }
 
+               wfRunHooks( 'TitleMove', array( $this, $nt, $wgUser ) );
+
                // If it is a file, move it first.
                // It is done before all other moving stuff is done because it's hard to revert.
                $dbw = wfGetDB( DB_MASTER );
index 3ff5c98..0c9086b 100644 (file)
@@ -185,10 +185,14 @@ class DifferenceEngine extends ContextSource {
                $out = $this->getOutput();
 
                $missing = array();
-               if ( $this->mOldRev === null ) {
+               if ( $this->mOldRev === null ||
+                       ( $this->mOldRev && $this->mOldContent === null )
+               ) {
                        $missing[] = $this->deletedIdMarker( $this->mOldid );
                }
-               if ( $this->mNewRev === null ) {
+               if ( $this->mNewRev === null ||
+                       ( $this->mNewRev && $this->mNewContent === null )
+               ) {
                        $missing[] = $this->deletedIdMarker( $this->mNewid );
                }
 
@@ -1181,26 +1185,29 @@ class DifferenceEngine extends ContextSource {
        function loadText() {
                if ( $this->mTextLoaded == 2 ) {
                        return true;
-               } else {
-                       // Whether it succeeds or fails, we don't want to try again
-                       $this->mTextLoaded = 2;
                }
 
+               // Whether it succeeds or fails, we don't want to try again
+               $this->mTextLoaded = 2;
+
                if ( !$this->loadRevisionData() ) {
                        return false;
                }
+
                if ( $this->mOldRev ) {
                        $this->mOldContent = $this->mOldRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
                        if ( $this->mOldContent === null ) {
                                return false;
                        }
                }
+
                if ( $this->mNewRev ) {
                        $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
                        if ( $this->mNewContent === null ) {
                                return false;
                        }
                }
+
                return true;
        }
 
@@ -1212,13 +1219,16 @@ class DifferenceEngine extends ContextSource {
        function loadNewText() {
                if ( $this->mTextLoaded >= 1 ) {
                        return true;
-               } else {
-                       $this->mTextLoaded = 1;
                }
+
+               $this->mTextLoaded = 1;
+
                if ( !$this->loadRevisionData() ) {
                        return false;
                }
+
                $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
+
                return true;
        }
 }
index 0336e28..5e66259 100644 (file)
@@ -2507,21 +2507,21 @@ You may want to try at a less busy time.',
 'upload_source_file' => '(a file on your computer)',
 
 # Special:ListFiles
-'listfiles-summary'     => 'This special page shows all uploaded files.',
-'listfiles_search_for'  => 'Search for media name:',
-'imgfile'               => 'file',
-'listfiles'             => 'File list',
-'listfiles_thumb'       => 'Thumbnail',
-'listfiles_date'        => 'Date',
-'listfiles_name'        => 'Name',
-'listfiles_user'        => 'User',
-'listfiles_size'        => 'Size',
-'listfiles_description' => 'Description',
-'listfiles_count'       => 'Versions',
-'listfiles-show-all'    => 'Include old versions of images',
-'listfiles-latestversion' => 'Current version',
+'listfiles-summary'           => 'This special page shows all uploaded files.',
+'listfiles_search_for'        => 'Search for media name:',
+'imgfile'                     => 'file',
+'listfiles'                   => 'File list',
+'listfiles_thumb'             => 'Thumbnail',
+'listfiles_date'              => 'Date',
+'listfiles_name'              => 'Name',
+'listfiles_user'              => 'User',
+'listfiles_size'              => 'Size',
+'listfiles_description'       => 'Description',
+'listfiles_count'             => 'Versions',
+'listfiles-show-all'          => 'Include old versions of images',
+'listfiles-latestversion'     => 'Current version',
 'listfiles-latestversion-yes' => 'Yes',
-'listfiles-latestversion-no' => 'No',
+'listfiles-latestversion-no'  => 'No',
 
 # File description page
 'file-anchor-link'                  => 'File',
index 7cf9d8f..3e375fb 100644 (file)
@@ -3,10 +3,15 @@
  * @singleton
  */
 ( function ( mw, $ ) {
-       var callbacks, options, tokens, user;
+       var user,
+               callbacks = {},
+               // Extend the skeleton mw.user from mediawiki.js
+               // This is kind of ugly but we're stuck with this for b/c reasons
+               options = mw.user.options || new mw.Map(),
+               tokens = mw.user.tokens || new mw.Map();
 
        /**
-        * Gets the current user's groups or rights.
+        * Get the current user's groups or rights
         *
         * @private
         * @param {string} info One of 'groups' or 'rights'
                } );
        }
 
-       callbacks = {};
-
-       // Extend the skeleton mw.user from mediawiki.js
-       // This is kind of ugly but we're stuck with this for b/c reasons
-       options = mw.user.options || new mw.Map();
-       tokens = mw.user.tokens || new mw.Map();
-
        mw.user = user = {
                options: options,
                tokens: tokens,
 
                /**
-                * Generates a random user session ID (32 alpha-numeric characters).
+                * Generate a random user session ID (32 alpha-numeric characters)
                 *
                 * This information would potentially be stored in a cookie to identify a user during a
                 * session or series of sessions. Its uniqueness should not be depended on.
@@ -68,9 +66,9 @@
                },
 
                /**
-                * Gets the current user's database id.
+                * Get the current user's database id
                 *
-                * Not to be confused with #id
+                * Not to be confused with #id.
                 *
                 * @return {number} Current user's id, or 0 if user is anonymous
                 */
@@ -79,7 +77,7 @@
                },
 
                /**
-                * Gets the current user's name.
+                * Get the current user's name
                 *
                 * @return {string|null} User name string or null if user is anonymous
                 */
@@ -96,7 +94,7 @@
                },
 
                /**
-                * Get date user registered, if available.
+                * Get date user registered, if available
                 *
                 * @return {Date|boolean|null} Date user registered, or false for anonymous users, or
                 *  null when data is not available
                },
 
                /**
-                * Checks if the current user is anonymous.
+                * Whether the current user is anonymous
                 *
                 * @return {boolean}
                 */
                },
 
                /**
-                * Gets a random ID automatically generated and stored in a session cookie.
+                * Get an automatically generated random ID (stored in a session cookie)
                 *
                 * This ID is ephemeral for everyone, staying in their browser only until they close
                 * their browser.
                 */
                sessionId: function () {
                        var sessionId = $.cookie( 'mediaWiki.user.sessionId' );
-                       if ( typeof sessionId === 'undefined' || sessionId === null ) {
+                       if ( sessionId === undefined || sessionId === null ) {
                                sessionId = user.generateRandomSessionId();
-                               $.cookie( 'mediaWiki.user.sessionId', sessionId, { 'expires': null, 'path': '/' } );
+                               $.cookie( 'mediaWiki.user.sessionId', sessionId, { expires: null, path: '/' } );
                        }
                        return sessionId;
                },
 
                /**
-                * Gets the current user's name or the session ID
+                * Get the current user's name or the session ID
                 *
-                * Not to be confused with #getId
+                * Not to be confused with #getId.
                 *
                 * @return {string} User name or random session ID
                 */
                id: function () {
-                       var name = user.getName();
-                       if ( name ) {
-                               return name;
-                       }
-                       return user.sessionId();
+                       return user.getName() || user.sessionId();
                },
 
                /**
-                * Gets the user's bucket, placing them in one at random based on set odds if needed.
+                * Get the user's bucket (place them in one if not done already)
                 *
                 *     mw.user.bucket( 'test', {
-                *         'buckets': { 'ignored': 50, 'control': 25, 'test': 25 },
-                *         'version': 1,
-                *         'expires': 7
+                *         buckets: { ignored: 50, control: 25, test: 25 },
+                *         version: 1,
+                *         expires: 7
                 *     } );
                 *
                 * @param {string} key Name of bucket
                 * @param {Object} options Bucket configuration options
                 * @param {Object} options.buckets List of bucket-name/relative-probability pairs (required,
                 *  must have at least one pair)
-                * @param {number} options.version Version of bucket test, changing this forces rebucketing
-                *  (optional, default: 0)
-                * @param {number} options.expires Length of time (in days) until the user gets rebucketed
-                *  (optional, default: 30)
-                * @return {string} Bucket name - the randomly chosen key of the options.buckets object
+                * @param {number} [options.version=0] Version of bucket test, changing this forces
+                *  rebucketing
+                * @param {number} [options.expires=30] Length of time (in days) until the user gets
+                *  rebucketed
+                * @return {string} Bucket name - the randomly chosen key of the `options.buckets` object
                 */
                bucket: function ( key, options ) {
                        var cookie, parts, version, bucket,
                        cookie = $.cookie( 'mediaWiki.user.bucket:' + key );
 
                        // Bucket information is stored as 2 integers, together as version:bucket like: "1:2"
-                       if ( typeof cookie === 'string' && cookie.length > 2 && cookie.indexOf( ':' ) > 0 ) {
+                       if ( typeof cookie === 'string' && cookie.length > 2 && cookie.indexOf( ':' ) !== -1 ) {
                                parts = cookie.split( ':' );
                                if ( parts.length > 1 && Number( parts[0] ) === options.version ) {
                                        version = Number( parts[0] );
                                        bucket = String( parts[1] );
                                }
                        }
+
                        if ( bucket === undefined ) {
                                if ( !$.isPlainObject( options.buckets ) ) {
-                                       throw 'Invalid buckets error. Object expected for options.buckets.';
+                                       throw new Error( 'Invalid bucket. Object expected for options.buckets.' );
                                }
+
                                version = Number( options.version );
+
                                // Find range
                                range = 0;
                                for ( k in options.buckets ) {
                                        range += options.buckets[k];
                                }
+
                                // Select random value within range
                                rand = Math.random() * range;
+
                                // Determine which bucket the value landed in
                                total = 0;
                                for ( k in options.buckets ) {
                                                break;
                                        }
                                }
+
                                $.cookie(
                                        'mediaWiki.user.bucket:' + key,
                                        version + ':' + bucket,
-                                       { 'path': '/', 'expires': Number( options.expires ) }
+                                       { path: '/', expires: Number( options.expires ) }
                                );
                        }
+
                        return bucket;
                },
 
                /**
-                * Gets the current user's groups.
+                * Get the current user's groups
                 *
                 * @param {Function} callback
                 */
                },
 
                /**
-                * Gets the current user's rights.
+                * Get the current user's rights
                 *
                 * @param {Function} callback
                 */