2014-02-07 14:47:00 +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-02-07 14:47:00 +00:00
|
|
|
var L;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes log entries
|
2014-09-04 23:00:55 +00:00
|
|
|
* @class mw.mmv.logging.ActionLogger
|
|
|
|
* @extends mw.mmv.logging.Logger
|
2014-05-19 09:24:54 +00:00
|
|
|
* @constructor
|
2014-02-07 14:47:00 +00:00
|
|
|
*/
|
2014-05-19 09:24:54 +00:00
|
|
|
function ActionLogger() {}
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-09-04 23:00:55 +00:00
|
|
|
oo.inheritClass( ActionLogger, mw.mmv.logging.Logger );
|
2014-05-19 09:24:54 +00:00
|
|
|
|
|
|
|
L = ActionLogger.prototype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sampling factor key-value map.
|
|
|
|
*
|
|
|
|
* The map's keys are the action identifiers and the values are the sampling factor for each action type.
|
|
|
|
* There is a "default" key defined providing a default sampling factor for actions that aren't explicitely
|
|
|
|
* set in the map.
|
|
|
|
* @property {Object.<string, number>}
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
L.samplingFactorMap = mw.config.get( 'wgMultimediaViewer' ).actionLoggingSamplingFactorMap;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
L.schema = 'MediaViewer';
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-02-19 02:27:30 +00:00
|
|
|
/**
|
|
|
|
* Possible log actions, and their associated English developer log strings.
|
2014-02-28 10:44:26 +00:00
|
|
|
*
|
|
|
|
* These events are not de-duped. Eg. if the user opens the same site link
|
2014-04-15 16:14:06 +00:00
|
|
|
* in 10 tabs, there will be 10 file-description-page events. If they view the
|
2014-02-28 10:44:26 +00:00
|
|
|
* same image 10 times by hitting the prev/next buttons, there will be 10
|
|
|
|
* image-view events, etc.
|
2014-02-19 02:27:30 +00:00
|
|
|
* @property
|
|
|
|
* @static
|
|
|
|
*/
|
2014-02-07 14:47:00 +00:00
|
|
|
L.logActions = {
|
2014-04-15 16:14:06 +00:00
|
|
|
'thumbnail': 'User clicked on a thumbnail to open Media Viewer.',
|
|
|
|
'enlarge': 'User clicked on an enlarge link to open Media Viewer.',
|
|
|
|
'fullscreen': 'User entered fullscreen mode.',
|
|
|
|
'defullscreen': 'User exited fullscreen mode.',
|
|
|
|
'close': 'User closed Media Viewer.',
|
2014-06-19 01:21:51 +00:00
|
|
|
'view-original-file': 'User clicked on the direct link to the original file',
|
2014-04-15 16:14:06 +00:00
|
|
|
'file-description-page': 'User opened the file description page.',
|
2014-06-18 00:50:42 +00:00
|
|
|
'file-description-page-abovefold': 'User opened the file description page via the above-the-fold button.',
|
2014-04-15 16:14:06 +00:00
|
|
|
'use-this-file-open': 'User opened the dialog to use this file.',
|
|
|
|
'image-view': 'User viewed an image.',
|
|
|
|
'metadata-open': 'User opened the metadata panel.',
|
|
|
|
'metadata-close': 'User closed the metadata panel.',
|
2014-11-25 00:52:15 +00:00
|
|
|
'metadata-scroll-open': 'User opened the metadata panel by scrolling.',
|
|
|
|
'metadata-scroll-close': 'User closed the metadata panel by scrolling.',
|
2014-04-15 16:14:06 +00:00
|
|
|
'next-image': 'User viewed the next image.',
|
|
|
|
'prev-image': 'User viewed the previous image.',
|
|
|
|
'terms-open': 'User opened the usage terms.',
|
|
|
|
'license-page': 'User opened the license page.',
|
|
|
|
'author-page': 'User opened the author page.',
|
|
|
|
'source-page': 'User opened the source page.',
|
|
|
|
'hash-load': 'User loaded the image via a hash on pageload.',
|
2014-06-19 09:15:40 +00:00
|
|
|
'history-navigation': 'User navigated with the browser history.',
|
|
|
|
'optout-loggedin': 'opt-out (via quick link at bottom of metadata panel) by logged-in user',
|
|
|
|
'optout-anon': 'opt-out by anonymous user',
|
|
|
|
'optin-loggedin': 'opt-in (via quick link at bottom of metadata panel) by logged-in user',
|
2014-09-05 12:52:53 +00:00
|
|
|
'optin-anon': 'opt-in by anonymous user',
|
|
|
|
'about-page': 'User opened the about page.',
|
|
|
|
'discuss-page': 'User opened the discuss page.',
|
|
|
|
'help-page': 'User opened the help page.',
|
|
|
|
'location-page': 'User opened the location page.',
|
|
|
|
'uploader-page': 'User opened the uploader page.',
|
|
|
|
'download-select-menu-original': 'User selected the original size in the download dropdown menu.',
|
|
|
|
'download-select-menu-small': 'User selected the small size in the download dropdown menu.',
|
|
|
|
'download-select-menu-medium': 'User selected the medium size in the download dropdown menu.',
|
|
|
|
'download-select-menu-large': 'User selected the large size in the download dropdown menu.',
|
|
|
|
'download': 'User clicked on the button to download a file.',
|
|
|
|
'download-view-in-browser': 'User clicked on the link to view the image in the browser in the download tab.',
|
2015-01-01 02:24:32 +00:00
|
|
|
'right-click-image': 'User right-clicked on the image.',
|
2014-09-05 12:52:53 +00:00
|
|
|
'share-page': 'User opened the link to the current image.',
|
|
|
|
'share-link-copied': 'User copied the share link.',
|
|
|
|
'embed-html-copied': 'User copied the HTML embed code.',
|
|
|
|
'embed-wikitext-copied': 'User copied the wikitext embed code.',
|
|
|
|
'embed-switched-to-html': 'User switched to the HTML embed code.',
|
|
|
|
'embed-switched-to-wikitext': 'User switched to the wikitext embed code.',
|
|
|
|
'embed-select-menu-wikitext-default': 'User switched to the default thumbnail size on wikitext.',
|
|
|
|
'embed-select-menu-wikitext-small': 'User switched to the small thumbnail size on wikitext.',
|
|
|
|
'embed-select-menu-wikitext-medium': 'User switched to the medium thumbnail size on wikitext.',
|
|
|
|
'embed-select-menu-wikitext-large': 'User switched to the large thumbnail size on wikitext.',
|
|
|
|
'embed-select-menu-html-original': 'User switched to the original thumbnail size on html.',
|
|
|
|
'embed-select-menu-html-small': 'User switched to the small thumbnail size on html.',
|
|
|
|
'embed-select-menu-html-medium': 'User switched to the medium thumbnail size on html.',
|
|
|
|
'embed-select-menu-html-large': 'User switched to the large thumbnail size on html.',
|
2014-09-16 20:33:05 +00:00
|
|
|
'use-this-file-close': 'User closed the dialog to use this file.',
|
|
|
|
'download-open': 'User opened the dialog to download this file.',
|
2014-10-23 07:56:48 +00:00
|
|
|
'download-close': 'User closed the dialog to download this file.',
|
|
|
|
'options-open': 'User opened the enable/disable dialog.',
|
2014-10-22 16:20:19 +00:00
|
|
|
'options-close': 'User either canceled an enable/disable action or closed a confirmation window.',
|
|
|
|
'disable-about-link': 'User clicked on the "Learn more" link in the disable window.',
|
2014-11-15 15:32:04 +00:00
|
|
|
'enable-about-link': 'User clicked on the "Learn more" link in the enable window.',
|
|
|
|
'image-unview': 'User stopped looking at the current image.'
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs an action
|
|
|
|
* @param {string} action The key representing the action
|
2014-11-15 15:32:04 +00:00
|
|
|
* @param {boolean} forceEventLog True if we want the action to be logged regardless of the sampling factor
|
2014-02-28 11:05:29 +00:00
|
|
|
* @returns {jQuery.Promise}
|
2014-02-07 14:47:00 +00:00
|
|
|
*/
|
2014-11-15 15:32:04 +00:00
|
|
|
L.log = function ( action, forceEventLog ) {
|
|
|
|
var actionText = this.logActions[action] || action,
|
2014-05-19 09:24:54 +00:00
|
|
|
self = this;
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-11-15 15:32:04 +00:00
|
|
|
mw.log( actionText );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
2014-11-15 15:32:04 +00:00
|
|
|
if ( forceEventLog || self.isInSample( action ) ) {
|
2014-05-19 09:24:54 +00:00
|
|
|
return this.loadDependencies().then( function () {
|
|
|
|
self.eventLog.logEvent( self.schema, {
|
|
|
|
action : action,
|
|
|
|
samplingFactor : self.getActionFactor( action )
|
|
|
|
} );
|
2014-11-15 15:32:04 +00:00
|
|
|
|
|
|
|
return true;
|
2014-02-07 14:47:00 +00:00
|
|
|
} );
|
2014-05-19 09:24:54 +00:00
|
|
|
} else {
|
2014-11-15 15:32:04 +00:00
|
|
|
return $.Deferred().resolve( false );
|
2014-02-07 14:47:00 +00:00
|
|
|
}
|
2014-05-19 09:24:54 +00:00
|
|
|
};
|
2014-02-28 11:05:29 +00:00
|
|
|
|
2014-05-19 09:24:54 +00:00
|
|
|
/**
|
|
|
|
* Returns the sampling factor for a given action
|
|
|
|
* @param {string} action The key representing the action
|
|
|
|
* @returns {number} Sampling factor
|
|
|
|
*/
|
|
|
|
L.getActionFactor = function ( action ) {
|
2014-05-28 22:43:35 +00:00
|
|
|
return this.samplingFactorMap[ action ] || this.samplingFactorMap['default'];
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
2014-05-19 09:24:54 +00:00
|
|
|
/**
|
|
|
|
* Returns whether or not we should measure this request for this action
|
|
|
|
* @param {string} action The key representing the action
|
|
|
|
* @returns {boolean} True if this request needs to be sampled
|
|
|
|
*/
|
|
|
|
L.isInSample = function ( action ) {
|
|
|
|
var factor = this.getActionFactor( action );
|
2014-05-16 18:17:52 +00:00
|
|
|
|
|
|
|
if ( !$.isNumeric( factor ) || factor < 1 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return Math.floor( Math.random() * factor ) === 0;
|
|
|
|
};
|
|
|
|
|
2014-09-04 23:00:55 +00:00
|
|
|
mw.mmv.logging.ActionLogger = ActionLogger;
|
|
|
|
mw.mmv.actionLogger = new ActionLogger();
|
2014-05-19 09:24:54 +00:00
|
|
|
}( mediaWiki, jQuery, OO ) );
|