diff --git a/FancyCaptcha/FancyCaptcha.class.php b/FancyCaptcha/FancyCaptcha.class.php index 094aaf6e2..64b64f8e3 100644 --- a/FancyCaptcha/FancyCaptcha.class.php +++ b/FancyCaptcha/FancyCaptcha.class.php @@ -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 ); } /** diff --git a/extension.json b/extension.json index 095f95291..f0be55a11 100644 --- a/extension.json +++ b/extension.json @@ -1,7 +1,7 @@ { "@doc": "Please read README.md", "name": "ConfirmEdit", - "version": "1.4.0", + "version": "1.4.1", "author": [ "Brion Vibber", "Florian Schmidt", diff --git a/maintenance/CountFancyCaptchas.php b/maintenance/CountFancyCaptchas.php index 20a59462f..70f73a10d 100644 --- a/maintenance/CountFancyCaptchas.php +++ b/maintenance/CountFancyCaptchas.php @@ -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" ); } } diff --git a/maintenance/GenerateFancyCaptchas.php b/maintenance/GenerateFancyCaptchas.php index e366c37dc..beade3d39 100644 --- a/maintenance/GenerateFancyCaptchas.php +++ b/maintenance/GenerateFancyCaptchas.php @@ -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; }