Smarita has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/383048 )
Change subject: [WIP]Outreachy microtask: write a CAPTCHA plugin that can fall
back to another algorithm
......................................................................
[WIP]Outreachy microtask: write a CAPTCHA plugin that can fall back to
another algorithm
This captcha plugin, presents the user with a simple button asking him
whether he is a robot. If he clicks on "Yes" then the page reloads and
the captcha changes to SimpleCaptcha.
Kindly note that this is a WIP and hence DO NOT MERGE
BUG: T177034
Change-Id: I8233bdc114e980824d012bb889eb17bb709282d8
---
M FancyCaptcha/ApiFancyCaptchaReload.php
M FancyCaptcha/FancyCaptcha.class.php
M FancyCaptcha/HTMLFancyCaptchaField.php
M FancyCaptcha/resources/ext.confirmEdit.fancyCaptcha.js
M includes/ConfirmEditHooks.php
5 files changed, 30 insertions(+), 68 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ConfirmEdit
refs/changes/48/383048/1
diff --git a/FancyCaptcha/ApiFancyCaptchaReload.php
b/FancyCaptcha/ApiFancyCaptchaReload.php
index f3e0d11..45717db 100644
--- a/FancyCaptcha/ApiFancyCaptchaReload.php
+++ b/FancyCaptcha/ApiFancyCaptchaReload.php
@@ -7,13 +7,11 @@
*/
class ApiFancyCaptchaReload extends ApiBase {
public function execute() {
- # Get a new FancyCaptcha form data
- $captcha = new FancyCaptcha();
- $info = $captcha->getCaptcha();
- $captchaIndex = $captcha->storeCaptcha( $info );
-
- $result = $this->getResult();
- $result->addValue( null, $this->getModuleName(), [ 'index' =>
$captchaIndex ] );
+ global $wgSessionStarted;
+ if (! $wgSessionStarted) {
+ wfSetupSession();
+ }
+ $_SESSION["botdetected"]="detected";
return true;
}
diff --git a/FancyCaptcha/FancyCaptcha.class.php
b/FancyCaptcha/FancyCaptcha.class.php
index c2477bf..7dcf4cb 100644
--- a/FancyCaptcha/FancyCaptcha.class.php
+++ b/FancyCaptcha/FancyCaptcha.class.php
@@ -459,7 +459,6 @@
$formDescriptor['captchaWord'] = [
'class' => HTMLFancyCaptchaField::class,
- 'imageUrl' => $this->getCaptchaInfo( $req->captchaData,
$req->captchaId ),
'label-message' => $this->getMessage( $this->action ),
'showCreateHelp' => in_array( $action, [
AuthManager::ACTION_CREATE,
diff --git a/FancyCaptcha/HTMLFancyCaptchaField.php
b/FancyCaptcha/HTMLFancyCaptchaField.php
index fe8e7da..dcb886c 100644
--- a/FancyCaptcha/HTMLFancyCaptchaField.php
+++ b/FancyCaptcha/HTMLFancyCaptchaField.php
@@ -5,9 +5,6 @@
* Does not include the captcha ID; that must be included in the form as a
separate hidden field.
*/
class HTMLFancyCaptchaField extends HTMLFormField {
- /** @var string */
- protected $imageUrl;
-
/** @var bool */
protected $showCreateHelp;
@@ -21,7 +18,6 @@
*/
public function __construct( array $params ) {
parent::__construct( $params );
- $this->imageUrl = $params['imageUrl'];
$this->showCreateHelp = !empty( $params['showCreateHelp'] );
}
@@ -46,36 +42,23 @@
$captchaReload = '';
}
- $attribs = [
- 'type' => 'text',
- 'id' => $this->mID,
- 'name' => $this->mName,
- 'class' => 'mw-ui-input',
- 'size' => '12', // max_length in captcha.py plus fudge
factor
- 'dir' => $this->mDir,
- 'autocomplete' => 'off',
- 'autocorrect' => 'off',
- 'autocapitalize' => 'off',
- 'placeholder' => $this->mParent->msg(
'fancycaptcha-imgcaptcha-ph' )->text()
- ];
- $attribs += $this->getAttributes( [ 'tabindex', 'required',
'autofocus' ] );
-
$html = Html::openElement( 'div', [ 'class' =>
'fancycaptcha-captcha-container' ] )
. Html::openElement( 'div', [ 'class' =>
'fancycaptcha-captcha-and-reload' ] )
- . Html::openElement( 'div', [ 'class' =>
'fancycaptcha-image-container' ] )
- . Html::element( 'img', [
- 'class' => 'fancycaptcha-image',
- 'src' => $this->imageUrl,
- 'alt' => ''
- ] ) . $captchaReload . Html::closeElement( 'div' ) .
Html::closeElement( 'div' ) . "\n"
- . Html::element( 'input', $attribs );
-
- if ( $this->showCreateHelp ) {
- // use raw element, the message will contain a link
- $html .= Html::rawElement( 'small', [
- 'class' => 'mw-createacct-captcha-assisted'
- ], $this->mParent->msg( 'createacct-imgcaptcha-help'
)->parse() );
- }
+ . Html::linkButton(
+ "Yes, I am a bot!",
+ [ 'id' => 'bot']
+ ).
+ Html::check(
+ "Nope, not a bot!",
+ $checked = false,
+ ['id'=>'baba']
+ ).
+ Html::label(
+ "Nope, not a bot!",
+ 'radiodesc',
+ []
+ ). "\n"
+ ;
$html .= Html::closeElement( 'div' );
diff --git a/FancyCaptcha/resources/ext.confirmEdit.fancyCaptcha.js
b/FancyCaptcha/resources/ext.confirmEdit.fancyCaptcha.js
index d047b19..9511882 100644
--- a/FancyCaptcha/resources/ext.confirmEdit.fancyCaptcha.js
+++ b/FancyCaptcha/resources/ext.confirmEdit.fancyCaptcha.js
@@ -1,33 +1,9 @@
( function ( $, mw ) {
- $( document ).on( 'click', '.fancycaptcha-reload', function () {
- var $this = $( this ),
- $root = $this.closest(
'.fancycaptcha-captcha-container' ),
- $captchaImage = $root.find( '.fancycaptcha-image' );
-
- $this.addClass( 'fancycaptcha-reload-loading' );
-
- // AJAX request to get captcha index key
+ $( document ).on( 'click', '#bot', function () {
new mw.Api().post( { action: 'fancycaptchareload' } ).done(
function ( data ) {
- var captchaIndex = data.fancycaptchareload.index,
- imgSrc;
- if ( typeof captchaIndex === 'string' ) {
- // replace index key with a new one for captcha
image
- imgSrc = $captchaImage.attr( 'src' ).replace(
/(wpCaptchaId=)\w+/, '$1' + captchaIndex );
- $captchaImage.attr( 'src', imgSrc );
-
- // replace index key with a new one for hidden
tag
- $( '#mw-input-captchaId' ).val( captchaIndex );
- $( '#mw-input-captchaWord' ).val( '' ).focus();
-
- // now do the same with a selector that works
for pre-1.27 login forms
- $root.find( '[name="wpCaptchaId"]' ).val(
captchaIndex );
- $root.find( '[name="wpCaptchaWord"]' ).val( ''
).focus();
- }
- } )
- .always( function () {
- $this.removeClass( 'fancycaptcha-reload-loading' );
+ window.location.href=
"/core/index.php?title=Special:CreateAccount";
} );
return false;
} );
-}( jQuery, mediaWiki ) );
+}( jQuery, mediaWiki ) );
\ No newline at end of file
diff --git a/includes/ConfirmEditHooks.php b/includes/ConfirmEditHooks.php
index d2dcc55..d403be8 100644
--- a/includes/ConfirmEditHooks.php
+++ b/includes/ConfirmEditHooks.php
@@ -13,7 +13,13 @@
if ( !static::$instanceCreated ) {
static::$instanceCreated = true;
- $wgCaptcha = new $wgCaptchaClass;
+ if (isset($_SESSION['botdetected'])){
+ $captchatype = 'SimpleCaptcha';
+ }
+ else{
+ $captchatype = $wgCaptchaClass;
+ }
+ $wgCaptcha = new $captchatype;
}
return $wgCaptcha;
--
To view, visit https://gerrit.wikimedia.org/r/383048
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8233bdc114e980824d012bb889eb17bb709282d8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ConfirmEdit
Gerrit-Branch: master
Gerrit-Owner: Smarita <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits