Live hack: Skip some work on empty category/link sets
[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 require_once( 'Revision.php' );
14
15 /**
16 * Constructor
17 */
18 function wfSpecialRecentchanges( $par, $specialPage ) {
19 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
20 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
21 global $wgAllowCategorizedRecentChanges ;
22 $fname = 'wfSpecialRecentchanges';
23
24 # Get query parameters
25 $feedFormat = $wgRequest->getVal( 'feed' );
26
27 /* Checkbox values can't be true be default, because
28 * we cannot differentiate between unset and not set at all
29 */
30 $defaults = array(
31 /* int */ 'days' => $wgUser->getDefaultOption('rcdays'),
32 /* int */ 'limit' => $wgUser->getDefaultOption('rclimit'),
33 /* bool */ 'hideminor' => false,
34 /* bool */ 'hidebots' => true,
35 /* bool */ 'hideliu' => false,
36 /* bool */ 'hidepatrolled' => false,
37 /* bool */ 'hidemyself' => false,
38 /* text */ 'from' => '',
39 /* text */ 'namespace' => null,
40 /* bool */ 'invert' => false,
41 /* bool */ 'categories_any' => false,
42 );
43
44 extract($defaults);
45
46
47 $days = $wgUser->getOption( 'rcdays' );
48 if ( !$days ) { $days = $defaults['days']; }
49 $days = $wgRequest->getInt( 'days', $days );
50
51 $limit = $wgUser->getOption( 'rclimit' );
52 if ( !$limit ) { $limit = $defaults['limit']; }
53
54 # list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
55 $limit = $wgRequest->getInt( 'limit', $limit );
56
57 /* order of selection: url > preferences > default */
58 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor') ? true : $defaults['hideminor'] );
59
60 # As a feed, use limited settings only
61 if( $feedFormat ) {
62 global $wgFeedLimit;
63 if( $limit > $wgFeedLimit ) {
64 $options['limit'] = $wgFeedLimit;
65 }
66
67 } else {
68
69 $namespace = $wgRequest->getIntOrNull( 'namespace' );
70 $invert = $wgRequest->getBool( 'invert', $defaults['invert'] );
71 $hidebots = $wgRequest->getBool( 'hidebots', $defaults['hidebots'] );
72 $hideliu = $wgRequest->getBool( 'hideliu', $defaults['hideliu'] );
73 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', $defaults['hidepatrolled'] );
74 $hidemyself = $wgRequest->getBool ( 'hidemyself', $defaults['hidemyself'] );
75 $from = $wgRequest->getVal( 'from', $defaults['from'] );
76
77 # Get query parameters from path
78 if( $par ) {
79 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
80 foreach ( $bits as $bit ) {
81 if ( 'hidebots' == $bit ) $hidebots = 1;
82 if ( 'bots' == $bit ) $hidebots = 0;
83 if ( 'hideminor' == $bit ) $hideminor = 1;
84 if ( 'minor' == $bit ) $hideminor = 0;
85 if ( 'hideliu' == $bit ) $hideliu = 1;
86 if ( 'hidepatrolled' == $bit ) $hidepatrolled = 1;
87 if ( 'hidemyself' == $bit ) $hidemyself = 1;
88
89 if ( is_numeric( $bit ) ) {
90 $limit = $bit;
91 }
92
93 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
94 $limit = $m[1];
95 }
96
97 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
98 $days = $m[1];
99 }
100 }
101 }
102 }
103
104 if ( $limit < 0 || $limit > 5000 ) $limit = $defaults['limit'];
105
106
107 # Database connection and caching
108 $dbr =& wfGetDB( DB_SLAVE );
109 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
110
111
112 $cutoff_unixtime = time() - ( $days * 86400 );
113 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
114 $cutoff = $dbr->timestamp( $cutoff_unixtime );
115 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW,$cutoff)) {
116 $cutoff = $dbr->timestamp($from);
117 } else {
118 $from = $defaults['from'];
119 }
120
121 # 10 seconds server-side caching max
122 $wgOut->setSquidMaxage( 10 );
123
124 # Get last modified date, for client caching
125 # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
126 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
127 if ( $feedFormat || !$wgUseRCPatrol ) {
128 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
129 # Client cache fresh and headers sent, nothing more to do.
130 return;
131 }
132 }
133
134 $hidem = $hideminor ? 'AND rc_minor=0' : '';
135 $hidem .= $hidebots ? ' AND rc_bot=0' : '';
136 $hidem .= ( $hideliu && !$hidemyself ) ? ' AND rc_user=0' : '';
137 $hidem .= $hidepatrolled ? ' AND rc_patrolled=0' : '';
138 if ( $hidemyself ) {
139 if ( $wgUser->getID() ) {
140 $hidem .= ' AND rc_user <> '.$wgUser->getID();
141 } else {
142 $hidem .= ' AND rc_user_text<>' . $dbr->addQuotes( $wgUser->getName() );
143 }
144 }
145 $hidem .= is_null( $namespace ) ? '' : ' AND rc_namespace' . ($invert ? '!=' : '=') . $namespace;
146
147 // This is the big thing!
148
149 $uid = $wgUser->getID();
150
151 // Perform query
152 $sql2 = "SELECT * FROM $recentchanges FORCE INDEX (rc_timestamp) " .
153 ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") .
154 "WHERE rc_timestamp >= '{$cutoff}' {$hidem} " .
155 "ORDER BY rc_timestamp DESC";
156 $sql2 = $dbr->limitResult($sql2, $limit, 0);
157 $res = $dbr->query( $sql2, $fname );
158
159 // Fetch results, prepare a batch link existence check query
160 $rows = array();
161 $batch = new LinkBatch;
162 while( $row = $dbr->fetchObject( $res ) ){
163 $rows[] = $row;
164 if ( !$feedFormat ) {
165 // User page link
166 $title = Title::makeTitleSafe( NS_USER, $row->rc_user_text );
167 $batch->addObj( $title );
168
169 // User talk
170 $title = Title::makeTitleSafe( NS_USER_TALK, $row->rc_user_text );
171 $batch->addObj( $title );
172 }
173
174 }
175 $dbr->freeResult( $res );
176
177 if( $feedFormat ) {
178 rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod );
179 } else {
180
181 # Web output...
182
183 // Run existence checks
184 $batch->execute();
185 $any = $wgRequest->getBool( 'categories_any', $defaults['categories_any']);
186
187 // Output header
188 if ( !$specialPage->including() ) {
189 $wgOut->addWikiText( wfMsgForContent( "recentchangestext" ) );
190
191 // Dump everything here
192 $nondefaults = array();
193
194 wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults);
195 wfAppendToArrayIfNotDefault( 'limit', $limit , $defaults, $nondefaults);
196 wfAppendToArrayIfNotDefault( 'hideminor', $hideminor, $defaults, $nondefaults);
197 wfAppendToArrayIfNotDefault( 'hidebots', $hidebots, $defaults, $nondefaults);
198 wfAppendToArrayIfNotDefault( 'hideliu', $hideliu, $defaults, $nondefaults);
199 wfAppendToArrayIfNotDefault( 'hidepatrolled', $hidepatrolled, $defaults, $nondefaults);
200 wfAppendToArrayIfNotDefault( 'hidemyself', $hidemyself, $defaults, $nondefaults);
201 wfAppendToArrayIfNotDefault( 'from', $from, $defaults, $nondefaults);
202 wfAppendToArrayIfNotDefault( 'namespace', $namespace, $defaults, $nondefaults);
203 wfAppendToArrayIfNotDefault( 'invert', $invert, $defaults, $nondefaults);
204 wfAppendToArrayIfNotDefault( 'categories_any', $any, $defaults, $nondefaults);
205
206 // Add end of the texts
207 $wgOut->addHTML( '<div class="rcoptions">' . rcOptionsPanel( $defaults, $nondefaults ) . "\n" );
208 $wgOut->addHTML( rcNamespaceForm( $namespace, $invert, $nondefaults, $any ) . '</div>'."\n");
209 }
210
211 // And now for the content
212 $sk = $wgUser->getSkin();
213 $wgOut->setSyndicated( true );
214
215 $list = ChangesList::newFromUser( $wgUser );
216
217 if ( $wgAllowCategorizedRecentChanges ) {
218 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
219 $categories = str_replace ( "|" , "\n" , $categories ) ;
220 $categories = explode ( "\n" , $categories ) ;
221 rcFilterByCategories ( $rows , $categories , $any ) ;
222 }
223
224 $s = $list->beginRecentChangesList();
225 $counter = 1;
226 foreach( $rows as $obj ){
227 if( $limit == 0) {
228 break;
229 }
230
231 if ( ! ( $hideminor && $obj->rc_minor ) &&
232 ! ( $hidepatrolled && $obj->rc_patrolled ) ) {
233 $rc = RecentChange::newFromRow( $obj );
234 $rc->counter = $counter++;
235
236 if ($wgShowUpdatedMarker
237 && !empty( $obj->wl_notificationtimestamp )
238 && ($obj->rc_timestamp >= $obj->wl_notificationtimestamp)) {
239 $rc->notificationtimestamp = true;
240 } else {
241 $rc->notificationtimestamp = false;
242 }
243
244 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
245 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" . $dbr->strencode($obj->rc_title) ."' AND wl_namespace=$obj->rc_namespace" ;
246 $res3 = $dbr->query( $sql3, 'wfSpecialRecentChanges');
247 $x = $dbr->fetchObject( $res3 );
248 $rc->numberofWatchingusers = $x->n;
249 } else {
250 $rc->numberofWatchingusers = 0;
251 }
252 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ) );
253 --$limit;
254 }
255 }
256 $s .= $list->endRecentChangesList();
257 $wgOut->addHTML( $s );
258 }
259 }
260
261 function rcFilterByCategories ( &$rows , $categories , $any ) {
262 require_once ( 'Categoryfinder.php' ) ;
263
264 # Filter categories
265 $cats = array () ;
266 foreach ( $categories AS $cat ) {
267 $cat = trim ( $cat ) ;
268 if ( $cat == "" ) continue ;
269 $cats[] = $cat ;
270 }
271
272 # Filter articles
273 $articles = array () ;
274 $a2r = array () ;
275 foreach ( $rows AS $k => $r ) {
276 $nt = Title::newFromText ( $r->rc_title , $r->rc_namespace ) ;
277 $id = $nt->getArticleID() ;
278 if ( $id == 0 ) continue ; # Page might have been deleted...
279 if ( !in_array ( $id , $articles ) ) {
280 $articles[] = $id ;
281 }
282 if ( !isset ( $a2r[$id] ) ) {
283 $a2r[$id] = array() ;
284 }
285 $a2r[$id][] = $k ;
286 }
287
288 # Shortcut?
289 if ( count ( $articles ) == 0 OR count ( $cats ) == 0 )
290 return ;
291
292 # Look up
293 $c = new Categoryfinder ;
294 $c->seed ( $articles , $cats , $any ? "OR" : "AND" ) ;
295 $match = $c->run () ;
296
297 # Filter
298 $newrows = array () ;
299 foreach ( $match AS $id ) {
300 foreach ( $a2r[$id] AS $rev ) {
301 $k = $rev ;
302 $newrows[$k] = $rows[$k] ;
303 }
304 }
305 $rows = $newrows ;
306 }
307
308 function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
309 global $messageMemc, $wgDBname, $wgFeedCacheTimeout;
310 global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
311
312 if( !isset( $wgFeedClasses[$feedFormat] ) ) {
313 wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
314 return false;
315 }
316
317 $timekey = "$wgDBname:rcfeed:$feedFormat:timestamp";
318 $key = "$wgDBname:rcfeed:$feedFormat:limit:$limit:minor:$hideminor";
319
320 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchanges' ) .
321 ' [' . $wgContLanguageCode . ']';
322 $feed = new $wgFeedClasses[$feedFormat](
323 $feedTitle,
324 htmlspecialchars( wfMsgForContent( 'recentchangestext' ) ),
325 $wgTitle->getFullUrl() );
326
327 /**
328 * Bumping around loading up diffs can be pretty slow, so where
329 * possible we want to cache the feed output so the next visitor
330 * gets it quick too.
331 */
332 $cachedFeed = false;
333 if( ( $wgFeedCacheTimeout > 0 ) && ( $feedLastmod = $messageMemc->get( $timekey ) ) ) {
334 /**
335 * If the cached feed was rendered very recently, we may
336 * go ahead and use it even if there have been edits made
337 * since it was rendered. This keeps a swarm of requests
338 * from being too bad on a super-frequently edited wiki.
339 */
340 if( time() - wfTimestamp( TS_UNIX, $feedLastmod )
341 < $wgFeedCacheTimeout
342 || wfTimestamp( TS_UNIX, $feedLastmod )
343 > wfTimestamp( TS_UNIX, $lastmod ) ) {
344 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
345 $cachedFeed = $messageMemc->get( $key );
346 } else {
347 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
348 }
349 }
350 if( is_string( $cachedFeed ) ) {
351 wfDebug( "RC: Outputting cached feed\n" );
352 $feed->httpHeaders();
353 echo $cachedFeed;
354 } else {
355 wfDebug( "RC: rendering new feed and caching it\n" );
356 ob_start();
357 rcDoOutputFeed( $rows, $feed );
358 $cachedFeed = ob_get_contents();
359 ob_end_flush();
360
361 $expire = 3600 * 24; # One day
362 $messageMemc->set( $key, $cachedFeed );
363 $messageMemc->set( $timekey, wfTimestamp( TS_MW ), $expire );
364 }
365 return true;
366 }
367
368 function rcDoOutputFeed( $rows, &$feed ) {
369 $fname = 'rcDoOutputFeed';
370 wfProfileIn( $fname );
371
372 $feed->outHeader();
373
374 # Merge adjacent edits by one user
375 $sorted = array();
376 $n = 0;
377 foreach( $rows as $obj ) {
378 if( $n > 0 &&
379 $obj->rc_namespace >= 0 &&
380 $obj->rc_cur_id == $sorted[$n-1]->rc_cur_id &&
381 $obj->rc_user_text == $sorted[$n-1]->rc_user_text ) {
382 $sorted[$n-1]->rc_last_oldid = $obj->rc_last_oldid;
383 } else {
384 $sorted[$n] = $obj;
385 $n++;
386 }
387 $first = false;
388 }
389
390 foreach( $sorted as $obj ) {
391 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
392 $talkpage = $title->getTalkPage();
393 $item = new FeedItem(
394 $title->getPrefixedText(),
395 rcFormatDiff( $obj ),
396 $title->getFullURL(),
397 $obj->rc_timestamp,
398 $obj->rc_user_text,
399 $talkpage->getFullURL()
400 );
401 $feed->outItem( $item );
402 }
403 $feed->outFooter();
404 wfProfileOut( $fname );
405 }
406
407 /**
408 *
409 */
410 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
411 global $wgUser, $wgLang, $wgContLang;
412 $sk = $wgUser->getSkin();
413 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
414 ($lim ? $wgLang->formatNum( "{$lim}" ) : wfMsg( 'recentchangesall' ) ), "{$more}" .
415 ($d ? "days={$d}&" : '') . 'limit='.$lim );
416 return $s;
417 }
418
419 /**
420 *
421 */
422 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
423 global $wgUser, $wgLang, $wgContLang;
424 $sk = $wgUser->getSkin();
425 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
426 ($d ? $wgLang->formatNum( "{$d}" ) : wfMsg( 'recentchangesall' ) ), $more.'days='.$d .
427 ($lim ? '&limit='.$lim : '') );
428 return $s;
429 }
430
431 /**
432 * Used by Recentchangeslinked
433 */
434 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
435 $botLink = '', $liuLink = '', $patrLink = '', $myselfLink = '' ) {
436 if ($more != '') $more .= '&';
437 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
438 rcCountLink( 100, $days, $page, $more ) . ' | ' .
439 rcCountLink( 250, $days, $page, $more ) . ' | ' .
440 rcCountLink( 500, $days, $page, $more ) .
441 ( $doall ? ( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
442 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
443 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
444 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
445 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
446 rcDaysLink( $limit, 30, $page, $more ) .
447 ( $doall ? ( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
448 $shm = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink, $myselfLink );
449 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
450 return $note;
451 }
452
453
454 /**
455 * Makes change an option link which carries all the other options
456 */
457 function makeOptionsLink( $title, $override, $options ) {
458 global $wgUser, $wgContLang;
459 $sk = $wgUser->getSkin();
460 return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
461 $title, wfArrayToCGI( $override, $options ) );
462 }
463
464 /**
465 * Creates the options panel
466 */
467 function rcOptionsPanel( $defaults, $nondefaults ) {
468 global $wgLang;
469
470 $options = $nondefaults + $defaults;
471
472 if( $options['from'] )
473 $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $options['limit'] ), $wgLang->timeanddate( $options['from'], true ) );
474 else
475 $note = wfMsg( 'rcnote', $wgLang->formatNum( $options['limit'] ), $wgLang->formatNum( $options['days'] ) );
476
477 // limit links
478 $cl = '';
479 $options_limit = array(50, 100, 250, 500);
480 $i = 0;
481 while ( $i+1 < count($options_limit) ) {
482 $cl .= makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) . ' | ' ;
483 $i++;
484 }
485 $cl .= makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) ;
486
487 // day links, reset 'from' to none
488 $dl = '';
489 $options_days = array(1, 3, 7, 14, 30);
490 $i = 0;
491 while ( $i+1 < count($options_days) ) {
492 $dl .= makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) . ' | ' ;
493 $i++;
494 }
495 $dl .= makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) ;
496
497 // show/hide links
498 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
499 $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
500 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
501 $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
502 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
503 $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
504 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
505 $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
506 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
507 $myselfLink = makeOptionsLink( $showhide[1-$options['hidemyself']],
508 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
509 $hl = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink, $myselfLink );
510
511 // show from this onward link
512 $now = $wgLang->timeanddate( wfTimestampNow(), true );
513 $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
514
515 $rclinks = wfMsg( 'rclinks', $cl, $dl, $hl );
516 $rclistfrom = wfMsg( 'rclistfrom', $tl );
517 return "$note<br />$rclinks<br />$rclistfrom";
518
519 }
520
521 /**<F2>
522 * Creates the choose namespace selection
523 *
524 * @access private
525 *
526 * @param mixed $namespace The key of the currently selected namespace, empty string
527 * if there is none
528 * @param bool $invert Whether to invert the namespace selection
529 * @param array $nondefaults An array of non default options to be remembered
530 * @param bool $categories_any Default value for the checkbox
531 *
532 * @return string
533 */
534 function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
535 global $wgScript, $wgAllowCategorizedRecentChanges, $wgRequest;
536 $t = Title::makeTitle( NS_SPECIAL, 'Recentchanges' );
537
538 $namespaceselect = HTMLnamespaceselector($namespace, '');
539 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
540 $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ? ' checked="checked"' : '' ) . ' />';
541
542 if ( $wgAllowCategorizedRecentChanges ) {
543 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
544 $cb_arr = array( 'type' => 'checkbox', 'name' => 'categories_any', 'value' => "1" ) ;
545 if ( $categories_any ) $cb_arr['checked'] = "checked" ;
546 $catbox = "<br/>" ;
547 $catbox .= wfMsg('rc_categories') . " ";
548 $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
549 $catbox .= " &nbsp;" ;
550 $catbox .= wfElement('input', $cb_arr );
551 $catbox .= wfMsg('rc_categories_any');
552 } else {
553 $catbox = "" ;
554 }
555
556 $out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
557
558 foreach ( $nondefaults as $key => $value ) {
559 if ($key != 'namespace' && $key != 'invert')
560 $out .= wfElement('input', array( 'type' => 'hidden', 'name' => $key, 'value' => $value));
561 }
562
563 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
564 $out .= "
565 <div id='nsselect' class='recentchanges'>
566 <label for='namespace'>" . wfMsgHtml('namespace') . "</label>
567 {$namespaceselect}{$submitbutton}{$invertbox} <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>{$catbox}\n</div>";
568 $out .= '</form></div>';
569 return $out;
570 }
571
572
573 /**
574 * Format a diff for the newsfeed
575 */
576 function rcFormatDiff( $row ) {
577 global $wgFeedDiffCutoff, $wgContLang;
578 $fname = 'rcFormatDiff';
579 wfProfileIn( $fname );
580
581 require_once( 'DifferenceEngine.php' );
582 $completeText = '<p>' . htmlspecialchars( $row->rc_comment ) . "</p>\n";
583
584 if( $row->rc_namespace >= 0 ) {
585 if( $row->rc_last_oldid ) {
586 wfProfileIn( "$fname-dodiff" );
587
588 $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title );
589 $de = new DifferenceEngine( $titleObj, $row->rc_last_oldid, $row->rc_this_oldid );
590 $diffText = $de->getDiff( wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp ) ),
591 wfMsg( 'currentrev' ) );
592
593 if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
594 // Omit large diffs
595 $diffLink = $titleObj->escapeFullUrl(
596 'diff=' . $row->rc_this_oldid .
597 '&oldid=' . $row->rc_last_oldid );
598 $diffText = '<a href="' .
599 $diffLink .
600 '">' .
601 htmlspecialchars( wfMsgForContent( 'difference' ) ) .
602 '</a>';
603 } elseif ( $diffText === false ) {
604 // Error in diff engine, probably a missing revision
605 $diffText = "<p>Can't load revision $row->rc_this_oldid</p>";
606 } else {
607 // Diff output fine, clean up any illegal UTF-8
608 $diffText = UtfNormal::cleanUp( $diffText );
609 $diffText = rcApplyDiffStyle( $diffText );
610 }
611 wfProfileOut( "$fname-dodiff" );
612 } else {
613 $rev = Revision::newFromId( $row->rc_this_oldid );
614 if( is_null( $rev ) ) {
615 $newtext = '';
616 } else {
617 $newtext = $rev->getText();
618 }
619 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
620 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
621 }
622 $completeText .= $diffText;
623 }
624
625 wfProfileOut( $fname );
626 return $completeText;
627 }
628
629 /**
630 * Hacky application of diff styles for the feeds.
631 * Might be 'cleaner' to use DOM or XSLT or something,
632 * but *gack* it's a pain in the ass.
633 *
634 * @param string $text
635 * @return string
636 * @access private
637 */
638 function rcApplyDiffStyle( $text ) {
639 $styles = array(
640 'diff' => 'background-color: white;',
641 'diff-otitle' => 'background-color: white;',
642 'diff-ntitle' => 'background-color: white;',
643 'diff-addedline' => 'background: #cfc; font-size: smaller;',
644 'diff-deletedline' => 'background: #ffa; font-size: smaller;',
645 'diff-context' => 'background: #eee; font-size: smaller;',
646 'diffchange' => 'color: red; font-weight: bold;',
647 );
648
649 foreach( $styles as $class => $style ) {
650 $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
651 "\\1style=\"$style\"\\3", $text );
652 }
653
654 return $text;
655 }
656
657 ?>