* (bug 12142) CAPTCHA group exceptions only apply to edits
[toast/cookiecaptcha.git] / ConfirmEdit_body.php
1 <?php
2
3 class ConfirmEditHooks {
4         static function getInstance() {
5                 global $wgCaptcha, $wgCaptchaClass, $wgExtensionMessagesFiles;
6                 static $done = false;
7                 if ( !$done ) {
8                         $done = true;
9                         wfLoadExtensionMessages( 'ConfirmEdit' );
10                         if ( isset( $wgExtensionMessagesFiles[$wgCaptchaClass] ) ) {
11                                 wfLoadExtensionMessages( $wgCaptchaClass );
12                         }
13                         $wgCaptcha = new $wgCaptchaClass;
14                 }
15                 return $wgCaptcha;
16         }
17
18         static function confirmEdit( &$editPage, $newtext, $section ) {
19                 return self::getInstance()->confirmEdit( $editPage, $newtext, $section );
20         }
21
22         static function confirmEditMerged( &$editPage, $newtext ) {
23                 return self::getInstance()->confirmEditMerged( $editPage, $newtext );
24         }
25         
26         static function confirmEditAPI( &$editPage, $newtext, &$resultArr ) {
27                 return self::getInstance()->confirmEditAPI( $editPage, $newtext, $resultArr );
28         }
29
30         static function injectUserCreate( &$template ) {
31                 return self::getInstance()->injectUserCreate( $template );
32         }
33
34         static function confirmUserCreate( $u, &$message ) {
35                 return self::getInstance()->confirmUserCreate( $u, $message );
36         }
37
38         static function triggerUserLogin( $user, $password, $retval ) {
39                 return self::getInstance()->triggerUserLogin( $user, $password, $retval );
40         }
41
42         static function injectUserLogin( &$template ) {
43                 return self::getInstance()->injectUserLogin( $template );
44         }
45
46         static function confirmUserLogin( $u, $pass, &$retval ) {
47                 return self::getInstance()->confirmUserLogin( $u, $pass, $retval );
48         }
49 }
50
51 class CaptchaSpecialPage extends UnlistedSpecialPage {
52         function execute( $par ) {
53                 $this->setHeaders();
54                 $instance = ConfirmEditHooks::getInstance();
55                 switch( $par ) {
56                 case "image":
57                         return $instance->showImage();
58                 case "help":
59                 default:
60                         return $instance->showHelp();
61                 }
62         }
63 }
64
65
66 class SimpleCaptcha {
67         function SimpleCaptcha() {
68                 global $wgCaptchaStorageClass;
69                 $this->storage = new $wgCaptchaStorageClass;
70         }
71         
72         function getCaptcha() {
73                 $a = mt_rand(0, 100);
74                 $b = mt_rand(0, 10);
75                 $op = mt_rand(0, 1) ? '+' : '-';
76
77                 $test = "$a $op $b";
78                 $answer = ($op == '+') ? ($a + $b) : ($a - $b);
79                 return array('question' => $test, 'answer' => $answer);
80         }
81         
82         function addCaptchaAPI(&$resultArr) {
83                 $captcha = $this->getCaptcha();
84                 $index = $this->storeCaptcha( $captcha );
85                 $resultArr['captcha']['type'] = 'simple';
86                 $resultArr['captcha']['mime'] = 'text/plain';
87                 $resultArr['captcha']['id'] = $index;
88                 $resultArr['captcha']['question'] = $captcha['question'];
89         }
90         
91         /**
92          * Insert a captcha prompt into the edit form.
93          * This sample implementation generates a simple arithmetic operation;
94          * it would be easy to defeat by machine.
95          *
96          * Override this!
97          *
98          * @return string HTML
99          */
100         function getForm() {
101                 $captcha = $this->getCaptcha();
102                 $index = $this->storeCaptcha( $captcha );
103
104                 return "<p><label for=\"wpCaptchaWord\">{$captcha['question']}</label> = " .
105                         wfElement( 'input', array(
106                                 'name' => 'wpCaptchaWord',
107                                 'id'   => 'wpCaptchaWord',
108                                 'tabindex' => 1 ) ) . // tab in before the edit textarea
109                         "</p>\n" .
110                         wfElement( 'input', array(
111                                 'type'  => 'hidden',
112                                 'name'  => 'wpCaptchaId',
113                                 'id'    => 'wpCaptchaId',
114                                 'value' => $index ) );
115         }
116
117         /**
118          * Insert the captcha prompt into an edit form.
119          * @param OutputPage $out
120          */
121         function editCallback( &$out ) {
122                 $out->addWikiText( $this->getMessage( $this->action ) );
123                 $out->addHTML( $this->getForm() );
124         }
125
126         /**
127          * Show a message asking the user to enter a captcha on edit
128          * The result will be treated as wiki text
129          *
130          * @param $action Action being performed
131          * @return string
132          */
133         function getMessage( $action ) {
134                 $name = 'captcha-' . $action;
135                 $text = wfMsg( $name );
136                 # Obtain a more tailored message, if possible, otherwise, fall back to
137                 # the default for edits
138                 return wfEmptyMsg( $name, $text ) ? wfMsg( 'captcha-edit' ) : $text;
139         }
140
141         /**
142          * Inject whazawhoo
143          * @fixme if multiple thingies insert a header, could break
144          * @param SimpleTemplate $template
145          * @return bool true to keep running callbacks
146          */
147         function injectUserCreate( &$template ) {
148                 global $wgCaptchaTriggers, $wgOut, $wgUser;
149                 if( $wgCaptchaTriggers['createaccount'] ) {
150                         if( $wgUser->isAllowed( 'skipcaptcha' ) ) {
151                                 wfDebug( "ConfirmEdit: user group allows skipping captcha on account creation\n" );
152                                 return true;
153                         }
154                         $template->set( 'header',
155                                 "<div class='captcha'>" .
156                                 $wgOut->parse( $this->getMessage( 'createaccount' ) ) .
157                                 $this->getForm() .
158                                 "</div>\n" );
159                 }
160                 return true;
161         }
162
163         /**
164          * Inject a captcha into the user login form after a failed
165          * password attempt as a speedbump for mass attacks.
166          * @fixme if multiple thingies insert a header, could break
167          * @param SimpleTemplate $template
168          * @return bool true to keep running callbacks
169          */
170         function injectUserLogin( &$template ) {
171                 if( $this->isBadLoginTriggered() ) {
172                         global $wgOut;
173                         $template->set( 'header',
174                                 "<div class='captcha'>" .
175                                 $wgOut->parse( $this->getMessage( 'badlogin' ) ) .
176                                 $this->getForm() .
177                                 "</div>\n" );
178                 }
179                 return true;
180         }
181         
182         /**
183          * When a bad login attempt is made, increment an expiring counter
184          * in the memcache cloud. Later checks for this may trigger a
185          * captcha display to prevent too many hits from the same place.
186          * @param User $user
187          * @param string $password
188          * @param int $retval authentication return value
189          * @return bool true to keep running callbacks
190          */
191         function triggerUserLogin( $user, $password, $retval ) {
192                 global $wgCaptchaTriggers, $wgCaptchaBadLoginExpiration, $wgMemc;
193                 if( $retval == LoginForm::WRONG_PASS && $wgCaptchaTriggers['badlogin'] ) {
194                         $key = $this->badLoginKey();
195                         $count = $wgMemc->get( $key );
196                         if( !$count ) {
197                                 $wgMemc->add( $key, 0, $wgCaptchaBadLoginExpiration );
198                         }
199                         $count = $wgMemc->incr( $key );
200                 }
201                 return true;
202         }
203         
204         /**
205          * Check if a bad login has already been registered for this
206          * IP address. If so, require a captcha.
207          * @return bool
208          * @access private
209          */
210         function isBadLoginTriggered() {
211                 global $wgMemc, $wgCaptchaBadLoginAttempts;
212                 return intval( $wgMemc->get( $this->badLoginKey() ) ) >= $wgCaptchaBadLoginAttempts;
213         }
214         
215         /**
216          * Internal cache key for badlogin checks.
217          * @return string
218          * @access private
219          */
220         function badLoginKey() {
221                 return wfMemcKey( 'captcha', 'badlogin', 'ip', wfGetIP() );
222         }
223         
224         /**
225          * Check if the submitted form matches the captcha session data provided
226          * by the plugin when the form was generated.
227          *
228          * Override this!
229          *
230          * @param string $answer
231          * @param array $info
232          * @return bool
233          */
234         function keyMatch( $answer, $info ) {
235                 return $answer == $info['answer'];
236         }
237
238         // ----------------------------------
239
240         /**
241          * @param EditPage $editPage
242          * @param string $action (edit/create/addurl...)
243          * @return bool true if action triggers captcha on editPage's namespace
244          */
245         function captchaTriggers( &$editPage, $action) {
246                 global $wgCaptchaTriggers, $wgCaptchaTriggersOnNamespace;       
247                 //Special config for this NS?
248                 if (isset( $wgCaptchaTriggersOnNamespace[$editPage->mTitle->getNamespace()][$action] ) )
249                         return $wgCaptchaTriggersOnNamespace[$editPage->mTitle->getNamespace()][$action];
250
251                 return ( !empty( $wgCaptchaTriggers[$action] ) ); //Default
252         }
253
254
255         /**
256          * @param EditPage $editPage
257          * @param string $newtext
258          * @param string $section
259          * @return bool true if the captcha should run
260          */
261         function shouldCheck( &$editPage, $newtext, $section, $merged = false ) {
262                 $this->trigger = '';
263                 $title = $editPage->mArticle->getTitle();
264
265                 global $wgUser;
266                 if( $wgUser->isAllowed( 'skipcaptcha' ) ) {
267                         wfDebug( "ConfirmEdit: user group allows skipping captcha\n" );
268                         return false;
269                 }
270                 global $wgCaptchaWhitelistIP;
271                 if( !empty( $wgCaptchaWhitelistIP ) ) {
272                         $ip = wfGetIp();
273                         foreach ( $wgCaptchaWhitelistIP as $range ) {
274                                 if ( IP::isInRange( $ip, $range ) ) {
275                                         return false;
276                                 }
277                         }
278                 }
279
280
281                 global $wgEmailAuthentication, $ceAllowConfirmedEmail;
282                 if( $wgEmailAuthentication && $ceAllowConfirmedEmail &&
283                         $wgUser->isEmailConfirmed() ) {
284                         wfDebug( "ConfirmEdit: user has confirmed mail, skipping captcha\n" );
285                         return false;
286                 }
287
288                 if( $this->captchaTriggers( $editPage, 'edit' ) ) {
289                         // Check on all edits
290                         global $wgUser;
291                         $this->trigger = sprintf( "edit trigger by '%s' at [[%s]]",
292                                 $wgUser->getName(),
293                                 $title->getPrefixedText() );
294                         $this->action = 'edit';
295                         wfDebug( "ConfirmEdit: checking all edits...\n" );
296                         return true;
297                 }
298
299                 if( $this->captchaTriggers( $editPage, 'create' )  && !$editPage->mTitle->exists() ) {
300                         //Check if creating a page
301                         global $wgUser;
302                         $this->trigger = sprintf( "Create trigger by '%s' at [[%s]]",
303                                 $wgUser->getName(),
304                                 $title->getPrefixedText() );
305                         $this->action = 'create';
306                         wfDebug( "ConfirmEdit: checking on page creation...\n" );
307                         return true;
308                 }
309
310                 if( $this->captchaTriggers( $editPage, 'addurl' ) ) {
311                         // Only check edits that add URLs
312                         if ( $merged ) {
313                                 // Get links from the database
314                                 $oldLinks = $this->getLinksFromTracker( $title );
315                                 // Share a parse operation with Article::doEdit()
316                                 $editInfo = $editPage->mArticle->prepareTextForEdit( $newtext );
317                                 $newLinks = array_keys( $editInfo->output->getExternalLinks() );
318                         } else {
319                                 // Get link changes in the slowest way known to man
320                                 $oldtext = $this->loadText( $editPage, $section );
321                                 $oldLinks = $this->findLinks( $oldtext );
322                                 $newLinks = $this->findLinks( $newtext );
323                         }
324
325                         $unknownLinks = array_filter( $newLinks, array( &$this, 'filterLink' ) );
326                         $addedLinks = array_diff( $unknownLinks, $oldLinks );
327                         $numLinks = count( $addedLinks );
328
329                         if( $numLinks > 0 ) {
330                                 global $wgUser;
331                                 $this->trigger = sprintf( "%dx url trigger by '%s' at [[%s]]: %s",
332                                         $numLinks,
333                                         $wgUser->getName(),
334                                         $title->getPrefixedText(),
335                                         implode( ", ", $addedLinks ) );
336                                 $this->action = 'addurl';
337                                 return true;
338                         }
339                 }
340
341                 global $wgCaptchaRegexes;
342                 if( !empty( $wgCaptchaRegexes ) ) {
343                         // Custom regex checks
344                         $oldtext = $this->loadText( $editPage, $section );
345
346                         foreach( $wgCaptchaRegexes as $regex ) {
347                                 $newMatches = array();
348                                 if( preg_match_all( $regex, $newtext, $newMatches ) ) {
349                                         $oldMatches = array();
350                                         preg_match_all( $regex, $oldtext, $oldMatches );
351
352                                         $addedMatches = array_diff( $newMatches[0], $oldMatches[0] );
353
354                                         $numHits = count( $addedMatches );
355                                         if( $numHits > 0 ) {
356                                                 global $wgUser;
357                                                 $this->trigger = sprintf( "%dx %s at [[%s]]: %s",
358                                                         $numHits,
359                                                         $regex,
360                                                         $wgUser->getName(),
361                                                         $title->getPrefixedText(),
362                                                         implode( ", ", $addedMatches ) );
363                                                 $this->action = 'edit';
364                                                 return true;
365                                         }
366                                 }
367                         }
368                 }
369
370                 return false;
371         }
372
373         /**
374          * Filter callback function for URL whitelisting
375          * @param string url to check
376          * @return bool true if unknown, false if whitelisted
377          * @access private
378          */
379         function filterLink( $url ) {
380                 global $wgCaptchaWhitelist;
381                 $source = wfMsgForContent( 'captcha-addurl-whitelist' );
382
383                 $whitelist = wfEmptyMsg( 'captcha-addurl-whitelist', $source ) 
384                         ? false
385                         : $this->buildRegexes( explode( "\n", $source ) );
386
387                 $cwl = $wgCaptchaWhitelist !== false ? preg_match( $wgCaptchaWhitelist, $url ) : false;
388                 $wl  = $whitelist          !== false ? preg_match( $whitelist, $url )          : false;
389
390                 return !( $cwl || $wl );
391         }
392
393         /**
394          * Build regex from whitelist
395          * @param string lines from [[MediaWiki:Captcha-addurl-whitelist]]
396          * @return string Regex or bool false if whitelist is empty
397          * @access private
398          */
399         function buildRegexes( $lines ) {
400                 # Code duplicated from the SpamBlacklist extension (r19197)
401
402                 # Strip comments and whitespace, then remove blanks
403                 $lines = array_filter( array_map( 'trim', preg_replace( '/#.*$/', '', $lines ) ) );
404
405                 # No lines, don't make a regex which will match everything
406                 if ( count( $lines ) == 0 ) {
407                         wfDebug( "No lines\n" );
408                         return false;
409                 } else {
410                         # Make regex
411                         # It's faster using the S modifier even though it will usually only be run once
412                         //$regex = 'http://+[a-z0-9_\-.]*(' . implode( '|', $lines ) . ')';
413                         //return '/' . str_replace( '/', '\/', preg_replace('|\\\*/|', '/', $regex) ) . '/Si';
414                         $regexes = '';
415                         $regexStart = '/^https?:\/\/+[a-z0-9_\-.]*(';
416                         $regexEnd = ')/Si';
417                         $regexMax = 4096;
418                         $build = false;
419                         foreach( $lines as $line ) {
420                                 // FIXME: not very robust size check, but should work. :)
421                                 if( $build === false ) {
422                                         $build = $line;
423                                 } elseif( strlen( $build ) + strlen( $line ) > $regexMax ) {
424                                         $regexes .= $regexStart .
425                                                 str_replace( '/', '\/', preg_replace('|\\\*/|', '/', $build) ) .
426                                                 $regexEnd;
427                                         $build = $line;
428                                 } else {
429                                         $build .= '|' . $line;
430                                 }
431                         }
432                         if( $build !== false ) {
433                                 $regexes .= $regexStart .
434                                         str_replace( '/', '\/', preg_replace('|\\\*/|', '/', $build) ) .
435                                         $regexEnd;
436                         }
437                         return $regexes;
438                 }
439         }
440
441         /**
442          * Load external links from the externallinks table
443          */
444         function getLinksFromTracker( $title ) {
445                 $dbr =& wfGetDB( DB_SLAVE );
446                 $id = $title->getArticleId(); // should be zero queries
447                 $res = $dbr->select( 'externallinks', array( 'el_to' ), 
448                         array( 'el_from' => $id ), __METHOD__ );
449                 $links = array();
450                 while ( $row = $dbr->fetchObject( $res ) ) {
451                         $links[] = $row->el_to;
452                 }
453                 return $links;
454         }
455         
456         /**
457          * Backend function for confirmEdit() and confirmEditAPI()
458          * @return bool false if the CAPTCHA is rejected, true otherwise
459          */
460         private function doConfirmEdit( &$editPage, $newtext, $section, $merged = false ) {
461                 if( $this->shouldCheck( $editPage, $newtext, $section, $merged ) ) {
462                         if( $this->passCaptcha() ) {
463                                 return true;
464                         } else {
465                                 return false;
466                         }
467                 } else {
468                         wfDebug( "ConfirmEdit: no need to show captcha.\n" );
469                         return true;
470                 }
471         }
472
473         /**
474          * The main callback run on edit attempts.
475          * @param EditPage $editPage
476          * @param string $newtext
477          * @param string $section
478          * @param bool $merged
479          * @return bool true to continue saving, false to abort and show a captcha form
480          */
481         function confirmEdit( &$editPage, $newtext, $section, $merged = false ) {
482                 global $wgTitle;
483                 if( is_null( $wgTitle ) ) {
484                         # API mode
485                         # The CAPTCHA was already checked and approved 
486                         return true;
487                 }
488                 if( !$this->doConfirmEdit( $editPage, $newtext, $section, $merged ) ) {
489                         $editPage->showEditForm( array( &$this, 'editCallback' ) );
490                         return false;
491                 }
492                 return true;
493         }
494
495         /**
496          * A more efficient edit filter callback based on the text after section merging
497          * @param EditPage $editPage
498          * @param string $newtext
499          */
500         function confirmEditMerged( &$editPage, $newtext ) {
501                 return $this->confirmEdit( $editPage, $newtext, false, true );
502         }
503         
504         
505         function confirmEditAPI( &$editPage, $newtext, &$resultArr) {
506                 if( !$this->doConfirmEdit( $editPage, $newtext, false, false ) ) {
507                         $this->addCaptchaAPI($resultArr);
508                         return false;
509                 }
510                 return true;
511         }
512
513         /**
514          * Hook for user creation form submissions.
515          * @param User $u
516          * @param string $message
517          * @return bool true to continue, false to abort user creation
518          */
519         function confirmUserCreate( $u, &$message ) {
520                 global $wgCaptchaTriggers, $wgUser;
521                 if( $wgCaptchaTriggers['createaccount'] ) {
522                         if( $wgUser->isAllowed( 'skipcaptcha' ) ) {
523                                 wfDebug( "ConfirmEdit: user group allows skipping captcha on account creation\n" );
524                                 return true;
525                         }
526                         $this->trigger = "new account '" . $u->getName() . "'";
527                         if( !$this->passCaptcha() ) {
528                                 $message = wfMsg( 'captcha-createaccount-fail' );
529                                 return false;
530                         }
531                 }
532                 return true;
533         }
534         
535         /**
536          * Hook for user login form submissions.
537          * @param User $u
538          * @param string $message
539          * @return bool true to continue, false to abort user creation
540          */
541         function confirmUserLogin( $u, $pass, &$retval ) {
542                 if( $this->isBadLoginTriggered() ) {
543                         $this->trigger = "post-badlogin login '" . $u->getName() . "'";
544                         if( !$this->passCaptcha() ) {
545                                 $message = wfMsg( 'captcha-badlogin-fail' );
546                                 // Emulate a bad-password return to confuse the shit out of attackers
547                                 $retval = LoginForm::WRONG_PASS;
548                                 return false;
549                         }
550                 }
551                 return true;
552         }
553
554         /**
555          * Given a required captcha run, test form input for correct
556          * input on the open session.
557          * @return bool if passed, false if failed or new session
558          */
559         function passCaptcha() {
560                 $info = $this->retrieveCaptcha();
561                 if( $info ) {
562                         global $wgRequest;
563                         if( $this->keyMatch( $wgRequest->getVal('wpCaptchaWord'), $info ) ) {
564                                 $this->log( "passed" );
565                                 $this->clearCaptcha( $info );
566                                 return true;
567                         } else {
568                                 $this->clearCaptcha( $info );
569                                 $this->log( "bad form input" );
570                                 return false;
571                         }
572                 } else {
573                         $this->log( "new captcha session" );
574                         return false;
575                 }
576         }
577
578         /**
579          * Log the status and any triggering info for debugging or statistics
580          * @param string $message
581          */
582         function log( $message ) {
583                 wfDebugLog( 'captcha', 'ConfirmEdit: ' . $message . '; ' .  $this->trigger );
584         }
585
586         /**
587          * Generate a captcha session ID and save the info in PHP's session storage.
588          * (Requires the user to have cookies enabled to get through the captcha.)
589          *
590          * A random ID is used so legit users can make edits in multiple tabs or
591          * windows without being unnecessarily hobbled by a serial order requirement.
592          * Pass the returned id value into the edit form as wpCaptchaId.
593          *
594          * @param array $info data to store
595          * @return string captcha ID key
596          */
597         function storeCaptcha( $info ) {
598                 if( !isset( $info['index'] ) ) {
599                         // Assign random index if we're not udpating
600                         $info['index'] = strval( mt_rand() );
601                 }
602                 $this->storage->store( $info['index'], $info );
603                 return $info['index'];
604         }
605
606         /**
607          * Fetch this session's captcha info.
608          * @return mixed array of info, or false if missing
609          */
610         function retrieveCaptcha() {
611                 global $wgRequest;
612                 $index = $wgRequest->getVal( 'wpCaptchaId' );
613                 return $this->storage->retrieve( $index );
614         }
615
616         /**
617          * Clear out existing captcha info from the session, to ensure
618          * it can't be reused.
619          */
620         function clearCaptcha( $info ) {
621                 $this->storage->clear( $info['index'] );
622         }
623
624         /**
625          * Retrieve the current version of the page or section being edited...
626          * @param EditPage $editPage
627          * @param string $section
628          * @return string
629          * @access private
630          */
631         function loadText( $editPage, $section ) {
632                 $rev = Revision::newFromTitle( $editPage->mTitle );
633                 if( is_null( $rev ) ) {
634                         return "";
635                 } else {
636                         $text = $rev->getText();
637                         if( $section != '' ) {
638                                 return Article::getSection( $text, $section );
639                         } else {
640                                 return $text;
641                         }
642                 }
643         }
644
645         /**
646          * Extract a list of all recognized HTTP links in the text.
647          * @param string $text
648          * @return array of strings
649          */
650         function findLinks( $text ) {
651                 global $wgParser, $wgTitle, $wgUser;
652
653                 $options = new ParserOptions();
654                 $text = $wgParser->preSaveTransform( $text, $wgTitle, $wgUser, $options );
655                 $out = $wgParser->parse( $text, $wgTitle, $options );
656
657                 return array_keys( $out->getExternalLinks() );
658         }
659
660         /**
661          * Show a page explaining what this wacky thing is.
662          */
663         function showHelp() {
664                 global $wgOut, $ceAllowConfirmedEmail;
665                 $wgOut->setPageTitle( wfMsg( 'captchahelp-title' ) );
666                 $wgOut->addWikiText( wfMsg( 'captchahelp-text' ) );
667                 if ( $this->storage->cookiesNeeded() ) {
668                         $wgOut->addWikiText( wfMsg( 'captchahelp-cookies-needed' ) );
669                 }
670         }
671
672 }
673
674 class CaptchaSessionStore {
675         function store( $index, $info ) {
676                 $_SESSION['captcha' . $info['index']] = $info;
677         }
678         
679         function retrieve( $index ) {
680                 if( isset( $_SESSION['captcha' . $index] ) ) {
681                         return $_SESSION['captcha' . $index];
682                 } else {
683                         return false;
684                 }
685         }
686         
687         function clear( $index ) {
688                 unset( $_SESSION['captcha' . $index] );
689         }
690
691         function cookiesNeeded() {
692                 return true;
693         }
694 }
695
696 class CaptchaCacheStore {
697         function store( $index, $info ) {
698                 global $wgMemc, $wgCaptchaSessionExpiration;
699                 $wgMemc->set( wfMemcKey( 'captcha', $index ), $info,
700                         $wgCaptchaSessionExpiration );
701         }
702
703         function retrieve( $index ) {
704                 global $wgMemc;
705                 $info = $wgMemc->get( wfMemcKey( 'captcha', $index ) );
706                 if( $info ) {
707                         return $info;
708                 } else {
709                         return false;
710                 }
711         }
712         
713         function clear( $index ) {
714                 global $wgMemc;
715                 $wgMemc->delete( wfMemcKey( 'captcha', $index ) );
716         }
717
718         function cookiesNeeded() {
719                 return false;
720         }
721 }
722