Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ApiSpamBlacklist | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
execute | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 | |||
getAllowedParams | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * SpamBlacklist extension API |
4 | * |
5 | * Copyright © 2013 Wikimedia Foundation |
6 | * Based on code by Ian Baker, Victor Vasiliev, Bryan Tong Minh, Roan Kattouw, |
7 | * Alex Z., and Jackmcbarn |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License along |
20 | * with this program; if not, write to the Free Software Foundation, Inc., |
21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
22 | * http://www.gnu.org/copyleft/gpl.html |
23 | */ |
24 | |
25 | namespace MediaWiki\Extension\SpamBlacklist; |
26 | |
27 | use MediaWiki\Api\ApiBase; |
28 | use MediaWiki\Api\ApiResult; |
29 | use Wikimedia\ParamValidator\ParamValidator; |
30 | |
31 | /** |
32 | * Query module check a URL against the blacklist |
33 | * |
34 | * @ingroup API |
35 | * @ingroup Extensions |
36 | */ |
37 | class ApiSpamBlacklist extends ApiBase { |
38 | public function execute() { |
39 | $params = $this->extractRequestParams(); |
40 | $matches = BaseBlacklist::getSpamBlacklist()->filter( |
41 | $params['url'], |
42 | null, |
43 | $this->getUser(), |
44 | true |
45 | ); |
46 | $res = $this->getResult(); |
47 | |
48 | if ( $matches !== false ) { |
49 | // this url is blacklisted. |
50 | $res->addValue( 'spamblacklist', 'result', 'blacklisted' ); |
51 | ApiResult::setIndexedTagName( $matches, 'match' ); |
52 | $res->addValue( 'spamblacklist', 'matches', $matches ); |
53 | } else { |
54 | // not blacklisted |
55 | $res->addValue( 'spamblacklist', 'result', 'ok' ); |
56 | } |
57 | } |
58 | |
59 | /** @inheritDoc */ |
60 | public function getAllowedParams() { |
61 | return [ |
62 | 'url' => [ |
63 | ParamValidator::PARAM_REQUIRED => true, |
64 | ParamValidator::PARAM_ISMULTI => true, |
65 | ] |
66 | ]; |
67 | } |
68 | |
69 | /** |
70 | * @see ApiBase::getExamplesMessages() |
71 | * @return array |
72 | */ |
73 | protected function getExamplesMessages() { |
74 | return [ |
75 | 'action=spamblacklist&url=http://www.example.com/|http://www.example.org/' |
76 | => 'apihelp-spamblacklist-example-1', |
77 | ]; |
78 | } |
79 | |
80 | /** @inheritDoc */ |
81 | public function getHelpUrls() { |
82 | return [ 'https://www.mediawiki.org/wiki/Extension:SpamBlacklist/API' ]; |
83 | } |
84 | } |