Ejegg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/148540

Change subject: DO NOT MERGE: Revert banner cookie changes
......................................................................

DO NOT MERGE: Revert banner cookie changes

In case of FUBAR, break glass and pull lever

Change-Id: I580504c0600dbe03e9e84db560d06e185e97a6d6
---
M CentralNotice.hooks.php
M CentralNotice.modules.php
M CentralNotice.php
M modules/ext.centralNotice.bannerController/bannerController.js
M special/SpecialHideBanners.php
5 files changed, 31 insertions(+), 53 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice 
refs/changes/40/148540/1

diff --git a/CentralNotice.hooks.php b/CentralNotice.hooks.php
index ae5843c..649779d 100644
--- a/CentralNotice.hooks.php
+++ b/CentralNotice.hooks.php
@@ -293,7 +293,7 @@
        global $wgNoticeFundraisingUrl, $wgCentralPagePath, $wgContLang, 
$wgNoticeXXCountries,
                   $wgNoticeInfrastructure, $wgNoticeCloseButton, 
$wgCentralBannerDispatcher,
                   $wgCentralBannerRecorder, $wgNoticeNumberOfBuckets, 
$wgNoticeBucketExpiry,
-                  $wgNoticeNumberOfControllerBuckets, 
$wgNoticeCookieDurations, $wgScript,
+                  $wgNoticeNumberOfControllerBuckets, 
$wgNoticeCookieShortExpiry, $wgScript,
                   $wgNoticeHideUrls;
 
        // Making these calls too soon will causes issues with the namespace 
localisation cache. This seems
@@ -327,7 +327,7 @@
        $vars[ 'wgNoticeNumberOfBuckets' ] = $wgNoticeNumberOfBuckets;
        $vars[ 'wgNoticeBucketExpiry' ] = $wgNoticeBucketExpiry;
        $vars[ 'wgNoticeNumberOfControllerBuckets' ] = 
$wgNoticeNumberOfControllerBuckets;
-       $vars[ 'wgNoticeCookieDurations' ] = $wgNoticeCookieDurations;
+       $vars[ 'wgNoticeCookieShortExpiry' ] = $wgNoticeCookieShortExpiry;
        $vars[ 'wgNoticeHideUrls' ] = $wgNoticeHideUrls;
 
        if ( $wgNoticeInfrastructure ) {
diff --git a/CentralNotice.modules.php b/CentralNotice.modules.php
index f87d233..467b590 100644
--- a/CentralNotice.modules.php
+++ b/CentralNotice.modules.php
@@ -121,7 +121,6 @@
        'position'      => 'top',
        'dependencies'  => array(
                'jquery.cookie',
-               'jquery.json',
        ),
 );
 $wgResourceModules[ 'ext.centralNotice.adminUi.campaignManager' ] = array(
diff --git a/CentralNotice.php b/CentralNotice.php
index 3f420ce..3a49495 100644
--- a/CentralNotice.php
+++ b/CentralNotice.php
@@ -111,20 +111,13 @@
 // Example: '.wikipedia.org'
 $wgNoticeCookieDomain = '';
 
-/**
- * @var string[] $wgNoticeCookieDurations How long to respect different types
- * of banner hiding cookies, in seconds. bannerController.js selects one of
- * these entries based on the  cookie's 'reason' element and adds that to the
- * cookie's 'created' element to determine when to stop hiding the banner.
- */
-$wgNoticeCookieDurations = array(
-       // The amount of time banners will be hidden by the close box.
-       // Defaults to two weeks.
-       'close' => 1209600,
-       // Amount of time the banners will hide after a successful donation.
-       // Defaults to one year.
-       'donate' => 31536000
-);
+// The amount of time banners will be hidden by the close box.
+// Defaults to two weeks.
+$wgNoticeCookieShortExpiry = 1209600;
+
+// Amount of time the banners will hide after a successful donation.
+// Defaults to one year.
+$wgNoticeCookieLongExpiry = 31536000;
 
 /**
  * @var string[] $wgNoticeHideUrls Locations of Special:HideBanner targets to 
hit
diff --git a/modules/ext.centralNotice.bannerController/bannerController.js 
b/modules/ext.centralNotice.bannerController/bannerController.js
index 9b4e1b8..68cebef 100644
--- a/modules/ext.centralNotice.bannerController/bannerController.js
+++ b/modules/ext.centralNotice.bannerController/bannerController.js
@@ -273,7 +273,7 @@
        //
        // TODO: Migrate away from global functions
        window.insertBanner = function ( bannerJson ) {
-               var url, targets, expiry, cookieVal;
+               var url, targets;
 
                var impressionData = {
                        country: mw.centralNotice.data.country,
@@ -304,28 +304,21 @@
                                        result: 'hide',
                                        reason: 'preload'
                                };
-                       } else if ( mw.centralNotice.data.testing === false ) { 
/* And we want to see what we're testing! :) */
-                               cookieVal = $.cookie( 'centralnotice_hide_' + 
mw.centralNotice.data.category );
-                               expiry = mw.config.get( 
'wgNoticeCookieDurations' );
-
-                               if (
-                                       cookieVal === 'hide' ||
-                                       (
-                                               cookieVal !== null &&
-                                               cookieVal.indexOf( '{' ) === 0 
&&
-                                               expiry[$.parseJSON( cookieVal 
).reason] &&
-                                               $.parseJSON( cookieVal 
).created + expiry[$.parseJSON( cookieVal ).reason] > new Date().getTime() / 
1000
-                                       )
-                               ) {
-                                       // The banner was hidden by a category 
hide cookie and we're not testing
-                                       impressionResultData = {
-                                               result: 'hide',
-                                               reason: 'cookie'
-                                       };
-                               }
-                       }
-                       if ( !impressionResultData ) {
-                               // Not hidden yet, inject the banner
+                       } else if (
+                               mw.centralNotice.data.testing === false && /* 
And we want to see what we're testing! :) */
+                               (
+                                       $.cookie( 'centralnotice_hide_' + 
mw.centralNotice.data.category ) === 'hide' ||
+                                       /* Legacy for long duration fundraising 
cookies; remove after Oct 1, 2014 */
+                                       $.cookie( 'centralnotice_' + 
mw.centralNotice.data.category ) === 'hide'
+                               )
+                       ) {
+                               // The banner was hidden by a category hide 
cookie and we're not testing
+                               impressionResultData = {
+                                       result: 'hide',
+                                       reason: 'cookie'
+                               };
+                       } else {
+                               // All conditions fulfilled, inject the banner
                                mw.centralNotice.bannerData.bannerName = 
bannerJson.bannerName;
                                $( 'div#centralNotice' )
                                        .attr( 'class', mw.html.escape( 'cn-' + 
mw.centralNotice.data.category ) )
@@ -384,24 +377,19 @@
        };
 
        // Function for hiding banners when the user clicks the close button
+       // TODO: Make it call up to the special page for cross project hiding
        window.hideBanner = function () {
                var d = new Date(),
-                       cookieVal = {
-                               v: 1,
-                               created: Math.floor( d.getTime() / 1000 ),
-                               reason: 'close'
-                       },
-                       expiry = mw.config.get( 'wgNoticeCookieDurations' 
).close;
+                       expiry = mw.config.get( 'wgNoticeCookieShortExpiry' );
 
                // Immediately hide the banner on the page
                $( '#centralNotice' ).hide();
 
                // Set a local hide cookie for this banner category
                d.setSeconds( d.getSeconds() + expiry );
-
                $.cookie(
                        'centralnotice_hide_' + mw.centralNotice.data.category,
-                       $.toJSON( cookieVal ),
+                       'hide',
                        { expires: d, path: '/' }
                );
 
@@ -410,8 +398,7 @@
                $.each( mw.config.get( 'wgNoticeHideUrls' ), function( idx, 
value ) {
                        (new Image()).src = value + '?' + $.param( {
                                'duration': expiry,
-                               'category': mw.centralNotice.data.category,
-                               'reason' : 'close'
+                               'category': mw.centralNotice.data.category
                        } );
                } );
 
diff --git a/special/SpecialHideBanners.php b/special/SpecialHideBanners.php
index e8f2bb1..18e983e 100644
--- a/special/SpecialHideBanners.php
+++ b/special/SpecialHideBanners.php
@@ -14,10 +14,9 @@
        }
 
        function execute( $par ) {
-               global $wgNoticeCookieDurations;
+               global $wgNoticeCookieLongExpiry;
 
-               $reason = 'donate'; //Once bannerController.js is fully 
deployed, get this from the query string
-               $duration = $this->getRequest()->getInt( 'duration', 
$wgNoticeCookieDurations[$reason] );
+               $duration = $this->getRequest()->getInt( 'duration', 
$wgNoticeCookieLongExpiry );
                $category = $this->getRequest()->getText( 'category', 
'fundraising' );
                $category = Banner::sanitizeRenderedCategory( $category );
                $this->setHideCookie( $category, $duration );

-- 
To view, visit https://gerrit.wikimedia.org/r/148540
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I580504c0600dbe03e9e84db560d06e185e97a6d6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to