mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-24 00:04:15 +00:00
Use ResourceLoader callback to retrieve hCaptcha config
The old method is returning null, results in error that makes user stuck on the save your chagnes dialog in VE. Bug: T311449 Change-Id: I124093fff4f7e69f7ec76cc6b9994d7939bc80f1
This commit is contained in:
parent
608dda6ab5
commit
2de530d092
|
@ -46,21 +46,19 @@
|
|||
},
|
||||
"ResourceModules": {
|
||||
"ext.confirmEdit.hCaptcha.visualEditor": {
|
||||
"scripts": "ve-confirmedit-hCaptcha/ve.init.mw.HCaptchaSaveErrorHandler.js",
|
||||
"packageFiles": [
|
||||
"ve-confirmedit-hCaptcha/ve.init.mw.HCaptchaSaveErrorHandler.js",
|
||||
{
|
||||
"name": "ve-confirmedit-hCaptcha/config.json",
|
||||
"callback": "MediaWiki\\Extension\\ConfirmEdit\\hCaptcha\\Hooks\\ResourceLoaderHooks::getHCaptchaResourceLoaderConfig"
|
||||
}
|
||||
],
|
||||
"targets": [
|
||||
"desktop",
|
||||
"mobile"
|
||||
]
|
||||
}
|
||||
},
|
||||
"Hooks": {
|
||||
"ResourceLoaderGetConfigVars": "resourceloader"
|
||||
},
|
||||
"HookHandlers": {
|
||||
"resourceloader": {
|
||||
"class": "MediaWiki\\Extension\\ConfirmEdit\\hCaptcha\\Hooks\\ResourceLoaderHooks"
|
||||
}
|
||||
},
|
||||
"attributes": {
|
||||
"VisualEditor": {
|
||||
"PluginModules": [
|
||||
|
|
|
@ -5,25 +5,22 @@ declare( strict_types=1 );
|
|||
namespace MediaWiki\Extension\ConfirmEdit\hCaptcha\Hooks;
|
||||
|
||||
use Config;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook;
|
||||
use MediaWiki\ResourceLoader as RL;
|
||||
|
||||
class ResourceLoaderHooks implements ResourceLoaderGetConfigVarsHook {
|
||||
class ResourceLoaderHooks {
|
||||
/**
|
||||
* Adds extra variables to the global config
|
||||
*
|
||||
* @param array &$vars Global variables object
|
||||
* @param string $skin
|
||||
* Passes config variables to ext.confirmEdit.hCaptcha.visualEditor ResourceLoader module.
|
||||
* @param RL\Context $context
|
||||
* @param Config $config
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void {
|
||||
$hCaptchaConfig = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'hcaptcha' );
|
||||
if ( $hCaptchaConfig->get( 'CaptchaClass' ) === 'MediaWiki\\Extensions\\ConfirmEdit\\hCaptcha\\HCaptcha' ) {
|
||||
$vars['wgConfirmEditConfig'] = [
|
||||
'hCaptchaSiteKey' => $hCaptchaConfig->get( 'HCaptchaSiteKey' ),
|
||||
'hCaptchaScriptURL' => 'https://hcaptcha.com/1/api.js',
|
||||
public static function getHCaptchaResourceLoaderConfig(
|
||||
RL\Context $context,
|
||||
Config $config
|
||||
) {
|
||||
return [
|
||||
'hCaptchaSiteKey' => $config->get( 'HCaptchaSiteKey' ),
|
||||
'hCaptchaScriptURL' => 'https://js.hcaptcha.com/1/api.js',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,11 @@ mw.loader.using( 'ext.visualEditor.targetLoader' ).then( function () {
|
|||
|
||||
ve.init.mw.HCaptchaSaveErrorHandler.static.getReadyPromise = function () {
|
||||
var onLoadFn = 'onHcaptchaLoadCallback' + Date.now(),
|
||||
deferred, config, scriptURL, params;
|
||||
deferred, scriptURL, params;
|
||||
|
||||
if ( !this.readyPromise ) {
|
||||
deferred = $.Deferred();
|
||||
config = mw.config.get( 'wgConfirmEditConfig' );
|
||||
scriptURL = new mw.Uri( config.hCaptchaScriptURL );
|
||||
scriptURL = new mw.Uri( require( './config.json' ).hCaptchaScriptURL );
|
||||
params = { onload: onLoadFn, render: 'explicit' };
|
||||
scriptURL.query = $.extend( scriptURL.query, params );
|
||||
|
||||
|
@ -33,8 +32,7 @@ mw.loader.using( 'ext.visualEditor.targetLoader' ).then( function () {
|
|||
|
||||
ve.init.mw.HCaptchaSaveErrorHandler.static.process = function ( data, target ) {
|
||||
var self = this,
|
||||
config = mw.config.get( 'wgConfirmEditConfig' ),
|
||||
siteKey = config.hCaptchaSiteKey,
|
||||
siteKey = require( './config.json' ).hCaptchaSiteKey,
|
||||
$container = $( '<div>' );
|
||||
|
||||
// Register extra fields
|
||||
|
|
Loading…
Reference in a new issue