* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
/**
* A special page that expands submitted templates, parser functions,
* and variables, allowing easier debugging of these.
* @param string|null $subpage
*/
function execute( $subpage ) {
- global $wgParser;
-
$this->setHeaders();
$this->addHelpLink( 'Help:ExpandTemplates' );
$options->setTidy( true );
$options->setMaxIncludeSize( self::MAX_INCLUDE_SIZE );
+ $parser = MediaWikiServices::getInstance()->getParser();
if ( $this->generateXML ) {
- $wgParser->startExternalParse( $title, $options, Parser::OT_PREPROCESS );
- $dom = $wgParser->preprocessToDom( $input );
+ $parser->startExternalParse( $title, $options, Parser::OT_PREPROCESS );
+ $dom = $parser->preprocessToDom( $input );
if ( method_exists( $dom, 'saveXML' ) ) {
+ // @phan-suppress-next-line PhanUndeclaredMethod
$xml = $dom->saveXML();
} else {
+ // @phan-suppress-next-line PhanUndeclaredMethod
$xml = $dom->__toString();
}
}
- $output = $wgParser->preprocess( $input, $title, $options );
+ $output = $parser->preprocess( $input, $title, $options );
} else {
$this->removeComments = $request->getBool( 'wpRemoveComments', true );
$this->removeNowiki = $request->getBool( 'wpRemoveNowiki', false );
* @return ParserOutput
*/
private function generateHtml( Title $title, $text ) {
- global $wgParser;
-
$popts = ParserOptions::newFromContext( $this->getContext() );
$popts->setTargetLanguage( $title->getPageLanguage() );
- return $wgParser->parse( $text, $title, $popts );
+ return MediaWikiServices::getInstance()->getParser()->parse( $text, $title, $popts );
}
/**
// allowed and a valid edit token is not provided (T73111). However, MediaWiki
// does not currently provide logged-out users with CSRF protection; in that case,
// do not show the preview unless anonymous editing is allowed.
- if ( $user->isAnon() && !$user->isAllowed( 'edit' ) ) {
+ if ( $user->isAnon() && !MediaWikiServices::getInstance()
+ ->getPermissionManager()
+ ->userHasRight( $user, 'edit' )
+ ) {
$error = [ 'expand_templates_preview_fail_html_anon' ];
} elseif ( !$user->matchEditToken( $request->getVal( 'wpEditToken' ), '', $request ) ) {
$error = [ 'expand_templates_preview_fail_html' ];
}
if ( $error ) {
- $out->wrapWikiMsg( "<div class='previewnote'>\n$1\n</div>", $error );
+ $out->wrapWikiMsg( "<div class='previewnote errorbox'>\n$1\n</div>", $error );
return;
}
}