5 * @subpackage SpecialPage
11 require_once( 'Feed.php' );
12 require_once( 'ChangesList.php' );
13 require_once( 'Revision.php' );
18 function wfSpecialRecentchanges( $par, $specialPage ) {
19 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
20 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
21 global $wgAllowCategorizedRecentChanges ;
22 $fname = 'wfSpecialRecentchanges';
24 # Get query parameters
25 $feedFormat = $wgRequest->getVal( 'feed' );
27 /* Checkbox values can't be true be default, because
28 * we cannot differentiate between unset and not set at all
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,
48 $days = $wgUser->getOption( 'rcdays' );
49 if ( !$days ) { $days = $defaults['days']; }
50 $days = $wgRequest->getInt( 'days', $days );
52 $limit = $wgUser->getOption( 'rclimit' );
53 if ( !$limit ) { $limit = $defaults['limit']; }
55 # list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
56 $limit = $wgRequest->getInt( 'limit', $limit );
58 /* order of selection: url > preferences > default */
59 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor') ?
true : $defaults['hideminor'] );
61 # As a feed, use limited settings only
64 if( $limit > $wgFeedLimit ) {
65 $options['limit'] = $wgFeedLimit;
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'] );
79 # Get query parameters from path
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;
92 if ( is_numeric( $bit ) ) {
96 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
100 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
107 if ( $limit < 0 ||
$limit > 5000 ) $limit = $defaults['limit'];
110 # Database connection and caching
111 $dbr =& wfGetDB( DB_SLAVE
);
112 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
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);
121 $from = $defaults['from'];
124 # 10 seconds server-side caching max
125 $wgOut->setSquidMaxage( 10 );
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.
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 )
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' : '';
150 if( $wgUser->getID() ) {
151 $hidem .= ' AND rc_user != ' . $wgUser->getID();
153 $hidem .= ' AND rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() );
157 # Namespace filtering
158 $hidem .= is_null( $namespace ) ?
'' : ' AND rc_namespace' . ($invert ?
'!=' : '=') . $namespace;
160 // This is the big thing!
162 $uid = $wgUser->getID();
165 $sql2 = "SELECT * FROM $recentchanges FORCE INDEX (rc_timestamp) " .
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 ) ) : '' );
462 $shm = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink, $myselfLink );
463 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
469 * Makes change an option link which carries all the other options
471 function makeOptionsLink( $title, $override, $options ) {
472 global $wgUser, $wgContLang;
473 $sk = $wgUser->getSkin();
474 return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
475 $title, wfArrayToCGI( $override, $options ) );
479 * Creates the options panel
481 function rcOptionsPanel( $defaults, $nondefaults ) {
482 global $wgLang, $wgUseRCPatrol;
484 $options = $nondefaults +
$defaults;
486 if( $options['from'] )
487 $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $options['limit'] ), $wgLang->timeanddate( $options['from'], true ) );
489 $note = wfMsg( 'rcnote', $wgLang->formatNum( $options['limit'] ), $wgLang->formatNum( $options['days'] ) );
493 $options_limit = array(50, 100, 250, 500);
495 while ( $i+
1 < count($options_limit) ) {
496 $cl .= makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) . ' | ' ;
499 $cl .= makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) ;
501 // day links, reset 'from' to none
503 $options_days = array(1, 3, 7, 14, 30);
505 while ( $i+
1 < count($options_days) ) {
506 $dl .= makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) . ' | ' ;
509 $dl .= makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) ;
512 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
513 $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
514 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
515 $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
516 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
517 $anonsLink = makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
518 array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
519 $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
520 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
521 $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
522 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
523 $myselfLink = makeOptionsLink( $showhide[1-$options['hidemyself']],
524 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
526 $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
527 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
528 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
529 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
531 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
532 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
533 $hl = implode( ' | ', $links );
535 // show from this onward link
536 $now = $wgLang->timeanddate( wfTimestampNow(), true );
537 $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
539 $rclinks = wfMsg( 'rclinks', $cl, $dl, $hl );
540 $rclistfrom = wfMsg( 'rclistfrom', $tl );
541 return "$note<br />$rclinks<br />$rclistfrom";
546 * Creates the choose namespace selection
550 * @param mixed $namespace The key of the currently selected namespace, empty string
552 * @param bool $invert Whether to invert the namespace selection
553 * @param array $nondefaults An array of non default options to be remembered
554 * @param bool $categories_any Default value for the checkbox
558 function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
559 global $wgScript, $wgAllowCategorizedRecentChanges, $wgRequest;
560 $t = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
562 $namespaceselect = HTMLnamespaceselector($namespace, '');
563 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
564 $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ?
' checked="checked"' : '' ) . ' />';
566 if ( $wgAllowCategorizedRecentChanges ) {
567 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
568 $cb_arr = array( 'type' => 'checkbox', 'name' => 'categories_any', 'value' => "1" ) ;
569 if ( $categories_any ) $cb_arr['checked'] = "checked" ;
571 $catbox .= wfMsg('rc_categories') . " ";
572 $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
573 $catbox .= " " ;
574 $catbox .= wfElement('input', $cb_arr );
575 $catbox .= wfMsg('rc_categories_any');
580 $out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
582 foreach ( $nondefaults as $key => $value ) {
583 if ($key != 'namespace' && $key != 'invert')
584 $out .= wfElement('input', array( 'type' => 'hidden', 'name' => $key, 'value' => $value));
587 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
589 <div id='nsselect' class='recentchanges'>
590 <label for='namespace'>" . wfMsgHtml('namespace') . "</label>
591 {$namespaceselect}{$submitbutton}{$invertbox} <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>{$catbox}\n</div>";
592 $out .= '</form></div>';
598 * Format a diff for the newsfeed
600 function rcFormatDiff( $row ) {
601 global $wgFeedDiffCutoff, $wgContLang;
602 $fname = 'rcFormatDiff';
603 wfProfileIn( $fname );
605 require_once( 'DifferenceEngine.php' );
606 $completeText = '<p>' . htmlspecialchars( $row->rc_comment
) . "</p>\n";
608 if( $row->rc_namespace
>= 0 ) {
609 if( $row->rc_last_oldid
) {
610 wfProfileIn( "$fname-dodiff" );
612 $titleObj = Title
::makeTitle( $row->rc_namespace
, $row->rc_title
);
613 $de = new DifferenceEngine( $titleObj, $row->rc_last_oldid
, $row->rc_this_oldid
);
614 $diffText = $de->getDiff( wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp
) ),
615 wfMsg( 'currentrev' ) );
617 if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
619 $diffLink = $titleObj->escapeFullUrl(
620 'diff=' . $row->rc_this_oldid
.
621 '&oldid=' . $row->rc_last_oldid
);
622 $diffText = '<a href="' .
625 htmlspecialchars( wfMsgForContent( 'difference' ) ) .
627 } elseif ( $diffText === false ) {
628 // Error in diff engine, probably a missing revision
629 $diffText = "<p>Can't load revision $row->rc_this_oldid</p>";
631 // Diff output fine, clean up any illegal UTF-8
632 $diffText = UtfNormal
::cleanUp( $diffText );
633 $diffText = rcApplyDiffStyle( $diffText );
635 wfProfileOut( "$fname-dodiff" );
637 $rev = Revision
::newFromId( $row->rc_this_oldid
);
638 if( is_null( $rev ) ) {
641 $newtext = $rev->getText();
643 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
644 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
646 $completeText .= $diffText;
649 wfProfileOut( $fname );
650 return $completeText;
654 * Hacky application of diff styles for the feeds.
655 * Might be 'cleaner' to use DOM or XSLT or something,
656 * but *gack* it's a pain in the ass.
658 * @param string $text
662 function rcApplyDiffStyle( $text ) {
664 'diff' => 'background-color: white;',
665 'diff-otitle' => 'background-color: white;',
666 'diff-ntitle' => 'background-color: white;',
667 'diff-addedline' => 'background: #cfc; font-size: smaller;',
668 'diff-deletedline' => 'background: #ffa; font-size: smaller;',
669 'diff-context' => 'background: #eee; font-size: smaller;',
670 'diffchange' => 'color: red; font-weight: bold;',
673 foreach( $styles as $class => $style ) {
674 $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
675 "\\1style=\"$style\"\\3", $text );