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