Made CAPTCHA for guests' page editing work with the non-AJAX interface
authorDan
Fri, 28 Dec 2007 00:03:27 -0500
changeset 337 491518997ae5
parent 336 bfa2e9c23f03
child 340 993fb077944f
Made CAPTCHA for guests' page editing work with the non-AJAX interface
index.php
language/english/core.json
--- a/index.php	Thu Dec 27 23:32:11 2007 -0500
+++ b/index.php	Fri Dec 28 00:03:27 2007 -0500
@@ -130,13 +130,32 @@
       }
       if(isset($_POST['_save']))
       {
-        $e = PageUtils::savepage($paths->page_id, $paths->namespace, $_POST['page_text'], $_POST['edit_summary'], isset($_POST['minor']));
-        if ( $e == 'good' )
+        $captcha_valid = true;
+        if ( !$session->user_logged_in && getConfig('guest_edit_require_captcha') == '1' )
         {
-          redirect(makeUrl($paths->page), $lang->get('editor_msg_save_success_title'), $lang->get('editor_msg_save_success_body'), 3);
+          $captcha_valid = false;
+          if ( isset($_POST['captcha_id']) && isset($_POST['captcha_code']) )
+          {
+            $hash_correct = strtolower($session->get_captcha($_POST['captcha_id']));
+            $hash_input   = strtolower($_POST['captcha_code']);
+            if ( $hash_input === $hash_correct )
+              $captcha_valid = true;
+          }
+        }
+        if ( $captcha_valid )
+        {
+          $e = PageUtils::savepage($paths->page_id, $paths->namespace, $_POST['page_text'], $_POST['edit_summary'], isset($_POST['minor']));
+          if ( $e == 'good' )
+          {
+            redirect(makeUrl($paths->page), $lang->get('editor_msg_save_success_title'), $lang->get('editor_msg_save_success_body'), 3);
+          }
         }
       }
       $template->header();
+      if ( isset($captcha_valid) )
+      {
+        echo '<div class="usermessage">' . $lang->get('editor_err_captcha_wrong') . '</div>';
+      }
       if(isset($_POST['_preview']))
       {
         $text = $_POST['page_text'];
@@ -153,8 +172,21 @@
         <textarea name="page_text" rows="20" cols="60" style="width: 97%;">'.$text.'</textarea><br />
         <br />
         ';
-      if($paths->wiki_mode)
-        echo $lang->get('editor_lbl_edit_summary') . ' <input name="edit_summary" type="text" size="40" /><br /><label><input type="checkbox" name="minor" /> This is a minor edit</label><br />';  
+      echo $lang->get('editor_lbl_edit_summary') . ' <input name="edit_summary" type="text" size="40" /><br /><label><input type="checkbox" name="minor" /> ' . $lang->get('editor_lbl_minor_edit_field') . '</label><br />';
+      if ( !$session->user_logged_in && getConfig('guest_edit_require_captcha') == '1' )
+      {
+        echo '<br /><table border="0"><tr><td>';
+        echo '<b>' . $lang->get('editor_lbl_field_captcha') . '</b><br />'
+             . '<br />'
+             . $lang->get('editor_msg_captcha_pleaseenter') . '<br /><br />'
+             . $lang->get('editor_msg_captcha_blind');
+        echo '</td><td>';
+        $hash = $session->make_captcha();
+        echo '<img src="' . makeUrlNS('Special', "Captcha/$hash") . '" onclick="this.src+=\'/a\'" style="cursor: pointer;" /><br />';
+        echo '<input type="hidden" name="captcha_id" value="' . $hash . '" />';
+        echo $lang->get('editor_lbl_field_captcha_code') . ' <input type="text" name="captcha_code" value="" size="9" />';
+        echo '</td></tr></table>';
+      }
       echo '<br />
           <input type="submit" name="_save"    value="' . $lang->get('editor_btn_save') . '" style="font-weight: bold;" />
           <input type="submit" name="_preview" value="' . $lang->get('editor_btn_preview') . '" />
--- a/language/english/core.json	Thu Dec 27 23:32:11 2007 -0500
+++ b/language/english/core.json	Fri Dec 28 00:03:27 2007 -0500
@@ -258,7 +258,7 @@
       msg_save_success_title: 'Changes saved',
       msg_save_success_body: 'Your changes to this page have been saved. Redirecting...',
       
-      msg_captcha_pleaseenter: 'Please enter the code shown in the image to the right into the text box. This process helps to ensure that this page is not being edited by an automated bot. If the image to the right is illegible, you can regenerate it by clicking on the image.',
+      msg_captcha_pleaseenter: 'Please enter the code shown in the image to the right into the text box. This process helps to ensure that this page is not being edited by an automated bot. If the image to the right is illegible, you can regenerate it by clicking on the image (only works if your browser supports Javascript).',
       msg_captcha_blind: 'If you are visually impaired or otherwise cannot read the text shown to the right, please contact the site management and they will be able to make your requested edits.',
       lbl_field_captcha: 'Visual confirmation',
       lbl_field_captcha_code: 'Code:',