Session cookie is configurable. Added apache2 config example.
[toast/cookiecaptcha.git] / CookieCaptcha.class.php
1 <?php
2
3 class CookieCaptcha extends SimpleCaptcha {
4         /**
5          * Check if the submitted form matches the captcha session data provided
6          * by the plugin when the form was generated.
7          *
8          * @param string $answer
9          * @param array $info
10          * @return bool
11          */
12         function keyMatch( $answer, $info ) {
13                 global $wgCaptchaCookieName;
14                 if (isset($_COOKIE[$wgCaptchaCookieName])) {
15                         wfDebug( "CookieCaptcha: Found cookie\n" );
16                         return true;
17                 } else {
18                         wfDebug( "CookieCaptcha: Didn't find cookie...\n" );
19                         return false;
20                 }
21         }
22
23         function retrieveCaptcha() {
24                 return true;
25         }
26
27         /*
28         function addCaptchaAPI( &$resultArr ) {
29                 $info = $this->pickImage();
30                 if ( !$info ) {
31                         $resultArr['captcha']['error'] = 'Out of images';
32                         return;
33                 }
34                 $index = $this->storeCaptcha( $info );
35                 $title = SpecialPage::getTitleFor( 'Captcha', 'image' );
36                 $resultArr['captcha']['type'] = 'image';
37                 $resultArr['captcha']['mime'] = 'image/png';
38                 $resultArr['captcha']['id'] = $index;
39                 $resultArr['captcha']['url'] = $title->getLocalUrl( 'wpCaptchaId=' . urlencode( $index ) );
40         }
41          */
42
43         /**
44          * Insert the captcha prompt into the edit form.
45          */
46         function getForm() {
47                 global $wgCaptchaCookieName, $wgCaptchaCookieImage, $wgCaptchaCookieAlt, $wgCaptchaCookieStyle;
48                 return "<p>" .
49                         Html::element( 'img', array(
50                                 'src'    => $wgCaptchaCookieImage,
51                                 'alt'    => $wgCaptchaCookieAlt,
52                                 'style'  => $wgCaptchaCookieStyle ) ) .
53                         "</p>\n";
54         }
55
56         /**
57          * Show a message asking the user to enter a captcha on edit
58          * The result will be treated as wiki text
59          *
60          * @param $action string Action being performed
61          * @return string
62          */
63         /*
64         function getMessage( $action ) {
65                 $name = 'fancycaptcha-' . $action;
66                 $text = wfMessage( $name )->text();
67                 # Obtain a more tailored message, if possible, otherwise, fall back to
68                 # the default for edits
69                 return wfMessage( $name, $text )->isDisabled() ?
70                         wfMessage( 'fancycaptcha-edit' )->text() : $text;
71         }
72          */
73
74 }