42 'from' => [ self::PARAM_SOURCE =>
'path',
43 ParamValidator::PARAM_TYPE =>
'string',
44 ParamValidator::PARAM_REQUIRED =>
true, ],
45 'format' => [ self::PARAM_SOURCE =>
'path',
46 ParamValidator::PARAM_TYPE =>
'string',
47 ParamValidator::PARAM_REQUIRED =>
true, ],
48 'title' => [ self::PARAM_SOURCE =>
'path',
49 ParamValidator::PARAM_TYPE =>
'string',
50 ParamValidator::PARAM_REQUIRED =>
false, ],
51 'revision' => [ self::PARAM_SOURCE =>
'path',
52 ParamValidator::PARAM_TYPE =>
'string',
53 ParamValidator::PARAM_REQUIRED =>
false, ], ];
87 $from = $request->getPathParam(
'from' );
88 $format = $request->getPathParam(
'format' );
93 $validTransformations = $this->
getConfig()[
'transformations'] ?? ParsoidFormatHelper::VALID_TRANSFORM;
95 if ( !isset( $validTransformations[$from] ) || !in_array( $format,
96 $validTransformations[$from],
98 throw new HttpException(
"Invalid transform: {$from}/to/{$format}",
101 $attribs = &$this->getRequestAttributes();
102 if ( !$this->acceptable( $attribs ) ) {
106 if ( $from === ParsoidFormatHelper::FORMAT_WIKITEXT ) {
108 $wikitext = $attribs[
'opts'][
'wikitext'] ??
null;
109 if ( is_array( $wikitext ) ) {
110 $wikitext = $wikitext[
'body'];
112 if ( isset( $attribs[
'opts'][
'wikitext'][
'headers'][
'content-language'] ) ) {
113 $attribs[
'pagelanguage'] = $attribs[
'opts'][
'wikitext'][
'headers'][
'content-language'];
117 if ( $wikitext ===
null && isset( $attribs[
'opts'][
'original'][
'wikitext'] ) ) {
118 $wikitext = $attribs[
'opts'][
'original'][
'wikitext'][
'body'];
120 if ( isset( $attribs[
'opts'][
'original'][
'wikitext'][
'headers'][
'content-language'] ) ) {
121 $attribs[
'pagelanguage'] = $attribs[
'opts'][
'original'][
'wikitext'][
'headers'][
'content-language'];
125 if ( $wikitext ===
null && $attribs[
'titleMissing'] ) {
126 throw new HttpException(
'No title or wikitext was provided.',
129 $pageConfig = $this->tryToCreatePageConfig( $attribs,
132 return $this->wt2html( $pageConfig,
135 } elseif ( $format === ParsoidFormatHelper::FORMAT_WIKITEXT ) {
136 $html = $attribs[
'opts'][
'html'] ??
null;
138 if ( is_array( $html ) ) {
139 $html = $html[
'body'];
141 if ( $html ===
null ) {
142 throw new HttpException(
'No html was supplied.',
148 $page = $this->tryToCreatePageIdentity( $attribs );
150 return $this->html2wt(
156 return $this->pb2pb( $attribs );