[RL] Comment mod and other minor changes
authorKrinkle <krinkle@users.mediawiki.org>
Mon, 13 Feb 2012 15:17:15 +0000 (15:17 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Mon, 13 Feb 2012 15:17:15 +0000 (15:17 +0000)
_ 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
resources/mediawiki/mediawiki.js

index d9ec7eb..578c709 100644 (file)
@@ -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 ) );
        }
 
index cd7ada1..6b53515 100644 (file)
@@ -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 );