r100116 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100115‎ | r100116 | r100117 >
Date:15:22, 18 October 2011
Author:santhosh
Status:resolved (Comments)
Tags:
Comment:
have a configuraiton parameter $wgEnableWebFontsDefault , when set false, dont show the extension for anonymous users.
For logged in users, use the user's preference page settings.
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
@@ -17,7 +17,37 @@
1818
1919 return true; // Hooks must return value
2020 }
 21+
 22+ public static function addConfig( &$vars ) {
 23+ global $wgUser;
2124
 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+
2252 public static function addPreference( $user, &$preferences ) {
2353 // A checkbox in preferences to disable WebFonts
2454 $preferences['webfontsDisable'] = array(
Index: trunk/extensions/WebFonts/js/webfonts.js
@@ -158,6 +158,11 @@
159159 var config = [];
160160 var languages = $.webfonts.config.languages;
161161 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+ }
162167 for (var i = 0; i < requested.length; i++) {
163168 if (requested[i] in languages) {
164169 var fonts = languages[requested[i]];
Index: trunk/extensions/WebFonts/WebFonts.php
@@ -35,6 +35,8 @@
3636
3737 $wgHooks['BeforePageDisplay'][] = 'WebFontsHooks::addModules';
3838 $wgHooks['GetPreferences'][] = 'WebFontsHooks::addPreference';
 39+$wgHooks['ResourceLoaderGetConfigVars'][] = 'WebFontsHooks::addConfig';
 40+$wgHooks['MakeGlobalVariablesScript'][] = 'WebFontsHooks::addVariables';
3941
4042 $wgWebFontsEnabled = true;
4143

Follow-up revisions

RevisionCommit summaryAuthorDate
r100414Remove unnecessary addConfig. Follow up r100116santhosh06:39, 21 October 2011
r100416Remove no-op code. Condition has no effect.santhosh09:49, 21 October 2011
r100594Define the global property $wgWebFontsEnabledByDefault as true by default.santhosh09:43, 24 October 2011

Comments

#Comment by Nikerabbit (talk | contribs)   06:19, 21 October 2011

addConfig is not doing anything if I'm reading this correctly. Can we just remove that function?

#Comment by Santhosh.thottingal (talk | contribs)   06:40, 21 October 2011

Yes. Addressed that in r100414

Status & tagging log