r73025 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73024‎ | r73025 | r73026 >
Date:21:48, 14 September 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
* 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
Modified paths:
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/Resources.php
@@ -7,7 +7,7 @@
88 'site' => new ResourceLoaderSiteModule,
99 'startup' => new ResourceLoaderStartUpModule,
1010 'user' => new ResourceLoaderUserModule,
11 - 'user.preferences' => new ResourceLoaderUserPreferencesModule,
 11+ 'user.options' => new ResourceLoaderUserOptionsModule,
1212
1313 /* Skins */
1414
Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -44,10 +44,79 @@
4545 // This will not change until we are 100% ready to turn off legacy globals
4646 var LEGACY_GLOBALS = true;
4747
48 - /* Members */
 48+ /* Private Members */
4949
50 - this.legacy = LEGACY_GLOBALS ? window : {};
 50+ var that = this;
5151
 52+ /* Prototypes */
 53+
 54+ this.prototypes = {
 55+ /*
 56+ * An object which allows single and multiple get/set/exists functionality on a list of key / value pairs
 57+ *
 58+ * @param {boolean} global whether to get/set/exists values on the window object or a private object
 59+ */
 60+ 'configuration': function( global ) {
 61+
 62+ /* Private Members */
 63+
 64+ var that = this;
 65+ var values = global === true ? window : {};
 66+
 67+ /* Public Methods */
 68+
 69+ /**
 70+ * Gets one or multiple configuration values using a key and an optional fallback or an array of keys
 71+ */
 72+ this.get = function( keys, fallback ) {
 73+ if ( typeof keys === 'object' ) {
 74+ var result = {};
 75+ for ( var k = 0; k < keys.length; k++ ) {
 76+ if ( typeof values[keys[k]] !== 'undefined' ) {
 77+ result[keys[k]] = values[keys[k]];
 78+ }
 79+ }
 80+ return result;
 81+ } else if ( typeof keys === 'string' ) {
 82+ if ( typeof values[keys] === 'undefined' ) {
 83+ return typeof fallback !== 'undefined' ? fallback : null;
 84+ } else {
 85+ return values[keys];
 86+ }
 87+ } else {
 88+ return values;
 89+ }
 90+ };
 91+ /**
 92+ * Sets one or multiple configuration values using a key and a value or an object of keys and values
 93+ */
 94+ this.set = function( keys, value ) {
 95+ if ( typeof keys === 'object' ) {
 96+ for ( var k in keys ) {
 97+ values[k] = keys[k];
 98+ }
 99+ } else if ( typeof keys === 'string' && typeof value !== 'undefined' ) {
 100+ values[keys] = value;
 101+ }
 102+ };
 103+ /**
 104+ * Checks if one or multiple configuration fields exist
 105+ */
 106+ this.exists = function( keys ) {
 107+ if ( typeof keys === 'object' ) {
 108+ for ( var k = 0; k < keys.length; k++ ) {
 109+ if ( !( keys[k] in values ) ) {
 110+ return false;
 111+ }
 112+ }
 113+ return true;
 114+ } else {
 115+ return keys in values;
 116+ }
 117+ };
 118+ }
 119+ };
 120+
52121 /* Methods */
53122
54123 /*
@@ -55,67 +124,19 @@
56125 */
57126 this.log = function() { };
58127 /*
59 - * An object which allows single and multiple existence, setting and getting on a list of key / value pairs
 128+ * List of configuration values
 129+ *
 130+ * In legacy mode the values this object wraps will be in the global space
60131 */
61 - this.config = new ( function() {
 132+ this.config = new this.prototypes.configuration( LEGACY_GLOBALS );
 133+ /*
 134+ * Information about the current user
 135+ */
 136+ this.user = new ( function() {
62137
63 - /* Private Members */
 138+ /* Public Members */
64139
65 - var that = this;
66 - // List of configuration values - in legacy mode these configurations were ALL in the global space
67 - var values = LEGACY_GLOBALS ? window : {};
68 -
69 - /* Public Methods */
70 -
71 - /**
72 - * Sets one or multiple configuration values using a key and a value or an object of keys and values
73 - */
74 - this.set = function( keys, value ) {
75 - if ( typeof keys === 'object' ) {
76 - for ( var k in keys ) {
77 - values[k] = keys[k];
78 - }
79 - } else if ( typeof keys === 'string' && typeof value !== 'undefined' ) {
80 - values[keys] = value;
81 - }
82 - };
83 - /**
84 - * Gets one or multiple configuration values using a key and an optional fallback or an array of keys
85 - */
86 - this.get = function( keys, fallback ) {
87 - if ( typeof keys === 'object' ) {
88 - var result = {};
89 - for ( var k = 0; k < keys.length; k++ ) {
90 - if ( typeof values[keys[k]] !== 'undefined' ) {
91 - result[keys[k]] = values[keys[k]];
92 - }
93 - }
94 - return result;
95 - } else if ( typeof keys === 'string' ) {
96 - if ( typeof values[keys] === 'undefined' ) {
97 - return typeof fallback !== 'undefined' ? fallback : null;
98 - } else {
99 - return values[keys];
100 - }
101 - } else {
102 - return values;
103 - }
104 - };
105 - /**
106 - * Checks if one or multiple configuration fields exist
107 - */
108 - this.exists = function( keys ) {
109 - if ( typeof keys === 'object' ) {
110 - for ( var k = 0; k < keys.length; k++ ) {
111 - if ( !( keys[k] in values ) ) {
112 - return false;
113 - }
114 - }
115 - return true;
116 - } else {
117 - return keys in values;
118 - }
119 - };
 140+ this.options = new that.prototypes.configuration();
120141 } )();
121142 /*
122143 * Localization system

Comments

#Comment by Catrope (talk | contribs)   13:57, 1 October 2010

This revision contains a large amount of undescribed changes to mediawiki.js, which made those changes harder to review. Please review your diff before committing to prevent committing unintended changes.

#Comment by Trevor Parscal (WMF) (talk | contribs)   17:30, 1 October 2010

Yes, there should have also been a comment that said "refactored mediawiki.js to re-use an instantiated prototype for configuration and user.options objects"

Status & tagging log