Jdlrobson has uploaded a new change for review.

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

Change subject: Hygiene: Generalise EventLogging for main menu
......................................................................

Hygiene: Generalise EventLogging for main menu

Use data attributes for event name.
Move event logging for main menu into MainMenu.js
Add event logging support for collections

Change-Id: I6ac9933d1a164580b2691f60eb9064bba63c3a18
---
M includes/skins/SkinMinerva.php
M includes/skins/SkinMinervaBeta.php
M javascripts/loggingSchemas/init.js
M javascripts/modules/mainMenu/MainMenu.js
4 files changed, 27 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/24/199124/1

diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index ceecb35..1087c97 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',
                                        ),
                                ),
                        );
@@ -426,6 +430,7 @@
                                                'text' => wfMessage( 
'mobile-frontend-home-button' )->escaped(),
                                                'href' => 
Title::newMainPage()->getLocalUrl(),
                                                'class' => MobileUI::iconClass( 
'home', 'before' ),
+                                               'data-event-name' => 'home',
                                        ),
                                ),
                        ),
@@ -438,6 +443,7 @@
                                                                '#/random',
                                                'class' => MobileUI::iconClass( 
'random', 'before' ),
                                                'id' => 'randomButton',
+                                               'data-event-name' => 'random',
                                        ),
                                ),
                        ),
@@ -447,6 +453,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',
@@ -519,12 +526,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',
                                        ),
                                ),
                        );
@@ -542,6 +551,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/includes/skins/SkinMinervaBeta.php 
b/includes/skins/SkinMinervaBeta.php
index 47191c2..9bd6fdc 100644
--- a/includes/skins/SkinMinervaBeta.php
+++ b/includes/skins/SkinMinervaBeta.php
@@ -27,6 +27,7 @@
                                                                'href' => 
SpecialPage::getTitleFor( 'Gather' )->getLocalURL(),
                                                                // FIXME: 
Temporarily watchlist icon
                                                                'class' => 
MobileUI::iconClass( 'watchlist', 'before' ),
+                                                               
'data-event-name' => 'collections',
                                                        ),
                                                ),
                                        ),
diff --git a/javascripts/loggingSchemas/init.js 
b/javascripts/loggingSchemas/init.js
index 11a4d8a..b144260 100644
--- a/javascripts/loggingSchemas/init.js
+++ b/javascripts/loggingSchemas/init.js
@@ -1,24 +1,9 @@
 // Add EventLogging to hamburger menu
 ( function ( M, $ ) {
        var SchemaMobileWebClickTracking = M.require( 
'loggingSchemas/SchemaMobileWebClickTracking' ),
-               context = M.require( 'context' ),
+               skin = M.require( 'skin' ),
                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 +17,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' );
+               skin.getMainMenu().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..622274e 100644
--- a/javascripts/modules/mainMenu/MainMenu.js
+++ b/javascripts/modules/mainMenu/MainMenu.js
@@ -19,7 +19,20 @@
                        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
+                */
+               enableLogging: function ( schema ) {
+                       this.$( 'a' ).each( function () {
+                               var $link = $( this ),
+                                       eventName = $link.data( 'event-name' );
+                               if ( eventName ) {
+                                       schema.hijackLink( $link, eventName );
+                               }
+                       } );
+               },
                /**
                 * @inheritdoc
                 * Remove the nearby menu entry if the browser doesn't support 
geo location

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6ac9933d1a164580b2691f60eb9064bba63c3a18
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

Reply via email to