Page MenuHomePhabricator

3412.diff

Authored By
bzimport
Nov 21 2014, 8:49 PM
Size
6 KB
Referenced Files
None
Subscribers
None

3412.diff

Index: includes/Defines.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/Defines.php,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- includes/Defines.php 25 Jul 2005 06:57:11 -0000 1.30
+++ includes/Defines.php 13 Sep 2005 06:55:43 -0000 1.31
@@ -129,4 +129,15 @@
define( 'ALF_NO_BLOCK_LOCK', 8 );
/**#@-*/
+/**#@+
+ * Date format selectors; used in user preference storage and by
+ * Language::date() and co.
+ */
+define( 'MW_DATE_DEFAULT', '0' );
+define( 'MW_DATE_MDY', '1' );
+define( 'MW_DATE_DMY', '2' );
+define( 'MW_DATE_YMD', '3' );
+define( 'MW_DATE_ISO', 'ISO 8601' );
+/**#@-*/
+
?>
Index: languages/Language.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/languages/Language.php,v
retrieving revision 1.677
retrieving revision 1.678
diff -u -r1.677 -r1.678
--- languages/Language.php 6 Sep 2005 21:54:38 -0000 1.677
+++ languages/Language.php 13 Sep 2005 06:55:43 -0000 1.678
@@ -110,11 +110,11 @@
# Whether to use user or default setting in Language::date()
/* private */ $wgDateFormatsEn = array(
- 'No preference',
- '16:12, January 15, 2001',
- '16:12, 15 January 2001',
- '16:12, 2001 January 15',
- 'ISO 8601' => '2001-01-15 16:12:34'
+ MW_DATE_DEFAULT => 'No preference',
+ MW_DATE_MDY => '16:12, January 15, 2001',
+ MW_DATE_DMY => '16:12, 15 January 2001',
+ MW_DATE_YMD => '16:12, 2001 January 15',
+ MW_DATE_ISO => '2001-01-15 16:12:34'
);
/* private */ $wgUserTogglesEn = array(
@@ -2415,23 +2415,28 @@
* all children.
*
*<code>
- * function timeanddate([...], $format = '0') {
+ * function timeanddate([...], $format = true) {
* $datePreference = $this->dateFormat($format);
* [...]
*</code>
*
- * @param mixed $format
+ * @param bool $usePrefs: if false, the site/language default is used
* @return string
*/
- function dateFormat( $format ) {
- global $wgUser;
+ function dateFormat( $usePrefs = true ) {
+ global $wgUser, $wgAmericanDates;
- if ( !$wgUser->isLoggedIn() || $format === false ) {
- $options = $this->getDefaultUserOptions();
- return (string)$options['date'];
+ if( $usePrefs ) {
+ $datePreference = $wgUser->getOption( 'date' );
} else {
- return $wgUser->getOption( 'date' );
+ $options = $this->getDefaultUserOptions();
+ $datePreference = (string)$options['date'];
}
+
+ if( $datePreference == MW_DATE_DEFAULT || $datePreference == '' ) {
+ return $wgAmericanDates ? MW_DATE_MDY : MW_DATE_DMY;
+ }
+ return $datePreference;
}
/**
@@ -2440,30 +2445,26 @@
* date('YmdHis') format with wfTimestamp(TS_MW,$ts)
* @param bool $adj whether to adjust the time output according to the
* user configured offset ($timecorrection)
- * @param mixed $format what format to return, if it's false output the
- * default one.
+ * @param bool $format true to use user's date format preference
* @param string $timecorrection the time offset as returned by
* validateTimeZone() in Special:Preferences
* @return string
*/
function date( $ts, $adj = false, $format = true, $timecorrection = false ) {
- global $wgAmericanDates, $wgUser;
+ global $wgUser;
if ( $adj ) { $ts = $this->userAdjust( $ts, $timecorrection ); }
- $datePreference = $this->dateFormat($format);
-
- if ($datePreference == '0'
- || $datePreference == '' ) {$datePreference = $wgAmericanDates ? '0' : '2';}
+ $datePreference = $this->dateFormat( $format );
$month = $this->getMonthName( substr( $ts, 4, 2 ) );
$day = $this->formatNum( 0 + substr( $ts, 6, 2 ) );
$year = $this->formatNum( substr( $ts, 0, 4 ), true );
switch( $datePreference ) {
- case '2': return "$day $month $year";
- case '3': return "$year $month $day";
- case 'ISO 8601': return substr($ts, 0, 4). '-' . substr($ts, 4, 2). '-' .substr($ts, 6, 2);
+ case MW_DATE_DMY: return "$day $month $year";
+ case MW_DATE_YMD: return "$year $month $day";
+ case MW_DATE_ISO: return substr($ts, 0, 4). '-' . substr($ts, 4, 2). '-' .substr($ts, 6, 2);
default: return "$month $day, $year";
}
}
@@ -2474,23 +2475,20 @@
* date('YmdHis') format with wfTimestamp(TS_MW,$ts)
* @param bool $adj whether to adjust the time output according to the
* user configured offset ($timecorrection)
- * @param mixed $format what format to return, if it's false output the
- * default one (default true)
+ * @param bool $format true to use user's date format preference
* @param string $timecorrection the time offset as returned by
* validateTimeZone() in Special:Preferences
* @return string
*/
function time( $ts, $adj = false, $format = true, $timecorrection = false ) {
- global $wgUser, $wgAmericanDates;
+ global $wgUser;
if ( $adj ) { $ts = $this->userAdjust( $ts, $timecorrection ); }
- $datePreference = $this->dateFormat($format);
-
- if ($datePreference == '0') {$datePreference = $wgAmericanDates ? '0' : '2';}
+ $datePreference = $this->dateFormat( $format );
$t = substr( $ts, 8, 2 ) . ':' . substr( $ts, 10, 2 );
- if ( $datePreference === 'ISO 8601' ) {
+ if ( $datePreference == MW_DATE_ISO ) {
$t .= ':' . substr( $ts, 12, 2 );
}
return $this->formatNum( $t );
@@ -2502,22 +2500,20 @@
* date('YmdHis') format with wfTimestamp(TS_MW,$ts)
* @param bool $adj whether to adjust the time output according to the
* user configured offset ($timecorrection)
- * @param mixed $format what format to return, if it's false output the
- * default one (default true)
+ * @param bool $format true to use user's date format preference
* @param string $timecorrection the time offset as returned by
* validateTimeZone() in Special:Preferences
* @return string
*/
function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false) {
- global $wgUser, $wgAmericanDates;
+ global $wgUser;
$datePreference = $this->dateFormat($format);
-
switch ( $datePreference ) {
- case 'ISO 8601': return $this->date( $ts, $adj, $datePreference, $timecorrection ) . ' ' .
- $this->time( $ts, $adj, $datePreference, $timecorrection );
- default: return $this->time( $ts, $adj, $datePreference, $timecorrection ) . ', ' .
- $this->date( $ts, $adj, $datePreference, $timecorrection );
+ case MW_DATE_ISO: return $this->date( $ts, $adj, $format, $timecorrection ) . ' ' .
+ $this->time( $ts, $adj, $format, $timecorrection );
+ default: return $this->time( $ts, $adj, $format, $timecorrection ) . ', ' .
+ $this->date( $ts, $adj, $format, $timecorrection );
}
}

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1879
Default Alt Text
3412.diff (6 KB)

Event Timeline