2007-11-12 07:42:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class FancyCaptcha extends SimpleCaptcha {
|
2012-09-16 17:31:47 +00:00
|
|
|
/**
|
|
|
|
* @return FileBackend
|
|
|
|
*/
|
|
|
|
public function getBackend() {
|
|
|
|
global $wgCaptchaFileBackend, $wgCaptchaDirectory;
|
|
|
|
|
|
|
|
if ( $wgCaptchaFileBackend ) {
|
|
|
|
return FileBackendGroup::singleton()->get( $wgCaptchaFileBackend );
|
|
|
|
} else {
|
|
|
|
static $backend = null;
|
|
|
|
if ( !$backend ) {
|
|
|
|
$backend = new FSFileBackend( array(
|
|
|
|
'name' => 'captcha-backend',
|
2013-12-30 18:21:06 +00:00
|
|
|
'wikiId' => wfWikiId(),
|
|
|
|
'lockManager' => new NullLockManager( array() ),
|
2012-09-16 17:31:47 +00:00
|
|
|
'containerPaths' => array( 'captcha-render' => $wgCaptchaDirectory ),
|
|
|
|
'fileMode' => 777
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
return $backend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return integer Estimate of the number of captchas files
|
|
|
|
*/
|
|
|
|
public function estimateCaptchaCount() {
|
|
|
|
global $wgCaptchaDirectoryLevels;
|
|
|
|
|
|
|
|
$factor = 1;
|
|
|
|
$sampleDir = $this->getBackend()->getRootStoragePath() . '/captcha-render';
|
|
|
|
if ( $wgCaptchaDirectoryLevels >= 1 ) { // 1/16 sample if 16 shards
|
|
|
|
$sampleDir .= '/' . dechex( mt_rand( 0, 15 ) );
|
|
|
|
$factor = 16;
|
|
|
|
}
|
|
|
|
if ( $wgCaptchaDirectoryLevels >= 3 ) { // 1/256 sample if 4096 shards
|
|
|
|
$sampleDir .= '/' . dechex( mt_rand( 0, 15 ) );
|
|
|
|
$factor = 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
$count = 0;
|
|
|
|
foreach ( $this->getBackend()->getFileList( array( 'dir' => $sampleDir ) ) as $file ) {
|
|
|
|
++$count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( $count * $factor );
|
|
|
|
}
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
/**
|
|
|
|
* Check if the submitted form matches the captcha session data provided
|
|
|
|
* by the plugin when the form was generated.
|
|
|
|
*
|
2008-01-24 21:42:21 +00:00
|
|
|
* @param string $answer
|
2007-11-12 07:42:25 +00:00
|
|
|
* @param array $info
|
|
|
|
* @return bool
|
|
|
|
*/
|
2008-01-24 21:42:21 +00:00
|
|
|
function keyMatch( $answer, $info ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
global $wgCaptchaSecret;
|
|
|
|
|
|
|
|
$digest = $wgCaptchaSecret . $info['salt'] . $answer . $wgCaptchaSecret . $info['salt'];
|
|
|
|
$answerHash = substr( md5( $digest ), 0, 16 );
|
|
|
|
|
2009-07-19 15:13:01 +00:00
|
|
|
if ( $answerHash == $info['hash'] ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
wfDebug( "FancyCaptcha: answer hash matches expected {$info['hash']}\n" );
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
wfDebug( "FancyCaptcha: answer hashes to $answerHash, expected {$info['hash']}\n" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-19 15:13:01 +00:00
|
|
|
function addCaptchaAPI( &$resultArr ) {
|
2008-02-28 17:42:23 +00:00
|
|
|
$info = $this->pickImage();
|
2009-07-19 15:13:01 +00:00
|
|
|
if ( !$info ) {
|
2008-02-28 17:42:23 +00:00
|
|
|
$resultArr['captcha']['error'] = 'Out of images';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$index = $this->storeCaptcha( $info );
|
2010-06-08 19:30:48 +00:00
|
|
|
$title = SpecialPage::getTitleFor( 'Captcha', 'image' );
|
2008-02-28 17:42:23 +00:00
|
|
|
$resultArr['captcha']['type'] = 'image';
|
2008-02-29 21:44:21 +00:00
|
|
|
$resultArr['captcha']['mime'] = 'image/png';
|
2008-02-28 17:42:23 +00:00
|
|
|
$resultArr['captcha']['id'] = $index;
|
2009-07-19 15:13:01 +00:00
|
|
|
$resultArr['captcha']['url'] = $title->getLocalUrl( 'wpCaptchaId=' . urlencode( $index ) );
|
2008-02-28 17:42:23 +00:00
|
|
|
}
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
/**
|
|
|
|
* Insert the captcha prompt into the edit form.
|
|
|
|
*/
|
|
|
|
function getForm() {
|
2015-05-22 06:21:24 +00:00
|
|
|
global $wgOut, $wgEnableAPI;
|
2007-11-12 07:42:25 +00:00
|
|
|
|
2013-01-17 02:00:09 +00:00
|
|
|
// Uses addModuleStyles so it is loaded when JS is disabled.
|
|
|
|
$wgOut->addModuleStyles( 'ext.confirmEdit.fancyCaptcha.styles' );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
2010-06-08 19:30:48 +00:00
|
|
|
$title = SpecialPage::getTitleFor( 'Captcha', 'image' );
|
2013-01-17 02:00:09 +00:00
|
|
|
$index = $this->getCaptchaIndex();
|
|
|
|
|
|
|
|
if ( $wgEnableAPI ) {
|
|
|
|
// Loaded only if JS is enabled
|
|
|
|
$wgOut->addModules( 'ext.confirmEdit.fancyCaptcha' );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
2013-04-26 23:34:30 +00:00
|
|
|
$captchaReload = Html::element(
|
|
|
|
'small',
|
|
|
|
array(
|
|
|
|
'class' => 'confirmedit-captcha-reload fancycaptcha-reload'
|
2013-04-23 19:28:44 +00:00
|
|
|
),
|
2013-04-26 23:34:30 +00:00
|
|
|
wfMessage( 'fancycaptcha-reload-text' )->text()
|
|
|
|
);
|
2013-01-17 02:00:09 +00:00
|
|
|
} else {
|
|
|
|
$captchaReload = '';
|
|
|
|
}
|
|
|
|
|
2015-01-14 16:34:23 +00:00
|
|
|
$form = Html::openElement( 'div' ) .
|
|
|
|
Html::element( 'label', array(
|
|
|
|
'for' => 'wpCaptchaWord',
|
|
|
|
),
|
|
|
|
parent::getMessage( 'label' ) . ' ' . wfMessage( 'createacct-captcha' )->text()
|
|
|
|
) .
|
|
|
|
Html::openElement( 'div', array( 'class' => 'mw-createacct-captcha-container' ) ) .
|
|
|
|
Html::openElement( 'div', array( 'class' => 'mw-createacct-captcha-and-reload' ) ) .
|
|
|
|
Html::openElement( 'div', array( 'class' => 'fancycaptcha-image-container' ) ) .
|
2013-01-17 02:00:09 +00:00
|
|
|
Html::element( 'img', array(
|
2013-04-23 19:28:44 +00:00
|
|
|
'class' => 'fancycaptcha-image',
|
|
|
|
'src' => $title->getLocalUrl( 'wpCaptchaId=' . urlencode( $index ) ),
|
|
|
|
'alt' => ''
|
|
|
|
)
|
2015-01-14 16:34:23 +00:00
|
|
|
) . $captchaReload . Html::closeElement( 'div' ) . Html::closeElement( 'div' ) . "\n" .
|
2011-10-21 14:59:16 +00:00
|
|
|
Html::element( 'input', array(
|
2013-04-23 19:28:44 +00:00
|
|
|
'name' => 'wpCaptchaWord',
|
2014-07-30 01:39:22 +00:00
|
|
|
'class' => 'mw-ui-input',
|
2013-04-23 19:28:44 +00:00
|
|
|
'id' => 'wpCaptchaWord',
|
|
|
|
'type' => 'text',
|
2013-04-27 01:26:53 +00:00
|
|
|
'size' => '12', // max_length in captcha.py plus fudge factor
|
2013-05-03 01:09:51 +00:00
|
|
|
'autocomplete' => 'off',
|
2013-04-23 19:28:44 +00:00
|
|
|
'autocorrect' => 'off',
|
|
|
|
'autocapitalize' => 'off',
|
|
|
|
'required' => 'required',
|
2015-01-14 16:34:23 +00:00
|
|
|
'tabindex' => 1,
|
|
|
|
'placeholder' => wfMessage( 'createacct-imgcaptcha-ph' )
|
2013-04-23 19:28:44 +00:00
|
|
|
)
|
2015-01-14 16:34:23 +00:00
|
|
|
); // tab in before the edit textarea
|
|
|
|
if ( $this->action == 'usercreate' ) {
|
2015-06-09 16:27:41 +00:00
|
|
|
// use raw element, because the message can contain links or some other html
|
|
|
|
$form .= HTML::rawelement( 'small',array(
|
2015-01-14 16:34:23 +00:00
|
|
|
'class' => 'mw-createacct-captcha-assisted'
|
2015-06-09 16:27:41 +00:00
|
|
|
), wfMessage( 'createacct-imgcaptcha-help' )->parse()
|
2015-01-14 16:34:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$form .= Html::element( 'input', array(
|
2013-04-23 19:28:44 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'wpCaptchaId',
|
|
|
|
'id' => 'wpCaptchaId',
|
|
|
|
'value' => $index
|
|
|
|
)
|
2015-01-14 16:34:23 +00:00
|
|
|
) . Html::closeElement( 'div' ) . Html::closeElement( 'div' ) . "\n";
|
|
|
|
|
|
|
|
return $form;
|
2013-01-17 02:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get captcha index key
|
|
|
|
* @return string captcha ID key
|
|
|
|
*/
|
|
|
|
function getCaptchaIndex() {
|
|
|
|
$info = $this->pickImage();
|
|
|
|
if ( !$info ) {
|
2015-01-10 01:48:35 +00:00
|
|
|
throw new Exception( "Ran out of captcha images" );
|
2013-01-17 02:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a random key for use of this captcha image in this session.
|
|
|
|
// This is needed so multiple edits in separate tabs or windows can
|
|
|
|
// go through without extra pain.
|
|
|
|
$index = $this->storeCaptcha( $info );
|
|
|
|
|
|
|
|
return $index;
|
2007-11-12 07:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select a previously generated captcha image from the queue.
|
|
|
|
* @return mixed tuple of (salt key, text hash) or false if no image to find
|
|
|
|
*/
|
2012-09-16 17:31:47 +00:00
|
|
|
protected function pickImage() {
|
|
|
|
global $wgCaptchaDirectoryLevels;
|
|
|
|
|
|
|
|
$lockouts = 0; // number of times another process claimed a file before this one
|
|
|
|
$baseDir = $this->getBackend()->getRootStoragePath() . '/captcha-render';
|
|
|
|
return $this->pickImageDir( $baseDir, $wgCaptchaDirectoryLevels, $lockouts );
|
2007-11-12 07:42:25 +00:00
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
2012-09-16 17:31:47 +00:00
|
|
|
/**
|
|
|
|
* @param $directory string
|
|
|
|
* @param $levels integer
|
|
|
|
* @param $lockouts integer
|
|
|
|
* @return Array|bool
|
|
|
|
*/
|
|
|
|
protected function pickImageDir( $directory, $levels, &$lockouts ) {
|
|
|
|
global $wgMemc;
|
2009-07-19 15:13:01 +00:00
|
|
|
|
2012-09-16 17:31:47 +00:00
|
|
|
if ( $levels <= 0 ) { // $directory has regular files
|
|
|
|
return $this->pickImageFromDir( $directory, $lockouts );
|
|
|
|
}
|
|
|
|
|
|
|
|
$backend = $this->getBackend();
|
|
|
|
|
|
|
|
$key = "fancycaptcha:dirlist:{$backend->getWikiId()}:" . sha1( $directory );
|
|
|
|
$dirs = $wgMemc->get( $key ); // check cache
|
2013-01-01 00:36:02 +00:00
|
|
|
if ( !is_array( $dirs ) || !count( $dirs ) ) { // cache miss
|
2012-09-16 17:31:47 +00:00
|
|
|
$dirs = array(); // subdirs actually present...
|
|
|
|
foreach ( $backend->getTopDirectoryList( array( 'dir' => $directory ) ) as $entry ) {
|
2009-07-19 15:13:01 +00:00
|
|
|
if ( ctype_xdigit( $entry ) && strlen( $entry ) == 1 ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
$dirs[] = $entry;
|
|
|
|
}
|
|
|
|
}
|
2012-09-16 17:31:47 +00:00
|
|
|
wfDebug( "Cache miss for $directory subdirectory listing.\n" );
|
2013-01-01 00:36:02 +00:00
|
|
|
if ( count( $dirs ) ) {
|
|
|
|
$wgMemc->set( $key, $dirs, 86400 );
|
|
|
|
}
|
2007-11-12 07:42:25 +00:00
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
2012-09-16 17:31:47 +00:00
|
|
|
if ( !count( $dirs ) ) {
|
|
|
|
// Remove this directory if empty so callers don't keep looking here
|
|
|
|
$backend->clean( array( 'dir' => $directory ) );
|
|
|
|
return false; // none found
|
2007-11-12 07:42:25 +00:00
|
|
|
}
|
2012-09-16 17:31:47 +00:00
|
|
|
|
|
|
|
$place = mt_rand( 0, count( $dirs ) - 1 ); // pick a random subdir
|
|
|
|
// In case all dirs are not filled, cycle through next digits...
|
|
|
|
for ( $j = 0; $j < count( $dirs ); $j++ ) {
|
|
|
|
$char = $dirs[( $place + $j ) % count( $dirs )];
|
|
|
|
$info = $this->pickImageDir( "$directory/$char", $levels - 1, $lockouts );
|
|
|
|
if ( $info ) {
|
|
|
|
return $info; // found a captcha
|
|
|
|
} else {
|
|
|
|
wfDebug( "Could not find captcha in $directory.\n" );
|
|
|
|
$wgMemc->delete( $key ); // files changed on disk?
|
|
|
|
}
|
2012-08-30 15:49:16 +00:00
|
|
|
}
|
2007-11-12 07:42:25 +00:00
|
|
|
|
2012-09-16 17:31:47 +00:00
|
|
|
return false; // didn't find any images in this directory... empty?
|
|
|
|
}
|
2007-11-12 07:42:25 +00:00
|
|
|
|
2012-09-16 17:31:47 +00:00
|
|
|
/**
|
|
|
|
* @param $directory string
|
|
|
|
* @param $lockouts integer
|
|
|
|
* @return Array|bool
|
|
|
|
*/
|
|
|
|
protected function pickImageFromDir( $directory, &$lockouts ) {
|
|
|
|
global $wgMemc;
|
|
|
|
|
|
|
|
$backend = $this->getBackend();
|
|
|
|
|
|
|
|
$key = "fancycaptcha:filelist:{$backend->getWikiId()}:" . sha1( $directory );
|
|
|
|
$files = $wgMemc->get( $key ); // check cache
|
2013-01-01 00:36:02 +00:00
|
|
|
if ( !is_array( $files ) || !count( $files ) ) { // cache miss
|
2012-09-16 17:31:47 +00:00
|
|
|
$files = array(); // captcha files
|
|
|
|
foreach ( $backend->getTopFileList( array( 'dir' => $directory ) ) as $entry ) {
|
|
|
|
$files[] = $entry;
|
|
|
|
if ( count( $files ) >= 500 ) { // sanity
|
|
|
|
wfDebug( 'Skipping some captchas; $wgCaptchaDirectoryLevels set too low?.' );
|
2007-11-12 07:42:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-01 00:36:02 +00:00
|
|
|
if ( count( $files ) ) {
|
|
|
|
$wgMemc->set( $key, $files, 86400 );
|
|
|
|
}
|
2012-09-16 17:31:47 +00:00
|
|
|
wfDebug( "Cache miss for $directory captcha listing.\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !count( $files ) ) {
|
|
|
|
// Remove this directory if empty so callers don't keep looking here
|
|
|
|
$backend->clean( array( 'dir' => $directory ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$info = $this->pickImageFromList( $directory, $files, $lockouts );
|
|
|
|
if ( !$info ) {
|
|
|
|
wfDebug( "Could not find captcha in $directory.\n" );
|
|
|
|
$wgMemc->delete( $key ); // files changed on disk?
|
2007-11-12 07:42:25 +00:00
|
|
|
}
|
2012-09-16 17:31:47 +00:00
|
|
|
|
|
|
|
return $info;
|
2007-11-12 07:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-09-16 17:31:47 +00:00
|
|
|
* @param $directory string
|
|
|
|
* @param $files array
|
|
|
|
* @param $lockouts integer
|
|
|
|
* @return boolean
|
2007-11-12 07:42:25 +00:00
|
|
|
*/
|
2012-09-16 17:31:47 +00:00
|
|
|
protected function pickImageFromList( $directory, array $files, &$lockouts ) {
|
|
|
|
global $wgMemc, $wgCaptchaDeleteOnSolve;
|
|
|
|
|
|
|
|
if ( !count( $files ) ) {
|
|
|
|
return false; // none found
|
|
|
|
}
|
|
|
|
|
|
|
|
$backend = $this->getBackend();
|
|
|
|
$place = mt_rand( 0, count( $files ) - 1 ); // pick a random file
|
|
|
|
$misses = 0; // number of files in listing that don't actually exist
|
|
|
|
for ( $j = 0; $j < count( $files ); $j++ ) {
|
|
|
|
$entry = $files[( $place + $j ) % count( $files )];
|
|
|
|
if ( preg_match( '/^image_([0-9a-f]+)_([0-9a-f]+)\\.png$/', $entry, $matches ) ) {
|
|
|
|
if ( $wgCaptchaDeleteOnSolve ) { // captcha will be deleted when solved
|
|
|
|
$key = "fancycaptcha:filelock:{$backend->getWikiId()}:" . sha1( $entry );
|
|
|
|
// Try to claim this captcha for 10 minutes (for the user to solve)...
|
|
|
|
if ( ++$lockouts <= 10 && !$wgMemc->add( $key, '1', 600 ) ) {
|
|
|
|
continue; // could not acquire (skip it to avoid race conditions)
|
|
|
|
}
|
|
|
|
}
|
2013-01-03 01:21:53 +00:00
|
|
|
if ( !$backend->fileExists( array( 'src' => "$directory/$entry" ) ) ) {
|
2012-09-16 17:31:47 +00:00
|
|
|
if ( ++$misses >= 5 ) { // too many files in the listing don't exist
|
|
|
|
break; // listing cache too stale? break out so it will be cleared
|
|
|
|
}
|
|
|
|
continue; // try next file
|
|
|
|
}
|
|
|
|
return array(
|
|
|
|
'salt' => $matches[1],
|
|
|
|
'hash' => $matches[2],
|
|
|
|
'viewed' => false,
|
|
|
|
);
|
2007-11-12 07:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-16 17:31:47 +00:00
|
|
|
|
|
|
|
return false; // none found
|
2007-11-12 07:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showImage() {
|
2015-04-02 22:56:48 +00:00
|
|
|
global $wgOut;
|
2007-11-12 07:42:25 +00:00
|
|
|
|
|
|
|
$wgOut->disable();
|
|
|
|
|
2015-04-02 22:56:48 +00:00
|
|
|
$info = $this->retrieveCaptcha();
|
2009-07-19 15:13:01 +00:00
|
|
|
if ( $info ) {
|
2012-09-02 12:26:25 +00:00
|
|
|
$timestamp = new MWTimestamp();
|
|
|
|
$info['viewed'] = $timestamp->getTimestamp();
|
2007-11-12 07:42:25 +00:00
|
|
|
$this->storeCaptcha( $info );
|
|
|
|
|
|
|
|
$salt = $info['salt'];
|
|
|
|
$hash = $info['hash'];
|
2012-09-16 17:31:47 +00:00
|
|
|
|
|
|
|
return $this->getBackend()->streamFile( array(
|
|
|
|
'src' => $this->imagePath( $salt, $hash ),
|
|
|
|
'headers' => array( "Cache-Control: private, s-maxage=0, max-age=3600" )
|
|
|
|
) )->isOK();
|
2007-11-12 07:42:25 +00:00
|
|
|
}
|
2012-09-16 17:31:47 +00:00
|
|
|
|
2015-03-18 06:54:12 +00:00
|
|
|
wfHttpError( 400, 'Request Error', 'Requested bogus captcha image' );
|
2007-11-12 07:42:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
2012-09-16 17:31:47 +00:00
|
|
|
/**
|
|
|
|
* @param $salt string
|
|
|
|
* @param $hash string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function imagePath( $salt, $hash ) {
|
|
|
|
global $wgCaptchaDirectoryLevels;
|
|
|
|
|
|
|
|
$file = $this->getBackend()->getRootStoragePath() . '/captcha-render/';
|
2009-07-19 15:13:01 +00:00
|
|
|
for ( $i = 0; $i < $wgCaptchaDirectoryLevels; $i++ ) {
|
2012-09-16 17:31:47 +00:00
|
|
|
$file .= $hash{ $i } . '/';
|
2007-11-12 07:42:25 +00:00
|
|
|
}
|
|
|
|
$file .= "image_{$salt}_{$hash}.png";
|
2012-09-16 17:31:47 +00:00
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
return $file;
|
|
|
|
}
|
|
|
|
|
2012-09-16 17:31:47 +00:00
|
|
|
/**
|
|
|
|
* @param $basename string
|
|
|
|
* @return Array (salt, hash)
|
2015-01-10 01:48:35 +00:00
|
|
|
* @throws Exception
|
2012-09-16 17:31:47 +00:00
|
|
|
*/
|
|
|
|
public function hashFromImageName( $basename ) {
|
|
|
|
if ( preg_match( '/^image_([0-9a-f]+)_([0-9a-f]+)\\.png$/', $basename, $matches ) ) {
|
|
|
|
return array( $matches[1], $matches[2] );
|
|
|
|
} else {
|
2015-01-10 01:48:35 +00:00
|
|
|
throw new Exception( "Invalid filename '$basename'.\n" );
|
2012-09-16 17:31:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
/**
|
|
|
|
* Show a message asking the user to enter a captcha on edit
|
|
|
|
* The result will be treated as wiki text
|
|
|
|
*
|
2012-09-02 12:26:25 +00:00
|
|
|
* @param $action string Action being performed
|
2007-11-12 07:42:25 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function getMessage( $action ) {
|
|
|
|
$name = 'fancycaptcha-' . $action;
|
2012-08-16 21:21:50 +00:00
|
|
|
$text = wfMessage( $name )->text();
|
2007-11-12 07:42:25 +00:00
|
|
|
# Obtain a more tailored message, if possible, otherwise, fall back to
|
|
|
|
# the default for edits
|
2012-09-16 17:31:47 +00:00
|
|
|
return wfMessage( $name, $text )->isDisabled() ?
|
|
|
|
wfMessage( 'fancycaptcha-edit' )->text() : $text;
|
2007-11-12 07:42:25 +00:00
|
|
|
}
|
2010-08-29 13:31:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a solved captcha image, if $wgCaptchaDeleteOnSolve is true.
|
|
|
|
*/
|
|
|
|
function passCaptcha() {
|
2015-04-02 22:56:48 +00:00
|
|
|
global $wgCaptchaDeleteOnSolve;
|
2010-08-29 13:31:31 +00:00
|
|
|
|
2015-04-02 22:56:48 +00:00
|
|
|
$info = $this->retrieveCaptcha(); // get the captcha info before it gets deleted
|
2010-08-29 13:31:31 +00:00
|
|
|
$pass = parent::passCaptcha();
|
|
|
|
|
|
|
|
if ( $pass && $wgCaptchaDeleteOnSolve ) {
|
2012-09-16 17:31:47 +00:00
|
|
|
$this->getBackend()->quickDelete( array(
|
|
|
|
'src' => $this->imagePath( $info['salt'], $info['hash'] )
|
|
|
|
) );
|
2010-08-29 13:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $pass;
|
|
|
|
}
|
2007-11-12 07:42:25 +00:00
|
|
|
}
|