Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
94.12% |
16 / 17 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CountFancyCaptchas | |
94.12% |
16 / 17 |
|
50.00% |
1 / 2 |
4.00 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
3.02 | |||
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types=1 ); |
| 4 | /** |
| 5 | * Counts the number of fancy captchas remaining. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | * http://www.gnu.org/copyleft/gpl.html |
| 21 | * |
| 22 | * @file |
| 23 | * @ingroup Maintenance |
| 24 | */ |
| 25 | |
| 26 | namespace MediaWiki\Extension\ConfirmEdit\Maintenance; |
| 27 | |
| 28 | // @codeCoverageIgnoreStart |
| 29 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
| 30 | $IP = getenv( 'MW_INSTALL_PATH' ); |
| 31 | } else { |
| 32 | $IP = __DIR__ . '/../../..'; |
| 33 | } |
| 34 | |
| 35 | require_once "$IP/maintenance/Maintenance.php"; |
| 36 | // @codeCoverageIgnoreEnd |
| 37 | |
| 38 | use MediaWiki\Extension\ConfirmEdit\FancyCaptcha\FancyCaptcha; |
| 39 | use MediaWiki\Extension\ConfirmEdit\Services\CaptchaFactory; |
| 40 | use MediaWiki\Maintenance\Maintenance; |
| 41 | |
| 42 | /** |
| 43 | * Maintenance script that counts the number of captchas remaining. |
| 44 | * |
| 45 | * @ingroup Maintenance |
| 46 | */ |
| 47 | class CountFancyCaptchas extends Maintenance { |
| 48 | public function __construct() { |
| 49 | parent::__construct(); |
| 50 | $this->addDescription( "Counts the number of fancy captchas in storage" ); |
| 51 | $this->addOption( |
| 52 | 'captchastoragedir', |
| 53 | 'Overrides the value of $wgCaptchaStorageDirectory', |
| 54 | false, |
| 55 | true |
| 56 | ); |
| 57 | $this->requireExtension( "FancyCaptcha" ); |
| 58 | } |
| 59 | |
| 60 | public function execute() { |
| 61 | /** @var CaptchaFactory $captchaFactory */ |
| 62 | $captchaFactory = $this->getServiceContainer()->get( 'ConfirmEditCaptchaFactory' ); |
| 63 | $instance = $captchaFactory->getGlobalInstance(); |
| 64 | if ( !( $instance instanceof FancyCaptcha ) ) { |
| 65 | $this->fatalError( "\$wgCaptchaClass is not FancyCaptcha.\n", 1 ); |
| 66 | } |
| 67 | |
| 68 | // Overrides $wgCaptchaStorageDirectory for this script run |
| 69 | if ( $this->hasOption( 'captchastoragedir' ) ) { |
| 70 | global $wgCaptchaStorageDirectory; |
| 71 | $wgCaptchaStorageDirectory = $this->getOption( 'captchastoragedir' ); |
| 72 | } |
| 73 | |
| 74 | $countAct = $instance->getCaptchaCount(); |
| 75 | $this->output( "Current number of stored captchas is $countAct.\n" ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // @codeCoverageIgnoreStart |
| 80 | $maintClass = CountFancyCaptchas::class; |
| 81 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 82 | // @codeCoverageIgnoreEnd |