Cutoff on midnight always, making successive queries identical. This means it can...
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
1 <?
2
3 function wfSpecialRecentchanges( $par )
4 {
5 global $wgUser, $wgOut, $wgLang, $wgTitle;
6 global $days, $hideminor, $from, $hidebots, $hideliu; # From query string
7 $fname = "wfSpecialRecentchanges";
8
9 if( $par ) {
10 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
11 if( in_array( "hidebots", $bits ) ) $hidebots = 1;
12 if( in_array( "bots", $bits ) ) $hidebots = 0;
13 if( in_array( "hideminor", $bits ) ) $hideminor = 1;
14 if( in_array( "minor", $bits ) ) $hideminor = 0;
15 if( in_array( "hideliu", $bits) ) $hideliu = 1;
16 }
17
18 $sql = "SELECT MAX(rc_timestamp) AS lastmod FROM recentchanges";
19 $res = wfQuery( $sql, DB_READ, $fname );
20 $s = wfFetchObject( $res );
21 if( $wgOut->checkLastModified( $s->lastmod ) ){
22 # Client cache fresh and headers sent, nothing more to do.
23 return;
24 }
25
26 $rctext = wfMsg( "recentchangestext" );
27
28 # The next few lines can probably be commented out now that wfMsg can get text from the DB
29 $sql = "SELECT cur_text FROM cur WHERE cur_namespace=4 AND cur_title='Recentchanges'";
30 $res = wfQuery( $sql, DB_READ, $fname );
31 if( ( $s = wfFetchObject( $res ) ) and ( $s->cur_text != "" ) ) {
32 $rctext = $s->cur_text;
33 }
34
35 $wgOut->addWikiText( $rctext );
36
37 if ( ! $days ) {
38 $days = $wgUser->getOption( "rcdays" );
39 if ( ! $days ) { $days = 3; }
40 }
41 $days = (int)$days;
42 list( $limit, $offset ) = wfCheckLimits( 100, "rclimit" );
43 $now = wfTimestampNow();
44 $cutoff_unixtime = time() - ( $days * 86400 );
45 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
46 $cutoff = wfUnix2Timestamp( $cutoff_unixtime );
47 if(preg_match('/^[0-9]{14}$/', $from) and $from > $cutoff) {
48 $cutoff = $from;
49 } else {
50 unset($from);
51 }
52
53 $sk = $wgUser->getSkin();
54
55 if ( ! isset( $hideminor ) ) {
56 $hideminor = $wgUser->getOption( "hideminor" );
57 }
58 $hideminor = ($hideminor ? 1 : 0);
59 if ( $hideminor ) {
60 $hidem = "AND rc_minor=0";
61 $mltitle = wfMsg( "show" );
62 $mlhide = 0;
63 } else {
64 $hidem = "";
65 $mltitle = wfMsg( "hide" );
66 $mlhide = 1;
67 }
68
69 if ( isset( $from ) ) {
70 $mlparams = "from={$from}&hideminor={$mlhide}";
71 } else {
72 $mlparams = "days={$days}&limit={$limit}&hideminor={$mlhide}";
73 }
74
75 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
76 $mltitle, $mlparams );
77
78 if ( !isset( $hidebots ) ) {
79 $hidebots = 1;
80 }
81 if( $hidebots ) {
82 $hidem .= " AND rc_bot=0";
83 }
84
85 if ( $hideliu ) {
86 $hidem .= " AND rc_user=0";
87 }
88
89 $uid = $wgUser->getID();
90 $sql2 = "SELECT recentchanges.*" . ($uid ? ",wl_user" : "") . " FROM recentchanges " .
91 ($uid ? "LEFT OUTER JOIN watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
92 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
93 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
94 $res = wfQuery( $sql2, DB_READ, $fname );
95
96 if(isset($from)) {
97 $note = wfMsg( "rcnotefrom", $limit,
98 $wgLang->timeanddate( $from, true ) );
99 } else {
100 $note = wfMsg( "rcnote", $limit, $days );
101 }
102 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
103
104 $note = rcDayLimitLinks( $days, $limit, "Recentchanges", "hideminor={$hideminor}", false, $mlink );
105
106 $note .= "<br>\n" . wfMsg( "rclistfrom",
107 $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
108 $wgLang->timeanddate( $now, true ), "hideminor={$hideminor}&from=$now" ) );
109
110 $wgOut->addHTML( "{$note}\n" );
111
112 $count1 = wfNumRows( $res );
113 $obj1 = wfFetchObject( $res );
114
115 $s = $sk->beginRecentChangesList();
116 while ( $limit ) {
117 if ( ( 0 == $count1 ) ) {
118 break;
119 }
120 if ( ! ( $hideminor && $obj1->rc_minor ) ) {
121 $rc = RecentChange::newFromRow( $obj1 );
122 $s .= $sk->recentChangesLine( $rc, $obj1->wl_user );
123 --$limit;
124 }
125 $obj1 = wfFetchObject( $res );
126 --$count1;
127 }
128 $s .= $sk->endRecentChangesList();
129
130 wfFreeResult( $res );
131 $wgOut->addHTML( $s );
132 }
133
134 function rcCountLink( $lim, $d, $page="Recentchanges", $more="" )
135 {
136 global $wgUser, $wgLang;
137 $sk = $wgUser->getSkin();
138 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
139 ($lim ? "{$lim}" : wfMsg( "all" ) ), "{$more}" .
140 ($d ? "days={$d}&" : "") . "limit={$lim}" );
141 return $s;
142 }
143
144 function rcDaysLink( $lim, $d, $page="Recentchanges", $more="" )
145 {
146 global $wgUser, $wgLang;
147 $sk = $wgUser->getSkin();
148 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
149 ($d ? "{$d}" : wfMsg( "all" ) ), "{$more}days={$d}" .
150 ($lim ? "&limit={$lim}" : "") );
151 return $s;
152 }
153
154 function rcDayLimitLinks( $days, $limit, $page="Recentchanges", $more="", $doall = false, $mlink = "" )
155 {
156 if ($more != "") $more .= "&";
157 $cl = rcCountLink( 50, $days, $page, $more ) . " | " .
158 rcCountLink( 100, $days, $page, $more ) . " | " .
159 rcCountLink( 250, $days, $page, $more ) . " | " .
160 rcCountLink( 500, $days, $page, $more ) .
161 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
162 $dl = rcDaysLink( $limit, 1, $page, $more ) . " | " .
163 rcDaysLink( $limit, 3, $page, $more ) . " | " .
164 rcDaysLink( $limit, 7, $page, $more ) . " | " .
165 rcDaysLink( $limit, 14, $page, $more ) . " | " .
166 rcDaysLink( $limit, 30, $page, $more ) .
167 ( $doall ? ( " | " . rcDaysLink( $limit, 0, $page, $more ) ) : "" );
168 $shm = wfMsg( "showhideminor", $mlink );
169 $note = wfMsg( "rclinks", $cl, $dl, $shm );
170 return $note;
171 }
172
173 function rcLimitLinks( $page="Recentchanges", $more="", $doall = false )
174 {
175 if ($more != "") $more .= "&";
176 $cl = rcCountLink( 50, 0, $page, $more ) . " | " .
177 rcCountLink( 100, 0, $page, $more ) . " | " .
178 rcCountLink( 250, 0, $page, $more ) . " | " .
179 rcCountLink( 500, 0, $page, $more ) .
180 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
181 $note = wfMsg( "rclinks", $cl, "", $mlink );
182 return $note;
183 }
184
185 ?>