Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
20 / 20 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
SimpleAntiSpamConstraint | |
100.00% |
20 / 20 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
checkConstraint | |
100.00% |
11 / 11 |
|
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\Title\Title; |
24 | use MediaWiki\User\UserIdentity; |
25 | use Psr\Log\LoggerInterface; |
26 | use StatusValue; |
27 | |
28 | /** |
29 | * Verify simple anti spam measure of an extra hidden text field |
30 | * |
31 | * @since 1.36 |
32 | * @internal |
33 | */ |
34 | class SimpleAntiSpamConstraint implements IEditConstraint { |
35 | |
36 | /** @var LoggerInterface */ |
37 | private $logger; |
38 | |
39 | /** @var string */ |
40 | private $input; |
41 | |
42 | /** @var UserIdentity */ |
43 | private $user; |
44 | |
45 | /** @var Title */ |
46 | private $title; |
47 | |
48 | /** |
49 | * @param LoggerInterface $logger for logging hits |
50 | * @param string $inputText |
51 | * @param UserIdentity $user for logging hits |
52 | * @param Title $title for logging hits |
53 | */ |
54 | public function __construct( |
55 | LoggerInterface $logger, |
56 | string $inputText, |
57 | UserIdentity $user, |
58 | Title $title |
59 | ) { |
60 | $this->logger = $logger; |
61 | $this->input = $inputText; |
62 | $this->user = $user; |
63 | $this->title = $title; |
64 | } |
65 | |
66 | public function checkConstraint(): string { |
67 | if ( $this->input === '' ) { |
68 | return self::CONSTRAINT_PASSED; |
69 | } |
70 | $this->logger->debug( |
71 | '{name} editing "{title}" submitted bogus field "{input}"', |
72 | [ |
73 | 'name' => $this->user->getName(), |
74 | 'title' => $this->title->getPrefixedText(), |
75 | 'input' => $this->input |
76 | ] |
77 | ); |
78 | return self::CONSTRAINT_FAILED; |
79 | } |
80 | |
81 | public function getLegacyStatus(): StatusValue { |
82 | $statusValue = StatusValue::newGood(); |
83 | if ( $this->input !== '' ) { |
84 | $statusValue->fatal( 'spamprotectionmatch', false ); |
85 | $statusValue->value = self::AS_SPAM_ERROR; |
86 | } |
87 | return $statusValue; |
88 | } |
89 | |
90 | } |