Aude has uploaded a new change for review.

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


Change subject: extend ValueFormatterBase for MwIsoTimeFormatter
......................................................................

extend ValueFormatterBase for MwIsoTimeFormatter

- allows the formatter to be used in a consistent manner as other formatters

Change-Id: I52541c24044290451255441b991ef347f3e66d96
---
M lib/includes/formatters/MwTimeIsoFormatter.php
M lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
M repo/includes/EntityView.php
3 files changed, 47 insertions(+), 10 deletions(-)


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

diff --git a/lib/includes/formatters/MwTimeIsoFormatter.php 
b/lib/includes/formatters/MwTimeIsoFormatter.php
index e457cb8..5a77b30 100644
--- a/lib/includes/formatters/MwTimeIsoFormatter.php
+++ b/lib/includes/formatters/MwTimeIsoFormatter.php
@@ -2,7 +2,11 @@
 
 namespace Wikibase\Lib;
 
-use \ValueFormatters\TimeIsoFormatter;
+use Language;
+use ValueFormatters\FormatterOptions;
+use ValueFormatters\TimeIsoFormatter;
+use ValueFormatters\ValueFormatter;
+use ValueFormatters\ValueFormatterBase;
 
 /**
  * This program is free software; you can redistribute it and/or modify
@@ -28,16 +32,38 @@
  * @licence GNU GPL v2+
  * @author H. Snater < mediaw...@snater.com >
  */
-class MwTimeIsoFormatter implements TimeIsoFormatter {
+class MwTimeIsoFormatter extends ValueFormatterBase implements 
TimeIsoFormatter {
 
        /**
-        * MediaWiki language object.
-        * @var \Language
+        * MediaWiki language object.
+        * @var Language
         */
-       private $language;
+       protected $language;
 
-       public function __construct( $language ) {
-               $this->language = $language;
+       /**
+        * @param FormatterOptions $options
+        * @param Language $language
+        */
+       public function __construct( FormatterOptions $options, Language 
$language = null ) {
+               $this->options = $options;
+
+               $this->options->defaultOption( ValueFormatter::OPT_LANG, 'en' );
+
+               $this->language = ( $language !== null )
+                       ? $language
+                       : Language::factory( $this->options->getOption( 
ValueFormatter::OPT_LANG ) );
+
+               $this->options->setOption( ValueFormatter::OPT_LANG, 
$this->language->getCode() );
+       }
+
+       /**
+        * @see ValueFormatter::format
+        */
+       public function format( $value ) {
+               return $this->formatDate(
+                       $value->getTime(),
+                       $value->getPrecision()
+               );
        }
 
        /**
diff --git a/lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php 
b/lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
index 9ee2c08..0a7ca19 100644
--- a/lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
+++ b/lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
@@ -1,6 +1,8 @@
 <?php
-
 namespace ValueFormatters\Test;
+
+use ValueFormatters\ValueFormatter;
+use ValueFormatters\FormatterOptions;
 use Wikibase\Lib\MwTimeIsoFormatter;
 
 /**
@@ -97,7 +99,13 @@
         * @param integer $precision
         */
        public function testFormatDate( $expected, $extendedIsoString, 
$precision ) {
-               $isoFormatter = new MwTimeIsoFormatter( \Language::factory( 
'en' ) );
+               $langCode = 'en';
+               $options = new FormatterOptions( array(
+                       ValueFormatter::OPT_LANG => $langCode
+               ) );
+
+               $isoFormatter = new MwTimeIsoFormatter( $options, 
\Language::factory( $langCode ) );
+
                $this->assertEquals( $expected, $isoFormatter->formatDate( 
$extendedIsoString, $precision ) );
        }
 
diff --git a/repo/includes/EntityView.php b/repo/includes/EntityView.php
index 714d7e3..e3bb68c 100644
--- a/repo/includes/EntityView.php
+++ b/repo/includes/EntityView.php
@@ -624,7 +624,10 @@
                $valueFormatterOptions = new FormatterOptions( array(
                        ValueFormatter::OPT_LANG => $languageCode,
                        Lib\EntityIdFormatter::OPT_PREFIX_MAP => 
$entitiesPrefixMap,
-                       TimeFormatter::OPT_TIME_ISO_FORMATTER => new 
MwTimeIsoFormatter( \Language::factory( $languageCode ) ),
+                       TimeFormatter::OPT_TIME_ISO_FORMATTER => new 
MwTimeIsoFormatter(
+                               new FormatterOptions(),
+                               \Language::factory( $languageCode )
+                       ),
                ) );
 
                // TODO: display a "placeholder" message for novalue/somevalue 
snak

-- 
To view, visit https://gerrit.wikimedia.org/r/80968
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I52541c24044290451255441b991ef347f3e66d96
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <aude.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to