Index: branches/resourceloader/phase3/includes/ResourceLoader.php |
— | — | @@ -29,6 +29,15 @@ |
30 | 30 | * 'script' => 'resources/foo/foo.js', |
31 | 31 | * // Optionally you can have a style file as well |
32 | 32 | * 'style' => 'resources/foo/foo.css', |
| 33 | + * // List of styles to include based on the skin |
| 34 | + * 'themes' => array( |
| 35 | + * 'default' => 'resources/foo/themes/default/foo.css', |
| 36 | + * 'vector' => 'resources/foo/themes/vector.foo.css', |
| 37 | + * ), |
| 38 | + * // List of scripts to include based on the language |
| 39 | + * 'locales' => array( |
| 40 | + * 'en-gb' => 'resources/foo/locales/en-gb.js', |
| 41 | + * ), |
33 | 42 | * // Only needed if you are doing something fancy with your loader, otherwise one will be generated for you |
34 | 43 | * 'loader' => 'resources/foo/loader.js', |
35 | 44 | * // If you need any localized messages brought into the JavaScript environment, list the keys here |
— | — | @@ -100,8 +109,10 @@ |
101 | 110 | * array( |
102 | 111 | * 'script' => [string: path to file], |
103 | 112 | * 'style' => [string: path to file, optional], |
| 113 | + * 'themes' => [array: paths to styles to include, keyed by skin name, optional], |
| 114 | + * 'locales' => [array: paths to scripts to include, keyed by locale name, optional], |
| 115 | + * 'messages' => [array: message keys, optional], |
104 | 116 | * 'loader' => [string: path to file, optional], |
105 | | - * 'messages' => [array: message keys, optional], |
106 | 117 | * 'raw' => [boolean: include directly without any loading support, optional], |
107 | 118 | * 'debug' => [boolean: include in debug mode only, optional], |
108 | 119 | * ) |
— | — | @@ -129,6 +140,8 @@ |
130 | 141 | $options = array_merge( array( |
131 | 142 | 'script' => null, |
132 | 143 | 'style' => null, |
| 144 | + 'themes' => array(), |
| 145 | + 'locales' => array(), |
133 | 146 | 'messages' => array(), |
134 | 147 | 'loader' => null, |
135 | 148 | 'raw' => false, |
— | — | @@ -204,33 +217,35 @@ |
205 | 218 | echo "\n"; |
206 | 219 | } |
207 | 220 | } |
208 | | - // Special meta-information for the 'mw' module |
209 | | - if ( in_array( 'mw', $modules ) ) { |
| 221 | + // Special meta-information for the 'mediawiki' module |
| 222 | + if ( in_array( 'mediawiki', $modules ) ) { |
| 223 | + /* |
| 224 | + * Skin::makeGlobalVariablesScript needs to be modified so that we still output the globals for now, but also |
| 225 | + * put them into the initial payload like this: |
| 226 | + * |
| 227 | + * // Sets the inital configuration |
| 228 | + * mw.config.set( { 'name': 'value', ... } ); |
| 229 | + * |
| 230 | + * Also, the naming of these variables is horrible and sad, hopefully this can be worked on |
| 231 | + */ |
| 232 | + echo "mw.config.set( " . json_encode( $parameters ) . " );\n"; |
210 | 233 | // Collect all loaders |
211 | 234 | $loaders = array(); |
| 235 | + $registers = array(); |
212 | 236 | foreach ( self::$modules as $name => $options ) { |
213 | 237 | if ( $options['loader'] !== null ) { |
214 | 238 | $loaders[] = $options['loader']; |
| 239 | + } else { |
| 240 | + $registers[] = $name; |
215 | 241 | } |
216 | 242 | } |
217 | | - // Include each loader once |
| 243 | + // Include loaders |
218 | 244 | foreach ( array_unique( $loaders ) as $loader ) { |
219 | 245 | readfile( $loader ); |
220 | 246 | echo "\n"; |
221 | 247 | } |
222 | | - // Configure debug mode on server |
223 | | - if ( $parameters['debug'] ) { |
224 | | - echo "mw.debug = true;\n"; |
225 | | - } |
226 | | - /* |
227 | | - * Skin::makeGlobalVariablesScript needs to be modified so that we still output the globals for now, but also |
228 | | - * put them into the initial payload like this: |
229 | | - * |
230 | | - * // Sets the inital configuration |
231 | | - * mw.config.set( { 'name': 'value', ... } ); |
232 | | - * |
233 | | - * Also, the naming of these variables is horrible and sad, hopefully this can be worked on |
234 | | - */ |
| 248 | + // Register modules without loaders |
| 249 | + echo "mw.loader.register( " . json_encode( array_unique( $registers ) ) . " );\n"; |
235 | 250 | } |
236 | 251 | // Output non-raw modules |
237 | 252 | $blobs = MessageBlobStore::get( $modules, $parameters['lang'] ); |
— | — | @@ -238,11 +253,22 @@ |
239 | 254 | if ( !self::$modules[$module]['raw'] ) { |
240 | 255 | // Script |
241 | 256 | $script = file_get_contents( self::$modules[$module]['script'] ); |
| 257 | + // Locale |
| 258 | + if ( isset( self::$modules[$module]['locales'][$parameters['lang']] ) ) { |
| 259 | + $script .= file_get_contents( self::$modules[$module]['locales'][$parameters['lang']] ); |
| 260 | + } |
| 261 | + // Debug stripping - scary and probably a bad idea |
242 | 262 | if ( !$parameters['debug'] ) { |
243 | 263 | $script = self::filter( 'strip-debug', $script ); |
244 | 264 | } |
245 | 265 | // Style |
246 | 266 | $style = self::$modules[$module]['style'] ? file_get_contents( self::$modules[$module]['style'] ) : ''; |
| 267 | + // Theme |
| 268 | + if ( isset( self::$modules[$module]['themes'][$parameters['skin']] ) ) { |
| 269 | + $style .= file_get_contents( self::$modules[$module]['themes'][$parameters['skin']] ); |
| 270 | + } else if ( isset( self::$modules[$module]['themes']['default'] ) ) { |
| 271 | + $style .= file_get_contents( self::$modules[$module]['themes']['default'] ); |
| 272 | + } |
247 | 273 | if ( $style !== '' ) { |
248 | 274 | if ( $parameters['dir'] == 'rtl' ) { |
249 | 275 | $style = self::filter( 'flip-css', $style ); |