MediaWiki  master
SimpleAntiSpamConstraint.php
Go to the documentation of this file.
1 <?php
22 
25 use Psr\Log\LoggerInterface;
26 use StatusValue;
27 
35 
37  private $logger;
38 
40  private $input;
41 
43  private $user;
44 
46  private $title;
47 
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 }
if(!defined('MW_SETUP_CALLBACK'))
Definition: WebStart.php:88
Verify simple anti spam measure of an extra hidden text field.
getLegacyStatus()
Get the legacy status for failure (or success)
__construct(LoggerInterface $logger, string $inputText, UserIdentity $user, Title $title)
Represents a title within MediaWiki.
Definition: Title.php:76
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:46
fatal( $message,... $parameters)
Add an error and set OK to false, indicating that the operation as a whole was fatal.
Interface for all constraints that can prevent edits.
Interface for objects representing user identity.