Index: trunk/extensions/WebFonts/WebFonts.hooks.php |
— | — | @@ -17,7 +17,37 @@ |
18 | 18 | |
19 | 19 | return true; // Hooks must return value |
20 | 20 | } |
| 21 | + |
| 22 | + public static function addConfig( &$vars ) { |
| 23 | + global $wgUser; |
21 | 24 | |
| 25 | + if ( $wgUser->getOption( 'webfontsDisable' ) ) { |
| 26 | + wfDebugLog( 'webfonts', 'User disabled WebFonts: ' , true ); |
| 27 | + // User disabled WebFonts |
| 28 | + return true; |
| 29 | + } |
| 30 | + |
| 31 | + |
| 32 | + return true; |
| 33 | + } |
| 34 | + |
| 35 | + public static function addVariables( &$vars ) { |
| 36 | + global $wgWebFontsEnabledByDefault, $wgUser; |
| 37 | + |
| 38 | + if ( $wgUser->getOption( 'webfontsDisable' ) ) { |
| 39 | + // User disabled WebFonts |
| 40 | + return true; |
| 41 | + } |
| 42 | + |
| 43 | + if ( $wgUser->isAnon() ) { |
| 44 | + // If user enabled webfonts from preference page, |
| 45 | + // wgWebFontsEnabledByDefault is overridden by that. |
| 46 | + $vars['wgWebFontsEnabledByDefault'] = $wgWebFontsEnabledByDefault; |
| 47 | + } |
| 48 | + |
| 49 | + return true; |
| 50 | + } |
| 51 | + |
22 | 52 | public static function addPreference( $user, &$preferences ) { |
23 | 53 | // A checkbox in preferences to disable WebFonts |
24 | 54 | $preferences['webfontsDisable'] = array( |
Index: trunk/extensions/WebFonts/js/webfonts.js |
— | — | @@ -158,6 +158,11 @@ |
159 | 159 | var config = []; |
160 | 160 | var languages = $.webfonts.config.languages; |
161 | 161 | var requested = [wgUserLanguage, wgContentLanguage]; |
| 162 | + if ( mw.config.get( 'wgWebFontsEnabledByDefault' ) == false) { |
| 163 | + // Webfonts are not enabled by default. Not setting up. |
| 164 | + // This is applicable only for anonymous users. |
| 165 | + return false; |
| 166 | + } |
162 | 167 | for (var i = 0; i < requested.length; i++) { |
163 | 168 | if (requested[i] in languages) { |
164 | 169 | var fonts = languages[requested[i]]; |
Index: trunk/extensions/WebFonts/WebFonts.php |
— | — | @@ -35,6 +35,8 @@ |
36 | 36 | |
37 | 37 | $wgHooks['BeforePageDisplay'][] = 'WebFontsHooks::addModules'; |
38 | 38 | $wgHooks['GetPreferences'][] = 'WebFontsHooks::addPreference'; |
| 39 | +$wgHooks['ResourceLoaderGetConfigVars'][] = 'WebFontsHooks::addConfig'; |
| 40 | +$wgHooks['MakeGlobalVariablesScript'][] = 'WebFontsHooks::addVariables'; |
39 | 41 | |
40 | 42 | $wgWebFontsEnabled = true; |
41 | 43 | |