wiki.techinc.nl/includes/Rest/Handler/ContributionsCountHandler.php
Petr Pchelko 3a2e8883b4 Rest: use Authority in all core handlers
Bug: T239753
Change-Id: Idf2229255f49514dd8b68bf63573c5b619b4f2f1
2021-01-21 18:22:33 -06:00

48 lines
1.2 KiB
PHP

<?php
namespace MediaWiki\Rest\Handler;
use MediaWiki\ParamValidator\TypeDef\UserDef;
use MediaWiki\Rest\LocalizedHttpException;
use MediaWiki\Rest\ResponseInterface;
use Wikimedia\ParamValidator\ParamValidator;
/**
* @since 1.35
*/
class ContributionsCountHandler extends AbstractContributionHandler {
/**
* @return array|ResponseInterface
* @throws LocalizedHttpException
*/
public function execute() {
$target = $this->getTargetUser();
$tag = $this->getValidatedParams()['tag'];
$count = $this->contributionsLookup->getContributionCount( $target, $this->getAuthority(), $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;
}
}