49 private const MAX_INCLUDE_SIZE = 50_000_000;
65 parent::__construct(
'ExpandTemplates' );
66 $this->parserFactory = $parserFactory;
67 $this->userOptionsLookup = $userOptionsLookup;
80 $input = $request->getText(
'wpInput' );
82 if ( strlen( $input ) ) {
83 $removeComments = $request->getBool(
'wpRemoveComments',
false );
84 $removeNowiki = $request->getBool(
'wpRemoveNowiki',
false );
85 $generateXML = $request->getBool(
'wpGenerateXml' );
86 $generateRawHtml = $request->getBool(
'wpGenerateRawHtml' );
88 $options = ParserOptions::newFromContext( $this->
getContext() );
89 $options->setRemoveComments( $removeComments );
90 $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
92 $titleStr = $request->getText(
'wpContextTitle' );
93 $title = Title::newFromText( $titleStr );
99 $parser = $this->parserFactory->getInstance();
100 if ( $generateXML ) {
101 $parser->startExternalParse( $title, $options, Parser::OT_PREPROCESS );
102 $dom = $parser->preprocessToDom( $input );
104 if ( method_exists( $dom,
'saveXML' ) ) {
106 $xml = $dom->saveXML();
109 $xml = $dom->__toString();
113 $output = $parser->preprocess( $input, $title, $options );
117 if ( $generateXML ) {
119 $out->addHTML( $this->makeOutput( $xml,
'expand_templates_xml_output' ) );
122 $tmp = $this->makeOutput( $output );
124 if ( $removeNowiki ) {
126 [
'_<nowiki>_',
'_</nowiki>_',
'_<nowiki */>_' ],
132 $tmp = $this->tidy->tidy( $tmp );
134 $out->addHTML( $tmp );
136 $pout = $parser->parse( $output, $title, $options );
139 ->run( $pout, $options, [
'enableSectionEditLinks' =>
false ] )->getContentHolderText();
140 if ( $generateRawHtml && strlen( $rawhtml ) > 0 ) {
142 $out->addHTML( $this->makeOutput( $rawhtml,
'expand_templates_html_output' ) );
145 $this->showHtmlPreview( $title, $pout, $out );
160 $status = Status::newGood();
161 if ( !strlen( $values[
'Input'] ) ) {
162 $status = Status::newFatal(
'expand_templates_input_missing' );
170 private function makeForm() {
173 'type' =>
'textarea',
174 'label' => $this->
msg(
'expand_templates_input' )->text(),
177 'useeditfont' =>
true,
183 'label' => $this->
msg(
'expand_templates_title' )->plain(),
184 'id' =>
'contexttitle',
187 'RemoveComments' => [
189 'label' => $this->
msg(
'expand_templates_remove_comments' )->text(),
190 'id' =>
'removecomments',
195 'label' => $this->
msg(
'expand_templates_remove_nowiki' )->text(),
196 'id' =>
'removenowiki',
200 'label' => $this->
msg(
'expand_templates_generate_xml' )->text(),
201 'id' =>
'generate_xml',
203 'GenerateRawHtml' => [
205 'label' => $this->
msg(
'expand_templates_generate_rawhtml' )->text(),
206 'id' =>
'generate_rawhtml',
210 $form = HTMLForm::factory(
'ooui', $fields, $this->
getContext() );
212 ->setSubmitTextMsg(
'expand_templates_ok' )
213 ->setWrapperLegendMsg(
'expandtemplates' )
214 ->setHeaderHtml( $this->
msg(
'expand_templates_intro' )->parse() )
215 ->setSubmitCallback( [ $this,
'onSubmitInput' ] )
226 private function makeOutput( $output, $heading =
'expand_templates_output' ) {
227 $out =
"<h2>" . $this->
msg( $heading )->escaped() .
"</h2>\n";
235 'readonly' =>
'readonly',
236 'class' =>
'mw-editfont-' . $this->userOptionsLookup->getOption( $this->getUser(),
'editfont' )
250 private function showHtmlPreview( Title $title, ParserOutput $pout, OutputPage $out ) {
251 $out->addHTML(
"<h2>" . $this->
msg(
'expand_templates_preview' )->escaped() .
"</h2>\n" );
261 if ( $user->isAnon() && !$this->getAuthority()->isAllowed(
'edit' ) ) {
262 $error = [
'expand_templates_preview_fail_html_anon' ];
263 } elseif ( !$user->matchEditToken( $request->getVal(
'wpEditToken' ),
'', $request ) ) {
264 $error = [
'expand_templates_preview_fail_html' ];
272 $out->msg( $error )->parse(),
281 $out->addParserOutputContent( $pout, [
'enableSectionEditLinks' =>
false ] );
282 $out->addCategoryLinks( $pout->getCategoryMap() );
291class_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.