r105928 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105927‎ | r105928 | r105929 >
Date:21:04, 12 December 2011
Author:yonishostak
Status:resolved (Comments)
Tags:
Comment:
AFTv5: changed bucketing odds to 1/3 for option 1,2,3. changed loading mechanism for a) efficiency and b) remove lottery
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.startup.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.startup.js
@@ -46,36 +46,25 @@
4747 'current': mw.config.get( 'wgCategories', [] )
4848 };
4949
50 - // Categories are configured with underscores, but article's categories are returned with
51 - // spaces instead. Convert to underscores here for sane comparison.
52 - for ( var cat in categories['current'] ) {
53 - categories['current'][cat] = categories['current'][cat].replace(/\s/gi, '_');
54 - }
55 -
56 - // Category exclusion
57 - var disable = false;
58 - for ( var i = 0; i < categories.current.length; i++ ) {
59 - if ( $.inArray( categories.current[i], categories.exclude ) > -1 ) {
60 - disable = true;
61 - break;
62 - }
63 - }
64 -
65 - // Category inclusion
6650 var enable = false;
67 - for ( var i = 0; i < categories.current.length; i++ ) {
68 - if ( $.inArray( categories.current[i], categories.include ) > -1 ) {
 51+ for( cat in categories['current'] ) {
 52+ // Categories are configured with underscores, but article's categories are returned with
 53+ // spaces instead. Revert to underscores here for sane comparison.
 54+ categories['current'][cat] = categories['current'][cat].replace(/\s/gi, '_');
 55+ // Check exclusion - exclusion overrides everything else
 56+ if( $.inArray( categories['current'][cat], categories.exclude ) > -1 ) {
 57+ // Blacklist overrides everything else
 58+ return;
 59+ }
 60+ if( $.inArray( categories['current'][cat], categories.include ) > -1 ) {
 61+ // One match is enough for include, however we are iterating on the 'current'
 62+ // categories, and others might be blacklisted - so continue iterating
6963 enable = true;
70 - break;
7164 }
72 - }
 65+ }
7366
74 - // Lottery inclusion
75 - var wonLottery = ( Number( mw.config.get( 'wgArticleId', 0 ) ) % 1000 )
76 - < Number( mw.config.get( 'wgArticleFeedbackv5LotteryOdds', 0 ) ) * 10;
77 -
7867 // Lazy loading
79 - if ( !disable && ( wonLottery || enable ) ) {
 68+ if ( enable ) {
8069 mw.loader.load( 'ext.articleFeedbackv5' );
8170 // Load the IE-specific module
8271 if( navigator.appVersion.indexOf( 'MSIE' ) != -1 ) {
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php
@@ -63,10 +63,10 @@
6464 // the new odds are applied to everyone, not just people who have yet to be
6565 // placed in a bucket.
6666 'buckets' => array(
67 - 'zero' => 25,
68 - 'one' => 25,
69 - 'two' => 25,
70 - 'three' => 25,
 67+ 'zero' => 0,
 68+ 'one' => 34,
 69+ 'two' => 33,
 70+ 'three' => 33,
7171 'four' => 0,
7272 'five' => 0,
7373 ),

Comments

#Comment by Catrope (talk | contribs)   21:13, 12 December 2011

Please use tabs instead of spaces. The easiest test is to change your tab size setting and see if things look broken. For instance, the diff on this page uses a tab size of eight, and as you can see the indentation is pretty messed up.

+        for( cat in categories['current'] ) {

You need to use var cat here, otherwise the cat variable is leaked to the global scope.

OK otherwise. Marking fixme for the variable leakage.

Status & tagging log