f5e6cf9aa4bed6f6a9fb091b5b32ed9fb11a3aab
5 * @subpackage SpecialPage
11 require_once( 'Feed.php' );
12 require_once( 'ChangesList.php' );
17 function wfSpecialRecentchanges( $par ) {
18 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgTitle, $wgMemc, $wgDBname;
19 global $wgRequest, $wgSitename, $wgLanguageCode, $wgContLanguageCode;
20 global $wgFeedClasses, $wgUseRCPatrol;
21 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
22 $fname = 'wfSpecialRecentchanges';
24 # Get query parameters
25 $feedFormat = $wgRequest->getVal( 'feed' );
27 $defaultDays = $wgUser->getOption( 'rcdays' );
28 if ( !$defaultDays ) { $defaultDays = 3; }
30 $days = $wgRequest->getInt( 'days', $defaultDays );
31 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor' ) ) ?
1 : 0;
32 list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
34 # As a feed, use limited settings only
41 if( $limit > $wgFeedLimit ) {
42 $limit = $wgFeedLimit;
45 $from = $wgRequest->getText( 'from' );
46 $hidebots = $wgRequest->getBool( 'hidebots', true ) ?
1 : 0;
47 $hideliu = $wgRequest->getBool( 'hideliu', false ) ?
1 : 0;
48 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', false ) ?
1 : 0;
50 # Get query parameters from path
52 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
53 if( in_array( 'hidebots', $bits ) ) $hidebots = 1;
54 if( in_array( 'bots', $bits ) ) $hidebots = 0;
55 if( in_array( 'hideminor', $bits ) ) $hideminor = 1;
56 if( in_array( 'minor', $bits ) ) $hideminor = 0;
57 if( in_array( 'hideliu', $bits) ) $hideliu = 1;
58 if( in_array( 'hidepatrolled', $bits) ) $hidepatrolled = 1;
63 # Database connection and caching
64 $dbr =& wfGetDB( DB_SLAVE
);
65 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
68 # 10 seconds server-side caching max
69 $wgOut->setSquidMaxage( 10 );
71 # Get last modified date, for client caching
72 # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
73 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
74 if ( $feedFormat ||
!$wgUseRCPatrol ) {
75 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
76 # Client cache fresh and headers sent, nothing more to do.
82 $rctext = wfMsg( "recentchangestext" );
83 $wgOut->addWikiText( $rctext );
86 $now = wfTimestampNow();
87 $cutoff_unixtime = time() - ( $days * 86400 );
88 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime %
86400);
89 $cutoff = $dbr->timestamp( $cutoff_unixtime );
90 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW
,$cutoff)) {
91 $cutoff = $dbr->timestamp($from);
96 $sk = $wgUser->getSkin();
98 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
100 $hidem = ( $hideminor ) ?
'AND rc_minor=0' : '';
101 $hidem .= ( $hidebots ) ?
' AND rc_bot=0' : '';
102 $hidem .= ( $hideliu ) ?
' AND rc_user=0' : '';
103 $hidem .= ( $hidepatrolled )?
' AND rc_patrolled=0' : '';
105 $urlparams = array( 'hideminor' => $hideminor, 'hideliu' => $hideliu,
106 'hidebots' => $hidebots, 'hidepatrolled' => $hidepatrolled,
108 $hideparams = wfArrayToCGI( $urlparams );
110 $minorLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
111 $showhide[1-$hideminor], wfArrayToCGI( array( 'hideminor' => 1-$hideminor ), $urlparams ) );
112 $botLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
113 $showhide[1-$hidebots], wfArrayToCGI( array( 'hidebots' => 1-$hidebots ), $urlparams ) );
114 $liuLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
115 $showhide[1-$hideliu], wfArrayToCGI( array( 'hideliu' => 1-$hideliu ), $urlparams ) );
116 $patrLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
117 $showhide[1-$hidepatrolled], wfArrayToCGI( array( 'hidepatrolled' => 1-$hidepatrolled ), $urlparams ) );
119 $uid = $wgUser->getID();
120 # Patch for showing "updated since last visit" marker
121 $sql2 = "SELECT $recentchanges.*" . ($uid ?
",wl_user,wl_notificationtimestamp" : "") . " FROM $recentchanges " .
122 ($uid ?
"LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") .
123 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
124 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
126 $res = $dbr->query( $sql2, DB_SLAVE
, $fname );
128 while( $row = $dbr->fetchObject( $res ) ){
131 $dbr->freeResult( $res );
134 $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $limit ),
135 $wgLang->timeanddate( $from, true ) );
137 $note = wfMsg( 'rcnote', $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
139 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
141 $note = rcDayLimitLinks( $days, $limit, 'Recentchanges', $hideparams, false, $minorLink, $botLink, $liuLink, $patrLink );
143 $note .= "<br />\n" . wfMsg( 'rclistfrom',
144 $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
145 $wgLang->timeanddate( $now, true ), $hideparams.'&from='.$now ) );
147 $wgOut->addHTML( $note."\n" );
150 rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod );
153 $wgOut->setSyndicated( true );
154 $list =& new ChangesList( $sk );
155 $s = $list->beginRecentChangesList();
157 foreach( $rows as $obj ){
162 if ( ! ( $hideminor && $obj->rc_minor
) &&
163 ! ( $hidepatrolled && $obj->rc_patrolled
) ) {
164 $rc = RecentChange
::newFromRow( $obj );
165 $rc->counter
= $counter++
;
167 if ($wgShowUpdatedMarker
168 && $wgUser->getOption( 'showupdated' )
169 && !empty( $obj->wl_notificationtimestamp
)
170 && ($obj->rc_timestamp
>= $obj->wl_notificationtimestamp
)) {
171 $rc->notificationtimestamp
= true;
173 $rc->notificationtimestamp
= false;
176 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
177 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" . $dbr->strencode($obj->rc_title
) ."' AND wl_namespace=$obj->rc_namespace" ;
178 $res3 = $dbr->query( $sql3, 'wfSpecialRecentChanges');
179 $x = $dbr->fetchObject( $res3 );
180 $rc->numberofWatchingusers
= $x->n
;
182 $rc->numberofWatchingusers
= 0;
184 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user
) );
188 $s .= $list->endRecentChangesList();
189 $wgOut->addHTML( $s );
193 function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
194 global $messageMemc, $wgDBname, $wgFeedCacheTimeout;
195 global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
197 if( !isset( $wgFeedClasses[$feedFormat] ) ) {
198 wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
202 $timekey = "$wgDBname:rcfeed:timestamp";
203 $key = "$wgDBname:rcfeed:$feedFormat:limit:$limit:minor:$hideminor";
205 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchanges' ) .
206 ' [' . $wgContLanguageCode . ']';
207 $feed = new $wgFeedClasses[$feedFormat](
209 htmlspecialchars( wfMsgForContent( 'recentchangestext' ) ),
210 $wgTitle->getFullUrl() );
213 * Bumping around loading up diffs can be pretty slow, so where
214 * possible we want to cache the feed output so the next visitor
218 if( $feedLastmod = $messageMemc->get( $timekey ) ) {
220 * If the cached feed was rendered very recently, we may
221 * go ahead and use it even if there have been edits made
222 * since it was rendered. This keeps a swarm of requests
223 * from being too bad on a super-frequently edited wiki.
225 if( time() - wfTimestamp( TS_UNIX
, $feedLastmod )
226 < $wgFeedCacheTimeout
227 ||
wfTimestamp( TS_UNIX
, $feedLastmod )
228 > wfTimestamp( TS_UNIX
, $lastmod ) ) {
229 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
230 $cachedFeed = $messageMemc->get( $key );
232 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
235 if( is_string( $cachedFeed ) ) {
236 wfDebug( "RC: Outputting cached feed\n" );
237 $feed->httpHeaders();
240 wfDebug( "RC: rendering new feed and caching it\n" );
242 rcDoOutputFeed( $rows, $feed );
243 $cachedFeed = ob_get_contents();
246 $expire = 3600 * 24; # One day
247 $messageMemc->set( $key, $cachedFeed );
248 $messageMemc->set( $timekey, wfTimestamp( TS_MW
), $expire );
253 function rcDoOutputFeed( $rows, &$feed ) {
254 global $wgSitename, $wgFeedClasses, $wgContLanguageCode;
258 # Merge adjacent edits by one user
261 foreach( $rows as $obj ) {
263 $obj->rc_namespace
>= 0 &&
264 $obj->rc_cur_id
== $sorted[$n-1]->rc_cur_id
&&
265 $obj->rc_user_text
== $sorted[$n-1]->rc_user_text
) {
266 $sorted[$n-1]->rc_last_oldid
= $obj->rc_last_oldid
;
274 foreach( $sorted as $obj ) {
275 $title = Title
::makeTitle( $obj->rc_namespace
, $obj->rc_title
);
276 $talkpage = $title->getTalkPage();
277 $item = new FeedItem(
278 $title->getPrefixedText(),
279 rcFormatDiff( $obj ),
280 $title->getFullURL(),
283 $talkpage->getFullURL()
285 $feed->outItem( $item );
293 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
294 global $wgUser, $wgLang, $wgContLang;
295 $sk = $wgUser->getSkin();
296 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
297 ($lim ?
$wgLang->formatNum( "{$lim}" ) : wfMsg( 'all' ) ), "{$more}" .
298 ($d ?
"days={$d}&" : '') . 'limit='.$lim );
305 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
306 global $wgUser, $wgLang, $wgContLang;
307 $sk = $wgUser->getSkin();
308 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
309 ($d ?
$wgLang->formatNum( "{$d}" ) : wfMsg( "all" ) ), $more.'days='.$d .
310 ($lim ?
'&limit='.$lim : '') );
315 * Used also by Recentchangeslinked
317 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
318 $botLink = '', $liuLink = '', $patrLink = '' ) {
319 if ($more != '') $more .= '&';
320 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
321 rcCountLink( 100, $days, $page, $more ) . ' | ' .
322 rcCountLink( 250, $days, $page, $more ) . ' | ' .
323 rcCountLink( 500, $days, $page, $more ) .
324 ( $doall ?
( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
325 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
326 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
327 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
328 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
329 rcDaysLink( $limit, 30, $page, $more ) .
330 ( $doall ?
( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
331 $shm = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink );
332 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
337 * Format a diff for the newsfeed
339 function rcFormatDiff( $row ) {
340 $fname = 'rcFormatDiff';
341 wfProfileIn( $fname );
343 require_once( 'DifferenceEngine.php' );
344 $comment = "<p>" . htmlspecialchars( $row->rc_comment
) . "</p>\n";
346 if( $row->rc_namespace
>= 0 ) {
349 #$diff =& new DifferenceEngine( $row->rc_this_oldid, $row->rc_last_oldid, $row->rc_id );
350 #$diff->showDiffPage();
352 $dbr =& wfGetDB( DB_SLAVE
);
353 if( $row->rc_this_oldid
) {
354 $newrow = $dbr->selectRow( 'old',
355 array( 'old_flags', 'old_text' ),
356 array( 'old_id' => $row->rc_this_oldid
) );
357 $newtext = Article
::getRevisionText( $newrow );
359 $newrow = $dbr->selectRow( 'cur',
361 array( 'cur_id' => $row->rc_cur_id
) );
362 $newtext = $newrow->cur_text
;
364 if( $row->rc_last_oldid
) {
365 wfProfileIn( "$fname-dodiff" );
366 $oldrow = $dbr->selectRow( 'old',
367 array( 'old_flags', 'old_text' ),
368 array( 'old_id' => $row->rc_last_oldid
) );
369 $oldtext = Article
::getRevisionText( $oldrow );
371 global $wgFeedDiffCutoff;
372 if( strlen( $newtext ) > $wgFeedDiffCutoff ||
373 strlen( $oldtext ) > $wgFeedDiffCutoff ) {
374 $titleObj = Title
::makeTitle( $row->rc_namespace
, $row->rc_title
);
375 $diffLink = $titleObj->escapeFullUrl(
376 'diff=' . $row->rc_this_oldid
.
377 '&oldid=' . $row->rc_last_oldid
);
378 $diffText = '<a href="' .
381 htmlspecialchars( wfMsgForContent( 'difference' ) ) .
384 $diffText = DifferenceEngine
::getDiff( $oldtext, $newtext,
385 wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp
) ),
386 wfMsg( 'currentrev' ) );
388 wfProfileOut( "$fname-dodiff" );
390 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
391 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
394 wfProfileOut( $fname );
395 return $comment . $diffText;
398 wfProfileOut( $fname );