r81927 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81926‎ | r81927 | r81928 >
Date:02:38, 11 February 2011
Author:juliano
Status:deferred
Tags:
Comment:
Article and comment timestamps are now displayed in the wiki timezone
(as defined by $wgLocaltimezone).
Modified paths:
  • /trunk/extensions/Wikilog/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Wikilog/Wikilog.i18n.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogComment.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogItem.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogItemPager.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogUtils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikilog/WikilogItemPager.php
@@ -271,6 +271,7 @@
272272 * - 'published': empty (draft) or "*" (published)
273273 * - 'date': article publication date
274274 * - 'time': article publication time
 275+ * - 'tz': timezone information
275276 * - 'updatedDate': article last update date
276277 * - 'updatedTime': article last update time
277278 * - 'summary': article summary
@@ -313,7 +314,7 @@
314315 }
315316
316317 function formatRow( $row ) {
317 - global $wgParser, $wgContLang;
 318+ global $wgParser;
318319
319320 # Retrieve article parser output and other data.
320321 $item = WikilogItem::newFromRow( $row );
@@ -333,14 +334,12 @@
334335 $divclass = 'wl-entry' . ( $item->getIsPublished() ? '' : ' wl-draft' );
335336
336337 $itemPubdate = $item->getPublishDate();
337 - $pubdate = $wgContLang->timeanddate( $itemPubdate, true );
338 - $publishedDate = $wgContLang->date( $itemPubdate );
339 - $publishedTime = $wgContLang->time( $itemPubdate );
 338+ list( $publishedDate, $publishedTime, $publishedTz ) =
 339+ WikilogUtils::getLocalDateTime( $itemPubdate );
340340
341341 $itemUpdated = $item->getUpdatedDate();
342 - $updated = $wgContLang->timeanddate( $itemUpdated, true );
343 - $updatedDate = $wgContLang->date( $itemUpdated );
344 - $updatedTime = $wgContLang->time( $itemUpdated );
 342+ list( $updatedDate, $updatedTime, ) =
 343+ WikilogUtils::getLocalDateTime( $itemUpdated );
345344
346345 # Template parameters.
347346 $vars = array(
@@ -354,6 +353,7 @@
355354 'published' => $item->getIsPublished() ? '*' : '',
356355 'date' => $publishedDate,
357356 'time' => $publishedTime,
 357+ 'tz' => $publishedTz,
358358 'updatedDate' => $updatedDate,
359359 'updatedTime' => $updatedTime,
360360 'summary' => $wgParser->insertStripItem( $summary ),
Index: trunk/extensions/Wikilog/RELEASE-NOTES
@@ -11,6 +11,9 @@
1212
1313 === New features ===
1414
 15+* Article and comment timestamps are now displayed in the wiki timezone
 16+ (as defined by $wgLocaltimezone).
 17+
1518 === Bug fixes ===
1619
1720
Index: trunk/extensions/Wikilog/Wikilog.i18n.php
@@ -76,9 +76,9 @@
7777
7878 # Wikilog article header and footer
7979 'wikilog-summary-header' => '',
80 - 'wikilog-summary-footer' => 'Posted by $7 to [[$1|$2]] on $8 at $9, $10.',
 80+ 'wikilog-summary-footer' => 'Posted by $7 to [[$1|$2]] on $8 at $9 ($15), $10.',
8181 'wikilog-summary-header-single' => '',
82 - 'wikilog-summary-footer-single' => 'Posted by $7 on $8 at $9, $10.',
 82+ 'wikilog-summary-footer-single' => 'Posted by $7 on $8 at $9 ($15), $10.',
8383 'wikilog-summary-uncategorized' => 'Uncategorized',
8484 'wikilog-summary-categories' => 'Filed under $2',
8585 'wikilog-summary-more' => '[[$3|→ continue reading...]]',
@@ -98,7 +98,7 @@
9999 # Comments
100100 'wikilog-comment-header' => '',
101101 'wikilog-comment-footer' => '— $2 • $5 $6',
102 - 'wikilog-comment-permalink' => '$1 at $2',
 102+ 'wikilog-comment-permalink' => '$1 at $2 ($3)',
103103 'wikilog-comment-note-item' => 'posted to $1',
104104 'wikilog-comment-note-edited' => 'last edited on $1 at $2',
105105 'wikilog-comment-anonsig' => '$3 (anonymous)',
@@ -255,7 +255,8 @@
256256 * $7 is a list of authors of the article, each name formated with {{msg-mw|wikilog-author-signature}}
257257 * $8 is the publication date
258258 * $9 is the publication time
259 -* $10 is a link to the comments page, with either {{msg-mw|wikilog-no-comments}} or {{msg-mw|wikilog-has-comments}} as link text",
 259+* $10 is a link to the comments page, with either {{msg-mw|wikilog-no-comments}} or {{msg-mw|wikilog-has-comments}} as link text
 260+* $15 is the timezone information (optional)",
260261 'wikilog-summary-footer-single' => "Identical to {{msg-mw|wikilog-summary-footer}}, but used when listing articles from a single wikilog, so it is not necessary to say where it was posted to. Parameters:
261262 * $1 is a URL formatted link to the article's parent wikilog (optional)
262263 * $2 is the article's parent wikilog name (optional)
@@ -266,7 +267,8 @@
267268 * $7 is a list of authors of the article, each name formated with {{msg-mw|wikilog-author-signature}}
268269 * $8 is the publication date
269270 * $9 is the publication time
270 -* $10 is a link to the comments page, with either {{msg-mw|wikilog-no-comments}} or {{msg-mw|wikilog-has-comments}} as link text",
 271+* $10 is a link to the comments page, with either {{msg-mw|wikilog-no-comments}} or {{msg-mw|wikilog-has-comments}} as link text
 272+* $15 is the timezone information (optional)",
271273 'wikilog-summary-categories' => 'Parameters:
272274 * $1 is the number of categories listed in $2
273275 * $2 is a list of the categories the article is in',
@@ -291,14 +293,16 @@
292294 'wikilog-comment-permalink' => 'A permanent link to the comment.
293295 Parameters:
294296 * $1 is the comment date
295 -* $2 is the comment time',
 297+* $2 is the comment time
 298+* $3 is the timezone information (optional)',
296299 'wikilog-comment-note-item' => 'The title of the article that the comment was posted to.
297300 Parameters:
298301 * $1 is an article title.',
299302 'wikilog-comment-note-edited' => 'The last time the comment was edited.
300303 Parameters:
301304 * $1 is the last modification date
302 -* $2 is the last modification time',
 305+* $2 is the last modification time
 306+* $3 is the timezone information (optional)',
303307 'wikilog-comment-anonsig' => 'Signature used for anonymous users which post comments to articles.
304308 Parameters:
305309 * $1 is a link to the commenting user page (unused, it is an IP address)
Index: trunk/extensions/Wikilog/WikilogItem.php
@@ -196,6 +196,8 @@
197197 }
198198 }
199199
 200+ list( $date, $time, $tz ) = WikilogUtils::getLocalDateTime( $this->mPubDate );
 201+
200202 /*
201203 * This is probably the largest amount of parameters to a
202204 * system message in MediaWiki. This is the price of allowing
@@ -209,13 +211,14 @@
210212 /* $5 */ count( $authors ),
211213 /* $6 */ ( count( $authors ) > 0 ? $authors[0] : '' ),
212214 /* $7 */ $authorsFmt,
213 - /* $8 */ $wgContLang->date( $this->mPubDate ),
214 - /* $9 */ $wgContLang->time( $this->mPubDate ),
 215+ /* $8 */ $date,
 216+ /* $9 */ $time,
215217 /* $10 */ $commentsFmt,
216218 /* $11 */ count( $categories ),
217219 /* $12 */ $categoriesFmt,
218220 /* $13 */ count( $tags ),
219 - /* $14 */ $tagsFmt
 221+ /* $14 */ $tagsFmt,
 222+ /* $15 */ $tz
220223 );
221224 }
222225
Index: trunk/extensions/Wikilog/WikilogUtils.php
@@ -399,6 +399,44 @@
400400
401401 return array( 'date' => $date, 'user' => $user );
402402 }
 403+
 404+ /**
 405+ * Return the given timestamp as a tuple with date, time and timezone
 406+ * in the local timezone (if defined). This is meant to be compatible
 407+ * with signatures produced by Parser::pstPass2(). It was based on this
 408+ * same function.
 409+ *
 410+ * @param $timestamp Timestamp.
 411+ * @return Array(3) containing date, time and timezone.
 412+ */
 413+ public static function getLocalDateTime( $timestamp ) {
 414+ global $wgContLang, $wgLocaltimezone;
 415+
 416+ $ts = wfTimestamp( TS_UNIX, $timestamp );
 417+
 418+ if ( isset( $wgLocaltimezone ) ) {
 419+ $oldtz = date_default_timezone_get();
 420+ date_default_timezone_set( $wgLocaltimezone );
 421+ }
 422+
 423+ $ts = date( 'YmdHis', $ts );
 424+ $tz = date( 'T', $ts );
 425+
 426+ if ( isset( $oldtz ) ) {
 427+ date_default_timezone_set( $oldtz );
 428+ }
 429+
 430+ $date = $wgContLang->date( $ts, false, false );
 431+ $time = $wgContLang->time( $ts, false, false );
 432+
 433+ # Check for translation of timezones.
 434+ $key = 'timezone-' . strtolower( trim( $tz ) );
 435+ $value = wfMsgForContent( $key );
 436+ if ( !wfEmptyMsg( $key, $value ) ) $tz = $value;
 437+
 438+ return array( $date, $time, $tz );
 439+ }
 440+
403441 }
404442
405443 /**
Index: trunk/extensions/Wikilog/WikilogComment.php
@@ -721,9 +721,8 @@
722722 );
723723 }
724724
725 - $date = $wgContLang->date( $comment->mTimestamp );
726 - $time = $wgContLang->time( $comment->mTimestamp );
727 - $permalink = $this->getCommentPermalink( $comment, $date, $time );
 725+ list( $date, $time, $tz ) = WikilogUtils::getLocalDateTime( $comment->mTimestamp );
 726+ $permalink = $this->getCommentPermalink( $comment, $date, $time, $tz );
728727
729728 $extra = array();
730729 if ( $this->mShowItem && $comment->mItem ) {
@@ -737,11 +736,9 @@
738737 {
739738 if ( $comment->mUpdated != $comment->mTimestamp ) {
740739 # Comment was edited.
 740+ list( $updDate, $updTime, $updTz ) = WikilogUtils::getLocalDateTime( $comment->mUpdated );
741741 $extra[] = $this->mSkin->link( $comment->mCommentTitle,
742 - wfMsgForContent( 'wikilog-comment-note-edited',
743 - $wgContLang->date( $comment->mUpdated, true ),
744 - $wgContLang->time( $comment->mUpdated, true )
745 - ),
 742+ wfMsgForContent( 'wikilog-comment-note-edited', $updDate, $updTime, $updTz ),
746743 array( 'title' => wfMsg( 'wikilog-comment-history' ) ),
747744 array( 'action' => 'history' ), 'known'
748745 );
@@ -837,9 +834,10 @@
838835 * @param $comment Comment.
839836 * @param $date Comment date.
840837 * @param $time Comment time.
 838+ * @param $tz Comment timezone information.
841839 * @return HTML fragment.
842840 */
843 - protected function getCommentPermalink( $comment, $date, $time ) {
 841+ protected function getCommentPermalink( $comment, $date, $time, $tz ) {
844842 if ( $comment->mID ) {
845843 if ( $this->mPermalinkTitle ) {
846844 $title = $this->mPermalinkTitle;
@@ -848,11 +846,11 @@
849847 $title = $comment->mCommentTitle;
850848 }
851849 return $this->mSkin->link( $title,
852 - wfMsg( 'wikilog-comment-permalink', $date, $time ),
 850+ wfMsg( 'wikilog-comment-permalink', $date, $time, $tz ),
853851 array( 'title' => wfMsg( 'permalink' ) )
854852 );
855853 } else {
856 - return wfMsg( 'wikilog-comment-permalink', $date, $time );
 854+ return wfMsg( 'wikilog-comment-permalink', $date, $time, $tz );
857855 }
858856 }
859857

Status & tagging log