Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| TransformWikitextToLintRevisionHandler | |
0.00% |
0 / 43 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
| getParamSettings | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 | |||
| getRequestBodySchema | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
2 | |||
| getResponseBodySchemaFileName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Rest\Handler; |
| 4 | |
| 5 | use MediaWiki\Rest\Handler; |
| 6 | use Wikimedia\Message\MessageValue; |
| 7 | use Wikimedia\ParamValidator\ParamValidator; |
| 8 | |
| 9 | /** |
| 10 | * Handler for transforming content given in the request. |
| 11 | * |
| 12 | * This class primarily deals with parameter validation and OpenAPI spec generation. |
| 13 | * Everything else is handled by the base class. |
| 14 | * |
| 15 | * TODO: reconsider the ParsoidHandler => TransformHandler hierarchy. Consider consolidating |
| 16 | * classes and moving more validation into functions like getParamSettings(), |
| 17 | * getBodyParamSettings(), etc. |
| 18 | * |
| 19 | * @unstable Pending consolidation of the Parsoid extension with core code. |
| 20 | */ |
| 21 | class TransformWikitextToLintRevisionHandler extends TransformHandler { |
| 22 | |
| 23 | /** @inheritDoc */ |
| 24 | public function getParamSettings() { |
| 25 | return [ |
| 26 | 'title' => [ |
| 27 | self::PARAM_SOURCE => 'path', |
| 28 | ParamValidator::PARAM_TYPE => 'string', |
| 29 | ParamValidator::PARAM_REQUIRED => true, |
| 30 | Handler::PARAM_DESCRIPTION => new MessageValue( 'rest-param-desc-transform-title' ), |
| 31 | ], |
| 32 | 'revision' => [ |
| 33 | self::PARAM_SOURCE => 'path', |
| 34 | ParamValidator::PARAM_TYPE => 'string', |
| 35 | ParamValidator::PARAM_REQUIRED => true, |
| 36 | Handler::PARAM_DESCRIPTION => new MessageValue( 'rest-param-desc-transform-revision' ), |
| 37 | ], |
| 38 | ]; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * The parent TransformHandler class accepts a variety of body parameters in different |
| 43 | * situations, some of which can accept values in multiple types and therefore cannot |
| 44 | * be described in getBodyParamSettings(). See TransformHandler::execute(), and notice |
| 45 | * that both "wikitext" and "html" can be either a string or an object. |
| 46 | * |
| 47 | * We therefore define a request body schema directly rather than the more common approach of |
| 48 | * generating it from definitions in getBodyParamSettings(). |
| 49 | */ |
| 50 | protected function getRequestBodySchema( string $mediaType ): array { |
| 51 | return [ |
| 52 | 'oneOf' => [ |
| 53 | [ |
| 54 | 'type' => 'object', |
| 55 | 'properties' => [ |
| 56 | 'wikitext' => [ |
| 57 | 'type' => 'string', |
| 58 | ] |
| 59 | ] |
| 60 | ], |
| 61 | [ |
| 62 | 'type' => 'object', |
| 63 | 'properties' => [ |
| 64 | 'wikitext' => [ |
| 65 | 'type' => 'object', |
| 66 | 'properties' => [ |
| 67 | 'headers' => [ |
| 68 | 'type' => 'object', |
| 69 | ], |
| 70 | 'body' => [ |
| 71 | 'type' => 'string', |
| 72 | ] |
| 73 | ] |
| 74 | ] |
| 75 | ] |
| 76 | ] |
| 77 | ], |
| 78 | ]; |
| 79 | } |
| 80 | |
| 81 | public function getResponseBodySchemaFileName( string $method ): ?string { |
| 82 | return __DIR__ . '/Schema/ContentLintErrors.json'; |
| 83 | } |
| 84 | } |