74 $input = $request->getText(
'wpInput' );
76 if ( $input !==
'' ) {
77 $removeComments = $request->getBool(
'wpRemoveComments',
false );
78 $removeNowiki = $request->getBool(
'wpRemoveNowiki',
false );
79 $generateXML = $request->getBool(
'wpGenerateXml' );
80 $generateRawHtml = $request->getBool(
'wpGenerateRawHtml' );
82 $options = ParserOptions::newFromContext( $this->
getContext() );
83 $options->setRemoveComments( $removeComments );
84 $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
86 $titleStr = $request->getText(
'wpContextTitle' );
87 $title = Title::newFromText( $titleStr );
93 $parser = $this->parserFactory->getInstance();
95 $parser->startExternalParse( $title, $options, Parser::OT_PREPROCESS );
96 $dom = $parser->preprocessToDom( $input );
98 if ( method_exists( $dom,
'saveXML' ) ) {
100 $xml = $dom->saveXML();
103 $xml = $dom->__toString();
107 $output = $parser->preprocess( $input, $title, $options );
111 if ( $generateXML ) {
113 $out->addHTML( $this->makeOutput( $xml,
'expand_templates_xml_output' ) );
116 $tmp = $this->makeOutput( $output );
118 if ( $removeNowiki ) {
120 [
'_<nowiki>_',
'_</nowiki>_',
'_<nowiki */>_' ],
126 $tmp = $this->tidy->tidy( $tmp );
128 $out->addHTML( $tmp );
130 $pout = $parser->parse( $output, $title, $options );
133 ->run( $pout, $options, [
'enableSectionEditLinks' =>
false ] )->getContentHolderText();
134 if ( $generateRawHtml && $rawhtml !==
'' ) {
135 $out->addHTML( $this->makeOutput( $rawhtml,
'expand_templates_html_output' ) );
138 $this->showHtmlPreview( $title, $pout, $options, $out );
245 private function showHtmlPreview( Title $title, ParserOutput $pout, ParserOptions $popts, OutputPage $out ) {