diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2025-03-27 19:08:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2025-03-27 19:08:27 +0000 |
commit | 93f3bf559d5f6af4a74803343d8a05a86d498a44 (patch) | |
tree | dec3c013a3d6a95a35c136836c7c31496d238681 | |
parent | 27579c38387edfc7d14bb96e53fe4104a46346af (diff) | |
parent | 0e39e70f9d4c0f59d6b8f0ca9c7e0881b748a7e3 (diff) | |
download | mediawikicore-93f3bf559d5f6af4a74803343d8a05a86d498a44.tar.gz mediawikicore-93f3bf559d5f6af4a74803343d8a05a86d498a44.zip |
Merge "editRecovery: Add missing documentation and rename methods"
-rw-r--r-- | resources/src/mediawiki.editRecovery/edit.js | 48 | ||||
-rw-r--r-- | resources/src/mediawiki.editRecovery/postEdit.js | 2 |
2 files changed, 38 insertions, 12 deletions
diff --git a/resources/src/mediawiki.editRecovery/edit.js b/resources/src/mediawiki.editRecovery/edit.js index 9ebe571056da..80eea32a5d4e 100644 --- a/resources/src/mediawiki.editRecovery/edit.js +++ b/resources/src/mediawiki.editRecovery/edit.js @@ -1,8 +1,8 @@ /** * In-progress edit recovery for action=edit + * + * @ignore */ -'use strict'; - const storage = require( './storage.js' ); const LoadNotification = require( './LoadNotification.js' ); @@ -24,7 +24,7 @@ const isOldRevision = $( 'input[name="oldid"]' ).val() > 0; const isConflict = mw.config.get( 'wgEditMessage' ) === 'editconflict'; const useEditRecovery = !isUndo && !isOldRevision && !isConflict; if ( useEditRecovery ) { - mw.hook( 'wikipage.editform' ).add( onLoadHandler ); + mw.hook( 'wikipage.editform' ).add( init ); } else { // Always remove the data-saved flag when editing without Edit Recovery. // It may have been set by a previous editing session (within 5 minutes) that did use ER. @@ -34,8 +34,14 @@ if ( useEditRecovery ) { const windowManager = OO.ui.getWindowManager(); windowManager.addWindows( [ new mw.widgets.AbandonEditDialog() ] ); -function onLoadHandler( $editForm ) { - mw.hook( 'wikipage.editform' ).remove( onLoadHandler ); +/** + * Initialise when the wikipage.editform hook first fires + * + * @ignore + * @param {jQuery} $editForm + */ +function init( $editForm ) { + mw.hook( 'wikipage.editform' ).remove( init ); // Monitor all text-entry inputs for changes/typing. const inputsToMonitorSelector = 'textarea, select, input:not([type="hidden"], [type="submit"])'; @@ -91,7 +97,7 @@ function onLoadHandler( $editForm ) { storage.openDatabase().then( () => { // Check for and delete any expired data for any page, before loading any saved data for the current page. storage.deleteExpiredData().then( () => { - storage.loadData( pageName, section ).then( onLoadData ); + storage.loadData( pageName, section ).then( loadDataSuccess ); } ); } ); @@ -100,7 +106,7 @@ function onLoadHandler( $editForm ) { cancelButton.on( 'click', () => { windowManager.openWindow( 'abandonedit' ).closed.then( ( data ) => { if ( data && data.action === 'discard' ) { - // Note that originalData is used below in onLoadData() but that's always called before this method. + // Note that originalData is used below in loadDataSuccess() but that's always called before this method. // Here we set originalData to null in order to signal to saveFormData() to deleted the stored data. originalData = null; storage.deleteData( pageName, section ).finally( () => { @@ -115,7 +121,13 @@ function onLoadHandler( $editForm ) { } ); } -function onLoadData( pageData ) { +/** + * loadData promise resolved successfully + * + * @ignore + * @param {Object|undefined} pageData Page data, undefined if none found + */ +function loadDataSuccess( pageData ) { if ( wasPosted ) { // If this is a POST request, save the current data (e.g. from a preview). saveFormData(); @@ -133,7 +145,7 @@ function onLoadData( pageData ) { const notification = loadNotification.getNotification(); // On 'restore changes'. loadNotification.getRecoverButton().on( 'click', () => { - loadData( pageData ); + recover( pageData ); notification.close(); // statsv: Track the number of times the edit recovery data is recovered. mw.track( `counter.MediaWiki.edit_recovery.recover.by_wiki.${ wiki }` ); @@ -177,7 +189,13 @@ function onLoadData( pageData ) { mw.hook( 'editRecovery.loadEnd' ).fire( { fieldChangeHandler: fieldChangeHandler } ); } -function loadData( pageData ) { +/** + * Recover specified page data + * + * @ignore + * @param {Object} pageData Page data + */ +function recover( pageData ) { for ( const fieldName in inputFields ) { if ( pageData[ fieldNamePrefix + fieldName ] === undefined ) { return; @@ -202,6 +220,11 @@ function loadData( pageData ) { } } +/** + * Handle an edit form field changing + * + * @ignore + */ function fieldChangeHandler() { clearTimeout( changeDebounceTimer ); changeDebounceTimer = setTimeout( saveFormData, debounceTime ); @@ -236,6 +259,11 @@ function isSameAsOriginal( pageData, ignoreRevIds = false ) { return true; } +/** + * Save the current edit form state in the storage backend + * + * @ignore + */ function saveFormData() { const pageData = getFormData(); if ( ( originalData === null || isSameAsOriginal( pageData ) ) && !wasPosted ) { diff --git a/resources/src/mediawiki.editRecovery/postEdit.js b/resources/src/mediawiki.editRecovery/postEdit.js index cdedce360bf4..d28ad9bfa2c9 100644 --- a/resources/src/mediawiki.editRecovery/postEdit.js +++ b/resources/src/mediawiki.editRecovery/postEdit.js @@ -1,5 +1,3 @@ -'use strict'; - mw.hook( 'postEdit' ).add( () => { // Only continue to delete the data if the data-saved flag hasn't been set in ./edit.js if ( !mw.storage.session.get( 'EditRecovery-data-saved' ) ) { |