Spage has uploaded a new change for review.

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


Change subject: First cut at general campaign support
......................................................................

First cut at general campaign support

On any wiki page, ?camp=someValue in the query string triggers logging 
someValue.
If the query parameter is ?camp-s=aValue, then also set a mediaWiki-camp
cookie to aValue.
See 
<https://www.mediawiki.org/wiki/Account_creation_user_experience/Engineering#Campaign_support>
and the schema https://meta.wikimedia.org/wiki/Schema:Campaigns

Change-Id: Id8830715593cd9764cd62f2fa05c392db34f5b79
---
M EventLogging.hooks.php
M EventLogging.php
A modules/ext.eventLogging.campaigns.js
3 files changed, 113 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/EventLogging 
refs/changes/29/63829/1

diff --git a/EventLogging.hooks.php b/EventLogging.hooks.php
index 95fe130..1d25fd1 100644
--- a/EventLogging.hooks.php
+++ b/EventLogging.hooks.php
@@ -107,6 +107,29 @@
        }
 
        /**
+        * Adds a module to the page that detects campaigns.
+        *
+        * @param OutputPage $out output page
+        * @param Skin $skin current skin
+        * @return bool
+        */
+       public static function onBeforePageDisplay( OutputPage $out, Skin $skin 
) {
+               global $wgEventLoggingCampaigns;
+
+               if ( !$wgEventLoggingCampaigns ) {
+                       return true;
+               }
+               // TODO skip if user has pref 'vector-noexperiments' to not 
participate
+               // in experiments.
+               if ( $skin->getRequest()->getVal( 'camp', '' ) !== ''
+                       || $skin->getRequest()->getVal( 'camp-s', '' ) !== ''
+               ) {
+                       $out->addModules( 'ext.eventLogging.campaigns' );
+               }
+               return true;
+       }
+
+       /**
         * @param array &$testModules
         * @param ResourceLoader $resourceLoader
         * @return bool
diff --git a/EventLogging.php b/EventLogging.php
index f269a02..bcf5b37 100644
--- a/EventLogging.php
+++ b/EventLogging.php
@@ -227,6 +227,26 @@
        'mobileTargets' => array( 'alpha', 'beta', 'stable' ),
 );
 
+$wgResourceModules[ 'schema.Campaigns' ] = array(
+       'class'  => 'ResourceLoaderSchemaModule',
+       'schema' => 'Campaigns',
+       'revision' => 5485644,
+);
+
+$wgResourceModules[ 'ext.eventLogging.campaigns' ] = array(
+       'scripts'       => 'modules/ext.eventLogging.campaigns.js',
+       'localBasePath' => __DIR__,
+       'remoteExtPath' => 'EventLogging',
+       'dependencies'  => array(
+               'ext.eventLogging',
+               'mediawiki.user',
+               'jquery.cookie',
+               'schema.Campaigns',
+       ),
+       // probably works on mobile 'targets'       => array( 'desktop', 
'mobile' ),
+       // probably works on mobile 'mobileTargets' => array( 'alpha', 'beta', 
'stable' ),
+);
+
 
 $wgResourceModules[ 'ext.eventLogging.jsonSchema' ] = array(
        'scripts'       => 'modules/ext.eventLogging.jsonSchema.js',
@@ -245,6 +265,7 @@
 $wgHooks[ 'AddNewAccount' ][] = 'EventLoggingHooks::onAddNewAccount';
 $wgHooks[ 'PageContentSaveComplete' ][] = 
'EventLoggingHooks::onPageContentSaveComplete';
 $wgHooks[ 'ResourceLoaderGetConfigVars' ][] = 
'EventLoggingHooks::onResourceLoaderGetConfigVars';
+$wgHooks[ 'BeforePageDisplay' ][] = 'EventLoggingHooks::onBeforePageDisplay';
 $wgHooks[ 'ResourceLoaderTestModules' ][] = 
'EventLoggingHooks::onResourceLoaderTestModules';
 
 // Registers hook and content handlers for JSON schema content iff
diff --git a/modules/ext.eventLogging.campaigns.js 
b/modules/ext.eventLogging.campaigns.js
new file mode 100644
index 0000000..cc6f201
--- /dev/null
+++ b/modules/ext.eventLogging.campaigns.js
@@ -0,0 +1,69 @@
+/**
+ * This module implements campaign support.
+ * client-side JavaScript code. Instances of `ResourceLoaderSchemaModule`
+ * indicate a dependency on this module and declare themselves via its
+ * 'declareSchema' method.
+ *
+ * Developers should not load this module directly, but work with schema
+ * modules instead. Schema modules will load this module as a
+ * dependency.
+ *
+ * @module ext.eventLogging.core.js
+ * @author Ori Livneh <[email protected]>
+ */
+( function ( mw, $, console ) {
+       'use strict';
+
+       var warn,
+               match,
+               campaign,
+               setCookie,
+               logEvt,
+               res,
+               token = null;
+
+       // Same as ext.eventLogging.core.js.
+       warn = console && $.isFunction( console.warn ) ?
+               $.proxy( console.warn, console ) : mw.log,
+
+
+       // Look for ?camp=foo or camp-s=foo. Ignore multiple values, empty 
params, etc.
+       match = /[\?&]camp(-s)?=([^&#]*)/.exec( location.search );
+       if ( ! match ) {
+               warn( 'No campaign in query string, why did server load 
campaign module?' );
+               return;
+       }
+       setCookie = !!match[1];
+       campaign = decodeURI( match[2] );
+       console.log( 'campaign=' + campaign + ', setCookie=' + ( setCookie ? 
'true' : 'false' ) );
+
+       // Log the event.
+
+       logEvt = {
+               campaign:  campaign,
+               token:     token,
+               // XXX Needs work, need consistency with Echo, GettingStarted, 
etc.
+               pageNs:    mw.config.get( 'wgNamespaceNumber' ),
+               pageTitle: mw.config.get( 'wgCanonicalSpecialPageName' )
+                       || mw.config.get( 'wgPageName' ), // XXX? Or 
wgRelevantPageName ?
+               setCookie: setCookie
+       };
+       if ( mw.user.isAnon() ) {
+               logEvt.token = mw.user.sessionId();
+       } else {
+               logEvt.userId = mw.config.get( 'wgUserId' );
+       }
+       res = mw.eventLog.logEvent( 'Campaigns', logEvt );
+
+       // If query string param was camp-s=xx, set the cookie.
+       // As an enhancement and to avoid "Why did WMF set a cookie containing 
hate
+       // speech in my browser", only do this if the event is valid.
+       // TODO (spage, 2013-05-14) logEvent above validated, but there's no 
way to
+       // get the isValid status from logEvent
+       if ( setCookie &&  mw.eventLog.isValid( logEvt, 'Campaigns' ) ) {
+               $.cookie( 'mediaWiki.camp', campaign, { 'expires': null, 
'path': '/' } );
+       }
+
+       // TODO Remove the query string parameter from the browser history 
state.
+
+} ( mediaWiki, jQuery, window.console ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id8830715593cd9764cd62f2fa05c392db34f5b79
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/EventLogging
Gerrit-Branch: master
Gerrit-Owner: Spage <[email protected]>

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

Reply via email to