Index: branches/RL2/extensions/Gadgets/Gadgets.i18n.php |
— | — | @@ -19,6 +19,7 @@ |
20 | 20 | |
21 | 21 | # For Special:Preferences |
22 | 22 | 'prefs-gadgets' => 'Gadgets', |
| 23 | + 'prefs-gadgets-shared' => 'Shared gadgets', |
23 | 24 | 'gadgets-prefstext' => 'Below is a list of gadgets you can enable for your account. |
24 | 25 | These gadgets are mostly based on JavaScript, so JavaScript has to be enabled in your browser for them to work. |
25 | 26 | Note that these gadgets will have no effect on this preferences page. |
— | — | @@ -26,6 +27,7 @@ |
27 | 28 | Also note that these gadgets are not part of the MediaWiki software, and are usually developed and maintained by users of the wiki. |
28 | 29 | Administrators manage to the [[Special:GadgetManager|gadget definitions]] and the [[Special:Gadgets|titles and descriptions]] of available gadgets.', |
29 | 30 | 'gadgets-preference-description' => '$1: $2', |
| 31 | + 'gadgets-sharedprefstext' => 'Below is a list of gadgets from other wikis. TODO: This needs more text', |
30 | 32 | |
31 | 33 | # For Special:Gadgets (overview for users; titles, messages, description, exporting etc.) |
32 | 34 | 'gadgets' => 'Gadgets', |
Index: branches/RL2/extensions/Gadgets/Gadgets.php |
— | — | @@ -187,4 +187,7 @@ |
188 | 188 | 'gadgetmanager-comment-modify', |
189 | 189 | ), |
190 | 190 | ), |
| 191 | + 'ext.gadgets.preferences' => $gadResourceTemplate + array( |
| 192 | + 'scripts' => 'ext.gadgets.preferences.js', |
| 193 | + ), |
191 | 194 | ); |
Index: branches/RL2/extensions/Gadgets/GadgetHooks.php |
— | — | @@ -251,6 +251,28 @@ |
252 | 252 | 'prefix' => 'gadget-', |
253 | 253 | 'default' => $default, |
254 | 254 | ); |
| 255 | + |
| 256 | + // Add tab for shared gadgets |
| 257 | + $preferences['gadgets-intro-shared'] = |
| 258 | + array( |
| 259 | + 'type' => 'info', |
| 260 | + 'label' => ' ', |
| 261 | + 'default' => Xml::tags( 'tr', array(), |
| 262 | + Xml::tags( 'td', array( 'colspan' => 2 ), |
| 263 | + wfMsgExt( 'gadgets-sharedprefstext', 'parse' ) ) ), |
| 264 | + 'section' => 'gadgets-shared', |
| 265 | + 'raw' => 1, |
| 266 | + 'rawrow' => 1, |
| 267 | + ); |
| 268 | + $preferences['gadgets-shared'] = |
| 269 | + array( |
| 270 | + 'type' => 'multiselect', |
| 271 | + 'options' => array(), // TODO: Maybe fill in stuff anyway? The backend may need that |
| 272 | + 'section' => 'gadgets-shared', |
| 273 | + 'label' => ' ', |
| 274 | + 'prefix' => 'gadget-', |
| 275 | + 'default' => array(), |
| 276 | + ); |
255 | 277 | return true; |
256 | 278 | } |
257 | 279 | |
— | — | @@ -281,6 +303,11 @@ |
282 | 304 | } |
283 | 305 | } |
284 | 306 | |
| 307 | + // Add preferences JS if we're on Special:Preferences |
| 308 | + if ( $out->getTitle()->equals( SpecialPage::getTitleFor( 'Preferences' ) ) ) { |
| 309 | + $out->addModules( 'ext.gadgets.preferences' ); |
| 310 | + } |
| 311 | + |
285 | 312 | wfProfileOut( __METHOD__ ); |
286 | 313 | return true; |
287 | 314 | } |
Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.preferences.js |
— | — | @@ -0,0 +1,61 @@ |
| 2 | +/** |
| 3 | + * JavaScript to populate the shared gadgets tab on the preferences page. |
| 4 | + * |
| 5 | + * @author Roan Kattouw |
| 6 | + * @copyright © 2011 Roan Kattouw |
| 7 | + * @license GNU General Public Licence 2.0 or later |
| 8 | + */ |
| 9 | +( function( $ ) { |
| 10 | + function buildPref( id, text ) { |
| 11 | + var $div = $( '<div class="mw-htmlform-multiselect-item"></div>' ), |
| 12 | + // TODO: checked state should represent preference |
| 13 | + $input = $( '<input>', { |
| 14 | + 'type': 'checkbox', |
| 15 | + 'name': 'wpgadgets-shared[]', |
| 16 | + 'id': 'mw-input-wpgadgets-shared-' + id, |
| 17 | + 'value': id |
| 18 | + } ); |
| 19 | + $label = $( '<label>', { for: 'mw-input-wpgadgets-shared-' + id } ) |
| 20 | + .text( text ); |
| 21 | + return $div.append( $input ).append( ' ' ).append( $label ); |
| 22 | + } |
| 23 | + |
| 24 | + function buildForm( gadgetsByCategory, categoryNames ) { |
| 25 | + var $container = $( '#mw-prefsection-gadgets-shared .mw-input' ), |
| 26 | + // Detach the container from the DOM, so we can fill it without visible build-up. |
| 27 | + // This is faster, too. In order to put it back where it was, we need to store its parent. |
| 28 | + $containerParent = $container.parent(); |
| 29 | + $container.detach(); |
| 30 | + |
| 31 | + for ( var category in gadgetsByCategory ) { |
| 32 | + if ( category !== '' ) { |
| 33 | + $container.append( $( '<h1>' ).text( categoryNames[category] ) ); |
| 34 | + } |
| 35 | + for ( var gadget in gadgetsByCategory[category] ) { |
| 36 | + $container.append( buildPref( gadget, gadgetsByCategory[category][gadget] ) ); |
| 37 | + } |
| 38 | + } |
| 39 | + // Re-attach the container |
| 40 | + $containerParent.append( $container ); |
| 41 | + } |
| 42 | + |
| 43 | + // Temporary testing data |
| 44 | + var categoryNames = { |
| 45 | + 'foo': 'The Foreign Category of Foo' |
| 46 | + }; |
| 47 | + // TODO: This structure allows cross-pollination of categories when multiple foreign repos are involved, do we want that? |
| 48 | + // I guess probably not, because we wouldn't even know where to pull the category message from to begin with. |
| 49 | + // Probably needs an extra level for the repo. |
| 50 | + var gadgetsByCategory = { |
| 51 | + '': { |
| 52 | + 'b': 'Gadget B', |
| 53 | + 'UTCLiveClock': 'UTCLiveClock' |
| 54 | + }, |
| 55 | + 'foo': { |
| 56 | + 'a': 'Gadget A' |
| 57 | + } |
| 58 | + }; |
| 59 | + |
| 60 | + $( function() { buildForm( gadgetsByCategory, categoryNames ) } ); |
| 61 | + |
| 62 | +} )( jQuery ); |
Property changes on: branches/RL2/extensions/Gadgets/modules/ext.gadgets.preferences.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 63 | + native |