From: theopolisme
Date: Tue, 17 Dec 2013 12:11:49 +0000 (-0600)
Subject: Add raw HTML output functionality
X-Git-Tag: 1.31.0-rc.0~17592^2
X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/membres/fiche.php?a=commitdiff_plain;h=034d448bb5455074377bf2f15e640d9f34f5843a;p=lhc%2Fweb%2Fwiklou.git
Add raw HTML output functionality
A new checkbox labeled "Show raw HTML" at
Special:ExpandTemplates will display the
raw HTML output in a textarea when checked.
Bug: 56694
Change-Id: If7895d2f9a257d8dd753a58cdb26da8a66aceb29
---
diff --git a/includes/specials/SpecialExpandTemplates.php b/includes/specials/SpecialExpandTemplates.php
index a78133cb38..24476fe962 100644
--- a/includes/specials/SpecialExpandTemplates.php
+++ b/includes/specials/SpecialExpandTemplates.php
@@ -32,6 +32,9 @@ class SpecialExpandTemplates extends SpecialPage {
/** @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;
@@ -62,6 +65,7 @@ class SpecialExpandTemplates extends SpecialPage {
}
$input = $request->getText( 'wpInput' );
$this->generateXML = $request->getBool( 'wpGenerateXml' );
+ $this->generateRawHtml = $request->getBool( 'wpGenerateRawHtml' );
if ( strlen( $input ) ) {
$this->removeComments = $request->getBool( 'wpRemoveComments', false );
@@ -113,7 +117,15 @@ class SpecialExpandTemplates extends SpecialPage {
}
$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 );
+
}
}
@@ -171,6 +183,12 @@ class SpecialExpandTemplates extends SpecialPage {
'generate_xml',
$this->generateXML
) . '
';
+ $form .= '' . Xml::checkLabel(
+ $this->msg( 'expand_templates_generate_rawhtml' )->text(),
+ 'wpGenerateRawHtml',
+ 'generate_rawhtml',
+ $this->generateRawHtml
+ ) . '
';
$form .= '' . Xml::submitButton(
$this->msg( 'expand_templates_ok' )->text(),
array( 'accesskey' => 's' )
@@ -202,28 +220,38 @@ class SpecialExpandTemplates extends SpecialPage {
}
/**
- * 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( "
" . $this->msg( 'expand_templates_preview' )->escaped() . "
\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' ) );
}
}
diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php
index 0fe59e0347..f1094b791e 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -5110,19 +5110,21 @@ Otherwise, you can use the easy form below. Your comment will be added to the pa
'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
{{#language:â¦}}
and variables like
{{CURRENTDAY}}
.
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 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 tags in result',
+'expand_templates_generate_xml' => 'Show XML parse tree',
+'expand_templates_generate_rawhtml' => 'Show raw HTML',
+'expand_templates_preview' => 'Preview',
);
diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php
index e3e574a499..fb260b5c3f 100644
--- a/languages/messages/MessagesQqq.php
+++ b/languages/messages/MessagesQqq.php
@@ -10532,6 +10532,7 @@ For more information, see [[mw:Extension:ExpandTemplates]]',
'expand_templates_input' => '{{Identical|Input text}}',
'expand_templates_output' => '{{Identical|Result}}',
'expand_templates_xml_output' => 'Used as HTML
heading.',
+'expand_templates_html_output' => 'Used as HTML
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]]
@@ -10553,6 +10554,7 @@ Ticked:
test
",
'expand_templates_generate_xml' => 'Used as checkbox label.',
+'expand_templates_generate_rawhtml' => 'Used as checkbox label.',
'expand_templates_preview' => '{{Identical|Preview}}',
);
diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc
index aeb9453994..4ca74f773c 100644
--- a/maintenance/language/messages.inc
+++ b/maintenance/language/messages.inc
@@ -3948,10 +3948,12 @@ $wgMessageStructure = array(
'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',
),
);