r109977 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109976‎ | r109977 | r109978 >
Date:01:00, 25 January 2012
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
fixing bug 33931 with submitted patch - explicitly listing mw.user as a depenancy
Modified paths:
  • /trunk/extensions/CentralNotice/special/SpecialBannerController.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/special/SpecialBannerController.php
@@ -110,39 +110,41 @@
111111 }
112112 },
113113 chooseBanner: function( bannerList ) {
114 - var groomedBannerList = [], i, j, pointer;
 114+ mw.loader.using('mediawiki.user', function() {
 115+ var groomedBannerList = [], i, j, pointer;
115116
116 - // Make sure there are some banners to choose from
117 - if ( bannerList.length === 0 ) {
118 - return false;
119 - }
 117+ // Make sure there are some banners to choose from
 118+ if ( bannerList.length === 0 ) {
 119+ return false;
 120+ }
120121
121 - for( i = 0; i < bannerList.length; i++ ) {
122 - // Only include this banner if it's intended for the current user
123 - if( ( !mw.user.anonymous() && bannerList[i].display_account === 1 ) ||
124 - ( mw.user.anonymous() && bannerList[i].display_anon === 1 ) )
125 - {
126 - // Add the banner to our list once per weight
127 - for( j = 0; j < bannerList[i].weight; j++ ) {
128 - groomedBannerList.push( bannerList[i] );
 122+ for( i = 0; i < bannerList.length; i++ ) {
 123+ // Only include this banner if it's intended for the current user
 124+ if( ( !mw.user.anonymous() && bannerList[i].display_account === 1 ) ||
 125+ ( mw.user.anonymous() && bannerList[i].display_anon === 1 ) )
 126+ {
 127+ // Add the banner to our list once per weight
 128+ for( j = 0; j < bannerList[i].weight; j++ ) {
 129+ groomedBannerList.push( bannerList[i] );
 130+ }
129131 }
130132 }
131 - }
132133
133 - // Return if there's nothing left after the grooming
134 - if ( groomedBannerList.length === 0 ) {
135 - return false;
136 - }
 134+ // Return if there's nothing left after the grooming
 135+ if ( groomedBannerList.length === 0 ) {
 136+ return false;
 137+ }
137138
138 - // Choose a random key
139 - pointer = Math.floor( Math.random() * groomedBannerList.length );
 139+ // Choose a random key
 140+ pointer = Math.floor( Math.random() * groomedBannerList.length );
140141
141 - // Load a random banner from our groomed list
142 - $.centralNotice.fn.loadBanner(
143 - groomedBannerList[pointer].name,
144 - groomedBannerList[pointer].campaign,
145 - ( groomedBannerList[pointer].fundraising ? 'fundraising' : 'default' )
146 - );
 142+ // Load a random banner from our groomed list
 143+ $.centralNotice.fn.loadBanner(
 144+ groomedBannerList[pointer].name,
 145+ groomedBannerList[pointer].campaign,
 146+ ( groomedBannerList[pointer].fundraising ? 'fundraising' : 'default' )
 147+ );
 148+ });
147149 },
148150 getQueryStringVariables: function() {
149151 function decode( s ) {

Comments

#Comment by Kaldari (talk | contribs)   01:03, 25 January 2012

Patch was tested locally and seems to work.

#Comment by Krinkle (talk | contribs)   01:10, 25 January 2012

Just FYI, chooseBanner is now immediately returning undefined. And in asychronous, the callback is called and the return falses are given to the mw.loader.using() callback not to whomever called chooseBanner().

Looks like chooseBanner is only called from an $.ajax success callback so looking good.

Status & tagging log