24 namespace MediaWiki\Specials;
50 private const MAX_INCLUDE_SIZE = 50000000;
66 parent::__construct(
'ExpandTemplates' );
67 $this->parserFactory = $parserFactory;
68 $this->userOptionsLookup = $userOptionsLookup;
81 $input = $request->getText(
'wpInput' );
83 if ( strlen( $input ) ) {
84 $removeComments = $request->getBool(
'wpRemoveComments',
false );
85 $removeNowiki = $request->getBool(
'wpRemoveNowiki',
false );
86 $generateXML = $request->getBool(
'wpGenerateXml' );
87 $generateRawHtml = $request->getBool(
'wpGenerateRawHtml' );
90 $options->setRemoveComments( $removeComments );
91 $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
93 $titleStr = $request->getText(
'wpContextTitle' );
100 $parser = $this->parserFactory->getInstance();
101 if ( $generateXML ) {
103 $dom = $parser->preprocessToDom( $input );
105 if ( method_exists( $dom,
'saveXML' ) ) {
107 $xml = $dom->saveXML();
110 $xml = $dom->__toString();
114 $output = $parser->preprocess( $input, $title, $options );
118 if ( $generateXML && strlen( $output ) > 0 ) {
120 $out->addHTML( $this->makeOutput( $xml,
'expand_templates_xml_output' ) );
123 $tmp = $this->makeOutput( $output );
125 if ( $removeNowiki ) {
127 [
'_<nowiki>_',
'_</nowiki>_',
'_<nowiki */>_' ],
133 $tmp = $this->tidy->tidy( $tmp );
135 $out->addHTML( $tmp );
137 $pout = $parser->parse( $output, $title, $options );
138 $rawhtml = $pout->
getText( [
'enableSectionEditLinks' =>
false ] );
139 if ( $generateRawHtml && strlen( $rawhtml ) > 0 ) {
141 $out->addHTML( $this->makeOutput( $rawhtml,
'expand_templates_html_output' ) );
144 $this->showHtmlPreview( $title, $pout, $out );
160 if ( !strlen( $values[
'Input'] ) ) {
169 private function makeForm() {
173 'label' => $this->
msg(
'expand_templates_title' )->plain(),
174 'id' =>
'contexttitle',
179 'type' =>
'textarea',
180 'label' => $this->
msg(
'expand_templates_input' )->text(),
183 'useeditfont' =>
true,
185 'RemoveComments' => [
187 'label' => $this->
msg(
'expand_templates_remove_comments' )->text(),
188 'id' =>
'removecomments',
193 'label' => $this->
msg(
'expand_templates_remove_nowiki' )->text(),
194 'id' =>
'removenowiki',
198 'label' => $this->
msg(
'expand_templates_generate_xml' )->text(),
199 'id' =>
'generate_xml',
201 'GenerateRawHtml' => [
203 'label' => $this->
msg(
'expand_templates_generate_rawhtml' )->text(),
204 'id' =>
'generate_rawhtml',
210 ->setSubmitTextMsg(
'expand_templates_ok' )
211 ->setWrapperLegendMsg(
'expandtemplates' )
212 ->setHeaderHtml( $this->
msg(
'expand_templates_intro' )->parse() )
213 ->setSubmitCallback( [ $this,
'onSubmitInput' ] )
224 private function makeOutput( $output, $heading =
'expand_templates_output' ) {
225 $out =
"<h2>" . $this->
msg( $heading )->escaped() .
"</h2>\n";
233 'readonly' =>
'readonly',
234 'class' =>
'mw-editfont-' . $this->userOptionsLookup->getOption( $this->getUser(),
'editfont' )
248 private function showHtmlPreview( Title $title,
ParserOutput $pout, OutputPage $out ) {
249 $lang = $title->getPageViewLanguage();
250 $out->addHTML(
"<h2>" . $this->
msg(
'expand_templates_preview' )->escaped() .
"</h2>\n" );
260 if ( $user->isAnon() && !$this->getAuthority()->isAllowed(
'edit' ) ) {
261 $error = [
'expand_templates_preview_fail_html_anon' ];
262 } elseif ( !$user->matchEditToken( $request->getVal(
'wpEditToken' ),
'', $request ) ) {
263 $error = [
'expand_templates_preview_fail_html' ];
271 $out->msg( $error )->parse(),
281 'class' =>
'mw-content-' . $lang->getDir(),
282 'dir' => $lang->getDir(),
283 'lang' => $lang->getHtmlCode(),
285 $out->addParserOutputContent( $pout, [
'enableSectionEditLinks' =>
false ] );
298 class_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.
Set options of the Parser.
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
getText( $options=[])
Get the output HTML.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
const OT_PREPROCESS
Output type: like Parser::preprocess()
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static newGood( $value=null)
Factory function for good results.
Module of static functions for generating XML.
static textarea( $name, $content, $cols=40, $rows=5, $attribs=[])
Shortcut for creating textareas.