jenkins-bot has submitted this change and it was merged.

Change subject: Show calendar names instead of URIs in diffs
......................................................................


Show calendar names instead of URIs in diffs

This patch changes the diff view to not show the calendar model URIs
any more, but the human readable names. The names are not translated
at the moment. The source is copied from TimeFormatter (it was also
untranslated there).

Change-Id: I72362590baa287eee5c90eb61044f89e79bd6011
---
M lib/includes/formatters/TimeDetailsFormatter.php
M lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
2 files changed, 32 insertions(+), 12 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/includes/formatters/TimeDetailsFormatter.php 
b/lib/includes/formatters/TimeDetailsFormatter.php
index 5e5a021..e5700fb 100644
--- a/lib/includes/formatters/TimeDetailsFormatter.php
+++ b/lib/includes/formatters/TimeDetailsFormatter.php
@@ -21,15 +21,17 @@
  */
 class TimeDetailsFormatter extends ValueFormatterBase {
 
+       const OPT_CALENDARNAMES = 'calendars';
+
        /**
         * @var MwTimeIsoFormatter
         */
-       protected $isoTimeFormatter;
+       private $isoTimeFormatter;
 
        /**
         * @var TimeFormatter
         */
-       protected $timeFormatter;
+       private $timeFormatter;
 
        /**
         * @param FormatterOptions $options
@@ -45,6 +47,11 @@
                }
 
                $this->timeFormatter = new TimeFormatter( $options );
+
+               $this->defaultOption( self::OPT_CALENDARNAMES, array(
+                       TimeFormatter::CALENDAR_GREGORIAN => 'Gregorian',
+                       TimeFormatter::CALENDAR_JULIAN => 'Julian',
+               ) );
        }
 
        /**
@@ -63,6 +70,12 @@
                        throw new InvalidArgumentException( 'Data value type 
mismatch. Expected an TimeValue.' );
                }
 
+               $calendarModel = $value->getCalendarModel();
+               $calendarNames = $this->getOption( self::OPT_CALENDARNAMES );
+               if ( array_key_exists( $calendarModel, $calendarNames ) ) {
+                       $calendarModel = $calendarNames[$calendarModel];
+               }
+
                $html = '';
                $html .= Html::element( 'h4',
                        array( 'class' => 'wb-details wb-time-details 
wb-time-rendered' ),
@@ -77,7 +90,7 @@
                $html .= $this->renderLabelValuePair( 'timezone',
                        htmlspecialchars( $value->getTimezone() ) );
                $html .= $this->renderLabelValuePair( 'calendar',
-                       htmlspecialchars( $value->getCalendarModel() ) );
+                       htmlspecialchars( $calendarModel ) );
                $html .= $this->renderLabelValuePair( 'precision',
                        htmlspecialchars( $value->getPrecision() ) );
 
@@ -95,7 +108,7 @@
         *
         * @return string HTML for the label/value pair
         */
-       protected function renderLabelValuePair( $fieldName, $valueHtml ) {
+       private function renderLabelValuePair( $fieldName, $valueHtml ) {
                $html = Html::openElement( 'tr' );
 
                $html .= Html::element( 'th', array( 'class' => 'wb-time-' . 
$fieldName ),
@@ -112,7 +125,7 @@
         *
         * @return Message
         */
-       protected function getFieldLabel( $fieldName ) {
+       private function getFieldLabel( $fieldName ) {
                $lang = $this->getOption( ValueFormatter::OPT_LANG );
 
                // Messages: wb-timedetails-amount, wb-timedetails-upperbound,
diff --git a/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php 
b/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
index f5847ea..04307a6 100644
--- a/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
+++ b/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
@@ -18,6 +18,7 @@
  *
  * @licence GNU GPL v2+
  * @author Daniel Kinzler
+ * @author Thiemo Mättig
  */
 class TimeDetailsFormatterTest extends \PHPUnit_Framework_TestCase {
 
@@ -38,19 +39,24 @@
 
                return array(
                        array(
-                               new TimeValue( '+00000002001-01-01T00:00:00Z', 
60, 0, 1, 10, TimeFormatter::CALENDAR_GREGORIAN ),
+                               new TimeValue( '+2001-01-01T00:00:00Z', 60, 0, 
1, 10, TimeFormatter::CALENDAR_GREGORIAN ),
                                $options,
                                '@' . implode( '.*',
                                        array(
                                                
'<h4[^<>]*>[^<>]*2001[^<>]*</h4>',
-                                               
'<td[^<>]*>[^<>]*\+00000002001-01-01T00:00:00Z[^<>]*</td>',
-                                               '<td[^<>]*>[^<>]*60[^<>]*</td>',
-                                               
'<td[^<>]*>[^<>]*.*Q1985727[^<>]*</td>',
-                                               '<td[^<>]*>[^<>]*10[^<>]*</td>',
-                                               '<td[^<>]*>[^<>]*0[^<>]*</td>',
-                                               '<td[^<>]*>[^<>]*1[^<>]*</td>',
+                                               
'<td[^<>]*>\+0*2001-01-01T00:00:00Z</td>',
+                                               '<td[^<>]*>60</td>',
+                                               '<td[^<>]*>Gregorian</td>',
+                                               '<td[^<>]*>10</td>',
+                                               '<td[^<>]*>0</td>',
+                                               '<td[^<>]*>1</td>',
                                        )
                                ) . '@s'
+                       ),
+                       array(
+                               new TimeValue( '+2001-01-01T00:00:00Z', 60, 0, 
1, 10, 'Stardate' ),
+                               $options,
+                               '@.*<td[^<>]*>Stardate</td>.*@s'
                        ),
                );
        }
@@ -62,4 +68,5 @@
                $this->setExpectedException( 'InvalidArgumentException' );
                $formatter->format( $value );
        }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I72362590baa287eee5c90eb61044f89e79bd6011
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to