r99119 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99118‎ | r99119 | r99120 >
Date:17:02, 6 October 2011
Author:krinkle
Status:ok
Tags:
Comment:
[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 (modified) (history)
  • /branches/RL2/extensions/Gadgets/SpecialGadgets.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/modules/ext.gadgets.api.js (modified) (history)
  • /branches/RL2/extensions/Gadgets/modules/ext.gadgets.gadgetmanager.js (modified) (history)
  • /branches/RL2/extensions/Gadgets/modules/ext.gadgets.init.js (added) (history)
  • /branches/RL2/extensions/Gadgets/modules/ext.gadgets.prejs.css (deleted) (history)
  • /branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.prejs.css (added) (history)
  • /branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.tabs.js (added) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/Gadgets.php
@@ -144,16 +144,39 @@
145145 'remoteExtPath' => 'Gadgets/modules'
146146 );
147147 $wgResourceModules += array(
148 - // Also loaded in if javascript disabled
149 - 'ext.gadgets.prejs' => $gadResourceTemplate + array(
150 - 'styles' => 'ext.gadgets.prejs.css',
 148+ // Styling for elements outputted by PHP
 149+ 'ext.gadgets.specialgadgets.prejs' => $gadResourceTemplate + array(
 150+ 'styles' => 'ext.gadgets.specialgadgets.prejs.css',
151151 'position' => 'top',
152152 ),
 153+ // Initializes mw.gadgets object
 154+ 'ext.gadgets.init' => $gadResourceTemplate + array(
 155+ 'scripts' => 'ext.gadgets.init.js',
 156+ 'position' => 'top',
 157+ ),
 158+ // Adds tabs to Special:Gadgets
 159+ 'ext.gadgets.specialgadgets.tabs' => $gadResourceTemplate + array(
 160+ 'scripts' => 'ext.gadgets.specialgadgets.tabs.js',
 161+ 'messages' => array(
 162+ 'gadgets-gadget-create',
 163+ 'gadgets-gadget-create-tooltip',
 164+ ),
 165+ 'dependencies' => array(
 166+ 'ext.gadgets.init',
 167+ 'mediawiki.util',
 168+ ),
 169+ 'position' => 'top',
 170+ ),
153171 // Method to interact with API
154172 'ext.gadgets.api' => $gadResourceTemplate + array(
155173 'scripts' => 'ext.gadgets.api.js',
156174 // Can't depend on user.tokens yet due to a bug in ResourceLoader (bug 30914)
157 - 'dependencies' => array( 'mediawiki.util', 'mediawiki.Title'/*, 'user.tokens'*/ ),
 175+ 'dependencies' => array(
 176+ 'ext.gadgets.init',
 177+ 'mediawiki.Title',
 178+ 'mediawiki.util',
 179+ #'user.tokens',
 180+ ),
158181 ),
159182 // jQuery plugin
160183 'jquery.createPropCloud' => $gadResourceTemplate + array(
@@ -164,6 +187,7 @@
165188 'scripts' => 'ext.gadgets.gadgetmanager.js',
166189 'styles' => 'ext.gadgets.gadgetmanager.css',
167190 'dependencies' => array(
 191+ 'ext.gadgets.init',
168192 'ext.gadgets.api',
169193 'jquery.localize',
170194 'jquery.ui.autocomplete',
@@ -174,8 +198,6 @@
175199 'jquery.spinner',
176200 ),
177201 'messages' => array(
178 - 'gadgets-gadget-create',
179 - 'gadgets-gadget-create-tooltip',
180202 'gadgetmanager-editor-title-editing',
181203 'gadgetmanager-editor-title-creating',
182204 'gadgetmanager-editor-prop-remove',
Index: branches/RL2/extensions/Gadgets/SpecialGadgets.php
@@ -32,7 +32,8 @@
3333 public function execute( $par ) {
3434 $this->par = $par;
3535 $out = $this->getOutput();
36 - $out->addModuleStyles( 'ext.gadgets.prejs' );
 36+ $out->addModuleStyles( 'ext.gadgets.specialgadgets.prejs' );
 37+ $out->addModules( 'ext.gadgets.specialgadgets.tabs' );
3738
3839 // Map title parts to query string
3940 if ( is_string( $par ) ) {
Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.prejs.css
@@ -1,65 +0,0 @@
2 -/* Gadget list */
3 -.mw-gadgets-list {
4 - width: 100%;
5 - border-bottom: 1px solid #ccc;
6 -}
7 -
8 -.mw-gadgets-gadget {
9 - overflow: hidden;
10 - position: relative;
11 - padding: 0.5em;
12 - border: 1px solid #ccc;
13 - border-bottom: 0;
14 -}
15 -
16 -.mw-gadgets-gadget:hover {
17 - background: #f9f9ff;
18 -}
19 -
20 -.mw-gadgets-title {
21 - font-weight: bold;
22 - min-height: 1.6em;
23 -}
24 -
25 -/* Tool links */
26 -
27 -.mw-gadgets-messagelink {
28 - font-size: 75%;
29 - font-weight: normal;
30 -}
31 -
32 -.mw-gadgets-messagelink a {
33 - padding-left: 18px;
34 - /* @embed */
35 - background-image: url(images/edit-faded.png);
36 - background-position: left top;
37 - background-repeat: no-repeat;
38 -}
39 -
40 -.mw-gadgets-messagelink a:hover {
41 - /* @embed */
42 - background-image: url(images/edit.png);
43 -}
44 -
45 -.mw-gadgets-gadgetlinks {
46 - position: absolute;
47 - top: 0;
48 - right: 0;
49 - height: 1.6em;
50 - padding: 9px;
51 - font-size: 75%;
52 - font-weight: normal;
53 -}
54 -
55 -.mw-gadgets-gadgetlinks {
56 - float: right;
57 -}
58 -
59 -.mw-gadgets-gadgetlinks a {
60 - margin: 0 9px;
61 -}
62 -
63 -/* Export */
64 -.mw-gadgets-exportform fieldset {
65 - max-width: 50%;
66 -}
Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.api.js
@@ -117,13 +117,7 @@
118118
119119 /* Public functions */
120120
121 - mw.gadgets = {
122 - /**
123 - * @todo: Add something derived from $wgGadgetRepositories to gadgetsConf
124 - * ... + repos: { local: { apiScript: .. }, awesomeRepo: { .. }, .. }
125 - */
126 - conf: mw.config.get( 'gadgetsConf' ),
127 - api: {
 121+ mw.gadgets.api = {
128122 /**
129123 * Get the gadget blobs for all gadgets from all repositories.
130124 *
@@ -385,6 +379,5 @@
386380 gadgetCategoryCache = {};
387381 return true;
388382 }
389 - }
390383 };
391384 })( jQuery );
Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.prejs.css
@@ -0,0 +1,65 @@
 2+/* Gadget list */
 3+.mw-gadgets-list {
 4+ width: 100%;
 5+ border-bottom: 1px solid #ccc;
 6+}
 7+
 8+.mw-gadgets-gadget {
 9+ overflow: hidden;
 10+ position: relative;
 11+ padding: 0.5em;
 12+ border: 1px solid #ccc;
 13+ border-bottom: 0;
 14+}
 15+
 16+.mw-gadgets-gadget:hover {
 17+ background: #f9f9ff;
 18+}
 19+
 20+.mw-gadgets-title {
 21+ font-weight: bold;
 22+ min-height: 1.6em;
 23+}
 24+
 25+/* Tool links */
 26+
 27+.mw-gadgets-messagelink {
 28+ font-size: 75%;
 29+ font-weight: normal;
 30+}
 31+
 32+.mw-gadgets-messagelink a {
 33+ padding-left: 18px;
 34+ /* @embed */
 35+ background-image: url(images/edit-faded.png);
 36+ background-position: left top;
 37+ background-repeat: no-repeat;
 38+}
 39+
 40+.mw-gadgets-messagelink a:hover {
 41+ /* @embed */
 42+ background-image: url(images/edit.png);
 43+}
 44+
 45+.mw-gadgets-gadgetlinks {
 46+ position: absolute;
 47+ top: 0;
 48+ right: 0;
 49+ height: 1.6em;
 50+ padding: 9px;
 51+ font-size: 75%;
 52+ font-weight: normal;
 53+}
 54+
 55+.mw-gadgets-gadgetlinks {
 56+ float: right;
 57+}
 58+
 59+.mw-gadgets-gadgetlinks a {
 60+ margin: 0 9px;
 61+}
 62+
 63+/* Export */
 64+.mw-gadgets-exportform fieldset {
 65+ max-width: 50%;
 66+}
Property changes on: branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.prejs.css
___________________________________________________________________
Added: svn:eol-style
167 + native
Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.init.js
@@ -0,0 +1,14 @@
 2+/**
 3+ * Initialize the mw.gadgets object
 4+ */
 5+(function() {
 6+
 7+ mw.gadgets = {
 8+ /**
 9+ * @todo: Add something derived from $wgGadgetRepositories to gadgetsConf
 10+ * ... + repos: { local: { apiScript: .. }, awesomeRepo: { .. }, .. }
 11+ */
 12+ conf: mw.config.get( 'gadgetsConf' )
 13+ };
 14+
 15+})();
Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.gadgetmanager.js
@@ -194,23 +194,6 @@
195195 e.stopPropagation();
196196 });
197197
198 - if ( ga.conf.userIsAllowed['gadgets-definition-create'] ) {
199 - var createTab = mw.util.addPortletLink(
200 - // Not all skins use the new separated tabs yet,
201 - // Fall back to the general 'p-cactions'.
202 - $( '#p-views' ).length ? 'p-views' : 'p-cactions',
203 - '#',
204 - mw.msg( 'gadgets-gadget-create' ),
205 - 'ca-create', // Use whatever core has for pages ? Or use gadget-create ?
206 - mw.msg( 'gadgets-gadget-create-tooltip' ),
207 - 'e' // Same as core for ca-edit
208 - );
209 - $( createTab ).click( function( e ) {
210 - e.preventDefault();
211 - ga.ui.startGadgetManager( 'create' );
212 - } );
213 - }
214 -
215198 },
216199
217200 /**
Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.specialgadgets.tabs.js
@@ -0,0 +1,28 @@
 2+/**
 3+ * JavaScript for Special:Gadgets
 4+ *
 5+ * @author Timo Tijhof
 6+ */
 7+
 8+jQuery( document ).ready( function( $ ) {
 9+
 10+ var ga = mw.gadgets;
 11+
 12+ if ( ga.conf.userIsAllowed['gadgets-definition-create'] ) {
 13+ var createTab = mw.util.addPortletLink(
 14+ // Not all skins use the new separated tabs yet,
 15+ // Fall back to the general 'p-cactions'.
 16+ $( '#p-views' ).length ? 'p-views' : 'p-cactions',
 17+ '#',
 18+ mw.msg( 'gadgets-gadget-create' ),
 19+ 'ca-create', // Use whatever core has for pages ? Or use gadget-create ?
 20+ mw.msg( 'gadgets-gadget-create-tooltip' ),
 21+ 'e' // Same as core for ca-edit
 22+ );
 23+ $( createTab ).click( function( e ) {
 24+ e.preventDefault();
 25+ ga.ui.startGadgetManager( 'create' );
 26+ } );
 27+ }
 28+
 29+});

Status & tagging log