MediaWiki  master
AbstractContributionHandler.php
Go to the documentation of this file.
1 <?php
2 
4 
11 
15 abstract 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()->getActor();
61  if ( !$user->isRegistered() ) {
62  throw new LocalizedHttpException(
63  new MessageValue( 'rest-permission-denied-anon' ), 401
64  );
65  }
66  return $user;
67  }
68 
69  /* @var UserIdentity $user */
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 }
MediaWiki\Rest\Handler\AbstractContributionHandler
Definition: AbstractContributionHandler.php:15
MediaWiki\Rest\Handler
Definition: AbstractContributionHandler.php:3
MediaWiki\Rest\Handler\AbstractContributionHandler\postInitSetup
postInitSetup()
The handler can override this to do any necessary setup after init() is called to inject the dependen...
Definition: AbstractContributionHandler.php:47
MediaWiki\Rest\Handler\AbstractContributionHandler\__construct
__construct(ContributionsLookup $contributionsLookup, UserNameUtils $userNameUtils)
Definition: AbstractContributionHandler.php:39
MediaWiki\Rest\Handler\AbstractContributionHandler\$contributionsLookup
ContributionsLookup $contributionsLookup
Definition: AbstractContributionHandler.php:20
MediaWiki\Rest\Handler\AbstractContributionHandler\$me
bool $me
User is requesting their own contributions.
Definition: AbstractContributionHandler.php:28
MediaWiki\Rest\Handler\AbstractContributionHandler\$userNameUtils
UserNameUtils $userNameUtils
Definition: AbstractContributionHandler.php:33
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
Wikimedia\Message\MessageValue
Value object representing a message for i18n.
Definition: MessageValue.php:16
MediaWiki\Rest\Handler
Base class for REST route handlers.
Definition: Handler.php:17
MediaWiki\Rest\Handler\getValidatedParams
getValidatedParams()
Fetch the validated parameters.
Definition: Handler.php:282
MediaWiki\Rest\Handler\getConfig
getConfig()
Get the configuration array for the current route.
Definition: Handler.php:160
MediaWiki\Rest\Handler\AbstractContributionHandler\getTargetUser
getTargetUser()
Returns the user who's contributions we are requesting.
Definition: AbstractContributionHandler.php:58
Revision\ContributionsLookup
Definition: ContributionsLookup.php:23
MediaWiki\Rest\Handler\AbstractContributionHandler\MAX_LIMIT
const MAX_LIMIT
Hard limit results to 20 contributions.
Definition: AbstractContributionHandler.php:23
MediaWiki\User\UserNameUtils
UserNameUtils service.
Definition: UserNameUtils.php:42
MediaWiki\Rest\Handler\getAuthority
getAuthority()
Get the current acting authority.
Definition: Handler.php:149
MediaWiki\Rest\LocalizedHttpException
@newable
Definition: LocalizedHttpException.php:10