r70219 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70218‎ | r70219 | r70220 >
Date:17:09, 31 July 2010
Author:tparscal
Status:ok
Tags:
Comment:
Added theme and locale support. Added parameter passing through mw.config. Reduced simple register statements to a single call.
Modified paths:
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -29,6 +29,15 @@
3030 * 'script' => 'resources/foo/foo.js',
3131 * // Optionally you can have a style file as well
3232 * '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+ * ),
3342 * // Only needed if you are doing something fancy with your loader, otherwise one will be generated for you
3443 * 'loader' => 'resources/foo/loader.js',
3544 * // If you need any localized messages brought into the JavaScript environment, list the keys here
@@ -100,8 +109,10 @@
101110 * array(
102111 * 'script' => [string: path to file],
103112 * '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],
104116 * 'loader' => [string: path to file, optional],
105 - * 'messages' => [array: message keys, optional],
106117 * 'raw' => [boolean: include directly without any loading support, optional],
107118 * 'debug' => [boolean: include in debug mode only, optional],
108119 * )
@@ -129,6 +140,8 @@
130141 $options = array_merge( array(
131142 'script' => null,
132143 'style' => null,
 144+ 'themes' => array(),
 145+ 'locales' => array(),
133146 'messages' => array(),
134147 'loader' => null,
135148 'raw' => false,
@@ -204,33 +217,35 @@
205218 echo "\n";
206219 }
207220 }
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";
210233 // Collect all loaders
211234 $loaders = array();
 235+ $registers = array();
212236 foreach ( self::$modules as $name => $options ) {
213237 if ( $options['loader'] !== null ) {
214238 $loaders[] = $options['loader'];
 239+ } else {
 240+ $registers[] = $name;
215241 }
216242 }
217 - // Include each loader once
 243+ // Include loaders
218244 foreach ( array_unique( $loaders ) as $loader ) {
219245 readfile( $loader );
220246 echo "\n";
221247 }
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";
235250 }
236251 // Output non-raw modules
237252 $blobs = MessageBlobStore::get( $modules, $parameters['lang'] );
@@ -238,11 +253,22 @@
239254 if ( !self::$modules[$module]['raw'] ) {
240255 // Script
241256 $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
242262 if ( !$parameters['debug'] ) {
243263 $script = self::filter( 'strip-debug', $script );
244264 }
245265 // Style
246266 $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+ }
247273 if ( $style !== '' ) {
248274 if ( $parameters['dir'] == 'rtl' ) {
249275 $style = self::filter( 'flip-css', $style );

Status & tagging log