Profiling points. Bump version to 1.4.0beta0; update HISTORY notes to current 1.3...
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 require_once( 'Feed.php' );
12 require_once( 'ChangesList.php' );
13
14 /**
15 * Constructor
16 */
17 function wfSpecialRecentchanges( $par ) {
18 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgTitle, $wgMemc, $wgDBname;
19 global $wgRequest, $wgSitename, $wgLanguageCode, $wgContLanguageCode;
20 global $wgFeedClasses, $wgUseRCPatrol;
21 $fname = 'wfSpecialRecentchanges';
22
23 # Get query parameters
24 $feedFormat = $wgRequest->getVal( 'feed' );
25
26 $defaultDays = $wgUser->getOption( 'rcdays' );
27 if ( !$defaultDays ) { $defaultDays = 3; }
28
29 $days = $wgRequest->getInt( 'days', $defaultDays );
30 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor' ) ) ? 1 : 0;
31 $from = $wgRequest->getText( 'from' );
32 $hidebots = $wgRequest->getBool( 'hidebots', true ) ? 1 : 0;
33 $hideliu = $wgRequest->getBool( 'hideliu', false ) ? 1 : 0;
34 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', false ) ? 1 : 0;
35
36 list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
37
38 # Get query parameters from path
39 if( $par ) {
40 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
41 if( in_array( 'hidebots', $bits ) ) $hidebots = 1;
42 if( in_array( 'bots', $bits ) ) $hidebots = 0;
43 if( in_array( 'hideminor', $bits ) ) $hideminor = 1;
44 if( in_array( 'minor', $bits ) ) $hideminor = 0;
45 if( in_array( 'hideliu', $bits) ) $hideliu = 1;
46 if( in_array( 'hidepatrolled', $bits) ) $hidepatrolled = 1;
47 }
48
49
50 # Database connection and caching
51 $dbr =& wfGetDB( DB_SLAVE );
52 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
53
54
55 # 10 seconds server-side caching max
56 $wgOut->setSquidMaxage( 10 );
57
58 # Get last modified date, for client caching
59 # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
60 if ( !$wgUseRCPatrol ) {
61 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
62 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
63 # Client cache fresh and headers sent, nothing more to do.
64 return;
65 }
66 }
67
68 # Output header
69 $rctext = wfMsg( "recentchangestext" );
70 $wgOut->addWikiText( $rctext );
71
72
73 $now = wfTimestampNow();
74 $cutoff_unixtime = time() - ( $days * 86400 );
75 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
76 $cutoff = $dbr->timestamp( $cutoff_unixtime );
77 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW,$cutoff)) {
78 $cutoff = $dbr->timestamp($from);
79 } else {
80 unset($from);
81 }
82
83 $sk = $wgUser->getSkin();
84
85 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
86
87 $hidem = ( $hideminor ) ? 'AND rc_minor=0' : '';
88 $hidem .= ( $hidebots ) ? ' AND rc_bot=0' : '';
89 $hidem .= ( $hideliu ) ? ' AND rc_user=0' : '';
90 $hidem .= ( $hidepatrolled )? ' AND rc_patrolled=0' : '';
91
92 $urlparams = array( 'hideminor' => $hideminor, 'hideliu' => $hideliu,
93 'hidebots' => $hidebots, 'hidepatrolled' => $hidepatrolled,
94 'limit' => $limit );
95 $hideparams = wfArrayToCGI( $urlparams );
96
97 $minorLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
98 $showhide[1-$hideminor], wfArrayToCGI( array( 'hideminor' => 1-$hideminor ), $urlparams ) );
99 $botLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
100 $showhide[1-$hidebots], wfArrayToCGI( array( 'hidebots' => 1-$hidebots ), $urlparams ) );
101 $liuLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
102 $showhide[1-$hideliu], wfArrayToCGI( array( 'hideliu' => 1-$hideliu ), $urlparams ) );
103 $patrLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
104 $showhide[1-$hidepatrolled], wfArrayToCGI( array( 'hidepatrolled' => 1-$hidepatrolled ), $urlparams ) );
105
106 $uid = $wgUser->getID();
107 $sql2 = "SELECT $recentchanges.*" . ($uid ? ",wl_user" : "") . " FROM $recentchanges " .
108 ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
109 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
110 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
111
112 $res = $dbr->query( $sql2, DB_SLAVE, $fname );
113 $rows = array();
114 while( $row = $dbr->fetchObject( $res ) ){
115 $rows[] = $row;
116 }
117 $dbr->freeResult( $res );
118
119 if(isset($from)) {
120 $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $limit ),
121 $wgLang->timeanddate( $from, true ) );
122 } else {
123 $note = wfMsg( 'rcnote', $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
124 }
125 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
126
127 $note = rcDayLimitLinks( $days, $limit, 'Recentchanges', $hideparams, false, $minorLink, $botLink, $liuLink, $patrLink );
128
129 $note .= "<br />\n" . wfMsg( 'rclistfrom',
130 $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
131 $wgLang->timeanddate( $now, true ), $hideparams.'&from='.$now ) );
132
133 $wgOut->addHTML( $note."\n" );
134
135 if( isset($wgFeedClasses[$feedFormat]) ) {
136 $feed = new $wgFeedClasses[$feedFormat](
137 $wgSitename . ' - ' . wfMsg( 'recentchanges' ) . ' [' . $wgContLanguageCode . ']',
138 htmlspecialchars( wfMsg( 'recentchangestext' ) ),
139 $wgTitle->getFullUrl() );
140 $feed->outHeader();
141
142 # Merge adjacent edits by one user
143 $sorted = array();
144 $n = 0;
145 foreach( $rows as $obj ) {
146 if( $n > 0 &&
147 $obj->rc_namespace >= 0 &&
148 $obj->rc_cur_id == $sorted[$n-1]->rc_cur_id &&
149 $obj->rc_user_text == $sorted[$n-1]->rc_user_text ) {
150 $sorted[$n-1]->rc_last_oldid = $obj->rc_last_oldid;
151 } else {
152 $sorted[$n] = $obj;
153 $n++;
154 }
155 $first = false;
156 }
157
158 foreach( $sorted as $obj ) {
159 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
160 $talkpage = $title->getTalkPage();
161 $item = new FeedItem(
162 $title->getPrefixedText(),
163 rcFormatDiff( $obj ),
164 $title->getFullURL(),
165 $obj->rc_timestamp,
166 $obj->rc_user_text,
167 $talkpage->getFullURL()
168 );
169 $feed->outItem( $item );
170 }
171 $feed->outFooter();
172 } else {
173 $wgOut->setSyndicated( true );
174 $list =& new ChangesList( $sk );
175 $s = $list->beginRecentChangesList();
176 $counter = 1;
177 foreach( $rows as $obj ){
178 if( $limit == 0) {
179 break;
180 }
181
182 if ( ! ( $hideminor && $obj->rc_minor ) &&
183 ! ( $hidepatrolled && $obj->rc_patrolled ) ) {
184 $rc = RecentChange::newFromRow( $obj );
185 $rc->counter = $counter++;
186 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ) );
187 --$limit;
188 }
189 }
190 $s .= $list->endRecentChangesList();
191 $wgOut->addHTML( $s );
192 }
193 }
194
195 /**
196 *
197 */
198 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
199 global $wgUser, $wgLang, $wgContLang;
200 $sk = $wgUser->getSkin();
201 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
202 ($lim ? $wgLang->formatNum( "{$lim}" ) : wfMsg( 'all' ) ), "{$more}" .
203 ($d ? "days={$d}&" : '') . 'limit='.$lim );
204 return $s;
205 }
206
207 /**
208 *
209 */
210 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
211 global $wgUser, $wgLang, $wgContLang;
212 $sk = $wgUser->getSkin();
213 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
214 ($d ? $wgLang->formatNum( "{$d}" ) : wfMsg( "all" ) ), $more.'days='.$d .
215 ($lim ? '&limit='.$lim : '') );
216 return $s;
217 }
218
219 /**
220 *
221 */
222 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
223 $botLink = '', $liuLink = '', $patrLink = '' ) {
224 if ($more != '') $more .= '&';
225 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
226 rcCountLink( 100, $days, $page, $more ) . ' | ' .
227 rcCountLink( 250, $days, $page, $more ) . ' | ' .
228 rcCountLink( 500, $days, $page, $more ) .
229 ( $doall ? ( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
230 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
231 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
232 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
233 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
234 rcDaysLink( $limit, 30, $page, $more ) .
235 ( $doall ? ( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
236 $shm = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink );
237 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
238 return $note;
239 }
240
241 /**
242 * Obsolete? Isn't called from anywhere and $mlink isn't defined
243 */
244 function rcLimitLinks( $page='Recentchanges', $more='', $doall = false ) {
245 if ($more != '') $more .= '&';
246 $cl = rcCountLink( 50, 0, $page, $more ) . ' | ' .
247 rcCountLink( 100, 0, $page, $more ) . ' | ' .
248 rcCountLink( 250, 0, $page, $more ) . ' | ' .
249 rcCountLink( 500, 0, $page, $more ) .
250 ( $doall ? ( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
251 $note = wfMsg( 'rclinks', $cl, '', $mlink );
252 return $note;
253 }
254
255 function rcFormatDiff( $row ) {
256 $fname = 'rcFormatDiff';
257 wfProfileIn( $fname );
258
259 require_once( 'DifferenceEngine.php' );
260 $comment = "<p>" . htmlspecialchars( $row->rc_comment ) . "</p>\n";
261
262 if( $row->rc_namespace >= 0 ) {
263 global $wgContLang;
264
265 #$diff =& new DifferenceEngine( $row->rc_this_oldid, $row->rc_last_oldid, $row->rc_id );
266 #$diff->showDiffPage();
267
268 $dbr =& wfGetDB( DB_SLAVE );
269 if( $row->rc_this_oldid ) {
270 $newrow = $dbr->selectRow( 'old',
271 array( 'old_flags', 'old_text' ),
272 array( 'old_id' => $row->rc_this_oldid ) );
273 $newtext = Article::getRevisionText( $newrow );
274 } else {
275 $newrow = $dbr->selectRow( 'cur',
276 array( 'cur_text' ),
277 array( 'cur_id' => $row->rc_cur_id ) );
278 $newtext = $newrow->cur_text;
279 }
280 if( $row->rc_last_oldid ) {
281 wfProfileIn( "$fname-dodiff" );
282 $oldrow = $dbr->selectRow( 'old',
283 array( 'old_flags', 'old_text' ),
284 array( 'old_id' => $row->rc_last_oldid ) );
285 $oldtext = Article::getRevisionText( $oldrow );
286 $diffText = DifferenceEngine::getDiff( $oldtext, $newtext,
287 wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp ) ),
288 wfMsg( 'currentrev' ) );
289 wfProfileOut( "$fname-dodiff" );
290 } else {
291 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
292 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
293 }
294
295 wfProfileOut( $fname );
296 return $comment . $diffText;
297 }
298
299 wfProfileOut( $fname );
300 return $comment;
301 }
302
303 ?>