2024-06-07 03:55:13 +00:00
|
|
|
mw.loader.using( 'ext.visualEditor.targetLoader' ).then( () => {
|
|
|
|
mw.libs.ve.targetLoader.addPlugin( () => {
|
2018-12-07 20:44:46 +00:00
|
|
|
|
2020-06-30 15:26:12 +00:00
|
|
|
ve.init.mw.NoCaptchaReCaptchaSaveErrorHandler = function () {};
|
2018-12-07 20:44:46 +00:00
|
|
|
|
2020-06-30 15:26:12 +00:00
|
|
|
OO.inheritClass( ve.init.mw.NoCaptchaReCaptchaSaveErrorHandler, ve.init.mw.SaveErrorHandler );
|
2018-12-07 20:44:46 +00:00
|
|
|
|
2020-06-30 15:26:12 +00:00
|
|
|
ve.init.mw.NoCaptchaReCaptchaSaveErrorHandler.static.name = 'confirmEditNoCaptchaReCaptcha';
|
2018-12-07 20:44:46 +00:00
|
|
|
|
2020-06-30 15:26:12 +00:00
|
|
|
ve.init.mw.NoCaptchaReCaptchaSaveErrorHandler.static.getReadyPromise = function () {
|
2023-09-20 08:27:51 +00:00
|
|
|
const onLoadFn = 'onRecaptchaLoadCallback' + Date.now();
|
|
|
|
let deferred, config, scriptURL, params;
|
2018-12-07 20:44:46 +00:00
|
|
|
|
2020-06-30 15:26:12 +00:00
|
|
|
if ( !this.readyPromise ) {
|
|
|
|
deferred = $.Deferred();
|
|
|
|
config = mw.config.get( 'wgConfirmEditConfig' );
|
|
|
|
scriptURL = new mw.Uri( config.reCaptchaScriptURL );
|
|
|
|
params = { onload: onLoadFn, render: 'explicit' };
|
2024-06-20 03:50:29 +00:00
|
|
|
scriptURL.query = Object.assign( scriptURL.query, params );
|
2018-12-07 20:44:46 +00:00
|
|
|
|
2020-06-30 15:26:12 +00:00
|
|
|
this.readyPromise = deferred.promise();
|
|
|
|
window[ onLoadFn ] = deferred.resolve;
|
|
|
|
mw.loader.load( scriptURL.toString() );
|
|
|
|
}
|
2018-12-07 20:44:46 +00:00
|
|
|
|
2020-06-30 15:26:12 +00:00
|
|
|
return this.readyPromise;
|
|
|
|
};
|
2018-12-07 20:44:46 +00:00
|
|
|
|
2020-06-30 15:26:12 +00:00
|
|
|
ve.init.mw.NoCaptchaReCaptchaSaveErrorHandler.static.matchFunction = function ( data ) {
|
2023-09-20 08:27:51 +00:00
|
|
|
const captchaData = ve.getProp( data, 'visualeditoredit', 'edit', 'captcha' );
|
2018-12-07 20:44:46 +00:00
|
|
|
|
2020-06-30 15:26:12 +00:00
|
|
|
return !!( captchaData && captchaData.type === 'recaptchanocaptcha' );
|
|
|
|
};
|
2018-12-07 20:44:46 +00:00
|
|
|
|
2020-06-30 15:26:12 +00:00
|
|
|
ve.init.mw.NoCaptchaReCaptchaSaveErrorHandler.static.process = function ( data, target ) {
|
2023-09-20 08:27:51 +00:00
|
|
|
const self = this,
|
2020-06-30 15:26:12 +00:00
|
|
|
config = mw.config.get( 'wgConfirmEditConfig' ),
|
|
|
|
siteKey = config.reCaptchaSiteKey,
|
|
|
|
$container = $( '<div>' );
|
|
|
|
|
|
|
|
// Register extra fields
|
|
|
|
target.saveFields.wpCaptchaWord = function () {
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
return $( '#g-recaptcha-response' ).val();
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getReadyPromise()
|
2024-06-07 03:55:13 +00:00
|
|
|
.then( () => {
|
2020-06-30 15:26:12 +00:00
|
|
|
if ( self.widgetId ) {
|
|
|
|
window.grecaptcha.reset( self.widgetId );
|
|
|
|
} else {
|
|
|
|
target.saveDialog.showMessage( 'api-save-error', $container, { wrap: false } );
|
|
|
|
self.widgetId = window.grecaptcha.render( $container[ 0 ], {
|
|
|
|
sitekey: siteKey,
|
|
|
|
callback: function () {
|
|
|
|
target.saveDialog.executeAction( 'save' );
|
|
|
|
},
|
|
|
|
'expired-callback': function () {},
|
|
|
|
'error-callback': function () {}
|
|
|
|
} );
|
|
|
|
|
|
|
|
target.saveDialog.updateSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
target.emit( 'saveErrorCaptcha' );
|
|
|
|
} );
|
2018-12-07 20:44:46 +00:00
|
|
|
};
|
|
|
|
|
2020-06-30 15:26:12 +00:00
|
|
|
ve.init.mw.saveErrorHandlerFactory.register( ve.init.mw.NoCaptchaReCaptchaSaveErrorHandler );
|
2018-12-07 20:44:46 +00:00
|
|
|
|
2020-06-30 15:26:12 +00:00
|
|
|
} );
|
2018-12-07 20:44:46 +00:00
|
|
|
} );
|