r102646 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102645‎ | r102646 | r102647 >
Date:12:42, 10 November 2011
Author:santhosh
Status:ok
Tags:
Comment:
Set the default user option webfontsEnable value to "$wgWebFontsEnabledByDefault" in UserGetDefaultOptions hook and simplify the options handling.
No need to pass varibles to client, and remove MakeGlobalVariablesScript hook.

As per https://www.mediawiki.org/wiki/User:Krinkle/Extension_review/WebFonts#Default_user_options
Modified paths:
  • /trunk/extensions/WebFonts/WebFonts.hooks.php (modified) (history)
  • /trunk/extensions/WebFonts/WebFonts.php (modified) (history)
  • /trunk/extensions/WebFonts/js/webfonts.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WebFonts/WebFonts.hooks.php
@@ -22,21 +22,6 @@
2323 }
2424
2525 /**
26 - * MakeGlobalVariablesScript hook handler.
27 - */
28 - public static function addVariables( &$vars, $out ) {
29 - global $wgWebFontsEnabledByDefault;
30 -
31 - if ( $out->getUser()->isAnon() ) {
32 - // If user enabled webfonts from preference page,
33 - // wgWebFontsEnabledByDefault is overridden by that.
34 - $vars['wgWebFontsEnabledByDefault'] = $wgWebFontsEnabledByDefault;
35 - }
36 -
37 - return true;
38 - }
39 -
40 - /**
4126 * GetPreferences hook handler.
4227 */
4328 public static function addPreference( $user, &$preferences ) {
@@ -50,4 +35,14 @@
5136
5237 return true;
5338 }
 39+
 40+ /**
 41+ * UserGetDefaultOptions hook handler.
 42+ */
 43+ public static function addDefaultOptions( &$defaultOptions ) {
 44+ global $wgWebFontsEnabledByDefault;
 45+ // By default, the preference page option to enable webfonts is set to wgWebFontsEnabledByDefault value.
 46+ $defaultOptions['webfontsEnable'] = $wgWebFontsEnabledByDefault;
 47+ return true;
 48+ }
5449 }
Index: trunk/extensions/WebFonts/js/webfonts.js
@@ -162,11 +162,7 @@
163163 var config = [];
164164 var languages = $.webfonts.config.languages;
165165 var requested = [mw.config.get( 'wgUserVariant' ), mw.config.get( 'wgContentLanguage' ), mw.config.get( 'wgUserLanguage' )];
166 - if ( mw.config.get( 'wgWebFontsEnabledByDefault' ) == false ) {
167 - // Webfonts are not enabled by default. Not setting up.
168 - // This is applicable only for anonymous users.
169 - return false;
170 - }
 166+
171167 for (var i = 0; i < requested.length; i++) {
172168 if (requested[i] in languages) {
173169 var fonts = languages[requested[i]];
Index: trunk/extensions/WebFonts/WebFonts.php
@@ -36,13 +36,10 @@
3737
3838 $wgHooks['BeforePageDisplay'][] = 'WebFontsHooks::addModules';
3939 $wgHooks['GetPreferences'][] = 'WebFontsHooks::addPreference';
40 -$wgHooks['MakeGlobalVariablesScript'][] = 'WebFontsHooks::addVariables';
 40+$wgHooks['UserGetDefaultOptions'][] = 'WebFontsHooks::addDefaultOptions';
4141
4242 $wgWebFontsEnabledByDefault = true;
4343
44 -// By default, the preference page option to enable webfonts is set to true.
45 -$wgDefaultUserOptions['webfontsEnable'] = true;
46 -
4744 $wgResourceModules['webfonts'] = array(
4845 'scripts' => 'js/webfonts.js',
4946 'styles' => 'css/webfonts.css',

Status & tagging log