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;
33
34/**
35 * Maintenance script that counts the number of captchas remaining.
36 *
37 * @ingroup Maintenance
38 */
39class CountFancyCaptchas extends Maintenance {
40    public function __construct() {
41        parent::__construct();
42        $this->addDescription( "Counts the number of fancy captchas in storage" );
43        $this->addOption(
44            'captchastoragedir',
45            'Overrides the value of $wgCaptchaStorageDirectory',
46            false,
47            true
48        );
49        $this->requireExtension( "FancyCaptcha" );
50    }
51
52    public function execute() {
53        $instance = Hooks::getInstance();
54        if ( !( $instance instanceof FancyCaptcha ) ) {
55            $this->fatalError( "\$wgCaptchaClass is not FancyCaptcha.\n", 1 );
56        }
57
58        // Overrides $wgCaptchaStorageDirectory for this script run
59        if ( $this->hasOption( 'captchastoragedir' ) ) {
60            global $wgCaptchaStorageDirectory;
61            $wgCaptchaStorageDirectory = $this->getOption( 'captchastoragedir' );
62        }
63
64        $countAct = $instance->getCaptchaCount();
65        $this->output( "Current number of stored captchas is $countAct.\n" );
66    }
67}
68
69$maintClass = CountFancyCaptchas::class;
70require_once RUN_MAINTENANCE_IF_MAIN;