Index: trunk/phase3/includes/db/DatabaseMysql.php |
— | — | @@ -474,6 +474,9 @@ |
475 | 475 | $this->query( "SET sql_big_selects=$encValue", __METHOD__ ); |
476 | 476 | } |
477 | 477 | |
| 478 | + public function unixTimestamp( $field ) { |
| 479 | + return "UNIX_TIMESTAMP($field)"; |
| 480 | + } |
478 | 481 | |
479 | 482 | /** |
480 | 483 | * Determines if the last failure was due to a deadlock |
Index: trunk/phase3/includes/db/DatabaseOracle.php |
— | — | @@ -839,6 +839,10 @@ |
840 | 840 | return 'SELECT * ' . ( $all ? '':'/* UNION_UNIQUE */ ' ) . 'FROM (' . implode( $glue, $sqls ) . ')' ; |
841 | 841 | } |
842 | 842 | |
| 843 | + public function unixTimestamp( $field ) { |
| 844 | + return "((trunc($field) - to_date('19700101','YYYYMMDD')) * 86400)"; |
| 845 | + } |
| 846 | + |
843 | 847 | function wasDeadlock() { |
844 | 848 | return $this->lastErrno() == 'OCI-00060'; |
845 | 849 | } |
Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -1989,6 +1989,16 @@ |
1990 | 1990 | } |
1991 | 1991 | |
1992 | 1992 | /** |
| 1993 | + * Convert a field to an unix timestamp |
| 1994 | + * |
| 1995 | + * @param $field String: field name |
| 1996 | + * @return String: SQL statement |
| 1997 | + */ |
| 1998 | + public function unixTimestamp( $field ) { |
| 1999 | + return "EXTRACT(epoch FROM $field)"; |
| 2000 | + } |
| 2001 | + |
| 2002 | + /** |
1993 | 2003 | * Determines if the last failure was due to a deadlock |
1994 | 2004 | * STUB |
1995 | 2005 | */ |
Index: trunk/phase3/includes/db/DatabaseMssql.php |
— | — | @@ -787,6 +787,10 @@ |
788 | 788 | return false; |
789 | 789 | } |
790 | 790 | |
| 791 | + public function unixTimestamp( $field ) { |
| 792 | + return "DATEDIFF(s,CONVERT(datetime,'1/1/1970'),$field)"; |
| 793 | + } |
| 794 | + |
791 | 795 | /** |
792 | 796 | * Begin a transaction, committing any previously open transaction |
793 | 797 | */ |
Index: trunk/phase3/includes/db/DatabaseSqlite.php |
— | — | @@ -431,6 +431,10 @@ |
432 | 432 | return implode( $glue, $sqls ); |
433 | 433 | } |
434 | 434 | |
| 435 | + public function unixTimestamp( $field ) { |
| 436 | + return $field; |
| 437 | + } |
| 438 | + |
435 | 439 | function wasDeadlock() { |
436 | 440 | return $this->lastErrno() == 5; // SQLITE_BUSY |
437 | 441 | } |
Index: trunk/phase3/includes/specials/SpecialUnusedimages.php |
— | — | @@ -40,25 +40,11 @@ |
41 | 41 | function isSyndicated() { return false; } |
42 | 42 | |
43 | 43 | function getSQL() { |
44 | | - global $wgCountCategorizedImagesAsUsed, $wgDBtype; |
| 44 | + global $wgCountCategorizedImagesAsUsed; |
| 45 | + |
45 | 46 | $dbr = wfGetDB( DB_SLAVE ); |
46 | 47 | |
47 | | - switch ($wgDBtype) { |
48 | | - case 'mysql': |
49 | | - $epoch = 'UNIX_TIMESTAMP(img_timestamp)'; |
50 | | - break; |
51 | | - case 'oracle': |
52 | | - $epoch = '((trunc(img_timestamp) - to_date(\'19700101\',\'YYYYMMDD\')) * 86400)'; |
53 | | - break; |
54 | | - case 'sqlite': |
55 | | - $epoch = 'img_timestamp'; |
56 | | - break; |
57 | | - case 'mssql': |
58 | | - $epoch = 'DATEDIFF(s,CONVERT(datetime,\'1/1/1970\'),img_timestamp)'; |
59 | | - break; |
60 | | - default: |
61 | | - $epoch = 'EXTRACT(epoch FROM img_timestamp)'; |
62 | | - } |
| 48 | + $epoch = $db->unixTimestamp( 'rev_timestamp' ); |
63 | 49 | |
64 | 50 | if ( $wgCountCategorizedImagesAsUsed ) { |
65 | 51 | list( $page, $image, $imagelinks, $categorylinks ) = $dbr->tableNamesN( 'page', 'image', 'imagelinks', 'categorylinks' ); |
Index: trunk/phase3/includes/specials/SpecialAncientpages.php |
— | — | @@ -39,32 +39,11 @@ |
40 | 40 | function isSyndicated() { return false; } |
41 | 41 | |
42 | 42 | function getSQL() { |
43 | | - global $wgDBtype; |
44 | 43 | $db = wfGetDB( DB_SLAVE ); |
45 | 44 | $page = $db->tableName( 'page' ); |
46 | 45 | $revision = $db->tableName( 'revision' ); |
| 46 | + $epoch = $db->unixTimestamp( 'rev_timestamp' ); |
47 | 47 | |
48 | | - switch ($wgDBtype) { |
49 | | - case 'mysql': |
50 | | - $epoch = 'UNIX_TIMESTAMP(rev_timestamp)'; |
51 | | - break; |
52 | | - case 'ibm_db2': |
53 | | - // TODO implement proper conversion to a Unix epoch |
54 | | - $epoch = 'rev_timestamp'; |
55 | | - break; |
56 | | - case 'oracle': |
57 | | - $epoch = '((trunc(rev_timestamp) - to_date(\'19700101\',\'YYYYMMDD\')) * 86400)'; |
58 | | - break; |
59 | | - case 'sqlite': |
60 | | - $epoch = 'rev_timestamp'; |
61 | | - break; |
62 | | - case 'mssql': |
63 | | - $epoch = 'DATEDIFF(s,CONVERT(datetime,\'1/1/1970\'),rev_timestamp)'; |
64 | | - break; |
65 | | - default: |
66 | | - $epoch = 'EXTRACT(epoch FROM rev_timestamp)'; |
67 | | - } |
68 | | - |
69 | 48 | return |
70 | 49 | "SELECT 'Ancientpages' as type, |
71 | 50 | page_namespace as namespace, |