Add properties that will be logged with each EL request

Bug: T131315
Change-Id: I16f5f8170174200bb20c6bcc2835efd136d752ff
This commit is contained in:
Baha 2016-05-16 16:32:11 -04:00 committed by jdlrobson
parent cda1ffe425
commit ca20031a0e
4 changed files with 58 additions and 5 deletions

View file

@ -75,6 +75,7 @@ class PopupsHooks {
$schemaPopups += [
'dependencies' => [
'schema.Popups',
'mediawiki.user'
],
'scripts' => [
'resources/ext.popups.schemaPopups.js',

View file

@ -149,6 +149,7 @@
mw.popups.render.cache[ href ].settings = {
title: page.title,
namespace: page.ns,
tall: ( tall === undefined ) ? false : tall,
thumbnail: ( thumbnail === undefined ) ? false : thumbnail
};

View file

@ -187,7 +187,7 @@
// Event logging
mw.popups.logData = {
pageTitleHover: cache.settings.title,
pageTitleSource: mw.config.get( 'wgTitle' ),
namespaceIdHover: cache.settings.namespace,
popupEnabled: mw.popups.enabled,
time: mw.now()
};

View file

@ -1,15 +1,66 @@
( function ( $, mw ) {
var schemaPopups,
defaults;
/**
* Log the popup event as defined in the schema
* Return the sampling rate for the Schema:Popups
*
* https://meta.wikimedia.org/wiki/Schema:Popups
* The sampling rate is always 0 if the browser doesn't support
* `navigator.sendBeacon`.
*
* @return {number}
*/
var schemaPopups = new mw.eventLog.Schema(
function getSamplingRate() {
return $.isFunction( navigator.sendBeacon ) ?
mw.config.get( 'wgPopupsSchemaPopupsSamplingRate', 0 ) : 0;
}
/**
* Return edit count bucket based on the number of edits
*
* @return {string}
*/
function getEditCountBucket( editCount ) {
var bucket;
if ( editCount === 0 ) {
bucket = '0';
} else if ( editCount >= 1 && editCount <= 4 ) {
bucket = '1-4';
} else if ( editCount >= 5 && editCount <= 99 ) {
bucket = '5-99';
} else if ( editCount >= 100 && editCount <= 999 ) {
bucket = '100-999';
} else if ( editCount >= 1000 ) {
bucket = '1000+';
}
return bucket + ' edits';
}
// Data that will be logged with each EL request
defaults = {
pageTitleSource: mw.config.get( 'wgPageName' ),
namespaceIdSource: mw.config.get( 'wgNamespaceNumber' ),
pageIdSource: mw.config.get( 'wgArticleId' ),
isAnon: mw.user.isAnon()
};
// Include edit count bucket if the user is logged in.
if ( !mw.user.isAnon() ) {
defaults.editCountBucket = getEditCountBucket( mw.config.get( 'wgUserEditCount' ) );
}
// Log the popup event as defined in the schema
// https://meta.wikimedia.org/wiki/Schema:Popups
schemaPopups = new mw.eventLog.Schema(
'Popups',
mw.config.get( 'wgPopupsSchemaPopupsSamplingRate', 0 )
getSamplingRate(),
defaults
);
mw.trackSubscribe( 'ext.popups.schemaPopups', function ( topic, data ) {
schemaPopups.log( data );
} );
} )( jQuery, mediaWiki );