MediaWiki  master
ContributionsCountHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Rest\Handler;
4 
9 
14 
19  public function execute() {
20  $target = $this->getTargetUser();
21  $tag = $this->getValidatedParams()['tag'];
22  $count = $this->contributionsLookup->getContributionCount( $target, $this->getAuthority(), $tag );
23  $response = [ 'count' => $count ];
24  return $response;
25  }
26 
27  public function getParamSettings() {
28  $settings = [
29  'tag' => [
30  self::PARAM_SOURCE => 'query',
31  ParamValidator::PARAM_TYPE => 'string',
32  ParamValidator::PARAM_REQUIRED => false,
33  ParamValidator::PARAM_DEFAULT => null,
34  ]
35  ];
36  if ( $this->me === false ) {
37  $settings['user'] = [
38  self::PARAM_SOURCE => 'path',
39  ParamValidator::PARAM_REQUIRED => true,
40  ParamValidator::PARAM_TYPE => 'user',
41  UserDef::PARAM_RETURN_OBJECT => true,
42  UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'ip' ],
43  ];
44  }
45  return $settings;
46  }
47 
48 }
MediaWiki\Rest\Handler\AbstractContributionHandler
Definition: AbstractContributionHandler.php:15
MediaWiki\Rest\Handler\ContributionsCountHandler\getParamSettings
getParamSettings()
Fetch ParamValidator settings for parameters.
Definition: ContributionsCountHandler.php:27
MediaWiki\Rest\Handler
Definition: AbstractContributionHandler.php:3
Wikimedia\ParamValidator\ParamValidator::TypeDef\UserDef
Type definition for user types.
Definition: UserDef.php:26
MediaWiki\Rest\Handler\ContributionsCountHandler
Definition: ContributionsCountHandler.php:13
MediaWiki\Rest\Handler\getValidatedParams
getValidatedParams()
Fetch the validated parameters.
Definition: Handler.php:282
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:58
MediaWiki\Rest\Handler\ContributionsCountHandler\execute
execute()
Definition: ContributionsCountHandler.php:19
MediaWiki\Rest\Handler\getAuthority
getAuthority()
Get the current acting authority.
Definition: Handler.php:148
Wikimedia\ParamValidator\ParamValidator
Service for formatting and validating API parameters.
Definition: ParamValidator.php:42
MediaWiki\Rest\LocalizedHttpException
@newable
Definition: LocalizedHttpException.php:10