Namespace captchas

Change-Id: I2933639f9cb50db2101c4765ce9d8f9069d253b8
This commit is contained in:
Reedy 2022-04-08 17:53:12 +01:00
parent 735ad9c19c
commit a0feac27b0
21 changed files with 134 additions and 28 deletions

View file

@ -9,7 +9,7 @@
"license-name": "GPL-2.0-or-later",
"type": "antispam",
"APIModules": {
"fancycaptchareload": "ApiFancyCaptchaReload"
"fancycaptchareload": "MediaWiki\\Extension\\ConfirmEdit\\FancyCaptcha\\ApiFancyCaptchaReload"
},
"MessagesDirs": {
"FancyCaptcha": [
@ -19,8 +19,10 @@
},
"AutoloadClasses": {
"FancyCaptcha": "includes/FancyCaptcha.php",
"HTMLFancyCaptchaField": "includes/HTMLFancyCaptchaField.php",
"ApiFancyCaptchaReload": "includes/ApiFancyCaptchaReload.php"
"MediaWiki\\Extension\\ConfirmEdit\\FancyCaptcha\\FancyCaptcha": "includes/FancyCaptcha.php"
},
"AutoloadNamespaces": {
"MediaWiki\\Extension\\ConfirmEdit\\FancyCaptcha\\": "includes/"
},
"ResourceModules": {
"ext.confirmEdit.fancyCaptcha.styles": {
@ -54,7 +56,7 @@
"callback": "MediaWiki\\Extension\\ConfirmEdit\\Hooks::onFancyCaptchaSetup",
"config": {
"CaptchaClass": {
"value": "FancyCaptcha"
"value": "MediaWiki\\Extension\\ConfirmEdit\\FancyCaptcha"
},
"CaptchaFileBackend": {
"value": ""

View file

@ -1,4 +1,9 @@
<?php
namespace MediaWiki\Extension\ConfirmEdit\FancyCaptcha;
use ApiBase;
/**
* Api module to reload FancyCaptcha
*

View file

@ -1,10 +1,23 @@
<?php
namespace MediaWiki\Extension\ConfirmEdit\FancyCaptcha;
use Exception;
use FileBackend;
use FSFileBackend;
use Html;
use MediaWiki\Auth\AuthenticationRequest;
use MediaWiki\Auth\AuthManager;
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
use MediaWiki\MediaWikiServices;
use MWTimestamp;
use NullLockManager;
use ObjectCache;
use SpecialPage;
use StatusValue;
use UnderflowException;
use WikiMap;
/**
* FancyCaptcha for displaying captchas precomputed by captcha.py
@ -498,3 +511,5 @@ class FancyCaptcha extends SimpleCaptcha {
] + $formDescriptor['captchaWord'];
}
}
class_alias( FancyCaptcha::class, 'FancyCaptcha' );

View file

@ -1,5 +1,10 @@
<?php
namespace MediaWiki\Extension\ConfirmEdit\FancyCaptcha;
use Html;
use HTMLFormField;
/**
* Captcha input field for FancyCaptcha that displays a question and returns the answer.
* Does not include the captcha ID; that must be included in the form as a separate hidden field.

View file

@ -18,11 +18,15 @@
]
},
"AutoloadClasses": {
"MathCaptcha": "includes/MathCaptcha.php"
"MathCaptcha": "includes/MathCaptcha.php",
"MediaWiki\\Extension\\ConfirmEdit\\MathCaptcha\\MathCaptcha": "includes/MathCaptcha.php"
},
"AutoloadNamespaces": {
"MediaWiki\\Extension\\ConfirmEdit\\MathCaptcha\\": "includes/"
},
"config": {
"CaptchaClass": {
"value": "MathCaptcha"
"value": "MediaWiki\\Extension\\ConfirmEdit\\MathCaptcha\\MathCaptcha"
}
},
"manifest_version": 2

View file

@ -1,5 +1,8 @@
<?php
namespace MediaWiki\Extension\ConfirmEdit\MathCaptcha;
use Html;
use MediaWiki\Auth\AuthenticationRequest;
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
@ -122,3 +125,5 @@ class MathCaptcha extends SimpleCaptcha {
$formDescriptor['captchaWord']['label-message'] = null;
}
}
class_alias( MathCaptcha::class, 'MathCaptcha' );

View file

@ -13,11 +13,15 @@
]
},
"AutoloadClasses": {
"QuestyCaptcha": "includes/QuestyCaptcha.php"
"QuestyCaptcha": "includes/QuestyCaptcha.php",
"MediaWiki\\Extension\\ConfirmEdit\\QuestyCaptcha\\QuestyCaptcha": "includes/QuestyCaptcha.php"
},
"AutoloadNamespaces": {
"MediaWiki\\Extension\\ConfirmEdit\\QuestyCaptcha\\": "includes/"
},
"config": {
"CaptchaClass": {
"value": "QuestyCaptcha"
"value": "MediaWiki\\Extension\\ConfirmEdit\\QuestyCaptcha\\QuestyCaptcha"
},
"CaptchaQuestions": {
"value": []

View file

@ -8,10 +8,14 @@
* @ingroup Extensions
*/
namespace MediaWiki\Extension\ConfirmEdit\QuestyCaptcha;
use Html;
use MediaWiki\Auth\AuthenticationRequest;
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
use MediaWiki\Extension\ConfirmEdit\Store\CaptchaStore;
use Xml;
class QuestyCaptcha extends SimpleCaptcha {
// used for questycaptcha-edit, questycaptcha-addurl, questycaptcha-badlogin,
@ -140,3 +144,5 @@ class QuestyCaptcha extends SimpleCaptcha {
$formDescriptor['captchaWord']['label-message'] = null;
}
}
class_alias( QuestyCaptcha::class, 'QuestyCaptcha' );

View file

@ -13,15 +13,12 @@
"i18n/api"
]
},
"AutoloadClasses": {
"ReCaptchaNoCaptcha": "includes/ReCaptchaNoCaptcha.php",
"ReCaptchaNoCaptchaHooks": "includes/ReCaptchaNoCaptchaHooks.php",
"HTMLReCaptchaNoCaptchaField": "includes/HTMLReCaptchaNoCaptchaField.php",
"ReCaptchaNoCaptchaAuthenticationRequest": "includes/ReCaptchaNoCaptchaAuthenticationRequest.php"
"AutoloadNamespaces": {
"MediaWiki\\Extension\\ConfirmEdit\\ReCaptchaNoCaptcha\\": "includes/ReCaptchaNoCaptcha.php"
},
"config": {
"CaptchaClass": {
"value": "ReCaptchaNoCaptcha"
"value": "MediaWiki\\Extension\\ConfirmEdit\\ReCaptchaNoCaptcha\\ReCaptchaNoCaptcha"
},
"ReCaptchaSiteKey": {
"value": ""
@ -47,7 +44,7 @@
}
},
"Hooks": {
"ResourceLoaderGetConfigVars": "ReCaptchaNoCaptchaHooks::onResourceLoaderGetConfigVars"
"ResourceLoaderGetConfigVars": "MediaWiki\\Extension\\ConfirmEdit\\ReCaptchaNoCaptcha\\Hooks::onResourceLoaderGetConfigVars"
},
"attributes": {
"VisualEditor": {

View file

@ -1,5 +1,10 @@
<?php
namespace MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha;
use Html;
use HTMLFormField;
/**
* Creates a ReCaptcha v2 widget. Does not return any data; handling the data submitted by the
* widget is callers' responsibility.

View file

@ -1,6 +1,8 @@
<?php
class ReCaptchaNoCaptchaHooks {
namespace MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha;
class Hooks {
/**
* Adds extra variables to the global config
*

View file

@ -1,10 +1,19 @@
<?php
namespace MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha;
use ApiBase;
use FormatJson;
use Html;
use MediaWiki\Auth\AuthenticationRequest;
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
use MediaWiki\Extension\ConfirmEdit\Hooks;
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
use MediaWiki\MediaWikiServices;
use Message;
use RawMessage;
use Status;
use WebRequest;
class ReCaptchaNoCaptcha extends SimpleCaptcha {
// used for renocaptcha-edit, renocaptcha-addurl, renocaptcha-badlogin, renocaptcha-createaccount,

View file

@ -1,5 +1,7 @@
<?php
namespace MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha;
use MediaWiki\Auth\AuthenticationRequest;
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;

View file

@ -65,11 +65,6 @@
"MediaWiki\\Extension\\ConfirmEdit\\": "includes/",
"MediaWiki\\Extension\\ConfirmEdit\\SimpleCaptcha\\": "SimpleCaptcha/"
},
"TestAutoloadClasses": {
"HTMLFancyCaptchaField": "FancyCaptcha/includes/HTMLFancyCaptchaField.php",
"HTMLReCaptchaNoCaptchaField": "ReCaptchaNoCaptcha/includes/HTMLReCaptchaNoCaptchaField.php",
"ReCaptchaNoCaptchaAuthenticationRequest": "ReCaptchaNoCaptcha/includes/ReCaptchaNoCaptchaAuthenticationRequest.php"
},
"ResourceModules": {
"ext.confirmEdit.editPreview.ipwhitelist.styles": {
"styles": "ext.confirmEdit.editPreview.ipwhitelist.styles.css"

View file

@ -28,6 +28,7 @@ if ( getenv( 'MW_INSTALL_PATH' ) ) {
require_once "$IP/maintenance/Maintenance.php";
use MediaWiki\Extension\ConfirmEdit\FancyCaptcha\FancyCaptcha;
use MediaWiki\Extension\ConfirmEdit\Hooks;
/**

View file

@ -28,6 +28,7 @@ if ( getenv( 'MW_INSTALL_PATH' ) ) {
require_once "$IP/maintenance/Maintenance.php";
use MediaWiki\Extension\ConfirmEdit\FancyCaptcha\FancyCaptcha;
use MediaWiki\Extension\ConfirmEdit\Hooks;
/**

View file

@ -29,6 +29,7 @@ if ( getenv( 'MW_INSTALL_PATH' ) ) {
require_once "$IP/maintenance/Maintenance.php";
use MediaWiki\Extension\ConfirmEdit\FancyCaptcha\FancyCaptcha;
use MediaWiki\Extension\ConfirmEdit\Hooks;
/**

View file

@ -1,9 +1,24 @@
<?php
use MediaWiki\Extension\ConfirmEdit\FancyCaptcha\HTMLFancyCaptchaField;
/**
* @covers HTMLFancyCaptchaField
* @covers \MediaWiki\Extension\ConfirmEdit\FancyCaptcha\HTMLFancyCaptchaField
*/
class HTMLFancyCaptchaFieldTest extends MediaWikiIntegrationTestCase {
public function setUp(): void {
parent::setUp();
$this->mergeMwGlobalArrayValue(
'wgAutoloadClasses',
[
'MediaWiki\\Extension\\ConfirmEdit\\FancyCaptcha\\HTMLFancyCaptchaField'
=> __DIR__ . '/../../FancyCaptcha/includes/HTMLFancyCaptchaField.php'
]
);
}
public function testGetHTML() {
$html = $this->getForm( [ 'imageUrl' => 'https://example.com/' ] )->getHTML( false );
$this->assertMatchesRegularExpression( '/"fancycaptcha-image"/', $html );

View file

@ -1,9 +1,24 @@
<?php
use MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha\HTMLReCaptchaNoCaptchaField;
/**
* @covers HTMLReCaptchaNoCaptchaField
* @covers \MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha\HTMLReCaptchaNoCaptchaField
*/
class HTMLReCaptchaNoCaptchaFieldTest extends PHPUnit\Framework\TestCase {
class HTMLReCaptchaNoCaptchaFieldTest extends MediaWikiIntegrationTestCase {
public function setUp(): void {
parent::setUp();
$this->mergeMwGlobalArrayValue(
'wgAutoloadClasses',
[
'MediaWiki\\Extension\\ConfirmEdit\\ReCaptchaNoCaptcha\\HTMLReCaptchaNoCaptchaField'
=> __DIR__ . '/../../ReCaptchaNoCaptcha/includes/HTMLReCaptchaNoCaptchaField.php'
]
);
}
public function testSubmit() {
$request = new FauxRequest( [
'foo' => 'abc',

View file

@ -1,7 +1,9 @@
<?php
use MediaWiki\Extension\ConfirmEdit\QuestyCaptcha\QuestyCaptcha;
/**
* @covers QuestyCaptcha
* @covers \MediaWiki\Extension\ConfirmEdit\QuestyCaptcha\QuestyCaptcha
*/
class QuestyCaptchaTest extends MediaWikiIntegrationTestCase {
@ -10,12 +12,13 @@ class QuestyCaptchaTest extends MediaWikiIntegrationTestCase {
$this->mergeMwGlobalArrayValue(
'wgAutoloadClasses',
[ 'QuestyCaptcha' => __DIR__ . '/../../QuestyCaptcha/includes/QuestyCaptcha.php' ]
[ 'MediaWiki\\Extension\\ConfirmEdit\\QuestyCaptcha\\QuestyCaptcha'
=> __DIR__ . '/../../QuestyCaptcha/includes/QuestyCaptcha.php' ]
);
}
/**
* @covers QuestyCaptcha::getCaptcha
* @covers \MediaWiki\Extension\ConfirmEdit\QuestyCaptcha\QuestyCaptcha::getCaptcha
* @dataProvider provideGetCaptcha
*/
public function testGetCaptcha( $config, $expected ) {

View file

@ -1,11 +1,25 @@
<?php
use MediaWiki\Auth\AuthenticationRequestTestCase;
use MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha\ReCaptchaNoCaptchaAuthenticationRequest;
/**
* @covers ReCaptchaNoCaptchaAuthenticationRequest
* @covers \MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha\ReCaptchaNoCaptchaAuthenticationRequest
*/
class ReCaptchaNoCaptchaAuthenticationRequestTest extends AuthenticationRequestTestCase {
public function setUp(): void {
parent::setUp();
$this->mergeMwGlobalArrayValue(
'wgAutoloadClasses',
[
'MediaWiki\\Extension\\ConfirmEdit\\ReCaptchaNoCaptcha\\ReCaptchaNoCaptchaAuthenticationRequest'
=> __DIR__ . '/../../ReCaptchaNoCaptcha/includes/ReCaptchaNoCaptchaAuthenticationRequest.php'
]
);
}
protected function getInstance( array $args = [] ) {
return new ReCaptchaNoCaptchaAuthenticationRequest();
}