Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.44% covered (success)
94.44%
17 / 18
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
DiffHeaderHandler
94.44% covered (success)
94.44%
17 / 18
66.67% covered (warning)
66.67%
2 / 3
3.00
0.00% covered (danger)
0.00%
0 / 1
 run
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 needsWriteAccess
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getParamSettings
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace MediaWiki\Extension\FlaggedRevs\Rest;
4
5use FlaggablePageView;
6use MediaWiki\Rest\Response;
7use MediaWiki\Rest\SimpleHandler;
8use MediaWiki\Rest\StringStream;
9use Wikimedia\ParamValidator\ParamValidator;
10
11/**
12 * Handler class for REST API endpoints that update diff header items
13 */
14class 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}