http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73412

Revision: 73412
Author:   tparscal
Date:     2010-09-20 21:23:29 +0000 (Mon, 20 Sep 2010)

Log Message:
-----------
Added group functionality to ResourceLoaderModule objects. Also fixed a bug 
that was registering non-ResourceLoaderFileModule objects incorrectly in the 
startup script.

Modified Paths:
--------------
    trunk/phase3/includes/ResourceLoader.php
    trunk/phase3/includes/ResourceLoaderModule.php
    trunk/phase3/resources/mediawiki/mediawiki.js

Modified: trunk/phase3/includes/ResourceLoader.php
===================================================================
--- trunk/phase3/includes/ResourceLoader.php    2010-09-20 20:52:22 UTC (rev 
73411)
+++ trunk/phase3/includes/ResourceLoader.php    2010-09-20 21:23:29 UTC (rev 
73412)
@@ -176,8 +176,7 @@
        }
 
        /**
-        * Gets registration code for all modules, except pre-registered ones 
listed in 
-        * self::$preRegisteredModules
+        * Gets registration code for all modules
         *
         * @param $context ResourceLoaderContext object
         * @return String: JavaScript code for registering all modules with the 
client loader
@@ -193,23 +192,29 @@
                        // Support module loader scripts
                        if ( ( $loader = $module->getLoaderScript() ) !== false 
) {
                                $deps = FormatJson::encode( 
$module->getDependencies() );
-                               $version = wfTimestamp( TS_ISO_8601, 
-                                       round( $module->getModifiedTime( 
$context ), -2 ) );
+                               $group = FormatJson::encode( 
$module->getGroup() );
+                               $version = wfTimestamp( TS_ISO_8601, round( 
$module->getModifiedTime( $context ), -2 ) );
                                $scripts .= "( function( name, version, 
dependencies ) { $loader } )\n" . 
-                                       "( '$name', '$version', $deps );\n";
+                                       "( '$name', '$version', $deps, $group 
);\n";
                        }
                        // Automatically register module
                        else {
-                               // Modules without dependencies pass two 
arguments (name, timestamp) to 
+                               // Modules without dependencies or a group pass 
two arguments (name, timestamp) to 
                                // mediaWiki.loader.register()
-                               if ( !count( $module->getDependencies() ) ) {
+                               if ( !count( $module->getDependencies() && 
$module->getGroup() === null ) ) {
                                        $registrations[] = array( $name, 
$module->getModifiedTime( $context ) );
                                }
-                               // Modules with dependencies pass three 
arguments (name, timestamp, dependencies) 
+                               // Modules with dependencies but no group pass 
three arguments (name, timestamp, dependencies) 
                                // to mediaWiki.loader.register()
+                               else if ( $module->getGroup() === null ) {
+                                       $registrations[] = array(
+                                               $name, 
$module->getModifiedTime( $context ),  $module->getDependencies() );
+                               }
+                               // Modules with dependencies pass four 
arguments (name, timestamp, dependencies, group) 
+                               // to mediaWiki.loader.register()
                                else {
-                                       $registrations[] = array( $name, 
$module->getModifiedTime( $context ), 
-                                               $module->getDependencies() );
+                                       $registrations[] = array(
+                                               $name, 
$module->getModifiedTime( $context ),  $module->getDependencies(), 
$module->getGroup() );
                                }
                        }
                }

Modified: trunk/phase3/includes/ResourceLoaderModule.php
===================================================================
--- trunk/phase3/includes/ResourceLoaderModule.php      2010-09-20 20:52:22 UTC 
(rev 73411)
+++ trunk/phase3/includes/ResourceLoaderModule.php      2010-09-20 21:23:29 UTC 
(rev 73412)
@@ -91,6 +91,16 @@
                // Stub, override expected
                return array();
        }
+       
+       /**
+        * Get the group this module is in.
+        * 
+        * @return string of group name
+        */
+       public function getGroup() {
+               // Stub, override expected
+               return null;
+       }
 
        /**
         * Get the loader JS for this module, if set.
@@ -99,7 +109,7 @@
         */
        public function getLoaderScript() {
                // Stub, override expected
-               return '';
+               return false;
        }
 
        /**
@@ -146,6 +156,7 @@
        protected $scripts = array();
        protected $styles = array();
        protected $messages = array();
+       protected $group;
        protected $dependencies = array();
        protected $debugScripts = array();
        protected $languageScripts = array();
@@ -170,7 +181,7 @@
         *      array(
         *              // Required module options (mutually exclusive)
         *              'scripts' => 'dir/script.js' | array( 'dir/script1.js', 
'dir/script2.js' ... ),
-        *
+        * 
         *              // Optional module options
         *              'languageScripts' => array(
         *                      '[lang name]' => 'dir/lang.js' | '[lang name]' 
=> array( 'dir/lang1.js', 'dir/lang2.js' ... )
@@ -190,6 +201,7 @@
         *                      ...
         *              ),
         *              'messages' => array( 'message1', 'message2' ... ),
+        *              'group' => 'stuff',
         *      )
         */
        public function __construct( $options = array() ) {
@@ -204,6 +216,9 @@
                                case 'messages':
                                        $this->messages = (array)$value;
                                        break;
+                               case 'group':
+                                       $this->group = (string)$value;
+                                       break;
                                case 'dependencies':
                                        $this->dependencies = (array)$value;
                                        break;
@@ -253,8 +268,17 @@
        public function addMessages( $messages ) {
                $this->messages = array_merge( $this->messages, 
(array)$messages );
        }
-
+       
        /**
+        * Sets the group of this module.
+        *
+        * @param $group string group name
+        */
+       public function setGroup( $group ) {
+               $this->group = $group;
+       }
+       
+       /**
         * Add dependencies. Dependency information is taken into account when
         * loading a module on the client side. When adding a module on the
         * server side, dependency information is NOT taken into account and
@@ -403,6 +427,10 @@
                return $this->messages;
        }
 
+       public function getGroup() {
+               return $this->group;
+       }
+
        public function getDependencies() {
                return $this->dependencies;
        }
@@ -798,6 +826,12 @@
                }
                return $pages;
        }
+       
+       /* Methods */
+       
+       public function getGroup() {
+               return 'site';
+       }
 }
 
 /**
@@ -821,6 +855,12 @@
                }
                return array();
        }
+       
+       /* Methods */
+       
+       public function getGroup() {
+               return 'user';
+       }
 }
 
 /**
@@ -848,7 +888,7 @@
                if ( $user ) {
                        return $this->modifiedTime[$hash] = $user->getTouched();
                } else {
-                       return 0;
+                       return 1;
                }
        }
 
@@ -901,6 +941,10 @@
 
                return $wgContLang->getDir() !== $context->getDirection();
        }
+       
+       public function getGroup() {
+               return 'user';
+       }
 }
 
 class ResourceLoaderStartUpModule extends ResourceLoaderModule {
@@ -1034,4 +1078,10 @@
 
                return $wgContLang->getDir() !== $context->getDirection();
        }
+       
+       /* Methods */
+       
+       public function getGroup() {
+               return 'startup';
+       }
 }

Modified: trunk/phase3/resources/mediawiki/mediawiki.js
===================================================================
--- trunk/phase3/resources/mediawiki/mediawiki.js       2010-09-20 20:52:22 UTC 
(rev 73411)
+++ trunk/phase3/resources/mediawiki/mediawiki.js       2010-09-20 21:23:29 UTC 
(rev 73412)
@@ -541,7 +541,7 @@
                 * Registers a module, letting the system know about it and 
it's dependencies. loader.js files contain calls
                 * to this function.
                 */
-               this.register = function( module, version, dependencies, status 
) {
+               this.register = function( module, version, dependencies, group 
) {
                        // Allow multiple registration
                        if ( typeof module === 'object' ) {
                                for ( var m = 0; m < module.length; m++ ) {
@@ -557,12 +557,13 @@
                        if ( typeof module !== 'string' ) {
                                throw new Error( 'module must be a string, not 
a ' + typeof module );
                        }
-                       if ( typeof registry[module] !== 'undefined' && typeof 
status === 'undefined' ) {
+                       if ( typeof registry[module] !== 'undefined' ) {
                                throw new Error( 'module already implemeneted: 
' + module );
                        }
                        // List the module as registered
                        registry[module] = {
-                               'state': typeof status === 'string' ? status : 
'registered',
+                               'state': 'registered',
+                               'group': typeof group === 'string' ? group : 
null,
                                'dependencies': [],
                                'version': typeof version !== 'undefined' ? 
parseInt( version ) : 0
                        };



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to