Hoo man has uploaded a new change for review.
https://gerrit.wikimedia.org/r/190631
Change subject: Remove Utils, introduce LanguageNameLookup
......................................................................
Remove Utils, introduce LanguageNameLookup
This finally removes the static Utils class!
Also I've remove the ContentLanguages/WikibaseContentLanguages::getName
method, as that doesn't really belong there (while the set
of languages supported might differ between features, language
names will always be the same).
Change-Id: Iec9922875489e48749bc096d8c992f91d6991644
---
M client/includes/WikibaseClient.php
M client/tests/phpunit/includes/WikibaseClientTest.php
M lib/includes/ContentLanguages.php
R lib/includes/LanguageNameLookup.php
M lib/includes/WikibaseContentLanguages.php
M lib/includes/formatters/EntityIdHtmlLinkFormatter.php
M lib/includes/formatters/EntityIdHtmlLinkFormatterFactory.php
M lib/includes/formatters/MonolingualHtmlFormatter.php
M lib/includes/formatters/WikibaseValueFormatterBuilders.php
M lib/includes/modules/SitesModule.php
M lib/tests/phpunit/LanguageFallbackChainFactoryTest.php
M lib/tests/phpunit/LanguageFallbackChainTest.php
A lib/tests/phpunit/LanguageNameLookupTest.php
D lib/tests/phpunit/UtilsTest.php
M lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterFactoryTest.php
M lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterTest.php
M lib/tests/phpunit/formatters/MonolingualHtmlFormatterTest.php
M lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
M lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
M repo/Wikibase.hooks.php
M repo/includes/View/EntityTermsView.php
M repo/includes/View/EntityViewFactory.php
M repo/includes/View/EntityViewPlaceholderExpander.php
M repo/includes/View/SiteLinksView.php
M repo/includes/WikibaseRepo.php
M repo/includes/specials/SpecialItemDisambiguation.php
M repo/tests/phpunit/includes/View/EntityTermsViewTest.php
M repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
M repo/tests/phpunit/includes/View/EntityViewPlaceholderExpanderTest.php
M repo/tests/phpunit/includes/View/SiteLinksViewTest.php
M repo/tests/phpunit/includes/WikibaseRepoTest.php
M repo/tests/phpunit/includes/specials/SpecialItemDisambiguationTest.php
32 files changed, 193 insertions(+), 187 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/31/190631/1
diff --git a/client/includes/WikibaseClient.php
b/client/includes/WikibaseClient.php
index e95dc7f..655975b 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -41,6 +41,7 @@
use Wikibase\Lib\Changes\EntityChangeFactory;
use Wikibase\Lib\EntityRetrievingDataTypeLookup;
use Wikibase\Lib\FormatterLabelLookupFactory;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\Lib\OutputFormatSnakFormatterFactory;
use Wikibase\Lib\OutputFormatValueFormatterFactory;
use Wikibase\Lib\PropertyInfoDataTypeLookup;
@@ -512,8 +513,7 @@
return new WikibaseValueFormatterBuilders(
$this->contentLanguage,
new FormatterLabelLookupFactory( $this->getTermLookup()
),
- new WikibaseContentLanguages(),
- $this->getTermsLanguages()
+ new LanguageNameLookup()
);
}
diff --git a/client/tests/phpunit/includes/WikibaseClientTest.php
b/client/tests/phpunit/includes/WikibaseClientTest.php
index 1a514d9..a7d0c1f 100644
--- a/client/tests/phpunit/includes/WikibaseClientTest.php
+++ b/client/tests/phpunit/includes/WikibaseClientTest.php
@@ -210,6 +210,11 @@
$this->assertInstanceOf(
'Wikibase\DataAccess\PropertyParserFunction\Runner', $runner );
}
+ public function testGetTermsLanguages() {
+ $langs = $this->getWikibaseClient()->getTermsLanguages();
+ $this->assertInstanceOf( 'Wikibase\Lib\ContentLanguages', $langs );
+ }
+
/**
* @return WikibaseClient
*/
diff --git a/lib/includes/ContentLanguages.php
b/lib/includes/ContentLanguages.php
index 55ab7e9..3080a39 100644
--- a/lib/includes/ContentLanguages.php
+++ b/lib/includes/ContentLanguages.php
@@ -22,16 +22,4 @@
*/
public function hasLanguage( $languageCode );
- /**
- * Get the name of the language specified by $languageCode. The name
should be in the language
- * specified by $inLanguage, but it might be in any other language. If
null is given as $inLanguage,
- * $languageCode is used, i. e. the service tries to give the autonym
of the language.
- *
- * @param string $languageCode
- * @param string|null $inLanguage
- *
- * @return string
- */
- public function getName( $languageCode, $inLanguage = null );
-
}
diff --git a/lib/includes/Utils.php b/lib/includes/LanguageNameLookup.php
similarity index 61%
rename from lib/includes/Utils.php
rename to lib/includes/LanguageNameLookup.php
index 703c596..26341fc 100644
--- a/lib/includes/Utils.php
+++ b/lib/includes/LanguageNameLookup.php
@@ -1,32 +1,33 @@
<?php
-namespace Wikibase;
+namespace Wikibase\Lib;
use Language;
+
/**
- * Utility functions for Wikibase.
+ * Service for looking up language names based on MediaWiki's Language
+ * class.
*
- * @since 0.1
+ * @since 0.5
*
- * @licence GNU GPL v2+
+ * @license GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
* @author Tobias Gritschacher
* @author Jens Ohlig < [email protected] >
* @author John Erling Blad < [email protected] >
+ * @author Marius Hoch < [email protected] >
*/
-final class Utils {
+class LanguageNameLookup {
/**
- * @see Language::fetchLanguageName()
- *
- * @since 0.1
+ * @since 0.5
*
* @param string $languageCode
- * @param string|null $inLanguage
+ * @param string|null $inLanguage Code of language in which to return
the name (null for autonyms)
*
* @return string
*/
- public static function fetchLanguageName( $languageCode, $inLanguage =
null ) {
+ public function getName( $languageCode, $inLanguage = null ) {
$languageCode = str_replace( '_', '-', $languageCode );
if ( isset( $inLanguage ) ) {
@@ -37,7 +38,7 @@
$languageName = Language::fetchLanguageName(
$languageCode );
}
- if ( $languageName == '' ) {
+ if ( $languageName === '' ) {
$languageName = $languageCode;
}
diff --git a/lib/includes/WikibaseContentLanguages.php
b/lib/includes/WikibaseContentLanguages.php
index c8c10e3..3efdfcb 100644
--- a/lib/includes/WikibaseContentLanguages.php
+++ b/lib/includes/WikibaseContentLanguages.php
@@ -3,10 +3,9 @@
namespace Wikibase\Lib;
use Language;
-use Wikibase\Utils;
/**
- * Provide languages supported as content language based on Wikibase\Utils
+ * Provide languages supported as content languages based on MediaWiki's
Language class.
*
* @author Adrian Heine < [email protected] >
* @author Marius Hoch < [email protected] >
@@ -41,20 +40,6 @@
}
return $this->languageMap;
- }
-
- /**
- * Get the name of the language specified by $languageCode. The name
should be in the language
- * specified by $inLanguage, but it might be in any other language. If
null is given as $inLanguage,
- * $languageCode is used, i. e. the service tries to give the autonym
of the language.
- *
- * @param string $languageCode
- * @param string|null $inLanguage
- *
- * @return string
- */
- public function getName( $languageCode, $inLanguage = null ) {
- return Utils::fetchLanguageName( $languageCode, $inLanguage );
}
}
diff --git a/lib/includes/formatters/EntityIdHtmlLinkFormatter.php
b/lib/includes/formatters/EntityIdHtmlLinkFormatter.php
index 73b7a28..db4f3e3 100644
--- a/lib/includes/formatters/EntityIdHtmlLinkFormatter.php
+++ b/lib/includes/formatters/EntityIdHtmlLinkFormatter.php
@@ -22,25 +22,31 @@
class EntityIdHtmlLinkFormatter extends EntityIdLabelFormatter {
/**
- * @var ContentLanguages
+ * @var LanguageNameLookup
*/
- private $termsLanguages;
+ private $languageNameLookup;
/**
* @var EntityTitleLookup
*/
protected $entityTitleLookup;
+ /**
+ * @param FormatterOptions $options
+ * @param LabelLookup $labelLookup
+ * @param EntityTitleLookup $entityTitleLookup
+ * @param LanguageNameLookup $languageNameLookup
+ */
public function __construct(
FormatterOptions $options,
LabelLookup $labelLookup,
EntityTitleLookup $entityTitleLookup,
- ContentLanguages $termsLanguages
+ LanguageNameLookup $languageNameLookup
) {
parent::__construct( $options, $labelLookup );
$this->entityTitleLookup = $entityTitleLookup;
- $this->termsLanguages = $termsLanguages;
+ $this->languageNameLookup = $languageNameLookup;
}
/**
@@ -127,7 +133,7 @@
* @return string
*/
private function getLanguageName( $languageCode, $inLanguage ) {
- return $this->termsLanguages->getName( $languageCode,
$inLanguage );
+ return $this->languageNameLookup->getName( $languageCode,
$inLanguage );
}
private function getHtmlForFallbackIndicator( TermFallback $term ) {
diff --git a/lib/includes/formatters/EntityIdHtmlLinkFormatterFactory.php
b/lib/includes/formatters/EntityIdHtmlLinkFormatterFactory.php
index d3eef26..e4a2d0a 100644
--- a/lib/includes/formatters/EntityIdHtmlLinkFormatterFactory.php
+++ b/lib/includes/formatters/EntityIdHtmlLinkFormatterFactory.php
@@ -23,22 +23,23 @@
private $titleLookup;
/**
- * @var ContentLanguages
+ * @var LanguageNameLookup
*/
- private $termsLanguages;
+ private $languageNameLookup;
/**
* @param FormatterLabelLookupFactory $labelLookupFactory
* @param EntityTitleLookup $titleLookup
+ * @param LanguageNameLookup $languageNameLookup
*/
public function __construct(
FormatterLabelLookupFactory $labelLookupFactory,
EntityTitleLookup $titleLookup,
- ContentLanguages $termsLanguages
+ LanguageNameLookup $languageNameLookup
) {
$this->labelLookupFactory = $labelLookupFactory;
- $this->termsLanguages = $termsLanguages;
$this->titleLookup = $titleLookup;
+ $this->languageNameLookup = $languageNameLookup;
}
/**
@@ -63,7 +64,7 @@
$options,
$labelLookup,
$this->titleLookup,
- $this->termsLanguages
+ $this->languageNameLookup
);
}
diff --git a/lib/includes/formatters/MonolingualHtmlFormatter.php
b/lib/includes/formatters/MonolingualHtmlFormatter.php
index 808e180..fdf442a 100644
--- a/lib/includes/formatters/MonolingualHtmlFormatter.php
+++ b/lib/includes/formatters/MonolingualHtmlFormatter.php
@@ -7,7 +7,7 @@
use ValueFormatters\FormatterOptions;
use ValueFormatters\ValueFormatter;
use ValueFormatters\ValueFormatterBase;
-use Wikibase\Lib\ContentLanguages;
+use Wikibase\Lib\LanguageNameLookup;
/**
* @since 0.5
@@ -18,17 +18,17 @@
class MonolingualHtmlFormatter extends ValueFormatterBase {
/**
- * @var ContentLanguages $contentLanguages
+ * @var LanguageNameLookup
*/
- private $contentLanguages;
+ private $languageNameLookup;
/**
* @param FormatterOptions $options
- * @param ContentLanguages $contentLanguages
+ * @param LanguageNameLookup $languageNameLookup
*/
- public function __construct( FormatterOptions $options,
ContentLanguages $contentLanguages ) {
+ public function __construct( FormatterOptions $options,
LanguageNameLookup $languageNameLookup ) {
parent::__construct( $options );
- $this->contentLanguages = $contentLanguages;
+ $this->languageNameLookup = $languageNameLookup;
}
/**
@@ -43,7 +43,7 @@
$text = $value->getText();
$languageCode = $value->getLanguageCode();
- $languageName = $this->contentLanguages->getName(
$languageCode, $userLanguage );
+ $languageName = $this->languageNameLookup->getName(
$languageCode, $userLanguage );
$msg = wfMessage( 'wikibase-monolingualtext' )->params(
wfEscapeWikiText( $text ),
diff --git a/lib/includes/formatters/WikibaseValueFormatterBuilders.php
b/lib/includes/formatters/WikibaseValueFormatterBuilders.php
index 55809d9..3a1df42 100644
--- a/lib/includes/formatters/WikibaseValueFormatterBuilders.php
+++ b/lib/includes/formatters/WikibaseValueFormatterBuilders.php
@@ -43,18 +43,9 @@
private $entityTitleLookup;
/**
- * The languages available for MonolingualTextValues
- *
- * @var ContentLanguages
+ * @var LanguageNameLookup
*/
- private $monolingualTextLanguages;
-
- /**
- * The languages available for terms
- *
- * @var ContentLanguages
- */
- private $termsLanguages;
+ private $languageNameLookup;
/**
* This determines which value is formatted how by providing a
formatter mapping
@@ -124,17 +115,21 @@
),
);
+ /**
+ * @param Language $defaultLanguage
+ * @param FormatterLabelLookupFactory $labelLookupFactory
+ * @param LanguageNameLookup $languageNameLookup
+ * @param EntityTitleLookup|null $entityTitleLookup
+ */
public function __construct(
Language $defaultLanguage,
FormatterLabelLookupFactory $labelLookupFactory,
- ContentLanguages $monolingualTextLanguages,
- ContentLanguages $termsLanguages,
+ LanguageNameLookup $languageNameLookup,
EntityTitleLookup $entityTitleLookup = null
) {
$this->defaultLanguage = $defaultLanguage;
$this->labelLookupFactory = $labelLookupFactory;
- $this->monolingualTextLanguages = $monolingualTextLanguages;
- $this->termsLanguages = $termsLanguages;
+ $this->languageNameLookup = $languageNameLookup;
$this->entityTitleLookup = $entityTitleLookup;
}
@@ -556,7 +551,7 @@
$options,
$labelLookup,
$this->entityTitleLookup,
- $this->termsLanguages
+ $this->languageNameLookup
);
}
@@ -614,7 +609,7 @@
* @return MonolingualHtmlFormatter
*/
private function newMonolingualHtmlFormatter( FormatterOptions $options
) {
- return new MonolingualHtmlFormatter( $options,
$this->monolingualTextLanguages );
+ return new MonolingualHtmlFormatter( $options,
$this->languageNameLookup );
}
/**
diff --git a/lib/includes/modules/SitesModule.php
b/lib/includes/modules/SitesModule.php
index 6f0b549..3fcac18 100644
--- a/lib/includes/modules/SitesModule.php
+++ b/lib/includes/modules/SitesModule.php
@@ -7,6 +7,7 @@
use Site;
use SiteSQLStore;
use Xml;
+use Wikibase\Lib\LanguageNameLookup;
/**
*
@@ -70,6 +71,7 @@
$groups = $this->getSiteLinkGroups();
$specialGroups = $this->getSpecialSiteLinkGroups();
+ $languageNameLookup = new LanguageNameLookup();
/**
* @var MediaWikiSite $site
@@ -88,7 +90,7 @@
$languageName = $languageNameMsg->exists() ?
$languageNameMsg->parse() : $site->getGlobalId();
$groupName = 'special';
} else {
- $languageName = Utils::fetchLanguageName(
$site->getLanguageCode() );
+ $languageName = $languageNameLookup->getName(
$site->getLanguageCode() );
$groupName = $group;
}
$globalId = $site->getGlobalId();
diff --git a/lib/tests/phpunit/LanguageFallbackChainFactoryTest.php
b/lib/tests/phpunit/LanguageFallbackChainFactoryTest.php
index c20e84c..4874e3d 100644
--- a/lib/tests/phpunit/LanguageFallbackChainFactoryTest.php
+++ b/lib/tests/phpunit/LanguageFallbackChainFactoryTest.php
@@ -14,7 +14,6 @@
*
* @group Wikibase
* @group WikibaseLib
- * @group WikibaseUtils
*
* @licence GNU GPL v2+
* @author Liangent
diff --git a/lib/tests/phpunit/LanguageFallbackChainTest.php
b/lib/tests/phpunit/LanguageFallbackChainTest.php
index ed845eb..a8cea58 100644
--- a/lib/tests/phpunit/LanguageFallbackChainTest.php
+++ b/lib/tests/phpunit/LanguageFallbackChainTest.php
@@ -12,7 +12,6 @@
*
* @group Wikibase
* @group WikibaseLib
- * @group WikibaseUtils
*
* @licence GNU GPL v2+
* @author Liangent
diff --git a/lib/tests/phpunit/LanguageNameLookupTest.php
b/lib/tests/phpunit/LanguageNameLookupTest.php
new file mode 100644
index 0000000..ba69536
--- /dev/null
+++ b/lib/tests/phpunit/LanguageNameLookupTest.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Wikibase\Lib\Test;
+
+use PHPUnit_Framework_TestCase;
+use Wikibase\Lib\LanguageNameLookup;
+
+/**
+ * @covers Wikibase\Lib\LanguageNameLookup
+ *
+ * @group WikibaseLib
+ * @group Wikibase
+ *
+ * @license GNU GPL v2+
+ * @author John Erling Blad < [email protected] >
+ * @author Tobias Gritschacher
+ * @author Jeroen De Dauw < [email protected] >
+ * @author Marius Hoch < [email protected] >
+ */
+class LanguageNameLookupTest extends PHPUnit_Framework_TestCase {
+
+ public function getNameProvider() {
+ return array(
+ array( // #0
+ 'en',
+ null,
+ 'English'
+ ),
+ array( // #1
+ 'de',
+ null,
+ 'Deutsch'
+ ),
+ array( // #2
+ 'en',
+ 'de',
+ 'Englisch'
+ ),
+ array( // #3
+ 'de',
+ 'en',
+ 'German'
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider getNameProvider
+ */
+ public function testGetName( $lang, $in, $expected ) {
+ if ( $in !== null && !defined( 'CLDR_VERSION' ) ) {
+ $this->markTestSkipped( 'CLDR extension required for
full language name support' );
+ }
+
+ $languageNameLookup = new LanguageNameLookup();
+ $name = $languageNameLookup->getName( $lang, $in );
+ $this->assertSame( $expected, $name );
+ }
+
+}
diff --git a/lib/tests/phpunit/UtilsTest.php b/lib/tests/phpunit/UtilsTest.php
deleted file mode 100644
index 62aee38..0000000
--- a/lib/tests/phpunit/UtilsTest.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-namespace Wikibase\Test;
-
-use Wikibase\Utils;
-
-/**
- * @covers Wikibase\Utils
- *
- * @group WikibaseLib
- * @group Wikibase
- * @group WikibaseUtils
- *
- * @licence GNU GPL v2+
- * @author John Erling Blad < [email protected] >
- * @author Tobias Gritschacher
- * @author Jeroen De Dauw < [email protected] >
- */
-class UtilsTest extends \MediaWikiTestCase {
-
- public function provideFetchLanguageName() {
- return array(
- array( // #0
- 'en',
- null,
- 'English'
- ),
- array( // #1
- 'de',
- null,
- 'Deutsch'
- ),
- array( // #2
- 'en',
- 'de',
- 'Englisch'
- ),
- array( // #3
- 'de',
- 'en',
- 'German'
- ),
- );
- }
-
- /**
- * @dataProvider provideFetchLanguageName
- */
- public function testFetchLanguageName( $lang, $in, $expected ) {
- if ( $in !== null && !defined('CLDR_VERSION') ) {
- $this->markTestSkipped( "CLDR extension required for
full language name support" );
- }
-
- $name = Utils::fetchLanguageName( $lang, $in );
- $this->assertEquals( $expected, $name );
- }
-
-}
diff --git
a/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterFactoryTest.php
b/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterFactoryTest.php
index 4eba408..cd9d0e6 100644
--- a/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterFactoryTest.php
+++ b/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterFactoryTest.php
@@ -34,7 +34,7 @@
return new EntityIdHtmlLinkFormatterFactory(
$labelLookupFactory,
$titleLookup,
- $this->getMock( 'Wikibase\Lib\ContentLanguages' )
+ $this->getMock( 'Wikibase\Lib\LanguageNameLookup' )
);
}
diff --git a/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterTest.php
b/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterTest.php
index 1902170..bc97149 100644
--- a/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterTest.php
+++ b/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterTest.php
@@ -122,8 +122,8 @@
$entityTitleLookup = $this->newEntityTitleLookup( $exists );
- $termsLanguages = $this->getMock(
'Wikibase\Lib\ContentLanguages' );
- $termsLanguages->expects( $this->any() )
+ $languageNameLookup = $this->getMock(
'Wikibase\Lib\LanguageNameLookup' );
+ $languageNameLookup->expects( $this->any() )
->method( 'getName' )
->will( $this->returnCallback( function( $languageCode
) {
$names = array(
@@ -140,7 +140,7 @@
$options,
$labelLookup,
$entityTitleLookup,
- $termsLanguages
+ $languageNameLookup
);
return $entityIdHtmlLinkFormatter;
diff --git a/lib/tests/phpunit/formatters/MonolingualHtmlFormatterTest.php
b/lib/tests/phpunit/formatters/MonolingualHtmlFormatterTest.php
index ea67480..ab7b8b7 100644
--- a/lib/tests/phpunit/formatters/MonolingualHtmlFormatterTest.php
+++ b/lib/tests/phpunit/formatters/MonolingualHtmlFormatterTest.php
@@ -24,7 +24,7 @@
* @dataProvider monolingualHtmlFormatProvider
*/
public function testFormat( $value, $options, $pattern, $not = '' ) {
- $contentLanguages = $this->getMock(
'Wikibase\Lib\ContentLanguages' );
+ $contentLanguages = $this->getMock(
'Wikibase\Lib\LanguageNameLookup' );
$contentLanguages->expects( $this->any() )
->method( 'getName' )
->will( $this->returnValue( 'Deutsch' ));
diff --git a/lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
b/lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
index 66c712a..455f918 100644
--- a/lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
+++ b/lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
@@ -67,8 +67,7 @@
$valueFormatterBuilders = new WikibaseValueFormatterBuilders(
$lang,
new FormatterLabelLookupFactory( $termLookup ),
- $this->getMock( 'Wikibase\Lib\ContentLanguages' ),
- $this->getMock( 'Wikibase\Lib\ContentLanguages' )
+ $this->getMock( 'Wikibase\Lib\LanguageNameLookup' )
);
return new WikibaseSnakFormatterBuilders(
$valueFormatterBuilders, $typeLookup, $typeFactory );
diff --git
a/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
b/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
index d40776d..1fd9a25 100644
--- a/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
+++ b/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
@@ -73,16 +73,15 @@
);
} ) );
- $contentLanguages = $this->getMock(
'Wikibase\Lib\ContentLanguages' );
- $contentLanguages->expects( $this->any() )
+ $languageNameLookup = $this->getMock(
'Wikibase\Lib\LanguageNameLookup' );
+ $languageNameLookup->expects( $this->any() )
->method( 'getName' )
->will( $this->returnValue( 'Deutsch' ));
return new WikibaseValueFormatterBuilders(
Language::factory( 'en' ),
new FormatterLabelLookupFactory( $termLookup ),
- $contentLanguages,
- $contentLanguages,
+ $languageNameLookup,
$entityTitleLookup
);
}
diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index a058c3f..53a84df 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -25,6 +25,7 @@
use User;
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\EntityIdParsingException;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\Repo\BabelUserLanguageLookup;
use Wikibase\Repo\Content\EntityHandler;
use Wikibase\Repo\Hooks\OutputPageJsConfigHookHandler;
@@ -1011,7 +1012,8 @@
WikibaseRepo::getDefaultInstance()->getEntityIdParser(),
WikibaseRepo::getDefaultInstance()->getEntityRevisionLookup(),
$userLanguageLookup,
-
WikibaseRepo::getDefaultInstance()->getTermsLanguages()
+
WikibaseRepo::getDefaultInstance()->getTermsLanguages(),
+ new LanguageNameLookup()
);
$html = $injector->inject( $html, array( $expander,
'getHtmlForPlaceholder' ) );
diff --git a/repo/includes/View/EntityTermsView.php
b/repo/includes/View/EntityTermsView.php
index dfc6957..dbf54a7 100644
--- a/repo/includes/View/EntityTermsView.php
+++ b/repo/includes/View/EntityTermsView.php
@@ -8,7 +8,7 @@
use Wikibase\DataModel\Term\AliasGroupList;
use Wikibase\DataModel\Term\Fingerprint;
use Wikibase\DataModel\Term\TermList;
-use Wikibase\Lib\ContentLanguages;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\Template\TemplateFactory;
/**
@@ -40,26 +40,26 @@
private $languageCode;
/**
- * @var ContentLanguages
+ * @var LanguageNameLookup
*/
- private $termsLanguages;
+ private $languageNameLookup;
/**
* @param TemplateFactory $templateFactory
* @param SectionEditLinkGenerator|null $sectionEditLinkGenerator
- * @param ContentLanguages $termsLanguages
+ * @param LanguageNameLookup $languageNameLookup
* @param string $languageCode
*/
public function __construct(
TemplateFactory $templateFactory,
SectionEditLinkGenerator $sectionEditLinkGenerator = null,
- ContentLanguages $termsLanguages,
+ LanguageNameLookup $languageNameLookup,
$languageCode
) {
$this->sectionEditLinkGenerator = $sectionEditLinkGenerator;
$this->languageCode = $languageCode;
$this->templateFactory = $templateFactory;
- $this->termsLanguages = $termsLanguages;
+ $this->languageNameLookup = $languageNameLookup;
}
/**
@@ -222,7 +222,7 @@
is_null( $title )
? '#'
: $title->getLocalURL( array( 'setlang'
=> $languageCode ) ),
- htmlspecialchars(
$this->termsLanguages->getName( $languageCode, $this->languageCode ) )
+ htmlspecialchars(
$this->languageNameLookup->getName( $languageCode, $this->languageCode ) )
),
$this->templateFactory->render( 'wikibase-labelview',
$hasLabel ? '' : 'wb-empty',
diff --git a/repo/includes/View/EntityViewFactory.php
b/repo/includes/View/EntityViewFactory.php
index 4632110..5717126 100644
--- a/repo/includes/View/EntityViewFactory.php
+++ b/repo/includes/View/EntityViewFactory.php
@@ -9,7 +9,7 @@
use ValueFormatters\FormatterOptions;
use ValueFormatters\ValueFormatter;
use Wikibase\LanguageFallbackChain;
-use Wikibase\Lib\ContentLanguages;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\Lib\EntityIdFormatter;
use Wikibase\Lib\EntityIdFormatterFactory;
use Wikibase\Lib\OutputFormatSnakFormatterFactory;
@@ -77,9 +77,9 @@
private $templateFactory;
/**
- * @var ContentLanguages
+ * @var LanguageNameLookup
*/
- private $termsLanguages;
+ private $languageNameLookup;
/**
* @param EntityIdFormatterFactory $idFormatterFactory
@@ -88,7 +88,7 @@
* @param SiteStore $siteStore
* @param DataTypeFactory $dataTypeFactory
* @param TemplateFactory $templateFactory
- * @param ContentLanguages $termsLanguages
+ * @param LanguageNameLookup $languageNameLookup
* @param string[] $siteLinkGroups
* @param string[] $specialSiteLinkGroups
* @param string[] $badgeItems
@@ -100,7 +100,7 @@
SiteStore $siteStore,
DataTypeFactory $dataTypeFactory,
TemplateFactory $templateFactory,
- ContentLanguages $termsLanguages,
+ LanguageNameLookup $languageNameLookup,
array $siteLinkGroups,
array $specialSiteLinkGroups,
array $badgeItems
@@ -119,7 +119,7 @@
$this->sectionEditLinkGenerator = new SectionEditLinkGenerator(
$this->templateFactory
);
- $this->termsLanguages = $termsLanguages;
+ $this->languageNameLookup = $languageNameLookup;
}
/**
@@ -173,6 +173,7 @@
$this->siteStore->getSites(),
$this->sectionEditLinkGenerator,
$this->entityLookup,
+ $this->languageNameLookup,
$this->badgeItems,
$this->specialSiteLinkGroups,
$language->getCode()
@@ -243,7 +244,7 @@
return new EntityTermsView(
$this->templateFactory,
$this->sectionEditLinkGenerator,
- $this->termsLanguages,
+ $this->languageNameLookup,
$languageCode
);
}
diff --git a/repo/includes/View/EntityViewPlaceholderExpander.php
b/repo/includes/View/EntityViewPlaceholderExpander.php
index c779878..71ec0ec 100644
--- a/repo/includes/View/EntityViewPlaceholderExpander.php
+++ b/repo/includes/View/EntityViewPlaceholderExpander.php
@@ -11,6 +11,7 @@
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\EntityIdParser;
use Wikibase\Lib\ContentLanguages;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\Lib\Store\EntityRevisionLookup;
use Wikibase\Lib\Store\StorageException;
use Wikibase\Lib\UserLanguageLookup;
@@ -80,6 +81,11 @@
private $termsLanguages;
/**
+ * @var LanguageNameLookup
+ */
+ private $languageNameLookup;
+
+ /**
* @param TemplateFactory $templateFactory
* @param Title $targetPage the page for which this expander is
supposed to handle expansion.
* @param User $user the current user
@@ -88,6 +94,7 @@
* @param EntityRevisionLookup $entityRevisionLookup
* @param UserLanguageLookup $userLanguageLookup
* @param ContentLanguages $termsLanguages
+ * @param LanguageNameLookup $languageNameLookup
*/
public function __construct(
TemplateFactory $templateFactory,
@@ -97,7 +104,8 @@
EntityIdParser $entityIdParser,
EntityRevisionLookup $entityRevisionLookup,
UserLanguageLookup $userLanguageLookup,
- ContentLanguages $termsLanguages
+ ContentLanguages $termsLanguages,
+ LanguageNameLookup $languageNameLookup
) {
$this->targetPage = $targetPage;
$this->user = $user;
@@ -107,6 +115,7 @@
$this->userLanguageLookup = $userLanguageLookup;
$this->templateFactory = $templateFactory;
$this->termsLanguages = $termsLanguages;
+ $this->languageNameLookup = $languageNameLookup;
}
/**
@@ -250,7 +259,7 @@
$entityTermsView = new EntityTermsView(
$this->templateFactory,
null,
- $this->termsLanguages,
+ $this->languageNameLookup,
$this->uiLanguage->getCode()
);
$html = $entityTermsView->getEntityTermsForLanguageListView(
diff --git a/repo/includes/View/SiteLinksView.php
b/repo/includes/View/SiteLinksView.php
index 0360a95..e7d0aac 100644
--- a/repo/includes/View/SiteLinksView.php
+++ b/repo/includes/View/SiteLinksView.php
@@ -11,8 +11,8 @@
use Wikibase\DataModel\SiteLink;
use Wikibase\DataModel\Term\FingerprintProvider;
use Wikibase\Lib\Store\EntityLookup;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\Template\TemplateFactory;
-use Wikibase\Utils;
/**
* Creates views for lists of site links.
@@ -46,6 +46,11 @@
private $entityLookup;
/**
+ * @var LanguageNameLookup
+ */
+ private $languageNameLookup;
+
+ /**
* @var string[]
*/
private $badgeItems;
@@ -65,6 +70,7 @@
* @param SiteList $sites
* @param SectionEditLinkGenerator $sectionEditLinkGenerator
* @param EntityLookup $entityLookup
+ * @param LanguageNameLookup $languageNameLookup
* @param string[] $badgeItems
* @param string[] $specialSiteLinkGroups
* @param string $languageCode
@@ -74,6 +80,7 @@
SiteList $sites,
SectionEditLinkGenerator $sectionEditLinkGenerator,
EntityLookup $entityLookup,
+ LanguageNameLookup $languageNameLookup,
array $badgeItems,
array $specialSiteLinkGroups,
$languageCode
@@ -85,6 +92,7 @@
$this->specialSiteLinkGroups = $specialSiteLinkGroups;
$this->languageCode = $languageCode;
$this->templateFactory = $templateFactory;
+ $this->languageNameLookup = $languageNameLookup;
}
/**
@@ -257,7 +265,7 @@
$siteName = $siteNameMsg->exists() ?
$siteNameMsg->parse() : $siteId;
} else {
// TODO: get an actual site name rather then just the
language
- $siteName = htmlspecialchars( Utils::fetchLanguageName(
$languageCode ) );
+ $siteName = htmlspecialchars(
$this->languageNameLookup->getName( $languageCode ) );
}
// TODO: for non-JS, also set the dir attribute on the link
cell;
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 54a0ec8..ae25427 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -37,6 +37,7 @@
use Wikibase\Lib\EntityIdLinkFormatter;
use Wikibase\Lib\EntityRetrievingDataTypeLookup;
use Wikibase\Lib\FormatterLabelLookupFactory;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\Lib\Localizer\DispatchingExceptionLocalizer;
use Wikibase\Lib\Localizer\ExceptionLocalizer;
use Wikibase\Lib\Localizer\GenericExceptionLocalizer;
@@ -173,12 +174,12 @@
private $entityNamespaceLookup = null;
/**
- * @var TermLookup
+ * @var TermLookup|null
*/
private $termLookup;
/**
- * @var ContentLanguages
+ * @var ContentLanguages|null
*/
private $monolingualTextLanguages = null;
@@ -545,8 +546,7 @@
return new WikibaseValueFormatterBuilders(
$wgContLang,
new FormatterLabelLookupFactory( $termLookup ),
- $this->getMonolingualTextLanguages(),
- $this->getTermsLanguages(),
+ new LanguageNameLookup(),
$this->getEntityTitleLookup()
);
}
@@ -1003,7 +1003,7 @@
return new EntityIdHtmlLinkFormatterFactory(
new FormatterLabelLookupFactory( $this->getTermLookup()
),
$this->getEntityTitleLookup(),
- $this->getTermsLanguages()
+ new LanguageNameLookup()
);
}
@@ -1019,7 +1019,7 @@
$this->getSiteStore(),
$this->getDataTypeFactory(),
new TemplateFactory(
TemplateRegistry::getDefaultInstance() ),
- $this->getTermsLanguages(),
+ new LanguageNameLookup(),
$this->getSettings()->getSetting( 'siteLinkGroups' ),
$this->getSettings()->getSetting(
'specialSiteLinkGroups' ),
$this->getSettings()->getSetting( 'badgeItems' )
diff --git a/repo/includes/specials/SpecialItemDisambiguation.php
b/repo/includes/specials/SpecialItemDisambiguation.php
index 63310c8..1e9c808 100644
--- a/repo/includes/specials/SpecialItemDisambiguation.php
+++ b/repo/includes/specials/SpecialItemDisambiguation.php
@@ -8,7 +8,7 @@
use ValueFormatters\ValueFormatter;
use Wikibase\DataModel\Entity\Item;
use Wikibase\ItemDisambiguation;
-use Wikibase\Lib\ContentLanguages;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\Lib\EntityIdHtmlLinkFormatter;
use Wikibase\Lib\Store\EntityLookup;
use Wikibase\Lib\Store\EntityRetrievingTermLookup;
@@ -46,9 +46,9 @@
private $entityTitleLookup;
/**
- * @var ContentLanguages
+ * @var LanguageNameLookup
*/
- private $termLanguages;
+ private $languageNameLookup;
/**
* @var int
@@ -67,7 +67,7 @@
WikibaseRepo::getDefaultInstance()->getStore()->getTermIndex(),
WikibaseRepo::getDefaultInstance()->getEntityLookup(),
WikibaseRepo::getDefaultInstance()->getEntityTitleLookup(),
- WikibaseRepo::getDefaultInstance()->getTermsLanguages()
+ new LanguageNameLookup()
);
//@todo: make this configurable
@@ -82,12 +82,12 @@
TermIndex $termIndex,
EntityLookup $entityLookup,
EntityTitleLookup $entityTitleLookup,
- ContentLanguages $termsLanguages
+ LanguageNameLookup $languageNameLookup
) {
$this->termIndex = $termIndex;
$this->entityLookup = $entityLookup;
$this->entityTitleLookup = $entityTitleLookup;
- $this->termLanguages = $termsLanguages;
+ $this->languageNameLookup = $languageNameLookup;
}
/**
@@ -186,7 +186,7 @@
$formatterOptions,
$labelLookup,
$this->entityTitleLookup,
- $this->termLanguages
+ $this->languageNameLookup
);
$disambiguationList = new ItemDisambiguation(
diff --git a/repo/tests/phpunit/includes/View/EntityTermsViewTest.php
b/repo/tests/phpunit/includes/View/EntityTermsViewTest.php
index 6cd06d4..43a926f 100644
--- a/repo/tests/phpunit/includes/View/EntityTermsViewTest.php
+++ b/repo/tests/phpunit/includes/View/EntityTermsViewTest.php
@@ -48,7 +48,7 @@
return new EntityTermsView(
$templateFactory,
new SectionEditLinkGenerator( $templateFactory ),
- $this->getMock( 'Wikibase\Lib\ContentLanguages' ),
+ $this->getMock( 'Wikibase\Lib\LanguageNameLookup' ),
$languageCode
);
}
diff --git a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
index 73581a0..427dad9 100644
--- a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
+++ b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
@@ -59,7 +59,7 @@
$this->getSiteStore(),
$this->getMock( 'DataTypes\DataTypeFactory' ),
new TemplateFactory(
TemplateRegistry::getDefaultInstance() ),
- $this->getMock( 'Wikibase\Lib\ContentLanguages' ),
+ $this->getMock( 'Wikibase\Lib\LanguageNameLookup' ),
array(),
array(),
array()
diff --git
a/repo/tests/phpunit/includes/View/EntityViewPlaceholderExpanderTest.php
b/repo/tests/phpunit/includes/View/EntityViewPlaceholderExpanderTest.php
index c15787c..cc4c9c7 100644
--- a/repo/tests/phpunit/includes/View/EntityViewPlaceholderExpanderTest.php
+++ b/repo/tests/phpunit/includes/View/EntityViewPlaceholderExpanderTest.php
@@ -9,6 +9,7 @@
use Wikibase\EntityRevision;
use Wikibase\Lib\Store\EntityRevisionLookup;
use Wikibase\Lib\Store\StorageException;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\Lib\WikibaseContentLanguages;
use Wikibase\Repo\View\EntityViewPlaceholderExpander;
use Wikibase\Template\TemplateFactory;
@@ -62,7 +63,8 @@
$idParser,
$entityRevisionLookup,
$userLanguages,
- new WikibaseContentLanguages()
+ new WikibaseContentLanguages(),
+ new LanguageNameLookup()
);
}
diff --git a/repo/tests/phpunit/includes/View/SiteLinksViewTest.php
b/repo/tests/phpunit/includes/View/SiteLinksViewTest.php
index 115144b..a6fcea9 100644
--- a/repo/tests/phpunit/includes/View/SiteLinksViewTest.php
+++ b/repo/tests/phpunit/includes/View/SiteLinksViewTest.php
@@ -8,6 +8,7 @@
use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\SiteLink;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\Lib\Store\EntityLookup;
use Wikibase\Repo\View\SectionEditLinkGenerator;
use Wikibase\Repo\View\SiteLinksView;
@@ -189,6 +190,7 @@
$this->newSiteList(),
$this->getSectionEditLinkGeneratorMock(),
$this->getEntityLookupMock(),
+ new LanguageNameLookup(),
array(
'Q42' => 'wb-badge-featuredarticle',
'Q12' => 'wb-badge-goodarticle'
diff --git a/repo/tests/phpunit/includes/WikibaseRepoTest.php
b/repo/tests/phpunit/includes/WikibaseRepoTest.php
index 27760c0..e47a2c7 100644
--- a/repo/tests/phpunit/includes/WikibaseRepoTest.php
+++ b/repo/tests/phpunit/includes/WikibaseRepoTest.php
@@ -253,4 +253,9 @@
$this->assertSame( $service, $repo->getTermLookup(),
'TermBuffer and TermLookup should be the same object' );
}
+ public function testGetTermsLanguages() {
+ $service = $this->getWikibaseRepo()->getTermsLanguages();
+ $this->assertInstanceOf( 'Wikibase\Lib\ContentLanguages',
$service );
+ }
+
}
diff --git
a/repo/tests/phpunit/includes/specials/SpecialItemDisambiguationTest.php
b/repo/tests/phpunit/includes/specials/SpecialItemDisambiguationTest.php
index 95e3c72..4e717e4 100644
--- a/repo/tests/phpunit/includes/specials/SpecialItemDisambiguationTest.php
+++ b/repo/tests/phpunit/includes/specials/SpecialItemDisambiguationTest.php
@@ -100,10 +100,6 @@
return $repo;
}
- private function getTermsLanguages() {
- return $this->getMock( 'Wikibase\Lib\ContentLanguages' );
- }
-
protected function newSpecialPage() {
$page = new SpecialItemDisambiguation();
@@ -111,7 +107,7 @@
$this->getTermIndex(),
$this->getEntityLookup(),
$this->getEntityTitleLookup(),
- $this->getTermsLanguages()
+ $this->getMock( 'Wikibase\Lib\LanguageNameLookup' )
);
return $page;
--
To view, visit https://gerrit.wikimedia.org/r/190631
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iec9922875489e48749bc096d8c992f91d6991644
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits