Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| TransformWikitextToHtmlTitleHandler | |
0.00% |
0 / 47 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
| getParamSettings | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| getRequestBodySchema | |
0.00% |
0 / 36 |
|
0.00% |
0 / 1 |
2 | |||
| getRequestBodyDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRequestBodyExample | |
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 TransformWikitextToHtmlTitleHandler 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-wikitext-to-html-title' ), |
| 31 | Handler::PARAM_EXAMPLE => 'Main_Page', |
| 32 | ], |
| 33 | ]; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * The parent TransformHandler class accepts a variety of body parameters in different |
| 38 | * situations, some of which can accept values in multiple types and therefore cannot |
| 39 | * be described in getBodyParamSettings(). See TransformHandler::execute(), and notice |
| 40 | * that both "wikitext" and "html" can be either a string or an object. |
| 41 | * |
| 42 | * We therefore define a request body schema directly rather than the more common approach of |
| 43 | * generating it from definitions in getBodyParamSettings(). |
| 44 | */ |
| 45 | protected function getRequestBodySchema( string $mediaType ): array { |
| 46 | return [ |
| 47 | 'oneOf' => [ |
| 48 | [ |
| 49 | 'type' => 'object', |
| 50 | 'properties' => [ |
| 51 | 'wikitext' => [ |
| 52 | 'x-i18n-description' => 'rest-property-desc-transform-wikitext', |
| 53 | 'example' => '== Hello world ==', |
| 54 | 'type' => 'string', |
| 55 | ] |
| 56 | ] |
| 57 | ], |
| 58 | [ |
| 59 | 'type' => 'object', |
| 60 | 'properties' => [ |
| 61 | 'wikitext' => [ |
| 62 | 'x-i18n-description' => 'rest-property-desc-transform-wikitext-with-headers', |
| 63 | 'example' => [ 'body' => '== Hello world ==' ], |
| 64 | 'type' => 'object', |
| 65 | 'properties' => [ |
| 66 | 'headers' => [ |
| 67 | 'x-i18n-description' => 'rest-property-desc-transform-wikitext-headers', |
| 68 | 'example' => [ 'content-language' => 'en' ], |
| 69 | 'type' => 'object', |
| 70 | ], |
| 71 | 'body' => [ |
| 72 | 'x-i18n-description' => 'rest-property-desc-transform-wikitext-body', |
| 73 | 'example' => '== Hello world ==', |
| 74 | 'type' => 'string', |
| 75 | ] |
| 76 | ] |
| 77 | ] |
| 78 | ] |
| 79 | ] |
| 80 | ], |
| 81 | ]; |
| 82 | } |
| 83 | |
| 84 | public function getRequestBodyDescription(): MessageValue|string|null { |
| 85 | return new MessageValue( 'rest-requestbody-desc-transform-wikitext' ); |
| 86 | } |
| 87 | |
| 88 | public function getRequestBodyExample( string $mediaType ): ?array { |
| 89 | return [ 'wikitext' => '== Hello world ==' ]; |
| 90 | } |
| 91 | } |