43 'from' => [ self::PARAM_SOURCE =>
'path',
44 ParamValidator::PARAM_TYPE =>
'string',
45 ParamValidator::PARAM_REQUIRED =>
true, ],
46 'format' => [ self::PARAM_SOURCE =>
'path',
47 ParamValidator::PARAM_TYPE =>
'string',
48 ParamValidator::PARAM_REQUIRED =>
true, ],
49 'title' => [ self::PARAM_SOURCE =>
'path',
50 ParamValidator::PARAM_TYPE =>
'string',
51 ParamValidator::PARAM_REQUIRED =>
false, ],
52 'revision' => [ self::PARAM_SOURCE =>
'path',
53 ParamValidator::PARAM_TYPE =>
'string',
54 ParamValidator::PARAM_REQUIRED =>
false, ], ];
88 $from = $request->getPathParam(
'from' );
89 $format = $request->getPathParam(
'format' );
94 $validTransformations = $this->
getConfig()[
'transformations'] ?? ParsoidFormatHelper::VALID_TRANSFORM;
96 if ( !isset( $validTransformations[$from] ) || !in_array( $format,
97 $validTransformations[$from],
101 $attribs = &$this->getRequestAttributes();
102 if ( !$this->acceptable( $attribs ) ) {
105 if ( $from === ParsoidFormatHelper::FORMAT_WIKITEXT ) {
107 $wikitext = $attribs[
'opts'][
'wikitext'] ??
null;
108 if ( is_array( $wikitext ) ) {
109 $wikitext = $wikitext[
'body'];
111 if ( isset( $attribs[
'opts'][
'wikitext'][
'headers'][
'content-language'] ) ) {
112 $attribs[
'pagelanguage'] = $attribs[
'opts'][
'wikitext'][
'headers'][
'content-language'];
116 if ( $wikitext ===
null && isset( $attribs[
'opts'][
'original'][
'wikitext'] ) ) {
117 $wikitext = $attribs[
'opts'][
'original'][
'wikitext'][
'body'];
119 if ( isset( $attribs[
'opts'][
'original'][
'wikitext'][
'headers'][
'content-language'] ) ) {
120 $attribs[
'pagelanguage'] = $attribs[
'opts'][
'original'][
'wikitext'][
'headers'][
'content-language'];
124 if ( $wikitext ===
null && empty( $attribs[
'pageName'] ) ) {
125 throw new LocalizedHttpException(
new MessageValue(
"rest-transform-missing-title" ), 400 );
127 $pageConfig = $this->tryToCreatePageConfig( $attribs, $wikitext );
129 return $this->wt2html( $pageConfig,
132 } elseif ( $format === ParsoidFormatHelper::FORMAT_WIKITEXT ) {
133 $html = $attribs[
'opts'][
'html'] ??
null;
135 if ( is_array( $html ) ) {
136 $html = $html[
'body'];
138 if ( $html ===
null ) {
139 throw new LocalizedHttpException(
new MessageValue(
"rest-transform-missing-html" ), 400 );
144 $page = $this->tryToCreatePageIdentity( $attribs );
146 return $this->html2wt(
152 return $this->pb2pb( $attribs );