* Support for table name prefixes throughout the code. No support yet for converting...
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
1 <?php
2
3 require_once( "Feed.php" );
4
5 function wfSpecialRecentchanges( $par )
6 {
7 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname;
8 global $wgRequest, $wgSitename, $wgLanguageCode;
9 global $wgFeedClasses;
10 $fname = "wfSpecialRecentchanges";
11
12 # Get query parameters
13 $feedFormat = $wgRequest->getVal( "feed" );
14
15 $defaultDays = $wgUser->getOption( 'rcdays' );
16 if ( !$defaultDays ) {
17 $defaultDays = 3;
18 }
19
20 $days = $wgRequest->getInt( 'days', $defaultDays );
21 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor' ) ) ? 1 : 0;
22 $from = $wgRequest->getText( 'from' );
23 $hidebots = $wgRequest->getBool( 'hidebots', true ) ? 1 : 0;
24 $hideliu = $wgRequest->getBool( 'hideliu', false ) ? 1 : 0;
25
26 # Get query parameters from path
27 if( $par ) {
28 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
29 if( in_array( "hidebots", $bits ) ) $hidebots = 1;
30 if( in_array( "bots", $bits ) ) $hidebots = 0;
31 if( in_array( "hideminor", $bits ) ) $hideminor = 1;
32 if( in_array( "minor", $bits ) ) $hideminor = 0;
33 if( in_array( "hideliu", $bits) ) $hideliu = 1;
34 }
35
36 $dbr =& wfGetDB( DB_SLAVE );
37 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
38
39 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
40 # 10 seconds server-side caching max
41 $wgOut->setSquidMaxage( 10 );
42 if( $wgOut->checkLastModified( $lastmod ) ){
43 # Client cache fresh and headers sent, nothing more to do.
44 return;
45 }
46
47 # The next few lines can probably be commented out now that wfMsg can get text from the DB
48 $rctext = $dbr->selectField( 'cur', 'cur_text',
49 array( 'cur_namespace' => NS_WIKIPEDIA, 'cur_title' => 'Recentchanges' ),
50 $fname
51 );
52 if( !$rctext ) {
53 $rctext = wfMsg( "recentchangestext" );
54 }
55
56 $wgOut->addWikiText( $rctext );
57
58 list( $limit, $offset ) = wfCheckLimits( 100, "rclimit" );
59 $now = wfTimestampNow();
60 $cutoff_unixtime = time() - ( $days * 86400 );
61 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
62 $cutoff = wfUnix2Timestamp( $cutoff_unixtime );
63 if(preg_match('/^[0-9]{14}$/', $from) and $from > $cutoff) {
64 $cutoff = $from;
65 } else {
66 unset($from);
67 }
68
69 $sk = $wgUser->getSkin();
70 $showhide = array( wfMsg( "show" ), wfMsg( "hide" ));
71
72 if ( $hideminor ) {
73 $hidem = "AND rc_minor=0";
74 } else {
75 $hidem = "";
76 }
77
78 if( $hidebots ) {
79 $hidem .= " AND rc_bot=0";
80 }
81
82 if ( $hideliu ) {
83 $hidem .= " AND rc_user=0";
84 }
85 $hideliu = ($hideliu ? 1 : 0);
86 #$hideparams = "hideminor={$hideminor}&hideliu={$hideliu}&hidebots={$hidebots}";
87 $urlparams = array( "hideminor" => $hideminor, "hideliu" => $hideliu, "hidebots" => $hidebots );
88 $hideparams = wfArrayToCGI( $urlparams );
89
90 $minorLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
91 $showhide[1-$hideminor], wfArrayToCGI( array( "hideminor" => 1-$hideminor ), $urlparams ) );
92 $botLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
93 $showhide[1-$hidebots], wfArrayToCGI( array( "hidebots" => 1-$hidebots ), $urlparams ) );
94 $liuLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
95 $showhide[1-$hideliu], wfArrayToCGI( array( "hideliu" => 1-$hideliu ), $urlparams ) );
96
97 $uid = $wgUser->getID();
98 $sql2 = "SELECT $recentchanges.*" . ($uid ? ",wl_user" : "") . " FROM $recentchanges " .
99 ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
100 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
101 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
102
103 $res = $dbr->query( $sql2, DB_SLAVE, $fname );
104 $rows = array();
105 while( $row = $dbr->fetchObject( $res ) ){
106 $rows[] = $row;
107 }
108 $dbr->freeResult( $res );
109
110 if(isset($from)) {
111 $note = wfMsg( "rcnotefrom", $wgLang->formatNum( $limit ),
112 $wgLang->timeanddate( $from, true ) );
113 } else {
114 $note = wfMsg( "rcnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
115 }
116 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
117
118 $note = rcDayLimitLinks( $days, $limit, "Recentchanges", $hideparams, false, $minorLink, $botLink, $liuLink );
119
120 $note .= "<br />\n" . wfMsg( "rclistfrom",
121 $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
122 $wgLang->timeanddate( $now, true ), "{$hideparams}&from=$now" ) );
123
124 $wgOut->addHTML( "{$note}\n" );
125
126 if( isset($wgFeedClasses[$feedFormat]) ) {
127 $feed = new $wgFeedClasses[$feedFormat](
128 $wgSitename . " - " . wfMsg( "recentchanges" ) . " [" . $wgLanguageCode . "]",
129 htmlspecialchars( wfMsg( "recentchangestext" ) ),
130 $wgTitle->getFullUrl() );
131 $feed->outHeader();
132 foreach( $rows as $obj ) {
133 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
134 $talkpage = $title->getTalkPage();
135 $item = new FeedItem(
136 $title->getPrefixedText(),
137 htmlspecialchars( $obj->rc_comment ),
138 $title->getFullURL(),
139 $obj->rc_timestamp,
140 $obj->rc_user_text,
141 $talkpage->getFullURL()
142 );
143 $feed->outItem( $item );
144 }
145 $feed->outFooter();
146 } else {
147 $wgOut->setSyndicated( true );
148 $s = $sk->beginRecentChangesList();
149 $counter = 1;
150 foreach( $rows as $obj ){
151 if( $limit == 0) {
152 break;
153 }
154
155 if ( ! ( $hideminor && $obj->rc_minor ) ) {
156 $rc = RecentChange::newFromRow( $obj );
157 $rc->counter = $counter++;
158 $s .= $sk->recentChangesLine( $rc, !empty( $obj->wl_user ) );
159 --$limit;
160 }
161 }
162 $s .= $sk->endRecentChangesList();
163 $wgOut->addHTML( $s );
164 }
165 }
166
167 function rcCountLink( $lim, $d, $page="Recentchanges", $more="" )
168 {
169 global $wgUser, $wgLang;
170 $sk = $wgUser->getSkin();
171 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
172 ($lim ? $wgLang->formatNum( "{$lim}" ) : wfMsg( "all" ) ), "{$more}" .
173 ($d ? "days={$d}&" : "") . "limit={$lim}" );
174 return $s;
175 }
176
177 function rcDaysLink( $lim, $d, $page="Recentchanges", $more="" )
178 {
179 global $wgUser, $wgLang;
180 $sk = $wgUser->getSkin();
181 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
182 ($d ? $wgLang->formatNum( "{$d}" ) : wfMsg( "all" ) ), "{$more}days={$d}" .
183 ($lim ? "&limit={$lim}" : "") );
184 return $s;
185 }
186
187 function rcDayLimitLinks( $days, $limit, $page="Recentchanges", $more="", $doall = false, $minorLink = "",
188 $botLink = "", $liuLink = "" )
189 {
190 if ($more != "") $more .= "&";
191 $cl = rcCountLink( 50, $days, $page, $more ) . " | " .
192 rcCountLink( 100, $days, $page, $more ) . " | " .
193 rcCountLink( 250, $days, $page, $more ) . " | " .
194 rcCountLink( 500, $days, $page, $more ) .
195 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
196 $dl = rcDaysLink( $limit, 1, $page, $more ) . " | " .
197 rcDaysLink( $limit, 3, $page, $more ) . " | " .
198 rcDaysLink( $limit, 7, $page, $more ) . " | " .
199 rcDaysLink( $limit, 14, $page, $more ) . " | " .
200 rcDaysLink( $limit, 30, $page, $more ) .
201 ( $doall ? ( " | " . rcDaysLink( $limit, 0, $page, $more ) ) : "" );
202 $shm = wfMsg( "showhideminor", $minorLink, $botLink, $liuLink );
203 $note = wfMsg( "rclinks", $cl, $dl, $shm );
204 return $note;
205 }
206
207 # Obsolete? Isn't called from anywhere and $mlink isn't defined
208 function rcLimitLinks( $page="Recentchanges", $more="", $doall = false )
209 {
210 if ($more != "") $more .= "&";
211 $cl = rcCountLink( 50, 0, $page, $more ) . " | " .
212 rcCountLink( 100, 0, $page, $more ) . " | " .
213 rcCountLink( 250, 0, $page, $more ) . " | " .
214 rcCountLink( 500, 0, $page, $more ) .
215 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
216 $note = wfMsg( "rclinks", $cl, "", $mlink );
217 return $note;
218 }
219
220 ?>