MediaWiki  1.33.0
ApiSpamBlacklist.php
Go to the documentation of this file.
1 <?php
31 class ApiSpamBlacklist extends ApiBase {
32 
33  public function execute() {
34  $params = $this->extractRequestParams();
35  $matches = BaseBlacklist::getInstance( 'spam' )->filter( $params['url'], null, true );
36  $res = $this->getResult();
37 
38  if ( $matches !== false ) {
39  // this url is blacklisted.
40  $res->addValue( 'spamblacklist', 'result', 'blacklisted' );
41  $res->setIndexedTagName( $matches, 'match' );
42  $res->addValue( 'spamblacklist', 'matches', $matches );
43  } else {
44  // not blacklisted
45  $res->addValue( 'spamblacklist', 'result', 'ok' );
46  }
47  }
48 
49  public function getAllowedParams() {
50  return [
51  'url' => [
53  ApiBase::PARAM_ISMULTI => true,
54  ]
55  ];
56  }
57 
62  protected function getExamplesMessages() {
63  return [
64  'action=spamblacklist&url=http://www.example.com/|http://www.example.org/'
65  => 'apihelp-spamblacklist-example-1',
66  ];
67  }
68 
69  public function getHelpUrls() {
70  return [ 'https://www.mediawiki.org/wiki/Extension:SpamBlacklist/API' ];
71  }
72 }
BaseBlacklist\getInstance
static getInstance( $type)
Returns an instance of the given blacklist.
Definition: BaseBlacklist.php:115
ApiBase\PARAM_REQUIRED
const PARAM_REQUIRED
(boolean) Is the parameter required?
Definition: ApiBase.php:111
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:632
$params
$params
Definition: styleTest.css.php:44
$res
$res
Definition: database.txt:21
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:37
$matches
$matches
Definition: NoLocalSettings.php:24
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:743
ApiSpamBlacklist\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiSpamBlacklist.php:49
ApiSpamBlacklist
SpamBlacklist extension API.
Definition: ApiSpamBlacklist.php:31
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:51
ApiSpamBlacklist\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiSpamBlacklist.php:69
ApiSpamBlacklist\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiSpamBlacklist.php:33
ApiSpamBlacklist\getExamplesMessages
getExamplesMessages()
Definition: ApiSpamBlacklist.php:62