class SimpleCaptcha {
- /**
- * @var CaptchaStore
- */
- protected $storage;
-
- function __construct() {
- global $wgCaptchaStorageClass;
- if( in_array( 'CaptchaStore', class_implements( $wgCaptchaStorageClass ) ) ) {
- $this->storage = new $wgCaptchaStorageClass;
- } else {
- throw new MWException( "Invalid CaptchaStore class $wgCaptchaStorageClass" );
- }
- }
-
function getCaptcha() {
$a = mt_rand( 0, 100 );
$b = mt_rand( 0, 10 );
$captcha = $this->getCaptcha();
$index = $this->storeCaptcha( $captcha );
- return "<p><label for=\"wpCaptchaWord\">{$captcha['question']}</label> = " .
+ // dir="ltr" is needed because otherwise it may say
+ // "5 - 20" instead of "20 - 5" and that would be wrong.
+ return "<p><label dir=\"ltr\" for=\"wpCaptchaWord\">{$captcha['question']}</label> = " .
Xml::element( 'input', array(
'name' => 'wpCaptchaWord',
'id' => 'wpCaptchaWord',
// Assign random index if we're not udpating
$info['index'] = strval( mt_rand() );
}
- $this->storage->store( $info['index'], $info );
+ CaptchaStore::get()->store( $info['index'], $info );
return $info['index'];
}
function retrieveCaptcha() {
global $wgRequest;
$index = $wgRequest->getVal( 'wpCaptchaId' );
- return $this->storage->retrieve( $index );
+ return CaptchaStore::get()->retrieve( $index );
}
/**
* it can't be reused.
*/
function clearCaptcha( $info ) {
- $this->storage->clear( $info['index'] );
+ CaptchaStore::get()->clear( $info['index'] );
}
/**
global $wgOut;
$wgOut->setPageTitle( wfMsg( 'captchahelp-title' ) );
$wgOut->addWikiText( wfMsg( 'captchahelp-text' ) );
- if ( $this->storage->cookiesNeeded() ) {
+ if ( CaptchaStore::get()->cookiesNeeded() ) {
$wgOut->addWikiText( wfMsg( 'captchahelp-cookies-needed' ) );
}
}