r88771 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88770‎ | r88771 | r88772 >
Date:00:44, 25 May 2011
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Added $wgArticleFeedbackBlacklistCategories, a way to disable ArticleFeedback on pages in a certain category (such as "All disambiguation pages" on English Wikipedia). Also refactored the category intersection code, making it a little easier to read.
Modified paths:
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.hooks.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.startup.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/ArticleFeedback.hooks.php
@@ -232,12 +232,14 @@
233233 public static function resourceLoaderGetConfigVars( &$vars ) {
234234 global $wgArticleFeedbackSMaxage,
235235 $wgArticleFeedbackCategories,
 236+ $wgArticleFeedbackBlacklistCategories,
236237 $wgArticleFeedbackLotteryOdds,
237238 $wgArticleFeedbackTracking,
238239 $wgArticleFeedbackOptions,
239240 $wgArticleFeedbackNamespaces;
240241 $vars['wgArticleFeedbackSMaxage'] = $wgArticleFeedbackSMaxage;
241242 $vars['wgArticleFeedbackCategories'] = $wgArticleFeedbackCategories;
 243+ $vars['wgArticleFeedbackBlacklistCategories'] = $wgArticleFeedbackBlacklistCategories;
242244 $vars['wgArticleFeedbackLotteryOdds'] = $wgArticleFeedbackLotteryOdds;
243245 $vars['wgArticleFeedbackTracking'] = $wgArticleFeedbackTracking;
244246 $vars['wgArticleFeedbackOptions'] = $wgArticleFeedbackOptions;
Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.startup.js
@@ -16,29 +16,42 @@
1717 // Not viewing a redirect
1818 && mw.util.getParamValue( 'redirect' ) != 'no'
1919 ) {
20 - var trackingBucket = mw.user.bucket(
 20+ // Assign a tracking bucket using options from wgArticleFeedbackTracking
 21+ mw.user.bucket(
2122 'ext.articleFeedback-tracking', mw.config.get( 'wgArticleFeedbackTracking' )
2223 );
23 - // Category activation
24 - var articleFeedbackCategories = mw.config.get( 'wgArticleFeedbackCategories', [] );
25 - var articleCategories = mw.config.get( 'wgCategories', [] );
26 - var inCategory = false;
27 - for ( var i = 0; i < articleCategories.length; i++ ) {
28 - for ( var j = 0; j < articleFeedbackCategories.length; j++ ) {
29 - if ( articleCategories[i] == articleFeedbackCategories[j] ) {
30 - inCategory = true;
31 - // Break 2 levels - could do this with a label, but eww.
32 - i = articleCategories.length;
33 - j = articleFeedbackCategories.length;
34 - }
 24+
 25+ // Collect categories for intersection tests
 26+ var categories = {
 27+ 'include': mw.config.get( 'wgArticleFeedbackCategories', [] ),
 28+ 'exclude': mw.config.get( 'wgArticleFeedbackBlacklistCategories', [] ),
 29+ 'current': mw.config.get( 'wgCategories', [] )
 30+ };
 31+
 32+ // Category exclusion
 33+ var disable = false;
 34+ for ( var i = 0; i < categories.current.length; i++ ) {
 35+ if ( $.inArray( categories.current[i], categories.exclude ) > -1 ) {
 36+ disable = true;
 37+ break;
3538 }
3639 }
37 - // Lottery activation
 40+
 41+ // Category inclusion
 42+ var enable = false;
 43+ for ( var i = 0; i < categories.current.length; i++ ) {
 44+ if ( $.inArray( categories.current[i], categories.include ) > -1 ) {
 45+ enable = true;
 46+ break;
 47+ }
 48+ }
 49+
 50+ // Lottery inclusion
3851 var wonLottery = ( Number( mw.config.get( 'wgArticleId', 0 ) ) % 1000 )
3952 < Number( mw.config.get( 'wgArticleFeedbackLotteryOdds', 0 ) ) * 10;
40 -
 53+
4154 // Lazy loading
42 - if ( wonLottery || inCategory ) {
 55+ if ( !disable && ( wonLottery || enable ) ) {
4356 mw.loader.load( 'ext.articleFeedback' );
4457 }
4558 }
Index: trunk/extensions/ArticleFeedback/ArticleFeedback.php
@@ -31,6 +31,9 @@
3232 // Extension is "disabled" if this field is an empty array (as per default configuration)
3333 $wgArticleFeedbackCategories = array();
3434
 35+// Which categories the pages must not belong to have the rating widget added (with _ in text)
 36+$wgArticleFeedbackBlacklistCategories = array();
 37+
3538 // Only load the module / enable the tool in these namespaces
3639 // Default to $wgContentNamespaces (defaults to array( NS_MAIN ) ).
3740 $wgArticleFeedbackNamespaces = $wgContentNamespaces;

Sign-offs

UserFlagDate
Krinkleinspected17:29, 25 May 2011

Comments

#Comment by He7d3r (talk | contribs)   22:17, 30 May 2011

The pair of names "disable" and "enable" is a little weird since usually "!disable" means exactly "enable". Maybe there is a better name for one of them?

#Comment by Trevor Parscal (WMF) (talk | contribs)   17:13, 31 May 2011

Well, I'm open to suggestions. Essentially both can be true, or both can be false - disable overrides everything, enable is only used if the lottery fails and it's not disabled. Made sense to me when I wrote it, but you should change it if you think you can improve on the readability.

#Comment by He7d3r (talk | contribs)   23:49, 31 May 2011

I think "disable" could be changed to "inBlackList" or "blackListed", for consistence with "wgArticleFeedbackBlacklistCategories", and "enable" could be changed back to "inCategory".

Status & tagging log