Moved switches in Special:Unusedimages and Special:Ancientpages to extract a unix...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Wed, 24 Nov 2010 15:40:25 +0000 (15:40 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Wed, 24 Nov 2010 15:40:25 +0000 (15:40 +0000)
includes/db/Database.php
includes/db/DatabaseMssql.php
includes/db/DatabaseMysql.php
includes/db/DatabaseOracle.php
includes/db/DatabaseSqlite.php
includes/specials/SpecialAncientpages.php
includes/specials/SpecialUnusedimages.php

index c9a45e1..26d4d2b 100644 (file)
@@ -1988,6 +1988,16 @@ abstract class DatabaseBase implements DatabaseType {
                return "REPLACE({$orig}, {$old}, {$new})";
        }
 
+       /**
+        * Convert a field to an unix timestamp
+        *
+        * @param $field String: field name
+        * @return String: SQL statement
+        */
+       public function unixTimestamp( $field ) {
+               return "EXTRACT(epoch FROM $field)";
+       }
+
        /**
         * Determines if the last failure was due to a deadlock
         * STUB
index d525e2a..93c1cf2 100644 (file)
@@ -787,6 +787,10 @@ class DatabaseMssql extends DatabaseBase {
                return false;
        }
 
+       public function unixTimestamp( $field ) {
+               return "DATEDIFF(s,CONVERT(datetime,'1/1/1970'),$field)";
+       }
+
        /**
         * Begin a transaction, committing any previously open transaction
         */
index 10c6cf2..c4f0f47 100644 (file)
@@ -474,6 +474,9 @@ class DatabaseMysql extends DatabaseBase {
                $this->query( "SET sql_big_selects=$encValue", __METHOD__ );
        }
 
+       public function unixTimestamp( $field ) {
+               return "UNIX_TIMESTAMP($field)";
+       }
 
        /**
         * Determines if the last failure was due to a deadlock
index 33e1104..be974d6 100644 (file)
@@ -839,6 +839,10 @@ class DatabaseOracle extends DatabaseBase {
                return 'SELECT * ' . ( $all ? '':'/* UNION_UNIQUE */ ' ) . 'FROM (' . implode( $glue, $sqls ) . ')' ;
        }
 
+       public function unixTimestamp( $field ) {
+               return "((trunc($field) - to_date('19700101','YYYYMMDD')) * 86400)";
+       }
+
        function wasDeadlock() {
                return $this->lastErrno() == 'OCI-00060';
        }
index 4635d33..e29e1a4 100644 (file)
@@ -431,6 +431,10 @@ class DatabaseSqlite extends DatabaseBase {
                return implode( $glue, $sqls );
        }
 
+       public function unixTimestamp( $field ) {
+               return $field;
+       }
+
        function wasDeadlock() {
                return $this->lastErrno() == 5; // SQLITE_BUSY
        }
index 74251b7..2d5047d 100644 (file)
@@ -39,31 +39,10 @@ class AncientPagesPage extends QueryPage {
        function isSyndicated() { return false; }
 
        function getSQL() {
-               global $wgDBtype;
                $db = wfGetDB( DB_SLAVE );
                $page = $db->tableName( 'page' );
                $revision = $db->tableName( 'revision' );
-
-               switch ($wgDBtype) {
-                       case 'mysql': 
-                               $epoch = 'UNIX_TIMESTAMP(rev_timestamp)'; 
-                               break;
-                       case 'ibm_db2':
-                               // TODO implement proper conversion to a Unix epoch
-                               $epoch = 'rev_timestamp';
-                               break;
-                       case 'oracle': 
-                               $epoch = '((trunc(rev_timestamp) - to_date(\'19700101\',\'YYYYMMDD\')) * 86400)'; 
-                               break;
-                       case 'sqlite':
-                               $epoch = 'rev_timestamp';
-                               break;
-                       case 'mssql':
-                               $epoch = 'DATEDIFF(s,CONVERT(datetime,\'1/1/1970\'),rev_timestamp)';
-                               break;
-                       default:
-                               $epoch = 'EXTRACT(epoch FROM rev_timestamp)';
-               }
+               $epoch = $db->unixTimestamp( 'rev_timestamp' );
 
                return
                        "SELECT 'Ancientpages' as type,
index 88600e5..0bc1e1f 100644 (file)
@@ -40,25 +40,11 @@ class UnusedimagesPage extends ImageQueryPage {
        function isSyndicated() { return false; }
 
        function getSQL() {
-               global $wgCountCategorizedImagesAsUsed, $wgDBtype;
+               global $wgCountCategorizedImagesAsUsed;
+
                $dbr = wfGetDB( DB_SLAVE );
 
-               switch ($wgDBtype) {
-                       case 'mysql': 
-                               $epoch = 'UNIX_TIMESTAMP(img_timestamp)'; 
-                               break;
-                       case 'oracle': 
-                               $epoch = '((trunc(img_timestamp) - to_date(\'19700101\',\'YYYYMMDD\')) * 86400)'; 
-                               break;
-                       case 'sqlite':
-                               $epoch = 'img_timestamp';
-                               break;
-                       case 'mssql':
-                               $epoch = 'DATEDIFF(s,CONVERT(datetime,\'1/1/1970\'),img_timestamp)';
-                               break;
-                       default:
-                               $epoch = 'EXTRACT(epoch FROM img_timestamp)';
-               }
+               $epoch = $db->unixTimestamp( 'rev_timestamp' );
 
                if ( $wgCountCategorizedImagesAsUsed ) {
                        list( $page, $image, $imagelinks, $categorylinks ) = $dbr->tableNamesN( 'page', 'image', 'imagelinks', 'categorylinks' );