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