VE: Convert to SaveErrorHandler

Change-Id: I18386a72146e1179c8656e3c9c01a256ec2096d6
Depends-On: I036ee32847cc3b25a1cc478247cfe54599781098
This commit is contained in:
Ed Sanders 2018-11-29 16:51:27 +00:00
parent 15eba91749
commit 057db3d77a
2 changed files with 23 additions and 15 deletions

View file

@ -72,7 +72,7 @@
"styles": "ext.confirmEdit.editPreview.ipwhitelist.styles.css"
},
"ext.confirmEdit.visualEditor": {
"scripts": "ve-confirmedit/ve.init.ConfirmEdit.init.js"
"scripts": "ve-confirmedit/ve.init.mw.CaptchaSaveErrorHandler.js"
}
},
"VisualEditorPluginModules": [

View file

@ -6,21 +6,28 @@
// API for different things in the UI. At this point we only support the SimpleCaptcha and FancyCaptcha
// which we very intuitively detect by the presence of a "url" property.
mw.libs.ve.targetLoader.addPlugin( function () {
ve.init.mw.saveErrorHandlerRegistry.register( 'confirmEditCaptchas', function ( editApi, target ) {
var $captchaImg, msg, question,
captchaInput, $captchaDiv, $captchaParagraph,
captchaData = editApi.captcha;
if ( !(
captchaData && (
ve.init.mw.CaptchaSaveErrorHandler = function () {};
OO.inheritClass( ve.init.mw.CaptchaSaveErrorHandler, ve.init.mw.SaveErrorHandler );
ve.init.mw.CaptchaSaveErrorHandler.static.name = 'confirmEditCaptchas';
ve.init.mw.CaptchaSaveErrorHandler.static.matchFunction = function ( editApi ) {
var captchaData = editApi.captcha;
return !!( captchaData && (
captchaData.url ||
captchaData.type === 'simple' ||
captchaData.type === 'math' ||
captchaData.type === 'question'
)
) ) {
return false;
}
) );
};
ve.init.mw.CaptchaSaveErrorHandler.static.process = function ( editApi, target ) {
var $captchaImg, msg, question,
captchaInput, $captchaDiv, $captchaParagraph,
captchaData = editApi.captcha;
captchaInput = new OO.ui.TextInputWidget( { classes: [ 've-ui-saveDialog-captchaInput' ] } );
@ -106,7 +113,8 @@ mw.libs.ve.targetLoader.addPlugin( function () {
// Emit event for tracking. TODO: This is a bad design
target.emit( 'saveErrorCaptcha' );
};
ve.init.mw.saveErrorHandlerFactory.register( ve.init.mw.CaptchaSaveErrorHandler );
return true;
} );
} );