Log whether attribution could be presented by MediaViewer

Change-Id: Ib4e8fbafa16c86ff902c838cc93b1710a7ca87af
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/858
This commit is contained in:
Gergő Tisza 2014-09-05 00:45:36 +00:00
parent c4c262bf44
commit e5de2a5415
4 changed files with 100 additions and 3 deletions

View file

@ -35,6 +35,16 @@ if ( !isset( $wgMediaViewerDurationLoggingSamplingFactor ) ) {
$wgMediaViewerDurationLoggingSamplingFactor = false;
}
if ( !isset( $wgMediaViewerAttributionLoggingSamplingFactor ) ) {
/**
* If set, records whether image attribution data was available. A value of 1000 means there will be an
* 1:1000 chance to log the attribution event.
* False if unset.
* @var int|bool
*/
$wgMediaViewerAttributionLoggingSamplingFactor = false;
}
if ( !isset( $wgMediaViewerActionLoggingSamplingFactorMap ) ) {
/**
* If set, records user actions via EventLogging and applies a sampling factor according to the map. A "default" key in the map must be set.
@ -497,6 +507,7 @@ $wgResourceModules += array(
'mediawiki.user',
'mmv.HtmlUtils',
'mmv.logging.ActionLogger',
'mmv.logging.AttributionLogger',
'mmv.ui',
'mmv.ui.progressBar',
'mmv.ui.stripeButtons',
@ -876,7 +887,7 @@ $wgResourceModules += array(
'mmv.base',
'mmv.logging.Logger',
'oojs'
)
),
),
'mmv.logging.DurationLogger' => $wgMediaViewerResourceTemplate + array(
@ -889,7 +900,20 @@ $wgResourceModules += array(
'mmv.logging.Logger',
'oojs',
'mediawiki.user',
)
),
),
'mmv.logging.AttributionLogger' => $wgMediaViewerResourceTemplate + array(
'scripts' => array(
'mmv/logging/mmv.logging.AttributionLogger.js',
),
'dependencies' => array(
'mmv.base',
'mmv.logging.Logger',
'oojs',
'mediawiki.user',
),
),
'mmv.head' => $wgMediaViewerResourceTemplate + array(
@ -925,6 +949,7 @@ $wgExtensionFunctions[] = function () {
$wgEventLoggingSchemas[ 'MediaViewer' ] = 8935662;
$wgEventLoggingSchemas[ 'MultimediaViewerNetworkPerformance' ] = 7917896;
$wgEventLoggingSchemas[ 'MultimediaViewerDuration' ] = 8572641;
$wgEventLoggingSchemas[ 'MultimediaViewerAttribution' ] = 9758179;
$wgResourceModules['mmv.logging.ActionLogger']['dependencies'][] = 'ext.eventLogging';
$wgResourceModules['mmv.logging.Performance']['dependencies'][] = 'ext.eventLogging';

View file

@ -140,7 +140,7 @@ class MultimediaViewerHooks {
*/
public static function resourceLoaderGetConfigVars( &$vars ) {
global $wgAPIPropModules, $wgMediaViewerActionLoggingSamplingFactorMap, $wgNetworkPerformanceSamplingFactor, $wgMediaViewerDurationLoggingSamplingFactor,
$wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing;
$wgMediaViewerAttributionLoggingSamplingFactor, $wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing;
$vars['wgMultimediaViewer'] = array(
'infoLink' => self::$infoLink,
'discussionLink' => self::$discussionLink,
@ -150,6 +150,7 @@ class MultimediaViewerHooks {
'durationSamplingFactor' => $wgMediaViewerDurationLoggingSamplingFactor,
'networkPerformanceSamplingFactor' => $wgNetworkPerformanceSamplingFactor,
'actionLoggingSamplingFactorMap' => $wgMediaViewerActionLoggingSamplingFactorMap,
'attributionSamplingFactor' => $wgMediaViewerAttributionLoggingSamplingFactor,
'tooltipDelay' => 1000,
);
$vars['wgMediaViewer'] = true;

View file

@ -0,0 +1,69 @@
/*
* This file is part of the MediaWiki extension MultimediaViewer.
*
* MultimediaViewer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MultimediaViewer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
*/
( function ( mw, $, oo ) {
var AL;
/**
* Writes EventLogging entries for duration measurements
* @class mw.mmv.logging.AttributionLogger
* @extends mw.mmv.logging.Logger
* @constructor
*/
function AttributionLogger() {
this.starts = {};
}
oo.inheritClass( AttributionLogger, mw.mmv.logging.Logger );
AL = AttributionLogger.prototype;
/**
* @override
* @inheritdoc
*/
AL.samplingFactor = mw.config.get( 'wgMultimediaViewer' ).attributionSamplingFactor;
/**
* @override
* @inheritdoc
*/
AL.schema = 'MultimediaViewerAttribution';
/**
* Logs attribution data
* @param {mw.mmv.model.Image} image Image data
*/
AL.logAttribution = function ( image ) {
var data;
data = {
authorPresent: !!image.author,
sourcePresent: !!image.source,
licensePresent: !!image.license,
loggedIn: !mw.user.isAnon(),
samplingFactor: this.samplingFactor
};
mw.log( 'author: ' + ( data.authorPresent ? 'present' : 'absent' ) +
', source: ' + ( data.sourcePresent ? 'present' : 'absent' ) +
', license: ' + ( data.licensePresent ? 'present' : 'absent' ) );
this.log( data );
};
mw.mmv.attributionLogger = new AttributionLogger();
}( mediaWiki, jQuery, OO ) );

View file

@ -777,6 +777,8 @@
var panel = this,
fileTitle = image.filePageTitle;
mw.mmv.attributionLogger.logAttribution( imageData );
this.setFileTitle( fileTitle.getNameText() );
this.setRepoDisplay( repoData );
this.setFilePageLink( imageData.descriptionUrl );