Index: trunk/extensions/SpecialForm/SpecialForm.body.php |
— | — | @@ -98,7 +98,7 @@ |
99 | 99 | } |
100 | 100 | |
101 | 101 | function showForm($form, $errmsg = NULL) { |
102 | | - global $wgOut, $wgRequest, $wgParser, $wgTitle; |
| 102 | + global $wgOut, $wgRequest, $wgParser, $wgTitle, $wgUser, $wgSpecialFormRecaptcha; |
103 | 103 | |
104 | 104 | $self = SpecialPage::getTitleFor(wfMsgForContent('form') . '/' . $form->name); |
105 | 105 | |
— | — | @@ -127,6 +127,12 @@ |
128 | 128 | $wgOut->addHtml($field->render($wgRequest->getText($field->name)) . wfElement('br') . "\n"); |
129 | 129 | } |
130 | 130 | |
| 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 | + |
131 | 137 | $wgOut->addHtml(wfElement('input', array('type' => 'submit', |
132 | 138 | 'value' => wfMsg('formsave')))); |
133 | 139 | |
— | — | @@ -135,7 +141,24 @@ |
136 | 142 | |
137 | 143 | function createArticle($form) { |
138 | 144 | |
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 | + } |
140 | 163 | |
141 | 164 | # Check for required fields |
142 | 165 | |
Index: trunk/extensions/SpecialForm/SpecialForm.i18n.php |
— | — | @@ -41,6 +41,7 @@ |
42 | 42 | 'formarticleexists' => 'Page exists', |
43 | 43 | 'formarticleexiststext' => 'The page [[$1]] already exists.', |
44 | 44 | 'formbadpagename' => 'Bad page name', |
| 45 | + 'formbadrecaptcha' => 'Incorrect values for reCaptcha. Try again.', |
45 | 46 | 'formbadpagenametext' => 'The form data you entered makes a bad page name, "$1".', |
46 | 47 | 'formrequiredfieldpluralerror' => 'The fields $1 are required for this form. |
47 | 48 | Please fill them in.', |
Index: trunk/extensions/SpecialForm/SpecialForm.setup.php |
— | — | @@ -45,6 +45,10 @@ |
46 | 46 | 'descriptionmsg' => 'form-desc', |
47 | 47 | ); |
48 | 48 | |
| 49 | +# Use recaptcha; default to false |
| 50 | + |
| 51 | +$wgSpecialFormRecaptcha = false; |
| 52 | + |
49 | 53 | function formLocalizedPageName(&$specialPageArray, $code) { |
50 | 54 | # The localized title of the special page is among the messages of the extension: |
51 | 55 | SpecialForm::loadMessages(); |