r39168 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39167‎ | r39168 | r39169 >
Date:19:20, 11 August 2008
Author:evan
Status:old
Tags:
Comment:
Optionally show reCaptcha

I added a little bit of code to optionally show a recaptcha box. I
used the plain-old PHP interface, rather than the MediaWiki plugin,
since the plugin assumes that you're coming from a real edit page...
which we're not.
Modified paths:
  • /trunk/extensions/SpecialForm/SpecialForm.body.php (modified) (history)
  • /trunk/extensions/SpecialForm/SpecialForm.i18n.php (modified) (history)
  • /trunk/extensions/SpecialForm/SpecialForm.setup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SpecialForm/SpecialForm.body.php
@@ -98,7 +98,7 @@
9999 }
100100
101101 function showForm($form, $errmsg = NULL) {
102 - global $wgOut, $wgRequest, $wgParser, $wgTitle;
 102+ global $wgOut, $wgRequest, $wgParser, $wgTitle, $wgUser, $wgSpecialFormRecaptcha;
103103
104104 $self = SpecialPage::getTitleFor(wfMsgForContent('form') . '/' . $form->name);
105105
@@ -127,6 +127,12 @@
128128 $wgOut->addHtml($field->render($wgRequest->getText($field->name)) . wfElement('br') . "\n");
129129 }
130130
 131+ if ($wgUser->getId() == 0 && $wgSpecialFormRecaptcha) { # Anonymous user, use recaptcha
 132+ require_once('recaptchalib.php');
 133+ global $recaptcha_public_key; # same as used by Recaptcha plugin
 134+ $wgOut->addHtml(recaptcha_get_html($recaptcha_public_key));
 135+ }
 136+
131137 $wgOut->addHtml(wfElement('input', array('type' => 'submit',
132138 'value' => wfMsg('formsave'))));
133139
@@ -135,7 +141,24 @@
136142
137143 function createArticle($form) {
138144
139 - global $wgOut, $wgRequest, $wgLang;
 145+ global $wgOut, $wgRequest, $wgLang, $wgUser, $wgSpecialFormRecaptcha;
 146+
 147+ # Check recaptcha
 148+
 149+ if ($wgUser->getId() == 0 && $wgSpecialFormRecaptcha) {
 150+
 151+ require_once('recaptchalib.php');
 152+ global $recaptcha_private_key; # same as used by Recaptcha plugin
 153+ $resp = recaptcha_check_answer($recaptcha_private_key,
 154+ $_SERVER["REMOTE_ADDR"],
 155+ $wgRequest->getText("recaptcha_challenge_field"),
 156+ $wgRequest->getText("recaptcha_response_field"));
 157+
 158+ if (!$resp->is_valid) {
 159+ $this->showForm($form, wfMsg('formbadrecaptcha'));
 160+ return;
 161+ }
 162+ }
140163
141164 # Check for required fields
142165
Index: trunk/extensions/SpecialForm/SpecialForm.i18n.php
@@ -41,6 +41,7 @@
4242 'formarticleexists' => 'Page exists',
4343 'formarticleexiststext' => 'The page [[$1]] already exists.',
4444 'formbadpagename' => 'Bad page name',
 45+ 'formbadrecaptcha' => 'Incorrect values for reCaptcha. Try again.',
4546 'formbadpagenametext' => 'The form data you entered makes a bad page name, "$1".',
4647 'formrequiredfieldpluralerror' => 'The fields $1 are required for this form.
4748 Please fill them in.',
Index: trunk/extensions/SpecialForm/SpecialForm.setup.php
@@ -45,6 +45,10 @@
4646 'descriptionmsg' => 'form-desc',
4747 );
4848
 49+# Use recaptcha; default to false
 50+
 51+$wgSpecialFormRecaptcha = false;
 52+
4953 function formLocalizedPageName(&$specialPageArray, $code) {
5054 # The localized title of the special page is among the messages of the extension:
5155 SpecialForm::loadMessages();

Follow-up revisions

RevisionCommit summaryAuthorDate
r39169pybal (0.1+r39168-1) hardy; urgency=low...mark19:21, 11 August 2008
r39170(bug 13056) Fix for missing message (spotted by Lejonel)...siebrand19:32, 11 August 2008

Status & tagging log