Capitalization fix in memcached setting
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 require_once( 'Feed.php' );
12
13 /**
14 * Constructor
15 */
16 function wfSpecialRecentchanges( $par ) {
17 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgTitle, $wgMemc, $wgDBname;
18 global $wgRequest, $wgSitename, $wgLanguageCode, $wgContLanguageCode;
19 global $wgFeedClasses, $wgUseRCPatrol;
20 $fname = 'wfSpecialRecentchanges';
21
22 # Get query parameters
23 $feedFormat = $wgRequest->getVal( 'feed' );
24
25 $defaultDays = $wgUser->getOption( 'rcdays' );
26 if ( !$defaultDays ) { $defaultDays = 3; }
27
28 $days = $wgRequest->getInt( 'days', $defaultDays );
29 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor' ) ) ? 1 : 0;
30 $from = $wgRequest->getText( 'from' );
31 $hidebots = $wgRequest->getBool( 'hidebots', true ) ? 1 : 0;
32 $hideliu = $wgRequest->getBool( 'hideliu', false ) ? 1 : 0;
33 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', false ) ? 1 : 0;
34
35 list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
36
37 # Get query parameters from path
38 if( $par ) {
39 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
40 if( in_array( 'hidebots', $bits ) ) $hidebots = 1;
41 if( in_array( 'bots', $bits ) ) $hidebots = 0;
42 if( in_array( 'hideminor', $bits ) ) $hideminor = 1;
43 if( in_array( 'minor', $bits ) ) $hideminor = 0;
44 if( in_array( 'hideliu', $bits) ) $hideliu = 1;
45 if( in_array( 'hidepatrolled', $bits) ) $hidepatrolled = 1;
46 }
47
48
49 # Database connection and caching
50 $dbr =& wfGetDB( DB_SLAVE );
51 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
52
53
54 # 10 seconds server-side caching max
55 $wgOut->setSquidMaxage( 10 );
56
57 # Get last modified date, for client caching
58 # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
59 if ( !$wgUseRCPatrol ) {
60 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
61 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
62 # Client cache fresh and headers sent, nothing more to do.
63 return;
64 }
65 }
66
67 # Output header
68 $rctext = wfMsg( "recentchangestext" );
69 $wgOut->addWikiText( $rctext );
70
71
72 $now = wfTimestampNow();
73 $cutoff_unixtime = time() - ( $days * 86400 );
74 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
75 $cutoff = $dbr->timestamp( $cutoff_unixtime );
76 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW,$cutoff)) {
77 $cutoff = $dbr->timestamp($from);
78 } else {
79 unset($from);
80 }
81
82 $sk = $wgUser->getSkin();
83
84 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
85
86 $hidem = ( $hideminor ) ? 'AND rc_minor=0' : '';
87 $hidem .= ( $hidebots ) ? ' AND rc_bot=0' : '';
88 $hidem .= ( $hideliu ) ? ' AND rc_user=0' : '';
89 $hidem .= ( $hidepatrolled )? ' AND rc_patrolled=0' : '';
90
91 $urlparams = array( 'hideminor' => $hideminor, 'hideliu' => $hideliu,
92 'hidebots' => $hidebots, 'hidepatrolled' => $hidepatrolled,
93 'limit' => $limit );
94 $hideparams = wfArrayToCGI( $urlparams );
95
96 $minorLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
97 $showhide[1-$hideminor], wfArrayToCGI( array( 'hideminor' => 1-$hideminor ), $urlparams ) );
98 $botLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
99 $showhide[1-$hidebots], wfArrayToCGI( array( 'hidebots' => 1-$hidebots ), $urlparams ) );
100 $liuLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
101 $showhide[1-$hideliu], wfArrayToCGI( array( 'hideliu' => 1-$hideliu ), $urlparams ) );
102 $patrLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
103 $showhide[1-$hidepatrolled], wfArrayToCGI( array( 'hidepatrolled' => 1-$hidepatrolled ), $urlparams ) );
104
105 $uid = $wgUser->getID();
106 $sql2 = "SELECT $recentchanges.*" . ($uid ? ",wl_user" : "") . " FROM $recentchanges " .
107 ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
108 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
109 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
110
111 $res = $dbr->query( $sql2, DB_SLAVE, $fname );
112 $rows = array();
113 while( $row = $dbr->fetchObject( $res ) ){
114 $rows[] = $row;
115 }
116 $dbr->freeResult( $res );
117
118 if(isset($from)) {
119 $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $limit ),
120 $wgLang->timeanddate( $from, true ) );
121 } else {
122 $note = wfMsg( 'rcnote', $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
123 }
124 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
125
126 $note = rcDayLimitLinks( $days, $limit, 'Recentchanges', $hideparams, false, $minorLink, $botLink, $liuLink, $patrLink );
127
128 $note .= "<br />\n" . wfMsg( 'rclistfrom',
129 $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
130 $wgLang->timeanddate( $now, true ), $hideparams.'&from='.$now ) );
131
132 $wgOut->addHTML( $note."\n" );
133
134 if( isset($wgFeedClasses[$feedFormat]) ) {
135 $feed = new $wgFeedClasses[$feedFormat](
136 $wgSitename . ' - ' . wfMsg( 'recentchanges' ) . ' [' . $wgContLanguageCode . ']',
137 htmlspecialchars( wfMsg( 'recentchangestext' ) ),
138 $wgTitle->getFullUrl() );
139 $feed->outHeader();
140
141 # Merge adjacent edits by one user
142 $sorted = array();
143 $n = 0;
144 foreach( $rows as $obj ) {
145 if( $n > 0 &&
146 $obj->rc_namespace >= 0 &&
147 $obj->rc_cur_id == $sorted[$n-1]->rc_cur_id &&
148 $obj->rc_user_text == $sorted[$n-1]->rc_user_text ) {
149 $sorted[$n-1]->rc_last_oldid = $obj->rc_last_oldid;
150 } else {
151 $sorted[$n] = $obj;
152 $n++;
153 }
154 $first = false;
155 }
156
157 foreach( $sorted as $obj ) {
158 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
159 $talkpage = $title->getTalkPage();
160 $item = new FeedItem(
161 $title->getPrefixedText(),
162 rcFormatDiff( $obj ),
163 $title->getFullURL(),
164 $obj->rc_timestamp,
165 $obj->rc_user_text,
166 $talkpage->getFullURL()
167 );
168 $feed->outItem( $item );
169 }
170 $feed->outFooter();
171 } else {
172 $wgOut->setSyndicated( true );
173 $s = $sk->beginRecentChangesList();
174 $counter = 1;
175 foreach( $rows as $obj ){
176 if( $limit == 0) {
177 break;
178 }
179
180 if ( ! ( $hideminor && $obj->rc_minor ) &&
181 ! ( $hidepatrolled && $obj->rc_patrolled ) ) {
182 $rc = RecentChange::newFromRow( $obj );
183 $rc->counter = $counter++;
184 $s .= $sk->recentChangesLine( $rc, !empty( $obj->wl_user ) );
185 --$limit;
186 }
187 }
188 $s .= $sk->endRecentChangesList();
189 $wgOut->addHTML( $s );
190 }
191 }
192
193 /**
194 *
195 */
196 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
197 global $wgUser, $wgLang, $wgContLang;
198 $sk = $wgUser->getSkin();
199 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
200 ($lim ? $wgLang->formatNum( "{$lim}" ) : wfMsg( 'all' ) ), "{$more}" .
201 ($d ? "days={$d}&" : '') . 'limit='.$lim );
202 return $s;
203 }
204
205 /**
206 *
207 */
208 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
209 global $wgUser, $wgLang, $wgContLang;
210 $sk = $wgUser->getSkin();
211 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
212 ($d ? $wgLang->formatNum( "{$d}" ) : wfMsg( "all" ) ), $more.'days='.$d .
213 ($lim ? '&limit='.$lim : '') );
214 return $s;
215 }
216
217 /**
218 *
219 */
220 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
221 $botLink = '', $liuLink = '', $patrLink = '' ) {
222 if ($more != '') $more .= '&';
223 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
224 rcCountLink( 100, $days, $page, $more ) . ' | ' .
225 rcCountLink( 250, $days, $page, $more ) . ' | ' .
226 rcCountLink( 500, $days, $page, $more ) .
227 ( $doall ? ( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
228 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
229 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
230 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
231 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
232 rcDaysLink( $limit, 30, $page, $more ) .
233 ( $doall ? ( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
234 $shm = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink );
235 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
236 return $note;
237 }
238
239 /**
240 * Obsolete? Isn't called from anywhere and $mlink isn't defined
241 */
242 function rcLimitLinks( $page='Recentchanges', $more='', $doall = false ) {
243 if ($more != '') $more .= '&';
244 $cl = rcCountLink( 50, 0, $page, $more ) . ' | ' .
245 rcCountLink( 100, 0, $page, $more ) . ' | ' .
246 rcCountLink( 250, 0, $page, $more ) . ' | ' .
247 rcCountLink( 500, 0, $page, $more ) .
248 ( $doall ? ( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
249 $note = wfMsg( 'rclinks', $cl, '', $mlink );
250 return $note;
251 }
252
253 function rcFormatDiff( $row ) {
254 require_once( 'DifferenceEngine.php' );
255 $comment = "<p>" . htmlspecialchars( $row->rc_comment ) . "</p>\n";
256
257 if( $row->rc_namespace >= 0 ) {
258 global $wgContLang;
259
260 #$diff =& new DifferenceEngine( $row->rc_this_oldid, $row->rc_last_oldid, $row->rc_id );
261 #$diff->showDiffPage();
262
263 $dbr =& wfGetDB( DB_SLAVE );
264 if( $row->rc_this_oldid ) {
265 $newrow = $dbr->selectRow( 'old',
266 array( 'old_flags', 'old_text' ),
267 array( 'old_id' => $row->rc_this_oldid ) );
268 $newtext = Article::getRevisionText( $newrow );
269 } else {
270 $newrow = $dbr->selectRow( 'cur',
271 array( 'cur_text' ),
272 array( 'cur_id' => $row->rc_cur_id ) );
273 $newtext = $newrow->cur_text;
274 }
275 if( $row->rc_last_oldid ) {
276 $oldrow = $dbr->selectRow( 'old',
277 array( 'old_flags', 'old_text' ),
278 array( 'old_id' => $row->rc_last_oldid ) );
279 $oldtext = Article::getRevisionText( $oldrow );
280 $diffText = DifferenceEngine::getDiff( $oldtext, $newtext,
281 wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp ) ),
282 wfMsg( 'currentrev' ) );
283 } else {
284 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
285 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
286 }
287
288 return $comment . $diffText;
289 }
290
291 return $comment;
292 }
293
294 ?>