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

Revision: 99119
Author:   krinkle
Date:     2011-10-06 17:02:32 +0000 (Thu, 06 Oct 2011)
Log Message:
-----------
[RL2] Optimize module organization
* Moving tab-addition into separate module. This tab should only be added on 
Special:Gadgets (or wherever the tabs module is loaded), not per se wherever 
ext.gadgets.gadgetmanager is loaded. Until now it was fine in the 
ext.gadgets.gadgetmanager module since the Create-tab is only useful to people 
that are gadget managers, for which this module is obviously loaded. However 
soon I'll add more JS-tabs, some of which are even useful to anonymous users, 
so this clearly needs to be in a separate module. And the tab isn't part of the 
'manager'.
* A nice gain: The tab is now created before the page becomes visible, because 
I gave this tabs-module position top (the manager is and should not be position 
top)
* The ext.gadgets.specialgadgets.tabs module needs mw.gadgets to exist, moving 
the creation of that object and the 'conf' key out of ext.gadgets.api into a 
new module (ext.gadgets.init).
* Rename 'prejs' to 'specialgadgets.prejk'

Modified Paths:
--------------
    branches/RL2/extensions/Gadgets/Gadgets.php
    branches/RL2/extensions/Gadgets/SpecialGadgets.php
    branches/RL2/extensions/Gadgets/modules/ext.gadgets.api.js
    branches/RL2/extensions/Gadgets/modules/ext.gadgets.gadgetmanager.js

Added Paths:
-----------
    branches/RL2/extensions/Gadgets/modules/ext.gadgets.init.js
    branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.prejs.css
    branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.tabs.js

Removed Paths:
-------------
    branches/RL2/extensions/Gadgets/modules/ext.gadgets.prejs.css

Modified: branches/RL2/extensions/Gadgets/Gadgets.php
===================================================================
--- branches/RL2/extensions/Gadgets/Gadgets.php 2011-10-06 17:00:18 UTC (rev 
99118)
+++ branches/RL2/extensions/Gadgets/Gadgets.php 2011-10-06 17:02:32 UTC (rev 
99119)
@@ -144,16 +144,39 @@
        'remoteExtPath' => 'Gadgets/modules'
 );
 $wgResourceModules += array(
-       // Also loaded in if javascript disabled
-       'ext.gadgets.prejs' => $gadResourceTemplate + array(
-               'styles' => 'ext.gadgets.prejs.css',
+       // Styling for elements outputted by PHP
+       'ext.gadgets.specialgadgets.prejs' => $gadResourceTemplate + array(
+               'styles' => 'ext.gadgets.specialgadgets.prejs.css',
                'position' => 'top',
        ),
+       // Initializes mw.gadgets object
+       'ext.gadgets.init' => $gadResourceTemplate + array(
+               'scripts' => 'ext.gadgets.init.js',
+               'position' => 'top',
+       ),
+       // Adds tabs to Special:Gadgets
+       'ext.gadgets.specialgadgets.tabs' => $gadResourceTemplate + array(
+               'scripts' => 'ext.gadgets.specialgadgets.tabs.js',
+               'messages' => array(
+                       'gadgets-gadget-create',
+                       'gadgets-gadget-create-tooltip',
+               ),
+               'dependencies' => array(
+                       'ext.gadgets.init',
+                       'mediawiki.util',
+               ),
+               'position' => 'top',
+       ),
        // Method to interact with API
        'ext.gadgets.api' => $gadResourceTemplate + array(
                'scripts' => 'ext.gadgets.api.js',
                // Can't depend on user.tokens yet due to a bug in 
ResourceLoader (bug 30914)
-               'dependencies' => array( 'mediawiki.util', 'mediawiki.Title'/*, 
'user.tokens'*/ ),
+               'dependencies' => array(
+                       'ext.gadgets.init',
+                       'mediawiki.Title',
+                       'mediawiki.util',
+                       #'user.tokens',
+               ),
        ),
        // jQuery plugin
        'jquery.createPropCloud' => $gadResourceTemplate + array(
@@ -164,6 +187,7 @@
                'scripts' => 'ext.gadgets.gadgetmanager.js',
                'styles' => 'ext.gadgets.gadgetmanager.css',
                'dependencies' => array(
+                       'ext.gadgets.init',
                        'ext.gadgets.api',
                        'jquery.localize',
                        'jquery.ui.autocomplete',
@@ -174,8 +198,6 @@
                        'jquery.spinner',
                ),
                'messages' => array(
-                       'gadgets-gadget-create',
-                       'gadgets-gadget-create-tooltip',
                        'gadgetmanager-editor-title-editing',
                        'gadgetmanager-editor-title-creating',
                        'gadgetmanager-editor-prop-remove',

Modified: branches/RL2/extensions/Gadgets/SpecialGadgets.php
===================================================================
--- branches/RL2/extensions/Gadgets/SpecialGadgets.php  2011-10-06 17:00:18 UTC 
(rev 99118)
+++ branches/RL2/extensions/Gadgets/SpecialGadgets.php  2011-10-06 17:02:32 UTC 
(rev 99119)
@@ -32,7 +32,8 @@
        public function execute( $par ) {
                $this->par = $par;
                $out = $this->getOutput();
-               $out->addModuleStyles( 'ext.gadgets.prejs' );
+               $out->addModuleStyles( 'ext.gadgets.specialgadgets.prejs' );
+               $out->addModules( 'ext.gadgets.specialgadgets.tabs' );
 
                // Map title parts to query string
                if ( is_string( $par ) ) {

Modified: branches/RL2/extensions/Gadgets/modules/ext.gadgets.api.js
===================================================================
--- branches/RL2/extensions/Gadgets/modules/ext.gadgets.api.js  2011-10-06 
17:00:18 UTC (rev 99118)
+++ branches/RL2/extensions/Gadgets/modules/ext.gadgets.api.js  2011-10-06 
17:02:32 UTC (rev 99119)
@@ -117,13 +117,7 @@
 
        /* Public functions */
 
-       mw.gadgets = {
-               /**
-                * @todo: Add something derived from $wgGadgetRepositories to 
gadgetsConf
-                * ... + repos: { local: { apiScript: .. }, awesomeRepo: { .. 
}, .. }
-                */
-               conf: mw.config.get( 'gadgetsConf' ),
-               api: {
+       mw.gadgets.api = {
                        /**
                         * Get the gadget blobs for all gadgets from all 
repositories.
                         *
@@ -385,6 +379,5 @@
                                gadgetCategoryCache = {};
                                return true;
                        }
-               }
        };
 })( jQuery );

Modified: branches/RL2/extensions/Gadgets/modules/ext.gadgets.gadgetmanager.js
===================================================================
--- branches/RL2/extensions/Gadgets/modules/ext.gadgets.gadgetmanager.js        
2011-10-06 17:00:18 UTC (rev 99118)
+++ branches/RL2/extensions/Gadgets/modules/ext.gadgets.gadgetmanager.js        
2011-10-06 17:02:32 UTC (rev 99119)
@@ -194,23 +194,6 @@
                                e.stopPropagation();
                        });
 
-                       if ( ga.conf.userIsAllowed['gadgets-definition-create'] 
) {
-                               var createTab = mw.util.addPortletLink(
-                                       // Not all skins use the new separated 
tabs yet,
-                                       // Fall back to the general 
'p-cactions'.
-                                       $( '#p-views' ).length ? 'p-views' : 
'p-cactions',
-                                       '#',
-                                       mw.msg( 'gadgets-gadget-create' ),
-                                       'ca-create', // Use whatever core has 
for pages ? Or use gadget-create ?
-                                       mw.msg( 'gadgets-gadget-create-tooltip' 
),
-                                       'e' // Same as core for ca-edit
-                               );
-                               $( createTab ).click( function( e ) {
-                                       e.preventDefault();
-                                       ga.ui.startGadgetManager( 'create' );
-                               } );
-                       }
-
                },
 
                /**

Added: branches/RL2/extensions/Gadgets/modules/ext.gadgets.init.js
===================================================================
--- branches/RL2/extensions/Gadgets/modules/ext.gadgets.init.js                 
        (rev 0)
+++ branches/RL2/extensions/Gadgets/modules/ext.gadgets.init.js 2011-10-06 
17:02:32 UTC (rev 99119)
@@ -0,0 +1,14 @@
+/**
+ * Initialize the mw.gadgets object
+ */
+(function() {
+
+       mw.gadgets = {
+               /**
+                * @todo: Add something derived from $wgGadgetRepositories to 
gadgetsConf
+                * ... + repos: { local: { apiScript: .. }, awesomeRepo: { .. 
}, .. }
+                */
+               conf: mw.config.get( 'gadgetsConf' )
+       };
+
+})();

Deleted: branches/RL2/extensions/Gadgets/modules/ext.gadgets.prejs.css
===================================================================
--- branches/RL2/extensions/Gadgets/modules/ext.gadgets.prejs.css       
2011-10-06 17:00:18 UTC (rev 99118)
+++ branches/RL2/extensions/Gadgets/modules/ext.gadgets.prejs.css       
2011-10-06 17:02:32 UTC (rev 99119)
@@ -1,65 +0,0 @@
-/* Gadget list */
-.mw-gadgets-list {
-       width: 100%;
-       border-bottom: 1px solid #ccc;
-}
-
-.mw-gadgets-gadget {
-       overflow: hidden;
-       position: relative;
-       padding: 0.5em;
-       border: 1px solid #ccc;
-       border-bottom: 0;
-}
-
-.mw-gadgets-gadget:hover {
-       background: #f9f9ff;
-}
-
-.mw-gadgets-title {
-       font-weight: bold;
-       min-height: 1.6em;
-}
-
-/* Tool links */
-
-.mw-gadgets-messagelink {
-       font-size: 75%;
-       font-weight: normal;
-}
-
-.mw-gadgets-messagelink a {
-       padding-left: 18px;
-       /* @embed */
-       background-image: url(images/edit-faded.png);
-       background-position: left top;
-       background-repeat: no-repeat;
-}
-
-.mw-gadgets-messagelink a:hover {
-       /* @embed */
-       background-image: url(images/edit.png);
-}
-
-.mw-gadgets-gadgetlinks {
-       position: absolute;
-       top: 0;
-       right: 0;
-       height: 1.6em;
-       padding: 9px;
-       font-size: 75%;
-       font-weight: normal;
-}
-
-.mw-gadgets-gadgetlinks {
-       float: right;
-}
-
-.mw-gadgets-gadgetlinks a {
-       margin: 0 9px;
-}
-
-/* Export */
-.mw-gadgets-exportform fieldset {
-       max-width: 50%;
-}

Copied: 
branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.prejs.css 
(from rev 99071, branches/RL2/extensions/Gadgets/modules/ext.gadgets.prejs.css)
===================================================================
--- 
branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.prejs.css    
                            (rev 0)
+++ 
branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.prejs.css    
    2011-10-06 17:02:32 UTC (rev 99119)
@@ -0,0 +1,65 @@
+/* Gadget list */
+.mw-gadgets-list {
+       width: 100%;
+       border-bottom: 1px solid #ccc;
+}
+
+.mw-gadgets-gadget {
+       overflow: hidden;
+       position: relative;
+       padding: 0.5em;
+       border: 1px solid #ccc;
+       border-bottom: 0;
+}
+
+.mw-gadgets-gadget:hover {
+       background: #f9f9ff;
+}
+
+.mw-gadgets-title {
+       font-weight: bold;
+       min-height: 1.6em;
+}
+
+/* Tool links */
+
+.mw-gadgets-messagelink {
+       font-size: 75%;
+       font-weight: normal;
+}
+
+.mw-gadgets-messagelink a {
+       padding-left: 18px;
+       /* @embed */
+       background-image: url(images/edit-faded.png);
+       background-position: left top;
+       background-repeat: no-repeat;
+}
+
+.mw-gadgets-messagelink a:hover {
+       /* @embed */
+       background-image: url(images/edit.png);
+}
+
+.mw-gadgets-gadgetlinks {
+       position: absolute;
+       top: 0;
+       right: 0;
+       height: 1.6em;
+       padding: 9px;
+       font-size: 75%;
+       font-weight: normal;
+}
+
+.mw-gadgets-gadgetlinks {
+       float: right;
+}
+
+.mw-gadgets-gadgetlinks a {
+       margin: 0 9px;
+}
+
+/* Export */
+.mw-gadgets-exportform fieldset {
+       max-width: 50%;
+}

Added: 
branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.tabs.js
===================================================================
--- branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.tabs.js  
                        (rev 0)
+++ branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.tabs.js  
2011-10-06 17:02:32 UTC (rev 99119)
@@ -0,0 +1,28 @@
+/**
+ * JavaScript for Special:Gadgets
+ *
+ * @author Timo Tijhof
+ */
+
+jQuery( document ).ready( function( $ ) {
+
+       var ga = mw.gadgets;
+
+       if ( ga.conf.userIsAllowed['gadgets-definition-create'] ) {
+               var createTab = mw.util.addPortletLink(
+                       // Not all skins use the new separated tabs yet,
+                       // Fall back to the general 'p-cactions'.
+                       $( '#p-views' ).length ? 'p-views' : 'p-cactions',
+                       '#',
+                       mw.msg( 'gadgets-gadget-create' ),
+                       'ca-create', // Use whatever core has for pages ? Or 
use gadget-create ?
+                       mw.msg( 'gadgets-gadget-create-tooltip' ),
+                       'e' // Same as core for ca-edit
+               );
+               $( createTab ).click( function( e ) {
+                       e.preventDefault();
+                       ga.ui.startGadgetManager( 'create' );
+               } );
+       }
+
+});


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to