Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1426040
SpamChecker.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
SpamChecker.php
View Options
<?php
namespace
MediaWiki\EditPage
;
/**
* Service to check if text (either content or a summary) qualifies as spam
*
* Text qualifies as spam if it matches the global $wgSpamRegex
* Summaries qualify as spam if they match the global $wgSummarySpamRegex
*
* @author DannyS712
* @since 1.35
*/
class
SpamChecker
{
/** @var string[] */
private
$spamRegex
;
/** @var string[] */
private
$summaryRegex
;
/**
* @param string[] $spamRegex
* @param string[] $summaryRegex
*/
public
function
__construct
(
$spamRegex
,
$summaryRegex
)
{
$this
->
spamRegex
=
$spamRegex
;
$this
->
summaryRegex
=
$summaryRegex
;
}
/**
* Check whether content text is considered spam
*
* @param string $text
* @return string|false Matching string or false
*/
public
function
checkContent
(
string
$text
)
{
return
self
::
checkInternal
(
$text
,
$this
->
spamRegex
);
}
/**
* Check whether summary text is considered spam
*
* @param string $summary
* @return string|false Matching string or false
*/
public
function
checkSummary
(
string
$summary
)
{
return
self
::
checkInternal
(
$summary
,
$this
->
summaryRegex
);
}
/**
* @param string $text
* @param array $regexes
* @return string|false
*/
private
static
function
checkInternal
(
string
$text
,
array
$regexes
)
{
foreach
(
$regexes
as
$regex
)
{
$matches
=
[];
if
(
preg_match
(
$regex
,
$text
,
$matches
)
)
{
return
$matches
[
0
];
}
}
return
false
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 12:27 (1 d, 4 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
b3/2b/098da9641b55d52e340c248c182e
Default Alt Text
SpamChecker.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment