Add raw HTML output functionality
authortheopolisme <theopolismewiki@gmail.com>
Tue, 17 Dec 2013 12:11:49 +0000 (06:11 -0600)
committertheopolisme <theopolismewiki@gmail.com>
Tue, 17 Dec 2013 21:49:44 +0000 (15:49 -0600)
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

includes/specials/SpecialExpandTemplates.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index a78133c..24476fe 100644 (file)
@@ -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
                ) . '</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' )
@@ -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( "<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' ) );
        }
 }
index 0fe59e0..f1094b7 100644 (file)
@@ -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
 <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',
 );
index e3e574a..fb260b5 100644 (file)
@@ -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 <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]]
@@ -10553,6 +10554,7 @@ Ticked:
 test
 </pre>",
 'expand_templates_generate_xml' => 'Used as checkbox label.',
+'expand_templates_generate_rawhtml' => 'Used as checkbox label.',
 'expand_templates_preview' => '{{Identical|Preview}}',
 
 );
index aeb9453..4ca74f7 100644 (file)
@@ -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',
        ),
 );