37 private const MAX_INCLUDE_SIZE = 50000000;
43 private $userOptionsLookup;
58 parent::__construct(
'ExpandTemplates' );
59 $this->parser = $parser;
60 $this->userOptionsLookup = $userOptionsLookup;
73 $input = $request->getText(
'wpInput' );
75 if ( strlen( $input ) ) {
76 $removeComments = $request->getBool(
'wpRemoveComments',
false );
77 $removeNowiki = $request->getBool(
'wpRemoveNowiki',
false );
78 $generateXML = $request->getBool(
'wpGenerateXml' );
79 $generateRawHtml = $request->getBool(
'wpGenerateRawHtml' );
81 $options = ParserOptions::newFromContext( $this->
getContext() );
82 $options->setRemoveComments( $removeComments );
83 $options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
85 $titleStr = $request->getText(
'wpContextTitle' );
86 $title = Title::newFromText( $titleStr );
94 $dom = $this->parser->preprocessToDom( $input );
96 if ( method_exists( $dom,
'saveXML' ) ) {
98 $xml = $dom->saveXML();
101 $xml = $dom->__toString();
105 $output = $this->parser->preprocess( $input,
$title, $options );
109 if ( $generateXML && strlen( $output ) > 0 ) {
111 $out->
addHTML( $this->makeOutput( $xml,
'expand_templates_xml_output' ) );
114 $tmp = $this->makeOutput( $output );
116 if ( $removeNowiki ) {
118 [
'_<nowiki>_',
'_</nowiki>_',
'_<nowiki */>_' ],
124 $tmp = $this->tidy->tidy( $tmp );
128 $pout = $this->generateHtml(
$title, $output );
130 if ( $generateRawHtml && strlen( $rawhtml ) > 0 ) {
132 $out->
addHTML( $this->makeOutput( $rawhtml,
'expand_templates_html_output' ) );
135 $this->showHtmlPreview(
$title, $pout, $out );
150 $status = Status::newGood();
151 if ( !strlen( $values[
'Input'] ) ) {
152 $status = Status::newFatal(
'expand_templates_input_missing' );
160 private function makeForm() {
164 'label' => $this->
msg(
'expand_templates_title' )->plain(),
165 'id' =>
'contexttitle',
170 'type' =>
'textarea',
171 'label' => $this->
msg(
'expand_templates_input' )->text(),
174 'useeditfont' =>
true,
176 'RemoveComments' => [
178 'label' => $this->
msg(
'expand_templates_remove_comments' )->text(),
179 'id' =>
'removecomments',
184 'label' => $this->
msg(
'expand_templates_remove_nowiki' )->text(),
185 'id' =>
'removenowiki',
189 'label' => $this->
msg(
'expand_templates_generate_xml' )->text(),
190 'id' =>
'generate_xml',
192 'GenerateRawHtml' => [
194 'label' => $this->
msg(
'expand_templates_generate_rawhtml' )->text(),
195 'id' =>
'generate_rawhtml',
199 $form = HTMLForm::factory(
'ooui', $fields, $this->
getContext() );
201 ->setSubmitTextMsg(
'expand_templates_ok' )
202 ->setWrapperLegendMsg(
'expandtemplates' )
203 ->setHeaderText( $this->
msg(
'expand_templates_intro' )->parse() )
204 ->setSubmitCallback( [ $this,
'onSubmitInput' ] )
215 private function makeOutput( $output, $heading =
'expand_templates_output' ) {
216 $out =
"<h2>" . $this->
msg( $heading )->escaped() .
"</h2>\n";
224 'readonly' =>
'readonly',
225 'class' =>
'mw-editfont-' . $this->userOptionsLookup->getOption( $this->getUser(),
'editfont' )
239 private function generateHtml(
Title $title, $text ) {
241 $popts->setTargetLanguage(
$title->getPageLanguage() );
242 return $this->parser->parse( $text,
$title, $popts );
254 $out->
addHTML(
"<h2>" . $this->
msg(
'expand_templates_preview' )->escaped() .
"</h2>\n" );
256 if ( $this->
getConfig()->
get( MainConfigNames::RawHtml ) ) {
264 if ( $user->isAnon() && !$this->getAuthority()->isAllowed(
'edit' ) ) {
265 $error = [
'expand_templates_preview_fail_html_anon' ];
266 } elseif ( !$user->matchEditToken( $request->getVal(
'wpEditToken' ),
'', $request ) ) {
267 $error = [
'expand_templates_preview_fail_html' ];
275 $out->
msg( $error )->parse(),
284 $out->
addHTML( Html::openElement(
'div', [
285 'class' =>
'mw-content-' .
$lang->getDir(),
286 'dir' =>
$lang->getDir(),
287 'lang' =>
$lang->getHtmlCode(),
290 $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.
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...
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.
Represents a title within MediaWiki.
static textarea( $name, $content, $cols=40, $rows=5, $attribs=[])
Shortcut for creating textareas.
if(!isset( $args[0])) $lang