MediaWiki master
SimpleAntiSpamConstraint.php
Go to the documentation of this file.
1<?php
22
25use Psr\Log\LoggerInterface;
26use StatusValue;
27
35
36 private LoggerInterface $logger;
37 private string $input;
38 private UserIdentity $user;
39 private Title $title;
40
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}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
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:79
Generic operation result class Has warning/error list, boolean status and arbitrary value.
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.