mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-27 09:30:06 +00:00
Use an accurate number of captchas
Change-Id: Ice434235687aa68ccf37a0219d379beb97e5a8ec
This commit is contained in:
parent
0cbcb020fa
commit
a2fc069174
|
@ -34,28 +34,24 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return integer Estimate of the number of captchas files
|
||||
* @deprecated Use getCaptchaCount instead for an accurate figure
|
||||
* @return int Number of captcha files
|
||||
*/
|
||||
public function estimateCaptchaCount() {
|
||||
global $wgCaptchaDirectoryLevels;
|
||||
wfDeprecated( __METHOD__ );
|
||||
return $this->getCaptchaCount();
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
/**
|
||||
* @return int Number of captcha files
|
||||
*/
|
||||
public function getCaptchaCount() {
|
||||
$backend = $this->getBackend();
|
||||
$files = $backend->getFileList(
|
||||
[ 'dir' => $backend->getRootStoragePath() . '/captcha-render' ]
|
||||
);
|
||||
|
||||
$count = 0;
|
||||
foreach ( $this->getBackend()->getFileList( [ 'dir' => $sampleDir ] ) as $file ) {
|
||||
++$count;
|
||||
}
|
||||
|
||||
return ( $count * $factor );
|
||||
return iterator_count( $files );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"@doc": "Please read README.md",
|
||||
"name": "ConfirmEdit",
|
||||
"version": "1.4.0",
|
||||
"version": "1.4.1",
|
||||
"author": [
|
||||
"Brion Vibber",
|
||||
"Florian Schmidt",
|
||||
|
|
|
@ -41,22 +41,16 @@ class CountCaptchas extends Maintenance {
|
|||
}
|
||||
|
||||
public function execute() {
|
||||
|
||||
$instance = ConfirmEditHooks::getInstance();
|
||||
if ( !( $instance instanceof FancyCaptcha ) ) {
|
||||
$this->error( "\$wgCaptchaClass is not FancyCaptcha.\n", 1 );
|
||||
}
|
||||
$backend = $instance->getBackend();
|
||||
|
||||
$countEst = $instance->estimateCaptchaCount();
|
||||
$this->output( "Estimated number of current captchas is $countEst.\n" );
|
||||
|
||||
$files = $backend->getFileList(
|
||||
[ 'dir' => $backend->getRootStoragePath() . '/captcha-render' ]
|
||||
);
|
||||
|
||||
$count = iterator_count( $files );
|
||||
$this->output( "Actual number of current captchas is $count.\n" );
|
||||
$countAct = $instance->getCaptchaCount();
|
||||
$this->output( "Current number of captchas is $countAct.\n" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
if ( getenv( 'MW_INSTALL_PATH' ) ) {
|
||||
$IP = getenv( 'MW_INSTALL_PATH' );
|
||||
} else {
|
||||
$IP = __DIR__.'/../../..';
|
||||
$IP = __DIR__ . '/../../..';
|
||||
}
|
||||
|
||||
require_once ( "$IP/maintenance/Maintenance.php" );
|
||||
|
@ -37,6 +37,7 @@ require_once ( "$IP/maintenance/Maintenance.php" );
|
|||
class GenerateFancyCaptchas extends Maintenance {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
// See captcha.py for argument usage
|
||||
$this->addOption( "wordlist", 'A list of words', true, true );
|
||||
$this->addOption( "font", "The font to use", true, true );
|
||||
|
@ -66,8 +67,8 @@ class GenerateFancyCaptchas extends Maintenance {
|
|||
|
||||
$countGen = (int)$this->getOption( 'fill' );
|
||||
if ( !$deleteOldCaptchas ) {
|
||||
$countAct = $instance->estimateCaptchaCount();
|
||||
$this->output( "Estimated number of current captchas is $countAct.\n" );
|
||||
$countAct = $instance->getCaptchaCount();
|
||||
$this->output( "Current number of captchas is $countAct.\n" );
|
||||
$countGen -= $countAct;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue