Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.44% |
17 / 18 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
DiffHeaderHandler | |
94.44% |
17 / 18 |
|
66.67% |
2 / 3 |
3.00 | |
0.00% |
0 / 1 |
run | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
needsWriteAccess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getParamSettings | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\FlaggedRevs\Rest; |
4 | |
5 | use FlaggablePageView; |
6 | use MediaWiki\Rest\Response; |
7 | use MediaWiki\Rest\SimpleHandler; |
8 | use MediaWiki\Rest\StringStream; |
9 | use Wikimedia\ParamValidator\ParamValidator; |
10 | |
11 | /** |
12 | * Handler class for REST API endpoints that update diff header items |
13 | */ |
14 | class DiffHeaderHandler extends SimpleHandler { |
15 | |
16 | /** |
17 | * @param int $oldId |
18 | * @param int $newId |
19 | * @return Response |
20 | */ |
21 | public function run( int $oldId, int $newId ) { |
22 | $html = FlaggablePageView::buildDiffHeaderItems( $oldId, $newId ); |
23 | $response = $this->getResponseFactory()->create(); |
24 | $response->setBody( new StringStream( $html ) ); |
25 | $response->setHeader( 'Content-Type', 'text/html' ); |
26 | return $response; |
27 | } |
28 | |
29 | public function needsWriteAccess() { |
30 | return false; |
31 | } |
32 | |
33 | /** @inheritDoc */ |
34 | public function getParamSettings() { |
35 | return [ |
36 | 'oldId' => [ |
37 | self::PARAM_SOURCE => 'path', |
38 | ParamValidator::PARAM_REQUIRED => true, |
39 | ParamValidator::PARAM_TYPE => 'integer', |
40 | ], |
41 | 'newId' => [ |
42 | self::PARAM_SOURCE => 'path', |
43 | ParamValidator::PARAM_REQUIRED => true, |
44 | ParamValidator::PARAM_TYPE => 'integer', |
45 | ] |
46 | ]; |
47 | } |
48 | } |