/** @var boolean whether or not to show the XML parse tree */
protected $generateXML;
+ /** @var boolean whether or not to show the raw HTML code */
+ protected $generateRawHtml;
+
/** @var boolean whether or not to remove comments in the expanded wikitext */
protected $removeComments;
}
$input = $request->getText( 'wpInput' );
$this->generateXML = $request->getBool( 'wpGenerateXml' );
+ $this->generateRawHtml = $request->getBool( 'wpGenerateRawHtml' );
if ( strlen( $input ) ) {
$this->removeComments = $request->getBool( 'wpRemoveComments', false );
}
$out->addHTML( $tmp );
- $this->showHtmlPreview( $title, $output, $out );
+
+ $rawhtml = $this->generateHtml( $title, $output );
+
+ if ( $this->generateRawHtml && strlen( $rawhtml ) > 0 ) {
+ $out->addHTML( $this->makeOutput( $rawhtml, 'expand_templates_html_output' ) );
+ }
+
+ $this->showHtmlPreview( $title, $rawhtml, $out );
+
}
}
'generate_xml',
$this->generateXML
) . '</p>';
+ $form .= '<p>' . Xml::checkLabel(
+ $this->msg( 'expand_templates_generate_rawhtml' )->text(),
+ 'wpGenerateRawHtml',
+ 'generate_rawhtml',
+ $this->generateRawHtml
+ ) . '</p>';
$form .= '<p>' . Xml::submitButton(
$this->msg( 'expand_templates_ok' )->text(),
array( 'accesskey' => 's' )
}
/**
- * Render the supplied wiki text and append to the page as a preview
+ * Renders the supplied wikitext as html
*
* @param Title $title
* @param string $text
- * @param OutputPage $out
+ * @return string
*/
- private function showHtmlPreview( Title $title, $text, OutputPage $out ) {
+ private function generateHtml( Title $title, $text ) {
global $wgParser;
$popts = ParserOptions::newFromContext( $this->getContext() );
$popts->setTargetLanguage( $title->getPageLanguage() );
$pout = $wgParser->parse( $text, $title, $popts );
- $lang = $title->getPageViewLanguage();
+ return $pout->getText();
+ }
+
+ /**
+ * Wraps the provided html code in a div and outputs it to the page
+ *
+ * @param Title $title
+ * @param string $html
+ * @param OutputPage $out
+ */
+ private function showHtmlPreview( Title $title, $html, OutputPage $out ) {
+ $lang = $title->getPageViewLanguage();
$out->addHTML( "<h2>" . $this->msg( 'expand_templates_preview' )->escaped() . "</h2>\n" );
$out->addHTML( Html::openElement( 'div', array(
'class' => 'mw-content-' . $lang->getDir(),
'dir' => $lang->getDir(),
'lang' => $lang->getHtmlCode(),
) ) );
-
- $out->addHTML( $pout->getText() );
+ $out->addHTML( $html );
$out->addHTML( Html::closeElement( 'div' ) );
}
}
'limitreport-expensivefunctioncount-value' => '$1/$2', # only translate this message to other languages if you have to change it
# ExpandTemplates
-'expandtemplates' => 'Expand templates',
-'expand_templates_intro' => 'This special page takes text and expands all templates in it recursively.
+'expandtemplates' => 'Expand templates',
+'expand_templates_intro' => 'This special page takes text and expands all templates in it recursively.
It also expands supported parser functions like
<code><nowiki>{{</nowiki>#language:…}}</code> and variables like
<code><nowiki>{{</nowiki>CURRENTDAY}}</code>.
In fact, it expands pretty much everything in double-braces.',
-'expand_templates_title' => 'Context title, for {{FULLPAGENAME}}, etc.:',
-'expand_templates_input' => 'Input text:',
-'expand_templates_output' => 'Result',
-'expand_templates_xml_output' => 'XML output',
-'expand_templates_ok' => 'OK',
-'expand_templates_remove_comments' => 'Remove comments',
-'expand_templates_remove_nowiki' => 'Suppress <nowiki> tags in result',
-'expand_templates_generate_xml' => 'Show XML parse tree',
-'expand_templates_preview' => 'Preview',
+'expand_templates_title' => 'Context title, for {{FULLPAGENAME}}, etc.:',
+'expand_templates_input' => 'Input text:',
+'expand_templates_output' => 'Result',
+'expand_templates_xml_output' => 'XML output',
+'expand_templates_html_output' => 'Raw HTML output',
+'expand_templates_ok' => 'OK',
+'expand_templates_remove_comments' => 'Remove comments',
+'expand_templates_remove_nowiki' => 'Suppress <nowiki> tags in result',
+'expand_templates_generate_xml' => 'Show XML parse tree',
+'expand_templates_generate_rawhtml' => 'Show raw HTML',
+'expand_templates_preview' => 'Preview',
);
'expand_templates_input' => '{{Identical|Input text}}',
'expand_templates_output' => '{{Identical|Result}}',
'expand_templates_xml_output' => 'Used as HTML <code><nowiki><h2></nowiki></code> heading.',
+'expand_templates_html_output' => 'Used as HTML <code><nowiki><h2></nowiki></code> heading.',
'expand_templates_ok' => '{{Identical|OK}}',
'expand_templates_remove_comments' => 'Check box to tell [[mw:Extension:ExpandTemplates]] to not show comments in the expanded template.',
'expand_templates_remove_nowiki' => "Option on [[Special:Expandtemplates]]
test
</pre>",
'expand_templates_generate_xml' => 'Used as checkbox label.',
+'expand_templates_generate_rawhtml' => 'Used as checkbox label.',
'expand_templates_preview' => '{{Identical|Preview}}',
);
'expand_templates_input',
'expand_templates_output',
'expand_templates_xml_output',
+ 'expand_templates_html_output',
'expand_templates_ok',
'expand_templates_remove_comments',
'expand_templates_remove_nowiki',
'expand_templates_generate_xml',
+ 'expand_templates_generate_rawhtml',
'expand_templates_preview',
),
);