2014-04-28 16:11:55 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2014-05-19 09:24:54 +00:00
|
|
|
( function ( mw, $, oo ) {
|
2014-04-28 16:11:55 +00:00
|
|
|
var L;
|
|
|
|
|
|
|
|
/**
|
2014-05-19 09:24:54 +00:00
|
|
|
* Writes EventLogging entries for duration measurements
|
2014-04-28 16:11:55 +00:00
|
|
|
* @class mw.mmv.DurationLogger
|
2014-05-19 09:24:54 +00:00
|
|
|
* @extends mw.mmv.Logger
|
2014-05-05 07:52:34 +00:00
|
|
|
* @constructor
|
2014-04-28 16:11:55 +00:00
|
|
|
*/
|
|
|
|
function DurationLogger() {
|
|
|
|
this.starts = {};
|
|
|
|
}
|
|
|
|
|
2014-05-19 09:24:54 +00:00
|
|
|
oo.inheritClass( DurationLogger, mw.mmv.Logger );
|
|
|
|
|
2014-04-28 16:11:55 +00:00
|
|
|
L = DurationLogger.prototype;
|
|
|
|
|
2014-05-05 07:52:34 +00:00
|
|
|
/**
|
2014-05-19 09:24:54 +00:00
|
|
|
* @override
|
|
|
|
* @inheritdoc
|
2014-05-05 07:52:34 +00:00
|
|
|
*/
|
2014-05-19 09:24:54 +00:00
|
|
|
L.samplingFactor = mw.config.get( 'wgMultimediaViewer' ).durationSamplingFactor;
|
2014-05-05 07:52:34 +00:00
|
|
|
|
|
|
|
/**
|
2014-05-19 09:24:54 +00:00
|
|
|
* @override
|
|
|
|
* @inheritdoc
|
2014-05-05 07:52:34 +00:00
|
|
|
*/
|
2014-05-19 09:24:54 +00:00
|
|
|
L.schema = 'MultimediaViewerDuration';
|
2014-05-05 07:52:34 +00:00
|
|
|
|
2014-04-28 16:11:55 +00:00
|
|
|
/**
|
|
|
|
* Saves the start of a duration
|
|
|
|
* @param {string|string[]} type_or_types Type(s) of duration being measured.
|
|
|
|
*/
|
|
|
|
L.start = function ( typeOrTypes ) {
|
|
|
|
var i,
|
|
|
|
start = $.now();
|
|
|
|
|
2014-05-05 07:52:34 +00:00
|
|
|
if ( !typeOrTypes ) {
|
|
|
|
throw 'Must specify type';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !$.isArray( typeOrTypes ) ) {
|
|
|
|
typeOrTypes = [ typeOrTypes ];
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0; i < typeOrTypes.length; i++ ) {
|
|
|
|
// Don't overwrite an existing value
|
|
|
|
if ( !this.starts.hasOwnProperty( typeOrTypes[ i ] ) ) {
|
|
|
|
this.starts[ typeOrTypes[ i ] ] = start;
|
2014-04-28 16:11:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs a duration if a start was recorded first
|
|
|
|
* @param {string} type Type of duration being measured.
|
2014-05-19 09:24:54 +00:00
|
|
|
* @param {number} start Start timestamp that to substitute the one coming from start()
|
2014-04-28 16:11:55 +00:00
|
|
|
*/
|
2014-05-19 09:24:54 +00:00
|
|
|
L.stop = function ( type, start ) {
|
|
|
|
var e, duration, message, startTimestamp;
|
2014-05-05 07:52:34 +00:00
|
|
|
|
|
|
|
if ( !type ) {
|
|
|
|
throw 'Must specify type';
|
|
|
|
}
|
2014-04-28 16:11:55 +00:00
|
|
|
|
2014-05-19 09:24:54 +00:00
|
|
|
startTimestamp = this.starts.hasOwnProperty( type ) ? this.starts[ type ] : start;
|
|
|
|
|
|
|
|
if ( startTimestamp !== undefined ) {
|
|
|
|
duration = $.now() - startTimestamp;
|
2014-04-28 16:11:55 +00:00
|
|
|
|
|
|
|
e = {
|
|
|
|
type : type,
|
|
|
|
duration : duration,
|
2014-05-19 09:24:54 +00:00
|
|
|
loggedIn : !mw.user.isAnon(),
|
|
|
|
samplingFactor : this.samplingFactor
|
2014-04-28 16:11:55 +00:00
|
|
|
};
|
|
|
|
|
2014-05-05 07:52:34 +00:00
|
|
|
message = type + ': ' + duration + 'ms';
|
2014-04-28 16:11:55 +00:00
|
|
|
|
2014-05-19 09:24:54 +00:00
|
|
|
mw.log( message );
|
2014-04-28 16:11:55 +00:00
|
|
|
|
2014-05-19 09:24:54 +00:00
|
|
|
this.log( e );
|
2014-04-28 16:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.starts.hasOwnProperty( type ) ) {
|
|
|
|
delete this.starts[ type ];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-05 07:52:34 +00:00
|
|
|
mw.mmv.durationLogger = new DurationLogger();
|
2014-05-19 09:24:54 +00:00
|
|
|
}( mediaWiki, jQuery, OO ) );
|