Date/time fixes: try to ensure that timestamps are always kept in GMT, with conversio...
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
1 <?
2
3 function wfSpecialRecentchanges()
4 {
5 global $wgUser, $wgOut, $wgLang, $wgTitle;
6 global $days, $hideminor, $from, $hidebots; # From query string
7 $fname = "wfSpecialRecentchanges";
8
9 $sql = "SELECT MAX(rc_timestamp) AS lastmod FROM recentchanges";
10 $res = wfQuery( $sql, $fname );
11 $s = wfFetchObject( $res );
12 $wgOut->checkLastModified( $s->lastmod );
13
14 $rctext = wfMsg( "recentchangestext" );
15 $sql = "SELECT cur_text FROM cur WHERE cur_namespace=4 AND cur_title='Recentchanges'";
16 $res = wfQuery( $sql, $fname );
17 if( ( $s = wfFetchObject( $res ) ) and ( $s->cur_text != "" ) ) {
18 $rctext = $s->cur_text;
19 }
20 $wgOut->addWikiText( $rctext );
21
22 if ( ! $days ) {
23 $days = $wgUser->getOption( "rcdays" );
24 if ( ! $days ) { $days = 3; }
25 }
26 $days = (int)$days;
27 list( $limit, $offset ) = wfCheckLimits( 100, "rclimit" );
28 $now = wfTimestampNow();
29 $cutoff = wfUnix2Timestamp( time() - ( $days * 86400 ) );
30 if(preg_match('/^[0-9]{14}$/', $from) and $from > $cutoff) {
31 $cutoff = $from;
32 } else {
33 unset($from);
34 }
35
36 $sk = $wgUser->getSkin();
37
38 if ( ! isset( $hideminor ) ) {
39 $hideminor = $wgUser->getOption( "hideminor" );
40 }
41 if ( $hideminor ) {
42 $hidem = "AND rc_minor=0";
43 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
44 WfMsg( "show" ), "days={$days}&limit={$limit}&hideminor=0" );
45 } else {
46 $hidem = "";
47 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
48 WfMsg( "hide" ), "days={$days}&limit={$limit}&hideminor=1" );
49 }
50
51 if ( !isset( $hidebots ) ) {
52 $hidebots = 1;
53 }
54 if( $hidebots ) {
55 $hidem .= " AND rc_bot=0";
56 }
57
58 $uid = $wgUser->getID();
59 $sql2 = "SELECT rc_cur_id,rc_namespace,rc_title,rc_user,rc_new," .
60 "rc_comment,rc_user_text,rc_timestamp,rc_minor,rc_this_oldid,rc_last_oldid,rc_bot" . ($uid ? ",wl_user" : "") . " FROM recentchanges " .
61 ($uid ? "LEFT OUTER JOIN watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
62 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
63 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
64 $res = wfQuery( $sql2, $fname );
65
66 if(isset($from)) {
67 $note = wfMsg( "rcnotefrom", $limit,
68 $wgLang->timeanddate( $from, true ) );
69 } else {
70 $note = wfMsg( "rcnote", $limit, $days );
71 }
72 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
73
74 $note = rcDayLimitLinks( $days, $limit );
75
76 $note .= "<br>\n" . wfMsg( "rclistfrom",
77 $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
78 $wgLang->timeanddate( $now, true ), "from=$now" ) );
79
80 $wgOut->addHTML( "{$note}\n" );
81
82 $count1 = wfNumRows( $res );
83 $obj1 = wfFetchObject( $res );
84
85 $s = $sk->beginRecentChangesList();
86 while ( $limit ) {
87 if ( ( 0 == $count1 ) ) { break; }
88
89 $ts = $obj1->rc_timestamp;
90 $u = $obj1->rc_user;
91 $ut = $obj1->rc_user_text;
92 $ns = $obj1->rc_namespace;
93 $ttl = $obj1->rc_title;
94 $com = $obj1->rc_comment;
95 $me = ( $obj1->rc_minor > 0 );
96 $new = ( $obj1->rc_new > 0 );
97 $watched = ($obj1->wl_user > 0);
98 $oldid = $obj1->rc_this_oldid ;
99 $diffid = $obj1->rc_last_oldid ;
100
101 $obj1 = wfFetchObject( $res );
102 --$count1;
103 if ( ! ( $hideminor && $me ) ) {
104 $s .= $sk->recentChangesLine( $ts, $u, $ut, $ns, $ttl,
105 $com, $me, $new, $watched, $oldid , $diffid );
106 --$limit;
107 }
108 }
109 $s .= $sk->endRecentChangesList();
110
111 wfFreeResult( $res );
112 $wgOut->addHTML( $s );
113 }
114
115 function rcCountLink( $lim, $d, $page="Recentchanges", $more="" )
116 {
117 global $wgUser, $wgLang;
118 $sk = $wgUser->getSkin();
119 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
120 ($lim ? "{$lim}" : wfMsg( "all" ) ), "{$more}" .
121 ($d ? "days={$d}&" : "") . "limit={$lim}" );
122 return $s;
123 }
124
125 function rcDaysLink( $lim, $d, $page="Recentchanges", $more="" )
126 {
127 global $wgUser, $wgLang;
128 $sk = $wgUser->getSkin();
129 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
130 ($d ? "{$d}" : wfMsg( "all" ) ), "{$more}days={$d}" .
131 ($lim ? "&limit={$lim}" : "") );
132 return $s;
133 }
134
135 function rcDayLimitLinks( $days, $limit, $page="Recentchanges", $more="", $doall = false )
136 {
137 if ($more != "") $more .= "&";
138 $cl = rcCountLink( 50, $days, $page, $more ) . " | " .
139 rcCountLink( 100, $days, $page, $more ) . " | " .
140 rcCountLink( 250, $days, $page, $more ) . " | " .
141 rcCountLink( 500, $days, $page, $more ) .
142 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
143 $dl = rcDaysLink( $limit, 1, $page, $more ) . " | " .
144 rcDaysLink( $limit, 3, $page, $more ) . " | " .
145 rcDaysLink( $limit, 7, $page, $more ) . " | " .
146 rcDaysLink( $limit, 14, $page, $more ) . " | " .
147 rcDaysLink( $limit, 30, $page, $more ) .
148 ( $doall ? ( " | " . rcDaysLink( $limit, 0, $page, $more ) ) : "" );
149 $note = wfMsg( "rclinks", $cl, $dl, $mlink );
150 return $note;
151 }
152
153 function rcLimitLinks( $page="Recentchanges", $more="", $doall = false )
154 {
155 if ($more != "") $more .= "&";
156 $cl = rcCountLink( 50, 0, $page, $more ) . " | " .
157 rcCountLink( 100, 0, $page, $more ) . " | " .
158 rcCountLink( 250, 0, $page, $more ) . " | " .
159 rcCountLink( 500, 0, $page, $more ) .
160 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
161 $note = wfMsg( "rclinks", $cl, "", $mlink );
162 return $note;
163 }
164
165 ?>