39 private const MAX_INCLUDE_SIZE = 50000000;
45 private $userOptionsLookup;
60 parent::__construct(
'ExpandTemplates' );
61 $this->parser = $parser;
62 $this->userOptionsLookup = $userOptionsLookup;
75 $input = $request->getText(
'wpInput' );
77 if ( strlen( $input ) ) {
78 $removeComments = $request->getBool(
'wpRemoveComments',
false );
79 $removeNowiki = $request->getBool(
'wpRemoveNowiki',
false );
80 $generateXML = $request->getBool(
'wpGenerateXml' );
81 $generateRawHtml = $request->getBool(
'wpGenerateRawHtml' );
83 $options = ParserOptions::newFromContext( $this->
getContext() );
84 $options->setRemoveComments( $removeComments );
85 $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
87 $titleStr = $request->getText(
'wpContextTitle' );
88 $title = Title::newFromText( $titleStr );
96 $dom = $this->parser->preprocessToDom( $input );
98 if ( method_exists( $dom,
'saveXML' ) ) {
100 $xml = $dom->saveXML();
103 $xml = $dom->__toString();
107 $output = $this->parser->preprocess( $input,
$title, $options );
111 if ( $generateXML && strlen( $output ) > 0 ) {
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 );
130 $pout = $this->parser->parse( $output,
$title, $options );
131 $rawhtml = $pout->
getText( [
'enableSectionEditLinks' =>
false ] );
132 if ( $generateRawHtml && strlen( $rawhtml ) > 0 ) {
134 $out->
addHTML( $this->makeOutput( $rawhtml,
'expand_templates_html_output' ) );
137 $this->showHtmlPreview(
$title, $pout, $out );
152 $status = Status::newGood();
153 if ( !strlen( $values[
'Input'] ) ) {
154 $status = Status::newFatal(
'expand_templates_input_missing' );
162 private function makeForm() {
166 'label' => $this->
msg(
'expand_templates_title' )->plain(),
167 'id' =>
'contexttitle',
172 'type' =>
'textarea',
173 'label' => $this->
msg(
'expand_templates_input' )->text(),
176 'useeditfont' =>
true,
178 'RemoveComments' => [
180 'label' => $this->
msg(
'expand_templates_remove_comments' )->text(),
181 'id' =>
'removecomments',
186 'label' => $this->
msg(
'expand_templates_remove_nowiki' )->text(),
187 'id' =>
'removenowiki',
191 'label' => $this->
msg(
'expand_templates_generate_xml' )->text(),
192 'id' =>
'generate_xml',
194 'GenerateRawHtml' => [
196 'label' => $this->
msg(
'expand_templates_generate_rawhtml' )->text(),
197 'id' =>
'generate_rawhtml',
201 $form = HTMLForm::factory(
'ooui', $fields, $this->
getContext() );
203 ->setSubmitTextMsg(
'expand_templates_ok' )
204 ->setWrapperLegendMsg(
'expandtemplates' )
205 ->setHeaderHtml( $this->
msg(
'expand_templates_intro' )->parse() )
206 ->setSubmitCallback( [ $this,
'onSubmitInput' ] )
217 private function makeOutput( $output, $heading =
'expand_templates_output' ) {
218 $out =
"<h2>" . $this->
msg( $heading )->escaped() .
"</h2>\n";
226 'readonly' =>
'readonly',
227 'class' =>
'mw-editfont-' . $this->userOptionsLookup->getOption( $this->getUser(),
'editfont' )
243 $out->
addHTML(
"<h2>" . $this->
msg(
'expand_templates_preview' )->escaped() .
"</h2>\n" );
245 if ( $this->
getConfig()->
get( MainConfigNames::RawHtml ) ) {
253 if ( $user->isAnon() && !$this->getAuthority()->isAllowed(
'edit' ) ) {
254 $error = [
'expand_templates_preview_fail_html_anon' ];
255 } elseif ( !$user->matchEditToken( $request->getVal(
'wpEditToken' ),
'', $request ) ) {
256 $error = [
'expand_templates_preview_fail_html' ];
264 $out->
msg( $error )->parse(),
273 $out->
addHTML( Html::openElement(
'div', [
274 'class' =>
'mw-content-' .
$lang->getDir(),
275 'dir' =>
$lang->getDir(),
276 'lang' =>
$lang->getHtmlCode(),
279 $out->
addHTML( Html::closeElement(
'div' ) );
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
A class containing constants representing the names of configuration variables.
This is one of the Core classes and should be read at least once by any new developers.
setCategoryLinks(array $categories)
Reset the category links (but not the category list) and add $categories.
addParserOutputContent(ParserOutput $parserOutput, $poOptions=[])
Add the HTML and enhancements for it (like ResourceLoader modules) associated with a ParserOutput obj...
addHTML( $text)
Append $text to the body HTML.
getText( $options=[])
Get the output HTML.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
A special page that expands submitted templates, parser functions, and variables, allowing easier deb...
__construct(Parser $parser, UserOptionsLookup $userOptionsLookup, TidyDriverBase $tidy)
onSubmitInput(array $values)
Callback for the HTMLForm used in self::makeForm.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
execute( $subpage)
Show the special page.
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
getContentLanguage()
Shortcut to get content language.
static textarea( $name, $content, $cols=40, $rows=5, $attribs=[])
Shortcut for creating textareas.
if(!isset( $args[0])) $lang