From 3c4d38faee679dfc63fded82d7fb6ce9610ccc3f Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 29 Jun 2004 12:23:59 +0000 Subject: [PATCH] Removed arbitrary change in timestamp formats between MySQL and PostgreSQL, moved global functions to GlobalFunctions --- includes/Database.php | 30 ++---------------------------- includes/DatabasePostgreSQL.php | 27 --------------------------- includes/EditPage.php | 8 +------- includes/GlobalFunctions.php | 28 ++++++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 62 deletions(-) diff --git a/includes/Database.php b/includes/Database.php index 080d372387..3cb22ea957 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -465,8 +465,7 @@ class Database { function stopTimer() { } - -} +} #------------------------------------------------------------------------------ # Global functions @@ -526,34 +525,9 @@ function wfStrencode( $s ) return addslashes( $s ); } -# Ideally we'd be using actual time fields in the db -function wfTimestamp2Unix( $ts ) { - return gmmktime( ( (int)substr( $ts, 8, 2) ), - (int)substr( $ts, 10, 2 ), (int)substr( $ts, 12, 2 ), - (int)substr( $ts, 4, 2 ), (int)substr( $ts, 6, 2 ), - (int)substr( $ts, 0, 4 ) ); -} - -function wfUnix2Timestamp( $unixtime ) { - return gmdate( "YmdHis", $unixtime ); -} - -function wfTimestampNow() { - # return NOW - return gmdate( "YmdHis" ); -} - -# Sorting hack for MySQL 3, which doesn't use index sorts for DESC -function wfInvertTimestamp( $ts ) { - return strtr( - $ts, - "0123456789", - "9876543210" - ); -} - function wfLimitResult( $limit, $offset ) { return " LIMIT ".(is_numeric($offset)?"{$offset},":"")."{$limit} "; } + ?> diff --git a/includes/DatabasePostgreSQL.php b/includes/DatabasePostgreSQL.php index f9add198cc..2b3ba25f10 100644 --- a/includes/DatabasePostgreSQL.php +++ b/includes/DatabasePostgreSQL.php @@ -515,33 +515,6 @@ function wfStrencode( $s ) return pg_escape_string( $s ); } -# Use PostgreSQL timestamp without timezone data type -function wfTimestamp2Unix( $ts ) { - return gmmktime( ( (int)substr( $ts, 11, 2) ), - (int)substr( $ts, 14, 2 ), (int)substr( $ts, 17, 2 ), - (int)substr( $ts, 5, 2 ), (int)substr( $ts, 8, 2 ), - (int)substr( $ts, 0, 4 ) ); -} - -function wfUnix2Timestamp( $unixtime ) { - return gmdate( "Y-m-d H:i:s", $unixtime ); -} - -function wfTimestampNow() { - # return NOW - return gmdate( "Y-m-d H:i:s" ); -} - -# Sorting hack for MySQL 3, which doesn't use index sorts for DESC -function wfInvertTimestamp( $ts ) { - $ts=preg_replace("/\D/","",$ts); - return strtr( - $ts, - "0123456789", - "9876543210" - ); -} - function wfLimitResult( $limit, $offset ) { return " LIMIT $limit ".(is_numeric($offset)?" OFFSET {$offset} ":""); } diff --git a/includes/EditPage.php b/includes/EditPage.php index 2d779ac70e..b2e0171e38 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -62,7 +62,6 @@ class EditPage { } function importFormData( &$request ) { - global $wgIsMySQL, $wgIsPg; # These fields need to be checked for encoding. # Also remove trailing whitespace, but don't remove _initial_ # whitespace from the text boxes. This may be significant formatting. @@ -71,12 +70,7 @@ class EditPage { $this->summary = trim( $request->getText( "wpSummary" ) ); $this->edittime = $request->getVal( 'wpEdittime' ); - if ($wgIsMySQL) - if( !preg_match( '/^\d{14}$/', $this->edittime )) $this->edittime = ""; - if ($wgIsPg) - if ( !preg_match( '/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/', - $this->edittime )) - $this->edittime = ""; + if( !preg_match( '/^\d{14}$/', $this->edittime )) $this->edittime = ""; $this->preview = $request->getCheck( 'wpPreview' ); $this->save = $request->wasPosted() && !$this->preview; diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 0ae7fdcbe4..a37e1dc20f 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -972,4 +972,32 @@ function wfIsWindows() { } } + +# Ideally we'd be using actual time fields in the db +function wfTimestamp2Unix( $ts ) { + return gmmktime( ( (int)substr( $ts, 8, 2) ), + (int)substr( $ts, 10, 2 ), (int)substr( $ts, 12, 2 ), + (int)substr( $ts, 4, 2 ), (int)substr( $ts, 6, 2 ), + (int)substr( $ts, 0, 4 ) ); +} + +function wfUnix2Timestamp( $unixtime ) { + return gmdate( "YmdHis", $unixtime ); +} + +function wfTimestampNow() { + # return NOW + return gmdate( "YmdHis" ); +} + +# Sorting hack for MySQL 3, which doesn't use index sorts for DESC +function wfInvertTimestamp( $ts ) { + return strtr( + $ts, + "0123456789", + "9876543210" + ); +} + + ?> -- 2.20.1