From 5bf04171dc34521f7ee7e33ba17a90c7a772ab31 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Mon, 13 Feb 2012 15:17:15 +0000 Subject: [PATCH] [RL] Comment mod and other minor changes _ Add comment about why it casts to (object) - Modify function comment - Whitespace (start the function body on a new line in debug mode. In production mode this is trimmed away afterwards) - Remove the jQuery->$ passage from loader. There is already a global alias for $ by jQuery, and aside from that every module has it's own (function(){}) wrapper that aliases it from jQuery (not from $), so there is no performance gain either by having it locally here since it doesn't use that. --- includes/resourceloader/ResourceLoader.php | 12 +++++++++--- resources/mediawiki/mediawiki.js | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index d9ec7eba48..578c7093bf 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -354,6 +354,7 @@ class ResourceLoader { * @return Array */ public function getTestModuleNames( $framework = 'all' ) { + /// @TODO: api siteinfo prop testmodulenames modulenames if ( $framework == 'all' ) { return $this->testModuleNames; } elseif ( isset( $this->testModuleNames[$framework] ) && is_array( $this->testModuleNames[$framework] ) ) { @@ -797,7 +798,7 @@ class ResourceLoader { * * @param $name string Module name * @param $scripts Mixed: List of URLs to JavaScript files or String of JavaScript code - * @param $styles Mixed: List of CSS strings keyed by media type, or list of lists of URLs to + * @param $styles Mixed: Array of CSS strings keyed by media type, or an array of lists of URLs to * CSS files keyed by media type * @param $messages Mixed: List of messages associated with this module. May either be an * associative array mapping message key to value, or a JSON-encoded message blob containing @@ -807,7 +808,7 @@ class ResourceLoader { */ public static function makeLoaderImplementScript( $name, $scripts, $styles, $messages ) { if ( is_string( $scripts ) ) { - $scripts = new XmlJsCode( "function( $ ) {{$scripts}}" ); + $scripts = new XmlJsCode( "function () {\n{$scripts}\n}" ); } elseif ( !is_array( $scripts ) ) { throw new MWException( 'Invalid scripts error. Array of URLs or string of code expected.' ); } @@ -816,6 +817,11 @@ class ResourceLoader { array( $name, $scripts, + // Force objects. mw.loader.implement requires them to be javascript objects. + // Although these variables are associative arrays, which become javascript + // objects through json_encode. In many cases they will be empty arrays, and + // PHP/json_encode() consider empty arrays to be numerical arrays and + // output javascript "[]" instead of "{}". This fixes that. (object)$styles, (object)$messages ) ); @@ -901,7 +907,7 @@ class ResourceLoader { public static function makeCustomLoaderScript( $name, $version, $dependencies, $group, $source, $script ) { $script = str_replace( "\n", "\n\t", trim( $script ) ); return Xml::encodeJsCall( - "( function( name, version, dependencies, group, source ) {\n\t$script\n} )", + "( function ( name, version, dependencies, group, source ) {\n\t$script\n} )", array( $name, $version, $dependencies, $group, $source ) ); } diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index cd7ada1243..6b535157d1 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -315,7 +315,7 @@ var mw = ( function ( $, undefined ) { /** * Client-side module loader which integrates with the MediaWiki ResourceLoader */ - loader: ( function() { + loader: ( function () { /* Private Members */ @@ -756,7 +756,7 @@ var mw = ( function ( $, undefined ) { registry[module].state = 'loading'; nestedAddScript( script, markModuleReady, registry[module].blocking, 0 ); } else if ( $.isFunction( script ) ) { - script( $ ); + script(); markModuleReady(); } } catch ( e ) { @@ -1418,7 +1418,7 @@ var mw = ( function ( $, undefined ) { return s; } }; - })() + }() ) }; })( jQuery ); -- 2.20.1