<exclude name="MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName" />
<exclude name="MediaWiki.Usage.DbrQueryUsage.DbrQueryFound" />
<exclude name="MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgContLang" />
- <exclude name="MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgParser" />
<exclude name="MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgTitle" />
<exclude name="MediaWiki.Usage.ForbiddenFunctions.passthru" />
<exclude name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment" />
*
* The entire associative array will be passed through to the constructor as
* the first parameter. Note that only Setup.php can use this variable --
- * the configuration will change at runtime via $wgParser member functions, so
+ * the configuration will change at runtime via Parser member functions, so
* the contents of this variable will be out-of-date. The variable can only be
* changed during LocalSettings.php, in particular, it can't be changed during
* an extension setup function.
* @return string
*/
private function newSectionSummary( &$sectionanchor = null ) {
- global $wgParser;
-
if ( $this->sectiontitle !== '' ) {
$sectionanchor = $this->guessSectionName( $this->sectiontitle );
// If no edit summary was specified, create one automatically from the section
// title and have it link to the new section. Otherwise, respect the summary as
// passed.
if ( $this->summary === '' ) {
- $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
+ $cleanSectionTitle = MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( $this->sectiontitle );
return $this->context->msg( 'newsectionsummary' )
->plaintextParams( $cleanSectionTitle )->inContentLanguage()->text();
}
$sectionanchor = $this->guessSectionName( $this->summary );
# This is a new section, so create a link to the new section
# in the revision summary.
- $cleanSummary = $wgParser->stripSectionName( $this->summary );
+ $cleanSummary = MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( $this->summary );
return $this->context->msg( 'newsectionsummary' )
->plaintextParams( $cleanSummary )->inContentLanguage()->text();
}
public static function extractSectionTitle( $text ) {
preg_match( "/^(=+)(.+)\\1\\s*(\n|$)/i", $text, $matches );
if ( !empty( $matches[2] ) ) {
- global $wgParser;
- return $wgParser->stripSectionName( trim( $matches[2] ) );
+ return MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( trim( $matches[2] ) );
} else {
return false;
}
return "";
}
- global $wgParser;
-
if ( $isSubjectPreview ) {
$summary = $this->context->msg( 'newsectionsummary' )
- ->rawParams( $wgParser->stripSectionName( $summary ) )
+ ->rawParams( MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( $summary ) )
->inContentLanguage()->text();
}
* @return string
*/
private function guessSectionName( $text ) {
- global $wgParser;
-
// Detect Microsoft browsers
$userAgent = $this->context->getRequest()->getHeader( 'User-Agent' );
+ $parser = MediaWikiServices::getInstance()->getParser();
if ( $userAgent && preg_match( '/MSIE|Edge/', $userAgent ) ) {
// ...and redirect them to legacy encoding, if available
- return $wgParser->guessLegacySectionNameFromWikiText( $text );
+ return $parser->guessLegacySectionNameFromWikiText( $text );
}
// Meanwhile, real browsers get real anchors
- $name = $wgParser->guessSectionNameFromWikiText( $text );
+ $name = $parser->guessSectionNameFromWikiText( $text );
// With one little caveat: per T216029, fragments in HTTP redirects need to be urlencoded,
// otherwise Chrome double-escapes the rest of the URL.
return '#' . urlencode( mb_substr( $name, 1 ) );
* @return ParserOutput
*/
private function parseInternal( $text, $title, $linestart, $tidy, $interface, $language ) {
- global $wgParser;
-
if ( is_null( $title ) ) {
throw new MWException( 'Empty $mTitle in ' . __METHOD__ );
}
$oldLang = $popts->setTargetLanguage( $language );
}
- $parserOutput = $wgParser->getFreshParser()->parse(
+ $parserOutput = MediaWikiServices::getInstance()->getParser()->getFreshParser()->parse(
$text, $title, $popts,
$linestart, true, $this->mRevisionId
);
*/
use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
/**
* A simple method to retrieve the plain source of an article,
* @return string|bool
*/
public function getRawText() {
- global $wgParser;
-
$text = false;
$title = $this->getTitle();
$request = $this->getRequest();
}
if ( $text !== false && $text !== '' && $request->getRawVal( 'templates' ) === 'expand' ) {
- $text = $wgParser->preprocess(
+ $text = MediaWikiServices::getInstance()->getParser()->preprocess(
$text,
$title,
ParserOptions::newFromContext( $this->getContext() )
$result = $this->getResult();
// Parse text
- global $wgParser;
$options = ParserOptions::newFromContext( $this->getContext() );
if ( $params['includecomments'] ) {
$retval = [];
+ $parser = MediaWikiServices::getInstance()->getParser();
if ( isset( $prop['parsetree'] ) || $params['generatexml'] ) {
- $wgParser->startExternalParse( $titleObj, $options, Parser::OT_PREPROCESS );
- $dom = $wgParser->preprocessToDom( $params['text'] );
+ $parser->startExternalParse( $titleObj, $options, Parser::OT_PREPROCESS );
+ $dom = $parser->preprocessToDom( $params['text'] );
if ( is_callable( [ $dom, 'saveXML' ] ) ) {
$xml = $dom->saveXML();
} else {
// if they didn't want any output except (probably) the parse tree,
// then don't bother actually fully expanding it
if ( $prop || $params['prop'] === null ) {
- $wgParser->startExternalParse( $titleObj, $options, Parser::OT_PREPROCESS );
- $frame = $wgParser->getPreprocessor()->newFrame();
- $wikitext = $wgParser->preprocess( $params['text'], $titleObj, $options, $revid, $frame );
+ $parser->startExternalParse( $titleObj, $options, Parser::OT_PREPROCESS );
+ $frame = $parser->getPreprocessor()->newFrame();
+ $wikitext = $parser->preprocess( $params['text'], $titleObj, $options, $revid, $frame );
if ( $params['prop'] === null ) {
// the old way
ApiResult::setContentValue( $retval, 'wikitext', $wikitext );
} else {
- $p_output = $wgParser->getOutput();
+ $p_output = $parser->getOutput();
if ( isset( $prop['categories'] ) ) {
$categories = $p_output->getCategories();
if ( $categories ) {
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* This action allows users to get their watchlist items in RSS/Atom formats.
* When executed, it performs a nested call to the API to get the needed data,
if ( $this->linkToSections && $comment !== null &&
preg_match( '!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment, $matches )
) {
- global $wgParser;
- $titleUrl .= $wgParser->guessSectionNameFromWikiText( $matches[ 2 ] );
+ $titleUrl .= MediaWikiServices::getInstance()->getParser()
+ ->guessSectionNameFromWikiText( $matches[ 2 ] );
}
$timestamp = $info['timestamp'];
// The parser needs $wgTitle to be set, apparently the
// $title parameter in Parser::parse isn't enough *sigh*
// TODO: Does this still need $wgTitle?
- global $wgParser, $wgTitle;
+ global $wgTitle;
$redirValues = null;
$this->dieWithError( 'apierror-parsetree-notwikitext', 'notwikitext' );
}
- $wgParser->startExternalParse( $titleObj, $popts, Parser::OT_PREPROCESS );
- $xml = $wgParser->preprocessToDom( $this->content->getText() )->__toString();
+ $parser = MediaWikiServices::getInstance()->getParser();
+ $parser->startExternalParse( $titleObj, $popts, Parser::OT_PREPROCESS );
+ $xml = $parser->preprocessToDom( $this->content->getText() )->__toString();
$result_array['parsetree'] = $xml;
$result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsetree';
}
* @return Content|bool
*/
private function formatSummary( $title, $params ) {
- global $wgParser;
$summary = $params['summary'] ?? '';
$sectionTitle = $params['sectiontitle'] ?? '';
}
if ( $summary !== '' ) {
$summary = wfMessage( 'newsectionsummary' )
- ->rawParams( $wgParser->stripSectionName( $summary ) )
- ->inContentLanguage()->text();
+ ->rawParams( MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( $summary ) )
+ ->inContentLanguage()->text();
}
}
return Linker::formatComment( $summary, $title, $this->section === 'new' );
* @return array
*/
private function extractDeprecatedContent( Content $content, RevisionRecord $revision ) {
- global $wgParser;
-
$vals = [];
$title = Title::newFromLinkTarget( $revision->getPageAsLinkTarget() );
if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
$t = $content->getText(); # note: don't set $text
- $wgParser->startExternalParse(
+ $parser = MediaWikiServices::getInstance()->getParser();
+ $parser->startExternalParse(
$title,
ParserOptions::newFromContext( $this->getContext() ),
Parser::OT_PREPROCESS
);
- $dom = $wgParser->preprocessToDom( $t );
+ $dom = $parser->preprocessToDom( $t );
if ( is_callable( [ $dom, 'saveXML' ] ) ) {
$xml = $dom->saveXML();
} else {
if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
$text = $content->getText();
- $text = $wgParser->preprocess(
+ $text = MediaWikiServices::getInstance()->getParser()->preprocess(
$text,
$title,
ParserOptions::newFromContext( $this->getContext() )
}
public function appendExtensionTags( $property ) {
- global $wgParser;
$tags = array_map(
function ( $item ) {
return "<$item>";
},
- $wgParser->getTags()
+ MediaWikiServices::getInstance()->getParser()->getTags()
);
ApiResult::setArrayType( $tags, 'BCarray' );
ApiResult::setIndexedTagName( $tags, 't' );
}
public function appendFunctionHooks( $property ) {
- global $wgParser;
- $hooks = $wgParser->getFunctionHooks();
+ $hooks = MediaWikiServices::getInstance()->getParser()->getFunctionHooks();
ApiResult::setArrayType( $hooks, 'BCarray' );
ApiResult::setIndexedTagName( $hooks, 'h' );
* @return Parser
*/
public function getParser() {
- global $wgParser, $wgParserConf;
-
- if ( !$this->mParser && isset( $wgParser ) ) {
+ global $wgParserConf;
+ if ( !$this->mParser ) {
+ $parser = MediaWikiServices::getInstance()->getParser();
# Do some initialisation so that we don't have to do it twice
- $wgParser->firstCallInit();
+ $parser->firstCallInit();
# Clone it and store it
$class = $wgParserConf['class'];
if ( $class == ParserDiffTest::class ) {
# Uncloneable
$this->mParser = new $class( $wgParserConf );
} else {
- $this->mParser = clone $wgParser;
+ $this->mParser = clone $parser;
}
}
* @author Daniel Kinzler
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Content object for CSS pages.
*
* @see TextContent::preSaveTransform
*/
public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
- global $wgParser;
// @todo Make pre-save transformation optional for script pages
$text = $this->getText();
- $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts );
+ $pst = MediaWikiServices::getInstance()->getParser()
+ ->preSaveTransform( $text, $title, $user, $popts );
return new static( $pst );
}
* @author Daniel Kinzler
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Content for JavaScript pages.
*
* @return JavaScriptContent
*/
public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
- global $wgParser;
// @todo Make pre-save transformation optional for script pages
// See T34858
$text = $this->getText();
- $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts );
+ $pst = MediaWikiServices::getInstance()->getParser()
+ ->preSaveTransform( $text, $title, $user, $popts );
return new static( $pst );
}
protected function fillParserOutput( Title $title, $revId,
ParserOptions $options, $generateHtml, ParserOutput &$output
) {
- global $wgParser, $wgTextModelsToParse;
+ global $wgTextModelsToParse;
if ( in_array( $this->getModel(), $wgTextModelsToParse ) ) {
// parse just to get links etc into the database, HTML is replaced below.
- $output = $wgParser->parse( $this->getText(), $title, $options, true, true, $revId );
+ $output = MediaWikiServices::getInstance()->getParser()
+ ->parse( $this->getText(), $title, $options, true, true, $revId );
}
if ( $generateHtml ) {
* @see Content::getSection()
*/
public function getSection( $sectionId ) {
- global $wgParser;
-
$text = $this->getText();
- $sect = $wgParser->getSection( $text, $sectionId, false );
+ $sect = MediaWikiServices::getInstance()->getParser()
+ ->getSection( $text, $sectionId, false );
if ( $sect === false ) {
return false;
}
} else {
# Replacing an existing section; roll out the big guns
- global $wgParser;
-
- $text = $wgParser->replaceSection( $oldtext, $sectionId, $text );
+ $text = MediaWikiServices::getInstance()->getParser()
+ ->replaceSection( $oldtext, $sectionId, $text );
}
$newContent = new static( $text );
* @return Content
*/
public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
- global $wgParser;
-
$text = $this->getText();
- $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts );
+
+ $parser = MediaWikiServices::getInstance()->getParser();
+ $pst = $parser->preSaveTransform( $text, $title, $user, $popts );
if ( $text === $pst ) {
return $this;
$ret = new static( $pst );
- if ( $wgParser->getOutput()->getFlag( 'user-signature' ) ) {
+ if ( $parser->getOutput()->getFlag( 'user-signature' ) ) {
$ret->hadSignature = true;
}
* @return Content
*/
public function preloadTransform( Title $title, ParserOptions $popts, $params = [] ) {
- global $wgParser;
-
$text = $this->getText();
- $plt = $wgParser->getPreloadText( $text, $title, $popts, $params );
+ $plt = MediaWikiServices::getInstance()->getParser()
+ ->getPreloadText( $text, $title, $popts, $params );
return new static( $plt );
}
/**
* Returns a ParserOutput object resulting from parsing the content's text
- * using $wgParser.
+ * using the global Parser service.
*
* @param Title $title
* @param int $revId Revision to pass to the parser (default: null)
protected function fillParserOutput( Title $title, $revId,
ParserOptions $options, $generateHtml, ParserOutput &$output
) {
- global $wgParser;
-
$stackTrace = ( new RuntimeException() )->getTraceAsString();
if ( $this->previousParseStackTrace ) {
// NOTE: there may be legitimate changes to re-parse the same WikiText content,
$this->previousParseStackTrace = $stackTrace;
list( $redir, $text ) = $this->getRedirectTargetAndText();
- $output = $wgParser->parse( $text, $title, $options, true, true, $revId );
+ $output = MediaWikiServices::getInstance()->getParser()
+ ->parse( $text, $title, $options, true, true, $revId );
// Add redirect indicator at the top
if ( $redir ) {
* If you have pre-fetched the nickname or the fancySig option, you can
* specify them here to save a database query.
* Do not reuse this parser instance after calling getUserSig(),
- * as it may have changed if it's the $wgParser.
+ * as it may have changed.
*
* @param User &$user
* @param string|bool $nickname Nickname to use or false to use user's default nickname
/**
* Return this parser if it is not doing anything, otherwise
* get a fresh parser. You can use this method by doing
- * $myParser = $wgParser->getFreshParser(), or more simply
- * $wgParser->getFreshParser()->parse( ... );
- * if you're unsure if $wgParser is safe to use.
+ * $newParser = $oldParser->getFreshParser(), or more simply
+ * $oldParser->getFreshParser()->parse( ... );
+ * if you're unsure if $oldParser is safe to use.
*
* @since 1.24
* @return Parser A parser object that is not parsing anything
* unless only max-priority makes sense.
*
* @warning This will be called early in the MediaWiki setup process,
- * before $wgUser, $wgLang, $wgOut, $wgParser, $wgTitle, and corresponding
- * pieces of the main RequestContext are set up! If you try to use these,
- * things *will* break.
+ * before $wgUser, $wgLang, $wgOut, $wgTitle, the global parser, and
+ * corresponding pieces of the main RequestContext are set up! If you try
+ * to use these, things *will* break.
* @note The SessionProvider must not attempt to auto-create users.
* MediaWiki will do this later (when it's safe) if the chosen session has
* a user with a valid name but no ID.
* @note If self::__toString() is overridden, this will likely need to be
* overridden as well.
* @warning This will be called early during MediaWiki startup. Do not
- * use $wgUser, $wgLang, $wgOut, $wgParser, or their equivalents via
+ * use $wgUser, $wgLang, $wgOut, the global Parser, or their equivalents via
* RequestContext from this method!
* @return \Message
*/
* @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' ) ) {
$xml = $dom->saveXML();
}
}
- $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 );
}
/**
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Give information about the version of MediaWiki, PHP, the DB and extensions
*
* @return string HTML output
*/
protected function getParserTags() {
- global $wgParser;
-
- $tags = $wgParser->getTags();
+ $tags = MediaWikiServices::getInstance()->getParser()->getTags();
if ( count( $tags ) ) {
$out = Html::rawElement(
* @return string HTML output
*/
protected function getParserFunctionHooks() {
- global $wgParser;
-
- $fhooks = $wgParser->getFunctionHooks();
+ $fhooks = MediaWikiServices::getInstance()->getParser()->getFunctionHooks();
if ( count( $fhooks ) ) {
$out = Html::rawElement(
'h2',
}
public function checkOptions() {
- global $wgParser, $wgParserConf, $wgPreprocessorCacheThreshold;
+ global $wgParserConf, $wgPreprocessorCacheThreshold;
if ( !$this->hasOption( 'cache' ) ) {
$wgPreprocessorCacheThreshold = false;
$name = Preprocessor_DOM::class;
}
- $wgParser->firstCallInit();
+ MediaWikiServices::getInstance()->getParser()->firstCallInit();
$this->mPreprocessor = new $name( $this );
}
}
function execute() {
- global $wgParser, $wgUser;
+ global $wgUser;
$wgUser = new PPFuzzUser;
$wgUser->mName = 'Fuzz';
$options->setTemplateCallback( [ $this, 'templateHook' ] );
$options->setTimestamp( wfTimestampNow() );
$this->output = call_user_func(
- [ $wgParser, $this->entryPoint ],
+ [ MediaWikiServices::getInstance()->getParser(), $this->entryPoint ],
$this->mainText,
$this->title,
$options
* @return bool True if tag hook is present
*/
public function requireHook( $name ) {
- global $wgParser;
+ $parser = MediaWikiServices::getInstance()->getParser();
- $wgParser->firstCallInit(); // make sure hooks are loaded.
- if ( isset( $wgParser->mTagHooks[$name] ) ) {
+ $parser->firstCallInit(); // make sure hooks are loaded.
+ if ( isset( $parser->mTagHooks[$name] ) ) {
return true;
} else {
$this->recorder->warning( " This test suite requires the '$name' hook " .
* @return bool True if function hook is present
*/
public function requireFunctionHook( $name ) {
- global $wgParser;
+ $parser = MediaWikiServices::getInstance()->getParser();
- $wgParser->firstCallInit(); // make sure hooks are loaded.
+ $parser->firstCallInit(); // make sure hooks are loaded.
- if ( isset( $wgParser->mFunctionHooks[$name] ) ) {
+ if ( isset( $parser->mFunctionHooks[$name] ) ) {
return true;
} else {
$this->recorder->warning( " This test suite requires the '$name' function " .
* @return bool True if function hook is present
*/
public function requireTransparentHook( $name ) {
- global $wgParser;
+ $parser = MediaWikiServices::getInstance()->getParser();
- $wgParser->firstCallInit(); // make sure hooks are loaded.
+ $parser->firstCallInit(); // make sure hooks are loaded.
- if ( isset( $wgParser->mTransparentTagHooks[$name] ) ) {
+ if ( isset( $parser->mTransparentTagHooks[$name] ) ) {
return true;
} else {
$this->recorder->warning( " This test suite requires the '$name' transparent " .
<?php
-use MediaWiki\MediaWikiServices;
use Wikimedia\TestingAccessWrapper;
/**
// We have to reset the core hook registration.
// to register the html hook
MessageCache::destroyInstance();
- $this->setMwGlobals( 'wgParser',
- MediaWikiServices::getInstance()->getParserFactory()->create() );
+ $this->overrideMwServices();
$msg = new RawMessage( '<html><script>alert("xss")</script></html>' );
$txt = '<span class="error"><html> tags cannot be' .
}
public function testExtensionTags() {
- global $wgParser;
-
$expected = array_map(
function ( $tag ) {
return "<$tag>";
},
- $wgParser->getTags()
+ MediaWikiServices::getInstance()->getParser()->getTags()
);
$this->assertSame( $expected, $this->doQuery( 'extensiontags' ) );
}
public function testFunctionHooks() {
- global $wgParser;
-
- $this->assertSame( $wgParser->getFunctionHooks(), $this->doQuery( 'functionhooks' ) );
+ $this->assertSame( MediaWikiServices::getInstance()->getParser()->getFunctionHooks(),
+ $this->doQuery( 'functionhooks' ) );
}
public function testVariables() {
<?php
+use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\MutableRevisionRecord;
use MediaWiki\Revision\RevisionStore;
use MediaWiki\Revision\SlotRecord;
* @dataProvider providePreSaveTransform
*/
public function testPreSaveTransform( $text, $expected ) {
- global $wgParser;
-
$title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
$user = new User();
$user->setName( "127.0.0.1" );
$popts = ParserOptions::newFromUser( $user );
- $text = $wgParser->preSaveTransform( $text, $title, $user, $popts );
+ $text = MediaWikiServices::getInstance()->getParser()
+ ->preSaveTransform( $text, $title, $user, $popts );
$this->assertEquals( $expected, $text );
}
* Did you call Parser::parse recursively?
*/
public function testRecursiveParse() {
- global $wgParser;
$title = Title::newFromText( 'foo' );
+ $parser = MediaWikiServices::getInstance()->getParser();
$po = new ParserOptions;
- $wgParser->setHook( 'recursivecallparser', [ $this, 'helperParserFunc' ] );
- $wgParser->parse( '<recursivecallparser>baz</recursivecallparser>', $title, $po );
+ $parser->setHook( 'recursivecallparser', [ $this, 'helperParserFunc' ] );
+ $parser->parse( '<recursivecallparser>baz</recursivecallparser>', $title, $po );
}
public function helperParserFunc( $input, $args, $parser ) {
}
public function testCallParserFunction() {
- global $wgParser;
-
// Normal parses test passing PPNodes. Test passing an array.
$title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
- $wgParser->startExternalParse( $title, new ParserOptions(), Parser::OT_HTML );
- $frame = $wgParser->getPreprocessor()->newFrame();
- $ret = $wgParser->callParserFunction( $frame, '#tag',
+ $parser = MediaWikiServices::getInstance()->getParser();
+ $parser->startExternalParse( $title, new ParserOptions(), Parser::OT_HTML );
+ $frame = $parser->getPreprocessor()->newFrame();
+ $ret = $parser->callParserFunction( $frame, '#tag',
[ 'pre', 'foo', 'style' => 'margin-left: 1.6em' ]
);
- $ret['text'] = $wgParser->mStripState->unstripBoth( $ret['text'] );
+ $ret['text'] = $parser->mStripState->unstripBoth( $ret['text'] );
$this->assertSame( [
'found' => true,
'text' => '<pre style="margin-left: 1.6em">foo</pre>',
* @covers ParserOutput::getSections
*/
public function testGetSections() {
- global $wgParser;
-
$title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
- $out = $wgParser->parse( "==foo==\n<h2>bar</h2>\n==baz==\n", $title, new ParserOptions() );
+ $out = MediaWikiServices::getInstance()->getParser()
+ ->parse( "==foo==\n<h2>bar</h2>\n==baz==\n", $title, new ParserOptions() );
$this->assertSame( [
[
'toclevel' => 1,
}
public function testWrapOutput() {
- global $wgParser;
$title = Title::newFromText( 'foo' );
$po = new ParserOptions();
- $wgParser->parse( 'Hello World', $title, $po );
- $text = $wgParser->getOutput()->getText();
+ $parser = MediaWikiServices::getInstance()->getParser();
+ $parser->parse( 'Hello World', $title, $po );
+ $text = $parser->getOutput()->getText();
$this->assertContains( 'Hello World', $text );
$this->assertContains( '<div', $text );
$expectedInHtml,
$expectedInPst = null
) {
- global $wgParser;
-
$title = $this->getMockTitle( 'ParserRevisionAccessTest' );
$po->enableLimitReport( false );
$this->setService( 'RevisionStore', $revisionStore );
- $wgParser->parse( $text, $title, $po, true, true, $revId );
- $html = $wgParser->getOutput()->getText();
+ $parser = MediaWikiServices::getInstance()->getParser();
+ $parser->parse( $text, $title, $po, true, true, $revId );
+ $html = $parser->getOutput()->getText();
$this->assertContains( $expectedInHtml, $html, 'In HTML' );
if ( $expectedInPst !== null ) {
- $pst = $wgParser->preSaveTransform( $text, $title, $po->getUser(), $po );
+ $pst = $parser->preSaveTransform( $text, $title, $po->getUser(), $po );
$this->assertContains( $expectedInPst, $pst, 'After Pre-Safe Transform' );
}
}
/** @dataProvider provideGuessSectionNameFromWikiText */
public function testGuessSectionNameFromWikiText( $input, $mode, $expected ) {
$this->setMwGlobals( [ 'wgFragmentMode' => [ $mode ] ] );
- global $wgParser;
- $result = $wgParser->guessSectionNameFromWikiText( $input );
+ $result = MediaWikiServices::getInstance()->getParser()
+ ->guessSectionNameFromWikiText( $input );
$this->assertEquals( $result, $expected );
}
}
protected function setUp() {
- global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser,
- $wgLang, $wgOut, $wgRequest, $wgStyleDirectory,
+ global $IP, $messageMemc, $wgMemc, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory,
$wgParserCacheType, $wgNamespaceAliases, $wgNamespaceProtection;
$tmpDir = $this->getNewTempDirectory();
$wgUser = new User;
$wgLang = $context->getLanguage();
$wgOut = $context->getOutput();
- $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] );
$wgRequest = $context->getRequest();
if ( $wgStyleDirectory === false ) {