Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Hooks
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 onRegistration
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 onLocalUserCreated
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 onRenameUserComplete
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types=1 );
3/**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 */
19
20namespace MediaWiki\Extension\AntiSpoof;
21
22use MediaWiki\Auth\Hook\LocalUserCreatedHook;
23use MediaWiki\Permissions\GrantsInfo;
24use MediaWiki\RenameUser\Hook\RenameUserCompleteHook;
25
26class Hooks implements
27    LocalUserCreatedHook,
28    RenameUserCompleteHook
29{
30
31    public static function onRegistration() {
32        global $wgGrantRiskGroups;
33        // Make sure the risk rating is at least 'security'. AntiSpoof adds the
34        // override-antispoof right to the createaccount grant, which makes it possible
35        // to use it for social engineering attacks with lookalike usernames.
36        if ( $wgGrantRiskGroups['createaccount'] !== GrantsInfo::RISK_INTERNAL ) {
37            $wgGrantRiskGroups['createaccount'] = GrantsInfo::RISK_SECURITY;
38        }
39    }
40
41    /**
42     * On new account creation, record the username's thing-bob.
43     * Replaces AddNewAccountHook for more modern MediaWiki versions-
44     *
45     * @inheritDoc
46     */
47    public function onLocalUserCreated( $user, $autocreated ) {
48        if ( !$user->isTemp() ) {
49            $spoof = new SpoofUser( $user->getName() );
50            $spoof->record();
51        }
52    }
53
54    /**
55     * On rename, remove the old entry and add the new
56     * (After a successful user rename)
57     *
58     * @inheritDoc
59     */
60    public function onRenameUserComplete( int $uid, string $old, string $new ): void {
61        $spoof = new SpoofUser( $new );
62        $spoof->update( $old );
63    }
64}