MediaWiki
REL1_35
ContributionsCountHandler.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Rest\Handler
;
4
5
use
MediaWiki\Rest\Handler
;
6
use
MediaWiki\Rest\LocalizedHttpException
;
7
use
MediaWiki\Rest\ResponseInterface
;
8
use
MediaWiki\Revision\ContributionsLookup
;
9
use
RequestContext
;
10
use
Wikimedia\Message\MessageValue
;
11
use
Wikimedia\ParamValidator\ParamValidator
;
12
16
class
ContributionsCountHandler
extends
Handler
{
17
21
private
$contributionsLookup
;
22
23
public
function
__construct
(
ContributionsLookup
$contributionsLookup
) {
24
$this->contributionsLookup =
$contributionsLookup
;
25
}
26
31
public
function
execute
() {
32
$user = RequestContext::getMain()->getUser();
33
if
( $user->isAnon() ) {
34
throw
new
LocalizedHttpException
(
35
new
MessageValue
(
'rest-permission-denied-anon'
), 401
36
);
37
}
38
39
$tag = $this->
getValidatedParams
()[
'tag'
];
40
$count = $this->contributionsLookup->getContributionCount( $user, $user, $tag );
41
42
$response = [
'count'
=> $count ];
43
44
return
$response;
45
}
46
47
public
function
getParamSettings
() {
48
return
[
49
'tag'
=> [
50
self::PARAM_SOURCE =>
'query'
,
51
ParamValidator::PARAM_TYPE =>
'string'
,
52
ParamValidator::PARAM_REQUIRED =>
false
,
53
ParamValidator::PARAM_DEFAULT =>
null
,
54
],
55
];
56
}
57
58
}
MediaWiki\Rest\Handler\ContributionsCountHandler
Definition
ContributionsCountHandler.php:16
MediaWiki\Rest\Handler\ContributionsCountHandler\$contributionsLookup
ContributionsLookup $contributionsLookup
Definition
ContributionsCountHandler.php:21
MediaWiki\Rest\Handler\ContributionsCountHandler\__construct
__construct(ContributionsLookup $contributionsLookup)
Definition
ContributionsCountHandler.php:23
MediaWiki\Rest\Handler\ContributionsCountHandler\getParamSettings
getParamSettings()
Fetch ParamValidator settings for parameters.
Definition
ContributionsCountHandler.php:47
MediaWiki\Rest\Handler\ContributionsCountHandler\execute
execute()
Definition
ContributionsCountHandler.php:31
MediaWiki\Rest\Handler
Base class for REST route handlers.
Definition
Handler.php:16
MediaWiki\Rest\Handler\getValidatedParams
getValidatedParams()
Fetch the validated parameters.
Definition
Handler.php:257
MediaWiki\Rest\LocalizedHttpException
@newable
Definition
LocalizedHttpException.php:10
MediaWiki\Revision\ContributionsLookup
Definition
ContributionsLookup.php:14
RequestContext
Group all the pieces relevant to the context of a request into one instance @newable.
Definition
RequestContext.php:38
Wikimedia\Message\MessageValue
Value object representing a message for i18n.
Definition
MessageValue.php:16
Wikimedia\ParamValidator\ParamValidator
Service for formatting and validating API parameters.
Definition
ParamValidator.php:42
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
Definition
ActionModuleBasedHandler.php:3
includes
Rest
Handler
ContributionsCountHandler.php
Generated on Sat Apr 6 2024 00:07:43 for MediaWiki by
1.9.8