From 348fd983cdfa88562024bc9e9544c4ebb45436f1 Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Tue, 14 Sep 2010 21:48:23 +0000 Subject: [PATCH] * Added exporting of user preferences * Renamed user.preferences to user.options * Fixed bug that caused anonomous usernames (such as IP addresses) to be used in user style and script requests * Fixed user options styles not loading for anon users --- resources/Resources.php | 2 +- resources/mediawiki/mediawiki.js | 141 ++++++++++++++++++------------- 2 files changed, 82 insertions(+), 61 deletions(-) diff --git a/resources/Resources.php b/resources/Resources.php index 530bfc1df4..13433e97fd 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -7,7 +7,7 @@ ResourceLoader::register( array( 'site' => new ResourceLoaderSiteModule, 'startup' => new ResourceLoaderStartUpModule, 'user' => new ResourceLoaderUserModule, - 'user.preferences' => new ResourceLoaderUserPreferencesModule, + 'user.options' => new ResourceLoaderUserOptionsModule, /* Skins */ diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 4cebd029cc..40b5bdaddc 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -44,9 +44,78 @@ window.mediaWiki = new ( function( $ ) { // This will not change until we are 100% ready to turn off legacy globals var LEGACY_GLOBALS = true; - /* Members */ + /* Private Members */ - this.legacy = LEGACY_GLOBALS ? window : {}; + var that = this; + + /* Prototypes */ + + this.prototypes = { + /* + * An object which allows single and multiple get/set/exists functionality on a list of key / value pairs + * + * @param {boolean} global whether to get/set/exists values on the window object or a private object + */ + 'configuration': function( global ) { + + /* Private Members */ + + var that = this; + var values = global === true ? window : {}; + + /* Public Methods */ + + /** + * Gets one or multiple configuration values using a key and an optional fallback or an array of keys + */ + this.get = function( keys, fallback ) { + if ( typeof keys === 'object' ) { + var result = {}; + for ( var k = 0; k < keys.length; k++ ) { + if ( typeof values[keys[k]] !== 'undefined' ) { + result[keys[k]] = values[keys[k]]; + } + } + return result; + } else if ( typeof keys === 'string' ) { + if ( typeof values[keys] === 'undefined' ) { + return typeof fallback !== 'undefined' ? fallback : null; + } else { + return values[keys]; + } + } else { + return values; + } + }; + /** + * Sets one or multiple configuration values using a key and a value or an object of keys and values + */ + this.set = function( keys, value ) { + if ( typeof keys === 'object' ) { + for ( var k in keys ) { + values[k] = keys[k]; + } + } else if ( typeof keys === 'string' && typeof value !== 'undefined' ) { + values[keys] = value; + } + }; + /** + * Checks if one or multiple configuration fields exist + */ + this.exists = function( keys ) { + if ( typeof keys === 'object' ) { + for ( var k = 0; k < keys.length; k++ ) { + if ( !( keys[k] in values ) ) { + return false; + } + } + return true; + } else { + return keys in values; + } + }; + } + }; /* Methods */ @@ -55,67 +124,19 @@ window.mediaWiki = new ( function( $ ) { */ this.log = function() { }; /* - * An object which allows single and multiple existence, setting and getting on a list of key / value pairs + * List of configuration values + * + * In legacy mode the values this object wraps will be in the global space */ - this.config = new ( function() { - - /* Private Members */ - - var that = this; - // List of configuration values - in legacy mode these configurations were ALL in the global space - var values = LEGACY_GLOBALS ? window : {}; + this.config = new this.prototypes.configuration( LEGACY_GLOBALS ); + /* + * Information about the current user + */ + this.user = new ( function() { - /* Public Methods */ + /* Public Members */ - /** - * Sets one or multiple configuration values using a key and a value or an object of keys and values - */ - this.set = function( keys, value ) { - if ( typeof keys === 'object' ) { - for ( var k in keys ) { - values[k] = keys[k]; - } - } else if ( typeof keys === 'string' && typeof value !== 'undefined' ) { - values[keys] = value; - } - }; - /** - * Gets one or multiple configuration values using a key and an optional fallback or an array of keys - */ - this.get = function( keys, fallback ) { - if ( typeof keys === 'object' ) { - var result = {}; - for ( var k = 0; k < keys.length; k++ ) { - if ( typeof values[keys[k]] !== 'undefined' ) { - result[keys[k]] = values[keys[k]]; - } - } - return result; - } else if ( typeof keys === 'string' ) { - if ( typeof values[keys] === 'undefined' ) { - return typeof fallback !== 'undefined' ? fallback : null; - } else { - return values[keys]; - } - } else { - return values; - } - }; - /** - * Checks if one or multiple configuration fields exist - */ - this.exists = function( keys ) { - if ( typeof keys === 'object' ) { - for ( var k = 0; k < keys.length; k++ ) { - if ( !( keys[k] in values ) ) { - return false; - } - } - return true; - } else { - return keys in values; - } - }; + this.options = new that.prototypes.configuration(); } )(); /* * Localization system -- 2.20.1