Update LinkRenderer to use NamespaceInfo
Change-Id: I4af843238ffd58925f57c0f7b98253a90cb285ec
This commit is contained in:
parent
7159f97a55
commit
82311f8c2c
5 changed files with 45 additions and 13 deletions
|
|
@ -249,7 +249,8 @@ return [
|
|||
'LinkRendererFactory' => function ( MediaWikiServices $services ) : LinkRendererFactory {
|
||||
return new LinkRendererFactory(
|
||||
$services->getTitleFormatter(),
|
||||
$services->getLinkCache()
|
||||
$services->getLinkCache(),
|
||||
$services->getNamespaceInfo()
|
||||
);
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use HtmlArmor;
|
|||
use LinkCache;
|
||||
use Linker;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MWNamespace;
|
||||
use NamespaceInfo;
|
||||
use Sanitizer;
|
||||
use Title;
|
||||
use TitleFormatter;
|
||||
|
|
@ -69,6 +69,11 @@ class LinkRenderer {
|
|||
*/
|
||||
private $linkCache;
|
||||
|
||||
/**
|
||||
* @var NamespaceInfo
|
||||
*/
|
||||
private $nsInfo;
|
||||
|
||||
/**
|
||||
* Whether to run the legacy Linker hooks
|
||||
*
|
||||
|
|
@ -79,10 +84,14 @@ class LinkRenderer {
|
|||
/**
|
||||
* @param TitleFormatter $titleFormatter
|
||||
* @param LinkCache $linkCache
|
||||
* @param NamespaceInfo $nsInfo
|
||||
*/
|
||||
public function __construct( TitleFormatter $titleFormatter, LinkCache $linkCache ) {
|
||||
public function __construct(
|
||||
TitleFormatter $titleFormatter, LinkCache $linkCache, NamespaceInfo $nsInfo
|
||||
) {
|
||||
$this->titleFormatter = $titleFormatter;
|
||||
$this->linkCache = $linkCache;
|
||||
$this->nsInfo = $nsInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -468,8 +477,9 @@ class LinkRenderer {
|
|||
if ( $this->linkCache->getGoodLinkFieldObj( $target, 'redirect' ) ) {
|
||||
# Page is a redirect
|
||||
return 'mw-redirect';
|
||||
} elseif ( $this->stubThreshold > 0 && MWNamespace::isContent( $target->getNamespace() )
|
||||
&& $this->linkCache->getGoodLinkFieldObj( $target, 'length' ) < $this->stubThreshold
|
||||
} elseif (
|
||||
$this->stubThreshold > 0 && $this->nsInfo->isContent( $target->getNamespace() ) &&
|
||||
$this->linkCache->getGoodLinkFieldObj( $target, 'length' ) < $this->stubThreshold
|
||||
) {
|
||||
# Page is a stub
|
||||
return 'stub';
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
namespace MediaWiki\Linker;
|
||||
|
||||
use LinkCache;
|
||||
use NamespaceInfo;
|
||||
use TitleFormatter;
|
||||
use User;
|
||||
|
||||
|
|
@ -40,20 +41,29 @@ class LinkRendererFactory {
|
|||
*/
|
||||
private $linkCache;
|
||||
|
||||
/**
|
||||
* @var NamespaceInfo
|
||||
*/
|
||||
private $nsInfo;
|
||||
|
||||
/**
|
||||
* @param TitleFormatter $titleFormatter
|
||||
* @param LinkCache $linkCache
|
||||
* @param NamespaceInfo $nsInfo
|
||||
*/
|
||||
public function __construct( TitleFormatter $titleFormatter, LinkCache $linkCache ) {
|
||||
public function __construct(
|
||||
TitleFormatter $titleFormatter, LinkCache $linkCache, NamespaceInfo $nsInfo
|
||||
) {
|
||||
$this->titleFormatter = $titleFormatter;
|
||||
$this->linkCache = $linkCache;
|
||||
$this->nsInfo = $nsInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LinkRenderer
|
||||
*/
|
||||
public function create() {
|
||||
return new LinkRenderer( $this->titleFormatter, $this->linkCache );
|
||||
return new LinkRenderer( $this->titleFormatter, $this->linkCache, $this->nsInfo );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -19,10 +19,18 @@ class LinkRendererFactoryTest extends MediaWikiLangTestCase {
|
|||
*/
|
||||
private $linkCache;
|
||||
|
||||
/**
|
||||
* @var NamespaceInfo
|
||||
*/
|
||||
private $nsInfo;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
|
||||
$this->linkCache = MediaWikiServices::getInstance()->getLinkCache();
|
||||
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$this->titleFormatter = $services->getTitleFormatter();
|
||||
$this->linkCache = $services->getLinkCache();
|
||||
$this->nsInfo = $services->getNamespaceInfo();
|
||||
}
|
||||
|
||||
public static function provideCreateFromLegacyOptions() {
|
||||
|
|
@ -54,7 +62,8 @@ class LinkRendererFactoryTest extends MediaWikiLangTestCase {
|
|||
* @dataProvider provideCreateFromLegacyOptions
|
||||
*/
|
||||
public function testCreateFromLegacyOptions( $options, $func, $val ) {
|
||||
$factory = new LinkRendererFactory( $this->titleFormatter, $this->linkCache );
|
||||
$factory =
|
||||
new LinkRendererFactory( $this->titleFormatter, $this->linkCache, $this->nsInfo );
|
||||
$linkRenderer = $factory->createFromLegacyOptions(
|
||||
$options
|
||||
);
|
||||
|
|
@ -63,7 +72,8 @@ class LinkRendererFactoryTest extends MediaWikiLangTestCase {
|
|||
}
|
||||
|
||||
public function testCreate() {
|
||||
$factory = new LinkRendererFactory( $this->titleFormatter, $this->linkCache );
|
||||
$factory =
|
||||
new LinkRendererFactory( $this->titleFormatter, $this->linkCache, $this->nsInfo );
|
||||
$this->assertInstanceOf( LinkRenderer::class, $factory->create() );
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +84,8 @@ class LinkRendererFactoryTest extends MediaWikiLangTestCase {
|
|||
$user->expects( $this->once() )
|
||||
->method( 'getStubThreshold' )
|
||||
->willReturn( 15 );
|
||||
$factory = new LinkRendererFactory( $this->titleFormatter, $this->linkCache );
|
||||
$factory =
|
||||
new LinkRendererFactory( $this->titleFormatter, $this->linkCache, $this->nsInfo );
|
||||
$linkRenderer = $factory->createForUser( $user );
|
||||
$this->assertInstanceOf( LinkRenderer::class, $linkRenderer );
|
||||
$this->assertEquals( 15, $linkRenderer->getStubThreshold() );
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ class LinkRendererTest extends MediaWikiLangTestCase {
|
|||
0 // redir
|
||||
);
|
||||
|
||||
$linkRenderer = new LinkRenderer( $titleFormatter, $linkCache );
|
||||
$linkRenderer = new LinkRenderer( $titleFormatter, $linkCache, $nsInfo );
|
||||
$linkRenderer->setStubThreshold( 0 );
|
||||
$this->assertEquals(
|
||||
'',
|
||||
|
|
|
|||
Loading…
Reference in a new issue