9 require_once( 'Feed.php' );
14 function wfSpecialRecentchanges( $par ) {
15 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname;
16 global $wgRequest, $wgSitename, $wgLanguageCode;
17 global $wgFeedClasses;
18 $fname = 'wfSpecialRecentchanges';
20 # Get query parameters
21 $feedFormat = $wgRequest->getVal( 'feed' );
23 $defaultDays = $wgUser->getOption( 'rcdays' );
24 if ( !$defaultDays ) { $defaultDays = 3; }
26 $days = $wgRequest->getInt( 'days', $defaultDays );
27 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor' ) ) ?
1 : 0;
28 $from = $wgRequest->getText( 'from' );
29 $hidebots = $wgRequest->getBool( 'hidebots', true ) ?
1 : 0;
30 $hideliu = $wgRequest->getBool( 'hideliu', false ) ?
1 : 0;
31 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', false ) ?
1 : 0;
33 list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
35 # Get query parameters from path
37 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
38 if( in_array( 'hidebots', $bits ) ) $hidebots = 1;
39 if( in_array( 'bots', $bits ) ) $hidebots = 0;
40 if( in_array( 'hideminor', $bits ) ) $hideminor = 1;
41 if( in_array( 'minor', $bits ) ) $hideminor = 0;
42 if( in_array( 'hideliu', $bits) ) $hideliu = 1;
43 if( in_array( 'hidepatrolled', $bits) ) $hidepatrolled = 1;
47 # Database connection and caching
48 $dbr =& wfGetDB( DB_SLAVE
);
49 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
51 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
52 # 10 seconds server-side caching max
53 $wgOut->setSquidMaxage( 10 );
54 if( $wgOut->checkLastModified( $lastmod ) ){
55 # Client cache fresh and headers sent, nothing more to do.
60 $rctext = wfMsg( "recentchangestext" );
61 $wgOut->addWikiText( $rctext );
64 $now = wfTimestampNow();
65 $cutoff_unixtime = time() - ( $days * 86400 );
66 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime %
86400);
67 $cutoff = $dbr->timestamp( $cutoff_unixtime );
68 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW
,$cutoff)) {
69 $cutoff = $dbr->timestamp($from);
74 $sk = $wgUser->getSkin();
76 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
78 $hidem = ( $hideminor ) ?
'AND rc_minor=0' : '';
79 $hidem .= ( $hidebots ) ?
' AND rc_bot=0' : '';
80 $hidem .= ( $hideliu ) ?
' AND rc_user=0' : '';
81 $hidem .= ( $hidepatrolled )?
' AND rc_patrolled=0' : '';
83 $urlparams = array( 'hideminor' => $hideminor, 'hideliu' => $hideliu,
84 'hidebots' => $hidebots, 'hidepatrolled' => $hidepatrolled);
85 $hideparams = wfArrayToCGI( $urlparams );
87 $minorLink = $sk->makeKnownLink( $wgLang->specialPage( 'Recentchanges' ),
88 $showhide[1-$hideminor], wfArrayToCGI( array( 'hideminor' => 1-$hideminor ), $urlparams ) );
89 $botLink = $sk->makeKnownLink( $wgLang->specialPage( 'Recentchanges' ),
90 $showhide[1-$hidebots], wfArrayToCGI( array( 'hidebots' => 1-$hidebots ), $urlparams ) );
91 $liuLink = $sk->makeKnownLink( $wgLang->specialPage( 'Recentchanges' ),
92 $showhide[1-$hideliu], wfArrayToCGI( array( 'hideliu' => 1-$hideliu ), $urlparams ) );
93 $patrLink = $sk->makeKnownLink( $wgLang->specialPage( 'Recentchanges' ),
94 $showhide[1-$hidepatrolled], wfArrayToCGI( array( 'hidepatrolled' => 1-$hidepatrolled ), $urlparams ) );
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}";
102 $res = $dbr->query( $sql2, DB_SLAVE
, $fname );
104 while( $row = $dbr->fetchObject( $res ) ){
107 $dbr->freeResult( $res );
110 $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $limit ),
111 $wgLang->timeanddate( $from, true ) );
113 $note = wfMsg( 'rcnote', $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
115 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
117 $note = rcDayLimitLinks( $days, $limit, 'Recentchanges', $hideparams, false, $minorLink, $botLink, $liuLink, $patrLink );
119 $note .= "<br />\n" . wfMsg( 'rclistfrom',
120 $sk->makeKnownLink( $wgLang->specialPage( 'Recentchanges' ),
121 $wgLang->timeanddate( $now, true ), $hideparams.'&from='.$now ) );
123 $wgOut->addHTML( $note."\n" );
125 if( isset($wgFeedClasses[$feedFormat]) ) {
126 $feed = new $wgFeedClasses[$feedFormat](
127 $wgSitename . ' - ' . wfMsg( 'recentchanges' ) . ' [' . $wgLanguageCode . ']',
128 htmlspecialchars( wfMsg( 'recentchangestext' ) ),
129 $wgTitle->getFullUrl() );
131 foreach( $rows as $obj ) {
132 $title = Title
::makeTitle( $obj->rc_namespace
, $obj->rc_title
);
133 $talkpage = $title->getTalkPage();
134 $item = new FeedItem(
135 $title->getPrefixedText(),
136 htmlspecialchars( $obj->rc_comment
),
137 $title->getFullURL(),
140 $talkpage->getFullURL()
142 $feed->outItem( $item );
146 $wgOut->setSyndicated( true );
147 $s = $sk->beginRecentChangesList();
149 foreach( $rows as $obj ){
154 if ( ! ( $hideminor && $obj->rc_minor
) &&
155 ! ( $hidepatrolled && $obj->rc_patrolled
) ) {
156 $rc = RecentChange
::newFromRow( $obj );
157 $rc->counter
= $counter++
;
158 $s .= $sk->recentChangesLine( $rc, !empty( $obj->wl_user
) );
162 $s .= $sk->endRecentChangesList();
163 $wgOut->addHTML( $s );
170 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
171 global $wgUser, $wgLang;
172 $sk = $wgUser->getSkin();
173 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
174 ($lim ?
$wgLang->formatNum( "{$lim}" ) : wfMsg( 'all' ) ), "{$more}" .
175 ($d ?
"days={$d}&" : '') . 'limit='.$lim );
182 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
183 global $wgUser, $wgLang;
184 $sk = $wgUser->getSkin();
185 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
186 ($d ?
$wgLang->formatNum( "{$d}" ) : wfMsg( "all" ) ), $more.'days='.$d .
187 ($lim ?
'&limit='.$lim : '') );
194 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
195 $botLink = '', $liuLink = '', $patrLink = '' ) {
196 if ($more != '') $more .= '&';
197 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
198 rcCountLink( 100, $days, $page, $more ) . ' | ' .
199 rcCountLink( 250, $days, $page, $more ) . ' | ' .
200 rcCountLink( 500, $days, $page, $more ) .
201 ( $doall ?
( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
202 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
203 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
204 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
205 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
206 rcDaysLink( $limit, 30, $page, $more ) .
207 ( $doall ?
( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
208 $shm = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink );
209 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
214 * Obsolete? Isn't called from anywhere and $mlink isn't defined
216 function rcLimitLinks( $page='Recentchanges', $more='', $doall = false ) {
217 if ($more != '') $more .= '&';
218 $cl = rcCountLink( 50, 0, $page, $more ) . ' | ' .
219 rcCountLink( 100, 0, $page, $more ) . ' | ' .
220 rcCountLink( 250, 0, $page, $more ) . ' | ' .
221 rcCountLink( 500, 0, $page, $more ) .
222 ( $doall ?
( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
223 $note = wfMsg( 'rclinks', $cl, '', $mlink );