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 | /** @inheritDoc */ |
| 30 | public function needsWriteAccess() { |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | /** @inheritDoc */ |
| 35 | public function getParamSettings() { |
| 36 | return [ |
| 37 | 'oldId' => [ |
| 38 | self::PARAM_SOURCE => 'path', |
| 39 | ParamValidator::PARAM_REQUIRED => true, |
| 40 | ParamValidator::PARAM_TYPE => 'integer', |
| 41 | ], |
| 42 | 'newId' => [ |
| 43 | self::PARAM_SOURCE => 'path', |
| 44 | ParamValidator::PARAM_REQUIRED => true, |
| 45 | ParamValidator::PARAM_TYPE => 'integer', |
| 46 | ] |
| 47 | ]; |
| 48 | } |
| 49 | } |