3 include_once( "Feed.php" );
5 function wfSpecialRecentchanges( $par )
7 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname;
8 global $wgRequest, $wgSitename, $wgLanguageCode;
9 $fname = "wfSpecialRecentchanges";
11 # Get query parameters
12 $feedFormat = $wgRequest->getVal( "feed" );
14 // imported from Feed.php
15 $wgFeedClasses = array (
21 $defaultDays = $wgUser->getOption( 'rcdays' );
22 if ( !$defaultDays ) {
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;
32 # Get query parameters from path
34 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
35 if( in_array( "hidebots", $bits ) ) $hidebots = 1;
36 if( in_array( "bots", $bits ) ) $hidebots = 0;
37 if( in_array( "hideminor", $bits ) ) $hideminor = 1;
38 if( in_array( "minor", $bits ) ) $hideminor = 0;
39 if( in_array( "hideliu", $bits) ) $hideliu = 1;
42 $sql = "SELECT MAX(rc_timestamp) AS lastmod FROM recentchanges";
43 $res = wfQuery( $sql, DB_READ
, $fname );
44 $s = wfFetchObject( $res );
45 # 10 seconds server-side caching max
46 $wgOut->setSquidMaxage( 10 );
47 if( $wgOut->checkLastModified( $s->lastmod
) ){
48 # Client cache fresh and headers sent, nothing more to do.
52 $rctext = wfMsg( "recentchangestext" );
54 # The next few lines can probably be commented out now that wfMsg can get text from the DB
55 $sql = "SELECT cur_text FROM cur WHERE cur_namespace=4 AND cur_title='Recentchanges'";
56 $res = wfQuery( $sql, DB_READ
, $fname );
57 if( ( $s = wfFetchObject( $res ) ) and ( $s->cur_text
!= "" ) ) {
58 $rctext = $s->cur_text
;
61 $wgOut->addWikiText( $rctext );
63 list( $limit, $offset ) = wfCheckLimits( 100, "rclimit" );
64 $now = wfTimestampNow();
65 $cutoff_unixtime = time() - ( $days * 86400 );
66 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime %
86400);
67 $cutoff = wfUnix2Timestamp( $cutoff_unixtime );
68 if(preg_match('/^[0-9]{14}$/', $from) and $from > $cutoff) {
74 $sk = $wgUser->getSkin();
75 $showhide = array( wfMsg( "show" ), wfMsg( "hide" ));
78 $hidem = "AND rc_minor=0";
84 $hidem .= " AND rc_bot=0";
88 $hidem .= " AND rc_user=0";
90 $hideliu = ($hideliu ?
1 : 0);
91 #$hideparams = "hideminor={$hideminor}&hideliu={$hideliu}&hidebots={$hidebots}";
92 $urlparams = array( "hideminor" => $hideminor, "hideliu" => $hideliu, "hidebots" => $hidebots );
93 $hideparams = wfArrayToCGI( $urlparams );
95 $minorLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
96 $showhide[1-$hideminor], wfArrayToCGI( array( "hideminor" => 1-$hideminor ), $urlparams ) );
97 $botLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
98 $showhide[1-$hidebots], wfArrayToCGI( array( "hidebots" => 1-$hidebots ), $urlparams ) );
99 $liuLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
100 $showhide[1-$hideliu], wfArrayToCGI( array( "hideliu" => 1-$hideliu ), $urlparams ) );
102 $uid = $wgUser->getID();
103 $sql2 = "SELECT recentchanges.*" . ($uid ?
",wl_user" : "") . " FROM recentchanges " .
104 ($uid ?
"LEFT OUTER JOIN watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
105 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
106 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
108 $res = wfQuery( $sql2, DB_READ
, $fname );
110 while( $row = wfFetchObject( $res ) ){
115 $note = wfMsg( "rcnotefrom", $wgLang->formatNum( $limit ),
116 $wgLang->timeanddate( $from, true ) );
118 $note = wfMsg( "rcnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
120 $wgOut->addHTML( "\n<hr/>\n{$note}\n<br/>" );
122 $note = rcDayLimitLinks( $days, $limit, "Recentchanges", $hideparams, false, $minorLink, $botLink, $liuLink );
124 $note .= "<br/>\n" . wfMsg( "rclistfrom",
125 $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
126 $wgLang->timeanddate( $now, true ), "{$hideparams}&from=$now" ) );
128 $wgOut->addHTML( "{$note}\n" );
130 if( isset($wgFeedClasses[$feedFormat]) ) {
131 $feed = new $wgFeedClasses[$feedFormat](
132 $wgSitename . " - " . wfMsg( "recentchanges" ) . " [" . $wgLanguageCode . "]",
133 htmlspecialchars( wfMsg( "recentchangestext" ) ),
134 $wgTitle->getFullUrl() );
136 foreach( $rows as $obj ) {
137 $title = Title
::makeTitle( $obj->rc_namespace
, $obj->rc_title
);
138 $item = new FeedItem(
139 $title->getPrefixedText(),
140 htmlspecialchars( $obj->rc_comment
),
141 $title->getFullURL(),
144 htmlspecialchars( $obj->rc_comment
)
146 $feed->outItem( $item );
150 $wgOut->setSyndicated( true );
151 $s = $sk->beginRecentChangesList();
153 foreach( $rows as $obj ){
158 if ( ! ( $hideminor && $obj->rc_minor
) ) {
159 $rc = RecentChange
::newFromRow( $obj );
160 $rc->counter
= $counter++
;
161 $s .= $sk->recentChangesLine( $rc, !empty( $obj->wl_user
) );
165 $s .= $sk->endRecentChangesList();
166 $wgOut->addHTML( $s );
168 wfFreeResult( $res );
171 function rcCountLink( $lim, $d, $page="Recentchanges", $more="" )
173 global $wgUser, $wgLang;
174 $sk = $wgUser->getSkin();
175 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
176 ($lim ?
$wgLang->formatNum( "{$lim}" ) : wfMsg( "all" ) ), "{$more}" .
177 ($d ?
"days={$d}&" : "") . "limit={$lim}" );
181 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}" : "") );
191 function rcDayLimitLinks( $days, $limit, $page="Recentchanges", $more="", $doall = false, $minorLink = "",
192 $botLink = "", $liuLink = "" )
194 if ($more != "") $more .= "&";
195 $cl = rcCountLink( 50, $days, $page, $more ) . " | " .
196 rcCountLink( 100, $days, $page, $more ) . " | " .
197 rcCountLink( 250, $days, $page, $more ) . " | " .
198 rcCountLink( 500, $days, $page, $more ) .
199 ( $doall ?
( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
200 $dl = rcDaysLink( $limit, 1, $page, $more ) . " | " .
201 rcDaysLink( $limit, 3, $page, $more ) . " | " .
202 rcDaysLink( $limit, 7, $page, $more ) . " | " .
203 rcDaysLink( $limit, 14, $page, $more ) . " | " .
204 rcDaysLink( $limit, 30, $page, $more ) .
205 ( $doall ?
( " | " . rcDaysLink( $limit, 0, $page, $more ) ) : "" );
206 $shm = wfMsg( "showhideminor", $minorLink, $botLink, $liuLink );
207 $note = wfMsg( "rclinks", $cl, $dl, $shm );
211 # Obsolete? Isn't called from anywhere and $mlink isn't defined
212 function rcLimitLinks( $page="Recentchanges", $more="", $doall = false )
214 if ($more != "") $more .= "&";
215 $cl = rcCountLink( 50, 0, $page, $more ) . " | " .
216 rcCountLink( 100, 0, $page, $more ) . " | " .
217 rcCountLink( 250, 0, $page, $more ) . " | " .
218 rcCountLink( 500, 0, $page, $more ) .
219 ( $doall ?
( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
220 $note = wfMsg( "rclinks", $cl, "", $mlink );