2011-12-09 16:10:27 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Bachsau
|
|
|
|
* @author Niklas Laxström
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Asirra extends SimpleCaptcha {
|
2013-05-03 19:45:38 +00:00
|
|
|
public $asirra_clientscript = '//challenge.asirra.com/js/AsirraClientSide.js';
|
2011-12-09 16:10:27 +00:00
|
|
|
|
|
|
|
// As we don't have to store anything but some other things to do,
|
|
|
|
// we're going to replace that constructor completely.
|
|
|
|
function __construct() {
|
2012-08-16 21:21:50 +00:00
|
|
|
global $wgExtensionAssetsPath;
|
2011-12-09 16:10:27 +00:00
|
|
|
$this->asirra_localpath = "$wgExtensionAssetsPath/ConfirmEdit";
|
|
|
|
}
|
|
|
|
|
|
|
|
function getForm() {
|
2012-08-16 21:21:50 +00:00
|
|
|
global $wgOut;
|
2011-12-09 16:10:27 +00:00
|
|
|
|
2013-01-17 02:00:09 +00:00
|
|
|
$wgOut->addModules( 'ext.confirmEdit.asirra' );
|
2011-12-09 16:10:27 +00:00
|
|
|
$js = Html::linkedScript( $this->asirra_clientscript );
|
|
|
|
|
|
|
|
$message = Xml::encodeJsVar( wfMessage( 'asirra-createaccount-fail' )->plain() );
|
|
|
|
$js .= Html::inlineScript( <<<JAVASCRIPT
|
|
|
|
var asirra_js_failed = '$message';
|
|
|
|
JAVASCRIPT
|
|
|
|
);
|
|
|
|
$js .= '<noscript>' . wfMessage( 'asirra-nojs' )->parse() . '</noscript>';
|
|
|
|
return $js;
|
|
|
|
}
|
|
|
|
|
2012-09-04 14:50:06 +00:00
|
|
|
function getMessage( $action ) {
|
|
|
|
$name = 'asirra-' . $action;
|
|
|
|
$text = wfMessage( $name )->text();
|
|
|
|
# Obtain a more tailored message, if possible, otherwise, fall
|
|
|
|
# back to the default for edits
|
|
|
|
return wfMessage( $name, $text )->isDisabled() ? wfMessage( 'asirra-edit' )->text() : $text;
|
|
|
|
}
|
|
|
|
|
2011-12-09 16:10:27 +00:00
|
|
|
function passCaptcha() {
|
|
|
|
global $wgRequest;
|
|
|
|
|
|
|
|
$ticket = $wgRequest->getVal( 'Asirra_Ticket' );
|
|
|
|
$api = 'http://challenge.asirra.com/cgi/Asirra?';
|
2012-01-12 08:58:40 +00:00
|
|
|
$params = array(
|
2011-12-09 16:10:27 +00:00
|
|
|
'action' => 'ValidateTicket',
|
|
|
|
'ticket' => $ticket,
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = Http::get( $api . wfArrayToCgi( $params ) );
|
|
|
|
$xml = simplexml_load_string( $response );
|
|
|
|
$result = $xml->xpath( '/AsirraValidation/Result' );
|
|
|
|
return strval( $result[0] ) === 'Pass';
|
|
|
|
}
|
|
|
|
}
|