Go to the documentation of this file.
47 const MAX_INCLUDE_SIZE = 50000000;
50 parent::__construct(
'ExpandTemplates' );
62 $titleStr = $request->getText(
'wpContextTitle' );
68 $input = $request->getText(
'wpInput' );
69 $this->generateXML = $request->getBool(
'wpGenerateXml' );
70 $this->generateRawHtml = $request->getBool(
'wpGenerateRawHtml' );
72 if ( strlen( $input ) ) {
73 $this->removeComments = $request->getBool(
'wpRemoveComments',
false );
74 $this->removeNowiki = $request->getBool(
'wpRemoveNowiki',
false );
76 $options->setRemoveComments( $this->removeComments );
77 $options->setTidy(
true );
78 $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
80 $parser = MediaWikiServices::getInstance()->getParser();
81 if ( $this->generateXML ) {
83 $dom = $parser->preprocessToDom( $input );
85 if ( method_exists( $dom,
'saveXML' ) ) {
87 $xml = $dom->saveXML();
90 $xml = $dom->__toString();
96 $this->removeComments = $request->getBool(
'wpRemoveComments',
true );
97 $this->removeNowiki = $request->getBool(
'wpRemoveNowiki',
false );
103 $this->
makeForm( $titleStr, $input );
106 if ( $this->generateXML && strlen(
$output ) > 0 ) {
107 $out->addHTML( $this->
makeOutput( $xml,
'expand_templates_xml_output' ) );
112 if ( $this->removeNowiki ) {
114 [
'_<nowiki>_',
'_</nowiki>_',
'_<nowiki */>_' ],
127 $out->addHTML( $tmp );
130 $rawhtml = $pout->getText();
131 if ( $this->generateRawHtml && strlen( $rawhtml ) > 0 ) {
132 $out->addHTML( $this->
makeOutput( $rawhtml,
'expand_templates_html_output' ) );
149 if ( !strlen( $values[
'input'] ) ) {
165 'label' => $this->
msg(
'expand_templates_title' )->plain(),
166 'name' =>
'wpContextTitle',
167 'id' =>
'contexttitle',
173 'type' =>
'textarea',
175 'label' => $this->
msg(
'expand_templates_input' )->text(),
179 'useeditfont' =>
true,
181 'removecomments' => [
183 'label' => $this->
msg(
'expand_templates_remove_comments' )->text(),
184 'name' =>
'wpRemoveComments',
185 'id' =>
'removecomments',
190 'label' => $this->
msg(
'expand_templates_remove_nowiki' )->text(),
191 'name' =>
'wpRemoveNowiki',
192 'id' =>
'removenowiki',
197 'label' => $this->
msg(
'expand_templates_generate_xml' )->text(),
198 'name' =>
'wpGenerateXml',
199 'id' =>
'generate_xml',
202 'generate_rawhtml' => [
204 'label' => $this->
msg(
'expand_templates_generate_rawhtml' )->text(),
205 'name' =>
'wpGenerateRawHtml',
206 'id' =>
'generate_rawhtml',
213 ->setSubmitTextMsg(
'expand_templates_ok' )
214 ->setWrapperLegendMsg(
'expandtemplates' )
215 ->setHeaderText( $this->
msg(
'expand_templates_intro' )->parse() )
216 ->setSubmitCallback( [ $this,
'onSubmitInput' ] )
228 $out =
"<h2>" . $this->
msg( $heading )->escaped() .
"</h2>\n";
236 'readonly' =>
'readonly',
237 'class' =>
'mw-editfont-' . $this->
getUser()->getOption(
'editfont' )
253 $popts->setTargetLanguage(
$title->getPageLanguage() );
254 return MediaWikiServices::getInstance()->getParser()->parse( $text,
$title, $popts );
266 $out->addHTML(
"<h2>" . $this->
msg(
'expand_templates_preview' )->escaped() .
"</h2>\n" );
268 if ( $this->
getConfig()->
get(
'RawHtml' ) ) {
276 if ( $user->isAnon() && !MediaWikiServices::getInstance()
277 ->getPermissionManager()
278 ->userHasRight( $user,
'edit' )
280 $error = [
'expand_templates_preview_fail_html_anon' ];
281 } elseif ( !$user->matchEditToken( $request->getVal(
'wpEditToken' ),
'', $request ) ) {
282 $error = [
'expand_templates_preview_fail_html' ];
288 $out->wrapWikiMsg(
"<div class='previewnote errorbox'>\n$1\n</div>", $error );
293 $out->addHTML( Html::openElement(
'div', [
294 'class' =>
'mw-content-' .
$lang->getDir(),
295 'dir' =>
$lang->getDir(),
296 'lang' =>
$lang->getHtmlCode(),
298 $out->addParserOutputContent( $pout );
299 $out->addHTML( Html::closeElement(
'div' ) );
getPageTitle( $subpage=false)
Get a self-referential title object.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
getOutput()
Get the OutputPage being used for this instance.
bool $generateRawHtml
Whether or not to show the raw HTML code.
if(!isset( $args[0])) $lang
showHtmlPreview(Title $title, ParserOutput $pout, OutputPage $out)
Wraps the provided html code in a div and outputs it to the page.
static textarea( $name, $content, $cols=40, $rows=5, $attribs=[])
Shortcut for creating textareas.
execute( $subpage)
Show the special page.
makeOutput( $output, $heading='expand_templates_output')
Generate a nice little box with a heading for output.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
getConfig()
Shortcut to get main config object.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getUser()
Shortcut to get the User executing this instance.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getContext()
Gets the context this SpecialPage is executed in.
A special page that expands submitted templates, parser functions, and variables, allowing easier deb...
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
static newGood( $value=null)
Factory function for good results.
Parent class for all special pages.
bool $removeNowiki
Whether or not to remove <nowiki> tags in the expanded wikitext.
getRequest()
Get the WebRequest being used for this instance.
makeForm( $title, $input)
Generate a form allowing users to enter information.
generateHtml(Title $title, $text)
Renders the supplied wikitext as html.
Represents a title within MediaWiki.
bool $generateXML
Whether or not to show the XML parse tree.
onSubmitInput(array $values)
Callback for the HTMLForm used in self::makeForm.
bool $removeComments
Whether or not to remove comments in the expanded wikitext.
static tidy( $text)
Interface with Remex tidy.