Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
Hooks | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
onRegistration | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
onLocalUserCreated | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
onRenameUserComplete | |
0.00% |
0 / 2 |
|
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 | |
19 | namespace MediaWiki\Extension\AntiSpoof; |
20 | |
21 | use MediaWiki\Auth\Hook\LocalUserCreatedHook; |
22 | use MediaWiki\Permissions\GrantsInfo; |
23 | use MediaWiki\RenameUser\Hook\RenameUserCompleteHook; |
24 | use MediaWiki\User\User; |
25 | |
26 | class 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 | * @param User $user |
46 | * @param bool $autocreated |
47 | */ |
48 | public function onLocalUserCreated( $user, $autocreated ) { |
49 | if ( !$user->isTemp() ) { |
50 | $spoof = new SpoofUser( $user->getName() ); |
51 | $spoof->record(); |
52 | } |
53 | } |
54 | |
55 | /** |
56 | * On rename, remove the old entry and add the new |
57 | * (After a successful user rename) |
58 | * |
59 | * @param int $uid |
60 | * @param string $oldName |
61 | * @param string $newName |
62 | */ |
63 | public function onRenameUserComplete( int $uid, string $oldName, string $newName ): void { |
64 | $spoof = new SpoofUser( $newName ); |
65 | $spoof->update( $oldName ); |
66 | } |
67 | } |