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