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