Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
LinkPurgeRateLimitConstraint | |
100.00% |
12 / 12 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
limit | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
checkConstraint | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
getLegacyStatus | |
100.00% |
5 / 5 |
|
100.00% |
1 / 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 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\EditPage\Constraint; |
22 | |
23 | use MediaWiki\Permissions\RateLimiter; |
24 | use MediaWiki\Permissions\RateLimitSubject; |
25 | use StatusValue; |
26 | |
27 | /** |
28 | * Verify that the user doesn't exceed 'linkpurge' limits, which are weird and special. |
29 | * Other rate limits have been integrated into their respective permission checks. |
30 | * |
31 | * @since 1.44 |
32 | * @internal |
33 | * @author DannyS712 |
34 | */ |
35 | class LinkPurgeRateLimitConstraint implements IEditConstraint { |
36 | |
37 | private RateLimitSubject $subject; |
38 | private RateLimiter $limiter; |
39 | |
40 | private string $result; |
41 | |
42 | public function __construct( |
43 | RateLimiter $limiter, |
44 | RateLimitSubject $subject |
45 | ) { |
46 | $this->limiter = $limiter; |
47 | $this->subject = $subject; |
48 | } |
49 | |
50 | private function limit( string $action, int $inc = 1 ): bool { |
51 | return $this->limiter->limit( $this->subject, $action, $inc ); |
52 | } |
53 | |
54 | public function checkConstraint(): string { |
55 | // TODO inject and use a ThrottleStore once available, see T261744 |
56 | // Checking if the user is rate limited increments the counts, so we cannot perform |
57 | // the check again when getting the status; thus, store the result |
58 | if ( $this->limit( 'linkpurge', /* only counted after the fact */ 0 ) ) { |
59 | $this->result = self::CONSTRAINT_FAILED; |
60 | } else { |
61 | $this->result = self::CONSTRAINT_PASSED; |
62 | } |
63 | |
64 | return $this->result; |
65 | } |
66 | |
67 | public function getLegacyStatus(): StatusValue { |
68 | $statusValue = StatusValue::newGood(); |
69 | |
70 | if ( $this->result === self::CONSTRAINT_FAILED ) { |
71 | $statusValue->fatal( 'actionthrottledtext' ); |
72 | $statusValue->value = self::AS_RATE_LIMITED; |
73 | } |
74 | |
75 | return $statusValue; |
76 | } |
77 | |
78 | } |