r52461 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52460‎ | r52461 | r52462 >
Date:14:28, 26 June 2009
Author:werdna
Status:deferred
Tags:
Comment:
Deprecate the LiquidThreads Date class
Modified paths:
  • /trunk/extensions/LiquidThreads/LiquidThreads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/LqtDate.php (deleted) (history)
  • /trunk/extensions/LiquidThreads/classes/LqtThread.php (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/TalkpageArchiveView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/LqtDate.php
@@ -1,102 +0,0 @@
2 -<?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die;
4 -
5 -class Date {
6 - public $year, $month, $day, $hour, $minute, $second;
7 -
8 - // ex. "20070530033751"
9 - function __construct( $text ) {
10 - if ( !strlen( $text ) == 14 || !ctype_digit( $text ) ) {
11 - $this->isValid = false;
12 - return null;
13 - }
14 - $this->year = intval( substr( $text, 0, 4 ) );
15 - $this->month = intval( substr( $text, 4, 2 ) );
16 - $this->day = intval( substr( $text, 6, 2 ) );
17 - $this->hour = intval( substr( $text, 8, 2 ) );
18 - $this->minute = intval( substr( $text, 10, 2 ) );
19 - $this->second = intval( substr( $text, 12, 2 ) );
20 - }
21 -
22 - function lastMonth() {
23 - return $this->moved( '-1 month' );
24 - }
25 -
26 - function nextMonth() {
27 - return $this->moved( '+1 month' );
28 - }
29 -
30 - function moved( $str ) {
31 - // Try to set local timezone to attempt to avoid E_STRICT errors.
32 - global $wgLocaltimezone;
33 - if ( isset( $wgLocaltimezone ) ) {
34 - $oldtz = getenv( "TZ" );
35 - putenv( "TZ=$wgLocaltimezone" );
36 - }
37 - // Suppress warnings for installations without a set timezone.
38 - wfSuppressWarnings();
39 - // Make the date string.
40 - $date = date( 'YmdHis', strtotime( $this->text() . ' ' . $str ) );
41 - // Restore warnings, date no loner an issue.
42 - wfRestoreWarnings();
43 - // Generate the date object,
44 - $date = new Date( $date );
45 - // Restore the old timezone if needed.
46 - if ( isset( $wgLocaltimezone ) ) {
47 - putenv( "TZ=$oldtz" );
48 - }
49 - // Return the generated date object.
50 - return $date;
51 - }
52 -
53 - static function monthString( $text ) {
54 - return substr( $text, 0, 6 );
55 - }
56 -
57 - function delta( $o ) {
58 - $t = clone $this;
59 - $els = array( 'year', 'month', 'day', 'hour', 'minute', 'second' );
60 - $deltas = array();
61 - foreach ( $els as $e ) { $deltas[$e] = $t->$e - $o->$e;
62 - $t->$e += $t->$e - $o->$e;
63 - }
64 -
65 - // format in style of date().
66 - $result = "";
67 - foreach ( $deltas as $name => $val ) {
68 - $result .= "$val $name ";
69 - }
70 - return $result;
71 - }
72 -
73 - static function beginningOfMonth( $yyyymm ) { return $yyyymm . '00000000'; }
74 -
75 - static function endOfMonth( $yyyymm ) { return $yyyymm . '31235959'; }
76 -
77 - function text() {
78 - return sprintf( '%04d%02d%02d%02d%02d%02d', $this->year, $this->month, $this->day,
79 - $this->hour, $this->minute, $this->second );
80 - }
81 -
82 - static function now() {
83 - return new Date( wfTimestampNow() );
84 - }
85 -
86 - function nDaysAgo( $n ) {
87 - return $this->moved( "-$n days" );
88 - }
89 -
90 - function midnight() {
91 - $d = clone $this;
92 - $d->hour = $d->minute = $d->second = 0;
93 - return $d;
94 - }
95 -
96 - function isBefore( $d ) {
97 - foreach ( array( 'year', 'month', 'day', 'hour', 'minute', 'second' ) as $part ) {
98 - if ( $this->$part < $d->$part ) return true;
99 - if ( $this->$part > $d->$part ) return false;
100 - }
101 - return true; // exactly the same time; arguable.
102 - }
103 -}
Index: trunk/extensions/LiquidThreads/classes/LqtThread.php
@@ -781,10 +781,10 @@
782782 function isArchiveEligible( ) {
783783 $startDays = $this->getArchiveStartDays();
784784
785 - $timestamp = new Date( $this->modified() );
786 - $archiveCutoff = Date::now()->nDaysAgo( $startDays );
 785+ $timestamp = wfTimestamp( TS_UNIX, $this->modified() );
 786+ $archiveCutoff = time() - $startDays * 86400;
787787
788 - return $timestamp->isBefore( $archiveCutoff ) // X days must have elapsed
 788+ return $timestamp < $archiveCutoff // X days must have elapsed
789789 && !$this->hasSuperthread() // Must be a primary thread (i.e. not a reply)
790790 && !$this->isHistorical(); // Can't have already been archived, obviously
791791 }
Index: trunk/extensions/LiquidThreads/pages/TalkpageArchiveView.php
@@ -106,9 +106,6 @@
107107 'thread_type' => Threads::TYPE_MOVED );
108108 $hasSummaryClause = $dbr->makeList( $hasSummaryClauses, LIST_OR );
109109
110 - $startDays = Threads::getArticleArchiveStartDays( $this->article );
111 - $startdate = Date::now()->nDaysAgo( $startDays )->midnight();
112 -
113110 $queryInfo =
114111 array(
115112 'tables' => array( 'thread', 'page', 'revision' ),
Index: trunk/extensions/LiquidThreads/LiquidThreads.php
@@ -65,7 +65,6 @@
6666 // Classes
6767 $wgAutoloadClasses['LqtDispatch'] = $dir . 'classes/LqtDispatch.php';
6868 $wgAutoloadClasses['LqtView'] = $dir . 'classes/LqtView.php';
69 -$wgAutoloadClasses['Date'] = $dir . 'classes/LqtDate.php';
7069 $wgAutoloadClasses['Post'] = $dir . 'classes/LqtPost.php';
7170 $wgAutoloadClasses['ThreadHistoryIterator'] = $dir . 'classes/LqtThreadHistoryIterator.php';
7271 $wgAutoloadClasses['HistoricalThread'] = $dir . 'classes/LqtHistoricalThread.php';

Status & tagging log