2021-03-25 15:13:51 +00:00
|
|
|
mw.loader.using( 'ext.visualEditor.targetLoader' ).then( function () {
|
|
|
|
mw.libs.ve.targetLoader.addPlugin( function () {
|
|
|
|
ve.init.mw.HCaptchaSaveErrorHandler = function () {};
|
|
|
|
|
|
|
|
OO.inheritClass( ve.init.mw.HCaptchaSaveErrorHandler, ve.init.mw.SaveErrorHandler );
|
|
|
|
|
|
|
|
ve.init.mw.HCaptchaSaveErrorHandler.static.name = 'confirmEditHCaptcha';
|
|
|
|
|
|
|
|
ve.init.mw.HCaptchaSaveErrorHandler.static.getReadyPromise = function () {
|
2023-09-20 08:27:51 +00:00
|
|
|
const onLoadFn = 'onHcaptchaLoadCallback' + Date.now();
|
|
|
|
let deferred, scriptURL, params;
|
2021-03-25 15:13:51 +00:00
|
|
|
|
|
|
|
if ( !this.readyPromise ) {
|
|
|
|
deferred = $.Deferred();
|
2022-12-11 21:28:28 +00:00
|
|
|
scriptURL = new mw.Uri( require( './config.json' ).hCaptchaScriptURL );
|
2021-03-25 15:13:51 +00:00
|
|
|
params = { onload: onLoadFn, render: 'explicit' };
|
|
|
|
scriptURL.query = $.extend( scriptURL.query, params );
|
|
|
|
|
|
|
|
this.readyPromise = deferred.promise();
|
|
|
|
window[ onLoadFn ] = deferred.resolve;
|
|
|
|
mw.loader.load( scriptURL.toString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.readyPromise;
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.init.mw.HCaptchaSaveErrorHandler.static.matchFunction = function ( data ) {
|
2023-09-20 08:27:51 +00:00
|
|
|
const captchaData = ve.getProp( data, 'visualeditoredit', 'edit', 'captcha' );
|
2021-03-25 15:13:51 +00:00
|
|
|
|
|
|
|
return !!( captchaData && captchaData.type === 'hcaptcha' );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.init.mw.HCaptchaSaveErrorHandler.static.process = function ( data, target ) {
|
2023-09-20 08:27:51 +00:00
|
|
|
const self = this,
|
2022-12-11 21:28:28 +00:00
|
|
|
siteKey = require( './config.json' ).hCaptchaSiteKey,
|
2021-03-25 15:13:51 +00:00
|
|
|
$container = $( '<div>' );
|
|
|
|
|
|
|
|
// Register extra fields
|
|
|
|
target.saveFields.wpCaptchaWord = function () {
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
return $( '[name=h-captcha-response]' ).val();
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getReadyPromise()
|
|
|
|
.then( function () {
|
|
|
|
// ProcessDialog's error system isn't great for this yet.
|
|
|
|
target.saveDialog.clearMessage( 'api-save-error' );
|
|
|
|
target.saveDialog.showMessage( 'api-save-error', $container, { wrap: false } );
|
|
|
|
self.widgetId = window.hcaptcha.render( $container[ 0 ], {
|
|
|
|
sitekey: siteKey,
|
|
|
|
callback: function () {
|
|
|
|
target.saveDialog.executeAction( 'save' );
|
|
|
|
},
|
|
|
|
'expired-callback': function () {},
|
|
|
|
'error-callback': function () {}
|
|
|
|
} );
|
|
|
|
target.saveDialog.popPending();
|
|
|
|
target.saveDialog.updateSize();
|
|
|
|
|
|
|
|
target.emit( 'saveErrorCaptcha' );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.init.mw.saveErrorHandlerFactory.register( ve.init.mw.HCaptchaSaveErrorHandler );
|
|
|
|
} );
|
|
|
|
} );
|