wiki.techinc.nl/includes/Rest/Handler/ContributionsCountHandler.php
Thalia beff37ce18 Add 'temp' to allowed user types in various APIs
Why:

* Before this task, when an API parameter specifies allowed user
  types, temporary users and permanent users are in the same
  category: 'name'.
* However, it is useful to separate them out, and sometimes
  allow a permanent user but not a temporary user (e.g.
  ApiResetPassword, since temporary users don't have passwords).
* We therefore re-defined the 'name' type only to refer to
  permanent (named) users, and add a new 'temp' type.
* This fixes params that currently intend to allow temp users,
  and that use 'name' to do so, by adding 'temp'.

What:

* Based on a search for `UserDef::PARAM_ALLOWED_USER_TYPES`,
  add the 'temp' type where necessary.
* The following were not updated, because they shouldn't apply
  to temporary users:
  - owners for includes/api/ApiQueryWatchlist.php,
    includes/api/ApiQueryWatchlistRaw.php
  - users for includes/api/ApiResetPassword.php,
    includes/api/ApiUserrights.php,
    includes/api/ApiValidatePassword.php

Bug: T350701
Change-Id: If5ccf1d469327791acff74d013343307e411cca9
2023-11-30 14:19:40 +00: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', 'temp' ],
];
}
return $settings;
}
}