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 && strlen( $output ) > 0 ) {
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 ) {
141 $out->addHTML( $this->makeOutput( $rawhtml,
'expand_templates_html_output' ) );
144 $this->showHtmlPreview( $title, $pout, $out );
159 $status = Status::newGood();
160 if ( !strlen( $values[
'Input'] ) ) {
161 $status = Status::newFatal(
'expand_templates_input_missing' );
169 private function makeForm() {
172 'type' =>
'textarea',
173 'label' => $this->
msg(
'expand_templates_input' )->text(),
176 'useeditfont' =>
true,
182 'label' => $this->
msg(
'expand_templates_title' )->plain(),
183 'id' =>
'contexttitle',
186 'RemoveComments' => [
188 'label' => $this->
msg(
'expand_templates_remove_comments' )->text(),
189 'id' =>
'removecomments',
194 'label' => $this->
msg(
'expand_templates_remove_nowiki' )->text(),
195 'id' =>
'removenowiki',
199 'label' => $this->
msg(
'expand_templates_generate_xml' )->text(),
200 'id' =>
'generate_xml',
202 'GenerateRawHtml' => [
204 'label' => $this->
msg(
'expand_templates_generate_rawhtml' )->text(),
205 'id' =>
'generate_rawhtml',
209 $form = HTMLForm::factory(
'ooui', $fields, $this->
getContext() );
211 ->setSubmitTextMsg(
'expand_templates_ok' )
212 ->setWrapperLegendMsg(
'expandtemplates' )
213 ->setHeaderHtml( $this->
msg(
'expand_templates_intro' )->parse() )
214 ->setSubmitCallback( [ $this,
'onSubmitInput' ] )
225 private function makeOutput( $output, $heading =
'expand_templates_output' ) {
226 $out =
"<h2>" . $this->
msg( $heading )->escaped() .
"</h2>\n";
234 'readonly' =>
'readonly',
235 'class' =>
'mw-editfont-' . $this->userOptionsLookup->getOption( $this->getUser(),
'editfont' )
249 private function showHtmlPreview( Title $title, ParserOutput $pout, OutputPage $out ) {
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(),
280 $out->addParserOutputContent( $pout, [
'enableSectionEditLinks' =>
false ] );
281 $out->addCategoryLinks( $pout->getCategoryMap() );
290class_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.