Index: trunk/extensions/Narayam/Narayam.i18n.php |
— | — | @@ -18,6 +18,7 @@ |
19 | 19 | 'narayam-toggle-ime' => 'To toggle IM ($1)', // FIXME: better message |
20 | 20 | 'narayam-help-page' => 'Help:Typing', |
21 | 21 | 'narayam-checkbox-tooltip' => 'To toggle input method on and off', // FIXME: better message |
| 22 | + 'narayam-disable-preference' => 'Disable Narayam IME', |
22 | 23 | 'narayam-hi-inscript' => 'Hindi InScript', |
23 | 24 | 'narayam-kn' => 'Kannada Transliteration', |
24 | 25 | 'narayam-kn-inscript' => 'Kannada InScript', |
Index: trunk/extensions/Narayam/Narayam.hooks.php |
— | — | @@ -1,32 +1,50 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Hooks for Narayam extension |
5 | 6 | * @file |
6 | 7 | * @ingroup Extensions |
7 | 8 | */ |
8 | 9 | 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; |
14 | 18 | } |
| 19 | + $schemes = array_values(self::getSchemes ()); |
| 20 | + if (count($schemes)) { |
| 21 | + $out->addModules($schemes); |
| 22 | + $out->addModules('ext.narayam'); |
| 23 | + } |
15 | 24 | return true; |
16 | 25 | } |
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 | + } |
20 | 33 | $vars['wgNarayamEnabledByDefault'] = $wgNarayamEnabledByDefault; |
21 | 34 | $vars['wgNarayamShortcutKey'] = $wgNarayamShortcutKey; |
22 | | - |
| 35 | + |
23 | 36 | return true; |
24 | 37 | } |
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 | + } |
27 | 45 | $vars['wgNarayamAvailableSchemes'] = self::getSchemes(); // Note: scheme names must be keys, not values |
28 | 46 | return true; |
29 | 47 | } |
30 | | - |
| 48 | + |
31 | 49 | /** |
32 | 50 | * Get the available schemes for the user and content language |
33 | 51 | * @return array( scheme name => module name ) |
— | — | @@ -34,10 +52,21 @@ |
35 | 53 | protected static function getSchemes() { |
36 | 54 | global $wgLanguageCode, $wgLang, $wgNarayamSchemes; |
37 | 55 | $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(); |
42 | 60 | return $userlangSchemes + $contlangSchemes; |
43 | 61 | } |
| 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 | + |
44 | 73 | } |
Index: trunk/extensions/Narayam/Narayam.php |
— | — | @@ -98,6 +98,7 @@ |
99 | 99 | $wgHooks['BeforePageDisplay'][] = 'NarayamHooks::addModules'; |
100 | 100 | $wgHooks['ResourceLoaderGetConfigVars'][] = 'NarayamHooks::addConfig'; |
101 | 101 | $wgHooks['MakeGlobalVariablesScript'][] = 'NarayamHooks::addVariables'; |
| 102 | +$wgHooks['GetPreferences'][] = 'NarayamHooks::addPreference'; |
102 | 103 | |
103 | 104 | // Autoloader |
104 | 105 | $wgAutoloadClasses['NarayamHooks'] = dirname( __FILE__ ) . '/Narayam.hooks.php'; |