3 class CookieCaptcha extends SimpleCaptcha {
5 * Check if the submitted form matches the captcha session data provided
6 * by the plugin when the form was generated.
8 * @param string $answer
12 function keyMatch( $answer, $info ) {
13 global $wgCaptchaCookieName;
14 if (isset($_COOKIE[$wgCaptchaCookieName])) {
15 wfDebug( "CookieCaptcha: Found cookie\n" );
18 wfDebug( "CookieCaptcha: Didn't find cookie...\n" );
23 function retrieveCaptcha() {
28 function addCaptchaAPI( &$resultArr ) {
29 $info = $this->pickImage();
31 $resultArr['captcha']['error'] = 'Out of images';
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 ) );
44 * Insert the captcha prompt into the edit form.
47 global $wgCaptchaCookieName, $wgCaptchaCookieImage, $wgCaptchaCookieAlt, $wgCaptchaCookieStyle;
49 Html::element( 'img', array(
50 'src' => $wgCaptchaCookieImage,
51 'alt' => $wgCaptchaCookieAlt,
52 'style' => $wgCaptchaCookieStyle ) ) .
57 * Show a message asking the user to enter a captcha on edit
58 * The result will be treated as wiki text
60 * @param $action string Action being performed
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;