MediaWiki  master
SimpleAntiSpamConstraint.php
Go to the documentation of this file.
1 <?php
22 
24 use Psr\Log\LoggerInterface;
25 use StatusValue;
26 use Title;
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,
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 }
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
MediaWiki\EditPage\Constraint\SimpleAntiSpamConstraint
Verify simple anti spam measure of an extra hidden text field.
Definition: SimpleAntiSpamConstraint.php:34
MediaWiki\EditPage\Constraint\SimpleAntiSpamConstraint\__construct
__construct(LoggerInterface $logger, string $inputText, UserIdentity $user, Title $title)
Definition: SimpleAntiSpamConstraint.php:54
MediaWiki\EditPage\IEditObject\AS_SPAM_ERROR
const AS_SPAM_ERROR
Status: summary contained spam according to one of the regexes in $wgSummarySpamRegex.
Definition: IEditObject.php:89
MediaWiki\EditPage\Constraint\SimpleAntiSpamConstraint\checkConstraint
checkConstraint()
Definition: SimpleAntiSpamConstraint.php:66
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
MediaWiki\EditPage\Constraint\SimpleAntiSpamConstraint\$title
Title $title
Definition: SimpleAntiSpamConstraint.php:46
MediaWiki\EditPage\Constraint\SimpleAntiSpamConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition: SimpleAntiSpamConstraint.php:81
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
Title
Represents a title within MediaWiki.
Definition: Title.php:47
MediaWiki\EditPage\Constraint\SimpleAntiSpamConstraint\$logger
LoggerInterface $logger
Definition: SimpleAntiSpamConstraint.php:37
MediaWiki\EditPage\Constraint\SimpleAntiSpamConstraint\$user
UserIdentity $user
Definition: SimpleAntiSpamConstraint.php:43
MediaWiki\EditPage\Constraint
Definition: AccidentalRecreationConstraint.php:21
MediaWiki\EditPage\Constraint\SimpleAntiSpamConstraint\$input
string $input
Definition: SimpleAntiSpamConstraint.php:40
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition: IEditConstraint.php:33