From 843620632af2137dce0e044285964e9f725f809c Mon Sep 17 00:00:00 2001 From: Matthew Flaschen Date: Thu, 22 Oct 2015 10:46:13 -0400 Subject: [PATCH] Properly isolate reloading functionality, drop createacct name There can be more then one CAPTCHA on the page in AJAX scenarios, so it's important one reload not affect separate CAPTCHAs. Also, drop the legacy createacct naming, except for the one that is actually specific to CreateAccount. The following patch must be merged immediately after this: * Core - I8924d537cad3e39adace99fb20626247128d9bd9 Change-Id: I0e55a159efd66a73cd217d9a5e86b2bced90f57a --- FancyCaptcha/FancyCaptcha.class.php | 8 ++++---- FancyCaptcha/i18n/en.json | 2 ++ FancyCaptcha/i18n/qqq.json | 2 ++ .../resources/ext.confirmEdit.fancyCaptcha.js | 11 +++++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/FancyCaptcha/FancyCaptcha.class.php b/FancyCaptcha/FancyCaptcha.class.php index 1ae70f89b..24b910f4a 100644 --- a/FancyCaptcha/FancyCaptcha.class.php +++ b/FancyCaptcha/FancyCaptcha.class.php @@ -118,10 +118,10 @@ class FancyCaptcha extends SimpleCaptcha { Html::element( 'label', array( 'for' => 'wpCaptchaWord', ), - parent::getMessage( 'label' ) . ' ' . wfMessage( 'createacct-captcha' )->text() + parent::getMessage( 'label' ) . ' ' . wfMessage( 'fancycaptcha-captcha' )->text() ) . - Html::openElement( 'div', array( 'class' => 'mw-createacct-captcha-container' ) ) . - Html::openElement( 'div', array( 'class' => 'mw-createacct-captcha-and-reload' ) ) . + Html::openElement( 'div', array( 'class' => 'fancycaptcha-captcha-container' ) ) . + Html::openElement( 'div', array( 'class' => 'fancycaptcha-captcha-and-reload' ) ) . Html::openElement( 'div', array( 'class' => 'fancycaptcha-image-container' ) ) . Html::element( 'img', array( 'class' => 'fancycaptcha-image', @@ -140,7 +140,7 @@ class FancyCaptcha extends SimpleCaptcha { 'autocapitalize' => 'off', 'required' => 'required', 'tabindex' => $tabIndex, - 'placeholder' => wfMessage( 'createacct-imgcaptcha-ph' ) + 'placeholder' => wfMessage( 'fancycaptcha-imgcaptcha-ph' ) ) ); // tab in before the edit textarea if ( $this->action == 'usercreate' ) { diff --git a/FancyCaptcha/i18n/en.json b/FancyCaptcha/i18n/en.json index 4fd10cd6a..0cac618c8 100644 --- a/FancyCaptcha/i18n/en.json +++ b/FancyCaptcha/i18n/en.json @@ -5,9 +5,11 @@ "fancycaptcha-desc": "Fancy CAPTCHA generator for Confirm Edit", "fancycaptcha-addurl": "Your edit includes new external links.\nTo protect the wiki against automated spam, we kindly ask you to enter the words that appear below in the box ([[Special:Captcha/help|more info]]):", "fancycaptcha-badlogin": "To protect the wiki against automated password cracking, we kindly ask you to enter the words that appear below in the box ([[Special:Captcha/help|more info]]):", + "fancycaptcha-captcha": "Security check", "fancycaptcha-createaccount": "To protect the wiki against automated account creation, we kindly ask you to enter the words that appear below in the box ([[Special:Captcha/help|more info]]):", "fancycaptcha-create": "To create the page, please enter the words that appear below in the box ([[Special:Captcha/help|more info]]):", "fancycaptcha-edit": "To edit this page, please enter the words that appear below in the box ([[Special:Captcha/help|more info]]):", + "fancycaptcha-imgcaptcha-ph": "Enter the text you see above", "fancycaptcha-sendemail": "To protect the wiki against automated spamming, we kindly ask you to enter the words that appear below in the box ([[Special:Captcha/help|more info]]):", "fancycaptcha-reload-text": "Refresh", "apihelp-fancycaptchareload-description": "Get a new FancyCaptcha.", diff --git a/FancyCaptcha/i18n/qqq.json b/FancyCaptcha/i18n/qqq.json index 0d1651c3d..b2a00da49 100644 --- a/FancyCaptcha/i18n/qqq.json +++ b/FancyCaptcha/i18n/qqq.json @@ -10,9 +10,11 @@ "fancycaptcha-desc": "{{Optional}}\n{{desc}}", "fancycaptcha-addurl": "{{Related|ConfirmEdit-addurl}}", "fancycaptcha-badlogin": "{{Related|ConfirmEdit-badlogin}}", + "fancycaptcha-captcha": "Brief label for image CAPTCHA input field", "fancycaptcha-createaccount": "{{Related|ConfirmEdit-createaccount}}", "fancycaptcha-create": "{{Related|ConfirmEdit-create}}", "fancycaptcha-edit": "{{Related|ConfirmEdit-edit}}", + "fancycaptcha-imgcaptcha-ph": "Placeholder text for image CAPTCHA input field.", "fancycaptcha-sendemail": "{{Related|ConfirmEdit-sendemail}}", "fancycaptcha-reload-text": "Prompts a click to get a new FancyCaptcha image.\n{{Identical|Refresh}}", "apihelp-fancycaptchareload-description": "{{doc-apihelp-description|fancycaptchareload}}", diff --git a/FancyCaptcha/resources/ext.confirmEdit.fancyCaptcha.js b/FancyCaptcha/resources/ext.confirmEdit.fancyCaptcha.js index a8db72180..e2ded5b90 100644 --- a/FancyCaptcha/resources/ext.confirmEdit.fancyCaptcha.js +++ b/FancyCaptcha/resources/ext.confirmEdit.fancyCaptcha.js @@ -1,11 +1,13 @@ ( function ( $, mw ) { var api = new mw.Api(); $( document ).on( 'click', '.fancycaptcha-reload', function () { - var $this = $( this ), $captchaImage; + var $this = $( this ), $root, $captchaImage; + + $root = $this.closest( '.fancycaptcha-captcha-container' ); $this.addClass( 'fancycaptcha-reload-loading' ); - $captchaImage = $( '.fancycaptcha-image' ); + $captchaImage = $root.find( '.fancycaptcha-image' ); // AJAX request to get captcha index key api.post( { @@ -16,6 +18,7 @@ } ) .done( function ( xmldata ) { var imgSrc, captchaIndex; + captchaIndex = $( xmldata ).find( 'fancycaptchareload' ).attr( 'index' ); if ( typeof captchaIndex === 'string' ) { // replace index key with a new one for captcha image @@ -24,8 +27,8 @@ $captchaImage.attr( 'src', imgSrc ); // replace index key with a new one for hidden tag - $( '#wpCaptchaId' ).val( captchaIndex ); - $( '#wpCaptchaWord' ).val( '' ).focus(); + $root.find( '[name="wpCaptchaId"]' ).val( captchaIndex ); + $root.find( '[name="wpCaptchaWord"]' ).val( '' ).focus(); } } ) .always( function () {