Index: trunk/phase3/resources/Resources.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | 'site' => new ResourceLoaderSiteModule, |
9 | 9 | 'startup' => new ResourceLoaderStartUpModule, |
10 | 10 | 'user' => new ResourceLoaderUserModule, |
11 | | - 'user.preferences' => new ResourceLoaderUserPreferencesModule, |
| 11 | + 'user.options' => new ResourceLoaderUserOptionsModule, |
12 | 12 | |
13 | 13 | /* Skins */ |
14 | 14 | |
Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -44,10 +44,79 @@ |
45 | 45 | // This will not change until we are 100% ready to turn off legacy globals |
46 | 46 | var LEGACY_GLOBALS = true; |
47 | 47 | |
48 | | - /* Members */ |
| 48 | + /* Private Members */ |
49 | 49 | |
50 | | - this.legacy = LEGACY_GLOBALS ? window : {}; |
| 50 | + var that = this; |
51 | 51 | |
| 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 | + |
52 | 121 | /* Methods */ |
53 | 122 | |
54 | 123 | /* |
— | — | @@ -55,67 +124,19 @@ |
56 | 125 | */ |
57 | 126 | this.log = function() { }; |
58 | 127 | /* |
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 |
60 | 131 | */ |
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() { |
62 | 137 | |
63 | | - /* Private Members */ |
| 138 | + /* Public Members */ |
64 | 139 | |
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(); |
120 | 141 | } )(); |
121 | 142 | /* |
122 | 143 | * Localization system |