48 private const MAX_INCLUDE_SIZE = 50_000_000;
64 parent::__construct(
'ExpandTemplates' );
65 $this->parserFactory = $parserFactory;
66 $this->userOptionsLookup = $userOptionsLookup;
79 $input = $request->getText(
'wpInput' );
81 if ( strlen( $input ) ) {
82 $removeComments = $request->getBool(
'wpRemoveComments',
false );
83 $removeNowiki = $request->getBool(
'wpRemoveNowiki',
false );
84 $generateXML = $request->getBool(
'wpGenerateXml' );
85 $generateRawHtml = $request->getBool(
'wpGenerateRawHtml' );
87 $options = ParserOptions::newFromContext( $this->
getContext() );
88 $options->setRemoveComments( $removeComments );
89 $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
91 $titleStr = $request->getText(
'wpContextTitle' );
92 $title = Title::newFromText( $titleStr );
98 $parser = $this->parserFactory->getInstance();
100 $parser->startExternalParse( $title, $options, Parser::OT_PREPROCESS );
101 $dom = $parser->preprocessToDom( $input );
103 if ( method_exists( $dom,
'saveXML' ) ) {
105 $xml = $dom->saveXML();
108 $xml = $dom->__toString();
112 $output = $parser->preprocess( $input, $title, $options );
116 if ( $generateXML && strlen( $output ) > 0 ) {
118 $out->addHTML( $this->makeOutput( $xml,
'expand_templates_xml_output' ) );
121 $tmp = $this->makeOutput( $output );
123 if ( $removeNowiki ) {
125 [
'_<nowiki>_',
'_</nowiki>_',
'_<nowiki */>_' ],
131 $tmp = $this->tidy->tidy( $tmp );
133 $out->addHTML( $tmp );
135 $pout = $parser->parse( $output, $title, $options );
136 $rawhtml = $pout->getText( [
'enableSectionEditLinks' =>
false ] );
137 if ( $generateRawHtml && strlen( $rawhtml ) > 0 ) {
139 $out->addHTML( $this->makeOutput( $rawhtml,
'expand_templates_html_output' ) );
142 $this->showHtmlPreview( $title, $pout, $out );
157 $status = Status::newGood();
158 if ( !strlen( $values[
'Input'] ) ) {
159 $status = Status::newFatal(
'expand_templates_input_missing' );
167 private function makeForm() {
171 'label' => $this->
msg(
'expand_templates_title' )->plain(),
172 'id' =>
'contexttitle',
177 'type' =>
'textarea',
178 'label' => $this->
msg(
'expand_templates_input' )->text(),
181 'useeditfont' =>
true,
183 'RemoveComments' => [
185 'label' => $this->
msg(
'expand_templates_remove_comments' )->text(),
186 'id' =>
'removecomments',
191 'label' => $this->
msg(
'expand_templates_remove_nowiki' )->text(),
192 'id' =>
'removenowiki',
196 'label' => $this->
msg(
'expand_templates_generate_xml' )->text(),
197 'id' =>
'generate_xml',
199 'GenerateRawHtml' => [
201 'label' => $this->
msg(
'expand_templates_generate_rawhtml' )->text(),
202 'id' =>
'generate_rawhtml',
206 $form = HTMLForm::factory(
'ooui', $fields, $this->
getContext() );
208 ->setSubmitTextMsg(
'expand_templates_ok' )
209 ->setWrapperLegendMsg(
'expandtemplates' )
210 ->setHeaderHtml( $this->
msg(
'expand_templates_intro' )->parse() )
211 ->setSubmitCallback( [ $this,
'onSubmitInput' ] )
222 private function makeOutput( $output, $heading =
'expand_templates_output' ) {
223 $out =
"<h2>" . $this->
msg( $heading )->escaped() .
"</h2>\n";
231 'readonly' =>
'readonly',
232 'class' =>
'mw-editfont-' . $this->userOptionsLookup->getOption( $this->getUser(),
'editfont' )
246 private function showHtmlPreview( Title $title, ParserOutput $pout, OutputPage $out ) {
247 $out->addHTML(
"<h2>" . $this->
msg(
'expand_templates_preview' )->escaped() .
"</h2>\n" );
257 if ( $user->isAnon() && !$this->getAuthority()->isAllowed(
'edit' ) ) {
258 $error = [
'expand_templates_preview_fail_html_anon' ];
259 } elseif ( !$user->matchEditToken( $request->getVal(
'wpEditToken' ),
'', $request ) ) {
260 $error = [
'expand_templates_preview_fail_html' ];
268 $out->msg( $error )->parse(),
277 $out->addParserOutputContent( $pout, [
'enableSectionEditLinks' =>
false ] );
278 $out->setCategoryLinks( $pout->getCategoryMap() );
287class_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.