mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-24 07:34:11 +00:00
Add properties that will be logged with each EL request
Bug: T131315 Change-Id: I16f5f8170174200bb20c6bcc2835efd136d752ff
This commit is contained in:
parent
cda1ffe425
commit
ca20031a0e
|
@ -75,6 +75,7 @@ class PopupsHooks {
|
||||||
$schemaPopups += [
|
$schemaPopups += [
|
||||||
'dependencies' => [
|
'dependencies' => [
|
||||||
'schema.Popups',
|
'schema.Popups',
|
||||||
|
'mediawiki.user'
|
||||||
],
|
],
|
||||||
'scripts' => [
|
'scripts' => [
|
||||||
'resources/ext.popups.schemaPopups.js',
|
'resources/ext.popups.schemaPopups.js',
|
||||||
|
|
|
@ -149,6 +149,7 @@
|
||||||
|
|
||||||
mw.popups.render.cache[ href ].settings = {
|
mw.popups.render.cache[ href ].settings = {
|
||||||
title: page.title,
|
title: page.title,
|
||||||
|
namespace: page.ns,
|
||||||
tall: ( tall === undefined ) ? false : tall,
|
tall: ( tall === undefined ) ? false : tall,
|
||||||
thumbnail: ( thumbnail === undefined ) ? false : thumbnail
|
thumbnail: ( thumbnail === undefined ) ? false : thumbnail
|
||||||
};
|
};
|
||||||
|
|
|
@ -187,7 +187,7 @@
|
||||||
// Event logging
|
// Event logging
|
||||||
mw.popups.logData = {
|
mw.popups.logData = {
|
||||||
pageTitleHover: cache.settings.title,
|
pageTitleHover: cache.settings.title,
|
||||||
pageTitleSource: mw.config.get( 'wgTitle' ),
|
namespaceIdHover: cache.settings.namespace,
|
||||||
popupEnabled: mw.popups.enabled,
|
popupEnabled: mw.popups.enabled,
|
||||||
time: mw.now()
|
time: mw.now()
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,15 +1,66 @@
|
||||||
( function ( $, mw ) {
|
( 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',
|
'Popups',
|
||||||
mw.config.get( 'wgPopupsSchemaPopupsSamplingRate', 0 )
|
getSamplingRate(),
|
||||||
|
defaults
|
||||||
);
|
);
|
||||||
|
|
||||||
mw.trackSubscribe( 'ext.popups.schemaPopups', function ( topic, data ) {
|
mw.trackSubscribe( 'ext.popups.schemaPopups', function ( topic, data ) {
|
||||||
schemaPopups.log( data );
|
schemaPopups.log( data );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
} )( jQuery, mediaWiki );
|
} )( jQuery, mediaWiki );
|
||||||
|
|
Loading…
Reference in a new issue