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 ;
20 # Get query parameters
21 $feedFormat = $wgRequest->getVal( 'feed' );
23 /* Checkbox values can't be true by default, because
24 * we cannot differentiate between unset and not set at all
27 /* int */ 'days' => $wgUser->getDefaultOption('rcdays'),
28 /* int */ 'limit' => $wgUser->getDefaultOption('rclimit'),
29 /* bool */ 'hideminor' => false,
30 /* bool */ 'hidebots' => true,
31 /* bool */ 'hideanons' => false,
32 /* bool */ 'hideliu' => false,
33 /* bool */ 'hidepatrolled' => false,
34 /* bool */ 'hidemyself' => false,
35 /* text */ 'from' => '',
36 /* text */ 'namespace' => null,
37 /* bool */ 'invert' => false,
38 /* bool */ 'categories_any' => false,
44 $days = $wgUser->getOption( 'rcdays', $defaults['days']);
45 $days = $wgRequest->getInt( 'days', $days );
47 $limit = $wgUser->getOption( 'rclimit', $defaults['limit'] );
49 # list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
50 $limit = $wgRequest->getInt( 'limit', $limit );
52 /* order of selection: url > preferences > default */
53 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor') ?
true : $defaults['hideminor'] );
55 # As a feed, use limited settings only
58 $limit = min( $wgFeedLimit, $limit );
61 $namespace = $wgRequest->getIntOrNull( 'namespace' );
62 $invert = $wgRequest->getBool( 'invert', $defaults['invert'] );
63 $hidebots = $wgRequest->getBool( 'hidebots', $defaults['hidebots'] );
64 $hideanons = $wgRequest->getBool( 'hideanons', $defaults['hideanons'] );
65 $hideliu = $wgRequest->getBool( 'hideliu', $defaults['hideliu'] );
66 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', $defaults['hidepatrolled'] );
67 $hidemyself = $wgRequest->getBool ( 'hidemyself', $defaults['hidemyself'] );
68 $from = $wgRequest->getVal( 'from', $defaults['from'] );
70 # Get query parameters from path
72 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
73 foreach ( $bits as $bit ) {
74 if ( 'hidebots' == $bit ) $hidebots = 1;
75 if ( 'bots' == $bit ) $hidebots = 0;
76 if ( 'hideminor' == $bit ) $hideminor = 1;
77 if ( 'minor' == $bit ) $hideminor = 0;
78 if ( 'hideliu' == $bit ) $hideliu = 1;
79 if ( 'hidepatrolled' == $bit ) $hidepatrolled = 1;
80 if ( 'hideanons' == $bit ) $hideanons = 1;
81 if ( 'hidemyself' == $bit ) $hidemyself = 1;
83 if ( is_numeric( $bit ) ) {
88 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
92 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
99 if ( $limit < 0 ||
$limit > 5000 ) $limit = $defaults['limit'];
101 # Database connection and caching
102 $dbr = wfGetDB( DB_SLAVE
);
104 $cutoff_unixtime = time() - ( $days * 86400 );
105 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime %
86400);
106 $cutoff = $dbr->timestamp( $cutoff_unixtime );
107 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW
,$cutoff)) {
108 $cutoff = $dbr->timestamp($from);
110 $from = $defaults['from'];
113 # 10 seconds server-side caching max
114 $wgOut->setSquidMaxage( 10 );
116 # Get last modified date, for client caching
117 # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
118 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __FUNCTION__
);
119 if ( $feedFormat ||
!$wgUseRCPatrol ) {
120 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
121 # Client cache fresh and headers sent, nothing more to do.
126 # It makes no sense to hide both anons and logged-in users
127 # Where this occurs, force anons to be shown
129 if( $hideanons && $hideliu ){
130 # Check if the user wants to show bots only
139 # Form WHERE fragments for all the options
140 $hidem = $hideminor ?
'AND rc_minor = 0' : '';
141 $hidem .= $hidebots ?
' AND rc_bot = 0' : '';
142 $hidem .= $hideliu && !$forcebot ?
' AND rc_user = 0' : '';
143 $hidem .= ($wgUser->useRCPatrol() && $hidepatrolled ) ?
' AND rc_patrolled = 0' : '';
144 $hidem .= $hideanons && !$forcebot ?
' AND rc_user != 0' : '';
145 $hidem .= $forcebot ?
' AND rc_bot = 1' : '';
148 if( $wgUser->getId() ) {
149 $hidem .= ' AND rc_user != ' . $wgUser->getId();
151 $hidem .= ' AND rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() );
155 // JOIN on watchlist for users
156 $uid = $wgUser->getId();
158 $tables = array( 'recentchanges', 'watchlist' );
159 $join_conds = array( 'watchlist' => array('LEFT JOIN',"wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace") );
161 $tables = array( 'recentchanges' );
162 $join_conds = array();
165 # Namespace filtering
166 $hidem .= is_null($namespace) ?
'' : ' AND rc_namespace' . ($invert ?
'!=' : '=') . $namespace;
168 // Is there either one namespace selected or excluded?
169 // Also, if this is "all" or main namespace, just use timestamp index.
170 if( is_null($namespace) ||
$invert ||
$namespace == NS_MAIN
) {
171 $res = $dbr->select( $tables, '*',
172 array( "rc_timestamp >= '{$cutoff}' {$hidem}" ),
174 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
175 'USE INDEX' => array('recentchanges' => 'rc_timestamp') ),
177 // We have a new_namespace_time index! UNION over new=(0,1) and sort result set!
180 $sqlNew = $dbr->selectSQLText( $tables, '*',
181 array( 'rc_new' => 1,
182 "rc_timestamp >= '{$cutoff}' {$hidem}" ),
184 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
185 'USE INDEX' => array('recentchanges' => 'new_name_timestamp') ),
188 $sqlOld = $dbr->selectSQLText( $tables, '*',
189 array( 'rc_new' => 0,
190 "rc_timestamp >= '{$cutoff}' {$hidem}" ),
192 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
193 'USE INDEX' => array('recentchanges' => 'new_name_timestamp') ),
195 # Join the two fast queries, and sort the result set
196 $sql = "($sqlNew) UNION ($sqlOld) ORDER BY rc_timestamp DESC LIMIT $limit";
197 $res = $dbr->query( $sql, __METHOD__
);
200 // Fetch results, prepare a batch link existence check query
202 $batch = new LinkBatch
;
203 while( $row = $dbr->fetchObject( $res ) ){
205 if ( !$feedFormat ) {
206 // User page and talk links
207 $batch->add( NS_USER
, $row->rc_user_text
);
208 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
212 $dbr->freeResult( $res );
215 rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod );
220 // Run existence checks
222 $any = $wgRequest->getBool( 'categories_any', $defaults['categories_any']);
225 if ( !$specialPage->including() ) {
226 $wgOut->addWikiText( wfMsgForContentNoTrans( "recentchangestext" ) );
228 // Dump everything here
229 $nondefaults = array();
231 wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults);
232 wfAppendToArrayIfNotDefault( 'limit', $limit , $defaults, $nondefaults);
233 wfAppendToArrayIfNotDefault( 'hideminor', $hideminor, $defaults, $nondefaults);
234 wfAppendToArrayIfNotDefault( 'hidebots', $hidebots, $defaults, $nondefaults);
235 wfAppendToArrayIfNotDefault( 'hideanons', $hideanons, $defaults, $nondefaults );
236 wfAppendToArrayIfNotDefault( 'hideliu', $hideliu, $defaults, $nondefaults);
237 wfAppendToArrayIfNotDefault( 'hidepatrolled', $hidepatrolled, $defaults, $nondefaults);
238 wfAppendToArrayIfNotDefault( 'hidemyself', $hidemyself, $defaults, $nondefaults);
239 wfAppendToArrayIfNotDefault( 'from', $from, $defaults, $nondefaults);
240 wfAppendToArrayIfNotDefault( 'namespace', $namespace, $defaults, $nondefaults);
241 wfAppendToArrayIfNotDefault( 'invert', $invert, $defaults, $nondefaults);
242 wfAppendToArrayIfNotDefault( 'categories_any', $any, $defaults, $nondefaults);
244 // Add end of the texts
245 $wgOut->addHTML( '<div class="rcoptions">' . rcOptionsPanel( $defaults, $nondefaults ) . "\n" );
246 $wgOut->addHTML( rcNamespaceForm( $namespace, $invert, $nondefaults, $any ) . '</div>'."\n");
249 // And now for the content
250 $wgOut->setSyndicated( true );
252 $list = ChangesList
::newFromUser( $wgUser );
254 if ( $wgAllowCategorizedRecentChanges ) {
255 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
256 $categories = str_replace ( "|" , "\n" , $categories ) ;
257 $categories = explode ( "\n" , $categories ) ;
258 rcFilterByCategories ( $rows , $categories , $any ) ;
261 $s = $list->beginRecentChangesList();
264 $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' );
265 $watcherCache = array();
267 foreach( $rows as $obj ){
272 if ( ! ( $hideminor && $obj->rc_minor
) &&
273 ! ( $hidepatrolled && $obj->rc_patrolled
) ) {
274 $rc = RecentChange
::newFromRow( $obj );
275 $rc->counter
= $counter++
;
277 if ($wgShowUpdatedMarker
278 && !empty( $obj->wl_notificationtimestamp
)
279 && ($obj->rc_timestamp
>= $obj->wl_notificationtimestamp
)) {
280 $rc->notificationtimestamp
= true;
282 $rc->notificationtimestamp
= false;
285 $rc->numberofWatchingusers
= 0; // Default
286 if ($showWatcherCount && $obj->rc_namespace
>= 0) {
287 if (!isset($watcherCache[$obj->rc_namespace
][$obj->rc_title
])) {
288 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
289 $dbr->selectField( 'watchlist',
292 'wl_namespace' => $obj->rc_namespace
,
293 'wl_title' => $obj->rc_title
,
295 __METHOD__
. '-watchers' );
297 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
299 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user
) );
303 $s .= $list->endRecentChangesList();
304 $wgOut->addHTML( $s );
308 function rcFilterByCategories ( &$rows , $categories , $any ) {
309 if( empty( $categories ) ) {
315 foreach ( $categories AS $cat ) {
316 $cat = trim ( $cat ) ;
317 if ( $cat == "" ) continue ;
322 $articles = array () ;
324 foreach ( $rows AS $k => $r ) {
325 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
326 $id = $nt->getArticleID() ;
327 if ( $id == 0 ) continue ; # Page might have been deleted...
328 if ( !in_array ( $id , $articles ) ) {
331 if ( !isset ( $a2r[$id] ) ) {
332 $a2r[$id] = array() ;
338 if ( count ( $articles ) == 0 OR count ( $cats ) == 0 )
342 $c = new Categoryfinder
;
343 $c->seed ( $articles , $cats , $any ?
"OR" : "AND" ) ;
344 $match = $c->run () ;
347 $newrows = array () ;
348 foreach ( $match AS $id ) {
349 foreach ( $a2r[$id] AS $rev ) {
351 $newrows[$k] = $rows[$k] ;
357 function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
358 global $messageMemc, $wgFeedCacheTimeout;
359 global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
364 $wgOut->addWikiMsg( 'feed-unavailable' );
368 if( !isset( $wgFeedClasses[$feedFormat] ) ) {
369 wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
373 $timekey = wfMemcKey( 'rcfeed', $feedFormat, 'timestamp' );
374 $key = wfMemcKey( 'rcfeed', $feedFormat, 'limit', $limit, 'minor', $hideminor );
376 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchanges' ) .
377 ' [' . $wgContLanguageCode . ']';
378 $feed = new $wgFeedClasses[$feedFormat](
380 htmlspecialchars( wfMsgForContent( 'recentchanges-feed-description' ) ),
381 $wgTitle->getFullUrl() );
383 //purge cache if requested
384 global $wgRequest, $wgUser;
385 $purge = $wgRequest->getVal( 'action' ) == 'purge';
386 if ( $purge && $wgUser->isAllowed('purge') ) {
387 $messageMemc->delete( $timekey );
388 $messageMemc->delete( $key );
392 * Bumping around loading up diffs can be pretty slow, so where
393 * possible we want to cache the feed output so the next visitor
397 if( ( $wgFeedCacheTimeout > 0 ) && ( $feedLastmod = $messageMemc->get( $timekey ) ) ) {
399 * If the cached feed was rendered very recently, we may
400 * go ahead and use it even if there have been edits made
401 * since it was rendered. This keeps a swarm of requests
402 * from being too bad on a super-frequently edited wiki.
404 if( time() - wfTimestamp( TS_UNIX
, $feedLastmod )
405 < $wgFeedCacheTimeout
406 ||
wfTimestamp( TS_UNIX
, $feedLastmod )
407 > wfTimestamp( TS_UNIX
, $lastmod ) ) {
408 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
409 $cachedFeed = $messageMemc->get( $key );
411 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
414 if( is_string( $cachedFeed ) ) {
415 wfDebug( "RC: Outputting cached feed\n" );
416 $feed->httpHeaders();
419 wfDebug( "RC: rendering new feed and caching it\n" );
421 rcDoOutputFeed( $rows, $feed );
422 $cachedFeed = ob_get_contents();
425 $expire = 3600 * 24; # One day
426 $messageMemc->set( $key, $cachedFeed );
427 $messageMemc->set( $timekey, wfTimestamp( TS_MW
), $expire );
434 * @param $rows Database resource with recentchanges rows
436 function rcDoOutputFeed( $rows, &$feed ) {
437 wfProfileIn( __METHOD__
);
441 # Merge adjacent edits by one user
444 foreach( $rows as $obj ) {
446 $obj->rc_namespace
>= 0 &&
447 $obj->rc_cur_id
== $sorted[$n-1]->rc_cur_id
&&
448 $obj->rc_user_text
== $sorted[$n-1]->rc_user_text
) {
449 $sorted[$n-1]->rc_last_oldid
= $obj->rc_last_oldid
;
456 foreach( $sorted as $obj ) {
457 $title = Title
::makeTitle( $obj->rc_namespace
, $obj->rc_title
);
458 $talkpage = $title->getTalkPage();
459 $item = new FeedItem(
460 $title->getPrefixedText(),
461 rcFormatDiff( $obj ),
462 $title->getFullURL( 'diff=' . $obj->rc_this_oldid
. '&oldid=prev' ),
464 ($obj->rc_deleted
& Revision
::DELETED_USER
) ?
wfMsgHtml('rev-deleted-user') : $obj->rc_user_text
,
465 $talkpage->getFullURL()
467 $feed->outItem( $item );
470 wfProfileOut( __METHOD__
);
476 function rcCountLink( $lim, $d, $page='Recentchanges', $more='', $active = false ) {
477 global $wgUser, $wgLang, $wgContLang;
478 $sk = $wgUser->getSkin();
479 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
480 ($lim ?
$wgLang->formatNum( "{$lim}" ) : wfMsg( 'recentchangesall' ) ), "{$more}" .
481 ($d ?
"days={$d}&" : '') . 'limit='.$lim, '', '',
482 $active ?
'style="font-weight: bold;"' : '' );
489 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='', $active = false ) {
490 global $wgUser, $wgLang, $wgContLang;
491 $sk = $wgUser->getSkin();
492 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
493 ($d ?
$wgLang->formatNum( "{$d}" ) : wfMsg( 'recentchangesall' ) ), $more.'days='.$d .
494 ($lim ?
'&limit='.$lim : ''), '', '',
495 $active ?
'style="font-weight: bold;"' : '' );
500 * Used by Recentchangeslinked
502 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
503 $botLink = '', $liuLink = '', $patrLink = '', $myselfLink = '' ) {
504 global $wgRCLinkLimits, $wgRCLinkDays;
505 if ($more != '') $more .= '&';
507 # Sort data for display and make sure it's unique after we've added user data.
508 # FIXME: why does this piss around with globals like this? Why is $limit added on globally?
509 $wgRCLinkLimits[] = $limit;
510 $wgRCLinkDays[] = $days;
511 sort($wgRCLinkLimits);
513 $wgRCLinkLimits = array_unique($wgRCLinkLimits);
514 $wgRCLinkDays = array_unique($wgRCLinkDays);
517 foreach( $wgRCLinkLimits as $countLink ) {
518 $cl[] = rcCountLink( $countLink, $days, $page, $more, $countLink == $limit );
520 if( $doall ) $cl[] = rcCountLink( 0, $days, $page, $more );
521 $cl = implode( ' | ', $cl);
524 foreach( $wgRCLinkDays as $daysLink ) {
525 $dl[] = rcDaysLink( $limit, $daysLink, $page, $more, $daysLink == $days );
527 if( $doall ) $dl[] = rcDaysLink( $limit, 0, $page, $more );
528 $dl = implode( ' | ', $dl);
530 $linkParts = array( 'minorLink' => 'minor', 'botLink' => 'bots', 'liuLink' => 'liu', 'patrLink' => 'patr', 'myselfLink' => 'mine' );
531 foreach( $linkParts as $linkVar => $linkMsg ) {
532 if( $
$linkVar != '' )
533 $links[] = wfMsgHtml( 'rcshowhide' . $linkMsg, $
$linkVar );
536 $shm = implode( ' | ', $links );
537 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
543 * Makes change an option link which carries all the other options
544 * @param $title see Title
548 function makeOptionsLink( $title, $override, $options, $active = false ) {
549 global $wgUser, $wgContLang;
550 $sk = $wgUser->getSkin();
551 return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
552 htmlspecialchars( $title ), wfArrayToCGI( $override, $options ), '', '',
553 $active ?
'style="font-weight: bold;"' : '' );
557 * Creates the options panel.
559 * @param $nondefaults
561 function rcOptionsPanel( $defaults, $nondefaults ) {
562 global $wgLang, $wgUser, $wgRCLinkLimits, $wgRCLinkDays;
564 $options = $nondefaults +
$defaults;
566 if( $options['from'] )
567 $note = wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
568 $wgLang->formatNum( $options['limit'] ),
569 $wgLang->timeanddate( $options['from'], true ) );
571 $note = wfMsgExt( 'rcnote', array( 'parseinline' ),
572 $wgLang->formatNum( $options['limit'] ),
573 $wgLang->formatNum( $options['days'] ),
574 $wgLang->timeAndDate( wfTimestampNow(), true ) );
576 # Sort data for display and make sure it's unique after we've added user data.
577 $wgRCLinkLimits[] = $options['limit'];
578 $wgRCLinkDays[] = $options['days'];
579 sort($wgRCLinkLimits);
581 $wgRCLinkLimits = array_unique($wgRCLinkLimits);
582 $wgRCLinkDays = array_unique($wgRCLinkDays);
585 foreach( $wgRCLinkLimits as $value ) {
586 $cl[] = makeOptionsLink( $wgLang->formatNum( $value ),
587 array( 'limit' => $value ), $nondefaults, $value == $options['limit'] ) ;
589 $cl = implode( ' | ', $cl);
591 // day links, reset 'from' to none
592 foreach( $wgRCLinkDays as $value ) {
593 $dl[] = makeOptionsLink( $wgLang->formatNum( $value ),
594 array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] ) ;
596 $dl = implode( ' | ', $dl);
600 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
601 $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
602 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
603 $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
604 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
605 $anonsLink = makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
606 array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
607 $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
608 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
609 $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
610 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
611 $myselfLink = makeOptionsLink( $showhide[1-$options['hidemyself']],
612 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
614 $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
615 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
616 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
617 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
618 if( $wgUser->useRCPatrol() )
619 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
620 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
621 $hl = implode( ' | ', $links );
623 // show from this onward link
624 $now = $wgLang->timeanddate( wfTimestampNow(), true );
625 $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
627 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter'),
629 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter'), $tl );
630 return "$note<br />$rclinks<br />$rclistfrom";
635 * Creates the choose namespace selection
639 * @param $namespace Mixed: the key of the currently selected namespace, empty string
641 * @param $invert Bool: whether to invert the namespace selection
642 * @param $nondefaults Array: an array of non default options to be remembered
643 * @param $categories_any Bool: Default value for the checkbox
647 function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
648 global $wgScript, $wgAllowCategorizedRecentChanges, $wgRequest;
649 $t = SpecialPage
::getTitleFor( 'Recentchanges' );
651 $namespaceselect = HTMLnamespaceselector($namespace, '');
652 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
653 $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ?
' checked="checked"' : '' ) . ' />';
655 if ( $wgAllowCategorizedRecentChanges ) {
656 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
657 $cb_arr = array( 'type' => 'checkbox', 'name' => 'categories_any', 'value' => "1" ) ;
658 if ( $categories_any ) $cb_arr['checked'] = "checked" ;
660 $catbox .= wfMsgExt('rc_categories', array('parseinline')) . " ";
661 $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
662 $catbox .= " " ;
663 $catbox .= wfElement('input', $cb_arr );
664 $catbox .= wfMsgExt('rc_categories_any', array('parseinline'));
669 $out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
671 foreach ( $nondefaults as $key => $value ) {
672 if ($key != 'namespace' && $key != 'invert')
673 $out .= wfElement('input', array( 'type' => 'hidden', 'name' => $key, 'value' => $value));
676 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
678 <div id='nsselect' class='recentchanges'>
679 <label for='namespace'>" . wfMsgHtml('namespace') . "</label>
680 {$namespaceselect}{$submitbutton}{$invertbox} <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>{$catbox}\n</div>";
681 $out .= '</form></div>';
687 * Format a diff for the newsfeed
689 function rcFormatDiff( $row ) {
692 $titleObj = Title
::makeTitle( $row->rc_namespace
, $row->rc_title
);
693 $timestamp = wfTimestamp( TS_MW
, $row->rc_timestamp
);
695 if( $row->rc_type
== RC_LOG
) {
696 if( $row->rc_deleted
& LogPage
::DELETED_ACTION
) {
697 $actiontext = wfMsgHtml('rev-deleted-event');
699 $actiontext = LogPage
::actionText( $row->rc_log_type
, $row->rc_log_action
,
700 $titleObj, $wgUser->getSkin(), LogPage
::extractParams($row->rc_params
,true,true) );
703 return rcFormatDiffRow( $titleObj,
704 $row->rc_last_oldid
, $row->rc_this_oldid
,
706 ($row->rc_deleted
& Revision
::DELETED_COMMENT
) ?
wfMsgHtml('rev-deleted-comment') : $row->rc_comment
,
710 function rcFormatDiffRow( $title, $oldid, $newid, $timestamp, $comment, $actiontext='' ) {
711 global $wgFeedDiffCutoff, $wgContLang, $wgUser;
712 wfProfileIn( __FUNCTION__
);
714 $skin = $wgUser->getSkin();
717 $comment = "$actiontext $comment";
719 $completeText = '<p>' . $skin->formatComment( $comment ) . "</p>\n";
721 //NOTE: Check permissions for anonymous users, not current user.
722 // No "privileged" version should end up in the cache.
723 // Most feed readers will not log in anway.
725 $accErrors = $title->getUserPermissionsErrors( 'read', $anon, true );
727 if( $title->getNamespace() >= 0 && !$accErrors ) {
729 wfProfileIn( __FUNCTION__
."-dodiff" );
731 $de = new DifferenceEngine( $title, $oldid, $newid );
732 #$diffText = $de->getDiff( wfMsg( 'revisionasof',
733 # $wgContLang->timeanddate( $timestamp ) ),
734 # wfMsg( 'currentrev' ) );
735 $diffText = $de->getDiff(
736 wfMsg( 'previousrevision' ), // hack
737 wfMsg( 'revisionasof',
738 $wgContLang->timeanddate( $timestamp ) ) );
741 if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
743 $diffLink = $title->escapeFullUrl(
745 '&oldid=' . $oldid );
746 $diffText = '<a href="' .
749 htmlspecialchars( wfMsgForContent( 'difference' ) ) .
751 } elseif ( $diffText === false ) {
752 // Error in diff engine, probably a missing revision
753 $diffText = "<p>Can't load revision $newid</p>";
755 // Diff output fine, clean up any illegal UTF-8
756 $diffText = UtfNormal
::cleanUp( $diffText );
757 $diffText = rcApplyDiffStyle( $diffText );
759 wfProfileOut( __FUNCTION__
."-dodiff" );
761 $rev = Revision
::newFromId( $newid );
762 if( is_null( $rev ) ) {
765 $newtext = $rev->getText();
767 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
768 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
770 $completeText .= $diffText;
773 wfProfileOut( __FUNCTION__
);
774 return $completeText;
778 * Hacky application of diff styles for the feeds.
779 * Might be 'cleaner' to use DOM or XSLT or something,
780 * but *gack* it's a pain in the ass.
782 * @param $text String:
786 function rcApplyDiffStyle( $text ) {
788 'diff' => 'background-color: white; color:black;',
789 'diff-otitle' => 'background-color: white; color:black;',
790 'diff-ntitle' => 'background-color: white; color:black;',
791 'diff-addedline' => 'background: #cfc; color:black; font-size: smaller;',
792 'diff-deletedline' => 'background: #ffa; color:black; font-size: smaller;',
793 'diff-context' => 'background: #eee; color:black; font-size: smaller;',
794 'diffchange' => 'color: red; font-weight: bold; text-decoration: none;',
797 foreach( $styles as $class => $style ) {
798 $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
799 "\\1style=\"$style\"\\3", $text );