Debian Codegraph @

includes/editpage/Constraint/SimpleAntiSpamConstraint.php

raw symbols SCIP
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 private LoggerInterface $logger;
37 private string $input;
38 private UserIdentity $user;
39 private Title $title;
40
41 /**
42 * @param LoggerInterface $logger for logging hits
43 * @param string $inputText
44 * @param UserIdentity $user for logging hits
45 * @param Title $title for logging hits
46 */
47 public function __construct(
48 LoggerInterface $logger,
49 string $inputText,
50 UserIdentity $user,
51 Title $title
52 ) {
53 $this->logger = $logger;
54 $this->input = $inputText;
55 $this->user = $user;
56 $this->title = $title;
57 }
58
59 public function checkConstraint(): string {
60 if ( $this->input === '' ) {
61 return self::CONSTRAINT_PASSED;
62 }
63 $this->logger->debug(
64 '{name} editing "{title}" submitted bogus field "{input}"',
65 [
66 'name' => $this->user->getName(),
67 'title' => $this->title->getPrefixedText(),
68 'input' => $this->input
69 ]
70 );
71 return self::CONSTRAINT_FAILED;
72 }
73
74 public function getLegacyStatus(): StatusValue {
75 $statusValue = StatusValue::newGood();
76 if ( $this->input !== '' ) {
77 $statusValue->fatal( 'spamprotectionmatch', false );
78 $statusValue->value = self::AS_SPAM_ERROR;
79 }
80 return $statusValue;
81 }
82
83 }