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 }
MediaWiki\EditPage\SpamChecker\$spamRegex
string[] $spamRegex
Definition: SpamChecker.php:17
MediaWiki\EditPage\SpamChecker\__construct
__construct( $spamRegex, $summaryRegex)
Definition: SpamChecker.php:26
$matches
$matches
Definition: NoLocalSettings.php:24
MediaWiki\EditPage\SpamChecker\checkInternal
static checkInternal(string $text, array $regexes)
Definition: SpamChecker.php:56
MediaWiki\EditPage\SpamChecker\checkSummary
checkSummary(string $summary)
Check whether summary text is considered spam.
Definition: SpamChecker.php:47
MediaWiki\EditPage\SpamChecker
Service to check if text (either content or a summary) qualifies as spam.
Definition: SpamChecker.php:14
MediaWiki\EditPage\SpamChecker\$summaryRegex
string[] $summaryRegex
Definition: SpamChecker.php:20
MediaWiki\EditPage\SpamChecker\checkContent
checkContent(string $text)
Check whether content text is considered spam.
Definition: SpamChecker.php:37
MediaWiki\EditPage
Definition: IEditObject.php:3