r95849 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95848‎ | r95849 | r95850 >
Date:10:38, 31 August 2011
Author:siebrand
Status:ok
Tags:
Comment:
stylize.php.
Use $dir instead of multiple times dirname( __FILE__ ).
Various whitespace and indentation updates.
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/ext.narayam.core.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.or-inscript.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.si-singlish.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.si-wijesekara.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.ta.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.ta99.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Narayam/ext.narayam.rules.ta99.js
@@ -100,7 +100,7 @@
101101 ['ணo', '','ண்ட'],
102102 ['ஞ\\[', '','ஞ்ச'],
103103 ['மj', '','ம்ப'],
104 -
 104+
105105 ['q', '','ஆ'],
106106 ['w', '','ஈ'],
107107 ['e', '','ஊ'],
Index: trunk/extensions/Narayam/ext.narayam.rules.si-singlish.js
@@ -5,7 +5,7 @@
66 * @credits With help from Nishantha Anuruddha (si.wikipedia.org/wiki/user:බිඟුවා)
77 * License: GPLv3
88 */
9 -
 9+
1010 // Normal rules
1111 var rules = [
1212 ['\\\\([A-Za-z\\>_~\\.0-9])', '\\\\','$1'],
@@ -104,4 +104,4 @@
105105 'lookbackLength': 5,
106106 'keyBufferLength': 2,
107107 'rules': rules
108 -} );
 108+} );
Index: trunk/extensions/Narayam/ext.narayam.rules.si-wijesekara.js
@@ -6,14 +6,14 @@
77 * http://www.ucsc.lk/ltrl/services/layout/
88 * License: GPLv3
99 */
10 -
 10+
1111 var rules = [
1212 ['`', '', '්‍ර'],
1313 ['~', '', 'ර්‍'],
1414
1515 ['q', '', 'ු'],
1616 ['w', '', 'අ'],
17 -['e', '', 'ැ'],
 17+['e', '', 'ැ'],
1818 ['r', '', 'ර'],
1919 ['t', '', 'එ'],
2020 ['y', '', 'හ'],
@@ -95,4 +95,4 @@
9696 'keyBufferLength': 0,
9797 'rules': rules,
9898 'rules_x': rules_x
99 -} );
 99+} );
Index: trunk/extensions/Narayam/ext.narayam.core.js
@@ -16,7 +16,7 @@
1717 ( function( $ ) {
1818 $.narayam = new ( function() {
1919 /* Private members */
20 -
 20+
2121 // Reference to this object
2222 var that = this;
2323 // jQuery array holding all text inputs Narayam applies to
@@ -41,9 +41,9 @@
4242 shiftKey: false,
4343 key: null
4444 };
45 -
 45+
4646 /* Private functions */
47 -
 47+
4848 /**
4949 * Transliterate a string using the current scheme
5050 * @param str String to transliterate
@@ -68,7 +68,7 @@
6969 // No matches, return the input
7070 return str;
7171 }
72 -
 72+
7373 /**
7474 * Get the n characters in str that immediately precede pos
7575 * Example: lastNChars( "foobarbaz", 5, 2 ) == "ba"
@@ -87,7 +87,7 @@
8888 return str.substr( pos - n, n);
8989 }
9090 }
91 -
 91+
9292 /**
9393 * Find the point at which a and b diverge, i.e. the first position
9494 * at which they don't have matching characters.
@@ -104,7 +104,7 @@
105105 }
106106 return -1;
107107 }
108 -
 108+
109109 /**
110110 * Check whether a keypress event corresponds to the shortcut key
111111 * @param e Event object
@@ -116,7 +116,7 @@
117117 e.shiftKey == shortcutKey.shiftKey &&
118118 String.fromCharCode( e.which ).toLowerCase() == shortcutKey.key.toLowerCase();
119119 }
120 -
 120+
121121 /**
122122 * Get a description of the shortcut key, e.g. "Ctrl-M"
123123 * @return string
@@ -136,7 +136,7 @@
137137 text += shortcutKey.key.toUpperCase();
138138 return text;
139139 }
140 -
 140+
141141 /**
142142 * Change visual appearance of element (text input, textarea) according
143143 * current state of Narayam
@@ -150,7 +150,7 @@
151151 $element.removeClass( 'narayam-input' );
152152 }
153153 }
154 -
 154+
155155 /**
156156 * Keydown event handler. Handles shortcut key presses
157157 * @param e Event object
@@ -168,7 +168,7 @@
169169 }
170170 return true;
171171 }
172 -
 172+
173173 /**
174174 * Keypress event handler. This is where the real work happens
175175 * @param e Event object
@@ -177,19 +177,19 @@
178178 if ( !enabled ) {
179179 return true;
180180 }
181 -
 181+
182182 if ( e.which == 8 ) { // Backspace
183183 // Blank the keybuffer
184184 $( this ).data( 'narayamKeyBuffer', '' );
185185 return true;
186186 }
187 -
 187+
188188 // Leave non-ASCII stuff alone, as well as anything involving
189189 // Alt (except for extended keymaps), Ctrl and Meta
190190 if ( e.which < 32 || ( e.altKey && !currentScheme.extended_keyboard ) || e.ctrlKey || e.metaKey ) {
191191 return true;
192192 }
193 -
 193+
194194 var $this = $( this );
195195 var c = String.fromCharCode( e.which );
196196 // Get the current caret position. The user may have selected text to overwrite,
@@ -204,7 +204,7 @@
205205 var input = lastNChars( $this.val(), startPos, currentScheme.lookbackLength ) + c;
206206 var keyBuffer = $this.data( 'narayamKeyBuffer' );
207207 var replacement = transliterate( input, keyBuffer, e.altKey );
208 -
 208+
209209 // Update the key buffer
210210 keyBuffer += c;
211211 if ( keyBuffer.length > currentScheme.keyBufferLength ) {
@@ -212,7 +212,7 @@
213213 keyBuffer = keyBuffer.substring( keyBuffer.length - currentScheme.keyBufferLength );
214214 }
215215 $this.data( 'narayamKeyBuffer', keyBuffer );
216 -
 216+
217217 // textSelection() magic is expensive, so we avoid it as much as we can
218218 if ( replacement == input ) {
219219 return true;
@@ -222,7 +222,7 @@
223223 var divergingPos = firstDivergence( input, replacement );
224224 input = input.substring( divergingPos );
225225 replacement = replacement.substring( divergingPos );
226 -
 226+
227227 // Select and replace the text
228228 $this.textSelection( 'setSelection', {
229229 'start': startPos - input.length + 1,
@@ -233,11 +233,11 @@
234234 'replace': true,
235235 'selectPeri': false
236236 } );
237 -
 237+
238238 e.stopPropagation();
239239 return false;
240240 }
241 -
 241+
242242 /**
243243 * Focus event handler.
244244 * @param e Event object
@@ -246,7 +246,7 @@
247247 $( this ).data( 'narayamKeyBuffer', '' );
248248 changeVisual( $( this ) );
249249 }
250 -
 250+
251251 /**
252252 * Blur event handler.
253253 * @param e Event object
@@ -254,7 +254,7 @@
255255 function onblur( e ) {
256256 $( this ).removeClass( 'narayam-input' );
257257 }
258 -
 258+
259259 /**
260260 * Change handler for the scheme dropdown. Updates the current scheme
261261 * based on the new selection in the dropdown.
@@ -263,7 +263,7 @@
264264 var scheme = $( this ).val();
265265 that.setScheme( scheme );
266266 }
267 -
 267+
268268 /* Public functions */
269269
270270 /**
@@ -291,7 +291,7 @@
292292 .bind( 'blur', onblur);
293293 }
294294 };
295 -
 295+
296296 /**
297297 * Enable Narayam
298298 */
@@ -302,7 +302,7 @@
303303 enabled = true;
304304 }
305305 };
306 -
 306+
307307 /**
308308 * Disable Narayam
309309 */
@@ -313,7 +313,7 @@
314314 enabled = false;
315315 }
316316 };
317 -
 317+
318318 /**
319319 * Toggle the enabled/disabled state
320320 */
@@ -324,7 +324,7 @@
325325 that.enable();
326326 }
327327 };
328 -
 328+
329329 /**
330330 * Add a transliteration scheme. Schemes whose name is not in
331331 * wgNarayamAvailableSchemes will be ignored.
@@ -373,7 +373,7 @@
374374 return false;
375375 }
376376 };
377 -
 377+
378378 /**
379379 * Change the current transliteration scheme
380380 * @param name String
@@ -385,7 +385,7 @@
386386 $select.val( name );
387387 }
388388 };
389 -
 389+
390390 /**
391391 * Set up Narayam. This adds the scheme dropdown, binds the handlers
392392 * and initializes the enabled/disabled state and selected scheme
@@ -403,18 +403,18 @@
404404 haveSchemes = true;
405405 }
406406 $select.change( updateSchemeFromSelect );
407 -
 407+
408408 if ( !haveSchemes ) {
409409 // No schemes available, don't show the tool
410410 return;
411411 }
412 -
 412+
413413 // Build enable/disable checkbox and label
414414 var $checkbox = $( '<input type="checkbox" id="narayam-toggle" />' );
415415 $checkbox
416416 .attr( 'title', mw.msg( 'narayam-checkbox-tooltip' ) )
417417 .click( that.toggle );
418 -
 418+
419419 var helppage = mw.msg( 'narayam-help-page' );
420420 var $label = $( '<label for="narayam-toggle" />' );
421421 $label
@@ -424,7 +424,7 @@
425425 // Link to the help page
426426 $label.wrapInner( $( '<a />' ).attr( 'href', mw.util.wikiGetlink( helppage ) ) );
427427 }
428 -
 428+
429429 var $checkboxAndLabel = $( '<span />' )
430430 .addClass( 'narayam-toggle-wrapper' )
431431 .append( $checkbox )
@@ -433,11 +433,11 @@
434434 .addClass( 'narayam-wrapper' )
435435 .append( $select )
436436 .append( $checkboxAndLabel );
437 -
 437+
438438 // Put the dropdown and the checkbox at the beginning of the
439439 // search form. This seems to be the most reliable way across skins.
440440 $( '#searchform' ).prepend( $spanWithEverything );
441 -
 441+
442442 // Restore state from cookies
443443 var savedScheme = $.cookie( 'narayam-scheme' );
444444 if ( savedScheme && savedScheme in schemes ) {
@@ -453,9 +453,9 @@
454454 if ( enabledCookie ) {
455455 $.cookie( 'narayam-enabled', enabledCookie, { 'path': '/', 'expires': 30 } );
456456 }
457 -
 457+
458458 };
459 -
 459+
460460 } )();
461461
462462 } )( jQuery );
Index: trunk/extensions/Narayam/Narayam.i18n.php
@@ -4,7 +4,7 @@
55 *
66 * @addtogroup Extensions
77 * @author Junaid P V <http://junaidpv.in>
8 - * @copyright 2010 Junaid P V
 8+ * @copyright 2010-2011 Junaid P V
99 * @license GNU General Public Licence 3.0 or later
1010 */
1111
Index: trunk/extensions/Narayam/ext.narayam.rules.ta.js
@@ -11,7 +11,7 @@
1212 ['ழ்h','h','ழ்ஹ்',],
1313
1414 //'(ஸ்ரிi|ஸ்ர்I)', '','',
15 -
 15+
1616 ['([க-ஹ])்a', '','$1'],
1717 ['([க-ஹ])(்A|a)', '','$1ா'],
1818 ['([க-ஹ])்i', '','$1ி'],
@@ -26,7 +26,7 @@
2727 ['([க-ஹ])u', '','$1ௌ'],
2828
2929 ['([அ-ஹ][ெ-்]?)n', '','$1ன்'],
30 -
 30+
3131 ['அa', '','ஆ'],
3232 ['இi', '','ஈ'],
3333 ['உu', '','ஊ'],
@@ -34,14 +34,14 @@
3535 ['அi', '','ஐ'],
3636 ['ஒo', '','ஓ'],
3737 ['அu', '','ஔ'],
38 -
 38+
3939 ['(ந்|ன்)g', '','ங்'],
4040 ['(ந்|ன்)j', '','ஞ்'],
4141 ['ச்h', '','ச்'],
4242 ['ழ்h', '','ழ்'],
4343 ['ட்h', '','த்'],
4444 ['ஸ்h', '','ஷ்'],
45 -
 45+
4646 ['a', '','அ'],
4747 ['b', '','ப்'],
4848 ['c', '','ச்'],
Index: trunk/extensions/Narayam/Narayam.hooks.php
@@ -1,32 +1,37 @@
22 <?php
3 -
43 /**
54 * Hooks for Narayam extension
65 * @file
76 * @ingroup Extensions
87 */
 8+
99 class NarayamHooks {
10 -
1110 public static function addModules( $out, $skin ) {
1211 global $wgUser;
 12+
1313 if ( $wgUser->getOption( 'narayamDisable' ) ) {
1414 // User disabled Narayam
1515 return true;
1616 }
 17+
1718 $schemes = array_values( self::getSchemes () );
 19+
1820 if ( count( $schemes ) ) {
1921 $out->addModules( $schemes );
2022 $out->addModules( 'ext.narayam' );
2123 }
 24+
2225 return true;
2326 }
2427
2528 public static function addConfig( &$vars ) {
2629 global $wgNarayamEnabledByDefault, $wgNarayamShortcutKey, $wgUser;
 30+
2731 if ( $wgUser->getOption( 'narayamDisable' ) ) {
2832 // User disabled Narayam
2933 return true;
3034 }
 35+
3136 $vars['wgNarayamEnabledByDefault'] = $wgNarayamEnabledByDefault;
3237 $vars['wgNarayamShortcutKey'] = $wgNarayamShortcutKey;
3338
@@ -35,11 +40,14 @@
3641
3742 public static function addVariables( &$vars ) {
3843 global $wgUser;
 44+
3945 if ( $wgUser->getOption( 'narayamDisable' ) ) {
4046 // User disabled Narayam
4147 return true;
4248 }
 49+
4350 $vars['wgNarayamAvailableSchemes'] = self::getSchemes(); // Note: scheme names must be keys, not values
 51+
4452 return true;
4553 }
4654
@@ -49,11 +57,13 @@
5058 */
5159 protected static function getSchemes() {
5260 global $wgLanguageCode, $wgLang, $wgNarayamSchemes;
 61+
5362 $userlangCode = $wgLang->getCode();
5463 $contlangSchemes = isset( $wgNarayamSchemes[$wgLanguageCode] ) ?
5564 $wgNarayamSchemes[$wgLanguageCode] : array();
5665 $userlangSchemes = isset( $wgNarayamSchemes[$userlangCode] ) ?
5766 $wgNarayamSchemes[$userlangCode] : array();
 67+
5868 return $userlangSchemes + $contlangSchemes;
5969 }
6070
@@ -64,7 +74,7 @@
6575 'label-message' => 'narayam-disable-preference', // a system message
6676 'section' => 'editing/advancedediting', // under 'Advanced options' section of 'Editing' tab
6777 );
 78+
6879 return true;
6980 }
70 -
7181 }
Index: trunk/extensions/Narayam/ext.narayam.rules.or-inscript.js
@@ -5,7 +5,7 @@
66 * @date 2011-02-28
77 * License: GPLv3
88 */
9 -
 9+
1010 var rules = [
1111 ['X', '', '\u0B01'],
1212 ['x', '', '\u0B02'],
Index: trunk/extensions/Narayam/Narayam.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * NAME
65 * Narayam
@@ -23,11 +22,11 @@
2423 * @copyright Copyright 2010 Junaid P V
2524 * @license GPLv3
2625 */
 26+
2727 if ( !defined( 'MEDIAWIKI' ) ) {
2828 exit( 1 );
2929 }
3030
31 -
3231 /* Configuration */
3332
3433 // Whether the input method should be active as default or not
@@ -91,6 +90,8 @@
9291
9392 /* Setup */
9493
 94+$dir = dirname( __FILE__ );
 95+
9596 // Register extension credits
9697 $wgExtensionCredits['other'][] = array(
9798 'path' => __FILE__,
@@ -102,7 +103,7 @@
103104 );
104105
105106 // Localization
106 -$wgExtensionMessagesFiles['Narayam'] = dirname( __FILE__ ) . '/Narayam.i18n.php';
 107+$wgExtensionMessagesFiles['Narayam'] = $dir . '/Narayam.i18n.php';
107108
108109 // Register hook function
109110 $wgHooks['BeforePageDisplay'][] = 'NarayamHooks::addModules';
@@ -111,11 +112,11 @@
112113 $wgHooks['GetPreferences'][] = 'NarayamHooks::addPreference';
113114
114115 // Autoloader
115 -$wgAutoloadClasses['NarayamHooks'] = dirname( __FILE__ ) . '/Narayam.hooks.php';
 116+$wgAutoloadClasses['NarayamHooks'] = $dir . '/Narayam.hooks.php';
116117
117118 // ResourceLoader module registration
118119 $narayamTpl = array(
119 - 'localBasePath' => dirname( __FILE__ ),
 120+ 'localBasePath' => $dir,
120121 'remoteExtPath' => 'Narayam',
121122 );
122123 $wgResourceModules['ext.narayam'] = $narayamTpl + array(

Status & tagging log