diff --git a/includes/SemanticData.php b/includes/SemanticData.php index 14f71fa1b9..eb679ebcfe 100644 --- a/includes/SemanticData.php +++ b/includes/SemanticData.php @@ -638,6 +638,7 @@ public function findSubSemanticData( $subobjectName ) { */ public function addSubSemanticData( SemanticData $semanticData ) { + $semanticData->setLastModified( $this->getLastModified() ); $this->hash = null; if ( $this->subContainerDepthCounter > $this->subContainerMaxDepth ) { diff --git a/includes/datavalues/SMW_DataValue.php b/includes/datavalues/SMW_DataValue.php index 5913518750..2d44a9513e 100644 --- a/includes/datavalues/SMW_DataValue.php +++ b/includes/datavalues/SMW_DataValue.php @@ -101,6 +101,11 @@ abstract class SMWDataValue { */ protected $m_outformat = false; + /** + * @var string + */ + private $languageCode = ''; + /** * Used to control the addition of the standard search link. * @var boolean @@ -269,6 +274,24 @@ public function getProperty() { return $this->m_property; } + /** + * @since 2.4 + * + * @param string $languageCode + */ + public function setLanguageCode( $languageCode ) { + $this->languageCode = $languageCode; + } + + /** + * @since 2.4 + * + * @return string + */ + public function getLanguageCode() { + return $this->languageCode; + } + /** * Specify the wiki page to which this value refers. This information is * used to parse user values such as "#subsection" which only make sense diff --git a/includes/specials/SMW_SpecialBrowse.php b/includes/specials/SMW_SpecialBrowse.php index 28bca60b81..2cbd10078d 100644 --- a/includes/specials/SMW_SpecialBrowse.php +++ b/includes/specials/SMW_SpecialBrowse.php @@ -2,6 +2,7 @@ use SMW\DIProperty; use SMW\UrlEncoder; +use SMW\Localizer; /** * @ingroup SMWSpecialPage @@ -251,6 +252,11 @@ private function displayData( SMWSemanticData $data, $left = true, $incoming = f private function displayValue( SMWPropertyValue $property, SMWDataValue $dataValue, $incoming ) { $linker = smwfGetLinker(); + // Allow the DV formatter to access a specific language code + $dataValue->setLanguageCode( + Localizer::getInstance()->getUserLanguage()->getCode() + ); + $html = $dataValue->getLongHTMLText( $linker ); if ( $dataValue->getTypeID() === '_wpg' || $dataValue->getTypeID() === '__sob' ) { diff --git a/includes/storage/SMW_ResultArray.php b/includes/storage/SMW_ResultArray.php index 07bbde64b7..9ec5af8390 100644 --- a/includes/storage/SMW_ResultArray.php +++ b/includes/storage/SMW_ResultArray.php @@ -178,6 +178,12 @@ public function getNextDataValue() { if ( $this->mPrintRequest->getOutputFormat() ) { $dv->setOutputFormat( $this->mPrintRequest->getOutputFormat() ); } + + // Allow the DV formatter to access a specific language code + $dv->setLanguageCode( + \SMW\Localizer::getInstance()->getUserLanguage()->getCode() + ); + return $dv; } diff --git a/src/DataValues/ValueFormatters/TimeValueFormatter.php b/src/DataValues/ValueFormatters/TimeValueFormatter.php index 116a85977a..e3856e5116 100644 --- a/src/DataValues/ValueFormatters/TimeValueFormatter.php +++ b/src/DataValues/ValueFormatters/TimeValueFormatter.php @@ -164,7 +164,10 @@ public function getMediaWikiDate() { */ public function getCaptionFromDataItem( DITime $dataItem ) { - $extraneousLanguage = Localizer::getInstance()->getExtraneousLanguage(); + // If the language code is empty then the content language code is used + $extraneousLanguage = Localizer::getInstance()->getExtraneousLanguage( + $this->dataValue->getLanguageCode() + ); // https://en.wikipedia.org/wiki/Anno_Domini // "...placing the "AD" abbreviation before the year number ... BC is diff --git a/src/Localizer.php b/src/Localizer.php index eb7eab2e28..c473517464 100644 --- a/src/Localizer.php +++ b/src/Localizer.php @@ -74,10 +74,17 @@ public function getUserLanguage() { /** * @since 2.4 * + * @param string $languageCode + * * @return ExtraneousLanguage */ - public function getExtraneousLanguage() { - return $GLOBALS['smwgContLang']; + public function getExtraneousLanguage( $languageCode = '' ) { + + if ( $languageCode === '' ) { + $languageCode = $this->getContentLanguage()->getCode(); + } + + return ExtraneousLanguage::getInstance()->fetchByLanguageCode( $languageCode ); } /** diff --git a/tests/phpunit/Unit/LocalizerTest.php b/tests/phpunit/Unit/LocalizerTest.php index fa21f7a875..4b994e32b5 100644 --- a/tests/phpunit/Unit/LocalizerTest.php +++ b/tests/phpunit/Unit/LocalizerTest.php @@ -161,4 +161,19 @@ public function testCanNotGetLanguageCodeOnMissingLanguageCode() { ); } + public function testExtraneousLanguage() { + + $this->assertInstanceOf( + '\SMW\ExtraneousLanguage', + Localizer::getInstance()->getExtraneousLanguage() + ); + + $this->assertInstanceOf( + '\SMW\ExtraneousLanguage', + Localizer::getInstance()->getExtraneousLanguage( 'en' ) + ); + + Localizer::clear(); + } + }