[MediaWiki-commits] [Gerrit] ValueFormatter for Time DataValue - change (mediawiki...DataValues)
jenkins-bot has submitted this change and it was merged. Change subject: ValueFormatter for Time DataValue .. ValueFormatter for Time DataValue (bug 48937) Change-Id: I0dd02909834ce8b428daea86e8bd2bf87ba9a085 --- M ValueFormatters/ValueFormatters.classes.php M ValueFormatters/ValueFormatters.mw.php M ValueFormatters/ValueFormatters.php A ValueFormatters/includes/formatters/TimeFormatter.php A ValueFormatters/includes/formatters/TimeIsoFormatter.php A ValueFormatters/tests/phpunit/formatters/TimeFormatterTest.php 6 files changed, 284 insertions(+), 2 deletions(-) Approvals: Tobias Gritschacher: Looks good to me, approved jenkins-bot: Verified diff --git a/ValueFormatters/ValueFormatters.classes.php b/ValueFormatters/ValueFormatters.classes.php index 1713cc7..ca2ddc3 100644 --- a/ValueFormatters/ValueFormatters.classes.php +++ b/ValueFormatters/ValueFormatters.classes.php @@ -36,6 +36,8 @@ 'ValueFormatters\GeoCoordinateFormatter' = 'includes/formatters/GeoCoordinateFormatter.php', 'ValueFormatters\IriFormatter' = 'includes/formatters/IriFormatter.php', 'ValueFormatters\StringFormatter' = 'includes/formatters/StringFormatter.php', + 'ValueFormatters\TimeIsoFormatter' = 'includes/formatters/TimeIsoFormatter.php', + 'ValueFormatters\TimeFormatter' = 'includes/formatters/TimeFormatter.php', 'ValueFormatters\Test\ValueFormatterFactoryTest' = 'tests/phpunit/ValueFormatterFactoryTest.php', 'ValueFormatters\Test\ValueFormatterTestBase' = 'tests/phpunit/ValueFormatterTestBase.php', diff --git a/ValueFormatters/ValueFormatters.mw.php b/ValueFormatters/ValueFormatters.mw.php index 9c11d74..f138125 100644 --- a/ValueFormatters/ValueFormatters.mw.php +++ b/ValueFormatters/ValueFormatters.mw.php @@ -49,7 +49,8 @@ } $wgValueFormatters = array( - \DataValues\GeoCoordinateValue::getType() = 'ValueFormatters\GeoCoordinateFormatter' + \DataValues\GeoCoordinateValue::getType() = 'ValueFormatters\GeoCoordinateFormatter', + \DataValues\TimeValue::getType() = 'ValueFormatters\TimeFormatter', ); /** diff --git a/ValueFormatters/ValueFormatters.php b/ValueFormatters/ValueFormatters.php index 563974a..2c27b01 100644 --- a/ValueFormatters/ValueFormatters.php +++ b/ValueFormatters/ValueFormatters.php @@ -58,7 +58,8 @@ * @deprecated since 0.1 This is a global registry that provides no control over object lifecycle */ $wgValueFormatters = array( - 'globecoordinate' = 'ValueFormatters\GeoCoordinateFormatter' + 'globecoordinate' = 'ValueFormatters\GeoCoordinateFormatter', + 'timevalue' = 'ValueFormatters\TimeFormatter', ); spl_autoload_register( function ( $className ) { diff --git a/ValueFormatters/includes/formatters/TimeFormatter.php b/ValueFormatters/includes/formatters/TimeFormatter.php new file mode 100644 index 000..5c122cf --- /dev/null +++ b/ValueFormatters/includes/formatters/TimeFormatter.php @@ -0,0 +1,95 @@ +?php + +namespace ValueFormatters; + +use DataValues\TimeValue; +use InvalidArgumentException; + +/** + * Time formatter. + * + * Some code in this class has been borrowed from the + * MapsCoordinateParser class of the Maps extension for MediaWiki. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @since 0.1 + * + * @file + * @ingroup ValueFormatters + * + * @licence GNU GPL v2+ + * @author H. Snater mediaw...@snater.com + */ +class TimeFormatter extends ValueFormatterBase { + const CALENDAR_GREGORIAN = 'http://www.wikidata.org/entity/Q1985727'; + const CALENDAR_JULIAN = 'http://www.wikidata.org/entity/Q1985786'; + + const OPT_LANGUAGE = 'language'; + const OPT_CALENDARNAMES = 'calendars'; + const OPT_TIME_ISO_FORMATTER = 'time iso formatter'; + + /** +* @since 0.1 +* +* @param FormatterOptions $options +*/ + public function __construct( FormatterOptions $options ) { + parent::__construct( $options ); + + $this-defaultOption( self::OPT_LANGUAGE, null ); + + $this-defaultOption( self::OPT_CALENDARNAMES, array( + self::CALENDAR_GREGORIAN = 'Gregorian', +
[MediaWiki-commits] [Gerrit] ValueFormatter for Time DataValue - change (mediawiki...DataValues)
Henning Snater has uploaded a new change for review. https://gerrit.wikimedia.org/r/77089 Change subject: ValueFormatter for Time DataValue .. ValueFormatter for Time DataValue (bug 48937) Change-Id: I0dd02909834ce8b428daea86e8bd2bf87ba9a085 --- M ValueFormatters/ValueFormatters.classes.php M ValueFormatters/ValueFormatters.mw.php M ValueFormatters/ValueFormatters.php A ValueFormatters/includes/formatters/TimeFormatter.php A ValueFormatters/includes/formatters/TimeIsoFormatter.php A ValueFormatters/tests/phpunit/formatters/TimeFormatterTest.php 6 files changed, 284 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues refs/changes/89/77089/1 diff --git a/ValueFormatters/ValueFormatters.classes.php b/ValueFormatters/ValueFormatters.classes.php index 1713cc7..ca2ddc3 100644 --- a/ValueFormatters/ValueFormatters.classes.php +++ b/ValueFormatters/ValueFormatters.classes.php @@ -36,6 +36,8 @@ 'ValueFormatters\GeoCoordinateFormatter' = 'includes/formatters/GeoCoordinateFormatter.php', 'ValueFormatters\IriFormatter' = 'includes/formatters/IriFormatter.php', 'ValueFormatters\StringFormatter' = 'includes/formatters/StringFormatter.php', + 'ValueFormatters\TimeIsoFormatter' = 'includes/formatters/TimeIsoFormatter.php', + 'ValueFormatters\TimeFormatter' = 'includes/formatters/TimeFormatter.php', 'ValueFormatters\Test\ValueFormatterFactoryTest' = 'tests/phpunit/ValueFormatterFactoryTest.php', 'ValueFormatters\Test\ValueFormatterTestBase' = 'tests/phpunit/ValueFormatterTestBase.php', diff --git a/ValueFormatters/ValueFormatters.mw.php b/ValueFormatters/ValueFormatters.mw.php index 9c11d74..f138125 100644 --- a/ValueFormatters/ValueFormatters.mw.php +++ b/ValueFormatters/ValueFormatters.mw.php @@ -49,7 +49,8 @@ } $wgValueFormatters = array( - \DataValues\GeoCoordinateValue::getType() = 'ValueFormatters\GeoCoordinateFormatter' + \DataValues\GeoCoordinateValue::getType() = 'ValueFormatters\GeoCoordinateFormatter', + \DataValues\TimeValue::getType() = 'ValueFormatters\TimeFormatter', ); /** diff --git a/ValueFormatters/ValueFormatters.php b/ValueFormatters/ValueFormatters.php index 563974a..2c27b01 100644 --- a/ValueFormatters/ValueFormatters.php +++ b/ValueFormatters/ValueFormatters.php @@ -58,7 +58,8 @@ * @deprecated since 0.1 This is a global registry that provides no control over object lifecycle */ $wgValueFormatters = array( - 'globecoordinate' = 'ValueFormatters\GeoCoordinateFormatter' + 'globecoordinate' = 'ValueFormatters\GeoCoordinateFormatter', + 'timevalue' = 'ValueFormatters\TimeFormatter', ); spl_autoload_register( function ( $className ) { diff --git a/ValueFormatters/includes/formatters/TimeFormatter.php b/ValueFormatters/includes/formatters/TimeFormatter.php new file mode 100644 index 000..5c122cf --- /dev/null +++ b/ValueFormatters/includes/formatters/TimeFormatter.php @@ -0,0 +1,95 @@ +?php + +namespace ValueFormatters; + +use DataValues\TimeValue; +use InvalidArgumentException; + +/** + * Time formatter. + * + * Some code in this class has been borrowed from the + * MapsCoordinateParser class of the Maps extension for MediaWiki. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @since 0.1 + * + * @file + * @ingroup ValueFormatters + * + * @licence GNU GPL v2+ + * @author H. Snater mediaw...@snater.com + */ +class TimeFormatter extends ValueFormatterBase { + const CALENDAR_GREGORIAN = 'http://www.wikidata.org/entity/Q1985727'; + const CALENDAR_JULIAN = 'http://www.wikidata.org/entity/Q1985786'; + + const OPT_LANGUAGE = 'language'; + const OPT_CALENDARNAMES = 'calendars'; + const OPT_TIME_ISO_FORMATTER = 'time iso formatter'; + + /** +* @since 0.1 +* +* @param FormatterOptions $options +*/ + public function __construct( FormatterOptions $options ) { + parent::__construct( $options ); + + $this-defaultOption( self::OPT_LANGUAGE, null ); + + $this-defaultOption( self::OPT_CALENDARNAMES, array( +