2024-06-07 03:55:13 +00:00
|
|
|
mw.loader.using( 'ext.visualEditor.targetLoader' ).then( () => {
|
|
|
|
mw.libs.ve.targetLoader.addPlugin( () => {
|
2023-10-02 22:42:57 +00:00
|
|
|
|
|
|
|
ve.init.mw.TurnstileSaveErrorHandler = function () {};
|
|
|
|
|
|
|
|
OO.inheritClass( ve.init.mw.TurnstileSaveErrorHandler, ve.init.mw.SaveErrorHandler );
|
|
|
|
|
|
|
|
ve.init.mw.TurnstileSaveErrorHandler.static.name = 'confirmEditTurnstile';
|
|
|
|
|
|
|
|
ve.init.mw.TurnstileSaveErrorHandler.static.getReadyPromise = function () {
|
|
|
|
const onLoadFn = 'onTurnstileLoadCallback' + Date.now();
|
|
|
|
let deferred, config, scriptURL, params;
|
|
|
|
|
|
|
|
if ( !this.readyPromise ) {
|
|
|
|
deferred = $.Deferred();
|
|
|
|
config = mw.config.get( 'wgConfirmEditConfig' );
|
|
|
|
scriptURL = new mw.Uri( config.turnstileScriptURL );
|
|
|
|
params = { onload: onLoadFn, render: 'explicit' };
|
2024-06-20 03:50:29 +00:00
|
|
|
scriptURL.query = Object.assign( scriptURL.query, params );
|
2023-10-02 22:42:57 +00:00
|
|
|
|
|
|
|
this.readyPromise = deferred.promise();
|
|
|
|
window[ onLoadFn ] = deferred.resolve;
|
|
|
|
mw.loader.load( scriptURL.toString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.readyPromise;
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.init.mw.TurnstileSaveErrorHandler.static.matchFunction = function ( data ) {
|
|
|
|
const captchaData = ve.getProp( data, 'visualeditoredit', 'edit', 'captcha' );
|
|
|
|
|
|
|
|
return !!( captchaData && captchaData.type === 'turnstile' );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.init.mw.TurnstileSaveErrorHandler.static.process = function ( data, target ) {
|
|
|
|
const self = this,
|
|
|
|
config = mw.config.get( 'wgConfirmEditConfig' ),
|
|
|
|
siteKey = config.turnstileSiteKey,
|
|
|
|
$container = $( '<div>' );
|
|
|
|
|
|
|
|
// Register extra fields
|
|
|
|
target.saveFields.wpCaptchaWord = function () {
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2024-06-25 01:05:49 +00:00
|
|
|
return $( 'input[ name="cf-turnstile-response" ]' ).val();
|
2023-10-02 22:42:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.getReadyPromise()
|
2024-06-07 03:55:13 +00:00
|
|
|
.then( () => {
|
2023-10-02 22:42:57 +00:00
|
|
|
if ( self.widgetId ) {
|
|
|
|
window.turnstile.reset( self.widgetId );
|
|
|
|
} else {
|
|
|
|
target.saveDialog.showMessage( 'api-save-error', $container, { wrap: false } );
|
|
|
|
self.widgetId = window.turnstile.render( $container[ 0 ], {
|
|
|
|
sitekey: siteKey,
|
|
|
|
callback: function () {
|
|
|
|
target.saveDialog.executeAction( 'save' );
|
|
|
|
},
|
|
|
|
'expired-callback': function () {},
|
|
|
|
'error-callback': function () {}
|
|
|
|
} );
|
|
|
|
|
|
|
|
target.saveDialog.updateSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
target.emit( 'saveErrorCaptcha' );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.init.mw.saveErrorHandlerFactory.register( ve.init.mw.TurnstileSaveErrorHandler );
|
|
|
|
|
|
|
|
} );
|
|
|
|
} );
|