Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
TransformWikitextToHtmlTitleHandler
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 getParamSettings
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 getRequestBodySchema
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Rest\Handler;
4
5use MediaWiki\Rest\Handler;
6use Wikimedia\Message\MessageValue;
7use 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 */
21class 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-transform-title' ),
31            ],
32        ];
33    }
34
35    /**
36     * The parent TransformHandler class accepts a variety of body parameters in different
37     * situations, some of which can accept values in multiple types and therefore cannot
38     * be described in getBodyParamSettings(). See TransformHandler::execute(), and notice
39     * that both "wikitext" and "html" can be either a string or an object.
40     *
41     * We therefore define a request body schema directly rather than the more common approach of
42     * generating it from definitions in getBodyParamSettings().
43     */
44    protected function getRequestBodySchema( string $mediaType ): array {
45        return [
46            'oneOf' => [
47                [
48                    'type' => 'object',
49                    'properties' => [
50                        'wikitext' => [
51                            'type' => 'string',
52                        ]
53                    ]
54                ],
55                [
56                    'type' => 'object',
57                    'properties' => [
58                        'wikitext' => [
59                            'type' => 'object',
60                            'properties' => [
61                                'headers' => [
62                                    'type' => 'object',
63                                ],
64                                'body' => [
65                                    'type' => 'string',
66                                ]
67                            ]
68                        ]
69                    ]
70                ]
71            ],
72        ];
73    }
74}