MediaWiki  master
ContributionsCountHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Rest\Handler;
4 
10 
15 
20  public function execute() {
21  $performer = RequestContext::getMain()->getUser();
22  $target = $this->getTargetUser();
23  $tag = $this->getValidatedParams()['tag'];
24  $count = $this->contributionsLookup->getContributionCount( $target, $performer, $tag );
25  $response = [ 'count' => $count ];
26  return $response;
27  }
28 
29  public function getParamSettings() {
30  $settings = [
31  'tag' => [
32  self::PARAM_SOURCE => 'query',
33  ParamValidator::PARAM_TYPE => 'string',
34  ParamValidator::PARAM_REQUIRED => false,
35  ParamValidator::PARAM_DEFAULT => null,
36  ]
37  ];
38  if ( $this->me === false ) {
39  $settings['user'] = [
40  self::PARAM_SOURCE => 'path',
41  ParamValidator::PARAM_REQUIRED => true,
42  ParamValidator::PARAM_TYPE => 'user',
43  UserDef::PARAM_RETURN_OBJECT => true,
44  UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'ip' ],
45  ];
46  }
47  return $settings;
48  }
49 
50 }
MediaWiki\Rest\Handler\AbstractContributionHandler
Definition: AbstractContributionHandler.php:16
MediaWiki\Rest\Handler\ContributionsCountHandler\getParamSettings
getParamSettings()
Fetch ParamValidator settings for parameters.
Definition: ContributionsCountHandler.php:29
MediaWiki\Rest\Handler
Definition: AbstractContributionHandler.php:3
Wikimedia\ParamValidator\ParamValidator::TypeDef\UserDef
Type definition for user types.
Definition: UserDef.php:25
MediaWiki\Rest\Handler\ContributionsCountHandler
Definition: ContributionsCountHandler.php:14
RequestContext
Group all the pieces relevant to the context of a request into one instance @newable.
Definition: RequestContext.php:38
MediaWiki\Rest\Handler\getValidatedParams
getValidatedParams()
Fetch the validated parameters.
Definition: Handler.php:257
MediaWiki\Rest\ResponseInterface
An interface similar to PSR-7's ResponseInterface, the primary difference being that it is mutable.
Definition: ResponseInterface.php:41
MediaWiki\Rest\Handler\AbstractContributionHandler\getTargetUser
getTargetUser()
Returns the user who's contributions we are requesting.
Definition: AbstractContributionHandler.php:59
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:451
MediaWiki\Rest\Handler\ContributionsCountHandler\execute
execute()
Definition: ContributionsCountHandler.php:20
Wikimedia\ParamValidator\ParamValidator
Service for formatting and validating API parameters.
Definition: ParamValidator.php:42
MediaWiki\Rest\LocalizedHttpException
@newable
Definition: LocalizedHttpException.php:10