5 * @subpackage SpecialPage
11 require_once( 'Feed.php' );
12 require_once( 'ChangesList.php' );
17 function wfSpecialRecentchanges( $par, $specialPage ) {
18 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol, $wgDBtype;
19 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
20 global $wgAllowCategorizedRecentChanges ;
21 $fname = 'wfSpecialRecentchanges';
23 # Get query parameters
24 $feedFormat = $wgRequest->getVal( 'feed' );
26 /* Checkbox values can't be true be default, because
27 * we cannot differentiate between unset and not set at all
30 /* int */ 'days' => $wgUser->getDefaultOption('rcdays'),
31 /* int */ 'limit' => $wgUser->getDefaultOption('rclimit'),
32 /* bool */ 'hideminor' => false,
33 /* bool */ 'hidebots' => true,
34 /* bool */ 'hideanons' => false,
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,
47 $days = $wgUser->getOption( 'rcdays' );
48 if ( !$days ) { $days = $defaults['days']; }
49 $days = $wgRequest->getInt( 'days', $days );
51 $limit = $wgUser->getOption( 'rclimit' );
52 if ( !$limit ) { $limit = $defaults['limit']; }
54 # list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
55 $limit = $wgRequest->getInt( 'limit', $limit );
57 /* order of selection: url > preferences > default */
58 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor') ?
true : $defaults['hideminor'] );
60 # As a feed, use limited settings only
63 if( $limit > $wgFeedLimit ) {
64 $options['limit'] = $wgFeedLimit;
69 $namespace = $wgRequest->getIntOrNull( 'namespace' );
70 $invert = $wgRequest->getBool( 'invert', $defaults['invert'] );
71 $hidebots = $wgRequest->getBool( 'hidebots', $defaults['hidebots'] );
72 $hideanons = $wgRequest->getBool( 'hideanons', $defaults['hideanons'] );
73 $hideliu = $wgRequest->getBool( 'hideliu', $defaults['hideliu'] );
74 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', $defaults['hidepatrolled'] );
75 $hidemyself = $wgRequest->getBool ( 'hidemyself', $defaults['hidemyself'] );
76 $from = $wgRequest->getVal( 'from', $defaults['from'] );
78 # Get query parameters from path
80 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
81 foreach ( $bits as $bit ) {
82 if ( 'hidebots' == $bit ) $hidebots = 1;
83 if ( 'bots' == $bit ) $hidebots = 0;
84 if ( 'hideminor' == $bit ) $hideminor = 1;
85 if ( 'minor' == $bit ) $hideminor = 0;
86 if ( 'hideliu' == $bit ) $hideliu = 1;
87 if ( 'hidepatrolled' == $bit ) $hidepatrolled = 1;
88 if ( 'hideanons' == $bit ) $hideanons = 1;
89 if ( 'hidemyself' == $bit ) $hidemyself = 1;
91 if ( is_numeric( $bit ) ) {
95 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
99 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
106 if ( $limit < 0 ||
$limit > 5000 ) $limit = $defaults['limit'];
109 # Database connection and caching
110 $dbr =& wfGetDB( DB_SLAVE
);
111 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
114 $cutoff_unixtime = time() - ( $days * 86400 );
115 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime %
86400);
116 $cutoff = $dbr->timestamp( $cutoff_unixtime );
117 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW
,$cutoff)) {
118 $cutoff = $dbr->timestamp($from);
120 $from = $defaults['from'];
123 # 10 seconds server-side caching max
124 $wgOut->setSquidMaxage( 10 );
126 # Get last modified date, for client caching
127 # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
128 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
129 if ( $feedFormat ||
!$wgUseRCPatrol ) {
130 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
131 # Client cache fresh and headers sent, nothing more to do.
136 # It makes no sense to hide both anons and logged-in users
137 # Where this occurs, force anons to be shown
138 if( $hideanons && $hideliu )
141 # Form WHERE fragments for all the options
142 $hidem = $hideminor ?
'AND rc_minor = 0' : '';
143 $hidem .= $hidebots ?
' AND rc_bot = 0' : '';
144 $hidem .= $hideliu ?
' AND rc_user = 0' : '';
145 $hidem .= ( $wgUseRCPatrol && $hidepatrolled ) ?
' AND rc_patrolled = 0' : '';
146 $hidem .= $hideanons ?
' AND rc_user != 0' : '';
149 if( $wgUser->getID() ) {
150 $hidem .= ' AND rc_user != ' . $wgUser->getID();
152 $hidem .= ' AND rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() );
156 # Namespace filtering
157 $hidem .= is_null( $namespace ) ?
'' : ' AND rc_namespace' . ($invert ?
'!=' : '=') . $namespace;
159 // This is the big thing!
161 $uid = $wgUser->getID();
164 $forceclause = $dbr->useIndexClause("rc_timestamp");
165 $sql2 = "SELECT * FROM $recentchanges $forceclause".
166 ($uid ?
"LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") .
167 "WHERE rc_timestamp >= '{$cutoff}' {$hidem} " .
168 "ORDER BY rc_timestamp DESC";
169 $sql2 = $dbr->limitResult($sql2, $limit, 0);
170 $res = $dbr->query( $sql2, $fname );
172 // Fetch results, prepare a batch link existence check query
174 $batch = new LinkBatch
;
175 while( $row = $dbr->fetchObject( $res ) ){
177 if ( !$feedFormat ) {
179 $title = Title
::makeTitleSafe( NS_USER
, $row->rc_user_text
);
180 $batch->addObj( $title );
183 $title = Title
::makeTitleSafe( NS_USER_TALK
, $row->rc_user_text
);
184 $batch->addObj( $title );
188 $dbr->freeResult( $res );
191 rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod );
196 // Run existence checks
198 $any = $wgRequest->getBool( 'categories_any', $defaults['categories_any']);
201 if ( !$specialPage->including() ) {
202 $wgOut->addWikiText( wfMsgForContent( "recentchangestext" ) );
204 // Dump everything here
205 $nondefaults = array();
207 wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults);
208 wfAppendToArrayIfNotDefault( 'limit', $limit , $defaults, $nondefaults);
209 wfAppendToArrayIfNotDefault( 'hideminor', $hideminor, $defaults, $nondefaults);
210 wfAppendToArrayIfNotDefault( 'hidebots', $hidebots, $defaults, $nondefaults);
211 wfAppendToArrayIfNotDefault( 'hideanons', $hideanons, $defaults, $nondefaults );
212 wfAppendToArrayIfNotDefault( 'hideliu', $hideliu, $defaults, $nondefaults);
213 wfAppendToArrayIfNotDefault( 'hidepatrolled', $hidepatrolled, $defaults, $nondefaults);
214 wfAppendToArrayIfNotDefault( 'hidemyself', $hidemyself, $defaults, $nondefaults);
215 wfAppendToArrayIfNotDefault( 'from', $from, $defaults, $nondefaults);
216 wfAppendToArrayIfNotDefault( 'namespace', $namespace, $defaults, $nondefaults);
217 wfAppendToArrayIfNotDefault( 'invert', $invert, $defaults, $nondefaults);
218 wfAppendToArrayIfNotDefault( 'categories_any', $any, $defaults, $nondefaults);
220 // Add end of the texts
221 $wgOut->addHTML( '<div class="rcoptions">' . rcOptionsPanel( $defaults, $nondefaults ) . "\n" );
222 $wgOut->addHTML( rcNamespaceForm( $namespace, $invert, $nondefaults, $any ) . '</div>'."\n");
225 // And now for the content
226 $sk = $wgUser->getSkin();
227 $wgOut->setSyndicated( true );
229 $list = ChangesList
::newFromUser( $wgUser );
231 if ( $wgAllowCategorizedRecentChanges ) {
232 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
233 $categories = str_replace ( "|" , "\n" , $categories ) ;
234 $categories = explode ( "\n" , $categories ) ;
235 rcFilterByCategories ( $rows , $categories , $any ) ;
238 $s = $list->beginRecentChangesList();
240 foreach( $rows as $obj ){
245 if ( ! ( $hideminor && $obj->rc_minor
) &&
246 ! ( $hidepatrolled && $obj->rc_patrolled
) ) {
247 $rc = RecentChange
::newFromRow( $obj );
248 $rc->counter
= $counter++
;
250 if ($wgShowUpdatedMarker
251 && !empty( $obj->wl_notificationtimestamp
)
252 && ($obj->rc_timestamp
>= $obj->wl_notificationtimestamp
)) {
253 $rc->notificationtimestamp
= true;
255 $rc->notificationtimestamp
= false;
258 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
259 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" . $dbr->strencode($obj->rc_title
) ."' AND wl_namespace=$obj->rc_namespace" ;
260 $res3 = $dbr->query( $sql3, 'wfSpecialRecentChanges');
261 $x = $dbr->fetchObject( $res3 );
262 $rc->numberofWatchingusers
= $x->n
;
264 $rc->numberofWatchingusers
= 0;
266 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user
) );
270 $s .= $list->endRecentChangesList();
271 $wgOut->addHTML( $s );
275 function rcFilterByCategories ( &$rows , $categories , $any ) {
276 require_once ( 'Categoryfinder.php' ) ;
280 foreach ( $categories AS $cat ) {
281 $cat = trim ( $cat ) ;
282 if ( $cat == "" ) continue ;
287 $articles = array () ;
289 foreach ( $rows AS $k => $r ) {
290 $nt = Title
::newFromText ( $r->rc_title
, $r->rc_namespace
) ;
291 $id = $nt->getArticleID() ;
292 if ( $id == 0 ) continue ; # Page might have been deleted...
293 if ( !in_array ( $id , $articles ) ) {
296 if ( !isset ( $a2r[$id] ) ) {
297 $a2r[$id] = array() ;
303 if ( count ( $articles ) == 0 OR count ( $cats ) == 0 )
307 $c = new Categoryfinder
;
308 $c->seed ( $articles , $cats , $any ?
"OR" : "AND" ) ;
309 $match = $c->run () ;
312 $newrows = array () ;
313 foreach ( $match AS $id ) {
314 foreach ( $a2r[$id] AS $rev ) {
316 $newrows[$k] = $rows[$k] ;
322 function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
323 global $messageMemc, $wgDBname, $wgFeedCacheTimeout;
324 global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
326 if( !isset( $wgFeedClasses[$feedFormat] ) ) {
327 wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
331 $timekey = "$wgDBname:rcfeed:$feedFormat:timestamp";
332 $key = "$wgDBname:rcfeed:$feedFormat:limit:$limit:minor:$hideminor";
334 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchanges' ) .
335 ' [' . $wgContLanguageCode . ']';
336 $feed = new $wgFeedClasses[$feedFormat](
338 htmlspecialchars( wfMsgForContent( 'recentchangestext' ) ),
339 $wgTitle->getFullUrl() );
342 * Bumping around loading up diffs can be pretty slow, so where
343 * possible we want to cache the feed output so the next visitor
347 if( ( $wgFeedCacheTimeout > 0 ) && ( $feedLastmod = $messageMemc->get( $timekey ) ) ) {
349 * If the cached feed was rendered very recently, we may
350 * go ahead and use it even if there have been edits made
351 * since it was rendered. This keeps a swarm of requests
352 * from being too bad on a super-frequently edited wiki.
354 if( time() - wfTimestamp( TS_UNIX
, $feedLastmod )
355 < $wgFeedCacheTimeout
356 ||
wfTimestamp( TS_UNIX
, $feedLastmod )
357 > wfTimestamp( TS_UNIX
, $lastmod ) ) {
358 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
359 $cachedFeed = $messageMemc->get( $key );
361 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
364 if( is_string( $cachedFeed ) ) {
365 wfDebug( "RC: Outputting cached feed\n" );
366 $feed->httpHeaders();
369 wfDebug( "RC: rendering new feed and caching it\n" );
371 rcDoOutputFeed( $rows, $feed );
372 $cachedFeed = ob_get_contents();
375 $expire = 3600 * 24; # One day
376 $messageMemc->set( $key, $cachedFeed );
377 $messageMemc->set( $timekey, wfTimestamp( TS_MW
), $expire );
382 function rcDoOutputFeed( $rows, &$feed ) {
383 $fname = 'rcDoOutputFeed';
384 wfProfileIn( $fname );
388 # Merge adjacent edits by one user
391 foreach( $rows as $obj ) {
393 $obj->rc_namespace
>= 0 &&
394 $obj->rc_cur_id
== $sorted[$n-1]->rc_cur_id
&&
395 $obj->rc_user_text
== $sorted[$n-1]->rc_user_text
) {
396 $sorted[$n-1]->rc_last_oldid
= $obj->rc_last_oldid
;
404 foreach( $sorted as $obj ) {
405 $title = Title
::makeTitle( $obj->rc_namespace
, $obj->rc_title
);
406 $talkpage = $title->getTalkPage();
407 $item = new FeedItem(
408 $title->getPrefixedText(),
409 rcFormatDiff( $obj ),
410 $title->getFullURL(),
413 $talkpage->getFullURL()
415 $feed->outItem( $item );
418 wfProfileOut( $fname );
424 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
425 global $wgUser, $wgLang, $wgContLang;
426 $sk = $wgUser->getSkin();
427 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
428 ($lim ?
$wgLang->formatNum( "{$lim}" ) : wfMsg( 'recentchangesall' ) ), "{$more}" .
429 ($d ?
"days={$d}&" : '') . 'limit='.$lim );
436 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
437 global $wgUser, $wgLang, $wgContLang;
438 $sk = $wgUser->getSkin();
439 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
440 ($d ?
$wgLang->formatNum( "{$d}" ) : wfMsg( 'recentchangesall' ) ), $more.'days='.$d .
441 ($lim ?
'&limit='.$lim : '') );
446 * Used by Recentchangeslinked
448 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
449 $botLink = '', $liuLink = '', $patrLink = '', $myselfLink = '' ) {
450 if ($more != '') $more .= '&';
451 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
452 rcCountLink( 100, $days, $page, $more ) . ' | ' .
453 rcCountLink( 250, $days, $page, $more ) . ' | ' .
454 rcCountLink( 500, $days, $page, $more ) .
455 ( $doall ?
( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
456 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
457 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
458 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
459 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
460 rcDaysLink( $limit, 30, $page, $more ) .
461 ( $doall ?
( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
463 $linkParts = array( 'minorLink' => 'minor', 'botLink' => 'bots', 'liuLink' => 'liu', 'patrLink' => 'patr', 'myselfLink' => 'mine' );
464 foreach( $linkParts as $linkVar => $linkMsg ) {
465 if( $
$linkVar != '' )
466 $links[] = wfMsgHtml( 'rcshowhide' . $linkMsg, $
$linkVar );
469 $shm = implode( ' | ', $links );
470 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
476 * Makes change an option link which carries all the other options
477 * @param $title @see Title
481 function makeOptionsLink( $title, $override, $options ) {
482 global $wgUser, $wgContLang;
483 $sk = $wgUser->getSkin();
484 return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
485 $title, wfArrayToCGI( $override, $options ) );
489 * Creates the options panel.
491 * @param $nondefaults
493 function rcOptionsPanel( $defaults, $nondefaults ) {
494 global $wgLang, $wgUseRCPatrol;
496 $options = $nondefaults +
$defaults;
498 if( $options['from'] )
499 $note = wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
500 $wgLang->formatNum( $options['limit'] ),
501 $wgLang->timeanddate( $options['from'], true ) );
503 $note = wfMsgExt( 'rcnote', array( 'parseinline' ),
504 $wgLang->formatNum( $options['limit'] ),
505 $wgLang->formatNum( $options['days'] ),
506 $wgLang->timeAndDate( wfTimestampNow(), true ) );
509 $options_limit = array(50, 100, 250, 500);
510 foreach( $options_limit as $value ) {
511 $cl[] = makeOptionsLink( $wgLang->formatNum( $value ),
512 array( 'limit' => $value ), $nondefaults) ;
514 $cl = implode( ' | ', $cl);
516 // day links, reset 'from' to none
517 $options_days = array(1, 3, 7, 14, 30);
518 foreach( $options_days as $value ) {
519 $dl[] = makeOptionsLink( $wgLang->formatNum( $value ),
520 array( 'days' => $value, 'from' => '' ), $nondefaults) ;
522 $dl = implode( ' | ', $dl);
526 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
527 $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
528 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
529 $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
530 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
531 $anonsLink = makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
532 array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
533 $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
534 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
535 $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
536 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
537 $myselfLink = makeOptionsLink( $showhide[1-$options['hidemyself']],
538 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
540 $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
541 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
542 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
543 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
545 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
546 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
547 $hl = implode( ' | ', $links );
549 // show from this onward link
550 $now = $wgLang->timeanddate( wfTimestampNow(), true );
551 $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
553 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter'),
555 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter'), $tl );
556 return "$note<br />$rclinks<br />$rclistfrom";
561 * Creates the choose namespace selection
565 * @param $namespace Mixed: the key of the currently selected namespace, empty string
567 * @param $invert Bool: whether to invert the namespace selection
568 * @param $nondefaults Array: an array of non default options to be remembered
569 * @param $categories_any Bool: Default value for the checkbox
573 function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
574 global $wgScript, $wgAllowCategorizedRecentChanges, $wgRequest;
575 $t = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
577 $namespaceselect = HTMLnamespaceselector($namespace, '');
578 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
579 $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ?
' checked="checked"' : '' ) . ' />';
581 if ( $wgAllowCategorizedRecentChanges ) {
582 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
583 $cb_arr = array( 'type' => 'checkbox', 'name' => 'categories_any', 'value' => "1" ) ;
584 if ( $categories_any ) $cb_arr['checked'] = "checked" ;
586 $catbox .= wfMsgExt('rc_categories', array('parseinline')) . " ";
587 $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
588 $catbox .= " " ;
589 $catbox .= wfElement('input', $cb_arr );
590 $catbox .= wfMsgExt('rc_categories_any', array('parseinline'));
595 $out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
597 foreach ( $nondefaults as $key => $value ) {
598 if ($key != 'namespace' && $key != 'invert')
599 $out .= wfElement('input', array( 'type' => 'hidden', 'name' => $key, 'value' => $value));
602 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
604 <div id='nsselect' class='recentchanges'>
605 <label for='namespace'>" . wfMsgHtml('namespace') . "</label>
606 {$namespaceselect}{$submitbutton}{$invertbox} <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>{$catbox}\n</div>";
607 $out .= '</form></div>';
613 * Format a diff for the newsfeed
615 function rcFormatDiff( $row ) {
616 $titleObj = Title
::makeTitle( $row->rc_namespace
, $row->rc_title
);
617 return rcFormatDiffRow( $titleObj,
618 $row->rc_last_oldid
, $row->rc_this_oldid
,
623 function rcFormatDiffRow( $title, $oldid, $newid, $timestamp, $comment ) {
624 global $wgFeedDiffCutoff, $wgContLang, $wgUser;
625 $fname = 'rcFormatDiff';
626 wfProfileIn( $fname );
628 require_once( 'DifferenceEngine.php' );
629 $skin = $wgUser->getSkin();
630 $completeText = '<p>' . $skin->formatComment( $comment ) . "</p>\n";
632 if( $title->getNamespace() >= 0 ) {
634 wfProfileIn( "$fname-dodiff" );
636 $de = new DifferenceEngine( $title, $oldid, $newid );
637 #$diffText = $de->getDiff( wfMsg( 'revisionasof',
638 # $wgContLang->timeanddate( $timestamp ) ),
639 # wfMsg( 'currentrev' ) );
640 $diffText = $de->getDiff(
641 wfMsg( 'previousrevision' ), // hack
642 wfMsg( 'revisionasof',
643 $wgContLang->timeanddate( $timestamp ) ) );
646 if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
648 $diffLink = $title->escapeFullUrl(
650 '&oldid=' . $oldid );
651 $diffText = '<a href="' .
654 htmlspecialchars( wfMsgForContent( 'difference' ) ) .
656 } elseif ( $diffText === false ) {
657 // Error in diff engine, probably a missing revision
658 $diffText = "<p>Can't load revision $newid</p>";
660 // Diff output fine, clean up any illegal UTF-8
661 $diffText = UtfNormal
::cleanUp( $diffText );
662 $diffText = rcApplyDiffStyle( $diffText );
664 wfProfileOut( "$fname-dodiff" );
666 $rev = Revision
::newFromId( $newid );
667 if( is_null( $rev ) ) {
670 $newtext = $rev->getText();
672 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
673 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
675 $completeText .= $diffText;
678 wfProfileOut( $fname );
679 return $completeText;
683 * Hacky application of diff styles for the feeds.
684 * Might be 'cleaner' to use DOM or XSLT or something,
685 * but *gack* it's a pain in the ass.
687 * @param $text String:
691 function rcApplyDiffStyle( $text ) {
693 'diff' => 'background-color: white;',
694 'diff-otitle' => 'background-color: white;',
695 'diff-ntitle' => 'background-color: white;',
696 'diff-addedline' => 'background: #cfc; font-size: smaller;',
697 'diff-deletedline' => 'background: #ffa; font-size: smaller;',
698 'diff-context' => 'background: #eee; font-size: smaller;',
699 'diffchange' => 'color: red; font-weight: bold;',
702 foreach( $styles as $class => $style ) {
703 $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
704 "\\1style=\"$style\"\\3", $text );