jenkins-bot has submitted this change and it was merged.
Change subject: Bug 51194: Localize the publication date in the metadata.
......................................................................
Bug 51194: Localize the publication date in the metadata.
This adds functionality to localize publication dates, which can
be either a year, a month and a year, or a day, month, and year.
This solution seems a bit... hacky... any suggestions would be
very welcome.
Change-Id: I21f750c3f3c66d4fbf1d6a88a13dad90beaa5dea
---
M BookManagerv2.hooks.php
1 file changed, 36 insertions(+), 8 deletions(-)
Approvals:
Mwalker: Looks good to me, approved
jenkins-bot: Verified
diff --git a/BookManagerv2.hooks.php b/BookManagerv2.hooks.php
index ec38eff..26ddfc6 100644
--- a/BookManagerv2.hooks.php
+++ b/BookManagerv2.hooks.php
@@ -197,18 +197,46 @@
* @return string HTML list item element
*/
public static function addDate( $year, $month, $day ) {
- // TODO: This needs to be localized.
- $output = Html::openElement( 'li', array() );
- if ( $day && !$month ) {
+ global $wgLang, $wgUser;
+
+ // Basic validation of inputs
+ if ( !$month || $month < 1 || $month > 12 ) {
+ $month = null;
+ } else {
+ $monthStr = str_pad( (string)$month, 2, "0",
STR_PAD_LEFT );
+ }
+
+ if ( !$day || $day < 1 || $day > 31 ) {
+ $day = null;
+ } else {
+ $dayStr = str_pad( (string)$day, 2, "0", STR_PAD_LEFT );
+ }
+
+ if ( $year ) {
+ $yearStr = str_pad( (string)$year, 4, "0", STR_PAD_LEFT
);
+ }
+
+ if ( $year && !$month ) {
// Having a day without a month doesn't make much sense
$date = $year;
+ $datetime = $year;
+ } else if ( $year && $month && !$day ) {
+ $ts = $yearStr . $monthStr . "01000000";
+ $format = $wgLang->getDateFormatString( 'monthonly',
+ $wgUser->getDatePreference() ?: 'default' );
+ $date = $wgLang->sprintfDate( $format, $ts );
+ $datetime = $yearStr . "-" . $monthStr;
} else {
- $date = $day ? $day . "/" : "";
- $date .= $month ? $month . "/" : "";
- $date .= $year ? $year : "";
+ $ts = $yearStr . $monthStr . $dayStr . "000000";
+ $format = $wgLang->getDateFormatString( 'date',
+ $wgUser->getDatePreference() ?: 'default' );
+ $date = $wgLang->sprintfDate( $format, $ts );
+ $datetime = $yearStr . "-" . $monthStr . "-" . $dayStr;
}
- $output .= wfMessage( 'bookmanagerv2-publication-date',
- $date )->text()
+ $output = Html::openElement( 'li', array() )
+ . Html::openElement( 'time', array( 'datetime' =>
$datetime ) )
+ . wfMessage( 'bookmanagerv2-publication-date', $date
)->text()
+ . Html::closeElement( 'time' )
. Html::closeElement( 'li' );
return $output;
}
--
To view, visit https://gerrit.wikimedia.org/r/76454
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I21f750c3f3c66d4fbf1d6a88a13dad90beaa5dea
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/BookManagerv2
Gerrit-Branch: master
Gerrit-Owner: Mollywhite <[email protected]>
Gerrit-Reviewer: Mollywhite <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits