wiki.techinc.nl/resources/src/mediawiki.editRecovery/hooks.js
Sam Wilson 613cbaa0b1 Edit Recovery: Add Special:EditRecovery link to personal menu
Add a link to Special:EditRecovery after the 'Contributions' link
in the personal menu. Grey it out if there is no data to show.

Bug: T351781
Change-Id: I0863f4e824cc2dc70d8a5fddea9dbfb2958fd478
2023-12-05 11:15:16 +08:00

28 lines
978 B
JavaScript

'use strict';
mw.hook( 'postEdit' ).add( function () {
const storage = require( './storage.js' );
storage.openDatabase().then( function () {
storage.deleteData( mw.config.get( 'wgPageName' ) );
storage.closeDatabase();
} );
} );
// Hide the link to Special:EditRecovery if there's no data to recovery.
const editRecoveryLink = document.getElementById( 'pt-editrecovery' );
if ( editRecoveryLink ) {
mw.hook( 'wikipage.content' ).add( function () {
const storage = require( './storage.js' );
storage.openDatabase().then( function () {
storage.loadAllData().then( function ( data ) {
if ( data.length === 0 ) {
editRecoveryLink.classList.add( 'mw-editrecovery-no-data' );
editRecoveryLink.title = mw.msg( 'edit-recovery-link-tooltip-no-data' );
} else {
editRecoveryLink.classList.remove( 'mw-editrecovery-no-data' );
editRecoveryLink.title = mw.msg( 'edit-recovery-link-tooltip-with-data', data.length );
}
} );
} );
} );
}