-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathUserWikiRequestsHandler.php
More file actions
67 lines (55 loc) · 1.8 KB
/
Copy pathUserWikiRequestsHandler.php
File metadata and controls
67 lines (55 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare( strict_types = 1 );
namespace Miraheze\CreateWiki\RequestWiki\Rest;
use MediaWiki\Rest\Response;
use MediaWiki\Rest\SimpleHandler;
use MediaWiki\User\UserFactory;
use Miraheze\CreateWiki\Services\CreateWikiRestUtils;
use Miraheze\CreateWiki\Services\WikiRequestManager;
use Wikimedia\Message\MessageValue;
use Wikimedia\ParamValidator\ParamValidator;
/**
* Returns the IDs and suppression level of all wiki requests made by a user
* GET /createwiki/v0/wiki_requests/user/{username}
*/
class UserWikiRequestsHandler extends SimpleHandler {
public function __construct(
private readonly CreateWikiRestUtils $restUtils,
private readonly UserFactory $userFactory,
private readonly WikiRequestManager $wikiRequestManager,
) {
}
public function run( string $username ): Response {
$this->restUtils->checkEnv();
$requester = $this->userFactory->newFromName( $username );
if ( !$requester ) {
// A non-existing user has no requests
return $this->getResponseFactory()->createLocalizedHttpError(
404, new MessageValue( 'createwiki-rest-usernowikirequests' )
);
}
$wikiRequests = $this->wikiRequestManager->getVisibleRequestsByUser(
$requester, $this->getAuthority()->getUser()
);
if ( $wikiRequests ) {
return $this->getResponseFactory()->createJson( $wikiRequests );
}
// This user has never made wiki requests or the current
// user can not view any of them.
return $this->getResponseFactory()->createLocalizedHttpError(
404, new MessageValue( 'createwiki-rest-usernowikirequests' )
);
}
public function needsWriteAccess(): bool {
return false;
}
public function getParamSettings(): array {
return [
'username' => [
self::PARAM_SOURCE => 'path',
ParamValidator::PARAM_TYPE => 'string',
ParamValidator::PARAM_REQUIRED => true,
],
];
}
}