tags in the expanded wikitext */ protected $removeNowiki; /** @var int Maximum size in bytes to include. 50MB allows fixing those huge pages */ const MAX_INCLUDE_SIZE = 50000000; function __construct() { parent::__construct( 'ExpandTemplates' ); } /** * Show the special page * @param string|null $subpage */ function execute( $subpage ) { global $wgParser; $this->setHeaders(); $request = $this->getRequest(); $titleStr = $request->getText( 'wpContextTitle' ); $title = Title::newFromText( $titleStr ); if ( !$title ) { $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 ); $this->removeNowiki = $request->getBool( 'wpRemoveNowiki', false ); $options = ParserOptions::newFromContext( $this->getContext() ); $options->setRemoveComments( $this->removeComments ); $options->setTidy( true ); $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE ); if ( $this->generateXML ) { $wgParser->startExternalParse( $title, $options, Parser::OT_PREPROCESS ); $dom = $wgParser->preprocessToDom( $input ); if ( method_exists( $dom, 'saveXML' ) ) { $xml = $dom->saveXML(); } else { $xml = $dom->__toString(); } } $output = $wgParser->preprocess( $input, $title, $options ); } else { $this->removeComments = $request->getBool( 'wpRemoveComments', true ); $this->removeNowiki = $request->getBool( 'wpRemoveNowiki', false ); $output = false; } $out = $this->getOutput(); $out->addWikiMsg( 'expand_templates_intro' ); $out->addHTML( $this->makeForm( $titleStr, $input ) ); if ( $output !== false ) { if ( $this->generateXML && strlen( $output ) > 0 ) { $out->addHTML( $this->makeOutput( $xml, 'expand_templates_xml_output' ) ); } $tmp = $this->makeOutput( $output ); if ( $this->removeNowiki ) { $tmp = preg_replace( array( '_<nowiki>_', '_</nowiki>_', '_<nowiki */>_' ), '', $tmp ); } $config = $this->getConfig(); if ( ( $config->get( 'UseTidy' ) && $options->getTidy() ) || $config->get( 'AlwaysUseTidy' ) ) { $tmp = MWTidy::tidy( $tmp ); } $out->addHTML( $tmp ); $pout = $this->generateHtml( $title, $output ); $rawhtml = $pout->getText(); if ( $this->generateRawHtml && strlen( $rawhtml ) > 0 ) { $out->addHTML( $this->makeOutput( $rawhtml, 'expand_templates_html_output' ) ); } $this->showHtmlPreview( $title, $pout, $out ); } } /** * Generate a form allowing users to enter information * * @param string $title Value for context title field * @param string $input Value for input textbox * @return string */ private function makeForm( $title, $input ) { $self = $this->getPageTitle(); $request = $this->getRequest(); $user = $this->getUser(); $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) ); $form .= "
\n"; $form .= Html::hidden( 'wpEditToken', $user->getEditToken( '', $request ) ); $form .= Xml::closeElement( 'form' ); return $form; } /** * Generate a nice little box with a heading for output * * @param string $output Wiki text output * @param string $heading * @return string */ private function makeOutput( $output, $heading = 'expand_templates_output' ) { $out = "