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