* @ingroup Parser
*/
use MediaWiki\Linker\LinkRenderer;
+use MediaWiki\Linker\LinkRendererFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\Special\SpecialPageFactory;
use Wikimedia\ScopedCallback;
/** @var Config */
private $siteConfig;
+ /** @var LinkRendererFactory */
+ private $linkRendererFactory;
+
+ /** @var NamespaceInfo */
+ private $nsInfo;
+
/**
* @param array $parserConf See $wgParserConf documentation
* @param MagicWordFactory|null $magicWordFactory
* @param string|null $urlProtocols As returned from wfUrlProtocols()
* @param SpecialPageFactory|null $spFactory
* @param Config|null $siteConfig
+ * @param LinkRendererFactory|null $linkRendererFactory
+ * @param NamespaceInfo|null $nsInfo
*/
public function __construct(
array $parserConf = [], MagicWordFactory $magicWordFactory = null,
Language $contLang = null, ParserFactory $factory = null, $urlProtocols = null,
- SpecialPageFactory $spFactory = null, Config $siteConfig = null
+ SpecialPageFactory $spFactory = null, Config $siteConfig = null,
+ LinkRendererFactory $linkRendererFactory = null,
+ NamespaceInfo $nsInfo = null
) {
$this->mConf = $parserConf;
$this->mUrlProtocols = $urlProtocols ?? wfUrlProtocols();
$this->factory = $factory ?? $services->getParserFactory();
$this->specialPageFactory = $spFactory ?? $services->getSpecialPageFactory();
- $this->siteConfig = $siteConfig ?? MediaWikiServices::getInstance()->getMainConfig();
+ $this->siteConfig = $siteConfig ?? $services->getMainConfig();
+ $this->linkRendererFactory =
+ $linkRendererFactory ?? $services->getLinkRendererFactory();
+ $this->nsInfo = $nsInfo ?? $services->getNamespaceInfo();
}
/**
* @return LinkRenderer
*/
public function getLinkRenderer() {
+ // XXX We make the LinkRenderer with current options and then cache it forever
if ( !$this->mLinkRenderer ) {
- $this->mLinkRenderer = MediaWikiServices::getInstance()
- ->getLinkRendererFactory()->create();
+ $this->mLinkRenderer = $this->linkRendererFactory->create();
$this->mLinkRenderer->setStubThreshold(
$this->getOptions()->getStubThreshold()
);
*/
public function areSubpagesAllowed() {
# Some namespaces don't allow subpages
- return MWNamespace::hasSubpages( $this->mTitle->getNamespace() );
+ return $this->nsInfo->hasSubpages( $this->mTitle->getNamespace() );
}
/**
$this->siteConfig->get( 'MiserMode' ) &&
!$this->mOptions->getInterfaceMessage() &&
// @TODO: disallow this word on all namespaces
- MWNamespace::isContent( $this->mTitle->getNamespace() )
+ $this->nsInfo->isContent( $this->mTitle->getNamespace() )
) {
- return $this->mRevisionId ? '-' : '';
+ if ( $this->mRevisionId || $this->mOptions->getSpeculativeRevId() ) {
+ return '-';
+ } else {
+ $this->mOutput->setFlag( 'vary-revision-exists' );
+
+ return '';
+ }
};
$pageLang = $this->getFunctionLang();
);
}
}
- } elseif ( MWNamespace::isNonincludable( $title->getNamespace() ) ) {
+ } elseif ( $this->nsInfo->isNonincludable( $title->getNamespace() ) ) {
$found = false; # access denied
wfDebug( __METHOD__ . ": template inclusion denied for " .
$title->getPrefixedDBkey() . "\n" );
* 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