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