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