mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-23 15:56:50 +00:00
Namespace base classes
Change-Id: I3fa9747e0ea970c5de39e2da8603e1bba9388a69
This commit is contained in:
parent
7e09b93ba7
commit
30cd1d8a23
|
@ -51,7 +51,7 @@
|
|||
"localBasePath": "resources",
|
||||
"remoteExtPath": "ConfirmEdit/FancyCaptcha/resources"
|
||||
},
|
||||
"callback": "ConfirmEditHooks::onFancyCaptchaSetup",
|
||||
"callback": "MediaWiki\\Extension\\ConfirmEdit\\Hooks::onFancyCaptchaSetup",
|
||||
"config": {
|
||||
"CaptchaClass": {
|
||||
"value": "FancyCaptcha"
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
use MediaWiki\Auth\AuthenticationRequest;
|
||||
use MediaWiki\Auth\AuthManager;
|
||||
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
|
||||
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Auth\AuthenticationRequest;
|
||||
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
|
||||
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
|
||||
use MediaWiki\Extension\Math\MathRenderer;
|
||||
|
||||
class MathCaptcha extends SimpleCaptcha {
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\Auth\AuthenticationRequest;
|
||||
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
|
||||
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
|
||||
use MediaWiki\Extension\ConfirmEdit\Store\CaptchaStore;
|
||||
|
||||
class QuestyCaptcha extends SimpleCaptcha {
|
||||
// used for questycaptcha-edit, questycaptcha-addurl, questycaptcha-badlogin,
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Auth\AuthenticationRequest;
|
||||
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
|
||||
use MediaWiki\Extension\ConfirmEdit\Hooks;
|
||||
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
class ReCaptchaNoCaptcha extends SimpleCaptcha {
|
||||
|
@ -255,7 +258,7 @@ HTML;
|
|||
}
|
||||
|
||||
// ugly way to retrieve error information
|
||||
$captcha = ConfirmEditHooks::getInstance();
|
||||
$captcha = Hooks::getInstance();
|
||||
|
||||
$formDescriptor['captchaWord'] = [
|
||||
'class' => HTMLReCaptchaNoCaptchaField::class,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Auth\AuthenticationRequest;
|
||||
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
|
||||
|
||||
/**
|
||||
* Authentication request for ReCaptcha v2. Unlike the parent class, no session storage is used
|
||||
|
|
|
@ -1,14 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\ConfirmEdit\SimpleCaptcha;
|
||||
|
||||
use ApiBase;
|
||||
use ApiEditPage;
|
||||
use BagOStuff;
|
||||
use Config;
|
||||
use ConfigException;
|
||||
use Content;
|
||||
use ContentSecurityPolicy;
|
||||
use EditPage;
|
||||
use ExtensionRegistry;
|
||||
use HTMLForm;
|
||||
use IContextSource;
|
||||
use MailAddress;
|
||||
use MediaWiki\Auth\AuthenticationRequest;
|
||||
use MediaWiki\Cache\CacheKeyHelper;
|
||||
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
|
||||
use MediaWiki\Extension\ConfirmEdit\CaptchaTriggers;
|
||||
use MediaWiki\Extension\ConfirmEdit\Hooks\HookRunner;
|
||||
use MediaWiki\Extension\ConfirmEdit\Store\CaptchaStore;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionAccessException;
|
||||
use MediaWiki\Revision\RevisionLookup;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
use MediaWiki\User\UserNameUtils;
|
||||
use Message;
|
||||
use ObjectCache;
|
||||
use OOUI\FieldLayout;
|
||||
use OOUI\HiddenInputWidget;
|
||||
use OOUI\NumberInputWidget;
|
||||
use OutputPage;
|
||||
use ParserOptions;
|
||||
use RequestContext;
|
||||
use Status;
|
||||
use TextContent;
|
||||
use Title;
|
||||
use UnexpectedValueException;
|
||||
use User;
|
||||
use WebRequest;
|
||||
use Wikimedia\IPUtils;
|
||||
use WikiPage;
|
||||
|
||||
/**
|
||||
* Demo CAPTCHA (not for production usage) and base class for real CAPTCHAs
|
||||
|
@ -142,8 +174,8 @@ class SimpleCaptcha {
|
|||
|
||||
return [
|
||||
'html' =>
|
||||
new OOUI\FieldLayout(
|
||||
new OOUI\NumberInputWidget( [
|
||||
new FieldLayout(
|
||||
new NumberInputWidget( [
|
||||
'name' => 'wpCaptchaWord',
|
||||
'classes' => [ 'simplecaptcha-answer' ],
|
||||
'id' => 'wpCaptchaWord',
|
||||
|
@ -157,7 +189,7 @@ class SimpleCaptcha {
|
|||
'classes' => [ 'simplecaptcha-field' ],
|
||||
]
|
||||
) .
|
||||
new OOUI\HiddenInputWidget( [
|
||||
new HiddenInputWidget( [
|
||||
'name' => 'wpCaptchaId',
|
||||
'id' => 'wpCaptchaId',
|
||||
'value' => $index
|
||||
|
@ -433,7 +465,7 @@ class SimpleCaptcha {
|
|||
);
|
||||
// And then store it in cache for one day. This cache is cleared on
|
||||
// modifications to the whitelist page.
|
||||
// @see ConfirmEditHooks::onPageSaveComplete()
|
||||
// @see MediaWiki\Extension\ConfirmEdit\Hooks::onPageSaveComplete()
|
||||
$cache->set( $cacheKey, $whitelist, 86400 );
|
||||
} else {
|
||||
// Whitelist from the cache
|
||||
|
|
|
@ -41,10 +41,10 @@
|
|||
}
|
||||
},
|
||||
"ExtensionFunctions": [
|
||||
"ConfirmEditHooks::confirmEditSetup"
|
||||
"MediaWiki\\Extension\\ConfirmEdit\\Hooks::confirmEditSetup"
|
||||
],
|
||||
"SpecialPages": {
|
||||
"Captcha": "SpecialCaptcha"
|
||||
"Captcha": "MediaWiki\\Extension\\ConfirmEdit\\Specials\\SpecialCaptcha"
|
||||
},
|
||||
"MessagesDirs": {
|
||||
"ConfirmEdit": [
|
||||
|
@ -55,20 +55,15 @@
|
|||
"ExtensionMessagesFiles": {
|
||||
"ConfirmEditAlias": "ConfirmEdit.alias.php"
|
||||
},
|
||||
"AutoloadNamespaces": {
|
||||
"MediaWiki\\Extension\\ConfirmEdit\\": "includes/"
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"ConfirmEditHooks": "includes/ConfirmEditHooks.php",
|
||||
"SimpleCaptcha": "SimpleCaptcha/SimpleCaptcha.php",
|
||||
"CaptchaStore": "includes/store/CaptchaStore.php",
|
||||
"CaptchaSessionStore": "includes/store/CaptchaSessionStore.php",
|
||||
"CaptchaCacheStore": "includes/store/CaptchaCacheStore.php",
|
||||
"CaptchaHashStore": "includes/store/CaptchaHashStore.php",
|
||||
"CaptchaTriggers": "includes/CaptchaTriggers.php",
|
||||
"SpecialCaptcha": "includes/specials/SpecialCaptcha.php",
|
||||
"CaptchaPreAuthenticationProvider": "includes/auth/CaptchaPreAuthenticationProvider.php",
|
||||
"CaptchaAuthenticationRequest": "includes/auth/CaptchaAuthenticationRequest.php"
|
||||
"CaptchaCacheStore": "includes/Store/CaptchaCacheStore.php",
|
||||
"ConfirmEditHooks": "includes/Hooks.php",
|
||||
"MediaWiki\\Extension\\ConfirmEdit\\Hooks": "includes/Hooks.php",
|
||||
"MediaWiki\\Extension\\ConfirmEdit\\Store\\CaptchaCacheStore": "includes/Store/CaptchaCacheStore.php"
|
||||
},
|
||||
"AutoloadNamespaces": {
|
||||
"MediaWiki\\Extension\\ConfirmEdit\\": "includes/",
|
||||
"MediaWiki\\Extension\\ConfirmEdit\\SimpleCaptcha\\": "SimpleCaptcha/"
|
||||
},
|
||||
"TestAutoloadClasses": {
|
||||
"HTMLFancyCaptchaField": "FancyCaptcha/includes/HTMLFancyCaptchaField.php",
|
||||
|
@ -104,7 +99,7 @@
|
|||
},
|
||||
"HookHandlers": {
|
||||
"ConfirmEditHooks": {
|
||||
"class": "ConfirmEditHooks"
|
||||
"class": "MediaWiki\\Extension\\ConfirmEdit\\Hooks"
|
||||
}
|
||||
},
|
||||
"Hooks": {
|
||||
|
@ -115,15 +110,15 @@
|
|||
"TitleReadWhitelist": "ConfirmEditHooks",
|
||||
"AlternateEditPreview": "ConfirmEditHooks",
|
||||
"ResourceLoaderRegisterModules": "ConfirmEditHooks",
|
||||
"EditPage::showEditForm:fields": "ConfirmEditHooks::showEditFormFields",
|
||||
"EditFilterMergedContent": "ConfirmEditHooks::confirmEditMerged",
|
||||
"APIGetAllowedParams": "ConfirmEditHooks::onAPIGetAllowedParams",
|
||||
"AuthChangeFormFields": "ConfirmEditHooks::onAuthChangeFormFields"
|
||||
"EditPage::showEditForm:fields": "MediaWiki\\Extension\\ConfirmEdit\\Hooks::showEditFormFields",
|
||||
"EditFilterMergedContent": "MediaWiki\\Extension\\ConfirmEdit\\Hooks::confirmEditMerged",
|
||||
"APIGetAllowedParams": "MediaWiki\\Extension\\ConfirmEdit\\Hooks::onAPIGetAllowedParams",
|
||||
"AuthChangeFormFields": "MediaWiki\\Extension\\ConfirmEdit\\Hooks::onAuthChangeFormFields"
|
||||
},
|
||||
"AuthManagerAutoConfig": {
|
||||
"preauth": {
|
||||
"CaptchaPreAuthenticationProvider": {
|
||||
"class": "CaptchaPreAuthenticationProvider",
|
||||
"class": "MediaWiki\\Extension\\ConfirmEdit\\Auth\\CaptchaPreAuthenticationProvider",
|
||||
"sort": 10
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +147,7 @@
|
|||
"merge_strategy": "array_plus_2d"
|
||||
},
|
||||
"CaptchaStorageClass": {
|
||||
"value": "CaptchaSessionStore"
|
||||
"value": "MediaWiki\\Extension\\ConfirmEdit\\Store\\CaptchaSessionStore"
|
||||
},
|
||||
"CaptchaSessionExpiration": {
|
||||
"value": 1800
|
||||
|
|
|
@ -3,17 +3,17 @@
|
|||
namespace MediaWiki\Extension\ConfirmEdit\hCaptcha;
|
||||
|
||||
use ApiBase;
|
||||
use CaptchaAuthenticationRequest;
|
||||
use ConfirmEditHooks;
|
||||
use ContentSecurityPolicy;
|
||||
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 RequestContext;
|
||||
use SimpleCaptcha;
|
||||
use Status;
|
||||
use WebRequest;
|
||||
|
||||
|
@ -268,7 +268,7 @@ class HCaptcha extends SimpleCaptcha {
|
|||
}
|
||||
|
||||
// ugly way to retrieve error information
|
||||
$captcha = ConfirmEditHooks::getInstance();
|
||||
$captcha = Hooks::getInstance();
|
||||
|
||||
$formDescriptor['captchaWord'] = [
|
||||
'class' => HTMLHCaptchaField::class,
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\ConfirmEdit\Auth;
|
||||
|
||||
use MediaWiki\Auth\AuthenticationRequest;
|
||||
use MediaWiki\Auth\AuthManager;
|
||||
use MediaWiki\Extension\ConfirmEdit\Hooks;
|
||||
|
||||
/**
|
||||
* Generic captcha authentication request class. A captcha consist some data stored in the session
|
||||
|
@ -35,7 +38,7 @@ class CaptchaAuthenticationRequest extends AuthenticationRequest {
|
|||
$success = parent::loadFromSubmission( $data );
|
||||
if ( $success ) {
|
||||
// captchaId and captchaWord was set from the submission but captchaData was not.
|
||||
$captcha = ConfirmEditHooks::getInstance();
|
||||
$captcha = Hooks::getInstance();
|
||||
$this->captchaData = $captcha->retrieveCaptcha( $this->captchaId );
|
||||
if ( !$this->captchaData ) {
|
||||
return false;
|
||||
|
@ -48,7 +51,7 @@ class CaptchaAuthenticationRequest extends AuthenticationRequest {
|
|||
* @inheritDoc
|
||||
*/
|
||||
public function getFieldInfo() {
|
||||
$captcha = ConfirmEditHooks::getInstance();
|
||||
$captcha = Hooks::getInstance();
|
||||
|
||||
// doesn't actually exist but *Captcha::getMessage will handle that
|
||||
$action = 'generic';
|
||||
|
@ -88,7 +91,7 @@ class CaptchaAuthenticationRequest extends AuthenticationRequest {
|
|||
* @inheritDoc
|
||||
*/
|
||||
public function getMetadata() {
|
||||
return ( ConfirmEditHooks::getInstance() )->describeCaptchaType();
|
||||
return ( Hooks::getInstance() )->describeCaptchaType();
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,17 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\ConfirmEdit\Auth;
|
||||
|
||||
use MediaWiki\Auth\AbstractPreAuthenticationProvider;
|
||||
use MediaWiki\Auth\AuthenticationRequest;
|
||||
use MediaWiki\Auth\AuthenticationResponse;
|
||||
use MediaWiki\Auth\AuthManager;
|
||||
use MediaWiki\Extension\ConfirmEdit\Hooks;
|
||||
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use Status;
|
||||
use User;
|
||||
|
||||
class CaptchaPreAuthenticationProvider extends AbstractPreAuthenticationProvider {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getAuthenticationRequests( $action, array $options ) {
|
||||
$captcha = ConfirmEditHooks::getInstance();
|
||||
$captcha = Hooks::getInstance();
|
||||
$user = User::newFromName( $options['username'] );
|
||||
|
||||
$needed = false;
|
||||
|
@ -77,7 +83,7 @@ class CaptchaPreAuthenticationProvider extends AbstractPreAuthenticationProvider
|
|||
* @inheritDoc
|
||||
*/
|
||||
public function testForAuthentication( array $reqs ) {
|
||||
$captcha = ConfirmEditHooks::getInstance();
|
||||
$captcha = Hooks::getInstance();
|
||||
$username = AuthenticationRequest::getUsernameFromRequests( $reqs );
|
||||
$success = true;
|
||||
$isBadLoginPerUserTriggered = $username ?
|
||||
|
@ -111,7 +117,7 @@ class CaptchaPreAuthenticationProvider extends AbstractPreAuthenticationProvider
|
|||
* @inheritDoc
|
||||
*/
|
||||
public function testForAccountCreation( $user, $creator, array $reqs ) {
|
||||
$captcha = ConfirmEditHooks::getInstance();
|
||||
$captcha = Hooks::getInstance();
|
||||
|
||||
if ( $captcha->needCreateAccountCaptcha( $creator ) ) {
|
||||
$username = $user->getName();
|
||||
|
@ -139,7 +145,7 @@ class CaptchaPreAuthenticationProvider extends AbstractPreAuthenticationProvider
|
|||
* @inheritDoc
|
||||
*/
|
||||
public function postAuthentication( $user, AuthenticationResponse $response ) {
|
||||
$captcha = ConfirmEditHooks::getInstance();
|
||||
$captcha = Hooks::getInstance();
|
||||
switch ( $response->status ) {
|
||||
case AuthenticationResponse::PASS:
|
||||
case AuthenticationResponse::RESTART:
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\ConfirmEdit;
|
||||
|
||||
/**
|
||||
* A class with constants of the CAPTCHA triggers built-in in ConfirmEdit. Other extensions may
|
||||
* add more possible triggers, which are not included in this class.
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\ConfirmEdit;
|
||||
|
||||
/**
|
||||
* Simple value object for storing a captcha question + answer.
|
||||
*/
|
||||
|
|
|
@ -1,20 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\ConfirmEdit;
|
||||
|
||||
use ApiBase;
|
||||
use Content;
|
||||
use EditPage;
|
||||
use ExtensionRegistry;
|
||||
use Html;
|
||||
use HTMLForm;
|
||||
use MailAddress;
|
||||
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
|
||||
use MediaWiki\Hook\AlternateEditPreviewHook;
|
||||
use MediaWiki\Hook\EditPageBeforeEditButtonsHook;
|
||||
use MediaWiki\Hook\EmailUserFormHook;
|
||||
use MediaWiki\Hook\EmailUserHook;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Permissions\Hook\TitleReadWhitelistHook;
|
||||
use MediaWiki\ResourceLoader\Hook\ResourceLoaderRegisterModulesHook;
|
||||
use MediaWiki\ResourceLoader\ResourceLoader;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Storage\EditResult;
|
||||
use MediaWiki\Storage\Hook\PageSaveCompleteHook;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MessageSpecifier;
|
||||
use OutputPage;
|
||||
use ParserOutput;
|
||||
use RequestContext;
|
||||
use SpecialPage;
|
||||
use Status;
|
||||
use Title;
|
||||
use User;
|
||||
use Wikimedia\IPUtils;
|
||||
use WikiPage;
|
||||
|
||||
class ConfirmEditHooks implements
|
||||
\MediaWiki\Hook\AlternateEditPreviewHook,
|
||||
\MediaWiki\Hook\EditPageBeforeEditButtonsHook,
|
||||
\MediaWiki\Hook\EmailUserFormHook,
|
||||
\MediaWiki\Hook\EmailUserHook,
|
||||
\MediaWiki\Permissions\Hook\TitleReadWhitelistHook,
|
||||
\MediaWiki\ResourceLoader\Hook\ResourceLoaderRegisterModulesHook,
|
||||
\MediaWiki\Storage\Hook\PageSaveCompleteHook
|
||||
class Hooks implements
|
||||
AlternateEditPreviewHook,
|
||||
EditPageBeforeEditButtonsHook,
|
||||
EmailUserFormHook,
|
||||
EmailUserHook,
|
||||
TitleReadWhitelistHook,
|
||||
ResourceLoaderRegisterModulesHook,
|
||||
PageSaveCompleteHook
|
||||
{
|
||||
|
||||
protected static $instanceCreated = false;
|
||||
|
@ -301,3 +327,5 @@ class ConfirmEditHooks implements
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
class_alias( Hooks::class, 'ConfirmEditHooks' );
|
|
@ -1,5 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\ConfirmEdit\Specials;
|
||||
|
||||
use MediaWiki\Extension\ConfirmEdit\Hooks;
|
||||
use UnlistedSpecialPage;
|
||||
|
||||
class SpecialCaptcha extends UnlistedSpecialPage {
|
||||
public function __construct() {
|
||||
parent::__construct( 'Captcha' );
|
||||
|
@ -11,7 +16,7 @@ class SpecialCaptcha extends UnlistedSpecialPage {
|
|||
public function execute( $par ) {
|
||||
$this->setHeaders();
|
||||
|
||||
$instance = ConfirmEditHooks::getInstance();
|
||||
$instance = Hooks::getInstance();
|
||||
|
||||
if ( $par === 'image' && method_exists( $instance, 'showImage' ) ) {
|
||||
// @todo: Do this in a more OOP way
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\ConfirmEdit\Store;
|
||||
|
||||
use BagOStuff;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
class CaptchaCacheStore extends CaptchaStore {
|
||||
|
@ -46,3 +49,5 @@ class CaptchaCacheStore extends CaptchaStore {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias( CaptchaCacheStore::class, 'CaptchaCacheStore' );
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\ConfirmEdit\Store;
|
||||
|
||||
class CaptchaHashStore extends CaptchaStore {
|
||||
protected $data = [];
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\ConfirmEdit\Store;
|
||||
|
||||
use MediaWiki\Session\SessionManager;
|
||||
|
||||
class CaptchaSessionStore extends CaptchaStore {
|
|
@ -1,5 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\ConfirmEdit\Store;
|
||||
|
||||
use Exception;
|
||||
use MWException;
|
||||
|
||||
abstract class CaptchaStore {
|
||||
/**
|
||||
* Store the correct answer for a given captcha
|
||||
|
@ -42,7 +47,7 @@ abstract class CaptchaStore {
|
|||
final public static function get() {
|
||||
global $wgCaptchaStorageClass;
|
||||
if ( !self::$instance instanceof self ) {
|
||||
if ( in_array( 'CaptchaStore', class_parents( $wgCaptchaStorageClass ) ) ) {
|
||||
if ( in_array( self::class, class_parents( $wgCaptchaStorageClass ) ) ) {
|
||||
self::$instance = new $wgCaptchaStorageClass;
|
||||
} else {
|
||||
throw new Exception( "Invalid CaptchaStore class $wgCaptchaStorageClass" );
|
|
@ -28,6 +28,8 @@ if ( getenv( 'MW_INSTALL_PATH' ) ) {
|
|||
|
||||
require_once "$IP/maintenance/Maintenance.php";
|
||||
|
||||
use MediaWiki\Extension\ConfirmEdit\Hooks;
|
||||
|
||||
/**
|
||||
* Maintenance script that counts the number of captchas remaining.
|
||||
*
|
||||
|
@ -41,7 +43,7 @@ class CountFancyCaptchas extends Maintenance {
|
|||
}
|
||||
|
||||
public function execute() {
|
||||
$instance = ConfirmEditHooks::getInstance();
|
||||
$instance = Hooks::getInstance();
|
||||
if ( !( $instance instanceof FancyCaptcha ) ) {
|
||||
$this->fatalError( "\$wgCaptchaClass is not FancyCaptcha.\n", 1 );
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ if ( getenv( 'MW_INSTALL_PATH' ) ) {
|
|||
|
||||
require_once "$IP/maintenance/Maintenance.php";
|
||||
|
||||
use MediaWiki\Extension\ConfirmEdit\Hooks;
|
||||
|
||||
/**
|
||||
* Maintenance script that deletes old fancy captchas from storage
|
||||
*
|
||||
|
@ -47,7 +49,7 @@ class DeleteOldFancyCaptchas extends Maintenance {
|
|||
}
|
||||
|
||||
public function execute() {
|
||||
$instance = ConfirmEditHooks::getInstance();
|
||||
$instance = Hooks::getInstance();
|
||||
if ( !( $instance instanceof FancyCaptcha ) ) {
|
||||
$this->fatalError( "\$wgCaptchaClass is not FancyCaptcha.\n", 1 );
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ if ( getenv( 'MW_INSTALL_PATH' ) ) {
|
|||
|
||||
require_once "$IP/maintenance/Maintenance.php";
|
||||
|
||||
use MediaWiki\Extension\ConfirmEdit\Hooks;
|
||||
|
||||
/**
|
||||
* Maintenance script to generate fancy captchas using a python script and copy them into storage.
|
||||
*
|
||||
|
@ -66,7 +68,7 @@ class GenerateFancyCaptchas extends Maintenance {
|
|||
|
||||
$totalTime = -microtime( true );
|
||||
|
||||
$instance = ConfirmEditHooks::getInstance();
|
||||
$instance = Hooks::getInstance();
|
||||
if ( !( $instance instanceof FancyCaptcha ) ) {
|
||||
$this->fatalError( "\$wgCaptchaClass is not FancyCaptcha.\n", 1 );
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Auth\AuthenticationRequestTestCase;
|
||||
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
|
||||
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
|
||||
use MediaWiki\Extension\ConfirmEdit\Store\CaptchaHashStore;
|
||||
use MediaWiki\Extension\ConfirmEdit\Store\CaptchaStore;
|
||||
|
||||
/**
|
||||
* @covers CaptchaAuthenticationRequest
|
||||
* @covers \MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest
|
||||
*/
|
||||
class CaptchaAuthenticationRequestTest extends AuthenticationRequestTestCase {
|
||||
public function setUp(): void {
|
||||
|
|
|
@ -2,11 +2,18 @@
|
|||
|
||||
use MediaWiki\Auth\AuthManager;
|
||||
use MediaWiki\Auth\UsernameAuthenticationRequest;
|
||||
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
|
||||
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaPreAuthenticationProvider;
|
||||
use MediaWiki\Extension\ConfirmEdit\Hooks;
|
||||
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
|
||||
use MediaWiki\Extension\ConfirmEdit\Store\CaptchaHashStore;
|
||||
use MediaWiki\Extension\ConfirmEdit\Store\CaptchaStore;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Tests\Unit\Auth\AuthenticationProviderTestTrait;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
/**
|
||||
* @covers CaptchaPreAuthenticationProvider
|
||||
* @covers \MediaWiki\Extension\ConfirmEdit\Auth\CaptchaPreAuthenticationProvider
|
||||
* @group Database
|
||||
*/
|
||||
class CaptchaPreAuthenticationProviderTest extends MediaWikiIntegrationTestCase {
|
||||
|
@ -23,7 +30,7 @@ class CaptchaPreAuthenticationProviderTest extends MediaWikiIntegrationTestCase
|
|||
] );
|
||||
CaptchaStore::unsetInstanceForTests();
|
||||
CaptchaStore::get()->clearAll();
|
||||
$services = \MediaWiki\MediaWikiServices::getInstance();
|
||||
$services = MediaWikiServices::getInstance();
|
||||
if ( method_exists( $services, 'getLocalClusterObjectCache' ) ) {
|
||||
$this->setService( 'LocalClusterObjectCache', new HashBagOStuff() );
|
||||
}
|
||||
|
@ -33,7 +40,7 @@ class CaptchaPreAuthenticationProviderTest extends MediaWikiIntegrationTestCase
|
|||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
// make sure $wgCaptcha resets between tests
|
||||
TestingAccessWrapper::newFromClass( ConfirmEditHooks::class )->instanceCreated = false;
|
||||
TestingAccessWrapper::newFromClass( Hooks::class )->instanceCreated = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,7 +124,7 @@ class CaptchaPreAuthenticationProviderTest extends MediaWikiIntegrationTestCase
|
|||
$captcha->expects( $this->any() )->method( 'isBadLoginPerUserTriggered' )
|
||||
->willReturn( $isBadLoginPerUserTriggered );
|
||||
$this->setMwGlobals( 'wgCaptcha', $captcha );
|
||||
TestingAccessWrapper::newFromClass( ConfirmEditHooks::class )->instanceCreated = true;
|
||||
TestingAccessWrapper::newFromClass( Hooks::class )->instanceCreated = true;
|
||||
$provider = new CaptchaPreAuthenticationProvider();
|
||||
$this->initProvider( $provider, null, null, $this->getServiceContainer()->getAuthManager() );
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\ConfirmEdit\CaptchaTriggers;
|
||||
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
|
||||
use Wikimedia\ScopedCallback;
|
||||
|
||||
/**
|
||||
* @covers SimpleCaptcha
|
||||
* @covers \MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha
|
||||
*/
|
||||
class CaptchaTest extends MediaWikiIntegrationTestCase {
|
||||
|
||||
|
|
Loading…
Reference in a new issue