fixed subtle bug -- missing comma in SQL causing watchlist to display user page link...
[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 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 $showhide = array( wfMsg( "show" ), wfMsg( "hide" ));
55
56 if ( ! isset( $hideminor ) ) {
57 $hideminor = $wgUser->getOption( "hideminor" );
58 }
59 $hideminor = ($hideminor ? 1 : 0);
60 if ( $hideminor ) {
61 $hidem = "AND rc_minor=0";
62 } else {
63 $hidem = "";
64 }
65
66 if ( !isset( $hidebots ) ) {
67 $hidebots = 1;
68 }
69 if( $hidebots ) {
70 $hidem .= " AND rc_bot=0";
71 }
72 $hidebots = ($hidebots ? 1 : 0);
73
74 if ( !isset( $hideliu ) ) {
75 $hideliu = 0;
76 }
77 if ( $hideliu ) {
78 $hidem .= " AND rc_user=0";
79 }
80 $hideliu = ($hideliu ? 1 : 0);
81 #$hideparams = "hideminor={$hideminor}&hideliu={$hideliu}&hidebots={$hidebots}";
82 $urlparams = array( "hideminor" => $hideminor, "hideliu" => $hideliu, "hidebots" => $hidebots );
83 $hideparams = wfArrayToCGI( $urlparams );
84
85 $minorLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
86 $showhide[1-$hideminor], wfArrayToCGI( array( "hideminor" => 1-$hideminor ), $urlparams ) );
87 $botLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
88 $showhide[1-$hidebots], wfArrayToCGI( array( "hidebots" => 1-$hidebots ), $urlparams ) );
89 $liuLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
90 $showhide[1-$hideliu], wfArrayToCGI( array( "hideliu" => 1-$hideliu ), $urlparams ) );
91
92 $uid = $wgUser->getID();
93 $sql2 = "SELECT recentchanges.*" . ($uid ? ",wl_user" : "") . " FROM recentchanges " .
94 ($uid ? "LEFT OUTER JOIN watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
95 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
96 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
97
98 $res = wfQuery( $sql2, DB_READ, $fname );
99 $rows = array();
100 while( $row = wfFetchObject( $res ) ){
101 $rows[] = $row;
102 }
103
104 if(isset($from)) {
105 $note = wfMsg( "rcnotefrom", $limit,
106 $wgLang->timeanddate( $from, true ) );
107 } else {
108 $note = wfMsg( "rcnote", $limit, $days );
109 }
110 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
111
112 $note = rcDayLimitLinks( $days, $limit, "Recentchanges", $hideparams, false, $minorLink, $botLink, $liuLink );
113
114 $note .= "<br>\n" . wfMsg( "rclistfrom",
115 $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
116 $wgLang->timeanddate( $now, true ), "{$hideparams}&from=$now" ) );
117
118 $wgOut->addHTML( "{$note}\n" );
119
120 $s = $sk->beginRecentChangesList();
121 foreach( $rows as $obj ){
122 if( $limit == 0) {
123 break;
124 }
125
126 if ( ! ( $hideminor && $obj->rc_minor ) ) {
127 $rc = RecentChange::newFromRow( $obj );
128 $s .= $sk->recentChangesLine( $rc, $obj->wl_user );
129 --$limit;
130 }
131 }
132 $s .= $sk->endRecentChangesList();
133
134 wfFreeResult( $res );
135 $wgOut->addHTML( $s );
136 }
137
138 function rcCountLink( $lim, $d, $page="Recentchanges", $more="" )
139 {
140 global $wgUser, $wgLang;
141 $sk = $wgUser->getSkin();
142 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
143 ($lim ? "{$lim}" : wfMsg( "all" ) ), "{$more}" .
144 ($d ? "days={$d}&" : "") . "limit={$lim}" );
145 return $s;
146 }
147
148 function rcDaysLink( $lim, $d, $page="Recentchanges", $more="" )
149 {
150 global $wgUser, $wgLang;
151 $sk = $wgUser->getSkin();
152 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
153 ($d ? "{$d}" : wfMsg( "all" ) ), "{$more}days={$d}" .
154 ($lim ? "&limit={$lim}" : "") );
155 return $s;
156 }
157
158 function rcDayLimitLinks( $days, $limit, $page="Recentchanges", $more="", $doall = false, $minorLink = "",
159 $botLink = "", $liuLink = "" )
160 {
161 if ($more != "") $more .= "&";
162 $cl = rcCountLink( 50, $days, $page, $more ) . " | " .
163 rcCountLink( 100, $days, $page, $more ) . " | " .
164 rcCountLink( 250, $days, $page, $more ) . " | " .
165 rcCountLink( 500, $days, $page, $more ) .
166 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
167 $dl = rcDaysLink( $limit, 1, $page, $more ) . " | " .
168 rcDaysLink( $limit, 3, $page, $more ) . " | " .
169 rcDaysLink( $limit, 7, $page, $more ) . " | " .
170 rcDaysLink( $limit, 14, $page, $more ) . " | " .
171 rcDaysLink( $limit, 30, $page, $more ) .
172 ( $doall ? ( " | " . rcDaysLink( $limit, 0, $page, $more ) ) : "" );
173 $shm = wfMsg( "showhideminor", $minorLink, $botLink, $liuLink );
174 $note = wfMsg( "rclinks", $cl, $dl, $shm );
175 return $note;
176 }
177
178 # Obsolete? Isn't called from anywhere and $mlink isn't defined
179 function rcLimitLinks( $page="Recentchanges", $more="", $doall = false )
180 {
181 if ($more != "") $more .= "&";
182 $cl = rcCountLink( 50, 0, $page, $more ) . " | " .
183 rcCountLink( 100, 0, $page, $more ) . " | " .
184 rcCountLink( 250, 0, $page, $more ) . " | " .
185 rcCountLink( 500, 0, $page, $more ) .
186 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
187 $note = wfMsg( "rclinks", $cl, "", $mlink );
188 return $note;
189 }
190
191 ?>