5 * @subpackage SpecialPage
11 function wfSpecialRecentchanges( $par, $specialPage ) {
12 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol, $wgDBtype;
13 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
14 global $wgAllowCategorizedRecentChanges ;
15 $fname = 'wfSpecialRecentchanges';
17 # Get query parameters
18 $feedFormat = $wgRequest->getVal( 'feed' );
20 /* Checkbox values can't be true be default, because
21 * we cannot differentiate between unset and not set at all
24 /* int */ 'days' => $wgUser->getDefaultOption('rcdays'),
25 /* int */ 'limit' => $wgUser->getDefaultOption('rclimit'),
26 /* bool */ 'hideminor' => false,
27 /* bool */ 'hidebots' => true,
28 /* bool */ 'hideanons' => false,
29 /* bool */ 'hideliu' => false,
30 /* bool */ 'hidepatrolled' => false,
31 /* bool */ 'hidemyself' => false,
32 /* text */ 'from' => '',
33 /* text */ 'namespace' => null,
34 /* bool */ 'invert' => false,
35 /* bool */ 'categories_any' => false,
41 $days = $wgUser->getOption( 'rcdays' );
42 if ( !$days ) { $days = $defaults['days']; }
43 $days = $wgRequest->getInt( 'days', $days );
45 $limit = $wgUser->getOption( 'rclimit' );
46 if ( !$limit ) { $limit = $defaults['limit']; }
48 # list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
49 $limit = $wgRequest->getInt( 'limit', $limit );
51 /* order of selection: url > preferences > default */
52 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor') ?
true : $defaults['hideminor'] );
54 # As a feed, use limited settings only
57 if( $limit > $wgFeedLimit ) {
58 $options['limit'] = $wgFeedLimit;
63 $namespace = $wgRequest->getIntOrNull( 'namespace' );
64 $invert = $wgRequest->getBool( 'invert', $defaults['invert'] );
65 $hidebots = $wgRequest->getBool( 'hidebots', $defaults['hidebots'] );
66 $hideanons = $wgRequest->getBool( 'hideanons', $defaults['hideanons'] );
67 $hideliu = $wgRequest->getBool( 'hideliu', $defaults['hideliu'] );
68 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', $defaults['hidepatrolled'] );
69 $hidemyself = $wgRequest->getBool ( 'hidemyself', $defaults['hidemyself'] );
70 $from = $wgRequest->getVal( 'from', $defaults['from'] );
72 # Get query parameters from path
74 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
75 foreach ( $bits as $bit ) {
76 if ( 'hidebots' == $bit ) $hidebots = 1;
77 if ( 'bots' == $bit ) $hidebots = 0;
78 if ( 'hideminor' == $bit ) $hideminor = 1;
79 if ( 'minor' == $bit ) $hideminor = 0;
80 if ( 'hideliu' == $bit ) $hideliu = 1;
81 if ( 'hidepatrolled' == $bit ) $hidepatrolled = 1;
82 if ( 'hideanons' == $bit ) $hideanons = 1;
83 if ( 'hidemyself' == $bit ) $hidemyself = 1;
85 if ( is_numeric( $bit ) ) {
89 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
93 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
100 if ( $limit < 0 ||
$limit > 5000 ) $limit = $defaults['limit'];
103 # Database connection and caching
104 $dbr =& wfGetDB( DB_SLAVE
);
105 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
108 $cutoff_unixtime = time() - ( $days * 86400 );
109 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime %
86400);
110 $cutoff = $dbr->timestamp( $cutoff_unixtime );
111 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW
,$cutoff)) {
112 $cutoff = $dbr->timestamp($from);
114 $from = $defaults['from'];
117 # 10 seconds server-side caching max
118 $wgOut->setSquidMaxage( 10 );
120 # Get last modified date, for client caching
121 # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
122 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
123 if ( $feedFormat ||
!$wgUseRCPatrol ) {
124 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
125 # Client cache fresh and headers sent, nothing more to do.
130 # It makes no sense to hide both anons and logged-in users
131 # Where this occurs, force anons to be shown
132 if( $hideanons && $hideliu )
135 # Form WHERE fragments for all the options
136 $hidem = $hideminor ?
'AND rc_minor = 0' : '';
137 $hidem .= $hidebots ?
' AND rc_bot = 0' : '';
138 $hidem .= $hideliu ?
' AND rc_user = 0' : '';
139 $hidem .= ( $wgUseRCPatrol && $hidepatrolled ) ?
' AND rc_patrolled = 0' : '';
140 $hidem .= $hideanons ?
' AND rc_user != 0' : '';
143 if( $wgUser->getID() ) {
144 $hidem .= ' AND rc_user != ' . $wgUser->getID();
146 $hidem .= ' AND rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() );
150 # Namespace filtering
151 $hidem .= is_null( $namespace ) ?
'' : ' AND rc_namespace' . ($invert ?
'!=' : '=') . $namespace;
153 // This is the big thing!
155 $uid = $wgUser->getID();
158 $forceclause = $dbr->useIndexClause("rc_timestamp");
159 $sql2 = "SELECT * FROM $recentchanges $forceclause".
160 ($uid ?
"LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") .
161 "WHERE rc_timestamp >= '{$cutoff}' {$hidem} " .
162 "ORDER BY rc_timestamp DESC";
163 $sql2 = $dbr->limitResult($sql2, $limit, 0);
164 $res = $dbr->query( $sql2, $fname );
166 // Fetch results, prepare a batch link existence check query
168 $batch = new LinkBatch
;
169 while( $row = $dbr->fetchObject( $res ) ){
171 if ( !$feedFormat ) {
173 $title = Title
::makeTitleSafe( NS_USER
, $row->rc_user_text
);
174 $batch->addObj( $title );
177 $title = Title
::makeTitleSafe( NS_USER_TALK
, $row->rc_user_text
);
178 $batch->addObj( $title );
182 $dbr->freeResult( $res );
185 rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod );
190 // Run existence checks
192 $any = $wgRequest->getBool( 'categories_any', $defaults['categories_any']);
195 if ( !$specialPage->including() ) {
196 $wgOut->addWikiText( wfMsgForContent( "recentchangestext" ) );
198 // Dump everything here
199 $nondefaults = array();
201 wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults);
202 wfAppendToArrayIfNotDefault( 'limit', $limit , $defaults, $nondefaults);
203 wfAppendToArrayIfNotDefault( 'hideminor', $hideminor, $defaults, $nondefaults);
204 wfAppendToArrayIfNotDefault( 'hidebots', $hidebots, $defaults, $nondefaults);
205 wfAppendToArrayIfNotDefault( 'hideanons', $hideanons, $defaults, $nondefaults );
206 wfAppendToArrayIfNotDefault( 'hideliu', $hideliu, $defaults, $nondefaults);
207 wfAppendToArrayIfNotDefault( 'hidepatrolled', $hidepatrolled, $defaults, $nondefaults);
208 wfAppendToArrayIfNotDefault( 'hidemyself', $hidemyself, $defaults, $nondefaults);
209 wfAppendToArrayIfNotDefault( 'from', $from, $defaults, $nondefaults);
210 wfAppendToArrayIfNotDefault( 'namespace', $namespace, $defaults, $nondefaults);
211 wfAppendToArrayIfNotDefault( 'invert', $invert, $defaults, $nondefaults);
212 wfAppendToArrayIfNotDefault( 'categories_any', $any, $defaults, $nondefaults);
214 // Add end of the texts
215 $wgOut->addHTML( '<div class="rcoptions">' . rcOptionsPanel( $defaults, $nondefaults ) . "\n" );
216 $wgOut->addHTML( rcNamespaceForm( $namespace, $invert, $nondefaults, $any ) . '</div>'."\n");
219 // And now for the content
220 $sk = $wgUser->getSkin();
221 $wgOut->setSyndicated( true );
223 $list = ChangesList
::newFromUser( $wgUser );
225 if ( $wgAllowCategorizedRecentChanges ) {
226 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
227 $categories = str_replace ( "|" , "\n" , $categories ) ;
228 $categories = explode ( "\n" , $categories ) ;
229 rcFilterByCategories ( $rows , $categories , $any ) ;
232 $s = $list->beginRecentChangesList();
234 foreach( $rows as $obj ){
239 if ( ! ( $hideminor && $obj->rc_minor
) &&
240 ! ( $hidepatrolled && $obj->rc_patrolled
) ) {
241 $rc = RecentChange
::newFromRow( $obj );
242 $rc->counter
= $counter++
;
244 if ($wgShowUpdatedMarker
245 && !empty( $obj->wl_notificationtimestamp
)
246 && ($obj->rc_timestamp
>= $obj->wl_notificationtimestamp
)) {
247 $rc->notificationtimestamp
= true;
249 $rc->notificationtimestamp
= false;
252 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
253 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" . $dbr->strencode($obj->rc_title
) ."' AND wl_namespace=$obj->rc_namespace" ;
254 $res3 = $dbr->query( $sql3, 'wfSpecialRecentChanges');
255 $x = $dbr->fetchObject( $res3 );
256 $rc->numberofWatchingusers
= $x->n
;
258 $rc->numberofWatchingusers
= 0;
260 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user
) );
264 $s .= $list->endRecentChangesList();
265 $wgOut->addHTML( $s );
269 function rcFilterByCategories ( &$rows , $categories , $any ) {
270 require_once ( 'Categoryfinder.php' ) ;
274 foreach ( $categories AS $cat ) {
275 $cat = trim ( $cat ) ;
276 if ( $cat == "" ) continue ;
281 $articles = array () ;
283 foreach ( $rows AS $k => $r ) {
284 $nt = Title
::newFromText ( $r->rc_title
, $r->rc_namespace
) ;
285 $id = $nt->getArticleID() ;
286 if ( $id == 0 ) continue ; # Page might have been deleted...
287 if ( !in_array ( $id , $articles ) ) {
290 if ( !isset ( $a2r[$id] ) ) {
291 $a2r[$id] = array() ;
297 if ( count ( $articles ) == 0 OR count ( $cats ) == 0 )
301 $c = new Categoryfinder
;
302 $c->seed ( $articles , $cats , $any ?
"OR" : "AND" ) ;
303 $match = $c->run () ;
306 $newrows = array () ;
307 foreach ( $match AS $id ) {
308 foreach ( $a2r[$id] AS $rev ) {
310 $newrows[$k] = $rows[$k] ;
316 function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
317 global $messageMemc, $wgDBname, $wgFeedCacheTimeout;
318 global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
320 if( !isset( $wgFeedClasses[$feedFormat] ) ) {
321 wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
325 $timekey = "$wgDBname:rcfeed:$feedFormat:timestamp";
326 $key = "$wgDBname:rcfeed:$feedFormat:limit:$limit:minor:$hideminor";
328 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchanges' ) .
329 ' [' . $wgContLanguageCode . ']';
330 $feed = new $wgFeedClasses[$feedFormat](
332 htmlspecialchars( wfMsgForContent( 'recentchangestext' ) ),
333 $wgTitle->getFullUrl() );
336 * Bumping around loading up diffs can be pretty slow, so where
337 * possible we want to cache the feed output so the next visitor
341 if( ( $wgFeedCacheTimeout > 0 ) && ( $feedLastmod = $messageMemc->get( $timekey ) ) ) {
343 * If the cached feed was rendered very recently, we may
344 * go ahead and use it even if there have been edits made
345 * since it was rendered. This keeps a swarm of requests
346 * from being too bad on a super-frequently edited wiki.
348 if( time() - wfTimestamp( TS_UNIX
, $feedLastmod )
349 < $wgFeedCacheTimeout
350 ||
wfTimestamp( TS_UNIX
, $feedLastmod )
351 > wfTimestamp( TS_UNIX
, $lastmod ) ) {
352 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
353 $cachedFeed = $messageMemc->get( $key );
355 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
358 if( is_string( $cachedFeed ) ) {
359 wfDebug( "RC: Outputting cached feed\n" );
360 $feed->httpHeaders();
363 wfDebug( "RC: rendering new feed and caching it\n" );
365 rcDoOutputFeed( $rows, $feed );
366 $cachedFeed = ob_get_contents();
369 $expire = 3600 * 24; # One day
370 $messageMemc->set( $key, $cachedFeed );
371 $messageMemc->set( $timekey, wfTimestamp( TS_MW
), $expire );
376 function rcDoOutputFeed( $rows, &$feed ) {
377 $fname = 'rcDoOutputFeed';
378 wfProfileIn( $fname );
382 # Merge adjacent edits by one user
385 foreach( $rows as $obj ) {
387 $obj->rc_namespace
>= 0 &&
388 $obj->rc_cur_id
== $sorted[$n-1]->rc_cur_id
&&
389 $obj->rc_user_text
== $sorted[$n-1]->rc_user_text
) {
390 $sorted[$n-1]->rc_last_oldid
= $obj->rc_last_oldid
;
398 foreach( $sorted as $obj ) {
399 $title = Title
::makeTitle( $obj->rc_namespace
, $obj->rc_title
);
400 $talkpage = $title->getTalkPage();
401 $item = new FeedItem(
402 $title->getPrefixedText(),
403 rcFormatDiff( $obj ),
404 $title->getFullURL(),
407 $talkpage->getFullURL()
409 $feed->outItem( $item );
412 wfProfileOut( $fname );
418 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
419 global $wgUser, $wgLang, $wgContLang;
420 $sk = $wgUser->getSkin();
421 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
422 ($lim ?
$wgLang->formatNum( "{$lim}" ) : wfMsg( 'recentchangesall' ) ), "{$more}" .
423 ($d ?
"days={$d}&" : '') . 'limit='.$lim );
430 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
431 global $wgUser, $wgLang, $wgContLang;
432 $sk = $wgUser->getSkin();
433 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
434 ($d ?
$wgLang->formatNum( "{$d}" ) : wfMsg( 'recentchangesall' ) ), $more.'days='.$d .
435 ($lim ?
'&limit='.$lim : '') );
440 * Used by Recentchangeslinked
442 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
443 $botLink = '', $liuLink = '', $patrLink = '', $myselfLink = '' ) {
444 if ($more != '') $more .= '&';
445 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
446 rcCountLink( 100, $days, $page, $more ) . ' | ' .
447 rcCountLink( 250, $days, $page, $more ) . ' | ' .
448 rcCountLink( 500, $days, $page, $more ) .
449 ( $doall ?
( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
450 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
451 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
452 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
453 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
454 rcDaysLink( $limit, 30, $page, $more ) .
455 ( $doall ?
( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
457 $linkParts = array( 'minorLink' => 'minor', 'botLink' => 'bots', 'liuLink' => 'liu', 'patrLink' => 'patr', 'myselfLink' => 'mine' );
458 foreach( $linkParts as $linkVar => $linkMsg ) {
459 if( $
$linkVar != '' )
460 $links[] = wfMsgHtml( 'rcshowhide' . $linkMsg, $
$linkVar );
463 $shm = implode( ' | ', $links );
464 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
470 * Makes change an option link which carries all the other options
471 * @param $title @see Title
475 function makeOptionsLink( $title, $override, $options ) {
476 global $wgUser, $wgContLang;
477 $sk = $wgUser->getSkin();
478 return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
479 $title, wfArrayToCGI( $override, $options ) );
483 * Creates the options panel.
485 * @param $nondefaults
487 function rcOptionsPanel( $defaults, $nondefaults ) {
488 global $wgLang, $wgUseRCPatrol;
490 $options = $nondefaults +
$defaults;
492 if( $options['from'] )
493 $note = wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
494 $wgLang->formatNum( $options['limit'] ),
495 $wgLang->timeanddate( $options['from'], true ) );
497 $note = wfMsgExt( 'rcnote', array( 'parseinline' ),
498 $wgLang->formatNum( $options['limit'] ),
499 $wgLang->formatNum( $options['days'] ),
500 $wgLang->timeAndDate( wfTimestampNow(), true ) );
503 $options_limit = array(50, 100, 250, 500);
504 foreach( $options_limit as $value ) {
505 $cl[] = makeOptionsLink( $wgLang->formatNum( $value ),
506 array( 'limit' => $value ), $nondefaults) ;
508 $cl = implode( ' | ', $cl);
510 // day links, reset 'from' to none
511 $options_days = array(1, 3, 7, 14, 30);
512 foreach( $options_days as $value ) {
513 $dl[] = makeOptionsLink( $wgLang->formatNum( $value ),
514 array( 'days' => $value, 'from' => '' ), $nondefaults) ;
516 $dl = implode( ' | ', $dl);
520 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
521 $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
522 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
523 $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
524 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
525 $anonsLink = makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
526 array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
527 $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
528 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
529 $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
530 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
531 $myselfLink = makeOptionsLink( $showhide[1-$options['hidemyself']],
532 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
534 $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
535 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
536 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
537 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
539 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
540 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
541 $hl = implode( ' | ', $links );
543 // show from this onward link
544 $now = $wgLang->timeanddate( wfTimestampNow(), true );
545 $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
547 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter'),
549 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter'), $tl );
550 return "$note<br />$rclinks<br />$rclistfrom";
555 * Creates the choose namespace selection
559 * @param $namespace Mixed: the key of the currently selected namespace, empty string
561 * @param $invert Bool: whether to invert the namespace selection
562 * @param $nondefaults Array: an array of non default options to be remembered
563 * @param $categories_any Bool: Default value for the checkbox
567 function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
568 global $wgScript, $wgAllowCategorizedRecentChanges, $wgRequest;
569 $t = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
571 $namespaceselect = HTMLnamespaceselector($namespace, '');
572 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
573 $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ?
' checked="checked"' : '' ) . ' />';
575 if ( $wgAllowCategorizedRecentChanges ) {
576 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
577 $cb_arr = array( 'type' => 'checkbox', 'name' => 'categories_any', 'value' => "1" ) ;
578 if ( $categories_any ) $cb_arr['checked'] = "checked" ;
580 $catbox .= wfMsgExt('rc_categories', array('parseinline')) . " ";
581 $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
582 $catbox .= " " ;
583 $catbox .= wfElement('input', $cb_arr );
584 $catbox .= wfMsgExt('rc_categories_any', array('parseinline'));
589 $out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
591 foreach ( $nondefaults as $key => $value ) {
592 if ($key != 'namespace' && $key != 'invert')
593 $out .= wfElement('input', array( 'type' => 'hidden', 'name' => $key, 'value' => $value));
596 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
598 <div id='nsselect' class='recentchanges'>
599 <label for='namespace'>" . wfMsgHtml('namespace') . "</label>
600 {$namespaceselect}{$submitbutton}{$invertbox} <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>{$catbox}\n</div>";
601 $out .= '</form></div>';
607 * Format a diff for the newsfeed
609 function rcFormatDiff( $row ) {
610 $titleObj = Title
::makeTitle( $row->rc_namespace
, $row->rc_title
);
611 return rcFormatDiffRow( $titleObj,
612 $row->rc_last_oldid
, $row->rc_this_oldid
,
617 function rcFormatDiffRow( $title, $oldid, $newid, $timestamp, $comment ) {
618 global $wgFeedDiffCutoff, $wgContLang, $wgUser;
619 $fname = 'rcFormatDiff';
620 wfProfileIn( $fname );
622 require_once( 'DifferenceEngine.php' );
623 $skin = $wgUser->getSkin();
624 $completeText = '<p>' . $skin->formatComment( $comment ) . "</p>\n";
626 if( $title->getNamespace() >= 0 ) {
628 wfProfileIn( "$fname-dodiff" );
630 $de = new DifferenceEngine( $title, $oldid, $newid );
631 #$diffText = $de->getDiff( wfMsg( 'revisionasof',
632 # $wgContLang->timeanddate( $timestamp ) ),
633 # wfMsg( 'currentrev' ) );
634 $diffText = $de->getDiff(
635 wfMsg( 'previousrevision' ), // hack
636 wfMsg( 'revisionasof',
637 $wgContLang->timeanddate( $timestamp ) ) );
640 if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
642 $diffLink = $title->escapeFullUrl(
644 '&oldid=' . $oldid );
645 $diffText = '<a href="' .
648 htmlspecialchars( wfMsgForContent( 'difference' ) ) .
650 } elseif ( $diffText === false ) {
651 // Error in diff engine, probably a missing revision
652 $diffText = "<p>Can't load revision $newid</p>";
654 // Diff output fine, clean up any illegal UTF-8
655 $diffText = UtfNormal
::cleanUp( $diffText );
656 $diffText = rcApplyDiffStyle( $diffText );
658 wfProfileOut( "$fname-dodiff" );
660 $rev = Revision
::newFromId( $newid );
661 if( is_null( $rev ) ) {
664 $newtext = $rev->getText();
666 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
667 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
669 $completeText .= $diffText;
672 wfProfileOut( $fname );
673 return $completeText;
677 * Hacky application of diff styles for the feeds.
678 * Might be 'cleaner' to use DOM or XSLT or something,
679 * but *gack* it's a pain in the ass.
681 * @param $text String:
685 function rcApplyDiffStyle( $text ) {
687 'diff' => 'background-color: white;',
688 'diff-otitle' => 'background-color: white;',
689 'diff-ntitle' => 'background-color: white;',
690 'diff-addedline' => 'background: #cfc; font-size: smaller;',
691 'diff-deletedline' => 'background: #ffa; font-size: smaller;',
692 'diff-context' => 'background: #eee; font-size: smaller;',
693 'diffchange' => 'color: red; font-weight: bold;',
696 foreach( $styles as $class => $style ) {
697 $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
698 "\\1style=\"$style\"\\3", $text );