Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/213988
Change subject: Hygiene: Use this keyword (it's your friend)
......................................................................
Hygiene: Use this keyword (it's your friend)
Change-Id: I1a6d24c5c01d2c62f85b1f48a843a1e29671686f
---
A modules/ext.centralNotice.banner.init/init.js
M modules/ext.centralNotice.bannerController/bannerController.js
M modules/ext.centralNotice.bannerController/bannerController.lib.js
3 files changed, 57 insertions(+), 55 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice
refs/changes/88/213988/1
diff --git a/modules/ext.centralNotice.banner.init/init.js
b/modules/ext.centralNotice.banner.init/init.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/modules/ext.centralNotice.banner.init/init.js
diff --git a/modules/ext.centralNotice.bannerController/bannerController.js
b/modules/ext.centralNotice.bannerController/bannerController.js
index bec6dc0..db46321 100644
--- a/modules/ext.centralNotice.bannerController/bannerController.js
+++ b/modules/ext.centralNotice.bannerController/bannerController.js
@@ -129,28 +129,27 @@
loadBanner: function () {
// If we're forcing a banner for testing, just load
that.
- if ( mw.centralNotice.data.getVars.banner ) {
+ if ( this.data.getVars.banner ) {
// Sending an empty string as the campaign name
will make the
// server skip checks on campaign validity.
- mw.centralNotice.loadTestingBanner(
- mw.centralNotice.data.getVars.banner,
'' );
+ this.loadTestingBanner(
this.data.getVars.banner, '' );
} else {
- mw.centralNotice.loadRandomBanner();
+ this.loadRandomBanner();
}
},
loadTestingBanner: function ( bannerName, campaign ) {
var bannerPageQuery, url;
- mw.centralNotice.data.testing = true;
+ this.data.testing = true;
// Get the requested banner
bannerPageQuery = {
banner: bannerName,
campaign: campaign,
uselang: mw.config.get( 'wgUserLanguage' ),
- debug: mw.centralNotice.data.getVars.debug
+ debug: this.data.getVars.debug
};
url = new mw.Uri( mw.config.get(
'wgCentralSelectedBannerDispatcher' ) );
@@ -167,17 +166,17 @@
var fetchBannerQueryParams,
scriptUrl;
- mw.centralNotice.chooseRandomBanner();
+ this.chooseRandomBanner();
- if ( mw.centralNotice.data.banner ) {
+ if ( this.data.banner ) {
// A banner was chosen! Let's fetch it.
fetchBannerQueryParams = {
- banner: mw.centralNotice.data.banner,
- campaign:
mw.centralNotice.data.campaign,
+ banner: this.data.banner,
+ campaign: this.data.campaign,
uselang: mw.config.get(
'wgUserLanguage' ),
- debug:
mw.centralNotice.data.getVars.debug
+ debug: this.data.getVars.debug
};
scriptUrl = new mw.Uri( mw.config.get(
'wgCentralSelectedBannerDispatcher' ) );
@@ -198,8 +197,8 @@
// Set the onlySampleRI flag to true to sample
empty results
// and return them via Special:RecordImpression.
// TODO Refactor
- mw.centralNotice.onlySampleRI = true;
- mw.centralNotice.insertBanner( false );
+ this.onlySampleRI = true;
+ this.insertBanner( false );
}
},
/**
@@ -243,7 +242,7 @@
// Get a random seed or use the dev-only randomcampaign
// parameter from the URL, and choose the campaign.
randomCampaign =
- mw.centralNotice.data.getVars.randomcampaign ||
Math.random();
+ this.data.getVars.randomcampaign ||
Math.random();
mw.cnBannerControllerLib.chooseCampaign( randomCampaign
);
@@ -277,7 +276,7 @@
// Get another random seed or use the randombanner=
parameter
// from the URL, and choose the banner.
randomBanner =
- mw.centralNotice.data.getVars.randombanner ||
Math.random();
+ this.data.getVars.randombanner || Math.random();
mw.cnBannerControllerLib.chooseBanner( randomBanner );
},
@@ -297,7 +296,7 @@
var sampleRate,
url = new mw.Uri( mw.config.get(
'wgCentralBannerRecorder' ) );
- if ( mw.centralNotice.onlySampleRI ) {
+ if ( this.onlySampleRI ) {
sampleRate = mw.config.get(
'wgCentralNoticeSampleRate' );
@@ -323,8 +322,9 @@
}
},
loadQueryStringVariables: function () {
+ var self = this;
document.location.search.replace(
/\??(?:([^=]+)=([^&]*)&?)/g, function ( str, p1, p2 ) {
- mw.centralNotice.data.getVars[decode( p1 )] =
decode( p2 );
+ self.data.getVars[decode( p1 )] = decode( p2 );
} );
},
/**
@@ -345,32 +345,34 @@
mw.log( 'Legacy mw.bannerController.storeBucket() is
deprecated no-op.' );
},
initialize: function () {
+ var self = this;
+
// === Do not allow CentralNotice to be re-initialized.
===
- if ( mw.centralNotice.alreadyRan ) {
+ if ( this.alreadyRan ) {
return;
}
- mw.centralNotice.alreadyRan = true;
+ this.alreadyRan = true;
// === Attempt to load parameters from the query string
===
- mw.centralNotice.loadQueryStringVariables();
+ this.loadQueryStringVariables();
// === Initialize some data ===
- mw.centralNotice.data.anonymous = ( mw.config.get(
'wgUserName' ) === null );
- mw.centralNotice.data.country =
mw.centralNotice.data.getVars.country || window.Geo.country || 'XX';
- mw.centralNotice.data.addressFamily = ( window.Geo.IPv6
|| window.Geo.af === 'v6' ) ? 'IPv6' : 'IPv4';
- mw.centralNotice.isPreviewFrame = (mw.config.get(
'wgCanonicalSpecialPageName' ) === 'BannerPreview');
- mw.centralNotice.data.device =
mw.centralNotice.data.getVars.device || mw.config.get( 'wgMobileDeviceName',
'desktop' );
+ this.data.anonymous = ( mw.config.get( 'wgUserName' )
=== null );
+ this.data.country = this.data.getVars.country ||
window.Geo.country || 'XX';
+ this.data.addressFamily = ( window.Geo.IPv6 ||
window.Geo.af === 'v6' ) ? 'IPv6' : 'IPv4';
+ this.isPreviewFrame = (mw.config.get(
'wgCanonicalSpecialPageName' ) === 'BannerPreview');
+ this.data.device = this.data.getVars.device ||
mw.config.get( 'wgMobileDeviceName', 'desktop' );
// === Do not actually load a banner on a special page
===
// But we keep this after the above initialization
for CentralNotice pages
// that do banner previews.
- if ( mw.config.get( 'wgNamespaceNumber' ) == -1 &&
!mw.centralNotice.isPreviewFrame ) {
+ if ( mw.config.get( 'wgNamespaceNumber' ) == -1 &&
!this.isPreviewFrame ) {
return;
}
// === Create Deferred and Promise Objects ===
- mw.centralNotice.deferredObjs.bannerLoaded =
$.Deferred();
- mw.centralNotice.events.bannerLoaded =
mw.centralNotice.deferredObjs.bannerLoaded.promise();
+ this.deferredObjs.bannerLoaded = $.Deferred();
+ this.events.bannerLoaded =
this.deferredObjs.bannerLoaded.promise();
// === Final prep to loading banner ===
// Add the CentralNotice div so that insert banner has
something to latch on to.
@@ -381,24 +383,24 @@
// If the user has no country assigned, we try a new
lookup via
// geoiplookup.wikimedia.org. This hostname has no IPv6
address,
// so will force dual-stack users to fall back to IPv4.
- if ( mw.centralNotice.data.country === 'XX' ) {
+ if ( this.data.country === 'XX' ) {
$.ajax( {
url: 'foo',
dataType: 'script',
cache: true
} ).always( function () {
if ( window.Geo && window.Geo.country )
{
- mw.centralNotice.data.country =
window.Geo.country;
+ self.data.country =
window.Geo.country;
} else {
- mw.centralNotice.data.country =
'XX';
+ self.data.country = 'XX';
}
// Set a session cookie so that
subsequent page views neither trigger
// an IP lookup in Varnish nor an AJAX
request to geoiplookup.
synthesizeGeoCookie();
- mw.centralNotice.loadBanner();
+ self.loadBanner();
} );
} else {
- mw.centralNotice.loadBanner();
+ this.loadBanner();
}
}
};
@@ -421,13 +423,13 @@
var url, targets, durations, cookieName, cookieVal, deleteOld,
now,
parsedCookie, bucket;
- var impressionData = $.extend( mw.centralNotice.impressionData,
{
- country: mw.centralNotice.data.country,
+ var impressionData = $.extend( this.impressionData, {
+ country: this.data.country,
uselang: mw.config.get( 'wgUserLanguage' ),
project: mw.config.get( 'wgNoticeProject' ),
db: mw.config.get( 'wgDBname' ),
- anonymous: mw.centralNotice.data.anonymous,
- device: mw.centralNotice.data.device
+ anonymous: this.data.anonymous,
+ device: this.data.device
} );
if ( !bannerJson ) {
@@ -444,7 +446,7 @@
// Set bucket info the impression data, unless a banner
is being
// forced via the banner URL param.
- if ( !mw.centralNotice.data.getVars.banner ) {
+ if ( !this.data.getVars.banner ) {
bucket =
mw.cnBannerControllerLib.bucketsByCampaign[impressionData.campaign];
impressionData.bucket = bucket.val;
impressionData.bucketStart = bucket.start;
@@ -452,12 +454,12 @@
}
// Get the banner type for more queryness
- mw.centralNotice.data.category = encodeURIComponent(
bannerJson.category );
+ this.data.category = encodeURIComponent(
bannerJson.category );
// Do some builtin hide cookie things, unless we're
testing.
// TODO: Push this into a mixin.
- if ( impressionData.result !== 'hide' &&
mw.centralNotice.data.testing === false ) {
- cookieName = 'centralnotice_hide_' +
mw.centralNotice.data.category;
+ if ( impressionData.result !== 'hide' &&
this.data.testing === false ) {
+ cookieName = 'centralnotice_hide_' +
this.data.category;
cookieVal = $.cookie( cookieName );
durations = mw.config.get(
'wgNoticeCookieDurations' );
now = new Date().getTime() / 1000;
@@ -485,9 +487,9 @@
if ( impressionData.result === 'show' ) {
// Not hidden yet, inject the banner
- mw.centralNotice.bannerData.bannerName =
bannerJson.bannerName;
+ this.bannerData.bannerName =
bannerJson.bannerName;
$( 'div#centralNotice' )
- .attr( 'class', mw.html.escape( 'cn-' +
mw.centralNotice.data.category ) )
+ .attr( 'class', mw.html.escape( 'cn-' +
this.data.category ) )
.prepend( '<!--googleoff: all-->' +
bannerJson.bannerHtml + '<!--googleon: all-->' );
// Create landing page links if required
@@ -495,8 +497,8 @@
url = new mw.Uri( mw.config.get(
'wgNoticeFundraisingUrl' ) );
if ( ( bannerJson.landingPages !== null
) && bannerJson.landingPages.length ) {
targets = String(
bannerJson.landingPages ).split( ',' );
- if ( $.inArray(
mw.centralNotice.data.country, mw.config.get( 'wgNoticeXXCountries' ) ) !== -1
) {
-
mw.centralNotice.data.country = 'XX';
+ if ( $.inArray(
this.data.country, mw.config.get( 'wgNoticeXXCountries' ) ) !== -1 ) {
+ this.data.country =
'XX';
}
url.extend( {
landing_page:
targets[Math.floor( Math.random() * targets.length )].replace( /^\s+|\s+$/, ''
),
@@ -504,7 +506,7 @@
utm_campaign:
bannerJson.campaign,
utm_source:
bannerJson.bannerName,
language:
mw.config.get( 'wgUserLanguage' ),
- country:
mw.centralNotice.data.country
+ country:
this.data.country
} );
$( '#cn-landingpage-link'
).attr( 'href', url.toString() );
}
@@ -512,8 +514,8 @@
// Query the initial impression state if the
banner callback exists
var bannerShown = true;
- if ( typeof
mw.centralNotice.bannerData.alterImpressionData === 'function' ) {
- bannerShown =
mw.centralNotice.bannerData.alterImpressionData( impressionData );
+ if ( typeof this.bannerData.alterImpressionData
=== 'function' ) {
+ bannerShown =
this.bannerData.alterImpressionData( impressionData );
} else {
impressionData.alterFunctionMissing =
true;
}
@@ -533,10 +535,10 @@
}
}
- if ( !mw.centralNotice.data.testing ) {
- mw.centralNotice.recordImpression( impressionData );
+ if ( !this.data.testing ) {
+ this.recordImpression( impressionData );
}
- mw.centralNotice.deferredObjs.bannerLoaded.resolve(
impressionData );
+ this.deferredObjs.bannerLoaded.resolve( impressionData );
};
// Function for hiding banners when the user clicks the close button
@@ -556,7 +558,7 @@
d.setSeconds( d.getSeconds() + duration );
$.cookie(
- 'centralnotice_hide_' + mw.centralNotice.data.category,
+ 'centralnotice_hide_' + this.data.category,
JSON.stringify( cookieVal ),
{ expires: d, path: '/' }
);
@@ -567,7 +569,7 @@
$.each( mw.config.get( 'wgNoticeHideUrls' ), function( idx,
value ) {
(new Image()).src = value + '?' + $.param( {
'duration': duration,
- 'category': mw.centralNotice.data.category,
+ 'category': this.data.category,
'reason' : 'close'
} );
} );
diff --git a/modules/ext.centralNotice.bannerController/bannerController.lib.js
b/modules/ext.centralNotice.bannerController/bannerController.lib.js
index f019bea..98bf917 100644
--- a/modules/ext.centralNotice.bannerController/bannerController.lib.js
+++ b/modules/ext.centralNotice.bannerController/bannerController.lib.js
@@ -524,8 +524,8 @@
// Optimize for just one banner available for the user
in this
// campaign, by far our most common scenario.
- if ( mw.cnBannerControllerLib.possibleBanners.length
=== 1 ) {
-
mw.cnBannerControllerLib.possibleBanners[0].allocation = 1;
+ if ( this.possibleBanners.length === 1 ) {
+ this.possibleBanners[0].allocation = 1;
return;
}
--
To view, visit https://gerrit.wikimedia.org/r/213988
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1a6d24c5c01d2c62f85b1f48a843a1e29671686f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits