Rename path param "name" to user in UserContributions endpoints. Name is more appropriate as "name" could be username as well as IP address or range of IP addresses. It also fits better with the implementation, as the user parameter gets validated as a User object. Bug: T259680 Change-Id: I6a146d99d1063c250f2ac460e4576bc287259766
50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Rest\Handler;
|
|
|
|
use MediaWiki\ParamValidator\TypeDef\UserDef;
|
|
use MediaWiki\Rest\LocalizedHttpException;
|
|
use MediaWiki\Rest\ResponseInterface;
|
|
use RequestContext;
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
|
|
|
/**
|
|
* @since 1.35
|
|
*/
|
|
class ContributionsCountHandler extends AbstractContributionHandler {
|
|
|
|
/**
|
|
* @return array|ResponseInterface
|
|
* @throws LocalizedHttpException
|
|
*/
|
|
public function execute() {
|
|
$performer = RequestContext::getMain()->getUser();
|
|
$target = $this->getTargetUser();
|
|
$tag = $this->getValidatedParams()['tag'];
|
|
$count = $this->contributionsLookup->getContributionCount( $target, $performer, $tag );
|
|
$response = [ 'count' => $count ];
|
|
return $response;
|
|
}
|
|
|
|
public function getParamSettings() {
|
|
$settings = [
|
|
'tag' => [
|
|
self::PARAM_SOURCE => 'query',
|
|
ParamValidator::PARAM_TYPE => 'string',
|
|
ParamValidator::PARAM_REQUIRED => false,
|
|
ParamValidator::PARAM_DEFAULT => null,
|
|
]
|
|
];
|
|
if ( $this->me === false ) {
|
|
$settings['user'] = [
|
|
self::PARAM_SOURCE => 'path',
|
|
ParamValidator::PARAM_REQUIRED => true,
|
|
ParamValidator::PARAM_TYPE => 'user',
|
|
UserDef::PARAM_RETURN_OBJECT => true,
|
|
UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'ip' ],
|
|
];
|
|
}
|
|
return $settings;
|
|
}
|
|
|
|
}
|