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