From e5de2a541518b6033ea6bfeda1446d4cb7d72192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Tisza?= Date: Fri, 5 Sep 2014 00:45:36 +0000 Subject: [PATCH] Log whether attribution could be presented by MediaViewer Change-Id: Ib4e8fbafa16c86ff902c838cc93b1710a7ca87af Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/858 --- MultimediaViewer.php | 29 +++++++- MultimediaViewerHooks.php | 3 +- .../logging/mmv.logging.AttributionLogger.js | 69 +++++++++++++++++++ resources/mmv/ui/mmv.ui.metadataPanel.js | 2 + 4 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 resources/mmv/logging/mmv.logging.AttributionLogger.js diff --git a/MultimediaViewer.php b/MultimediaViewer.php index e0fbfad64..78e8b93bc 100644 --- a/MultimediaViewer.php +++ b/MultimediaViewer.php @@ -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'; diff --git a/MultimediaViewerHooks.php b/MultimediaViewerHooks.php index 399044d2e..ff4fce512 100644 --- a/MultimediaViewerHooks.php +++ b/MultimediaViewerHooks.php @@ -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; diff --git a/resources/mmv/logging/mmv.logging.AttributionLogger.js b/resources/mmv/logging/mmv.logging.AttributionLogger.js new file mode 100644 index 000000000..45888f1a8 --- /dev/null +++ b/resources/mmv/logging/mmv.logging.AttributionLogger.js @@ -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 . + */ + +( 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 ) ); \ No newline at end of file diff --git a/resources/mmv/ui/mmv.ui.metadataPanel.js b/resources/mmv/ui/mmv.ui.metadataPanel.js index 8541d5f2f..3c01f0347 100644 --- a/resources/mmv/ui/mmv.ui.metadataPanel.js +++ b/resources/mmv/ui/mmv.ui.metadataPanel.js @@ -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 );