5 * @subpackage SpecialPage
11 require_once( 'Feed.php' );
16 function wfSpecialRecentchanges( $par ) {
17 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgTitle, $wgMemc, $wgDBname;
18 global $wgRequest, $wgSitename, $wgLanguageCode, $wgContLanguageCode;
19 global $wgFeedClasses;
20 $fname = 'wfSpecialRecentchanges';
22 # Get query parameters
23 $feedFormat = $wgRequest->getVal( 'feed' );
25 $defaultDays = $wgUser->getOption( 'rcdays' );
26 if ( !$defaultDays ) { $defaultDays = 3; }
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;
35 list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
37 # Get query parameters from path
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;
49 # Database connection and caching
50 $dbr =& wfGetDB( DB_SLAVE
);
51 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
53 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
54 # 10 seconds server-side caching max
55 $wgOut->setSquidMaxage( 10 );
56 if( $wgOut->checkLastModified( $lastmod ) ){
57 # Client cache fresh and headers sent, nothing more to do.
62 $rctext = wfMsg( "recentchangestext" );
63 $wgOut->addWikiText( $rctext );
66 $now = wfTimestampNow();
67 $cutoff_unixtime = time() - ( $days * 86400 );
68 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime %
86400);
69 $cutoff = $dbr->timestamp( $cutoff_unixtime );
70 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW
,$cutoff)) {
71 $cutoff = $dbr->timestamp($from);
76 $sk = $wgUser->getSkin();
78 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
80 $hidem = ( $hideminor ) ?
'AND rc_minor=0' : '';
81 $hidem .= ( $hidebots ) ?
' AND rc_bot=0' : '';
82 $hidem .= ( $hideliu ) ?
' AND rc_user=0' : '';
83 $hidem .= ( $hidepatrolled )?
' AND rc_patrolled=0' : '';
85 $urlparams = array( 'hideminor' => $hideminor, 'hideliu' => $hideliu,
86 'hidebots' => $hidebots, 'hidepatrolled' => $hidepatrolled,
88 $hideparams = wfArrayToCGI( $urlparams );
90 $minorLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
91 $showhide[1-$hideminor], wfArrayToCGI( array( 'hideminor' => 1-$hideminor ), $urlparams ) );
92 $botLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
93 $showhide[1-$hidebots], wfArrayToCGI( array( 'hidebots' => 1-$hidebots ), $urlparams ) );
94 $liuLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
95 $showhide[1-$hideliu], wfArrayToCGI( array( 'hideliu' => 1-$hideliu ), $urlparams ) );
96 $patrLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
97 $showhide[1-$hidepatrolled], wfArrayToCGI( array( 'hidepatrolled' => 1-$hidepatrolled ), $urlparams ) );
99 $uid = $wgUser->getID();
100 $sql2 = "SELECT $recentchanges.*" . ($uid ?
",wl_user" : "") . " FROM $recentchanges " .
101 ($uid ?
"LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
102 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
103 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
105 $res = $dbr->query( $sql2, DB_SLAVE
, $fname );
107 while( $row = $dbr->fetchObject( $res ) ){
110 $dbr->freeResult( $res );
113 $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $limit ),
114 $wgLang->timeanddate( $from, true ) );
116 $note = wfMsg( 'rcnote', $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
118 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
120 $note = rcDayLimitLinks( $days, $limit, 'Recentchanges', $hideparams, false, $minorLink, $botLink, $liuLink, $patrLink );
122 $note .= "<br />\n" . wfMsg( 'rclistfrom',
123 $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
124 $wgLang->timeanddate( $now, true ), $hideparams.'&from='.$now ) );
126 $wgOut->addHTML( $note."\n" );
128 if( isset($wgFeedClasses[$feedFormat]) ) {
129 $feed = new $wgFeedClasses[$feedFormat](
130 $wgSitename . ' - ' . wfMsg( 'recentchanges' ) . ' [' . $wgContLanguageCode . ']',
131 htmlspecialchars( wfMsg( 'recentchangestext' ) ),
132 $wgTitle->getFullUrl() );
135 # Merge adjacent edits by one user
138 foreach( $rows as $obj ) {
140 $obj->rc_namespace
>= 0 &&
141 $obj->rc_cur_id
== $sorted[$n-1]->rc_cur_id
&&
142 $obj->rc_user_text
== $sorted[$n-1]->rc_user_text
) {
143 $sorted[$n-1]->rc_last_oldid
= $obj->rc_last_oldid
;
151 foreach( $sorted as $obj ) {
152 $title = Title
::makeTitle( $obj->rc_namespace
, $obj->rc_title
);
153 $talkpage = $title->getTalkPage();
154 $item = new FeedItem(
155 $title->getPrefixedText(),
156 rcFormatDiff( $obj ),
157 $title->getFullURL(),
160 $talkpage->getFullURL()
162 $feed->outItem( $item );
166 $wgOut->setSyndicated( true );
167 $s = $sk->beginRecentChangesList();
169 foreach( $rows as $obj ){
174 if ( ! ( $hideminor && $obj->rc_minor
) &&
175 ! ( $hidepatrolled && $obj->rc_patrolled
) ) {
176 $rc = RecentChange
::newFromRow( $obj );
177 $rc->counter
= $counter++
;
178 $s .= $sk->recentChangesLine( $rc, !empty( $obj->wl_user
) );
182 $s .= $sk->endRecentChangesList();
183 $wgOut->addHTML( $s );
190 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
191 global $wgUser, $wgLang, $wgContLang;
192 $sk = $wgUser->getSkin();
193 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
194 ($lim ?
$wgLang->formatNum( "{$lim}" ) : wfMsg( 'all' ) ), "{$more}" .
195 ($d ?
"days={$d}&" : '') . 'limit='.$lim );
202 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
203 global $wgUser, $wgLang, $wgContLang;
204 $sk = $wgUser->getSkin();
205 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
206 ($d ?
$wgLang->formatNum( "{$d}" ) : wfMsg( "all" ) ), $more.'days='.$d .
207 ($lim ?
'&limit='.$lim : '') );
214 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
215 $botLink = '', $liuLink = '', $patrLink = '' ) {
216 if ($more != '') $more .= '&';
217 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
218 rcCountLink( 100, $days, $page, $more ) . ' | ' .
219 rcCountLink( 250, $days, $page, $more ) . ' | ' .
220 rcCountLink( 500, $days, $page, $more ) .
221 ( $doall ?
( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
222 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
223 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
224 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
225 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
226 rcDaysLink( $limit, 30, $page, $more ) .
227 ( $doall ?
( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
228 $shm = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink );
229 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
234 * Obsolete? Isn't called from anywhere and $mlink isn't defined
236 function rcLimitLinks( $page='Recentchanges', $more='', $doall = false ) {
237 if ($more != '') $more .= '&';
238 $cl = rcCountLink( 50, 0, $page, $more ) . ' | ' .
239 rcCountLink( 100, 0, $page, $more ) . ' | ' .
240 rcCountLink( 250, 0, $page, $more ) . ' | ' .
241 rcCountLink( 500, 0, $page, $more ) .
242 ( $doall ?
( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
243 $note = wfMsg( 'rclinks', $cl, '', $mlink );
247 function rcFormatDiff( $row ) {
248 require_once( 'DifferenceEngine.php' );
249 $comment = "<p>" . htmlspecialchars( $row->rc_comment
) . "</p>\n";
251 if( $row->rc_namespace
>= 0 ) {
254 #$diff =& new DifferenceEngine( $row->rc_this_oldid, $row->rc_last_oldid, $row->rc_id );
255 #$diff->showDiffPage();
257 $dbr =& wfGetDB( DB_SLAVE
);
258 if( $row->rc_this_oldid
) {
259 $newrow = $dbr->selectRow( 'old',
260 array( 'old_flags', 'old_text' ),
261 array( 'old_id' => $row->rc_this_oldid
) );
262 $newtext = Article
::getRevisionText( $newrow );
264 $newrow = $dbr->selectRow( 'cur',
266 array( 'cur_id' => $row->rc_cur_id
) );
267 $newtext = $newrow->cur_text
;
269 if( $row->rc_last_oldid
) {
270 $oldrow = $dbr->selectRow( 'old',
271 array( 'old_flags', 'old_text' ),
272 array( 'old_id' => $row->rc_last_oldid
) );
273 $oldtext = Article
::getRevisionText( $oldrow );
274 $diffText = DifferenceEngine
::getDiff( $oldtext, $newtext,
275 wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp
) ),
276 wfMsg( 'currentrev' ) );
278 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
279 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
282 return $comment . $diffText;