Debian Codegraph @

extensions/SpamBlacklist/includes/ApiSpamBlacklist.php

raw symbols SCIP
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 public function getAllowedParams() {
60 return [
61 'url' => [
62 ParamValidator::PARAM_REQUIRED => true,
63 ParamValidator::PARAM_ISMULTI => true,
64 ]
65 ];
66 }
67
68 /**
69 * @see ApiBase::getExamplesMessages()
70 * @return array
71 */
72 protected function getExamplesMessages() {
73 return [
74 'action=spamblacklist&url=http://www.example.com/|http://www.example.org/'
75 => 'apihelp-spamblacklist-example-1',
76 ];
77 }
78
79 public function getHelpUrls() {
80 return [ 'https://www.mediawiki.org/wiki/Extension:SpamBlacklist/API' ];
81 }
82 }