60 $input = $request->getText(
'wpInput' );
62 if ( $input !==
'' ) {
63 $removeComments = $request->getBool(
'wpRemoveComments',
false );
64 $removeNowiki = $request->getBool(
'wpRemoveNowiki',
false );
65 $generateXML = $request->getBool(
'wpGenerateXml' );
66 $generateRawHtml = $request->getBool(
'wpGenerateRawHtml' );
68 $options = ParserOptions::newFromContext( $this->
getContext() );
69 $options->setRemoveComments( $removeComments );
70 $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
72 $titleStr = $request->getText(
'wpContextTitle' );
73 $title = Title::newFromText( $titleStr );
79 $parser = $this->parserFactory->getInstance();
81 $parser->startExternalParse( $title, $options, Parser::OT_PREPROCESS );
82 $dom = $parser->preprocessToDom( $input );
84 if ( method_exists( $dom,
'saveXML' ) ) {
86 $xml = $dom->saveXML();
89 $xml = $dom->__toString();
93 $output = $parser->preprocess( $input, $title, $options );
99 $out->addHTML( $this->makeOutput( $xml,
'expand_templates_xml_output' ) );
102 $tmp = $this->makeOutput( $output );
104 if ( $removeNowiki ) {
106 [
'_<nowiki>_',
'_</nowiki>_',
'_<nowiki */>_' ],
112 $tmp = $this->tidy->tidy( $tmp );
114 $out->addHTML( $tmp );
116 $pout = $parser->parse( $output, $title, $options );
119 ->run( $pout, $options, [
'enableSectionEditLinks' =>
false ] )->getContentHolderText();
120 if ( $generateRawHtml && $rawhtml !==
'' ) {
121 $out->addHTML( $this->makeOutput( $rawhtml,
'expand_templates_html_output' ) );
124 $this->showHtmlPreview( $title, $pout, $options, $out );
231 private function showHtmlPreview( Title $title, ParserOutput $pout, ParserOptions $popts, OutputPage $out ) {