Manual:$wgParser

From mediawiki.org
Jump to navigation Jump to search
This page is a translated version of the page Manual:$wgParser and the translation is 43% complete.
Other languages:
English • ‎español • ‎português do Brasil • ‎čeština • ‎日本語

説明

Use MediaWikiServices::getInstance()->getParser() instead (phab:T160811).

The Parser object is responsible for parsing the tags and wikitext contained in wiki pages. Parser extensions hooks are also registered in the Parser object.

Mode of Operation

$wgParser は、includes/Setup.php で以下のコードで呼び出されます:

$wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );

StubObject は includes/StubObject.php で定義されています。

wgParserConf は、includes/DefaultSettings.php で以下のコードで定義されています:

$wgParserConf = array('class' => 'Parser',);

Replacement

MediaWiki バージョン:
1.32

New code should use dependency injection instead. The parser is now available in the service locator under the Parser service. Existing code that has not yet been changed to use dependency injection can call the service locator directly:

public function render() {
    $parser = \MediaWiki\MediaWikiServices::getInstance()->getParser();
    $text = $parser->parse(
        ...
    )->getText();
}