Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| ActionSpecifier | |
100.00% |
7 / 7 |
|
100.00% |
6 / 6 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
| getAction | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTitle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUser | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getIP | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAccountName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\AbuseFilter; |
| 4 | |
| 5 | use InvalidArgumentException; |
| 6 | use MediaWiki\Linker\LinkTarget; |
| 7 | use MediaWiki\User\UserIdentity; |
| 8 | |
| 9 | /** |
| 10 | * Plain value object that univocally represents an action being filtered |
| 11 | * @todo Add constants for possible actions? |
| 12 | * @todo Add the timestamp |
| 13 | */ |
| 14 | class ActionSpecifier { |
| 15 | |
| 16 | /** |
| 17 | * @param string $action Action being filtered (e.g. 'edit' or 'createaccount') |
| 18 | * @param LinkTarget $title Where the current action is executed. This is the user page |
| 19 | * for account creations. |
| 20 | * @param UserIdentity $user |
| 21 | * @param string $requestIP |
| 22 | * @param string|null $accountName Required iff the action is an account creation |
| 23 | */ |
| 24 | public function __construct( |
| 25 | private readonly string $action, |
| 26 | private readonly LinkTarget $title, |
| 27 | private readonly UserIdentity $user, |
| 28 | private readonly string $requestIP, |
| 29 | private readonly ?string $accountName |
| 30 | ) { |
| 31 | if ( $accountName === null && str_contains( $action, 'createaccount' ) ) { |
| 32 | throw new InvalidArgumentException( '$accountName required for account creations' ); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public function getAction(): string { |
| 37 | return $this->action; |
| 38 | } |
| 39 | |
| 40 | public function getTitle(): LinkTarget { |
| 41 | return $this->title; |
| 42 | } |
| 43 | |
| 44 | public function getUser(): UserIdentity { |
| 45 | return $this->user; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @return string |
| 50 | * @note It may be an empty string for less recent changes. |
| 51 | */ |
| 52 | public function getIP(): string { |
| 53 | return $this->requestIP; |
| 54 | } |
| 55 | |
| 56 | public function getAccountName(): ?string { |
| 57 | return $this->accountName; |
| 58 | } |
| 59 | } |