4 * @addtogroup SpecialPage
10 require_once( dirname(__FILE__
) . '/ChangesList.php' );
15 function wfSpecialRecentchanges( $par, $specialPage ) {
16 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
17 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
18 global $wgAllowCategorizedRecentChanges ;
19 $fname = 'wfSpecialRecentchanges';
21 # Get query parameters
22 $feedFormat = $wgRequest->getVal( 'feed' );
24 /* Checkbox values can't be true by default, because
25 * we cannot differentiate between unset and not set at all
28 /* int */ 'days' => $wgUser->getDefaultOption('rcdays'),
29 /* int */ 'limit' => $wgUser->getDefaultOption('rclimit'),
30 /* bool */ 'hideminor' => false,
31 /* bool */ 'hidebots' => true,
32 /* bool */ 'hideanons' => false,
33 /* bool */ 'hideliu' => false,
34 /* bool */ 'hidepatrolled' => false,
35 /* bool */ 'hidemyself' => false,
36 /* text */ 'from' => '',
37 /* text */ 'namespace' => null,
38 /* bool */ 'invert' => false,
39 /* bool */ 'categories_any' => false,
45 $days = $wgUser->getOption( 'rcdays', $defaults['days']);
46 $days = $wgRequest->getInt( 'days', $days );
48 $limit = $wgUser->getOption( 'rclimit', $defaults['limit'] );
50 # list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
51 $limit = $wgRequest->getInt( 'limit', $limit );
53 /* order of selection: url > preferences > default */
54 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor') ?
true : $defaults['hideminor'] );
56 # As a feed, use limited settings only
59 if( $limit > $wgFeedLimit ) {
60 $limit = $wgFeedLimit;
65 $namespace = $wgRequest->getIntOrNull( 'namespace' );
66 $invert = $wgRequest->getBool( 'invert', $defaults['invert'] );
67 $hidebots = $wgRequest->getBool( 'hidebots', $defaults['hidebots'] );
68 $hideanons = $wgRequest->getBool( 'hideanons', $defaults['hideanons'] );
69 $hideliu = $wgRequest->getBool( 'hideliu', $defaults['hideliu'] );
70 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', $defaults['hidepatrolled'] );
71 $hidemyself = $wgRequest->getBool ( 'hidemyself', $defaults['hidemyself'] );
72 $from = $wgRequest->getVal( 'from', $defaults['from'] );
74 # Get query parameters from path
76 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
77 foreach ( $bits as $bit ) {
78 if ( 'hidebots' == $bit ) $hidebots = 1;
79 if ( 'bots' == $bit ) $hidebots = 0;
80 if ( 'hideminor' == $bit ) $hideminor = 1;
81 if ( 'minor' == $bit ) $hideminor = 0;
82 if ( 'hideliu' == $bit ) $hideliu = 1;
83 if ( 'hidepatrolled' == $bit ) $hidepatrolled = 1;
84 if ( 'hideanons' == $bit ) $hideanons = 1;
85 if ( 'hidemyself' == $bit ) $hidemyself = 1;
87 if ( is_numeric( $bit ) ) {
92 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
96 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
103 if ( $limit < 0 ||
$limit > 5000 ) $limit = $defaults['limit'];
106 # Database connection and caching
107 $dbr = wfGetDB( DB_SLAVE
);
108 list( $recentchanges, $watchlist ) = $dbr->tableNamesN( 'recentchanges', 'watchlist' );
111 $cutoff_unixtime = time() - ( $days * 86400 );
112 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime %
86400);
113 $cutoff = $dbr->timestamp( $cutoff_unixtime );
114 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW
,$cutoff)) {
115 $cutoff = $dbr->timestamp($from);
117 $from = $defaults['from'];
120 # 10 seconds server-side caching max
121 $wgOut->setSquidMaxage( 10 );
123 # Get last modified date, for client caching
124 # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
125 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
126 if ( $feedFormat ||
!$wgUseRCPatrol ) {
127 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
128 # Client cache fresh and headers sent, nothing more to do.
133 # It makes no sense to hide both anons and logged-in users
134 # Where this occurs, force anons to be shown
135 if( $hideanons && $hideliu )
138 # Form WHERE fragments for all the options
139 $hidem = $hideminor ?
'AND rc_minor = 0' : '';
140 $hidem .= $hidebots ?
' AND rc_bot = 0' : '';
141 $hidem .= $hideliu ?
' AND rc_user = 0' : '';
142 $hidem .= ( $wgUseRCPatrol && $hidepatrolled ) ?
' AND rc_patrolled = 0' : '';
143 $hidem .= $hideanons ?
' AND rc_user != 0' : '';
146 if( $wgUser->getID() ) {
147 $hidem .= ' AND rc_user != ' . $wgUser->getID();
149 $hidem .= ' AND rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() );
153 # Namespace filtering
154 $hidem .= is_null( $namespace ) ?
'' : ' AND rc_namespace' . ($invert ?
'!=' : '=') . $namespace;
156 // This is the big thing!
158 $uid = $wgUser->getID();
161 $forceclause = $dbr->useIndexClause("rc_timestamp");
162 $sql2 = "SELECT * FROM $recentchanges $forceclause".
163 ($uid ?
"LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") .
164 "WHERE rc_timestamp >= '{$cutoff}' {$hidem} " .
165 "ORDER BY rc_timestamp DESC";
166 $sql2 = $dbr->limitResult($sql2, $limit, 0);
167 $res = $dbr->query( $sql2, $fname );
169 // Fetch results, prepare a batch link existence check query
171 $batch = new LinkBatch
;
172 while( $row = $dbr->fetchObject( $res ) ){
174 if ( !$feedFormat ) {
176 $title = Title
::makeTitleSafe( NS_USER
, $row->rc_user_text
);
177 $batch->addObj( $title );
180 $title = Title
::makeTitleSafe( NS_USER_TALK
, $row->rc_user_text
);
181 $batch->addObj( $title );
185 $dbr->freeResult( $res );
188 rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod );
193 // Run existence checks
195 $any = $wgRequest->getBool( 'categories_any', $defaults['categories_any']);
198 if ( !$specialPage->including() ) {
199 $wgOut->addWikiText( wfMsgForContentNoTrans( "recentchangestext" ) );
201 // Dump everything here
202 $nondefaults = array();
204 wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults);
205 wfAppendToArrayIfNotDefault( 'limit', $limit , $defaults, $nondefaults);
206 wfAppendToArrayIfNotDefault( 'hideminor', $hideminor, $defaults, $nondefaults);
207 wfAppendToArrayIfNotDefault( 'hidebots', $hidebots, $defaults, $nondefaults);
208 wfAppendToArrayIfNotDefault( 'hideanons', $hideanons, $defaults, $nondefaults );
209 wfAppendToArrayIfNotDefault( 'hideliu', $hideliu, $defaults, $nondefaults);
210 wfAppendToArrayIfNotDefault( 'hidepatrolled', $hidepatrolled, $defaults, $nondefaults);
211 wfAppendToArrayIfNotDefault( 'hidemyself', $hidemyself, $defaults, $nondefaults);
212 wfAppendToArrayIfNotDefault( 'from', $from, $defaults, $nondefaults);
213 wfAppendToArrayIfNotDefault( 'namespace', $namespace, $defaults, $nondefaults);
214 wfAppendToArrayIfNotDefault( 'invert', $invert, $defaults, $nondefaults);
215 wfAppendToArrayIfNotDefault( 'categories_any', $any, $defaults, $nondefaults);
217 // Add end of the texts
218 $wgOut->addHTML( '<div class="rcoptions">' . rcOptionsPanel( $defaults, $nondefaults ) . "\n" );
219 $wgOut->addHTML( rcNamespaceForm( $namespace, $invert, $nondefaults, $any ) . '</div>'."\n");
222 // And now for the content
223 $wgOut->setSyndicated( true );
225 $list = ChangesList
::newFromUser( $wgUser );
227 if ( $wgAllowCategorizedRecentChanges ) {
228 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
229 $categories = str_replace ( "|" , "\n" , $categories ) ;
230 $categories = explode ( "\n" , $categories ) ;
231 rcFilterByCategories ( $rows , $categories , $any ) ;
234 $s = $list->beginRecentChangesList();
236 foreach( $rows as $obj ){
241 if ( ! ( $hideminor && $obj->rc_minor
) &&
242 ! ( $hidepatrolled && $obj->rc_patrolled
) ) {
243 $rc = RecentChange
::newFromRow( $obj );
244 $rc->counter
= $counter++
;
246 if ($wgShowUpdatedMarker
247 && !empty( $obj->wl_notificationtimestamp
)
248 && ($obj->rc_timestamp
>= $obj->wl_notificationtimestamp
)) {
249 $rc->notificationtimestamp
= true;
251 $rc->notificationtimestamp
= false;
254 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
255 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" . $dbr->strencode($obj->rc_title
) ."' AND wl_namespace=$obj->rc_namespace" ;
256 $res3 = $dbr->query( $sql3, 'wfSpecialRecentChanges');
257 $x = $dbr->fetchObject( $res3 );
258 $rc->numberofWatchingusers
= $x->n
;
260 $rc->numberofWatchingusers
= 0;
262 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user
) );
266 $s .= $list->endRecentChangesList();
267 $wgOut->addHTML( $s );
271 function rcFilterByCategories ( &$rows , $categories , $any ) {
272 require_once ( 'Categoryfinder.php' ) ;
276 foreach ( $categories AS $cat ) {
277 $cat = trim ( $cat ) ;
278 if ( $cat == "" ) continue ;
283 $articles = array () ;
285 foreach ( $rows AS $k => $r ) {
286 $nt = Title
::newFromText ( $r->rc_title
, $r->rc_namespace
) ;
287 $id = $nt->getArticleID() ;
288 if ( $id == 0 ) continue ; # Page might have been deleted...
289 if ( !in_array ( $id , $articles ) ) {
292 if ( !isset ( $a2r[$id] ) ) {
293 $a2r[$id] = array() ;
299 if ( count ( $articles ) == 0 OR count ( $cats ) == 0 )
303 $c = new Categoryfinder
;
304 $c->seed ( $articles , $cats , $any ?
"OR" : "AND" ) ;
305 $match = $c->run () ;
308 $newrows = array () ;
309 foreach ( $match AS $id ) {
310 foreach ( $a2r[$id] AS $rev ) {
312 $newrows[$k] = $rows[$k] ;
318 function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
319 global $messageMemc, $wgFeedCacheTimeout;
320 global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
322 if( !isset( $wgFeedClasses[$feedFormat] ) ) {
323 wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
327 $timekey = wfMemcKey( 'rcfeed', $feedFormat, 'timestamp' );
328 $key = wfMemcKey( 'rcfeed', $feedFormat, 'limit', $limit, 'minor', $hideminor );
330 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchanges' ) .
331 ' [' . $wgContLanguageCode . ']';
332 $feed = new $wgFeedClasses[$feedFormat](
334 htmlspecialchars( wfMsgForContent( 'recentchanges-feed-description' ) ),
335 $wgTitle->getFullUrl() );
338 * Bumping around loading up diffs can be pretty slow, so where
339 * possible we want to cache the feed output so the next visitor
343 if( ( $wgFeedCacheTimeout > 0 ) && ( $feedLastmod = $messageMemc->get( $timekey ) ) ) {
345 * If the cached feed was rendered very recently, we may
346 * go ahead and use it even if there have been edits made
347 * since it was rendered. This keeps a swarm of requests
348 * from being too bad on a super-frequently edited wiki.
350 if( time() - wfTimestamp( TS_UNIX
, $feedLastmod )
351 < $wgFeedCacheTimeout
352 ||
wfTimestamp( TS_UNIX
, $feedLastmod )
353 > wfTimestamp( TS_UNIX
, $lastmod ) ) {
354 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
355 $cachedFeed = $messageMemc->get( $key );
357 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
360 if( is_string( $cachedFeed ) ) {
361 wfDebug( "RC: Outputting cached feed\n" );
362 $feed->httpHeaders();
365 wfDebug( "RC: rendering new feed and caching it\n" );
367 rcDoOutputFeed( $rows, $feed );
368 $cachedFeed = ob_get_contents();
371 $expire = 3600 * 24; # One day
372 $messageMemc->set( $key, $cachedFeed );
373 $messageMemc->set( $timekey, wfTimestamp( TS_MW
), $expire );
378 function rcDoOutputFeed( $rows, &$feed ) {
379 $fname = 'rcDoOutputFeed';
380 wfProfileIn( $fname );
384 # Merge adjacent edits by one user
387 foreach( $rows as $obj ) {
389 $obj->rc_namespace
>= 0 &&
390 $obj->rc_cur_id
== $sorted[$n-1]->rc_cur_id
&&
391 $obj->rc_user_text
== $sorted[$n-1]->rc_user_text
) {
392 $sorted[$n-1]->rc_last_oldid
= $obj->rc_last_oldid
;
399 foreach( $sorted as $obj ) {
400 $title = Title
::makeTitle( $obj->rc_namespace
, $obj->rc_title
);
401 $talkpage = $title->getTalkPage();
402 $item = new FeedItem(
403 $title->getPrefixedText(),
404 rcFormatDiff( $obj ),
405 $title->getFullURL(),
408 $talkpage->getFullURL()
410 $feed->outItem( $item );
413 wfProfileOut( $fname );
419 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
420 global $wgUser, $wgLang, $wgContLang;
421 $sk = $wgUser->getSkin();
422 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
423 ($lim ?
$wgLang->formatNum( "{$lim}" ) : wfMsg( 'recentchangesall' ) ), "{$more}" .
424 ($d ?
"days={$d}&" : '') . 'limit='.$lim );
431 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
432 global $wgUser, $wgLang, $wgContLang;
433 $sk = $wgUser->getSkin();
434 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
435 ($d ?
$wgLang->formatNum( "{$d}" ) : wfMsg( 'recentchangesall' ) ), $more.'days='.$d .
436 ($lim ?
'&limit='.$lim : '') );
441 * Used by Recentchangeslinked
443 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
444 $botLink = '', $liuLink = '', $patrLink = '', $myselfLink = '' ) {
445 if ($more != '') $more .= '&';
446 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
447 rcCountLink( 100, $days, $page, $more ) . ' | ' .
448 rcCountLink( 250, $days, $page, $more ) . ' | ' .
449 rcCountLink( 500, $days, $page, $more ) .
450 ( $doall ?
( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
451 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
452 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
453 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
454 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
455 rcDaysLink( $limit, 30, $page, $more ) .
456 ( $doall ?
( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
458 $linkParts = array( 'minorLink' => 'minor', 'botLink' => 'bots', 'liuLink' => 'liu', 'patrLink' => 'patr', 'myselfLink' => 'mine' );
459 foreach( $linkParts as $linkVar => $linkMsg ) {
460 if( $
$linkVar != '' )
461 $links[] = wfMsgHtml( 'rcshowhide' . $linkMsg, $
$linkVar );
464 $shm = implode( ' | ', $links );
465 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
471 * Makes change an option link which carries all the other options
472 * @param $title see Title
476 function makeOptionsLink( $title, $override, $options ) {
477 global $wgUser, $wgContLang;
478 $sk = $wgUser->getSkin();
479 return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
480 htmlspecialchars( $title ), wfArrayToCGI( $override, $options ) );
484 * Creates the options panel.
486 * @param $nondefaults
488 function rcOptionsPanel( $defaults, $nondefaults ) {
489 global $wgLang, $wgUseRCPatrol;
491 $options = $nondefaults +
$defaults;
493 if( $options['from'] )
494 $note = wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
495 $wgLang->formatNum( $options['limit'] ),
496 $wgLang->timeanddate( $options['from'], true ) );
498 $note = wfMsgExt( 'rcnote', array( 'parseinline' ),
499 $wgLang->formatNum( $options['limit'] ),
500 $wgLang->formatNum( $options['days'] ),
501 $wgLang->timeAndDate( wfTimestampNow(), true ) );
504 $options_limit = array(50, 100, 250, 500);
505 foreach( $options_limit as $value ) {
506 $cl[] = makeOptionsLink( $wgLang->formatNum( $value ),
507 array( 'limit' => $value ), $nondefaults) ;
509 $cl = implode( ' | ', $cl);
511 // day links, reset 'from' to none
512 $options_days = array(1, 3, 7, 14, 30);
513 foreach( $options_days as $value ) {
514 $dl[] = makeOptionsLink( $wgLang->formatNum( $value ),
515 array( 'days' => $value, 'from' => '' ), $nondefaults) ;
517 $dl = implode( ' | ', $dl);
521 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
522 $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
523 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
524 $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
525 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
526 $anonsLink = makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
527 array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
528 $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
529 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
530 $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
531 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
532 $myselfLink = makeOptionsLink( $showhide[1-$options['hidemyself']],
533 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
535 $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
536 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
537 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
538 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
540 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
541 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
542 $hl = implode( ' | ', $links );
544 // show from this onward link
545 $now = $wgLang->timeanddate( wfTimestampNow(), true );
546 $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
548 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter'),
550 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter'), $tl );
551 return "$note<br />$rclinks<br />$rclistfrom";
556 * Creates the choose namespace selection
560 * @param $namespace Mixed: the key of the currently selected namespace, empty string
562 * @param $invert Bool: whether to invert the namespace selection
563 * @param $nondefaults Array: an array of non default options to be remembered
564 * @param $categories_any Bool: Default value for the checkbox
568 function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
569 global $wgScript, $wgAllowCategorizedRecentChanges, $wgRequest;
570 $t = SpecialPage
::getTitleFor( 'Recentchanges' );
572 $namespaceselect = HTMLnamespaceselector($namespace, '');
573 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
574 $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ?
' checked="checked"' : '' ) . ' />';
576 if ( $wgAllowCategorizedRecentChanges ) {
577 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
578 $cb_arr = array( 'type' => 'checkbox', 'name' => 'categories_any', 'value' => "1" ) ;
579 if ( $categories_any ) $cb_arr['checked'] = "checked" ;
581 $catbox .= wfMsgExt('rc_categories', array('parseinline')) . " ";
582 $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
583 $catbox .= " " ;
584 $catbox .= wfElement('input', $cb_arr );
585 $catbox .= wfMsgExt('rc_categories_any', array('parseinline'));
590 $out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
592 foreach ( $nondefaults as $key => $value ) {
593 if ($key != 'namespace' && $key != 'invert')
594 $out .= wfElement('input', array( 'type' => 'hidden', 'name' => $key, 'value' => $value));
597 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
599 <div id='nsselect' class='recentchanges'>
600 <label for='namespace'>" . wfMsgHtml('namespace') . "</label>
601 {$namespaceselect}{$submitbutton}{$invertbox} <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>{$catbox}\n</div>";
602 $out .= '</form></div>';
608 * Format a diff for the newsfeed
610 function rcFormatDiff( $row ) {
611 $titleObj = Title
::makeTitle( $row->rc_namespace
, $row->rc_title
);
612 $timestamp = wfTimestamp( TS_MW
, $row->rc_timestamp
);
613 return rcFormatDiffRow( $titleObj,
614 $row->rc_last_oldid
, $row->rc_this_oldid
,
619 function rcFormatDiffRow( $title, $oldid, $newid, $timestamp, $comment ) {
620 global $wgFeedDiffCutoff, $wgContLang, $wgUser;
621 $fname = 'rcFormatDiff';
622 wfProfileIn( $fname );
624 $skin = $wgUser->getSkin();
625 $completeText = '<p>' . $skin->formatComment( $comment ) . "</p>\n";
627 if( $title->getNamespace() >= 0 && $title->userCan( 'read' ) ) {
629 wfProfileIn( "$fname-dodiff" );
631 $de = new DifferenceEngine( $title, $oldid, $newid );
632 #$diffText = $de->getDiff( wfMsg( 'revisionasof',
633 # $wgContLang->timeanddate( $timestamp ) ),
634 # wfMsg( 'currentrev' ) );
635 $diffText = $de->getDiff(
636 wfMsg( 'previousrevision' ), // hack
637 wfMsg( 'revisionasof',
638 $wgContLang->timeanddate( $timestamp ) ) );
641 if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
643 $diffLink = $title->escapeFullUrl(
645 '&oldid=' . $oldid );
646 $diffText = '<a href="' .
649 htmlspecialchars( wfMsgForContent( 'difference' ) ) .
651 } elseif ( $diffText === false ) {
652 // Error in diff engine, probably a missing revision
653 $diffText = "<p>Can't load revision $newid</p>";
655 // Diff output fine, clean up any illegal UTF-8
656 $diffText = UtfNormal
::cleanUp( $diffText );
657 $diffText = rcApplyDiffStyle( $diffText );
659 wfProfileOut( "$fname-dodiff" );
661 $rev = Revision
::newFromId( $newid );
662 if( is_null( $rev ) ) {
665 $newtext = $rev->getText();
667 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
668 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
670 $completeText .= $diffText;
673 wfProfileOut( $fname );
674 return $completeText;
678 * Hacky application of diff styles for the feeds.
679 * Might be 'cleaner' to use DOM or XSLT or something,
680 * but *gack* it's a pain in the ass.
682 * @param $text String:
686 function rcApplyDiffStyle( $text ) {
688 'diff' => 'background-color: white;',
689 'diff-otitle' => 'background-color: white;',
690 'diff-ntitle' => 'background-color: white;',
691 'diff-addedline' => 'background: #cfc; font-size: smaller;',
692 'diff-deletedline' => 'background: #ffa; font-size: smaller;',
693 'diff-context' => 'background: #eee; font-size: smaller;',
694 'diffchange' => 'color: red; font-weight: bold; text-decoration: none;',
697 foreach( $styles as $class => $style ) {
698 $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
699 "\\1style=\"$style\"\\3", $text );