Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
32 / 32 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ArchivedRevisionHandler | |
100.00% |
32 / 32 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
factory | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
getRevision | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace MediaWiki\IPInfo\Rest\Handler; |
4 | |
5 | use JobQueueGroup; |
6 | use MediaWiki\IPInfo\InfoManager; |
7 | use MediaWiki\IPInfo\Rest\Presenter\DefaultPresenter; |
8 | use MediaWiki\IPInfo\TempUserIPLookup; |
9 | use MediaWiki\Languages\LanguageFallback; |
10 | use MediaWiki\Permissions\PermissionManager; |
11 | use MediaWiki\Registration\ExtensionRegistry; |
12 | use MediaWiki\Rest\LocalizedHttpException; |
13 | use MediaWiki\Revision\ArchivedRevisionLookup; |
14 | use MediaWiki\Revision\RevisionRecord; |
15 | use MediaWiki\User\Options\UserOptionsLookup; |
16 | use MediaWiki\User\UserFactory; |
17 | use MediaWiki\User\UserIdentityUtils; |
18 | use Wikimedia\Message\MessageValue; |
19 | |
20 | class ArchivedRevisionHandler extends AbstractRevisionHandler { |
21 | |
22 | private ArchivedRevisionLookup $archivedRevisionLookup; |
23 | |
24 | public function __construct( |
25 | InfoManager $infoManager, |
26 | ArchivedRevisionLookup $archivedRevisionLookup, |
27 | PermissionManager $permissionManager, |
28 | UserOptionsLookup $userOptionsLookup, |
29 | UserFactory $userFactory, |
30 | DefaultPresenter $presenter, |
31 | JobQueueGroup $jobQueueGroup, |
32 | LanguageFallback $languageFallback, |
33 | UserIdentityUtils $userIdentityUtils, |
34 | TempUserIPLookup $tempUserIPLookup, |
35 | ExtensionRegistry $extensionRegistry |
36 | ) { |
37 | parent::__construct( |
38 | $infoManager, |
39 | $permissionManager, |
40 | $userOptionsLookup, |
41 | $userFactory, |
42 | $presenter, |
43 | $jobQueueGroup, |
44 | $languageFallback, |
45 | $userIdentityUtils, |
46 | $tempUserIPLookup, |
47 | $extensionRegistry |
48 | ); |
49 | $this->archivedRevisionLookup = $archivedRevisionLookup; |
50 | } |
51 | |
52 | public static function factory( |
53 | InfoManager $infoManager, |
54 | ArchivedRevisionLookup $archivedRevisionLookup, |
55 | PermissionManager $permissionManager, |
56 | UserOptionsLookup $userOptionsLookup, |
57 | UserFactory $userFactory, |
58 | JobQueueGroup $jobQueueGroup, |
59 | LanguageFallback $languageFallback, |
60 | UserIdentityUtils $userIdentityUtils, |
61 | TempUserIPLookup $tempUserIPLookup, |
62 | ?ExtensionRegistry $extensionRegistry = null |
63 | ): self { |
64 | return new self( |
65 | $infoManager, |
66 | $archivedRevisionLookup, |
67 | $permissionManager, |
68 | $userOptionsLookup, |
69 | $userFactory, |
70 | new DefaultPresenter( $permissionManager ), |
71 | $jobQueueGroup, |
72 | $languageFallback, |
73 | $userIdentityUtils, |
74 | $tempUserIPLookup, |
75 | $extensionRegistry ?? ExtensionRegistry::getInstance() |
76 | ); |
77 | } |
78 | |
79 | /** @inheritDoc */ |
80 | protected function getRevision( int $id ): ?RevisionRecord { |
81 | if ( !$this->permissionManager->userHasRight( $this->getAuthority()->getUser(), 'deletedhistory' ) ) { |
82 | throw new LocalizedHttpException( |
83 | new MessageValue( 'ipinfo-rest-access-denied' ), |
84 | $this->getAuthority()->getUser()->isRegistered() ? 403 : 401 |
85 | ); |
86 | } |
87 | |
88 | return $this->archivedRevisionLookup->getArchivedRevisionRecord( null, $id ); |
89 | } |
90 | } |