r84597 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84596‎ | r84597 | r84598 >
Date:15:14, 23 March 2011
Author:junaidpv
Status:resolved (Comments)
Tags:
Comment:
Narayam: Add a checkbox under 'Advanced options' section of 'Editing' tab toallow user to disable Narayam IME.
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)

Diff [purge]

Index: trunk/extensions/Narayam/Narayam.i18n.php
@@ -18,6 +18,7 @@
1919 'narayam-toggle-ime' => 'To toggle IM ($1)', // FIXME: better message
2020 'narayam-help-page' => 'Help:Typing',
2121 'narayam-checkbox-tooltip' => 'To toggle input method on and off', // FIXME: better message
 22+ 'narayam-disable-preference' => 'Disable Narayam IME',
2223 'narayam-hi-inscript' => 'Hindi InScript',
2324 'narayam-kn' => 'Kannada Transliteration',
2425 'narayam-kn-inscript' => 'Kannada InScript',
Index: trunk/extensions/Narayam/Narayam.hooks.php
@@ -1,32 +1,50 @@
22 <?php
 3+
34 /**
45 * Hooks for Narayam extension
56 * @file
67 * @ingroup Extensions
78 */
89 class NarayamHooks {
9 - public static function addModules( $out, $skin ) {
10 - $schemes = array_values( self::getSchemes () );
11 - if ( count( $schemes ) ) {
12 - $out->addModules( $schemes );
13 - $out->addModules( 'ext.narayam' );
 10+
 11+ protected static $disabled = false;
 12+
 13+ public static function addModules($out, $skin) {
 14+ global $wgUser;
 15+ if ($wgUser->getOption('narayamDisable')) {
 16+ // User disabled Narayam
 17+ return true;
1418 }
 19+ $schemes = array_values(self::getSchemes ());
 20+ if (count($schemes)) {
 21+ $out->addModules($schemes);
 22+ $out->addModules('ext.narayam');
 23+ }
1524 return true;
1625 }
17 -
18 - public static function addConfig( &$vars ) {
19 - global $wgNarayamEnabledByDefault, $wgNarayamShortcutKey;
 26+
 27+ public static function addConfig(&$vars) {
 28+ global $wgNarayamEnabledByDefault, $wgNarayamShortcutKey, $wgUser;
 29+ if ($wgUser->getOption('narayamDisable')) {
 30+ // User disabled Narayam
 31+ return true;
 32+ }
2033 $vars['wgNarayamEnabledByDefault'] = $wgNarayamEnabledByDefault;
2134 $vars['wgNarayamShortcutKey'] = $wgNarayamShortcutKey;
22 -
 35+
2336 return true;
2437 }
25 -
26 - public static function addVariables( &$vars ) {
 38+
 39+ public static function addVariables(&$vars) {
 40+ global $wgUser;
 41+ if ($wgUser->getOption('narayamDisable')) {
 42+ // User disabled Narayam
 43+ return true;
 44+ }
2745 $vars['wgNarayamAvailableSchemes'] = self::getSchemes(); // Note: scheme names must be keys, not values
2846 return true;
2947 }
30 -
 48+
3149 /**
3250 * Get the available schemes for the user and content language
3351 * @return array( scheme name => module name )
@@ -34,10 +52,21 @@
3553 protected static function getSchemes() {
3654 global $wgLanguageCode, $wgLang, $wgNarayamSchemes;
3755 $userlangCode = $wgLang->getCode();
38 - $contlangSchemes = isset( $wgNarayamSchemes[$wgLanguageCode] ) ?
39 - $wgNarayamSchemes[$wgLanguageCode] : array();
40 - $userlangSchemes = isset( $wgNarayamSchemes[$userlangCode] ) ?
41 - $wgNarayamSchemes[$userlangCode] : array();
 56+ $contlangSchemes = isset($wgNarayamSchemes[$wgLanguageCode]) ?
 57+ $wgNarayamSchemes[$wgLanguageCode] : array();
 58+ $userlangSchemes = isset($wgNarayamSchemes[$userlangCode]) ?
 59+ $wgNarayamSchemes[$userlangCode] : array();
4260 return $userlangSchemes + $contlangSchemes;
4361 }
 62+
 63+ public static function addPreference($user, &$preferences) {
 64+ // A checkbox in preferences to diable Narayam
 65+ $preferences['narayamDisable'] = array(
 66+ 'type' => 'toggle',
 67+ 'label-message' => 'narayam-disable-preference', // a system message
 68+ 'section' => 'editing/advancedediting', // under 'Advanced options' section of 'Editing' tab
 69+ );
 70+ return true;
 71+ }
 72+
4473 }
Index: trunk/extensions/Narayam/Narayam.php
@@ -98,6 +98,7 @@
9999 $wgHooks['BeforePageDisplay'][] = 'NarayamHooks::addModules';
100100 $wgHooks['ResourceLoaderGetConfigVars'][] = 'NarayamHooks::addConfig';
101101 $wgHooks['MakeGlobalVariablesScript'][] = 'NarayamHooks::addVariables';
 102+$wgHooks['GetPreferences'][] = 'NarayamHooks::addPreference';
102103
103104 // Autoloader
104105 $wgAutoloadClasses['NarayamHooks'] = dirname( __FILE__ ) . '/Narayam.hooks.php';

Follow-up revisions

RevisionCommit summaryAuthorDate
r84608Narayam: Fix white space issue in r84597junaidpv17:19, 23 March 2011
r84611Narayam: * Better sentence to describe checkbox * Remove unused variable rai...junaidpv17:36, 23 March 2011

Comments

#Comment by Catrope (talk | contribs)   16:10, 23 March 2011
+	'narayam-disable-preference' => 'Disable Narayam IME',

This message should probably be worded better: not everyone knows what IME stands for.

+	protected static $disabled = false;

This variable is unused.

-		if ( count( $schemes ) ) {
+		if (count($schemes)) {

Please don't mix mass whitespace changes with functional changes in the same commit. In fact, these changes make the code less conformant to MediaWiki's whitespace conventions, so they should be reverted (marking fixme).

Aside from the issues mentioned above this commit is OK.

Status & tagging log