r114063 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114062‎ | r114063 | r114064 >
Date:20:39, 17 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on i18n of duration stuff
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.studentactivity.css (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCachedPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
@@ -19,7 +19,7 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
23 - $this->cacheExpiry = 60;
 23+ $this->cacheExpiry = 180;
2424 parent::__construct( 'StudentActivity' );
2525 }
2626
@@ -72,7 +72,7 @@
7373 $pager = new EPStudentActivityPager( $this->getContext(), $conds );
7474
7575 if ( $pager->getNumRows() ) {
76 - return
 76+ $html =
7777 $pager->getFilterControl() .
7878 $pager->getNavigationBar() .
7979 $pager->getBody() .
@@ -80,10 +80,12 @@
8181 $pager->getMultipleItemControl();
8282 }
8383 else {
84 - return $pager->getFilterControl( true )
 84+ $html = $pager->getFilterControl( true )
8585 . '<br />'
8686 . wfMsgExt( 'ep-studentactivity-noresults', 'parseinline' );
8787 }
 88+
 89+ return '<div class="studentactivity">' . $html . '</div>';
8890 }
8991
9092 /**
Index: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
@@ -96,13 +96,12 @@
9797 if ( $this->cacheExpiry < 1000000000 ) {
9898 $message = $this->msg(
9999 'cachedspecial-viewing-cached-ttl',
100 - $this->getDurationText()
 100+ $this->getDurationText( $this->cacheExpiry )
101101 )->escaped();
102102 }
103103 else {
104104 $message = $this->msg(
105 - 'cachedspecial-viewing-cached-ts',
106 - $this->getDurationText()
 105+ 'cachedspecial-viewing-cached-ts'
107106 )->escaped();
108107 }
109108
@@ -114,10 +113,37 @@
115114 *
116115 * @since 0.1
117116 *
 117+ * @param integer $seconds
 118+ * @param array $chosenIntervals
 119+ *
118120 * @return string
119121 */
120 - protected function getDurationText() {
121 - return '5 minutes'; // TODO: generate and i18n
 122+ protected function getDurationText( $seconds, array $chosenIntervals = array( 'years', 'days', 'hours', 'minutes', 'seconds' ) ) {
 123+ $intervals = array(
 124+ 'years' => 31557600, // 86400 * 365.25
 125+ 'weeks' => 604800,
 126+ 'days' => 86400,
 127+ 'hours' => 3600,
 128+ 'minutes' => 60,
 129+ 'seconds' => 1,
 130+ );
 131+
 132+ if ( !empty( $chosenIntervals ) ) {
 133+ $intervals = array_intersect_key( $intervals, array_flip( $chosenIntervals ) );
 134+ }
 135+
 136+ $segments = array();
 137+
 138+ foreach ( $intervals as $name => $length ) {
 139+ $value = floor( $seconds / $length );
 140+
 141+ if ( $value > 0 || ( $name == 'seconds' && empty( $segments ) ) ) {
 142+ $seconds -= $value * $length;
 143+ $segments[] = wfMsgExt( 'duration-' . $name, 'parsemag', $value );
 144+ }
 145+ }
 146+
 147+ return $this->getLanguage()->listToText( $segments );
122148 }
123149
124150 /**
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -786,6 +786,15 @@
787787 'cachedspecial-viewing-cached-ttl' => 'You are viewing a cached version of this page, which can be up to $1 old.',
788788 'cachedspecial-viewing-cached-ts' => 'You are viewing a cached version of this page, which might not be completely actual.',
789789 'cachedspecial-refresh-now' => 'View latest.',
 790+
 791+ // Durations
 792+ 'duration-seconds' => '$1 {{PLURAL:$1|second|seconds}}',
 793+ 'duration-minutes' => '$1 {{PLURAL:$1|minute|minutes}}',
 794+ 'duration-hours' => '$1 {{PLURAL:$1|hour|hours}}',
 795+ 'duration-days' => '$1 {{PLURAL:$1|day|days}}',
 796+ 'duration-weeks' => '$1 {{PLURAL:$1|week|weeks}}',
 797+ 'duration-years' => '$1 {{PLURAL:$1|year|years}}',
 798+ 'duration-centuries' => '$1 {{PLURAL:$1|century|centuries}}',
790799 );
791800
792801 /** Message documentation (Message documentation)
Index: trunk/extensions/EducationProgram/resources/ep.studentactivity.css
@@ -6,7 +6,7 @@
77 * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
88 */
99
10 -img.studentometer, table.ep-studentactivity {
 10+img.studentometer, table.ep-studentactivity, div.studentactivity {
1111 margin-left: auto;
1212 margin-right: auto;
1313 }
@@ -14,3 +14,7 @@
1515 img.studentometer {
1616 display: block;
1717 }
 18+
 19+div.studentactivity {
 20+ text-align: center;
 21+}
\ No newline at end of file

Status & tagging log