Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
98.61% covered (success)
98.61%
71 / 72
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ReviewHandler
98.61% covered (success)
98.61%
71 / 72
75.00% covered (warning)
75.00%
3 / 4
5
0.00% covered (danger)
0.00%
0 / 1
 run
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 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%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 getBodyParamSettings
100.00% covered (success)
100.00%
57 / 57
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace MediaWiki\Extension\FlaggedRevs\Rest;
4
5use FlaggedRevs;
6use MediaWiki\Rest\Response;
7use MediaWiki\Rest\SimpleHandler;
8use RevisionReview;
9use Wikimedia\ParamValidator\ParamValidator;
10
11/**
12 * Handler class for REST API endpoint that updates revision review items
13 */
14class ReviewHandler extends SimpleHandler {
15
16    /**
17     * @param string $target
18     * @return Response
19     */
20    public function run( $target ) {
21        $body = $this->getValidatedBody();
22        $body[ 'target' ] = $target;
23        $result = RevisionReview::doReview( $body );
24        $response = $this->getResponseFactory()->createJson( $result );
25        if ( isset( $result[ 'error-html' ] ) ) {
26            $response->setStatus( 400 );
27        }
28        return $response;
29    }
30
31    public function needsWriteAccess() {
32        return true;
33    }
34
35    /** @inheritDoc */
36    public function getParamSettings() {
37        return [
38            'target' => [
39                self::PARAM_SOURCE => 'path',
40                ParamValidator::PARAM_TYPE => 'string',
41                ParamValidator::PARAM_REQUIRED => true,
42            ]
43        ];
44    }
45
46    /** @inheritDoc */
47    public function getBodyParamSettings(): array {
48        // NOTE: All parameters are received as strings, because review.js
49        //       takes the values from HTML form elements without understanding
50        //       their types.
51        //       This is not a problem since we pass the request body to
52        //       RevisionReview::doReview(), which is designed to handle submit
53        //       data from an HTML form, which is all strings anyway.
54
55        return [
56            'oldid' => [
57                self::PARAM_SOURCE => 'body',
58                ParamValidator::PARAM_TYPE => 'string',
59                ParamValidator::PARAM_REQUIRED => false,
60            ],
61            'refid' => [
62                self::PARAM_SOURCE => 'body',
63                ParamValidator::PARAM_TYPE => 'string',
64                ParamValidator::PARAM_REQUIRED => false,
65            ],
66            'validatedParams' => [
67                self::PARAM_SOURCE => 'body',
68                ParamValidator::PARAM_TYPE => 'string',
69                ParamValidator::PARAM_REQUIRED => false,
70            ],
71            'templateParams' => [
72                self::PARAM_SOURCE => 'body',
73                ParamValidator::PARAM_TYPE => 'string',
74                ParamValidator::PARAM_REQUIRED => false,
75            ],
76            'wpApprove' => [
77                self::PARAM_SOURCE => 'body',
78                ParamValidator::PARAM_TYPE => 'string',
79                ParamValidator::PARAM_REQUIRED => false,
80            ],
81            'wpUnapprove' => [
82                self::PARAM_SOURCE => 'body',
83                ParamValidator::PARAM_TYPE => 'string',
84                ParamValidator::PARAM_REQUIRED => false,
85            ],
86            'wpReject' => [
87                self::PARAM_SOURCE => 'body',
88                ParamValidator::PARAM_TYPE => 'string',
89                ParamValidator::PARAM_REQUIRED => false,
90            ],
91            'wpReason' => [
92                self::PARAM_SOURCE => 'body',
93                ParamValidator::PARAM_TYPE => 'string',
94                ParamValidator::PARAM_REQUIRED => false,
95            ],
96            'changetime' => [
97                self::PARAM_SOURCE => 'body',
98                ParamValidator::PARAM_TYPE => 'string',
99                ParamValidator::PARAM_REQUIRED => false,
100            ],
101            'wpEditToken' => [
102                self::PARAM_SOURCE => 'body',
103                ParamValidator::PARAM_TYPE => 'string',
104                ParamValidator::PARAM_REQUIRED => true,
105            ],
106            'wp' . FlaggedRevs::getTagName() => [
107                self::PARAM_SOURCE => 'body',
108                ParamValidator::PARAM_TYPE => 'string',
109                ParamValidator::PARAM_REQUIRED => false,
110            ],
111        ];
112    }
113}