5 * @subpackage SpecialPage
11 require_once( 'ChangesList.php' );
16 function wfSpecialRecentchanges( $par, $specialPage ) {
17 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
18 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
19 global $wgAllowCategorizedRecentChanges ;
20 $fname = 'wfSpecialRecentchanges';
22 # Get query parameters
23 $feedFormat = $wgRequest->getVal( 'feed' );
25 /* Checkbox values can't be true be default, because
26 * we cannot differentiate between unset and not set at all
29 /* int */ 'days' => $wgUser->getDefaultOption('rcdays'),
30 /* int */ 'limit' => $wgUser->getDefaultOption('rclimit'),
31 /* bool */ 'hideminor' => false,
32 /* bool */ 'hidebots' => true,
33 /* bool */ 'hideanons' => false,
34 /* bool */ 'hideliu' => false,
35 /* bool */ 'hidepatrolled' => false,
36 /* bool */ 'hidemyself' => false,
37 /* text */ 'from' => '',
38 /* text */ 'namespace' => null,
39 /* bool */ 'invert' => false,
40 /* bool */ 'categories_any' => false,
46 $days = $wgUser->getOption( 'rcdays' );
47 if ( !$days ) { $days = $defaults['days']; }
48 $days = $wgRequest->getInt( 'days', $days );
50 $limit = $wgUser->getOption( 'rclimit' );
51 if ( !$limit ) { $limit = $defaults['limit']; }
53 # list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
54 $limit = $wgRequest->getInt( 'limit', $limit );
56 /* order of selection: url > preferences > default */
57 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor') ?
true : $defaults['hideminor'] );
59 # As a feed, use limited settings only
62 if( $limit > $wgFeedLimit ) {
63 $options['limit'] = $wgFeedLimit;
68 $namespace = $wgRequest->getIntOrNull( 'namespace' );
69 $invert = $wgRequest->getBool( 'invert', $defaults['invert'] );
70 $hidebots = $wgRequest->getBool( 'hidebots', $defaults['hidebots'] );
71 $hideanons = $wgRequest->getBool( 'hideanons', $defaults['hideanons'] );
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'] );
77 # Get query parameters from path
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 ( 'hideanons' == $bit ) $hideanons = 1;
88 if ( 'hidemyself' == $bit ) $hidemyself = 1;
90 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 list( $recentchanges, $watchlist ) = $dbr->tableNamesN( '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 $wgOut->setSyndicated( true );
228 $list = ChangesList
::newFromUser( $wgUser );
230 if ( $wgAllowCategorizedRecentChanges ) {
231 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
232 $categories = str_replace ( "|" , "\n" , $categories ) ;
233 $categories = explode ( "\n" , $categories ) ;
234 rcFilterByCategories ( $rows , $categories , $any ) ;
237 $s = $list->beginRecentChangesList();
239 foreach( $rows as $obj ){
244 if ( ! ( $hideminor && $obj->rc_minor
) &&
245 ! ( $hidepatrolled && $obj->rc_patrolled
) ) {
246 $rc = RecentChange
::newFromRow( $obj );
247 $rc->counter
= $counter++
;
249 if ($wgShowUpdatedMarker
250 && !empty( $obj->wl_notificationtimestamp
)
251 && ($obj->rc_timestamp
>= $obj->wl_notificationtimestamp
)) {
252 $rc->notificationtimestamp
= true;
254 $rc->notificationtimestamp
= false;
257 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
258 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" . $dbr->strencode($obj->rc_title
) ."' AND wl_namespace=$obj->rc_namespace" ;
259 $res3 = $dbr->query( $sql3, 'wfSpecialRecentChanges');
260 $x = $dbr->fetchObject( $res3 );
261 $rc->numberofWatchingusers
= $x->n
;
263 $rc->numberofWatchingusers
= 0;
265 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user
) );
269 $s .= $list->endRecentChangesList();
270 $wgOut->addHTML( $s );
274 function rcFilterByCategories ( &$rows , $categories , $any ) {
275 require_once ( 'Categoryfinder.php' ) ;
279 foreach ( $categories AS $cat ) {
280 $cat = trim ( $cat ) ;
281 if ( $cat == "" ) continue ;
286 $articles = array () ;
288 foreach ( $rows AS $k => $r ) {
289 $nt = Title
::newFromText ( $r->rc_title
, $r->rc_namespace
) ;
290 $id = $nt->getArticleID() ;
291 if ( $id == 0 ) continue ; # Page might have been deleted...
292 if ( !in_array ( $id , $articles ) ) {
295 if ( !isset ( $a2r[$id] ) ) {
296 $a2r[$id] = array() ;
302 if ( count ( $articles ) == 0 OR count ( $cats ) == 0 )
306 $c = new Categoryfinder
;
307 $c->seed ( $articles , $cats , $any ?
"OR" : "AND" ) ;
308 $match = $c->run () ;
311 $newrows = array () ;
312 foreach ( $match AS $id ) {
313 foreach ( $a2r[$id] AS $rev ) {
315 $newrows[$k] = $rows[$k] ;
321 function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
322 global $messageMemc, $wgFeedCacheTimeout;
323 global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
325 if( !isset( $wgFeedClasses[$feedFormat] ) ) {
326 wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
330 $timekey = wfMemcKey( 'rcfeed', $feedFormat, 'timestamp' );
331 $key = wfMemcKey( 'rcfeed', $feedFormat, 'limit', $limit, 'minor', $hideminor );
333 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchanges' ) .
334 ' [' . $wgContLanguageCode . ']';
335 $feed = new $wgFeedClasses[$feedFormat](
337 htmlspecialchars( wfMsgForContent( 'recentchangestext' ) ),
338 $wgTitle->getFullUrl() );
341 * Bumping around loading up diffs can be pretty slow, so where
342 * possible we want to cache the feed output so the next visitor
346 if( ( $wgFeedCacheTimeout > 0 ) && ( $feedLastmod = $messageMemc->get( $timekey ) ) ) {
348 * If the cached feed was rendered very recently, we may
349 * go ahead and use it even if there have been edits made
350 * since it was rendered. This keeps a swarm of requests
351 * from being too bad on a super-frequently edited wiki.
353 if( time() - wfTimestamp( TS_UNIX
, $feedLastmod )
354 < $wgFeedCacheTimeout
355 ||
wfTimestamp( TS_UNIX
, $feedLastmod )
356 > wfTimestamp( TS_UNIX
, $lastmod ) ) {
357 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
358 $cachedFeed = $messageMemc->get( $key );
360 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
363 if( is_string( $cachedFeed ) ) {
364 wfDebug( "RC: Outputting cached feed\n" );
365 $feed->httpHeaders();
368 wfDebug( "RC: rendering new feed and caching it\n" );
370 rcDoOutputFeed( $rows, $feed );
371 $cachedFeed = ob_get_contents();
374 $expire = 3600 * 24; # One day
375 $messageMemc->set( $key, $cachedFeed );
376 $messageMemc->set( $timekey, wfTimestamp( TS_MW
), $expire );
381 function rcDoOutputFeed( $rows, &$feed ) {
382 $fname = 'rcDoOutputFeed';
383 wfProfileIn( $fname );
387 # Merge adjacent edits by one user
390 foreach( $rows as $obj ) {
392 $obj->rc_namespace
>= 0 &&
393 $obj->rc_cur_id
== $sorted[$n-1]->rc_cur_id
&&
394 $obj->rc_user_text
== $sorted[$n-1]->rc_user_text
) {
395 $sorted[$n-1]->rc_last_oldid
= $obj->rc_last_oldid
;
402 foreach( $sorted as $obj ) {
403 $title = Title
::makeTitle( $obj->rc_namespace
, $obj->rc_title
);
404 $talkpage = $title->getTalkPage();
405 $item = new FeedItem(
406 $title->getPrefixedText(),
407 rcFormatDiff( $obj ),
408 $title->getFullURL(),
411 $talkpage->getFullURL()
413 $feed->outItem( $item );
416 wfProfileOut( $fname );
422 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
423 global $wgUser, $wgLang, $wgContLang;
424 $sk = $wgUser->getSkin();
425 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
426 ($lim ?
$wgLang->formatNum( "{$lim}" ) : wfMsg( 'recentchangesall' ) ), "{$more}" .
427 ($d ?
"days={$d}&" : '') . 'limit='.$lim );
434 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
435 global $wgUser, $wgLang, $wgContLang;
436 $sk = $wgUser->getSkin();
437 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
438 ($d ?
$wgLang->formatNum( "{$d}" ) : wfMsg( 'recentchangesall' ) ), $more.'days='.$d .
439 ($lim ?
'&limit='.$lim : '') );
444 * Used by Recentchangeslinked
446 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
447 $botLink = '', $liuLink = '', $patrLink = '', $myselfLink = '' ) {
448 if ($more != '') $more .= '&';
449 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
450 rcCountLink( 100, $days, $page, $more ) . ' | ' .
451 rcCountLink( 250, $days, $page, $more ) . ' | ' .
452 rcCountLink( 500, $days, $page, $more ) .
453 ( $doall ?
( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
454 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
455 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
456 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
457 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
458 rcDaysLink( $limit, 30, $page, $more ) .
459 ( $doall ?
( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
461 $linkParts = array( 'minorLink' => 'minor', 'botLink' => 'bots', 'liuLink' => 'liu', 'patrLink' => 'patr', 'myselfLink' => 'mine' );
462 foreach( $linkParts as $linkVar => $linkMsg ) {
463 if( $
$linkVar != '' )
464 $links[] = wfMsgHtml( 'rcshowhide' . $linkMsg, $
$linkVar );
467 $shm = implode( ' | ', $links );
468 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
474 * Makes change an option link which carries all the other options
475 * @param $title @see Title
479 function makeOptionsLink( $title, $override, $options ) {
480 global $wgUser, $wgContLang;
481 $sk = $wgUser->getSkin();
482 return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
483 htmlspecialchars( $title ), wfArrayToCGI( $override, $options ) );
487 * Creates the options panel.
489 * @param $nondefaults
491 function rcOptionsPanel( $defaults, $nondefaults ) {
492 global $wgLang, $wgUseRCPatrol;
494 $options = $nondefaults +
$defaults;
496 if( $options['from'] )
497 $note = wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
498 $wgLang->formatNum( $options['limit'] ),
499 $wgLang->timeanddate( $options['from'], true ) );
501 $note = wfMsgExt( 'rcnote', array( 'parseinline' ),
502 $wgLang->formatNum( $options['limit'] ),
503 $wgLang->formatNum( $options['days'] ),
504 $wgLang->timeAndDate( wfTimestampNow(), true ) );
507 $options_limit = array(50, 100, 250, 500);
508 foreach( $options_limit as $value ) {
509 $cl[] = makeOptionsLink( $wgLang->formatNum( $value ),
510 array( 'limit' => $value ), $nondefaults) ;
512 $cl = implode( ' | ', $cl);
514 // day links, reset 'from' to none
515 $options_days = array(1, 3, 7, 14, 30);
516 foreach( $options_days as $value ) {
517 $dl[] = makeOptionsLink( $wgLang->formatNum( $value ),
518 array( 'days' => $value, 'from' => '' ), $nondefaults) ;
520 $dl = implode( ' | ', $dl);
524 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
525 $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
526 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
527 $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
528 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
529 $anonsLink = makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
530 array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
531 $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
532 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
533 $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
534 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
535 $myselfLink = makeOptionsLink( $showhide[1-$options['hidemyself']],
536 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
538 $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
539 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
540 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
541 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
543 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
544 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
545 $hl = implode( ' | ', $links );
547 // show from this onward link
548 $now = $wgLang->timeanddate( wfTimestampNow(), true );
549 $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
551 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter'),
553 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter'), $tl );
554 return "$note<br />$rclinks<br />$rclistfrom";
559 * Creates the choose namespace selection
563 * @param $namespace Mixed: the key of the currently selected namespace, empty string
565 * @param $invert Bool: whether to invert the namespace selection
566 * @param $nondefaults Array: an array of non default options to be remembered
567 * @param $categories_any Bool: Default value for the checkbox
571 function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
572 global $wgScript, $wgAllowCategorizedRecentChanges, $wgRequest;
573 $t = SpecialPage
::getTitleFor( 'Recentchanges' );
575 $namespaceselect = HTMLnamespaceselector($namespace, '');
576 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
577 $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ?
' checked="checked"' : '' ) . ' />';
579 if ( $wgAllowCategorizedRecentChanges ) {
580 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
581 $cb_arr = array( 'type' => 'checkbox', 'name' => 'categories_any', 'value' => "1" ) ;
582 if ( $categories_any ) $cb_arr['checked'] = "checked" ;
584 $catbox .= wfMsgExt('rc_categories', array('parseinline')) . " ";
585 $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
586 $catbox .= " " ;
587 $catbox .= wfElement('input', $cb_arr );
588 $catbox .= wfMsgExt('rc_categories_any', array('parseinline'));
593 $out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
595 foreach ( $nondefaults as $key => $value ) {
596 if ($key != 'namespace' && $key != 'invert')
597 $out .= wfElement('input', array( 'type' => 'hidden', 'name' => $key, 'value' => $value));
600 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
602 <div id='nsselect' class='recentchanges'>
603 <label for='namespace'>" . wfMsgHtml('namespace') . "</label>
604 {$namespaceselect}{$submitbutton}{$invertbox} <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>{$catbox}\n</div>";
605 $out .= '</form></div>';
611 * Format a diff for the newsfeed
613 function rcFormatDiff( $row ) {
614 $titleObj = Title
::makeTitle( $row->rc_namespace
, $row->rc_title
);
615 $timestamp = wfTimestamp( TS_MW
, $row->rc_timestamp
);
616 return rcFormatDiffRow( $titleObj,
617 $row->rc_last_oldid
, $row->rc_this_oldid
,
622 function rcFormatDiffRow( $title, $oldid, $newid, $timestamp, $comment ) {
623 global $wgFeedDiffCutoff, $wgContLang, $wgUser;
624 $fname = 'rcFormatDiff';
625 wfProfileIn( $fname );
627 $skin = $wgUser->getSkin();
628 $completeText = '<p>' . $skin->formatComment( $comment ) . "</p>\n";
630 if( $title->getNamespace() >= 0 ) {
632 wfProfileIn( "$fname-dodiff" );
634 $de = new DifferenceEngine( $title, $oldid, $newid );
635 #$diffText = $de->getDiff( wfMsg( 'revisionasof',
636 # $wgContLang->timeanddate( $timestamp ) ),
637 # wfMsg( 'currentrev' ) );
638 $diffText = $de->getDiff(
639 wfMsg( 'previousrevision' ), // hack
640 wfMsg( 'revisionasof',
641 $wgContLang->timeanddate( $timestamp ) ) );
644 if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
646 $diffLink = $title->escapeFullUrl(
648 '&oldid=' . $oldid );
649 $diffText = '<a href="' .
652 htmlspecialchars( wfMsgForContent( 'difference' ) ) .
654 } elseif ( $diffText === false ) {
655 // Error in diff engine, probably a missing revision
656 $diffText = "<p>Can't load revision $newid</p>";
658 // Diff output fine, clean up any illegal UTF-8
659 $diffText = UtfNormal
::cleanUp( $diffText );
660 $diffText = rcApplyDiffStyle( $diffText );
662 wfProfileOut( "$fname-dodiff" );
664 $rev = Revision
::newFromId( $newid );
665 if( is_null( $rev ) ) {
668 $newtext = $rev->getText();
670 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
671 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
673 $completeText .= $diffText;
676 wfProfileOut( $fname );
677 return $completeText;
681 * Hacky application of diff styles for the feeds.
682 * Might be 'cleaner' to use DOM or XSLT or something,
683 * but *gack* it's a pain in the ass.
685 * @param $text String:
689 function rcApplyDiffStyle( $text ) {
691 'diff' => 'background-color: white;',
692 'diff-otitle' => 'background-color: white;',
693 'diff-ntitle' => 'background-color: white;',
694 'diff-addedline' => 'background: #cfc; font-size: smaller;',
695 'diff-deletedline' => 'background: #ffa; font-size: smaller;',
696 'diff-context' => 'background: #eee; font-size: smaller;',
697 'diffchange' => 'color: red; font-weight: bold;',
700 foreach( $styles as $class => $style ) {
701 $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
702 "\\1style=\"$style\"\\3", $text );