Merge "Record virtual image views"

This commit is contained in:
jenkins-bot 2015-03-12 09:04:54 +00:00 committed by Gerrit Code Review
commit 0464c2b9e7
3 changed files with 23 additions and 18 deletions

View file

@ -117,12 +117,12 @@ if ( !isset( $wgMediaViewerImageQueryParameter ) ) {
$wgMediaViewerImageQueryParameter = false;
}
if ( !isset( $wgMediaViewerRecordViewDuration ) ) {
if ( !isset( $wgMediaViewerRecordVirtualViewBeaconURI ) ) {
/**
* If set, record the view duration via a HEAD request.
* @var bool
* If set, records a virtual view via the provided beacon URI.
* @var string|bool
*/
$wgMediaViewerRecordViewDuration = false;
$wgMediaViewerRecordVirtualViewBeaconURI = false;
}
$wgMessagesDirs['MultimediaViewer'] = __DIR__ . '/i18n';

View file

@ -150,7 +150,7 @@ class MultimediaViewerHooks {
$wgMediaViewerDurationLoggingSamplingFactor, $wgMediaViewerDurationLoggingLoggedinSamplingFactor,
$wgMediaViewerAttributionLoggingSamplingFactor, $wgMediaViewerDimensionLoggingSamplingFactor,
$wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing, $wgMediaViewerImageQueryParameter,
$wgMediaViewerRecordViewDuration;
$wgMediaViewerRecordVirtualViewBeaconURI;
$vars['wgMultimediaViewer'] = array(
'infoLink' => self::$infoLink,
@ -164,7 +164,7 @@ class MultimediaViewerHooks {
'attributionSamplingFactor' => $wgMediaViewerAttributionLoggingSamplingFactor,
'dimensionSamplingFactor' => $wgMediaViewerDimensionLoggingSamplingFactor,
'imageQueryParameter' => $wgMediaViewerImageQueryParameter,
'recordViewDuration' => $wgMediaViewerRecordViewDuration,
'recordVirtualViewBeaconURI' => $wgMediaViewerRecordVirtualViewBeaconURI,
'tooltipDelay' => 1000,
);
$vars['wgMediaViewer'] = true;

View file

@ -49,16 +49,16 @@
this.viewDuration = 0;
/**
* The image URL to hit with a HEAD request
* The image URL to record a virtual view for
* @property {string}
*/
this.url = '';
/**
* Should the view duration be recorded through a HEAD request
* @property {boolean}
* If set, URI to send the beacon request to in order to record the virtual view
* @property {string}
*/
this.shouldRecordViewDuration = config ? config.recordViewDuration : false;
this.recordVirtualViewBeaconURI = config ? config.recordVirtualViewBeaconURI : false;
/**
* Browser window
@ -112,14 +112,19 @@
this.stopViewDuration();
if ( this.shouldRecordViewDuration && this.viewDuration > 0 ) {
uri = new mw.Uri( this.url );
uri.extend( { viewDuration: this.viewDuration } );
if ( this.recordVirtualViewBeaconURI ) {
uri = new mw.Uri( this.recordVirtualViewBeaconURI );
uri.extend( { duration: this.viewDuration,
uri: this.url } );
try {
navigator.sendBeacon( uri.toString() );
} catch ( e ) {
$.ajax( {
type: 'HEAD',
url: uri.toString()
} );
}
mw.log( 'Image has been viewed for ', this.viewDuration );
}
@ -131,7 +136,7 @@
/**
* Sets up the view tracking for the current image
* @param {string} url URL of the image to send a HEAD request to
* @param {string} url URL of the image to record a virtual view for
*/
VL.attach = function ( url ) {
var view = this;