Merge "Regenerate editingStatsId on unload"

This commit is contained in:
jenkins-bot 2015-04-21 01:06:29 +00:00 committed by Gerrit Code Review
commit 4ca5349725

View file

@ -3,6 +3,8 @@
*/ */
( function ( $, mw ) { ( function ( $, mw ) {
var editingSessionId;
function logEditEvent( action, data ) { function logEditEvent( action, data ) {
if ( mw.loader.getState( 'schema.Edit' ) === null ) { if ( mw.loader.getState( 'schema.Edit' ) === null ) {
return; return;
@ -44,14 +46,14 @@
$( function () { $( function () {
var $textarea = $( '#wpTextbox1' ), var $textarea = $( '#wpTextbox1' ),
editingSessionIdInput = $( '#editingStatsId' ), $editingSessionIdInput = $( '#editingStatsId' ),
editingSessionId, submitting, onUnloadFallback; submitting, onUnloadFallback;
// Initialize wikiEditor // Initialize wikiEditor
$textarea.wikiEditor(); $textarea.wikiEditor();
if ( editingSessionIdInput.length ) { if ( $editingSessionIdInput.length ) {
editingSessionId = editingSessionIdInput.val(); editingSessionId = $editingSessionIdInput.val();
logEditEvent( 'ready', { logEditEvent( 'ready', {
editingSessionId: editingSessionId editingSessionId: editingSessionId
} ); } );
@ -73,6 +75,15 @@
} ); } );
} }
// 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 );
return fallbackResult; return fallbackResult;
}; };
} }