r100212 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100211‎ | r100212 | r100213 >
Date:04:37, 19 October 2011
Author:santhosh
Status:ok (Comments)
Tags:
Comment:
New feature - provide all input methods for the user, dynamically load the input method rules.
Bug 28474
Modified paths:
  • /trunk/extensions/Narayam/Narayam.hooks.php (modified) (history)
  • /trunk/extensions/Narayam/Narayam.i18n.php (modified) (history)
  • /trunk/extensions/Narayam/Narayam.php (modified) (history)
  • /trunk/extensions/Narayam/css/ext.narayam.core.css (modified) (history)
  • /trunk/extensions/Narayam/images/closed-ltr.png (added) (history)
  • /trunk/extensions/Narayam/images/closed-rtl.png (added) (history)
  • /trunk/extensions/Narayam/images/open.png (added) (history)
  • /trunk/extensions/Narayam/js/ext.narayam.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Narayam/Narayam.hooks.php
@@ -39,7 +39,7 @@
4040 }
4141
4242 public static function addVariables( &$vars ) {
43 - global $wgUser;
 43+ global $wgUser, $wgNarayamSchemes;
4444
4545 if ( $wgUser->getOption( 'narayamDisable' ) ) {
4646 // User disabled Narayam
@@ -47,7 +47,7 @@
4848 }
4949
5050 $vars['wgNarayamAvailableSchemes'] = self::getSchemes(); // Note: scheme names must be keys, not values
51 -
 51+ $vars['wgNarayamAllSchemes'] = $wgNarayamSchemes;
5252 return true;
5353 }
5454
Index: trunk/extensions/Narayam/images/open.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Narayam/images/open.png
___________________________________________________________________
Added: svn:mime-type
5555 + image/png
Index: trunk/extensions/Narayam/images/closed-ltr.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Narayam/images/closed-ltr.png
___________________________________________________________________
Added: svn:mime-type
5656 + image/png
Index: trunk/extensions/Narayam/images/closed-rtl.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Narayam/images/closed-rtl.png
___________________________________________________________________
Added: svn:mime-type
5757 + image/png
Index: trunk/extensions/Narayam/css/ext.narayam.core.css
@@ -139,3 +139,16 @@
140140 /* @embed */
141141 background: url('../images/narayam-inactive.png') no-repeat scroll left top transparent;
142142 }
 143+
 144+li.narayam-more-imes-link{
 145+ /* @embed */
 146+ background: url('../images/closed-ltr.png') no-repeat scroll left center transparent;
 147+}
 148+
 149+li.narayam-more-imes-link.open{
 150+ /* @embed */
 151+ background: url('../images/open.png') no-repeat scroll left center transparent;
 152+}
 153+li.narayam-more-imes-link a{
 154+ padding-left:10px;
 155+}
Index: trunk/extensions/Narayam/Narayam.i18n.php
@@ -22,6 +22,7 @@
2323 'narayam-help-page' => 'Help:Typing',
2424 'narayam-checkbox-tooltip' => 'To toggle input method on and off', // FIXME: better message
2525 'narayam-disable-preference' => 'Disable Narayam Input Method Editor (IME)',
 26+ 'narayam-more-imes' => 'More input methods',
2627 'narayam-am' => 'Amharic Transliteration',
2728 'narayam-as' => 'Assamese Transliteration',
2829 'narayam-as-avro' => 'Assamese Avro',
Index: trunk/extensions/Narayam/js/ext.narayam.core.js
@@ -30,6 +30,9 @@
3131 // This object is formatted as { 'schemename': '', 'schemename2': '', ... }
3232 // for easy searching
3333 var availableSchemes = mw.config.get( 'wgNarayamAvailableSchemes' ) || {};
 34+ // All input methods. This will be used for selecting input methods from languages
 35+ // other than uselang- optionally
 36+ var allImes = mw.config.get( 'wgNarayamAllSchemes' ) || {};
3437 // Currently selected scheme
3538 var currentScheme = null;
3639 // Shortcut key for turning Narayam on and off
@@ -389,12 +392,9 @@
390393 * @return True if added, false if not
391394 */
392395 this.addScheme = function( name, data ) {
393 - if ( name in availableSchemes ) {
394 - schemes[name] = data;
395 - return true;
396 - } else {
397 - return false;
398 - }
 396+ schemes[name] = data;
 397+ return true;
 398+
399399 };
400400
401401 /**
@@ -402,10 +402,14 @@
403403 * @param name String
404404 */
405405 this.setScheme = function( name ) {
406 - if ( name in schemes ) {
407 - currentScheme = schemes[name];
 406+ currentScheme = schemes[name];
 407+ if ( currentScheme ){
408408 $.cookie( 'narayam-scheme', name, { 'path': '/', 'expires': 30 } );
 409+ return true;
409410 }
 411+ else {
 412+ return false;
 413+ }
410414 };
411415
412416 /**
@@ -500,6 +504,52 @@
501505 .text( mw.msg( 'narayam-toggle-ime', shortcutText() ) )
502506 .prepend( $checkbox )
503507 .attr( 'title', mw.msg( 'narayam-checkbox-tooltip' ) );
 508+
 509+ $narayamMenuItems.append( $( '<li class="narayam-more-imes-link" />')
 510+ .append(
 511+ $( '<a/>' )
 512+ .text( mw.msg( 'narayam-more-imes' ) )
 513+ .click( function() {
 514+ $('.narayam-scheme-dynamic-item').toggle('fast');
 515+ if( $('li.narayam-more-imes-link').hasClass( 'open' )){
 516+ $('li.narayam-more-imes-link').removeClass('open');
 517+ }else{
 518+ $('li.narayam-more-imes-link').addClass('open');
 519+ }
 520+ })
 521+ )
 522+ );
 523+
 524+ for ( var lang in allImes ) {
 525+ var langschemes = allImes[lang];
 526+ for ( var langscheme in langschemes ) {
 527+
 528+ var $input = $( '<input type="radio" name="narayam-input-method" class="narayam-scheme-dynamic" />' );
 529+ $input
 530+ .attr( 'id', 'narayam-' + langscheme )
 531+ .val( langscheme );
 532+
 533+ var $narayamMenuItemLabel = $( '<label />' )
 534+ .attr( 'for' ,'narayam-' + langscheme )
 535+ .append( $input )
 536+ .append( mw.html.escape( mw.msg( "narayam-"+ langscheme ) ) );
 537+
 538+ var $narayamMenuItem = $( '<li class="narayam-scheme-dynamic-item" />' )
 539+ .append( $input )
 540+ .append( $narayamMenuItemLabel );
 541+
 542+ $narayamMenuItems.append( $narayamMenuItem );
 543+
 544+ }
 545+ }
 546+
 547+ // Event listener for scheme selection - dynamic loading of rules.
 548+ $( '.narayam-scheme-dynamic', $( '#narayam-menu-items > ul')[0] ).live( 'click', function() {
 549+ var curVal = $(this).val();
 550+ mw.loader.using( "ext.narayam.rules." + $(this).val() , function() {
 551+ that.setScheme( curVal )
 552+ });
 553+ } );
504554
505555 var helppage = mw.msg( 'narayam-help-page' );
506556 if ( helppage ) {
@@ -546,7 +596,7 @@
547597 $( '#searchform' ).css( 'visibility', 'visible' );
548598 });
549599 }
550 -
 600+ $('.narayam-scheme-dynamic-item').hide();
551601 // Narayam controls setup complete, returns true
552602 return true;
553603 };
Index: trunk/extensions/Narayam/Narayam.php
@@ -147,136 +147,137 @@
148148 'narayam-help',
149149 'narayam-help-page',
150150 'narayam-toggle-ime',
 151+ 'narayam-more-imes',
 152+ 'narayam-am',
 153+ 'narayam-as',
 154+ 'narayam-as-avro',
 155+ 'narayam-as-bornona',
 156+ 'narayam-as-inscript',
 157+ 'narayam-eo',
 158+ 'narayam-hi-inscript',
 159+ 'narayam-kn',
 160+ 'narayam-kn-inscript',
 161+ 'narayam-ml',
 162+ 'narayam-ml-inscript' ,
 163+ 'narayam-ne',
 164+ 'narayam-ne-inscript',
 165+ 'narayam-or',
 166+ 'narayam-or-inscript',
 167+ 'narayam-sa',
 168+ 'narayam-sa-inscript',
 169+ 'narayam-si-singlish',
 170+ 'narayam-si-wijesekara',
 171+ 'narayam-ta99',
 172+ 'narayam-ta',
 173+ 'narayam-ta-bamini',
 174+ 'narayam-te-inscript',
 175+ 'narayam-bn-avro',
 176+ 'narayam-bn-inscript',
 177+ 'narayam-bn-nkb',
151178 ),
152179 'dependencies' => array( 'mediawiki.util', 'jquery.textSelection' ),
153180 );
154181 $wgResourceModules['ext.narayam.rules.am'] = $narayamTpl + array(
155182 'scripts' => 'js/ext.narayam.rules.am.js',
156 - 'messages' => array( 'narayam-am' ),
157183 'dependencies' => 'ext.narayam.core',
158184 );
159185 $wgResourceModules['ext.narayam.rules.as'] = $narayamTpl + array(
160186 'scripts' => 'js/ext.narayam.rules.as.js',
161 - 'messages' => array( 'narayam-as' ),
162187 'dependencies' => 'ext.narayam.core',
163188 );
164189 $wgResourceModules['ext.narayam.rules.as-avro'] = $narayamTpl + array(
165190 'scripts' => 'js/ext.narayam.rules.as-avro.js',
166 - 'messages' => array( 'narayam-as-avro' ),
167191 'dependencies' => 'ext.narayam.core',
168192 );
169193 $wgResourceModules['ext.narayam.rules.as-bornona'] = $narayamTpl + array(
170194 'scripts' => 'js/ext.narayam.rules.as-bornona.js',
171 - 'messages' => array( 'narayam-as-bornona' ),
172195 'dependencies' => 'ext.narayam.core',
173196 );
174197 $wgResourceModules['ext.narayam.rules.as-inscript'] = $narayamTpl + array(
175198 'scripts' => 'js/ext.narayam.rules.as-inscript.js',
176 - 'messages' => array( 'narayam-as-inscript' ),
177199 'dependencies' => 'ext.narayam.core',
178200 );
179201 $wgResourceModules['ext.narayam.rules.bn-avro'] = $narayamTpl + array(
180202 'scripts' => 'js/ext.narayam.rules.bn-avro.js',
181 - 'messages' => array( 'narayam-bn-avro' ),
182203 'dependencies' => 'ext.narayam.core',
183204 );
184205 $wgResourceModules['ext.narayam.rules.bn-inscript'] = $narayamTpl + array(
185206 'scripts' => 'js/ext.narayam.rules.bn-inscript.js',
186 - 'messages' => array( 'narayam-bn-inscript' ),
187207 'dependencies' => 'ext.narayam.core',
188208 );
189209 $wgResourceModules['ext.narayam.rules.bn-nkb'] = $narayamTpl + array(
190210 'scripts' => 'js/ext.narayam.rules.bn-nkb.js',
191 - 'messages' => array( 'narayam-bn-nkb' ),
192211 'dependencies' => 'ext.narayam.core',
193212 );
194213 $wgResourceModules['ext.narayam.rules.eo'] = $narayamTpl + array(
195214 'scripts' => 'js/ext.narayam.rules.eo.js',
196 - 'messages' => array( 'narayam-eo' ),
197215 'dependencies' => 'ext.narayam.core',
198216 );
199217 $wgResourceModules['ext.narayam.rules.hi-inscript'] = $narayamTpl + array(
200218 'scripts' => 'js/ext.narayam.rules.hi-inscript.js',
201 - 'messages' => array( 'narayam-hi-inscript' ),
202219 'dependencies' => 'ext.narayam.core',
203220 );
204221 $wgResourceModules['ext.narayam.rules.kn'] = $narayamTpl + array(
205222 'scripts' => 'js/ext.narayam.rules.kn.js',
206 - 'messages' => array( 'narayam-kn' ),
207223 'dependencies' => 'ext.narayam.core',
208224 );
209225 $wgResourceModules['ext.narayam.rules.kn-inscript'] = $narayamTpl + array(
210226 'scripts' => 'js/ext.narayam.rules.kn-inscript.js',
211 - 'messages' => array( 'narayam-kn-inscript' ),
212227 'dependencies' => 'ext.narayam.core',
213228 );
214229 $wgResourceModules['ext.narayam.rules.ml'] = $narayamTpl + array(
215230 'scripts' => 'js/ext.narayam.rules.ml.js',
216 - 'messages' => array( 'narayam-ml' ),
217231 'dependencies' => 'ext.narayam.core',
218232 );
219233 $wgResourceModules['ext.narayam.rules.ml-inscript'] = $narayamTpl + array(
220234 'scripts' => 'js/ext.narayam.rules.ml-inscript.js',
221 - 'messages' => array( 'narayam-ml-inscript' ),
222235 'dependencies' => 'ext.narayam.core',
223236 );
224237 $wgResourceModules['ext.narayam.rules.ne'] = $narayamTpl + array(
225238 'scripts' => 'js/ext.narayam.rules.ne.js',
226 - 'messages' => array( 'narayam-ne' ),
227239 'dependencies' => 'ext.narayam.core',
228240 );
229241 $wgResourceModules['ext.narayam.rules.ne-inscript'] = $narayamTpl + array(
230242 'scripts' => 'js/ext.narayam.rules.ne-inscript.js',
231 - 'messages' => array( 'narayam-ne-inscript' ),
232243 'dependencies' => 'ext.narayam.core',
233244 );
234245 $wgResourceModules['ext.narayam.rules.or'] = $narayamTpl + array(
235246 'scripts' => 'js/ext.narayam.rules.or.js',
236 - 'messages' => array( 'narayam-or' ),
237247 'dependencies' => 'ext.narayam.core',
238248 );
239249 $wgResourceModules['ext.narayam.rules.or-inscript'] = $narayamTpl + array(
240250 'scripts' => 'js/ext.narayam.rules.or-inscript.js',
241 - 'messages' => array( 'narayam-or-inscript' ),
242251 'dependencies' => 'ext.narayam.core',
243252 );
244253 $wgResourceModules['ext.narayam.rules.sa'] = $narayamTpl + array(
245254 'scripts' => 'js/ext.narayam.rules.sa.js',
246 - 'messages' => array( 'narayam-sa' ),
247255 'dependencies' => 'ext.narayam.core',
248256 );
249257 $wgResourceModules['ext.narayam.rules.sa-inscript'] = $narayamTpl + array(
250258 'scripts' => 'js/ext.narayam.rules.sa-inscript.js',
251 - 'messages' => array( 'narayam-sa-inscript' ),
252259 'dependencies' => 'ext.narayam.core',
253260 );
254261 $wgResourceModules['ext.narayam.rules.si-singlish'] = $narayamTpl + array(
255262 'scripts' => 'js/ext.narayam.rules.si-singlish.js',
256 - 'messages' => array( 'narayam-si-singlish' ),
257263 'dependencies' => 'ext.narayam.core',
258264 );
259265 $wgResourceModules['ext.narayam.rules.si-wijesekara'] = $narayamTpl + array(
260266 'scripts' => 'js/ext.narayam.rules.si-wijesekara.js',
261 - 'messages' => array( 'narayam-si-wijesekara' ),
262267 'dependencies' => 'ext.narayam.core',
263268 );
264269 $wgResourceModules['ext.narayam.rules.ta'] = $narayamTpl + array(
265270 'scripts' => 'js/ext.narayam.rules.ta.js',
266 - 'messages' => array( 'narayam-ta' ),
267271 'dependencies' => 'ext.narayam.core',
268272 );
269273 $wgResourceModules['ext.narayam.rules.ta99'] = $narayamTpl + array(
270274 'scripts' => 'js/ext.narayam.rules.ta99.js',
271 - 'messages' => array( 'narayam-ta99' ),
272275 'dependencies' => 'ext.narayam.rules.ta', // make sure ta99 loads after ta
273276 );
274277 $wgResourceModules['ext.narayam.rules.ta-bamini'] = $narayamTpl + array(
275278 'scripts' => 'js/ext.narayam.rules.ta-bamini.js',
276 - 'messages' => array( 'narayam-ta-bamini' ),
277279 'dependencies' => 'ext.narayam.rules.ta', // make sure ta99 loads after ta
278280 );
279281 $wgResourceModules['ext.narayam.rules.te-inscript'] = $narayamTpl + array(
280282 'scripts' => 'js/ext.narayam.rules.te-inscript.js',
281 - 'messages' => array( 'narayam-te-inscript' ),
282283 'dependencies' => 'ext.narayam.core',
283284 );

Follow-up revisions

RevisionCommit summaryAuthorDate
r102305MFT r99387 r99395 r99456 r99457 r99682 r99683 r100013 r100024 r100108 r100212...nikerabbit18:21, 7 November 2011

Comments

#Comment by Junaidpv (talk | contribs)   06:46, 20 October 2011

Nice work!

Showing big list can be avoided by arranging by language.

#Comment by Santhosh.thottingal (talk | contribs)   06:48, 20 October 2011

We will do it in next step. Even if we group by language, list is growing and it will be big. Need to prototype a new UI and it is planned.

Status & tagging log