Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
InvalidateEmail | |
0.00% |
0 / 31 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | /** |
3 | * @copyright © 2017 Wikimedia Foundation and contributors. |
4 | * @section LICENSE |
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 | */ |
22 | |
23 | use MediaWiki\Extension\BounceHandler\BounceHandlerActions; |
24 | use MediaWiki\Maintenance\Maintenance; |
25 | use MediaWiki\WikiMap\WikiMap; |
26 | |
27 | $IP = getenv( 'MW_INSTALL_PATH' ); |
28 | if ( $IP === false ) { |
29 | $IP = __DIR__ . '/../../..'; |
30 | } |
31 | require_once "$IP/maintenance/Maintenance.php"; |
32 | |
33 | class InvalidateEmail extends Maintenance { |
34 | public function __construct() { |
35 | parent::__construct(); |
36 | $this->requireExtension( 'BounceHandler' ); |
37 | $this->addDescription( "Invalidate a user's email address and leave them a message." ); |
38 | $this->addOption( 'userlist', |
39 | 'List of usernames to invalidate, one per line', true, true ); |
40 | $this->addOption( 'dry-run', 'Do not invalidate addresses' ); |
41 | } |
42 | |
43 | public function execute() { |
44 | $list = $this->getOption( 'userlist' ); |
45 | if ( !is_file( $list ) ) { |
46 | $this->output( "ERROR - File not found: {$list}" ); |
47 | exit( 1 ); |
48 | } |
49 | $file = fopen( $list, 'r' ); |
50 | if ( $file === false ) { |
51 | $this->output( "ERROR - Could not open file: {$list}" ); |
52 | exit( 1 ); |
53 | } |
54 | $bounce = new BounceHandlerActions( |
55 | WikiMap::getCurrentWikiId(), 0, 0, false, 'Email invalidated manually.' ); |
56 | // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition |
57 | while ( strlen( $username = trim( fgets( $file ) ) ) ) { |
58 | $this->output( "Invalidate email for: {$username}\n" ); |
59 | $user = $this->getServiceContainer()->getUserFactory()->newFromName( $username ); |
60 | if ( $user && $user->getId() ) { |
61 | if ( !$this->hasOption( 'dry-run' ) ) { |
62 | $bounce->unSubscribeUser( |
63 | [ |
64 | 'rawEmail' => $user->getEmail(), |
65 | 'rawUserId' => $user->getId(), |
66 | ], |
67 | [ /* Headers intentionally blank */ ] |
68 | ); |
69 | } |
70 | } else { |
71 | $this->output( "ERROR - Unknown user {$username}\n" ); |
72 | } |
73 | } |
74 | fclose( $file ); |
75 | $this->output( "done.\n" ); |
76 | } |
77 | } |
78 | |
79 | $maintClass = InvalidateEmail::class; |
80 | require_once RUN_MAINTENANCE_IF_MAIN; |