Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/185089

Change subject: Add support for autofocus the CAPTCHA input
......................................................................

Add support for autofocus the CAPTCHA input

Added support to SimpleCaptcha::getForm() to provide the information,
if the input of the CAPTCHA form should have the focus, so that the user
doesn't overlook the message, that he had to solve a CAPTCHA.

Actually only addurl set's and autofocus, because it's the only one, which isn't
visible in the first workflow and can be easily overlooked.

Change-Id: Id090a9fdb078d188f1890fad9b5029674b88094b
Task: T11406
---
M Captcha.php
M FancyCaptcha.class.php
M MathCaptcha.class.php
M QuestyCaptcha.class.php
M ReCaptcha.class.php
5 files changed, 47 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ConfirmEdit 
refs/changes/89/185089/1

diff --git a/Captcha.php b/Captcha.php
index b176096..8c7c4fd 100644
--- a/Captcha.php
+++ b/Captcha.php
@@ -33,21 +33,24 @@
         * it would be easy to defeat by machine.
         *
         * Override this!
-        *
+        * @param boolean $autofocus Whether the input field should get 
autofocused on page load or not.
         * @return string HTML
         */
-       function getForm() {
+       function getForm( $autofocus = false ) {
                $captcha = $this->getCaptcha();
                $index = $this->storeCaptcha( $captcha );
 
                return "<p><label for=\"wpCaptchaWord\">{$captcha['question']} 
= </label>" .
                        Xml::element( 'input', array(
-                               'name' => 'wpCaptchaWord',
-                               'class' => 'mw-ui-input',
-                               'id'   => 'wpCaptchaWord',
-                               'size'  => 5,
-                               'autocomplete' => 'off',
-                               'tabindex' => 1 ) ) . // tab in before the edit 
textarea
+                                       'name' => 'wpCaptchaWord',
+                                       'class' => 'mw-ui-input',
+                                       'id'   => 'wpCaptchaWord',
+                                       'size'  => 5,
+                                       'autocomplete' => 'off',
+                                       'tabindex' => 1, // tab in before the 
edit textarea
+                                       'autofocus' => $autofocus // the input 
should have autofocus in special cases
+                               )
+                       ) .
                        "</p>\n" .
                        Xml::element( 'input', array(
                                'type'  => 'hidden',
@@ -104,8 +107,13 @@
                        $this->showEditCaptcha ||
                        $this->shouldCheck( $page, $newText, $section )
                ) {
+                       if ( $this->action === 'addurl' ) {
+                               $autofocus = true;
+                       } else {
+                               $autofocus = false;
+                       }
                        $out->addWikiText( $this->getMessage( $this->action ) );
-                       $out->addHTML( $this->getForm() );
+                       $out->addHTML( $this->getForm( $autofocus ) );
                }
                unset( $page->ConfirmEdit_ActivateCaptcha );
        }
diff --git a/FancyCaptcha.class.php b/FancyCaptcha.class.php
index 46387c9..26741d2 100644
--- a/FancyCaptcha.class.php
+++ b/FancyCaptcha.class.php
@@ -88,8 +88,9 @@
 
        /**
         * Insert the captcha prompt into the edit form.
+        * @param boolean $autofocus Whether the input field should get 
autofocused on page load or not.
         */
-       function getForm() {
+       function getForm( $autofocus = false ) {
                global $wgOut, $wgExtensionAssetsPath, $wgEnableAPI;
 
                // Uses addModuleStyles so it is loaded when JS is disabled.
@@ -137,6 +138,7 @@
                                        'autocomplete' => 'off',
                                        'autocorrect' => 'off',
                                        'autocapitalize' => 'off',
+                                       'autofocus' => $autofocus,
                                        'required' => 'required',
                                        'tabindex' => 1
                                )
diff --git a/MathCaptcha.class.php b/MathCaptcha.class.php
index ac220ba..0b676f8 100644
--- a/MathCaptcha.class.php
+++ b/MathCaptcha.class.php
@@ -17,12 +17,24 @@
        }
 
        /** Produce a nice little form */
-       function getForm() {
+       function getForm( $autofocus = false ) {
                list( $sum, $answer ) = $this->pickSum();
                $index = $this->storeCaptcha( array( 'answer' => $answer ) );
 
                $form = '<table><tr><td>' . $this->fetchMath( $sum ) . '</td>';
-               $form .= '<td>' . Html::input( 'wpCaptchaWord', false, false, 
array( 'tabindex' => '1', 'autocomplete' => 'off', 'required' ) ) . 
'</td></tr></table>';
+               $form .= '<td>' .
+                       Html::input(
+                               'wpCaptchaWord',
+                               false,
+                               false,
+                               array(
+                                       'tabindex' => '1',
+                                       'autocomplete' => 'off',
+                                       'required',
+                                       'autofocus' => $autofocus
+                               )
+                       ) .
+               '</td></tr></table>';
                $form .= Html::hidden( 'wpCaptchaId', $index );
                return $form;
        }
diff --git a/QuestyCaptcha.class.php b/QuestyCaptcha.class.php
index 2e5274a..cbc8db8 100644
--- a/QuestyCaptcha.class.php
+++ b/QuestyCaptcha.class.php
@@ -41,20 +41,24 @@
                return array( 'question' => $question, 'answer' => $answer );
        }
 
-       function getForm() {
+       function getForm( $autofocus = false ) {
                $captcha = $this->getCaptcha();
                if ( !$captcha ) {
                        die( "No questions found; set some in LocalSettings.php 
using the format from QuestyCaptcha.php." );
                }
                $index = $this->storeCaptcha( $captcha );
                return "<p><label 
for=\"wpCaptchaWord\">{$captcha['question']}</label> " .
-                       Html::element( 'input', array(
-                               'name' => 'wpCaptchaWord',
-                               'id'   => 'wpCaptchaWord',
-                               'class' => 'mw-ui-input',
-                               'required',
-                               'autocomplete' => 'off',
-                               'tabindex' => 1 ) ) . // tab in before the edit 
textarea
+                       Html::element( 'input',
+                               array(
+                                       'name' => 'wpCaptchaWord',
+                                       'id'   => 'wpCaptchaWord',
+                                       'class' => 'mw-ui-input',
+                                       'required',
+                                       'autocomplete' => 'off',
+                                       'tabindex' => 1, // tab in before the 
edit textarea
+                                       'autofocus' => $autofocus // the input 
should have autofocus in special cases
+                               )
+                       ) .
                        "</p>\n" .
                        Xml::element( 'input', array(
                                'type'  => 'hidden',
diff --git a/ReCaptcha.class.php b/ReCaptcha.class.php
index cd274a9..bb88507 100644
--- a/ReCaptcha.class.php
+++ b/ReCaptcha.class.php
@@ -9,7 +9,7 @@
         * If $this->recaptcha_error is set, it will display an error in the 
widget.
         *
         */
-       function getForm() {
+       function getForm( $autofocus = false ) {
                global $wgReCaptchaPublicKey, $wgReCaptchaTheme;
 
                $useHttps = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] 
== 'on' );

-- 
To view, visit https://gerrit.wikimedia.org/r/185089
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id090a9fdb078d188f1890fad9b5029674b88094b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ConfirmEdit
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to