Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/197454
Change subject: Generalise main menu logging
......................................................................
Generalise main menu logging
With collections needing to insert an item in the main menu that
is also getting event logged this seemed like a good time to generalise
how we do this.
Now each link has to specify a data attribute specifying the event name.
Note: This will temporarily disrupt event logging on main menu links (ie.
for anon users viewing cached HTML). I think this is an acceptable since the
data is
not being actively used for any purpose.
Change-Id: Ic6bc1dee164a6f94002f7f2469897cffb22f1d1e
---
M includes/skins/SkinMinerva.php
M javascripts/loggingSchemas/init.js
M javascripts/modules/mainMenu/MainMenu.js
M javascripts/modules/mainMenu/init.js
4 files changed, 24 insertions(+), 25 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/54/197454/1
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 9a53858..05a3577 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -348,6 +348,7 @@
'text' => wfMessage(
'mobile-frontend-main-menu-watchlist' )->escaped(),
'href' =>
$this->getPersonalUrl( $watchTitle, $watchlistQuery ),
'class' => MobileUI::iconClass(
'watchlist', 'before' ),
+ 'data-event-name' =>
'watchlist',
),
),
'class' => 'jsonly'
@@ -361,6 +362,7 @@
'text' => wfMessage(
'mobile-frontend-main-menu-upload' )->escaped(),
'href' =>
$this->getPersonalUrl( $donateTitle ),
'class' =>
MobileUI::iconClass( 'uploads', 'before' ),
+ 'data-event-name' =>
'uploads',
),
),
'class' => 'jsonly',
@@ -373,6 +375,7 @@
'href' =>
SpecialPage::getTitleFor( 'MobileOptions' )->
getLocalUrl( array(
'returnto' => $returnToTitle ) ),
'class' => MobileUI::iconClass(
'settings', 'before' ),
+ 'data-event-name' => 'settings',
),
),
);
@@ -383,6 +386,7 @@
'text' => wfMessage(
'preferences' )->escaped(),
'href' =>
$this->getPersonalUrl( SpecialPage::getTitleFor( 'Preferences' ) ),
'class' => MobileUI::iconClass(
'settings', 'before' ),
+ 'data-event-name' =>
'preferences',
),
),
);
@@ -429,6 +433,7 @@
'text' => wfMessage(
'mobile-frontend-home-button' )->escaped(),
'href' =>
Title::newMainPage()->getLocalUrl(),
'class' => MobileUI::iconClass(
'home', 'before' ),
+ 'data-event-name' => 'home',
),
),
),
@@ -441,6 +446,7 @@
'#/random',
'class' => MobileUI::iconClass(
'random', 'before' ),
'id' => 'randomButton',
+ 'data-event-name' => 'random',
),
),
),
@@ -450,6 +456,7 @@
'text' => wfMessage(
'mobile-frontend-main-menu-nearby' )->escaped(),
'href' =>
SpecialPage::getTitleFor( 'Nearby' )->getLocalURL(),
'class' => MobileUI::iconClass(
'nearby', 'before', 'nearby' ),
+ 'data-event-name' => 'nearby',
),
),
'class' => 'jsonly',
@@ -522,12 +529,14 @@
'text' => $username,
'href' =>
SpecialPage::getTitleFor( 'UserProfile', $username )->getLocalUrl(),
'class' => MobileUI::iconClass(
'profile', 'before', 'truncated-text' ),
+ 'data-event-name' => 'profile',
),
array(
'text' => wfMessage(
'mobile-frontend-main-menu-logout' )->escaped(),
'href' => $url,
'class' => MobileUI::iconClass(
'secondary-logout',
'element', 'icon-24px icon-secondary truncated-text' ),
+ 'data-event-name' => 'logout',
),
),
);
@@ -545,6 +554,7 @@
'text' => wfMessage(
'mobile-frontend-main-menu-login' )->escaped(),
'href' => $url,
'class' => MobileUI::iconClass(
'anonymous-white', 'before', 'icon-anon' ),
+ 'data-event-name' => 'login',
),
),
'class' => 'jsonly'
diff --git a/javascripts/loggingSchemas/init.js
b/javascripts/loggingSchemas/init.js
index 11a4d8a..b179a2c 100644
--- a/javascripts/loggingSchemas/init.js
+++ b/javascripts/loggingSchemas/init.js
@@ -2,23 +2,9 @@
( function ( M, $ ) {
var SchemaMobileWebClickTracking = M.require(
'loggingSchemas/SchemaMobileWebClickTracking' ),
context = M.require( 'context' ),
+ mainMenu = M.require( 'mainMenu' ),
mainMenuSchema = new SchemaMobileWebClickTracking( {},
'MobileWebMainMenuClickTracking' ),
uiSchema = new SchemaMobileWebClickTracking( {},
'MobileWebUIClickTracking' );
-
- /**
- * Get the icon selector for the given main menu element (depending on
alpha/stable mode)
- * @ignore
- * @param {String} name Name of the main menu element
- * @return {String} Complete selector
- */
- function mainMenuIconSelector( name ) {
- // FIXME: Remove when mw-ui-icon is in stable
- if ( !context.isAlphaGroupMember() ) {
- return '#mw-mf-page-left .icon-' + name;
- } else {
- return '#mw-mf-page-left .mw-ui-icon-' + name;
- }
- }
$( function () {
var $profileLink = $( '#mw-mf-last-modified a' )
@@ -32,15 +18,7 @@
} );
} );
- mainMenuSchema.hijackLink( '.icon-home', 'home' );
- mainMenuSchema.hijackLink( mainMenuIconSelector( 'random' ),
'random' );
- mainMenuSchema.hijackLink( mainMenuIconSelector( 'nearby' ),
'nearby' );
- mainMenuSchema.hijackLink( mainMenuIconSelector( 'watchlist' ),
'watchlist' );
- mainMenuSchema.hijackLink( mainMenuIconSelector( 'settings' ),
'settings' );
- mainMenuSchema.hijackLink( mainMenuIconSelector( 'uploads' ),
'uploads' );
- mainMenuSchema.hijackLink( mainMenuIconSelector( 'profile' ),
'profile' );
- mainMenuSchema.hijackLink( mainMenuIconSelector( 'anon' ),
'login' );
- mainMenuSchema.hijackLink( mainMenuIconSelector(
'secondary-logout' ), 'logout' );
+ mainMenu.enableLogging( mainMenuSchema );
uiSchema.hijackLink( $( '#mw-mf-last-modified a span'
).parent(), 'lastmodified-history' );
uiSchema.hijackLink( $profileLink, 'lastmodified-profile' );
uiSchema.hijackLink( '.nearby-button', 'nearby-button' );
diff --git a/javascripts/modules/mainMenu/MainMenu.js
b/javascripts/modules/mainMenu/MainMenu.js
index 57a93e9..937a7cd 100644
--- a/javascripts/modules/mainMenu/MainMenu.js
+++ b/javascripts/modules/mainMenu/MainMenu.js
@@ -19,7 +19,17 @@
el: '#mw-mf-page-left',
mainMenuButton: '#mw-mf-main-menu-button'
},
-
+ /**
+ * Turn on event logging on the existing main menu by reading
`event-name` data
+ * attributes on elements.
+ * @param {SchemaMobileWebClickTracking} schema to use
+ */
+ enableLogger: function ( schema ) {
+ this.$( 'a' ).each( function () {
+ var $link = $( this );
+ schema.hijackLink( $link )
+ } );
+ },
/**
* @inheritdoc
* Remove the nearby menu entry if the browser doesn't support
geo location
diff --git a/javascripts/modules/mainMenu/init.js
b/javascripts/modules/mainMenu/init.js
index 692f2c8..d9eec0f 100644
--- a/javascripts/modules/mainMenu/init.js
+++ b/javascripts/modules/mainMenu/init.js
@@ -21,5 +21,6 @@
} );
}
} );
+ M.define( 'mainMenu', mainMenu );
}( mw.mobileFrontend, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/197454
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic6bc1dee164a6f94002f7f2469897cffb22f1d1e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits