Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
SpamBlacklist | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
validate | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
getLinks | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\SpamFilter; |
4 | |
5 | use ExtensionRegistry; |
6 | use Flow\Model\AbstractRevision; |
7 | use IContextSource; |
8 | use MediaWiki\Extension\SpamBlacklist\BaseBlacklist; |
9 | use MediaWiki\MediaWikiServices; |
10 | use MediaWiki\Status\Status; |
11 | use MediaWiki\Title\Title; |
12 | use ParserOptions; |
13 | |
14 | class SpamBlacklist implements SpamFilter { |
15 | /** |
16 | * @param IContextSource $context |
17 | * @param AbstractRevision $newRevision |
18 | * @param AbstractRevision|null $oldRevision |
19 | * @param Title $title |
20 | * @param Title $ownerTitle |
21 | * @return Status |
22 | */ |
23 | public function validate( |
24 | IContextSource $context, |
25 | AbstractRevision $newRevision, |
26 | ?AbstractRevision $oldRevision, |
27 | Title $title, |
28 | Title $ownerTitle |
29 | ) { |
30 | $spamObj = BaseBlacklist::getSpamBlacklist(); |
31 | |
32 | // TODO: This seems to check topic titles. Should it? There can't |
33 | // actually be a link in a topic title, but http://spam.com can still look |
34 | // spammy even if it's not a working link. |
35 | $links = $this->getLinks( $newRevision, $title ); |
36 | $matches = $spamObj->filter( $links, $title, $context->getUser() ); |
37 | |
38 | if ( $matches !== false ) { |
39 | $status = Status::newFatal( 'spamprotectiontext' ); |
40 | |
41 | foreach ( $matches as $match ) { |
42 | $status->fatal( 'spamprotectionmatch', $match ); |
43 | } |
44 | |
45 | return $status; |
46 | } |
47 | |
48 | return Status::newGood(); |
49 | } |
50 | |
51 | /** |
52 | * @param AbstractRevision $revision |
53 | * @param Title $title |
54 | * @return array |
55 | */ |
56 | public function getLinks( AbstractRevision $revision, Title $title ) { |
57 | $options = ParserOptions::newFromAnon(); |
58 | $output = MediaWikiServices::getInstance()->getParser() |
59 | ->parse( $revision->getContentInWikitext(), $title, $options ); |
60 | return array_keys( $output->getExternalLinks() ); |
61 | } |
62 | |
63 | /** |
64 | * Checks if SpamBlacklist is enabled. |
65 | * |
66 | * @return bool |
67 | */ |
68 | public function enabled() { |
69 | return ExtensionRegistry::getInstance()->isLoaded( 'SpamBlacklist' ); |
70 | } |
71 | } |