MediaWiki  master
SpamChecker.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\EditPage;
4 
14 class SpamChecker {
15 
17  private $spamRegex;
18 
20  private $summaryRegex;
21 
26  public function __construct( $spamRegex, $summaryRegex ) {
27  $this->spamRegex = $spamRegex;
28  $this->summaryRegex = $summaryRegex;
29  }
30 
37  public function checkContent( string $text ) {
38  return self::checkInternal( $text, $this->spamRegex );
39  }
40 
47  public function checkSummary( string $summary ) {
48  return self::checkInternal( $summary, $this->summaryRegex );
49  }
50 
56  private static function checkInternal( string $text, array $regexes ) {
57  foreach ( $regexes as $regex ) {
58  $matches = [];
59  if ( preg_match( $regex, $text, $matches ) ) {
60  return $matches[0];
61  }
62  }
63  return false;
64  }
65 }
$matches
Service to check if text (either content or a summary) qualifies as spam.
Definition: SpamChecker.php:14
checkSummary(string $summary)
Check whether summary text is considered spam.
Definition: SpamChecker.php:47
checkContent(string $text)
Check whether content text is considered spam.
Definition: SpamChecker.php:37
static checkInternal(string $text, array $regexes)
Definition: SpamChecker.php:56
__construct( $spamRegex, $summaryRegex)
Definition: SpamChecker.php:26