48 private const MAX_INCLUDE_SIZE = 50000000;
69 parent::__construct(
'ExpandTemplates' );
84 $titleStr = $request->getText(
'wpContextTitle' );
85 $title = Title::newFromText( $titleStr );
90 $input = $request->getText(
'wpInput' );
91 $this->generateXML = $request->getBool(
'wpGenerateXml' );
92 $this->generateRawHtml = $request->getBool(
'wpGenerateRawHtml' );
94 if ( strlen( $input ) ) {
95 $this->removeComments = $request->getBool(
'wpRemoveComments',
false );
96 $this->removeNowiki = $request->getBool(
'wpRemoveNowiki',
false );
97 $options = ParserOptions::newFromContext( $this->
getContext() );
98 $options->setRemoveComments( $this->removeComments );
99 $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
101 if ( $this->generateXML ) {
103 $dom = $this->parser->preprocessToDom( $input );
105 if ( method_exists( $dom,
'saveXML' ) ) {
107 $xml = $dom->saveXML();
110 $xml = $dom->__toString();
114 $output = $this->parser->preprocess( $input,
$title, $options );
116 $this->removeComments = $request->getBool(
'wpRemoveComments',
true );
117 $this->removeNowiki = $request->getBool(
'wpRemoveNowiki',
false );
123 $this->
makeForm( $titleStr, $input );
125 if ( $output !==
false ) {
126 if ( $this->generateXML && strlen( $output ) > 0 ) {
127 $out->addHTML( $this->
makeOutput( $xml,
'expand_templates_xml_output' ) );
132 if ( $this->removeNowiki ) {
134 [
'_<nowiki>_',
'_</nowiki>_',
'_<nowiki */>_' ],
142 $tmp = $this->tidy->tidy( $tmp );
144 $out->addHTML( $tmp );
147 $rawhtml = $pout->getText();
148 if ( $this->generateRawHtml && strlen( $rawhtml ) > 0 ) {
150 $out->addHTML( $this->
makeOutput( $rawhtml,
'expand_templates_html_output' ) );
166 $status = Status::newGood();
167 if ( !strlen( $values[
'input'] ) ) {
168 $status = Status::newFatal(
'expand_templates_input_missing' );
183 'label' => $this->
msg(
'expand_templates_title' )->plain(),
184 'name' =>
'wpContextTitle',
185 'id' =>
'contexttitle',
191 'type' =>
'textarea',
193 'label' => $this->
msg(
'expand_templates_input' )->text(),
197 'useeditfont' =>
true,
199 'removecomments' => [
201 'label' => $this->
msg(
'expand_templates_remove_comments' )->text(),
202 'name' =>
'wpRemoveComments',
203 'id' =>
'removecomments',
208 'label' => $this->
msg(
'expand_templates_remove_nowiki' )->text(),
209 'name' =>
'wpRemoveNowiki',
210 'id' =>
'removenowiki',
215 'label' => $this->
msg(
'expand_templates_generate_xml' )->text(),
216 'name' =>
'wpGenerateXml',
217 'id' =>
'generate_xml',
220 'generate_rawhtml' => [
222 'label' => $this->
msg(
'expand_templates_generate_rawhtml' )->text(),
223 'name' =>
'wpGenerateRawHtml',
224 'id' =>
'generate_rawhtml',
229 $form = HTMLForm::factory(
'ooui', $fields, $this->
getContext() );
231 ->setSubmitTextMsg(
'expand_templates_ok' )
232 ->setWrapperLegendMsg(
'expandtemplates' )
233 ->setHeaderText( $this->
msg(
'expand_templates_intro' )->parse() )
234 ->setSubmitCallback( [ $this,
'onSubmitInput' ] )
245 private function makeOutput( $output, $heading =
'expand_templates_output' ) {
246 $out =
"<h2>" . $this->
msg( $heading )->escaped() .
"</h2>\n";
247 $out .= Xml::textarea(
254 'readonly' =>
'readonly',
255 'class' =>
'mw-editfont-' . $this->userOptionsLookup->getOption( $this->getUser(),
'editfont' )
270 $popts = ParserOptions::newFromContext( $this->
getContext() );
271 $popts->setTargetLanguage(
$title->getPageLanguage() );
272 return $this->parser->parse( $text,
$title, $popts );
284 $out->
addHTML(
"<h2>" . $this->
msg(
'expand_templates_preview' )->escaped() .
"</h2>\n" );
286 if ( $this->
getConfig()->
get(
'RawHtml' ) ) {
294 if ( $user->isAnon() && !$this->getAuthority()->isAllowed(
'edit' ) ) {
295 $error = [
'expand_templates_preview_fail_html_anon' ];
296 } elseif ( !$user->matchEditToken( $request->getVal(
'wpEditToken' ),
'', $request ) ) {
297 $error = [
'expand_templates_preview_fail_html' ];
303 $out->
wrapWikiMsg(
"<div class='previewnote errorbox'>\n$1\n</div>", $error );
308 $out->
addHTML( Html::openElement(
'div', [
309 'class' =>
'mw-content-' .
$lang->getDir(),
310 'dir' =>
$lang->getDir(),
311 'lang' =>
$lang->getHtmlCode(),
314 $out->
addHTML( Html::closeElement(
'div' ) );
This is one of the Core classes and should be read at least once by any new developers.
setCategoryLinks(array $categories)
Reset the category links (but not the category list) and add $categories.
wrapWikiMsg( $wrap,... $msgSpecs)
This function takes a number of message/argument specifications, wraps them in some overall structure...
addParserOutputContent(ParserOutput $parserOutput, $poOptions=[])
Add the HTML and enhancements for it (like ResourceLoader modules) associated with a ParserOutput obj...
addHTML( $text)
Append $text to the body HTML.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
A special page that expands submitted templates, parser functions, and variables, allowing easier deb...
bool $generateRawHtml
Whether or not to show the raw HTML code.
__construct(Parser $parser, UserOptionsLookup $userOptionsLookup, TidyDriverBase $tidy)
bool $removeComments
Whether or not to remove comments in the expanded wikitext.
UserOptionsLookup $userOptionsLookup
onSubmitInput(array $values)
Callback for the HTMLForm used in self::makeForm.
bool $generateXML
Whether or not to show the XML parse tree.
makeForm( $title, $input)
Generate a form allowing users to enter information.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
showHtmlPreview(Title $title, ParserOutput $pout, OutputPage $out)
Wraps the provided html code in a div and outputs it to the page.
generateHtml(Title $title, $text)
Renders the supplied wikitext as html.
makeOutput( $output, $heading='expand_templates_output')
Generate a nice little box with a heading for output.
execute( $subpage)
Show the special page.
bool $removeNowiki
Whether or not to remove <nowiki> tags in the expanded wikitext.
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Represents a title within MediaWiki.
if(!isset( $args[0])) $lang