2010-09-15 22:40:50 +00:00
|
|
|
/*
|
|
|
|
* JavaScript for WikiEditor
|
|
|
|
*/
|
2015-03-24 21:14:16 +00:00
|
|
|
|
|
|
|
( function ( $, mw ) {
|
2015-04-19 23:47:37 +00:00
|
|
|
var editingSessionId;
|
|
|
|
|
2015-03-24 21:14:16 +00:00
|
|
|
function logEditEvent( action, data ) {
|
|
|
|
if ( mw.loader.getState( 'schema.Edit' ) === null ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-15 22:53:59 +00:00
|
|
|
mw.loader.using( [ 'schema.Edit', 'ext.eventLogging.subscriber' ] ).done( function () {
|
|
|
|
// Sampling
|
|
|
|
// We have to do this on the client too because the unload handler
|
|
|
|
// can cause an editingSessionId to be generated on the client
|
|
|
|
// Not using mw.eventLog.inSample() because we need to be able to pass our own editingSessionId
|
2018-10-17 05:43:12 +00:00
|
|
|
var inSample = mw.eventLog.randomTokenMatch(
|
|
|
|
1 / mw.config.get( 'wgWMESchemaEditSamplingRate' ),
|
|
|
|
editingSessionId
|
|
|
|
);
|
|
|
|
if ( !inSample && !mw.config.get( 'wgWMESchemaEditOversample' ) ) {
|
2018-10-15 22:53:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-28 21:55:54 +00:00
|
|
|
|
2015-03-24 21:14:16 +00:00
|
|
|
data = $.extend( {
|
|
|
|
version: 1,
|
|
|
|
action: action,
|
2018-10-17 05:43:12 +00:00
|
|
|
isOversample: !inSample,
|
2018-10-15 22:53:59 +00:00
|
|
|
editingSessionId: editingSessionId,
|
2015-03-24 21:14:16 +00:00
|
|
|
editor: 'wikitext',
|
|
|
|
platform: 'desktop', // FIXME
|
|
|
|
integration: 'page',
|
|
|
|
'page.id': mw.config.get( 'wgArticleId' ),
|
|
|
|
'page.title': mw.config.get( 'wgPageName' ),
|
|
|
|
'page.ns': mw.config.get( 'wgNamespaceNumber' ),
|
|
|
|
'page.revid': mw.config.get( 'wgRevisionId' ),
|
|
|
|
'user.id': mw.user.getId(),
|
|
|
|
'user.editCount': mw.config.get( 'wgUserEditCount', 0 ),
|
|
|
|
'mediawiki.version': mw.config.get( 'wgVersion' )
|
|
|
|
}, data );
|
|
|
|
|
|
|
|
if ( mw.user.isAnon() ) {
|
2015-11-15 14:30:18 +00:00
|
|
|
data[ 'user.class' ] = 'IP';
|
2015-03-24 21:14:16 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 14:30:18 +00:00
|
|
|
data[ 'action.' + action + '.type' ] = data.type;
|
|
|
|
data[ 'action.' + action + '.mechanism' ] = data.mechanism;
|
|
|
|
data[ 'action.' + action + '.timing' ] = data.timing === undefined ?
|
2015-03-24 21:14:16 +00:00
|
|
|
0 : Math.floor( data.timing );
|
|
|
|
// Remove renamed properties
|
|
|
|
delete data.type;
|
|
|
|
delete data.mechanism;
|
|
|
|
delete data.timing;
|
|
|
|
|
|
|
|
mw.eventLog.logEvent( 'Edit', data );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
$( function () {
|
|
|
|
var $textarea = $( '#wpTextbox1' ),
|
2015-04-19 23:47:37 +00:00
|
|
|
$editingSessionIdInput = $( '#editingStatsId' ),
|
2015-04-20 01:13:50 +00:00
|
|
|
origText = $textarea.val(),
|
2015-04-19 23:47:37 +00:00
|
|
|
submitting, onUnloadFallback;
|
2015-03-24 21:14:16 +00:00
|
|
|
|
2015-04-19 23:47:37 +00:00
|
|
|
if ( $editingSessionIdInput.length ) {
|
|
|
|
editingSessionId = $editingSessionIdInput.val();
|
2017-12-11 17:46:47 +00:00
|
|
|
if ( window.performance && window.performance.timing ) {
|
|
|
|
// We want to track from the time the user started to try to
|
|
|
|
// launch the editor which navigationStart approximates. All
|
|
|
|
// of our supported browsers *should* allow this. Rather than
|
|
|
|
// fall back to the timestamp when the page loaded for those
|
|
|
|
// that don't, we just ignore them, so as to not skew the
|
|
|
|
// results towards better-performance in those cases.
|
|
|
|
logEditEvent( 'ready', {
|
|
|
|
timing: Date.now() - window.performance.timing.navigationStart
|
2017-12-06 16:31:52 +00:00
|
|
|
} );
|
2017-12-11 17:46:47 +00:00
|
|
|
$textarea.on( 'wikiEditor-toolbar-doneInitialSections', function () {
|
|
|
|
logEditEvent( 'loaded', {
|
|
|
|
timing: Date.now() - window.performance.timing.navigationStart
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}
|
2015-03-24 21:14:16 +00:00
|
|
|
$textarea.closest( 'form' ).submit( function () {
|
|
|
|
submitting = true;
|
|
|
|
} );
|
|
|
|
onUnloadFallback = window.onunload;
|
|
|
|
window.onunload = function () {
|
2015-09-04 19:46:56 +00:00
|
|
|
var fallbackResult, abortType,
|
2015-11-15 14:30:18 +00:00
|
|
|
caVeEdit = $( '#ca-ve-edit' )[ 0 ],
|
2015-04-20 01:13:50 +00:00
|
|
|
switchingToVE = caVeEdit && (
|
|
|
|
document.activeElement === caVeEdit ||
|
|
|
|
$.contains( caVeEdit, document.activeElement )
|
2015-09-04 19:46:56 +00:00
|
|
|
),
|
|
|
|
unmodified = mw.config.get( 'wgAction' ) !== 'submit' && origText === $textarea.val();
|
2015-03-24 21:14:16 +00:00
|
|
|
|
|
|
|
if ( onUnloadFallback ) {
|
|
|
|
fallbackResult = onUnloadFallback();
|
|
|
|
}
|
|
|
|
|
2015-09-04 19:46:56 +00:00
|
|
|
if ( switchingToVE && unmodified ) {
|
|
|
|
abortType = 'switchnochange';
|
|
|
|
} else if ( switchingToVE ) {
|
|
|
|
abortType = 'switchwithout';
|
|
|
|
} else if ( unmodified ) {
|
|
|
|
abortType = 'nochange';
|
|
|
|
} else {
|
|
|
|
abortType = 'abandon';
|
|
|
|
}
|
|
|
|
|
2015-03-24 21:14:16 +00:00
|
|
|
if ( !submitting ) {
|
|
|
|
logEditEvent( 'abort', {
|
2015-09-04 19:46:56 +00:00
|
|
|
type: abortType
|
2015-03-24 21:14:16 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2015-04-19 23:47:37 +00:00
|
|
|
// If/when the user uses the back button to go back to the edit form
|
|
|
|
// and the browser serves this from bfcache, regenerate the session ID
|
|
|
|
// so we don't use the same ID twice. Ideally we'd do this by listening to the pageshow
|
|
|
|
// event and checking e.originalEvent.persisted, but that doesn't work in Chrome:
|
|
|
|
// https://code.google.com/p/chromium/issues/detail?id=344507
|
|
|
|
// So instead we modify the DOM here, after sending the abort event.
|
|
|
|
editingSessionId = mw.user.generateRandomSessionId();
|
|
|
|
$editingSessionIdInput.val( editingSessionId );
|
|
|
|
|
2015-03-24 21:14:16 +00:00
|
|
|
return fallbackResult;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} );
|
2015-04-20 01:13:50 +00:00
|
|
|
}( jQuery, mediaWiki ) );
|