MediaWiki REL1_39
AbstractContributionHandler.php
Go to the documentation of this file.
1<?php
2
4
11
15abstract class AbstractContributionHandler extends Handler {
16
21
23 protected const MAX_LIMIT = 20;
24
28 protected $me;
29
33 protected $userNameUtils;
34
39 public function __construct(
42 ) {
43 $this->contributionsLookup = $contributionsLookup;
44 $this->userNameUtils = $userNameUtils;
45 }
46
47 protected function postInitSetup() {
48 $this->me = $this->getConfig()['mode'] === 'me';
49 }
50
58 protected function getTargetUser() {
59 if ( $this->me ) {
60 $user = $this->getAuthority()->getUser();
61 if ( !$user->isRegistered() ) {
62 throw new LocalizedHttpException(
63 new MessageValue( 'rest-permission-denied-anon' ), 401
64 );
65 }
66 return $user;
67 }
68
70 $user = $this->getValidatedParams()['user'];
71 $name = $user->getName();
72 if ( !$this->userNameUtils->isIp( $name ) && !$user->isRegistered() ) {
73 throw new LocalizedHttpException(
74 new MessageValue( 'rest-nonexistent-user', [ $name ] ), 404
75 );
76 }
77 return $user;
78 }
79}
__construct(ContributionsLookup $contributionsLookup, UserNameUtils $userNameUtils)
getTargetUser()
Returns the user who's contributions we are requesting.
const MAX_LIMIT
Hard limit results to 20 contributions.
bool $me
User is requesting their own contributions.
postInitSetup()
The handler can override this to do any necessary setup after init() is called to inject the dependen...
Base class for REST route handlers.
Definition Handler.php:20
getConfig()
Get the configuration array for the current route.
Definition Handler.php:168
getValidatedParams()
Fetch the validated parameters.
Definition Handler.php:336
getAuthority()
Get the current acting authority.
Definition Handler.php:157
UserNameUtils service.
Value object representing a message for i18n.
Interface for objects representing user identity.
Copyright (C) 2011-2020 Wikimedia Foundation and others.