34 private const MAX_INCLUDE_SIZE = 50_000_000;
41 parent::__construct(
'ExpandTemplates' );
53 $input =
$request->getText(
'wpInput' );
55 if ( $input !==
'' ) {
56 $removeComments =
$request->getBool(
'wpRemoveComments',
false );
57 $removeNowiki =
$request->getBool(
'wpRemoveNowiki',
false );
58 $generateXML =
$request->getBool(
'wpGenerateXml' );
59 $generateRawHtml =
$request->getBool(
'wpGenerateRawHtml' );
61 $options = ParserOptions::newFromContext( $this->
getContext() );
62 $options->setRemoveComments( $removeComments );
63 $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
64 $options->setSuppressSectionEditLinks();
66 $titleStr =
$request->getText(
'wpContextTitle' );
67 $title = Title::newFromText( $titleStr );
73 $parser = $this->parserFactory->getInstance();
75 $parser->startExternalParse( $title, $options, Parser::OT_PREPROCESS );
76 $dom = $parser->preprocessToDom( $input );
78 if ( method_exists( $dom,
'saveXML' ) ) {
80 $xml = $dom->saveXML();
83 $xml = $dom->__toString();
87 $output = $parser->preprocess( $input, $title, $options );
93 $out->addHTML( $this->makeOutput( $xml,
'expand_templates_xml_output' ) );
96 $tmp = $this->makeOutput( $output );
98 if ( $removeNowiki ) {
100 [
'_<nowiki>_',
'_</nowiki>_',
'_<nowiki */>_' ],
106 $tmp = $this->tidy->tidy( $tmp );
108 $out->addHTML( $tmp );
110 $pout = $parser->parse( $output, $title, $options );
113 ->run( $pout, $options, [] )->getContentHolderText();
114 if ( $generateRawHtml && $rawhtml !==
'' ) {
115 $out->addHTML( $this->makeOutput( $rawhtml,
'expand_templates_html_output' ) );
118 $this->showHtmlPreview( $pout, $options, $out );
132 private function onSubmitInput( array $values ) {
133 $status = Status::newGood();
134 if ( $values[
'Input'] ===
'' ) {
135 $status = Status::newFatal(
'expand_templates_input_missing' );
143 private function makeForm() {
146 'type' =>
'textarea',
147 'label' => $this->
msg(
'expand_templates_input' )->text(),
150 'useeditfont' =>
true,
156 'label' => $this->
msg(
'expand_templates_title' )->plain(),
157 'id' =>
'contexttitle',
160 'RemoveComments' => [
162 'label' => $this->
msg(
'expand_templates_remove_comments' )->text(),
163 'id' =>
'removecomments',
168 'label' => $this->
msg(
'expand_templates_remove_nowiki' )->text(),
169 'id' =>
'removenowiki',
173 'label' => $this->
msg(
'expand_templates_generate_xml' )->text(),
174 'id' =>
'generate_xml',
176 'GenerateRawHtml' => [
178 'label' => $this->
msg(
'expand_templates_generate_rawhtml' )->text(),
179 'id' =>
'generate_rawhtml',
183 $form = HTMLForm::factory(
'ooui', $fields, $this->
getContext() );
185 ->setSubmitTextMsg(
'expand_templates_ok' )
186 ->setWrapperLegendMsg(
'expandtemplates' )
187 ->setHeaderHtml( $this->
msg(
'expand_templates_intro' )->parse() )
188 ->setSubmitCallback( $this->onSubmitInput( ... ) )
199 private function makeOutput( $output, $heading =
'expand_templates_output' ) {
200 $out =
"<h2>" . $this->
msg( $heading )->escaped() .
"</h2>\n";
201 $out .= Html::textarea(
206 'id' => $heading ===
'expand_templates_output' ?
'output' : $heading,
209 'readonly' =>
'readonly',
210 'class' =>
'mw-editfont-' . $this->userOptionsLookup->getOption( $this->
getUser(),
'editfont' )
224 private function showHtmlPreview( ParserOutput $pout, ParserOptions $popts, OutputPage $out ) {
225 $out->addHTML(
"<h2>" . $this->
msg(
'expand_templates_preview' )->escaped() .
"</h2>\n" );
235 if ( $user->isAnon() && !$this->getAuthority()->isAllowed(
'edit' ) ) {
236 $error = [
'expand_templates_preview_fail_html_anon' ];
237 } elseif ( !$user->matchEditToken(
$request->getVal(
'wpEditToken' ),
'',
$request ) ) {
238 $error = [
'expand_templates_preview_fail_html' ];
246 $out->msg( $error )->parse(),
255 $out->addParserOutputContent( $pout, $popts );
256 $out->addCategoryLinks( $pout->getCategoryMap() );
266class_alias( SpecialExpandTemplates::class,
'SpecialExpandTemplates' );
A class containing constants representing the names of configuration variables.
const RawHtml
Name constant for the RawHtml setting, for use with Config::get()
This is one of the Core classes and should be read at least once by any new developers.
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getUser()
Shortcut to get the User executing this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
getConfig()
Shortcut to get main config object.
getContext()
Gets the context this SpecialPage is executed in.
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getContentLanguage()
Shortcut to get content language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.