X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialExpandTemplates.php;h=7241105561bf95ce65a51a8387183998d6774186;hb=cb78f7f82018d415073d021a13bfa6a999f0dcdb;hp=a78133cb38f173119a2cb89765f010535aaf5453;hpb=b0b37fd95cd0e97fa5ceab0b0d1f5e2ce88b2b90;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialExpandTemplates.php b/includes/specials/SpecialExpandTemplates.php index a78133cb38..7241105561 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; @@ -58,10 +61,11 @@ class SpecialExpandTemplates extends SpecialPage { $title = Title::newFromText( $titleStr ); if ( !$title ) { - $title = $this->getTitle(); + $title = $this->getPageTitle(); } $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 ); + } } @@ -126,7 +138,7 @@ class SpecialExpandTemplates extends SpecialPage { * @return string */ private function makeForm( $title, $input ) { - $self = $this->getTitle(); + $self = $this->getPageTitle(); $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) @@ -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,42 @@ 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' ) ); } + + protected function getGroupName() { + return 'wiki'; + } }