[MediaWiki-commits] [Gerrit] mediawiki...ConfirmEdit[master]: [WIP]Outreachy microtask: write a CAPTCHA plugin that can fa...
Smarita has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/383299 ) 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: I4bbaa8fba6a85aed05fe8ab26263007973968494 --- A SimplerCaptcha.php A SimplerCaptcha/ApiSimplerCaptchaReload.php A SimplerCaptcha/HTMLSimplerCaptchaField.php A SimplerCaptcha/SimplerCaptcha.class.php A SimplerCaptcha/SimplerCaptcha.php A SimplerCaptcha/extension.json A SimplerCaptcha/resources/ext.confirmEdit.simplerCaptcha.css A SimplerCaptcha/resources/ext.confirmEdit.simplerCaptcha.js M includes/ConfirmEditHooks.php 9 files changed, 407 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ConfirmEdit refs/changes/99/383299/1 diff --git a/SimplerCaptcha.php b/SimplerCaptcha.php new file mode 100644 index 000..91dca97 --- /dev/null +++ b/SimplerCaptcha.php @@ -0,0 +1,2 @@ + 'apihelp-simplercaptchareload-example-1', + ]; + } +} diff --git a/SimplerCaptcha/HTMLSimplerCaptchaField.php b/SimplerCaptcha/HTMLSimplerCaptchaField.php new file mode 100644 index 000..9bbe787 --- /dev/null +++ b/SimplerCaptcha/HTMLSimplerCaptchaField.php @@ -0,0 +1,73 @@ +showCreateHelp = !empty( $params['showCreateHelp'] ); + } + + public function getInputHTML( $value ) { + global $wgEnableAPI; + + $out = $this->mParent->getOutput(); + + // Uses addModuleStyles so it is loaded when JS is disabled. + $out->addModuleStyles( 'ext.confirmEdit.simplerCaptcha.styles' ); + + if ( $wgEnableAPI ) { + // Loaded only if JS is enabled + $out->addModules( 'ext.confirmEdit.simplerCaptcha' ); + + $captchaReload = Html::element( + 'small', + [ 'class' => 'confirmedit-captcha-reload simplercaptcha-reload' ], + $this->mParent->msg( 'simplercaptcha-reload-text' )->text() + ); + } else { + $captchaReload = ''; + } + + $html = Html::openElement( 'div', [ 'class' => 'simplercaptcha-captcha-container' ] ) + . Html::openElement( 'div', [ 'class' => 'simplercaptcha-captcha-and-reload' ] ) + . Html::linkButton( + "Yes, I am a bot!", + [ 'id' => 'bot'] +). "\n" + ; + + $html .= Html::closeElement( 'div' ); + + return $html; + } + + public function getLabel() { + // slight abuse of what getLabel() should mean; $mLabel is used for the pre-label text + // as the actual label is always the same + return $this->mParent->msg( 'captcha-label' )->text() . ' ' + . $this->mParent->msg( 'simplercaptcha-captcha' )->text(); + } + + public function getLabelHtml( $cellAttributes = [] ) { + $labelHtml = parent::getLabelHtml( $cellAttributes ); + if ( $this->mLabel ) { + // use raw element, the message will contain a link + $labelHtml = Html::rawElement( 'p', [], $this->mLabel ) . $labelHtml; + } + return $labelHtml; + } +} diff --git a/SimplerCaptcha/SimplerCaptcha.class.php b/SimplerCaptcha/SimplerCaptcha.class.php new file mode 100644 index 000..e4d622d --- /dev/null +++ b/SimplerCaptcha/SimplerCaptcha.class.php @@ -0,0 +1,169 @@ +getCaptcha(); + $index = $this->storeCaptcha( $info ); + + if ( $wgEnableAPI ) { + // Loaded only if JS is enabled + $modules[] = 'ext.confirmEdit.simplerCaptcha'; + + $captchaReload = Html::element( + 'small', + [ + 'class' => 'confirmedit-captcha-reload simplercaptcha-reload' + ], + wfMessage( 'simplercaptcha-reload-text' )->text() + ); + } else { + $captchaReload = ''; + } + + $form = Html::openElement( 'div' ) . + Html::element( 'label', [ + 'for' => 'wpCaptchaWord', + ], +
[MediaWiki-commits] [Gerrit] mediawiki...ConfirmEdit[master]: [WIP]Outreachy microtask: write a CAPTCHA plugin that can fa...
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