jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/336866 )
Change subject: Use an accurate number of captchas
......................................................................
Use an accurate number of captchas
Change-Id: Ice434235687aa68ccf37a0219d379beb97e5a8ec
---
M FancyCaptcha/FancyCaptcha.class.php
M extension.json
M maintenance/CountFancyCaptchas.php
M maintenance/GenerateFancyCaptchas.php
4 files changed, 21 insertions(+), 30 deletions(-)
Approvals:
Reedy: Looks good to me, approved
jenkins-bot: Verified
diff --git a/FancyCaptcha/FancyCaptcha.class.php
b/FancyCaptcha/FancyCaptcha.class.php
index 094aaf6..64b64f8 100644
--- a/FancyCaptcha/FancyCaptcha.class.php
+++ b/FancyCaptcha/FancyCaptcha.class.php
@@ -34,28 +34,24 @@
}
/**
- * @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 095f952..f0be55a 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 20a5946..70f73a1 100644
--- a/maintenance/CountFancyCaptchas.php
+++ b/maintenance/CountFancyCaptchas.php
@@ -41,22 +41,16 @@
}
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 b8b5692..0a02bd5 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 @@
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 @@
$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;
}
--
To view, visit https://gerrit.wikimedia.org/r/336866
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ice434235687aa68ccf37a0219d379beb97e5a8ec
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ConfirmEdit
Gerrit-Branch: wmf/1.29.0-wmf.11
Gerrit-Owner: Reedy <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits