- $text = $wgParser->parse( $text, $title, ParserOptions::newFromContext( $this->getContext() ) )->getText();
+ $po = $content->getParserOutput( $title, ParserOptions::newFromContext( $this->getContext() ) );
+ $text = $po->getText();
+ }
+
+ if ( $text === null ) {
+ $format = $this->contentFormat ? $this->contentFormat : $content->getDefaultFormat();
+
+ if ( !$content->isSupportedFormat( $format ) ) {
+ $model = $content->getModel();
+ $formatName = ContentHandler::getContentFormatMimeType( $format );
+ $modelName = ContentHandler::getContentModelName( $model );
+ $name = $title->getPrefixedDBkey();
+
+ $this->dieUsage( "The requested format #{$this->contentFormat} ($formatName) is not supported for content model #$model ($modelName) used by $name", 'badformat' );
+ }
+
+ $text = $content->serialize( $format );
+ $vals['textformat'] = ContentHandler::getContentFormatMimeType( $format );
+ }
+
+ if ( $text !== false ) {
+ ApiResult::setContent( $vals, $text );