Session cookie is configurable. Added apache2 config example.
[toast/cookiecaptcha.git] / CookieCaptcha.class.php
index 1ab28797a99497be8a70a37e87042b796a04529b..b96ac4c674db1774ca47df8333bf1fcbce89471d 100644 (file)
@@ -9,22 +9,20 @@ class CookieCaptcha extends SimpleCaptcha {
         * @param array $info
         * @return bool
         */
-       /*
        function keyMatch( $answer, $info ) {
-               global $wgCaptchaSecret;
-
-               $digest = $wgCaptchaSecret . $info['salt'] . $answer . $wgCaptchaSecret . $info['salt'];
-               $answerHash = substr( md5( $digest ), 0, 16 );
-
-               if ( $answerHash == $info['hash'] ) {
-                       wfDebug( "FancyCaptcha: answer hash matches expected {$info['hash']}\n" );
+               global $wgCaptchaCookieName;
+               if (isset($_COOKIE[$wgCaptchaCookieName])) {
+                       wfDebug( "CookieCaptcha: Found cookie\n" );
                        return true;
                } else {
-                       wfDebug( "FancyCaptcha: answer hashes to $answerHash, expected {$info['hash']}\n" );
+                       wfDebug( "CookieCaptcha: Didn't find cookie...\n" );
                        return false;
                }
        }
-        */
+
+       function retrieveCaptcha() {
+               return true;
+       }
 
        /*
        function addCaptchaAPI( &$resultArr ) {
@@ -45,49 +43,15 @@ class CookieCaptcha extends SimpleCaptcha {
        /**
         * Insert the captcha prompt into the edit form.
         */
-    /*
        function getForm() {
-               $info = $this->pickImage();
-               if ( !$info ) {
-                       throw new MWException( "Ran out of captcha images" );
-               }
-
-               // Generate a random key for use of this captcha image in this session.
-               // This is needed so multiple edits in separate tabs or windows can
-               // go through without extra pain.
-               $index = $this->storeCaptcha( $info );
-
-               wfDebug( "Captcha id $index using hash ${info['hash']}, salt ${info['salt']}.\n" );
-
-               $title = SpecialPage::getTitleFor( 'Captcha', 'image' );
-
+               global $wgCaptchaCookieName, $wgCaptchaCookieImage, $wgCaptchaCookieAlt, $wgCaptchaCookieStyle;
                return "<p>" .
                        Html::element( 'img', array(
-                               'src'    => $title->getLocalUrl( 'wpCaptchaId=' . urlencode( $index ) ),
-                               'width'  => $info['width'],
-                               'height' => $info['height'],
-                               'alt'    => '' ) ) .
-                       "</p>\n" .
-                       Html::element( 'input', array(
-                               'type'  => 'hidden',
-                               'name'  => 'wpCaptchaId',
-                               'id'    => 'wpCaptchaId',
-                               'value' => $index ) ) .
-                       '<p>' .
-                       Html::element( 'label', array(
-                               'for' => 'wpCaptchaWord',
-                       ), parent::getMessage( 'label' ) . wfMessage( 'colon-separator' )->text() ) .
-                       Html::element( 'input', array(
-                               'name' => 'wpCaptchaWord',
-                               'id'   => 'wpCaptchaWord',
-                               'type' => 'text',
-                               'autocorrect' => 'off',
-                               'autocapitalize' => 'off',
-                               'required' => 'required',
-                               'tabindex' => 1 ) ) . // tab in before the edit textarea
+                               'src'    => $wgCaptchaCookieImage,
+                               'alt'    => $wgCaptchaCookieAlt,
+                               'style'  => $wgCaptchaCookieStyle ) ) .
                        "</p>\n";
        }
-   */
 
        /**
         * Show a message asking the user to enter a captcha on edit