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 */ '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 $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 ( 'hidemyself' == $bit ) $hidemyself = 1;
89 if ( is_numeric( $bit ) ) {
93 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
97 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
104 if ( $limit < 0 ||
$limit > 5000 ) $limit = $defaults['limit'];
107 # Database connection and caching
108 $dbr =& wfGetDB( DB_SLAVE
);
109 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
112 $cutoff_unixtime = time() - ( $days * 86400 );
113 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime %
86400);
114 $cutoff = $dbr->timestamp( $cutoff_unixtime );
115 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW
,$cutoff)) {
116 $cutoff = $dbr->timestamp($from);
118 $from = $defaults['from'];
121 # 10 seconds server-side caching max
122 $wgOut->setSquidMaxage( 10 );
124 # Get last modified date, for client caching
125 # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
126 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
127 if ( $feedFormat ||
!$wgUseRCPatrol ) {
128 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
129 # Client cache fresh and headers sent, nothing more to do.
134 $hidem = $hideminor ?
'AND rc_minor=0' : '';
135 $hidem .= $hidebots ?
' AND rc_bot=0' : '';
136 $hidem .= ( $hideliu && !$hidemyself ) ?
' AND rc_user=0' : '';
137 $hidem .= $hidepatrolled ?
' AND rc_patrolled=0' : '';
139 if ( $wgUser->getID() ) {
140 $hidem .= ' AND rc_user <> '.$wgUser->getID();
142 $hidem .= ' AND rc_user_text<>' . $dbr->addQuotes( $wgUser->getName() );
145 $hidem .= is_null( $namespace ) ?
'' : ' AND rc_namespace' . ($invert ?
'!=' : '=') . $namespace;
147 // This is the big thing!
149 $uid = $wgUser->getID();
152 $sql2 = "SELECT * FROM $recentchanges FORCE INDEX (rc_timestamp) " .
153 ($uid ?
"LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") .
154 "WHERE rc_timestamp >= '{$cutoff}' {$hidem} " .
155 "ORDER BY rc_timestamp DESC";
156 $sql2 = $dbr->limitResult($sql2, $limit, 0);
157 $res = $dbr->query( $sql2, $fname );
159 // Fetch results, prepare a batch link existence check query
161 $batch = new LinkBatch
;
162 while( $row = $dbr->fetchObject( $res ) ){
164 if ( !$feedFormat ) {
166 $title = Title
::makeTitleSafe( NS_USER
, $row->rc_user_text
);
167 $batch->addObj( $title );
170 $title = Title
::makeTitleSafe( NS_USER_TALK
, $row->rc_user_text
);
171 $batch->addObj( $title );
175 $dbr->freeResult( $res );
178 rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod );
183 // Run existence checks
185 $any = $wgRequest->getBool( 'categories_any', $defaults['categories_any']);
188 if ( !$specialPage->including() ) {
189 $wgOut->addWikiText( wfMsgForContent( "recentchangestext" ) );
191 // Dump everything here
192 $nondefaults = array();
194 wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults);
195 wfAppendToArrayIfNotDefault( 'limit', $limit , $defaults, $nondefaults);
196 wfAppendToArrayIfNotDefault( 'hideminor', $hideminor, $defaults, $nondefaults);
197 wfAppendToArrayIfNotDefault( 'hidebots', $hidebots, $defaults, $nondefaults);
198 wfAppendToArrayIfNotDefault( 'hideliu', $hideliu, $defaults, $nondefaults);
199 wfAppendToArrayIfNotDefault( 'hidepatrolled', $hidepatrolled, $defaults, $nondefaults);
200 wfAppendToArrayIfNotDefault( 'hidemyself', $hidemyself, $defaults, $nondefaults);
201 wfAppendToArrayIfNotDefault( 'from', $from, $defaults, $nondefaults);
202 wfAppendToArrayIfNotDefault( 'namespace', $namespace, $defaults, $nondefaults);
203 wfAppendToArrayIfNotDefault( 'invert', $invert, $defaults, $nondefaults);
204 wfAppendToArrayIfNotDefault( 'categories_any', $any, $defaults, $nondefaults);
206 // Add end of the texts
207 $wgOut->addHTML( '<div class="rcoptions">' . rcOptionsPanel( $defaults, $nondefaults ) . "\n" );
208 $wgOut->addHTML( rcNamespaceForm( $namespace, $invert, $nondefaults, $any ) . '</div>'."\n");
211 // And now for the content
212 $sk = $wgUser->getSkin();
213 $wgOut->setSyndicated( true );
215 $list = ChangesList
::newFromUser( $wgUser );
217 if ( $wgAllowCategorizedRecentChanges ) {
218 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
219 $categories = str_replace ( "|" , "\n" , $categories ) ;
220 $categories = explode ( "\n" , $categories ) ;
221 rcFilterByCategories ( $rows , $categories , $any ) ;
224 $s = $list->beginRecentChangesList();
226 foreach( $rows as $obj ){
231 if ( ! ( $hideminor && $obj->rc_minor
) &&
232 ! ( $hidepatrolled && $obj->rc_patrolled
) ) {
233 $rc = RecentChange
::newFromRow( $obj );
234 $rc->counter
= $counter++
;
236 if ($wgShowUpdatedMarker
237 && !empty( $obj->wl_notificationtimestamp
)
238 && ($obj->rc_timestamp
>= $obj->wl_notificationtimestamp
)) {
239 $rc->notificationtimestamp
= true;
241 $rc->notificationtimestamp
= false;
244 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
245 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" . $dbr->strencode($obj->rc_title
) ."' AND wl_namespace=$obj->rc_namespace" ;
246 $res3 = $dbr->query( $sql3, 'wfSpecialRecentChanges');
247 $x = $dbr->fetchObject( $res3 );
248 $rc->numberofWatchingusers
= $x->n
;
250 $rc->numberofWatchingusers
= 0;
252 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user
) );
256 $s .= $list->endRecentChangesList();
257 $wgOut->addHTML( $s );
261 function rcFilterByCategories ( &$rows , $categories , $any ) {
262 require_once ( 'Categoryfinder.php' ) ;
266 foreach ( $categories AS $cat ) {
267 $cat = trim ( $cat ) ;
268 if ( $cat == "" ) continue ;
273 $articles = array () ;
275 foreach ( $rows AS $k => $r ) {
276 $nt = Title
::newFromText ( $r->rc_title
, $r->rc_namespace
) ;
277 $id = $nt->getArticleID() ;
278 if ( $id == 0 ) continue ; # Page might have been deleted...
279 if ( !in_array ( $id , $articles ) ) {
282 if ( !isset ( $a2r[$id] ) ) {
283 $a2r[$id] = array() ;
289 if ( count ( $articles ) == 0 OR count ( $cats ) == 0 )
293 $c = new Categoryfinder
;
294 $c->seed ( $articles , $cats , $any ?
"OR" : "AND" ) ;
295 $match = $c->run () ;
298 $newrows = array () ;
299 foreach ( $match AS $id ) {
300 foreach ( $a2r[$id] AS $rev ) {
302 $newrows[$k] = $rows[$k] ;
308 function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
309 global $messageMemc, $wgDBname, $wgFeedCacheTimeout;
310 global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
312 if( !isset( $wgFeedClasses[$feedFormat] ) ) {
313 wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
317 $timekey = "$wgDBname:rcfeed:$feedFormat:timestamp";
318 $key = "$wgDBname:rcfeed:$feedFormat:limit:$limit:minor:$hideminor";
320 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchanges' ) .
321 ' [' . $wgContLanguageCode . ']';
322 $feed = new $wgFeedClasses[$feedFormat](
324 htmlspecialchars( wfMsgForContent( 'recentchangestext' ) ),
325 $wgTitle->getFullUrl() );
328 * Bumping around loading up diffs can be pretty slow, so where
329 * possible we want to cache the feed output so the next visitor
333 if( ( $wgFeedCacheTimeout > 0 ) && ( $feedLastmod = $messageMemc->get( $timekey ) ) ) {
335 * If the cached feed was rendered very recently, we may
336 * go ahead and use it even if there have been edits made
337 * since it was rendered. This keeps a swarm of requests
338 * from being too bad on a super-frequently edited wiki.
340 if( time() - wfTimestamp( TS_UNIX
, $feedLastmod )
341 < $wgFeedCacheTimeout
342 ||
wfTimestamp( TS_UNIX
, $feedLastmod )
343 > wfTimestamp( TS_UNIX
, $lastmod ) ) {
344 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
345 $cachedFeed = $messageMemc->get( $key );
347 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
350 if( is_string( $cachedFeed ) ) {
351 wfDebug( "RC: Outputting cached feed\n" );
352 $feed->httpHeaders();
355 wfDebug( "RC: rendering new feed and caching it\n" );
357 rcDoOutputFeed( $rows, $feed );
358 $cachedFeed = ob_get_contents();
361 $expire = 3600 * 24; # One day
362 $messageMemc->set( $key, $cachedFeed );
363 $messageMemc->set( $timekey, wfTimestamp( TS_MW
), $expire );
368 function rcDoOutputFeed( $rows, &$feed ) {
369 $fname = 'rcDoOutputFeed';
370 wfProfileIn( $fname );
374 # Merge adjacent edits by one user
377 foreach( $rows as $obj ) {
379 $obj->rc_namespace
>= 0 &&
380 $obj->rc_cur_id
== $sorted[$n-1]->rc_cur_id
&&
381 $obj->rc_user_text
== $sorted[$n-1]->rc_user_text
) {
382 $sorted[$n-1]->rc_last_oldid
= $obj->rc_last_oldid
;
390 foreach( $sorted as $obj ) {
391 $title = Title
::makeTitle( $obj->rc_namespace
, $obj->rc_title
);
392 $talkpage = $title->getTalkPage();
393 $item = new FeedItem(
394 $title->getPrefixedText(),
395 rcFormatDiff( $obj ),
396 $title->getFullURL(),
399 $talkpage->getFullURL()
401 $feed->outItem( $item );
404 wfProfileOut( $fname );
410 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
411 global $wgUser, $wgLang, $wgContLang;
412 $sk = $wgUser->getSkin();
413 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
414 ($lim ?
$wgLang->formatNum( "{$lim}" ) : wfMsg( 'recentchangesall' ) ), "{$more}" .
415 ($d ?
"days={$d}&" : '') . 'limit='.$lim );
422 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
423 global $wgUser, $wgLang, $wgContLang;
424 $sk = $wgUser->getSkin();
425 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
426 ($d ?
$wgLang->formatNum( "{$d}" ) : wfMsg( 'recentchangesall' ) ), $more.'days='.$d .
427 ($lim ?
'&limit='.$lim : '') );
432 * Used by Recentchangeslinked
434 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
435 $botLink = '', $liuLink = '', $patrLink = '', $myselfLink = '' ) {
436 if ($more != '') $more .= '&';
437 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
438 rcCountLink( 100, $days, $page, $more ) . ' | ' .
439 rcCountLink( 250, $days, $page, $more ) . ' | ' .
440 rcCountLink( 500, $days, $page, $more ) .
441 ( $doall ?
( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
442 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
443 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
444 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
445 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
446 rcDaysLink( $limit, 30, $page, $more ) .
447 ( $doall ?
( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
448 $shm = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink, $myselfLink );
449 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
455 * Makes change an option link which carries all the other options
457 function makeOptionsLink( $title, $override, $options ) {
458 global $wgUser, $wgContLang;
459 $sk = $wgUser->getSkin();
460 return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
461 $title, wfArrayToCGI( $override, $options ) );
465 * Creates the options panel
467 function rcOptionsPanel( $defaults, $nondefaults ) {
470 $options = $nondefaults +
$defaults;
472 if( $options['from'] )
473 $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $options['limit'] ), $wgLang->timeanddate( $options['from'], true ) );
475 $note = wfMsg( 'rcnote', $wgLang->formatNum( $options['limit'] ), $wgLang->formatNum( $options['days'] ) );
479 $options_limit = array(50, 100, 250, 500);
481 while ( $i+
1 < count($options_limit) ) {
482 $cl .= makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) . ' | ' ;
485 $cl .= makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) ;
487 // day links, reset 'from' to none
489 $options_days = array(1, 3, 7, 14, 30);
491 while ( $i+
1 < count($options_days) ) {
492 $dl .= makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) . ' | ' ;
495 $dl .= makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) ;
498 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
499 $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
500 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
501 $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
502 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
503 $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
504 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
505 $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
506 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
507 $myselfLink = makeOptionsLink( $showhide[1-$options['hidemyself']],
508 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
509 $hl = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink, $myselfLink );
511 // show from this onward link
512 $now = $wgLang->timeanddate( wfTimestampNow(), true );
513 $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
515 $rclinks = wfMsg( 'rclinks', $cl, $dl, $hl );
516 $rclistfrom = wfMsg( 'rclistfrom', $tl );
517 return "$note<br />$rclinks<br />$rclistfrom";
522 * Creates the choose namespace selection
526 * @param mixed $namespace The key of the currently selected namespace, empty string
528 * @param bool $invert Whether to invert the namespace selection
529 * @param array $nondefaults An array of non default options to be remembered
530 * @param bool $categories_any Default value for the checkbox
534 function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
535 global $wgScript, $wgAllowCategorizedRecentChanges, $wgRequest;
536 $t = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
538 $namespaceselect = HTMLnamespaceselector($namespace, '');
539 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
540 $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ?
' checked="checked"' : '' ) . ' />';
542 if ( $wgAllowCategorizedRecentChanges ) {
543 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
544 $cb_arr = array( 'type' => 'checkbox', 'name' => 'categories_any', 'value' => "1" ) ;
545 if ( $categories_any ) $cb_arr['checked'] = "checked" ;
547 $catbox .= wfMsg('rc_categories') . " ";
548 $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
549 $catbox .= " " ;
550 $catbox .= wfElement('input', $cb_arr );
551 $catbox .= wfMsg('rc_categories_any');
556 $out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
558 foreach ( $nondefaults as $key => $value ) {
559 if ($key != 'namespace' && $key != 'invert')
560 $out .= wfElement('input', array( 'type' => 'hidden', 'name' => $key, 'value' => $value));
563 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
565 <div id='nsselect' class='recentchanges'>
566 <label for='namespace'>" . wfMsgHtml('namespace') . "</label>
567 {$namespaceselect}{$submitbutton}{$invertbox} <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>{$catbox}\n</div>";
568 $out .= '</form></div>';
574 * Format a diff for the newsfeed
576 function rcFormatDiff( $row ) {
577 global $wgFeedDiffCutoff, $wgContLang;
578 $fname = 'rcFormatDiff';
579 wfProfileIn( $fname );
581 require_once( 'DifferenceEngine.php' );
582 $completeText = '<p>' . htmlspecialchars( $row->rc_comment
) . "</p>\n";
584 if( $row->rc_namespace
>= 0 ) {
585 if( $row->rc_last_oldid
) {
586 wfProfileIn( "$fname-dodiff" );
588 $titleObj = Title
::makeTitle( $row->rc_namespace
, $row->rc_title
);
589 $de = new DifferenceEngine( $titleObj, $row->rc_last_oldid
, $row->rc_this_oldid
);
590 $diffText = $de->getDiff( wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp
) ),
591 wfMsg( 'currentrev' ) );
593 if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
595 $diffLink = $titleObj->escapeFullUrl(
596 'diff=' . $row->rc_this_oldid
.
597 '&oldid=' . $row->rc_last_oldid
);
598 $diffText = '<a href="' .
601 htmlspecialchars( wfMsgForContent( 'difference' ) ) .
603 } elseif ( $diffText === false ) {
604 // Error in diff engine, probably a missing revision
605 $diffText = "<p>Can't load revision $row->rc_this_oldid</p>";
607 // Diff output fine, clean up any illegal UTF-8
608 $diffText = UtfNormal
::cleanUp( $diffText );
609 $diffText = rcApplyDiffStyle( $diffText );
611 wfProfileOut( "$fname-dodiff" );
613 $rev = Revision
::newFromId( $row->rc_this_oldid
);
614 if( is_null( $rev ) ) {
617 $newtext = $rev->getText();
619 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
620 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
622 $completeText .= $diffText;
625 wfProfileOut( $fname );
626 return $completeText;
630 * Hacky application of diff styles for the feeds.
631 * Might be 'cleaner' to use DOM or XSLT or something,
632 * but *gack* it's a pain in the ass.
634 * @param string $text
638 function rcApplyDiffStyle( $text ) {
640 'diff' => 'background-color: white;',
641 'diff-otitle' => 'background-color: white;',
642 'diff-ntitle' => 'background-color: white;',
643 'diff-addedline' => 'background: #cfc; font-size: smaller;',
644 'diff-deletedline' => 'background: #ffa; font-size: smaller;',
645 'diff-context' => 'background: #eee; font-size: smaller;',
646 'diffchange' => 'color: red; font-weight: bold;',
649 foreach( $styles as $class => $style ) {
650 $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
651 "\\1style=\"$style\"\\3", $text );