Merge "Maintenance for ConfirmEdit extension."
[toast/cookiecaptcha.git] / Asirra.class.php
1 <?php
2 /**
3  * @author Bachsau
4  * @author Niklas Laxström
5  */
6
7 class Asirra extends SimpleCaptcha {
8         public $asirra_clientscript = 'http://challenge.asirra.com/js/AsirraClientSide.js';
9
10         // As we don't have to store anything but some other things to do,
11         // we're going to replace that constructor completely.
12         function __construct() {
13                 global $wgExtensionAssetsPath;
14                 $this->asirra_localpath = "$wgExtensionAssetsPath/ConfirmEdit";
15         }
16
17         function getForm() {
18                 global $wgOut;
19
20                 $wgOut->addModules( 'ext.confirmedit.asirra' );
21                 $js = Html::linkedScript( $this->asirra_clientscript );
22
23                 $message = Xml::encodeJsVar( wfMessage( 'asirra-createaccount-fail' )->plain() );
24                 $js .= Html::inlineScript( <<<JAVASCRIPT
25 var asirra_js_failed = '$message';
26 JAVASCRIPT
27                 );
28                 $js .=  '<noscript>' . wfMessage( 'asirra-nojs' )->parse() . '</noscript>';
29                 return $js;
30         }
31
32         function passCaptcha() {
33                 global $wgRequest;
34
35                 $ticket = $wgRequest->getVal( 'Asirra_Ticket' );
36                 $api = 'http://challenge.asirra.com/cgi/Asirra?';
37                 $params = array(
38                         'action' => 'ValidateTicket',
39                         'ticket' => $ticket,
40                 );
41
42                 $response = Http::get( $api . wfArrayToCgi( $params ) );
43                 $xml = simplexml_load_string( $response );
44                 $result = $xml->xpath( '/AsirraValidation/Result' );
45                 return strval( $result[0] ) === 'Pass';
46         }
47 }