Daniel Werner has uploaded a new change for review.

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


Change subject: Make use of Time data value formatter in EntityView
......................................................................

Make use of Time data value formatter in EntityView

Removes the special treatment for displaying instances of \DataValues\TimeValue 
in EntityView.

Requires Ib069a01 in DataValues repo.

Change-Id: I72bd2c49958a236028d8a5374d2fc64553955a97
---
M repo/includes/EntityView.php
1 file changed, 13 insertions(+), 19 deletions(-)


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

diff --git a/repo/includes/EntityView.php b/repo/includes/EntityView.php
index 803bd6c..370d40e 100644
--- a/repo/includes/EntityView.php
+++ b/repo/includes/EntityView.php
@@ -607,27 +607,21 @@
                if ( $claim->getMainSnak()->getType() === 'value' ) {
                        $value = $claim->getMainSnak()->getDataValue();
 
-                       // TODO: Bad to have a switch for different data types 
here, implement a formatter!
-                       if( $value instanceof \DataValues\TimeValue ) {
-                               $value = $value->getTime() . ' (' . 
$value->getCalendarModel() . ')';
+                       $valueFormatter = $this->valueFormatters->newFormatter(
+                               $value->getType(), $valueFormatterOptions
+                       );
+
+                       if( $valueFormatter !== null ) {
+                               $value = $valueFormatter->format( $value );
                        } else {
-                               // Proper way, use value formatter:
-                               $valueFormatter = 
$this->valueFormatters->newFormatter(
-                                       $value->getType(), 
$valueFormatterOptions
-                               );
+                               // If value representation is a string, just 
display that one as a
+                               // fallback for values not having a formatter 
implemented yet.
+                               $value = $value->getValue();
 
-                               if( $valueFormatter !== null ) {
-                                       $value = $valueFormatter->format( 
$value );
-                               } else {
-                                       // If value representation is a string, 
just display that one as a
-                                       // fallback for values not having a 
formatter implemented yet.
-                                       $value = $value->getValue();
-
-                                       if( !is_string( $value ) ) {
-                                               // TODO: don't fail here, 
display a message in the UI instead
-                                               throw new MWException( 
'Displaying of values of type "'
-                                                       . $value->getType() . 
'" not supported yet' );
-                                       }
+                               if( !is_string( $value ) ) {
+                                       // TODO: don't fail here, display a 
message in the UI instead
+                                       throw new MWException( 'Displaying of 
values of type "'
+                                               . $value->getType() . '" not 
supported yet' );
                                }
                        }
                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I72bd2c49958a236028d8a5374d2fc64553955a97
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to