Jack Phoenix has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/332672 )

Change subject: Use the PHP wfTimestamp() function instead of the DBMS-specific 
UNIX_TIMESTAMP function for converting timestamps
......................................................................

Use the PHP wfTimestamp() function instead of the DBMS-specific UNIX_TIMESTAMP 
function for converting timestamps

This'll allow us to eventually support non-MySQL/MariaDB DBMSes properly.

Change-Id: Iba1efb85a27fe166ab30ae65371d45e49f9a980f
---
M SystemGifts/UserSystemGiftsClass.php
M UserActivity/UserActivityClass.php
M UserBoard/UserBoardClass.php
M UserGifts/UserGiftsClass.php
M UserProfile/UserProfilePage.php
5 files changed, 65 insertions(+), 62 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SocialProfile 
refs/changes/72/332672/1

diff --git a/SystemGifts/UserSystemGiftsClass.php 
b/SystemGifts/UserSystemGiftsClass.php
index f689128..4ad5b29 100644
--- a/SystemGifts/UserSystemGiftsClass.php
+++ b/SystemGifts/UserSystemGiftsClass.php
@@ -369,7 +369,7 @@
                        array(
                                'sg_id', 'sg_user_id', 'sg_user_name', 
'sg_gift_id', 'sg_date',
                                'sg_status', 'gift_name', 'gift_description',
-                               'gift_given_count', 'UNIX_TIMESTAMP(sg_date) AS 
unix_time'
+                               'gift_given_count'
                        ),
                        array( "sg_user_id = {$this->user_id}" ),
                        __METHOD__,
@@ -386,14 +386,14 @@
                        $requests[] = array(
                                'id' => $row->sg_id,
                                'gift_id' => $row->sg_gift_id,
-                               'timestamp' => ( $row->sg_date ),
+                               'timestamp' => $row->sg_date,
                                'status' => $row->sg_status,
                                'user_id' => $row->sg_user_id,
                                'user_name' => $row->sg_user_name,
                                'gift_name' => $row->gift_name,
                                'gift_description' => $row->gift_description,
                                'gift_given_count' => $row->gift_given_count,
-                               'unix_timestamp' => $row->unix_time
+                               'unix_timestamp' => wfTimestamp( TS_UNIX, 
$row->sg_date )
                        );
                }
                return $requests;
diff --git a/UserActivity/UserActivityClass.php 
b/UserActivity/UserActivityClass.php
index ba26d32..442b959 100644
--- a/UserActivity/UserActivityClass.php
+++ b/UserActivity/UserActivityClass.php
@@ -105,7 +105,7 @@
                $res = $dbr->select(
                        'recentchanges',
                        array(
-                               'UNIX_TIMESTAMP(rc_timestamp) AS item_date', 
'rc_title',
+                               'rc_timestamp', 'rc_title',
                                'rc_user', 'rc_user_text', 'rc_comment', 
'rc_id', 'rc_minor',
                                'rc_new', 'rc_namespace', 'rc_cur_id', 
'rc_this_oldid',
                                'rc_last_oldid', 'rc_log_action'
@@ -126,11 +126,14 @@
                        if ( $row->rc_namespace == NS_SPECIAL || 
$row->rc_log_action != null ) {
                                continue;
                        }
+
                        $title = Title::makeTitle( $row->rc_namespace, 
$row->rc_title );
+                       $unixTS = wfTimestamp( TS_UNIX, $row->rc_timestamp );
+
                        
$this->items_grouped['edit'][$title->getPrefixedText()]['users'][$row->rc_user_text][]
 = array(
                                'id' => 0,
                                'type' => 'edit',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'pagetitle' => $row->rc_title,
                                'namespace' => $row->rc_namespace,
                                'username' => $row->rc_user_text,
@@ -141,12 +144,12 @@
                        );
 
                        // set last timestamp
-                       
$this->items_grouped['edit'][$title->getPrefixedText()]['timestamp'] = 
$row->item_date;
+                       
$this->items_grouped['edit'][$title->getPrefixedText()]['timestamp'] = $unixTS;
 
                        $this->items[] = array(
                                'id' => 0,
                                'type' => 'edit',
-                               'timestamp' => ( $row->item_date ),
+                               'timestamp' => $unixTS,
                                'pagetitle' => $row->rc_title,
                                'namespace' => $row->rc_namespace,
                                'username' => $row->rc_user_text,
@@ -199,7 +202,7 @@
                $res = $dbr->select(
                        array( 'Vote', 'page' ),
                        array(
-                               'UNIX_TIMESTAMP(vote_date) AS item_date', 
'username',
+                               'vote_date AS item_date', 'username',
                                'page_title', 'vote_count', 'comment_count', 
'vote_ip',
                                'vote_user_id'
                        ),
@@ -217,7 +220,7 @@
                        $this->items[] = array(
                                'id' => 0,
                                'type' => 'vote',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => wfTimestamp( TS_UNIX, 
$row->vote_date ),
                                'pagetitle' => $row->page_title,
                                'namespace' => $row->page_namespace,
                                'username' => $username,
@@ -242,7 +245,7 @@
                }
 
                $where = array();
-               $where[] = 'comment_page_id = page_id';
+               $where[] = 'Comment_Page_ID = page_id';
 
                if ( !empty( $this->rel_type ) ) {
                        $users = $dbr->select(
@@ -271,7 +274,7 @@
                $res = $dbr->select(
                        array( 'Comments', 'page' ),
                        array(
-                               'UNIX_TIMESTAMP(comment_date) AS item_date',
+                               'Comment_Date AS item_date',
                                'Comment_Username', 'Comment_IP', 'page_title', 
'Comment_Text',
                                'Comment_user_id', 'page_namespace', 'CommentID'
                        ),
@@ -296,10 +299,11 @@
 
                        if ( $show_comment ) {
                                $title = Title::makeTitle( 
$row->page_namespace, $row->page_title );
+                               $unixTS = wfTimestamp( TS_UNIX, $row->item_date 
);
                                
$this->items_grouped['comment'][$title->getPrefixedText()]['users'][$row->Comment_Username][]
 = array(
                                        'id' => $row->CommentID,
                                        'type' => 'comment',
-                                       'timestamp' => $row->item_date,
+                                       'timestamp' => $unixTS,
                                        'pagetitle' => $row->page_title,
                                        'namespace' => $row->page_namespace,
                                        'username' => $row->Comment_Username,
@@ -310,13 +314,13 @@
                                );
 
                                // set last timestamp
-                               
$this->items_grouped['comment'][$title->getPrefixedText()]['timestamp'] = 
$row->item_date;
+                               
$this->items_grouped['comment'][$title->getPrefixedText()]['timestamp'] = 
$unixTS;
 
                                $username = $row->Comment_Username;
                                $this->items[] = array(
                                        'id' => $row->CommentID,
                                        'type' => 'comment',
-                                       'timestamp' => $row->item_date,
+                                       'timestamp' => $unixTS,
                                        'pagetitle' => $row->page_title,
                                        'namespace' => $row->page_namespace,
                                        'username' => $username,
@@ -367,7 +371,7 @@
                        array(
                                'ug_id', 'ug_user_id_from', 'ug_user_name_from',
                                'ug_user_id_to', 'ug_user_name_to',
-                               'UNIX_TIMESTAMP(ug_date) AS item_date', 
'gift_name', 'gift_id'
+                               'ug_date', 'gift_name', 'gift_id'
                        ),
                        $where,
                        __METHOD__,
@@ -383,7 +387,7 @@
                        $this->items[] = array(
                                'id' => $row->ug_id,
                                'type' => 'gift-sent',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => wfTimestamp( TS_UNIX, 
$row->ug_date ),
                                'pagetitle' => $row->gift_name,
                                'namespace' => $row->gift_id,
                                'username' => $row->ug_user_name_from,
@@ -433,7 +437,7 @@
                        array(
                                'ug_id', 'ug_user_id_from', 'ug_user_name_from',
                                'ug_user_id_to', 'ug_user_name_to',
-                               'UNIX_TIMESTAMP(ug_date) AS item_date', 
'gift_name', 'gift_id'
+                               'ug_date', 'gift_name', 'gift_id'
                        ),
                        $where,
                        __METHOD__,
@@ -466,16 +470,18 @@
                                </a>
                        </div>";
 
+                       $unixTS = wfTimestamp( TS_UNIX, $row->ug_date );
+
                        $this->activityLines[] = array(
                                'type' => 'gift-rec',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'data' => ' ' . $html
                        );
 
                        $this->items[] = array(
                                'id' => $row->ug_id,
                                'type' => 'gift-rec',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'pagetitle' => $row->gift_name,
                                'namespace' => $row->gift_id,
                                'username' => $row->ug_user_name_to,
@@ -527,7 +533,7 @@
                        array( 'user_system_gift', 'system_gift' ),
                        array(
                                'sg_id', 'sg_user_id', 'sg_user_name',
-                               'UNIX_TIMESTAMP(sg_date) AS item_date', 
'gift_name', 'gift_id'
+                               'sg_date', 'gift_name', 'gift_id'
                        ),
                        $where,
                        __METHOD__,
@@ -558,16 +564,18 @@
                                </a>
                        </div>";
 
+                       $unixTS = wfTimestamp( TS_UNIX, $row->sg_date );
+
                        $this->activityLines[] = array(
                                'type' => 'system_gift',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'data' => ' ' . $html
                        );
 
                        $this->items[] = array(
                                'id' => $row->sg_id,
                                'type' => 'system_gift',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'pagetitle' => $row->gift_name,
                                'namespace' => $row->gift_id,
                                'username' => $row->sg_user_name,
@@ -618,8 +626,7 @@
                        'user_relationship',
                        array(
                                'r_id', 'r_user_id', 'r_user_name', 
'r_user_id_relation',
-                               'r_user_name_relation', 'r_type',
-                               'UNIX_TIMESTAMP(r_date) AS item_date'
+                               'r_user_name_relation', 'r_type', 'r_date'
                        ),
                        $where,
                        __METHOD__,
@@ -638,11 +645,12 @@
                        }
 
                        $user_name_short = $wgLang->truncate( 
$row->r_user_name, 25 );
+                       $unixTS = wfTimestamp( TS_UNIX, $row->r_date );
 
                        
$this->items_grouped[$r_type][$row->r_user_name_relation]['users'][$row->r_user_name][]
 = array(
                                'id' => $row->r_id,
                                'type' => $r_type,
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'pagetitle' => '',
                                'namespace' => '',
                                'username' => $user_name_short,
@@ -653,12 +661,12 @@
                        );
 
                        // set last timestamp
-                       
$this->items_grouped[$r_type][$row->r_user_name_relation]['timestamp'] = 
$row->item_date;
+                       
$this->items_grouped[$r_type][$row->r_user_name_relation]['timestamp'] = 
$unixTS;
 
                        $this->items[] = array(
                                'id' => $row->r_id,
                                'type' => $r_type,
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'pagetitle' => '',
                                'namespace' => '',
                                'username' => $row->r_user_name,
@@ -709,8 +717,7 @@
                        'user_board',
                        array(
                                'ub_id', 'ub_user_id', 'ub_user_name', 
'ub_user_id_from',
-                               'ub_user_name_from', 'UNIX_TIMESTAMP(ub_date) 
AS item_date',
-                               'ub_message'
+                               'ub_user_name_from', 'ub_date', 'ub_message'
                        ),
                        $where,
                        __METHOD__,
@@ -730,10 +737,12 @@
 
                        $to = stripslashes( $row->ub_user_name );
                        $from = stripslashes( $row->ub_user_name_from );
+                       $unixTS = wfTimestamp( TS_UNIX, $row->ub_date );
+
                        
$this->items_grouped['user_message'][$to]['users'][$from][] = array(
                                'id' => $row->ub_id,
                                'type' => 'user_message',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'pagetitle' => '',
                                'namespace' => '',
                                'username' => $from,
@@ -744,12 +753,12 @@
                        );
 
                        // set last timestamp
-                       $this->items_grouped['user_message'][$to]['timestamp'] 
= $row->item_date;
+                       $this->items_grouped['user_message'][$to]['timestamp'] 
= $unixTS;
 
                        $this->items[] = array(
                                'id' => $row->ub_id,
                                'type' => 'user_message',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'pagetitle' => '',
                                'namespace' => $this->fixItemComment( 
$row->ub_message ),
                                'username' => $from,
@@ -801,7 +810,7 @@
                        'user_system_messages',
                        array(
                                'um_id', 'um_user_id', 'um_user_name', 
'um_type', 'um_message',
-                               'UNIX_TIMESTAMP(um_date) AS item_date'
+                               'um_date'
                        ),
                        $where,
                        __METHOD__,
@@ -815,17 +824,18 @@
                foreach ( $res as $row ) {
                        $user_title = Title::makeTitle( NS_USER, 
$row->um_user_name );
                        $user_name_short = $wgLang->truncate( 
$row->um_user_name, 15 );
+                       $unixTS = wfTimestamp( TS_UNIX, $row->um_date );
 
                        $this->activityLines[] = array(
                                'type' => 'system_message',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'data' => ' ' . '<b><a href="' . 
htmlspecialchars( $user_title->getFullURL() ) . "\">{$user_name_short}</a></b> 
{$row->um_message}"
                        );
 
                        $this->items[] = array(
                                'id' => $row->um_id,
                                'type' => 'system_message',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'pagetitle' => '',
                                'namespace' => '',
                                'username' => $row->um_user_name,
@@ -880,8 +890,7 @@
                        'user_status',
                        array(
                                'us_id', 'us_user_id', 'us_user_name', 
'us_text',
-                               'UNIX_TIMESTAMP(us_date) AS item_date', 
'us_sport_id',
-                               'us_team_id'
+                               'us_date', 'us_sport_id', 'us_team_id'
                        ),
                        $where,
                        __METHOD__,
@@ -900,11 +909,12 @@
                                $sport = SportsTeams::getSport( 
$row->us_sport_id );
                                $network_name = $sport['name'];
                        }
+                       $unixTS = wfTimestamp( TS_UNIX, $row->us_date );
 
                        $this->items[] = array(
                                'id' => $row->us_id,
                                'type' => 'network_update',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'pagetitle' => '',
                                'namespace' => '',
                                'username' => $row->us_user_name,
@@ -937,7 +947,7 @@
 
                        $this->activityLines[] = array(
                                'type' => 'network_update',
-                               'timestamp' => $row->item_date,
+                               'timestamp' => $unixTS,
                                'data' => $html,
                        );
                }
diff --git a/UserBoard/UserBoardClass.php b/UserBoard/UserBoardClass.php
index 8b962a4..bc39c3f 100644
--- a/UserBoard/UserBoardClass.php
+++ b/UserBoard/UserBoardClass.php
@@ -308,7 +308,7 @@
                }
 
                $sql = "SELECT ub_id, ub_user_id_from, ub_user_name_from, 
ub_user_id, ub_user_name,
-                       ub_message,UNIX_TIMESTAMP(ub_date) AS unix_time,ub_type
+                       ub_message, ub_date, ub_type
                        FROM {$dbr->tableName( 'user_board' )}
                        WHERE {$user_sql}
                        ORDER BY ub_id DESC
@@ -324,7 +324,7 @@
 
                        $messages[] = array(
                                'id' => $row->ub_id,
-                               'timestamp' => ( $row->unix_time ),
+                               'timestamp' => wfTimestamp( TS_UNIX, 
$row->ub_date ),
                                'user_id_from' => $row->ub_user_id_from,
                                'user_name_from' => $row->ub_user_name_from,
                                'user_id' => $row->ub_user_id,
diff --git a/UserGifts/UserGiftsClass.php b/UserGifts/UserGiftsClass.php
index 075cac7..320f4dd 100644
--- a/UserGifts/UserGiftsClass.php
+++ b/UserGifts/UserGiftsClass.php
@@ -344,7 +344,7 @@
                        array(
                                'ug_id', 'ug_user_id_from', 
'ug_user_name_from', 'ug_gift_id',
                                'ug_date', 'ug_status', 'gift_name', 
'gift_description',
-                               'gift_given_count', 'UNIX_TIMESTAMP(ug_date) AS 
unix_time'
+                               'gift_given_count'
                        ),
                        array( "ug_user_id_to = {$this->user_id}" ),
                        __METHOD__,
@@ -357,14 +357,14 @@
                        $requests[] = array(
                                'id' => $row->ug_id,
                                'gift_id' => $row->ug_gift_id,
-                               'timestamp' => ( $row->ug_date ),
+                               'timestamp' => $row->ug_date,
                                'status' => $row->ug_status,
                                'user_id_from' => $row->ug_user_id_from,
                                'user_name_from' => $row->ug_user_name_from,
                                'gift_name' => $row->gift_name,
                                'gift_description' => $row->gift_description,
                                'gift_given_count' => $row->gift_given_count,
-                               'unix_timestamp' => $row->unix_time
+                               'unix_timestamp' => wfTimestamp( TS_UNIX, 
$row->ug_date )
                        );
                }
 
@@ -390,7 +390,7 @@
                        array(
                                'ug_id', 'ug_user_id_from', 
'ug_user_name_from', 'ug_gift_id',
                                'ug_date', 'ug_status', 'gift_name', 
'gift_description',
-                               'gift_given_count', 'UNIX_TIMESTAMP(ug_date) AS 
unix_time'
+                               'gift_given_count'
                        ),
                        array(),
                        __METHOD__,
@@ -403,14 +403,14 @@
                        $requests[] = array(
                                'id' => $row->ug_id,
                                'gift_id' => $row->ug_gift_id,
-                               'timestamp' => ( $row->ug_date ),
+                               'timestamp' => $row->ug_date,
                                'status' => $row->ug_status,
                                'user_id_from' => $row->ug_user_id_from,
                                'user_name_from' => $row->ug_user_name_from,
                                'gift_name' => $row->gift_name,
                                'gift_description' => $row->gift_description,
                                'gift_given_count' => $row->gift_given_count,
-                               'unix_timestamp' => $row->unix_time
+                               'unix_timestamp' => wfTimestamp( TS_UNIX, 
$row->ug_date )
                        );
                }
 
diff --git a/UserProfile/UserProfilePage.php b/UserProfile/UserProfilePage.php
index e563733..826687f 100644
--- a/UserProfile/UserProfilePage.php
+++ b/UserProfile/UserProfilePage.php
@@ -262,9 +262,7 @@
                        $dbr = wfGetDB( DB_SLAVE );
                        $res = $dbr->select(
                                array( 'poll_question', 'page' ),
-                               array(
-                                       'page_title', 
'UNIX_TIMESTAMP(poll_date) AS poll_date'
-                               ),
+                               array( 'page_title', 'poll_date' ),
                                /* WHERE */array( 'poll_user_id' => 
$this->user_id ),
                                __METHOD__,
                                array( 'ORDER BY' => 'poll_id DESC', 'LIMIT' => 
3 ),
@@ -273,7 +271,7 @@
                        foreach( $res as $row ) {
                                $polls[] = array(
                                        'title' => $row->page_title,
-                                       'timestamp' => $row->poll_date
+                                       'timestamp' => wfTimestamp( TS_UNIX, 
$row->poll_date )
                                );
                        }
                        $wgMemc->set( $key, $polls );
@@ -304,12 +302,10 @@
                        $dbr = wfGetDB( DB_SLAVE );
                        $res = $dbr->select(
                                'quizgame_questions',
-                               array(
-                                       'q_id', 'q_text', 
'UNIX_TIMESTAMP(q_date) AS quiz_date'
-                               ),
+                               array( 'q_id', 'q_text', 'q_date' ),
                                array(
                                        'q_user_id' => $this->user_id,
-                                       'q_flag' => 0 // the same as 
QUIZGAME_FLAG_NONE
+                                       'q_flag' => 0 // the same as 
QuizGameHome::$FLAG_NONE
                                ),
                                __METHOD__,
                                array(
@@ -321,7 +317,7 @@
                                $quiz[] = array(
                                        'id' => $row->q_id,
                                        'text' => $row->q_text,
-                                       'timestamp' => $row->quiz_date
+                                       'timestamp' => wfTimestamp( TS_UNIX, 
$row->q_date )
                                );
                        }
                        $wgMemc->set( $key, $quiz );
@@ -352,13 +348,10 @@
                        $dbr = wfGetDB( DB_SLAVE );
                        $res = $dbr->select(
                                'picturegame_images',
-                               array(
-                                       'id', 'title', 'img1', 'img2',
-                                       'UNIX_TIMESTAMP(pg_date) AS 
pic_game_date'
-                               ),
+                               array( 'id', 'title', 'img1', 'img2', 'pg_date' 
),
                                array(
                                        'userid' => $this->user_id,
-                                       'flag' => 0 // PICTUREGAME_FLAG_NONE
+                                       'flag' => 0 // 
PictureGameHome::$FLAG_NONE
                                ),
                                __METHOD__,
                                array(
@@ -372,7 +365,7 @@
                                        'title' => $row->title,
                                        'img1' => $row->img1,
                                        'img2' => $row->img2,
-                                       'timestamp' => $row->pic_game_date
+                                       'timestamp' => wfTimestamp( TS_UNIX, 
$row->pg_date )
                                );
                        }
                        $wgMemc->set( $key, $pics );

-- 
To view, visit https://gerrit.wikimedia.org/r/332672
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba1efb85a27fe166ab30ae65371d45e49f9a980f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SocialProfile
Gerrit-Branch: master
Gerrit-Owner: Jack Phoenix <j...@countervandalism.net>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to