r97108 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97107‎ | r97108 | r97109 >
Date:22:34, 14 September 2011
Author:catrope
Status:deferred (Comments)
Tags:
Comment:
RL2: Commit some initial code for the foreign gadgets preferences tab. Still needs work. Thinking I might want to do s/shared gadgets/foreign gadgets/g here.
Modified paths:
  • /branches/RL2/extensions/Gadgets/GadgetHooks.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/Gadgets.i18n.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/Gadgets.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/modules/ext.gadgets.preferences.js (added) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/Gadgets.i18n.php
@@ -19,6 +19,7 @@
2020
2121 # For Special:Preferences
2222 'prefs-gadgets' => 'Gadgets',
 23+ 'prefs-gadgets-shared' => 'Shared gadgets',
2324 'gadgets-prefstext' => 'Below is a list of gadgets you can enable for your account.
2425 These gadgets are mostly based on JavaScript, so JavaScript has to be enabled in your browser for them to work.
2526 Note that these gadgets will have no effect on this preferences page.
@@ -26,6 +27,7 @@
2728 Also note that these gadgets are not part of the MediaWiki software, and are usually developed and maintained by users of the wiki.
2829 Administrators manage to the [[Special:GadgetManager|gadget definitions]] and the [[Special:Gadgets|titles and descriptions]] of available gadgets.',
2930 'gadgets-preference-description' => '$1: $2',
 31+ 'gadgets-sharedprefstext' => 'Below is a list of gadgets from other wikis. TODO: This needs more text',
3032
3133 # For Special:Gadgets (overview for users; titles, messages, description, exporting etc.)
3234 'gadgets' => 'Gadgets',
Index: branches/RL2/extensions/Gadgets/Gadgets.php
@@ -187,4 +187,7 @@
188188 'gadgetmanager-comment-modify',
189189 ),
190190 ),
 191+ 'ext.gadgets.preferences' => $gadResourceTemplate + array(
 192+ 'scripts' => 'ext.gadgets.preferences.js',
 193+ ),
191194 );
Index: branches/RL2/extensions/Gadgets/GadgetHooks.php
@@ -251,6 +251,28 @@
252252 'prefix' => 'gadget-',
253253 'default' => $default,
254254 );
 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+ );
255277 return true;
256278 }
257279
@@ -281,6 +303,11 @@
282304 }
283305 }
284306
 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+
285312 wfProfileOut( __METHOD__ );
286313 return true;
287314 }
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( '&nbsp;' ).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
163 + native

Comments

#Comment by Siebrand (talk | contribs)   22:36, 14 September 2011

When adding UI messages, please also add documentation in the qqq/Message documentation language. It's a great help for translators. You do it once, and 100 translators do not have to assume what the context may be. TIA.

Status & tagging log