(bug 4974) Don't follow redirected talk page on "new messages" link
[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 global $wgSitename, $wgFeedClasses, $wgContLanguageCode;
370 $fname = 'rcDoOutputFeed';
371 wfProfileIn( $fname );
372
373 $feed->outHeader();
374
375 # Merge adjacent edits by one user
376 $sorted = array();
377 $n = 0;
378 foreach( $rows as $obj ) {
379 if( $n > 0 &&
380 $obj->rc_namespace >= 0 &&
381 $obj->rc_cur_id == $sorted[$n-1]->rc_cur_id &&
382 $obj->rc_user_text == $sorted[$n-1]->rc_user_text ) {
383 $sorted[$n-1]->rc_last_oldid = $obj->rc_last_oldid;
384 } else {
385 $sorted[$n] = $obj;
386 $n++;
387 }
388 $first = false;
389 }
390
391 foreach( $sorted as $obj ) {
392 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
393 $talkpage = $title->getTalkPage();
394 $item = new FeedItem(
395 $title->getPrefixedText(),
396 rcFormatDiff( $obj ),
397 $title->getFullURL(),
398 $obj->rc_timestamp,
399 $obj->rc_user_text,
400 $talkpage->getFullURL()
401 );
402 $feed->outItem( $item );
403 }
404 $feed->outFooter();
405 wfProfileOut( $fname );
406 }
407
408 /**
409 *
410 */
411 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
412 global $wgUser, $wgLang, $wgContLang;
413 $sk = $wgUser->getSkin();
414 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
415 ($lim ? $wgLang->formatNum( "{$lim}" ) : wfMsg( 'recentchangesall' ) ), "{$more}" .
416 ($d ? "days={$d}&" : '') . 'limit='.$lim );
417 return $s;
418 }
419
420 /**
421 *
422 */
423 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
424 global $wgUser, $wgLang, $wgContLang;
425 $sk = $wgUser->getSkin();
426 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
427 ($d ? $wgLang->formatNum( "{$d}" ) : wfMsg( 'recentchangesall' ) ), $more.'days='.$d .
428 ($lim ? '&limit='.$lim : '') );
429 return $s;
430 }
431
432 /**
433 * Used by Recentchangeslinked
434 */
435 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
436 $botLink = '', $liuLink = '', $patrLink = '', $myselfLink = '' ) {
437 if ($more != '') $more .= '&';
438 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
439 rcCountLink( 100, $days, $page, $more ) . ' | ' .
440 rcCountLink( 250, $days, $page, $more ) . ' | ' .
441 rcCountLink( 500, $days, $page, $more ) .
442 ( $doall ? ( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
443 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
444 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
445 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
446 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
447 rcDaysLink( $limit, 30, $page, $more ) .
448 ( $doall ? ( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
449 $shm = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink, $myselfLink );
450 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
451 return $note;
452 }
453
454
455 /**
456 * Makes change an option link which carries all the other options
457 */
458 function makeOptionsLink( $title, $override, $options ) {
459 global $wgUser, $wgLang, $wgContLang;
460 $sk = $wgUser->getSkin();
461 return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
462 $title, wfArrayToCGI( $override, $options ) );
463 }
464
465 /**
466 * Creates the options panel
467 */
468 function rcOptionsPanel( $defaults, $nondefaults ) {
469 global $wgLang;
470
471 $options = $nondefaults + $defaults;
472
473 if( $options['from'] )
474 $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $options['limit'] ), $wgLang->timeanddate( $options['from'], true ) );
475 else
476 $note = wfMsg( 'rcnote', $wgLang->formatNum( $options['limit'] ), $wgLang->formatNum( $options['days'] ) );
477
478 // limit links
479 $cl = '';
480 $options_limit = array(50, 100, 250, 500);
481 $i = 0;
482 while ( $i+1 < count($options_limit) ) {
483 $cl .= makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) . ' | ' ;
484 $i++;
485 }
486 $cl .= makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) ;
487
488 // day links, reset 'from' to none
489 $dl = '';
490 $options_days = array(1, 3, 7, 14, 30);
491 $i = 0;
492 while ( $i+1 < count($options_days) ) {
493 $dl .= makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) . ' | ' ;
494 $i++;
495 }
496 $dl .= makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) ;
497
498 // show/hide links
499 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
500 $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
501 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
502 $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
503 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
504 $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
505 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
506 $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
507 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
508 $myselfLink = makeOptionsLink( $showhide[1-$options['hidemyself']],
509 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
510 $hl = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink, $myselfLink );
511
512 // show from this onward link
513 $now = $wgLang->timeanddate( wfTimestampNow(), true );
514 $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
515
516 $rclinks = wfMsg( 'rclinks', $cl, $dl, $hl );
517 $rclistfrom = wfMsg( 'rclistfrom', $tl );
518 return "$note<br />$rclinks<br />$rclistfrom";
519
520 }
521
522 /**<F2>
523 * Creates the choose namespace selection
524 *
525 * @access private
526 *
527 * @param mixed $namespace The key of the currently selected namespace, empty string
528 * if there is none
529 * @param bool $invert Whether to invert the namespace selection
530 * @param array $nondefaults An array of non default options to be remembered
531 * @param bool $categories_any Default value for the checkbox
532 *
533 * @return string
534 */
535 function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
536 global $wgContLang, $wgScript, $wgAllowCategorizedRecentChanges, $wgRequest;
537 $t = Title::makeTitle( NS_SPECIAL, 'Recentchanges' );
538
539 $namespaceselect = HTMLnamespaceselector($namespace, '');
540 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
541 $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ? ' checked="checked"' : '' ) . ' />';
542
543 if ( $wgAllowCategorizedRecentChanges ) {
544 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
545 $cb_arr = array( 'type' => 'checkbox', 'name' => 'categories_any', 'value' => "1" ) ;
546 if ( $categories_any ) $cb_arr['checked'] = "checked" ;
547 $catbox = "<br/>" ;
548 $catbox .= wfMsg('rc_categories') . " ";
549 $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
550 $catbox .= " &nbsp;" ;
551 $catbox .= wfElement('input', $cb_arr );
552 $catbox .= wfMsg('rc_categories_any');
553 } else {
554 $catbox = "" ;
555 }
556
557 $out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
558
559 foreach ( $nondefaults as $key => $value ) {
560 if ($key != 'namespace' && $key != 'invert')
561 $out .= wfElement('input', array( 'type' => 'hidden', 'name' => $key, 'value' => $value));
562 }
563
564 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
565 $out .= "
566 <div id='nsselect' class='recentchanges'>
567 <label for='namespace'>" . wfMsgHtml('namespace') . "</label>
568 {$namespaceselect}{$submitbutton}{$invertbox} <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>{$catbox}\n</div>";
569 $out .= '</form></div>';
570 return $out;
571 }
572
573
574 /**
575 * Format a diff for the newsfeed
576 */
577 function rcFormatDiff( $row ) {
578 global $wgFeedDiffCutoff, $wgContLang;
579 $fname = 'rcFormatDiff';
580 wfProfileIn( $fname );
581
582 require_once( 'DifferenceEngine.php' );
583 $completeText = '<p>' . htmlspecialchars( $row->rc_comment ) . "</p>\n";
584
585 if( $row->rc_namespace >= 0 ) {
586 if( $row->rc_last_oldid ) {
587 wfProfileIn( "$fname-dodiff" );
588
589 $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title );
590 $de = new DifferenceEngine( $titleObj, $row->rc_last_oldid, $row->rc_this_oldid );
591 $diffText = $de->getDiff( wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp ) ),
592 wfMsg( 'currentrev' ) );
593
594 if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
595 // Omit large diffs
596 $diffLink = $titleObj->escapeFullUrl(
597 'diff=' . $row->rc_this_oldid .
598 '&oldid=' . $row->rc_last_oldid );
599 $diffText = '<a href="' .
600 $diffLink .
601 '">' .
602 htmlspecialchars( wfMsgForContent( 'difference' ) ) .
603 '</a>';
604 } elseif ( $diffText === false ) {
605 // Error in diff engine, probably a missing revision
606 $diffText = "<p>Can't load revision $row->rc_this_oldid</p>";
607 } else {
608 // Diff output fine, clean up any illegal UTF-8
609 $diffText = UtfNormal::cleanUp( $diffText );
610 $diffText = rcApplyDiffStyle( $diffText );
611 }
612 wfProfileOut( "$fname-dodiff" );
613 } else {
614 $rev = Revision::newFromId( $row->rc_this_oldid );
615 if( is_null( $rev ) ) {
616 $newtext = '';
617 } else {
618 $newtext = $rev->getText();
619 }
620 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
621 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
622 }
623 $completeText .= $diffText;
624 }
625
626 wfProfileOut( $fname );
627 return $completeText;
628 }
629
630 /**
631 * Hacky application of diff styles for the feeds.
632 * Might be 'cleaner' to use DOM or XSLT or something,
633 * but *gack* it's a pain in the ass.
634 *
635 * @param string $text
636 * @return string
637 * @access private
638 */
639 function rcApplyDiffStyle( $text ) {
640 $styles = array(
641 'diff' => 'background-color: white;',
642 'diff-otitle' => 'background-color: white;',
643 'diff-ntitle' => 'background-color: white;',
644 'diff-addedline' => 'background: #cfc; font-size: smaller;',
645 'diff-deletedline' => 'background: #ffa; font-size: smaller;',
646 'diff-context' => 'background: #eee; font-size: smaller;',
647 'diffchange' => 'color: red; font-weight: bold;',
648 );
649
650 foreach( $styles as $class => $style ) {
651 $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
652 "\\1style=\"$style\"\\3", $text );
653 }
654
655 return $text;
656 }
657
658 ?>