/** * Defines and installs the hCaptcha error handler plugin for VisualEditor. * This code will only handle displaying hCaptcha if VisualEditor tries to * make an edit and that edit fails due to requiring hCaptcha. * * Returns a callback that should be executed in initPlugins.js after `ve.init.mw.HCaptcha` * is loaded */ module.exports = () => { // Load these here so that in QUnit tests we have a chance to mock utils.js ve.init.mw.HCaptchaSaveErrorHandler = function () {}; OO.inheritClass( ve.init.mw.HCaptchaSaveErrorHandler, ve.init.mw.SaveErrorHandler ); OO.inheritClass( ve.init.mw.HCaptchaSaveErrorHandler, ve.init.mw.HCaptcha ); ve.init.mw.HCaptchaSaveErrorHandler.static.name = 'confirmEditHCaptcha'; ve.init.mw.HCaptchaSaveErrorHandler.static.matchFunction = function ( data ) { const captchaData = ve.getProp( data, 'visualeditoredit', 'edit', 'captcha' ); return !!( captchaData && captchaData.type === 'hcaptcha' ); }; ve.init.mw.HCaptchaSaveErrorHandler.static.process = function ( data, target ) { const self = this, siteKey = mw.config.get( 'wgConfirmEditHCaptchaSiteKey' ), $container = $( '