48 private const MAX_INCLUDE_SIZE = 50_000_000;
59 parent::__construct(
'ExpandTemplates' );
60 $this->parserFactory = $parserFactory;
61 $this->userOptionsLookup = $userOptionsLookup;
74 $input = $request->getText(
'wpInput' );
76 if ( $input !==
'' ) {
77 $removeComments = $request->getBool(
'wpRemoveComments',
false );
78 $removeNowiki = $request->getBool(
'wpRemoveNowiki',
false );
79 $generateXML = $request->getBool(
'wpGenerateXml' );
80 $generateRawHtml = $request->getBool(
'wpGenerateRawHtml' );
82 $options = ParserOptions::newFromContext( $this->
getContext() );
83 $options->setRemoveComments( $removeComments );
84 $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
86 $titleStr = $request->getText(
'wpContextTitle' );
87 $title = Title::newFromText( $titleStr );
93 $parser = $this->parserFactory->getInstance();
95 $parser->startExternalParse( $title, $options, Parser::OT_PREPROCESS );
96 $dom = $parser->preprocessToDom( $input );
98 if ( method_exists( $dom,
'saveXML' ) ) {
100 $xml = $dom->saveXML();
103 $xml = $dom->__toString();
107 $output = $parser->preprocess( $input, $title, $options );
111 if ( $generateXML ) {
113 $out->addHTML( $this->makeOutput( $xml,
'expand_templates_xml_output' ) );
116 $tmp = $this->makeOutput( $output );
118 if ( $removeNowiki ) {
120 [
'_<nowiki>_',
'_</nowiki>_',
'_<nowiki */>_' ],
126 $tmp = $this->tidy->tidy( $tmp );
128 $out->addHTML( $tmp );
130 $pout = $parser->parse( $output, $title, $options );
133 ->run( $pout, $options, [
'enableSectionEditLinks' =>
false ] )->getContentHolderText();
134 if ( $generateRawHtml && $rawhtml !==
'' ) {
135 $out->addHTML( $this->makeOutput( $rawhtml,
'expand_templates_html_output' ) );
138 $this->showHtmlPreview( $title, $pout, $options, $out );
153 $status = Status::newGood();
154 if ( $values[
'Input'] ===
'' ) {
155 $status = Status::newFatal(
'expand_templates_input_missing' );
163 private function makeForm() {
166 'type' =>
'textarea',
167 'label' => $this->
msg(
'expand_templates_input' )->text(),
170 'useeditfont' =>
true,
176 'label' => $this->
msg(
'expand_templates_title' )->plain(),
177 'id' =>
'contexttitle',
180 'RemoveComments' => [
182 'label' => $this->
msg(
'expand_templates_remove_comments' )->text(),
183 'id' =>
'removecomments',
188 'label' => $this->
msg(
'expand_templates_remove_nowiki' )->text(),
189 'id' =>
'removenowiki',
193 'label' => $this->
msg(
'expand_templates_generate_xml' )->text(),
194 'id' =>
'generate_xml',
196 'GenerateRawHtml' => [
198 'label' => $this->
msg(
'expand_templates_generate_rawhtml' )->text(),
199 'id' =>
'generate_rawhtml',
203 $form = HTMLForm::factory(
'ooui', $fields, $this->
getContext() );
205 ->setSubmitTextMsg(
'expand_templates_ok' )
206 ->setWrapperLegendMsg(
'expandtemplates' )
207 ->setHeaderHtml( $this->
msg(
'expand_templates_intro' )->parse() )
208 ->setSubmitCallback( [ $this,
'onSubmitInput' ] )
219 private function makeOutput( $output, $heading =
'expand_templates_output' ) {
220 $out =
"<h2>" . $this->
msg( $heading )->escaped() .
"</h2>\n";
221 $out .= Html::textarea(
228 'readonly' =>
'readonly',
229 'class' =>
'mw-editfont-' . $this->userOptionsLookup->getOption( $this->getUser(),
'editfont' )
244 private function showHtmlPreview( Title $title, ParserOutput $pout, ParserOptions $popts, OutputPage $out ) {
245 $out->addHTML(
"<h2>" . $this->
msg(
'expand_templates_preview' )->escaped() .
"</h2>\n" );
255 if ( $user->isAnon() && !$this->getAuthority()->isAllowed(
'edit' ) ) {
256 $error = [
'expand_templates_preview_fail_html_anon' ];
257 } elseif ( !$user->matchEditToken( $request->getVal(
'wpEditToken' ),
'', $request ) ) {
258 $error = [
'expand_templates_preview_fail_html' ];
266 $out->msg( $error )->parse(),
275 $out->addParserOutputContent( $pout, $popts, [
'enableSectionEditLinks' =>
false ] );
276 $out->addCategoryLinks( $pout->getCategoryMap() );
285class_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.