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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
( function ( mw, $ ) {
|
|
|
|
var L;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes log entries
|
2014-02-19 02:27:30 +00:00
|
|
|
* @class mw.mmv.Logger
|
2014-02-07 14:47:00 +00:00
|
|
|
*/
|
|
|
|
function Logger() {}
|
|
|
|
|
|
|
|
L = Logger.prototype;
|
|
|
|
|
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.',
|
|
|
|
'file-description-page': 'User opened the file description page.',
|
|
|
|
'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.',
|
|
|
|
'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.',
|
|
|
|
'history-navigation': 'User navigated with the browser history.'
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs an action
|
|
|
|
* @param {string} action The key representing the action
|
|
|
|
* @param {boolean} skipEventLog True if we don't want the action to be recorded in the event log
|
|
|
|
* @param {Object} substitutions A list of variable subtitutions for parametrized action texts
|
2014-02-28 11:05:29 +00:00
|
|
|
* @returns {jQuery.Promise}
|
2014-02-07 14:47:00 +00:00
|
|
|
*/
|
|
|
|
L.log = function ( action, skipEventLog, substitutions ) {
|
2014-02-11 13:25:39 +00:00
|
|
|
var translatedAction = this.logActions[action] || action;
|
2014-02-07 14:47:00 +00:00
|
|
|
|
|
|
|
if ( $.isPlainObject( substitutions ) ) {
|
|
|
|
$.each( substitutions, function( key, value ) {
|
2014-02-11 13:25:39 +00:00
|
|
|
translatedAction = translatedAction.replace( key, value );
|
2014-02-07 14:47:00 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2014-02-11 13:25:39 +00:00
|
|
|
mw.log( translatedAction );
|
2014-02-07 14:47:00 +00:00
|
|
|
|
|
|
|
if ( mw.eventLog && !skipEventLog ) {
|
2014-02-28 11:05:29 +00:00
|
|
|
return mw.eventLog.logEvent( 'MediaViewer', {
|
2014-02-07 14:47:00 +00:00
|
|
|
version: '1.1',
|
|
|
|
action: action
|
|
|
|
} );
|
|
|
|
}
|
2014-02-28 11:05:29 +00:00
|
|
|
|
|
|
|
return $.Deferred().resolve();
|
2014-02-07 14:47:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mw.mmv.logger = new Logger();
|
|
|
|
}( mediaWiki, jQuery ) );
|