r99582 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99581‎ | r99582 | r99583 >
Date:22:04, 11 October 2011
Author:jpostlethwaite
Status:deferred (Comments)
Tags:
Comment:
Added skeleton special page for LastModified.
Modified paths:
  • /trunk/extensions/LastModified/LastModified.i18n.php (modified) (history)
  • /trunk/extensions/LastModified/LastModified.php (modified) (history)
  • /trunk/extensions/LastModified/SpecialLastModified.php (added) (history)
  • /trunk/extensions/LastModified/modules/lastmodified.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LastModified/LastModified.i18n.php
@@ -28,7 +28,15 @@
2929 */
3030 $messages['en'] = array(
3131 'lastmodified-desc' => 'Generates last modified times for articles',
32 - 'lastmodified' => 'LastModified',
 32+ 'lastmodified' => 'Last Modified',
 33+ 'lastmodified-label-seconds' => 'seconds',
 34+ 'lastmodified-label-minutes' => 'minutes',
 35+ 'lastmodified-label-hours' => 'hours',
 36+ 'lastmodified-label-days' => 'days',
 37+ 'lastmodified-label-months' => 'months',
 38+ 'lastmodified-label-years' => 'years',
 39+ 'lastmodified-options' => 'Options',
 40+ 'lastmodified-display-range-value' => 'Display range value:',
3341 'lastmodified-seconds' => 'Last updated $1 seconds ago',
3442 'lastmodified-minutes' => 'Last updated $1 minutes ago',
3543 'lastmodified-hours' => 'Last updated $1 hours ago',
Index: trunk/extensions/LastModified/modules/lastmodified.js
@@ -112,7 +112,7 @@
113113 * @param integer displayRange The maximum unit of time to display for last updated
114114 *
115115 * displayRange
116 - * - 0: default - display: years, months, days, hours, minutes, seconds
 116+ * - 0: years - display: years, months, days, hours, minutes, seconds
117117 * - 1: months - display: months, days, hours, minutes, seconds
118118 * - 2: days - display: days, hours, minutes, seconds
119119 * - 3: hours - display: hours, minutes, seconds
@@ -136,37 +136,44 @@
137137 else if ( modifiedDifference < 3600 ) {
138138
139139 // minutes
140 - lastEdit = parseInt( modifiedDifference / 60 );
141 - message = ( mw.msg( 'lastmodified-minutes', myLastEdit ) );
 140+ if ( displayRange <= 4 ) {
 141+ lastEdit = parseInt( modifiedDifference / 60 );
 142+ message = ( mw.msg( 'lastmodified-minutes', myLastEdit ) );
 143+ }
142144
143145 }
144146 else if ( modifiedDifference < 86400 ) {
145147
146148 // hours
147 - myLastEdit = parseInt( modifiedDifference / 3600 );
148 - message = ( mw.msg( 'lastmodified-hours', myLastEdit ) );
149 -
 149+ if ( displayRange <= 3) {
 150+ myLastEdit = parseInt( modifiedDifference / 3600 );
 151+ message = ( mw.msg( 'lastmodified-hours', myLastEdit ) );
 152+ }
150153 }
151154 else if ( modifiedDifference < 2592000 ) {
152155
153156 // days
154 - myLastEdit = parseInt( modifiedDifference / 86400 );
155 - message = ( mw.msg( 'lastmodified-days', myLastEdit ) );
 157+ if ( displayRange <= 2) {
 158+ myLastEdit = parseInt( modifiedDifference / 86400 );
 159+ message = ( mw.msg( 'lastmodified-days', myLastEdit ) );
 160+ }
156161
157162 }
158163 else if ( modifiedDifference < 31536000 ) {
159164
160165 // months
161 - myLastEdit = parseInt( modifiedDifference / 2592000 );
162 - message = ( mw.msg( 'lastmodified-months', myLastEdit ) );
163 -
 166+ if ( displayRange <= 1) {
 167+ myLastEdit = parseInt( modifiedDifference / 2592000 );
 168+ message = ( mw.msg( 'lastmodified-months', myLastEdit ) );
 169+ }
164170 }
165171 else {
166172
167173 // years
168 - myLastEdit = parseInt( modifiedDifference / 31536000 );
169 - message = ( mw.msg( 'lastmodified-years', myLastEdit ) );
170 -
 174+ if ( displayRange == 0) {
 175+ myLastEdit = parseInt( modifiedDifference / 31536000 );
 176+ message = ( mw.msg( 'lastmodified-years', myLastEdit ) );
 177+ }
171178 }
172179
173180 return message;
Index: trunk/extensions/LastModified/LastModified.php
@@ -38,8 +38,10 @@
3939
4040 $dir = dirname( __FILE__ ) . '/';
4141
 42+$wgAutoloadClasses['SpecialLastModified'] = $dir . 'SpecialLastModified.php';
4243 $wgExtensionMessagesFiles['LastModified'] = $dir . 'LastModified.i18n.php';
4344 $wgExtensionAliasesFiles['LastModified'] = $dir . 'LastModified.alias.php';
 45+$wgSpecialPages['LastModified'] = 'SpecialLastModified';
4446
4547 /**
4648 * ADDITIONAL MAGICAL GLOBALS
Index: trunk/extensions/LastModified/SpecialLastModified.php
@@ -0,0 +1,84 @@
 2+<?php
 3+/**
 4+ * Wikimedia Foundation
 5+ *
 6+ * LICENSE
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ * @author Katie Horn <khorn@wikimedia.org>, Jeremy Postlethwaite <jpostlethwaite@wikimedia.org>
 19+ */
 20+
 21+if ( !defined( 'MEDIAWIKI' ) ) {
 22+ echo "LastModified extension\n";
 23+ exit( 1 );
 24+}
 25+
 26+/**
 27+ * Show LastModified options
 28+ */
 29+class SpecialLastModified extends SpecialPage {
 30+
 31+ public function __construct() {
 32+ // Register special page
 33+ parent::__construct( 'LastModified' );
 34+ }
 35+
 36+ public function execute( $sub ) {
 37+
 38+ global $wgLastModifiedRange;
 39+
 40+ $this->setHeaders();
 41+ $this->outputHeader();
 42+
 43+ $out = $this->getOutput();
 44+
 45+ $out->addHTML( Xml::openElement( 'h2' ) );
 46+ $out->addHTML( wfMsg( 'lastmodified-options' ) );
 47+ $out->addHTML( Xml::closeElement( 'h2' ) );
 48+
 49+ $out->addHTML( Xml::openElement( 'p' ) );
 50+ $out->addHTML( wfMsg( 'lastmodified-display-range-value' ) . ' ' . $wgLastModifiedRange );
 51+ $out->addHTML( Xml::closeElement( 'p' ) );
 52+
 53+ $rangeMessage = '<p>Display: ';
 54+ $rangeMessageDatetime = '';
 55+
 56+ $displayRange = array(
 57+ 0 => 'years',
 58+ 1 => 'months',
 59+ 2 => 'days',
 60+ 3 => 'hours',
 61+ 4 => 'minutes',
 62+ 5 => 'seconds',
 63+ );
 64+
 65+ // Display seconds
 66+
 67+ foreach ( $displayRange as $key => $value ) {
 68+
 69+ // Check to see which values to display.
 70+ if ( $wgLastModifiedRange == 0 || $key >= $wgLastModifiedRange ) {
 71+
 72+ // append a comma if necessary
 73+ $rangeMessageDatetime .= empty($rangeMessageDatetime) ? '' : ', ';
 74+
 75+ // append message
 76+ $rangeMessageDatetime .= wfMsg( 'lastmodified-label-' . $value );
 77+ }
 78+ }
 79+
 80+ $rangeMessage .= $rangeMessageDatetime;
 81+ $rangeMessage .= '</p>';
 82+
 83+ $out->addHTML( $rangeMessage );
 84+ }
 85+}
Property changes on: trunk/extensions/LastModified/SpecialLastModified.php
___________________________________________________________________
Added: svn:eol-style
186 + native
Added: svn:mime-type
287 + text/plain
Added: svn:keywords
388 + Author Date HeadURL Header Id Revision

Follow-up revisions

RevisionCommit summaryAuthorDate
r99612make unlisted for now since it's purely for debuggingerik00:41, 12 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99522Adding new extension LastModified.jpostlethwaite18:30, 11 October 2011

Comments

#Comment by Jpostlethwaite (talk | contribs)   22:07, 11 October 2011

This commit also included implementing displayRange in javascript.

This allows you to see up to certain time ranges.

#Comment by Siebrand (talk | contribs)   22:21, 11 October 2011

Look, this really, really will not work for other languages. Please give i18n a good read.

#Comment by Jpostlethwaite (talk | contribs)   20:52, 13 October 2011

Were you referring to the use of PLURAL?

#Comment by Siebrand (talk | contribs)   21:37, 13 October 2011

Yes. Although on closer examination, when label-* are used in a drop down or as field labels, not together/concatenated with a number, that would be ok.

#Comment by Catrope (talk | contribs)   13:22, 24 October 2011

You should take a look at Language::formatTimePeriod(), which does pretty much the same as what you're doing here.

#Comment by Jpostlethwaite (talk | contribs)   14:59, 24 October 2011

Thanks.

It looks like it does not say time in weeks, months or years, but that might not be a big deal.

We should test the method.

Status & tagging log