[MediaWiki-commits] [Gerrit] Resolve language confusion in terms view - change (mediawiki...Wikibase)

2016-01-19 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Resolve language confusion in terms view
..


Resolve language confusion in terms view

There is quite some confusion going on here.

Note that this class does have 3 public methods.

When requesting HTML via getHtml() (this is for the label,
description and aliases on top of the page) and getTitleHtml() the
$this->languageCode is *not* the interface language but the language
of the requested term. Messages use wfMessage(), which defaults to
$wgLang, which is set to qqx in the test.

But when calling getEntityTermsForLanguageListView() the same
$this->languageCode property is misused as the interface language.

Luckily this is not an issue in production because
$this->languageCode is always set to the users interface language.

This also splits a test with a bad data provider (note the removed
$numberOfPlaceholders and substr_count) and adds a bunch of missing
tests and assertions.

Change-Id: I4270a15e8f3e516d154d1a4d1018a9760c5ba95d
---
M view/src/EntityTermsView.php
M view/tests/phpunit/EntityTermsViewTest.php
2 files changed, 58 insertions(+), 34 deletions(-)

Approvals:
  Adrian Lang: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/view/src/EntityTermsView.php b/view/src/EntityTermsView.php
index a23ed17..a27f852 100644
--- a/view/src/EntityTermsView.php
+++ b/view/src/EntityTermsView.php
@@ -35,7 +35,7 @@
private $sectionEditLinkGenerator;
 
/**
-* @var string
+* @var string Language of the terms in the title and header section.
 */
private $languageCode;
 
@@ -48,7 +48,8 @@
 * @param TemplateFactory $templateFactory
 * @param EditSectionGenerator|null $sectionEditLinkGenerator
 * @param LanguageNameLookup $languageNameLookup
-* @param string $languageCode
+* @param string $languageCode Desired language of the label, 
description and aliases in the
+*  title and header section. Not necessarily identical to the 
interface language.
 */
public function __construct(
TemplateFactory $templateFactory,
@@ -207,7 +208,9 @@
$languageCode,
Title $title = null
) {
-   $languageName = $this->languageNameLookup->getName( 
$languageCode, $this->languageCode );
+   global $wgLang;
+
+   $languageName = $this->languageNameLookup->getName( 
$languageCode, $wgLang->getCode() );
$labels = $fingerprint->getLabels();
$descriptions = $fingerprint->getDescriptions();
$hasLabel = $labels->hasTermForLanguage( $languageCode );
@@ -299,7 +302,7 @@
 * @return Message
 */
private function msg( $key ) {
-   return wfMessage( $key )->inLanguage( $this->languageCode );
+   return wfMessage( $key );
}
 
 }
diff --git a/view/tests/phpunit/EntityTermsViewTest.php 
b/view/tests/phpunit/EntityTermsViewTest.php
index 9f7e7d3..6175784 100644
--- a/view/tests/phpunit/EntityTermsViewTest.php
+++ b/view/tests/phpunit/EntityTermsViewTest.php
@@ -49,7 +49,9 @@
$languageNameLookup = $this->getMock( 
'Wikibase\Lib\LanguageNameLookup' );
$languageNameLookup->expects( $this->exactly( 
$languageNameCalls ) )
->method( 'getName' )
-   ->will( $this->returnValue( '' ) );
+   ->will( $this->returnCallback( function( $languageCode, 
$inLanguage = null ) {
+   return 
"";
+   } ) );
 
return new EntityTermsView(
TemplateFactory::getDefaultInstance(),
@@ -110,30 +112,16 @@
$this->assertNotContains( 

[MediaWiki-commits] [Gerrit] Resolve language confusion in terms view - change (mediawiki...Wikibase)

2015-12-21 Thread WMDE
Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/260336

Change subject: Resolve language confusion in terms view
..

Resolve language confusion in terms view

There is quite some confusion going on here.

Note that this class does have 3 public methods.

When requesting HTML via getHtml() (this is for the label,
description and aliases on top of the page) and getTitleHtml() the
$this->languageCode is *not* the interface language but the language
of the requested term. Messages use wfMessage(), which defaults to
$wgLang, which is set to qqx in the test.

But when calling getEntityTermsForLanguageListView() the same
$this->languageCode property is misused as the interface language.

Luckily this is not an issue in production because
$this->languageCode is always set to the users interface language.

This also splits a test with a bad data provider (note the removed
$numberOfPlaceholders and substr_count) and adds a bunch of missing
tests and assertions.

Change-Id: I4270a15e8f3e516d154d1a4d1018a9760c5ba95d
---
M view/src/EntityTermsView.php
M view/tests/phpunit/EntityTermsViewTest.php
2 files changed, 69 insertions(+), 55 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/36/260336/1

diff --git a/view/src/EntityTermsView.php b/view/src/EntityTermsView.php
index 5344bc9..1ac6648 100644
--- a/view/src/EntityTermsView.php
+++ b/view/src/EntityTermsView.php
@@ -2,7 +2,6 @@
 
 namespace Wikibase\View;
 
-use Message;
 use Title;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Term\AliasGroupList;
@@ -35,20 +34,21 @@
private $sectionEditLinkGenerator;
 
/**
-* @var string
-*/
-   private $languageCode;
-
-   /**
 * @var LanguageNameLookup
 */
private $languageNameLookup;
 
/**
+* @var string Language of the terms in the title and header section.
+*/
+   private $languageCode;
+
+   /**
 * @param TemplateFactory $templateFactory
 * @param EditSectionGenerator|null $sectionEditLinkGenerator
 * @param LanguageNameLookup $languageNameLookup
-* @param string $languageCode
+* @param string $languageCode Desired language of the label, 
description and aliases in the
+*  title and header section. Not necessarily identical to the 
interface language.
 */
public function __construct(
TemplateFactory $templateFactory,
@@ -56,10 +56,10 @@
LanguageNameLookup $languageNameLookup,
$languageCode
) {
-   $this->sectionEditLinkGenerator = $sectionEditLinkGenerator;
-   $this->languageCode = $languageCode;
$this->templateFactory = $templateFactory;
+   $this->sectionEditLinkGenerator = $sectionEditLinkGenerator;
$this->languageNameLookup = $languageNameLookup;
+   $this->languageCode = $languageCode;
}
 
/**
@@ -187,10 +187,10 @@
}
 
return $this->templateFactory->render( 
'wikibase-entitytermsforlanguagelistview',
-   $this->msg( 
'wikibase-entitytermsforlanguagelistview-language' ),
-   $this->msg( 
'wikibase-entitytermsforlanguagelistview-label' ),
-   $this->msg( 
'wikibase-entitytermsforlanguagelistview-description' ),
-   $this->msg( 
'wikibase-entitytermsforlanguagelistview-aliases' ),
+   wfMessage( 
'wikibase-entitytermsforlanguagelistview-language' ),
+   wfMessage( 
'wikibase-entitytermsforlanguagelistview-label' ),
+   wfMessage( 
'wikibase-entitytermsforlanguagelistview-description' ),
+   wfMessage( 
'wikibase-entitytermsforlanguagelistview-aliases' ),
$entityTermsForLanguageViewsHtml
);
}
@@ -207,7 +207,9 @@
$languageCode,
Title $title = null
) {
-   $languageName = $this->languageNameLookup->getName( 
$languageCode, $this->languageCode );
+   global $wgLang;
+
+   $languageName = $this->languageNameLookup->getName( 
$languageCode, $wgLang->getCode() );
$labels = $fingerprint->getLabels();
$descriptions = $fingerprint->getDescriptions();
$hasLabel = $labels->hasTermForLanguage( $languageCode );
@@ -228,7 +230,7 @@
$hasLabel ? '' : 'wb-empty',
htmlspecialchars( $hasLabel
? $labels->getByLanguage( $languageCode 
)->getText()
-   : $this->msg( 'wikibase-label-empty' 
)->text()
+   : wfMessage(