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 ;
19 $fname = 'wfSpecialRecentchanges';
21 # Get query parameters
22 $feedFormat = $wgRequest->getVal( 'feed' );
24 /* Checkbox values can't be true by default, because
25 * we cannot differentiate between unset and not set at all
28 /* int */ 'days' => $wgUser->getDefaultOption('rcdays'),
29 /* int */ 'limit' => $wgUser->getDefaultOption('rclimit'),
30 /* bool */ 'hideminor' => false,
31 /* bool */ 'hidebots' => true,
32 /* bool */ 'hideanons' => false,
33 /* bool */ 'hideliu' => false,
34 /* bool */ 'hidepatrolled' => false,
35 /* bool */ 'hidemyself' => false,
36 /* text */ 'from' => '',
37 /* text */ 'namespace' => null,
38 /* bool */ 'invert' => false,
39 /* bool */ 'categories_any' => false,
45 $days = $wgUser->getOption( 'rcdays', $defaults['days']);
46 $days = $wgRequest->getInt( 'days', $days );
48 $limit = $wgUser->getOption( 'rclimit', $defaults['limit'] );
50 # list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
51 $limit = $wgRequest->getInt( 'limit', $limit );
53 /* order of selection: url > preferences > default */
54 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor') ?
true : $defaults['hideminor'] );
56 # As a feed, use limited settings only
59 $limit = min( $wgFeedLimit, $limit );
62 $namespace = $wgRequest->getIntOrNull( 'namespace' );
63 $invert = $wgRequest->getBool( 'invert', $defaults['invert'] );
64 $hidebots = $wgRequest->getBool( 'hidebots', $defaults['hidebots'] );
65 $hideanons = $wgRequest->getBool( 'hideanons', $defaults['hideanons'] );
66 $hideliu = $wgRequest->getBool( 'hideliu', $defaults['hideliu'] );
67 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', $defaults['hidepatrolled'] );
68 $hidemyself = $wgRequest->getBool ( 'hidemyself', $defaults['hidemyself'] );
69 $from = $wgRequest->getVal( 'from', $defaults['from'] );
71 # Get query parameters from path
73 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
74 foreach ( $bits as $bit ) {
75 if ( 'hidebots' == $bit ) $hidebots = 1;
76 if ( 'bots' == $bit ) $hidebots = 0;
77 if ( 'hideminor' == $bit ) $hideminor = 1;
78 if ( 'minor' == $bit ) $hideminor = 0;
79 if ( 'hideliu' == $bit ) $hideliu = 1;
80 if ( 'hidepatrolled' == $bit ) $hidepatrolled = 1;
81 if ( 'hideanons' == $bit ) $hideanons = 1;
82 if ( 'hidemyself' == $bit ) $hidemyself = 1;
84 if ( is_numeric( $bit ) ) {
89 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
93 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
100 if ( $limit < 0 ||
$limit > 5000 ) $limit = $defaults['limit'];
102 # Database connection and caching
103 $dbr = wfGetDB( DB_SLAVE
);
105 $cutoff_unixtime = time() - ( $days * 86400 );
106 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime %
86400);
107 $cutoff = $dbr->timestamp( $cutoff_unixtime );
108 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW
,$cutoff)) {
109 $cutoff = $dbr->timestamp($from);
111 $from = $defaults['from'];
114 # 10 seconds server-side caching max
115 $wgOut->setSquidMaxage( 10 );
117 # Get last modified date, for client caching
118 # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
119 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
120 if ( $feedFormat ||
!$wgUseRCPatrol ) {
121 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
122 # Client cache fresh and headers sent, nothing more to do.
127 # It makes no sense to hide both anons and logged-in users
128 # Where this occurs, force anons to be shown
130 if( $hideanons && $hideliu ){
131 # Check if the user wants to show bots only
140 # Form WHERE fragments for all the options
141 $hidem = $hideminor ?
'AND rc_minor = 0' : '';
142 $hidem .= $hidebots ?
' AND rc_bot = 0' : '';
143 $hidem .= $hideliu && !$forcebot ?
' AND rc_user = 0' : '';
144 $hidem .= ($wgUser->useRCPatrol() && $hidepatrolled ) ?
' AND rc_patrolled = 0' : '';
145 $hidem .= $hideanons && !$forcebot ?
' AND rc_user != 0' : '';
146 $hidem .= $forcebot ?
' AND rc_bot = 1' : '';
149 if( $wgUser->getId() ) {
150 $hidem .= ' AND rc_user != ' . $wgUser->getId();
152 $hidem .= ' AND rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() );
156 // JOIN on watchlist for users
157 $uid = $wgUser->getId();
159 $tables = array( 'recentchanges', 'watchlist' );
160 $join_conds = array( 'watchlist' => array('LEFT JOIN',"wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace") );
162 $tables = array( 'recentchanges' );
163 $join_conds = array();
166 # Namespace filtering
167 $hidem .= is_null($namespace) ?
'' : ' AND rc_namespace' . ($invert ?
'!=' : '=') . $namespace;
169 // Is there either one namespace selected or excluded?
170 // Also, if this is "all" or main namespace, just use timestamp index.
171 if( is_null($namespace) ||
$invert ||
$namespace == NS_MAIN
) {
172 $res = $dbr->select( $tables, '*',
173 array( "rc_timestamp >= '{$cutoff}' {$hidem}" ),
175 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
176 'USE INDEX' => array('recentchanges' => 'rc_timestamp') ),
178 // We have a new_namespace_time index! UNION over new=(0,1) and sort result set!
181 $sqlNew = $dbr->selectSQLText( $tables, '*',
182 array( 'rc_new' => 1,
183 "rc_timestamp >= '{$cutoff}' {$hidem}" ),
185 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
186 'USE INDEX' => array('recentchanges' => 'new_name_timestamp') ),
189 $sqlOld = $dbr->selectSQLText( $tables, '*',
190 array( 'rc_new' => 0,
191 "rc_timestamp >= '{$cutoff}' {$hidem}" ),
193 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
194 'USE INDEX' => array('recentchanges' => 'new_name_timestamp') ),
196 # Join the two fast queries, and sort the result set
197 $sql = "($sqlNew) UNION ($sqlOld) ORDER BY rc_timestamp DESC LIMIT $limit";
198 $res = $dbr->query( $sql, __METHOD__
);
201 // Fetch results, prepare a batch link existence check query
203 $batch = new LinkBatch
;
204 while( $row = $dbr->fetchObject( $res ) ){
206 if ( !$feedFormat ) {
207 // User page and talk links
208 $batch->add( NS_USER
, $row->rc_user_text
);
209 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
213 $dbr->freeResult( $res );
216 rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod );
221 // Run existence checks
223 $any = $wgRequest->getBool( 'categories_any', $defaults['categories_any']);
226 if ( !$specialPage->including() ) {
227 $wgOut->addWikiText( wfMsgForContentNoTrans( "recentchangestext" ) );
229 // Dump everything here
230 $nondefaults = array();
232 wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults);
233 wfAppendToArrayIfNotDefault( 'limit', $limit , $defaults, $nondefaults);
234 wfAppendToArrayIfNotDefault( 'hideminor', $hideminor, $defaults, $nondefaults);
235 wfAppendToArrayIfNotDefault( 'hidebots', $hidebots, $defaults, $nondefaults);
236 wfAppendToArrayIfNotDefault( 'hideanons', $hideanons, $defaults, $nondefaults );
237 wfAppendToArrayIfNotDefault( 'hideliu', $hideliu, $defaults, $nondefaults);
238 wfAppendToArrayIfNotDefault( 'hidepatrolled', $hidepatrolled, $defaults, $nondefaults);
239 wfAppendToArrayIfNotDefault( 'hidemyself', $hidemyself, $defaults, $nondefaults);
240 wfAppendToArrayIfNotDefault( 'from', $from, $defaults, $nondefaults);
241 wfAppendToArrayIfNotDefault( 'namespace', $namespace, $defaults, $nondefaults);
242 wfAppendToArrayIfNotDefault( 'invert', $invert, $defaults, $nondefaults);
243 wfAppendToArrayIfNotDefault( 'categories_any', $any, $defaults, $nondefaults);
245 // Add end of the texts
246 $wgOut->addHTML( '<div class="rcoptions">' . rcOptionsPanel( $defaults, $nondefaults ) . "\n" );
247 $wgOut->addHTML( rcNamespaceForm( $namespace, $invert, $nondefaults, $any ) . '</div>'."\n");
250 // And now for the content
251 $wgOut->setSyndicated( true );
253 $list = ChangesList
::newFromUser( $wgUser );
255 if ( $wgAllowCategorizedRecentChanges ) {
256 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
257 $categories = str_replace ( "|" , "\n" , $categories ) ;
258 $categories = explode ( "\n" , $categories ) ;
259 rcFilterByCategories ( $rows , $categories , $any ) ;
262 $s = $list->beginRecentChangesList();
265 $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' );
266 $watcherCache = array();
268 foreach( $rows as $obj ){
273 if ( ! ( $hideminor && $obj->rc_minor
) &&
274 ! ( $hidepatrolled && $obj->rc_patrolled
) ) {
275 $rc = RecentChange
::newFromRow( $obj );
276 $rc->counter
= $counter++
;
278 if ($wgShowUpdatedMarker
279 && !empty( $obj->wl_notificationtimestamp
)
280 && ($obj->rc_timestamp
>= $obj->wl_notificationtimestamp
)) {
281 $rc->notificationtimestamp
= true;
283 $rc->notificationtimestamp
= false;
286 $rc->numberofWatchingusers
= 0; // Default
287 if ($showWatcherCount && $obj->rc_namespace
>= 0) {
288 if (!isset($watcherCache[$obj->rc_namespace
][$obj->rc_title
])) {
289 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
290 $dbr->selectField( 'watchlist',
293 'wl_namespace' => $obj->rc_namespace
,
294 'wl_title' => $obj->rc_title
,
296 __METHOD__
. '-watchers' );
298 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
300 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user
) );
304 $s .= $list->endRecentChangesList();
305 $wgOut->addHTML( $s );
309 function rcFilterByCategories ( &$rows , $categories , $any ) {
310 if( empty( $categories ) ) {
316 foreach ( $categories AS $cat ) {
317 $cat = trim ( $cat ) ;
318 if ( $cat == "" ) continue ;
323 $articles = array () ;
325 foreach ( $rows AS $k => $r ) {
326 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
327 $id = $nt->getArticleID() ;
328 if ( $id == 0 ) continue ; # Page might have been deleted...
329 if ( !in_array ( $id , $articles ) ) {
332 if ( !isset ( $a2r[$id] ) ) {
333 $a2r[$id] = array() ;
339 if ( count ( $articles ) == 0 OR count ( $cats ) == 0 )
343 $c = new Categoryfinder
;
344 $c->seed ( $articles , $cats , $any ?
"OR" : "AND" ) ;
345 $match = $c->run () ;
348 $newrows = array () ;
349 foreach ( $match AS $id ) {
350 foreach ( $a2r[$id] AS $rev ) {
352 $newrows[$k] = $rows[$k] ;
358 function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
359 global $messageMemc, $wgFeedCacheTimeout;
360 global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
365 $wgOut->addWikiMsg( 'feed-unavailable' );
369 if( !isset( $wgFeedClasses[$feedFormat] ) ) {
370 wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
374 $timekey = wfMemcKey( 'rcfeed', $feedFormat, 'timestamp' );
375 $key = wfMemcKey( 'rcfeed', $feedFormat, 'limit', $limit, 'minor', $hideminor );
377 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchanges' ) .
378 ' [' . $wgContLanguageCode . ']';
379 $feed = new $wgFeedClasses[$feedFormat](
381 htmlspecialchars( wfMsgForContent( 'recentchanges-feed-description' ) ),
382 $wgTitle->getFullUrl() );
384 //purge cache if requested
385 global $wgRequest, $wgUser;
386 $purge = $wgRequest->getVal( 'action' ) == 'purge';
387 if ( $purge && $wgUser->isAllowed('purge') ) {
388 $messageMemc->delete( $timekey );
389 $messageMemc->delete( $key );
393 * Bumping around loading up diffs can be pretty slow, so where
394 * possible we want to cache the feed output so the next visitor
398 if( ( $wgFeedCacheTimeout > 0 ) && ( $feedLastmod = $messageMemc->get( $timekey ) ) ) {
400 * If the cached feed was rendered very recently, we may
401 * go ahead and use it even if there have been edits made
402 * since it was rendered. This keeps a swarm of requests
403 * from being too bad on a super-frequently edited wiki.
405 if( time() - wfTimestamp( TS_UNIX
, $feedLastmod )
406 < $wgFeedCacheTimeout
407 ||
wfTimestamp( TS_UNIX
, $feedLastmod )
408 > wfTimestamp( TS_UNIX
, $lastmod ) ) {
409 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
410 $cachedFeed = $messageMemc->get( $key );
412 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
415 if( is_string( $cachedFeed ) ) {
416 wfDebug( "RC: Outputting cached feed\n" );
417 $feed->httpHeaders();
420 wfDebug( "RC: rendering new feed and caching it\n" );
422 rcDoOutputFeed( $rows, $feed );
423 $cachedFeed = ob_get_contents();
426 $expire = 3600 * 24; # One day
427 $messageMemc->set( $key, $cachedFeed );
428 $messageMemc->set( $timekey, wfTimestamp( TS_MW
), $expire );
435 * @param $rows Database resource with recentchanges rows
437 function rcDoOutputFeed( $rows, &$feed ) {
438 wfProfileIn( __METHOD__
);
442 # Merge adjacent edits by one user
445 foreach( $rows as $obj ) {
447 $obj->rc_namespace
>= 0 &&
448 $obj->rc_cur_id
== $sorted[$n-1]->rc_cur_id
&&
449 $obj->rc_user_text
== $sorted[$n-1]->rc_user_text
) {
450 $sorted[$n-1]->rc_last_oldid
= $obj->rc_last_oldid
;
457 foreach( $sorted as $obj ) {
458 $title = Title
::makeTitle( $obj->rc_namespace
, $obj->rc_title
);
459 $talkpage = $title->getTalkPage();
460 $item = new FeedItem(
461 $title->getPrefixedText(),
462 rcFormatDiff( $obj ),
463 $title->getFullURL( 'diff=' . $obj->rc_this_oldid
. '&oldid=prev' ),
465 ($obj->rc_deleted
& Revision
::DELETED_USER
) ?
wfMsgHtml('rev-deleted-user') : $obj->rc_user_text
,
466 $talkpage->getFullURL()
468 $feed->outItem( $item );
471 wfProfileOut( __METHOD__
);
477 function rcCountLink( $lim, $d, $page='Recentchanges', $more='', $active = false ) {
478 global $wgUser, $wgLang, $wgContLang;
479 $sk = $wgUser->getSkin();
480 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
481 ($lim ?
$wgLang->formatNum( "{$lim}" ) : wfMsg( 'recentchangesall' ) ), "{$more}" .
482 ($d ?
"days={$d}&" : '') . 'limit='.$lim, '', '',
483 $active ?
'style="font-weight: bold;"' : '' );
490 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='', $active = false ) {
491 global $wgUser, $wgLang, $wgContLang;
492 $sk = $wgUser->getSkin();
493 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
494 ($d ?
$wgLang->formatNum( "{$d}" ) : wfMsg( 'recentchangesall' ) ), $more.'days='.$d .
495 ($lim ?
'&limit='.$lim : ''), '', '',
496 $active ?
'style="font-weight: bold;"' : '' );
501 * Used by Recentchangeslinked
503 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
504 $botLink = '', $liuLink = '', $patrLink = '', $myselfLink = '' ) {
505 global $wgRCLinkLimits, $wgRCLinkDays;
506 if ($more != '') $more .= '&';
508 # Sort data for display and make sure it's unique after we've added user data.
509 # FIXME: why does this piss around with globals like this? Why is $limit added on globally?
510 $wgRCLinkLimits[] = $limit;
511 $wgRCLinkDays[] = $days;
512 sort($wgRCLinkLimits);
514 $wgRCLinkLimits = array_unique($wgRCLinkLimits);
515 $wgRCLinkDays = array_unique($wgRCLinkDays);
518 foreach( $wgRCLinkLimits as $countLink ) {
519 $cl[] = rcCountLink( $countLink, $days, $page, $more, $countLink == $limit );
521 if( $doall ) $cl[] = rcCountLink( 0, $days, $page, $more );
522 $cl = implode( ' | ', $cl);
525 foreach( $wgRCLinkDays as $daysLink ) {
526 $dl[] = rcDaysLink( $limit, $daysLink, $page, $more, $daysLink == $days );
528 if( $doall ) $dl[] = rcDaysLink( $limit, 0, $page, $more );
529 $dl = implode( ' | ', $dl);
531 $linkParts = array( 'minorLink' => 'minor', 'botLink' => 'bots', 'liuLink' => 'liu', 'patrLink' => 'patr', 'myselfLink' => 'mine' );
532 foreach( $linkParts as $linkVar => $linkMsg ) {
533 if( $
$linkVar != '' )
534 $links[] = wfMsgHtml( 'rcshowhide' . $linkMsg, $
$linkVar );
537 $shm = implode( ' | ', $links );
538 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
544 * Makes change an option link which carries all the other options
545 * @param $title see Title
549 function makeOptionsLink( $title, $override, $options, $active = false ) {
550 global $wgUser, $wgContLang;
551 $sk = $wgUser->getSkin();
552 return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
553 htmlspecialchars( $title ), wfArrayToCGI( $override, $options ), '', '',
554 $active ?
'style="font-weight: bold;"' : '' );
558 * Creates the options panel.
560 * @param $nondefaults
562 function rcOptionsPanel( $defaults, $nondefaults ) {
563 global $wgLang, $wgUser, $wgRCLinkLimits, $wgRCLinkDays;
565 $options = $nondefaults +
$defaults;
567 if( $options['from'] )
568 $note = wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
569 $wgLang->formatNum( $options['limit'] ),
570 $wgLang->timeanddate( $options['from'], true ) );
572 $note = wfMsgExt( 'rcnote', array( 'parseinline' ),
573 $wgLang->formatNum( $options['limit'] ),
574 $wgLang->formatNum( $options['days'] ),
575 $wgLang->timeAndDate( wfTimestampNow(), true ) );
577 # Sort data for display and make sure it's unique after we've added user data.
578 $wgRCLinkLimits[] = $options['limit'];
579 $wgRCLinkDays[] = $options['days'];
580 sort($wgRCLinkLimits);
582 $wgRCLinkLimits = array_unique($wgRCLinkLimits);
583 $wgRCLinkDays = array_unique($wgRCLinkDays);
586 foreach( $wgRCLinkLimits as $value ) {
587 $cl[] = makeOptionsLink( $wgLang->formatNum( $value ),
588 array( 'limit' => $value ), $nondefaults, $value == $options['limit'] ) ;
590 $cl = implode( ' | ', $cl);
592 // day links, reset 'from' to none
593 foreach( $wgRCLinkDays as $value ) {
594 $dl[] = makeOptionsLink( $wgLang->formatNum( $value ),
595 array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] ) ;
597 $dl = implode( ' | ', $dl);
601 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
602 $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
603 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
604 $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
605 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
606 $anonsLink = makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
607 array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
608 $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
609 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
610 $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
611 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
612 $myselfLink = makeOptionsLink( $showhide[1-$options['hidemyself']],
613 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
615 $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
616 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
617 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
618 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
619 if( $wgUser->useRCPatrol() )
620 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
621 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
622 $hl = implode( ' | ', $links );
624 // show from this onward link
625 $now = $wgLang->timeanddate( wfTimestampNow(), true );
626 $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
628 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter'),
630 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter'), $tl );
631 return "$note<br />$rclinks<br />$rclistfrom";
636 * Creates the choose namespace selection
640 * @param $namespace Mixed: the key of the currently selected namespace, empty string
642 * @param $invert Bool: whether to invert the namespace selection
643 * @param $nondefaults Array: an array of non default options to be remembered
644 * @param $categories_any Bool: Default value for the checkbox
648 function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
649 global $wgScript, $wgAllowCategorizedRecentChanges, $wgRequest;
650 $t = SpecialPage
::getTitleFor( 'Recentchanges' );
652 $namespaceselect = HTMLnamespaceselector($namespace, '');
653 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
654 $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ?
' checked="checked"' : '' ) . ' />';
656 if ( $wgAllowCategorizedRecentChanges ) {
657 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
658 $cb_arr = array( 'type' => 'checkbox', 'name' => 'categories_any', 'value' => "1" ) ;
659 if ( $categories_any ) $cb_arr['checked'] = "checked" ;
661 $catbox .= wfMsgExt('rc_categories', array('parseinline')) . " ";
662 $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
663 $catbox .= " " ;
664 $catbox .= wfElement('input', $cb_arr );
665 $catbox .= wfMsgExt('rc_categories_any', array('parseinline'));
670 $out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
672 foreach ( $nondefaults as $key => $value ) {
673 if ($key != 'namespace' && $key != 'invert')
674 $out .= wfElement('input', array( 'type' => 'hidden', 'name' => $key, 'value' => $value));
677 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
679 <div id='nsselect' class='recentchanges'>
680 <label for='namespace'>" . wfMsgHtml('namespace') . "</label>
681 {$namespaceselect}{$submitbutton}{$invertbox} <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>{$catbox}\n</div>";
682 $out .= '</form></div>';
688 * Format a diff for the newsfeed
690 function rcFormatDiff( $row ) {
693 $titleObj = Title
::makeTitle( $row->rc_namespace
, $row->rc_title
);
694 $timestamp = wfTimestamp( TS_MW
, $row->rc_timestamp
);
696 if( $row->rc_type
== RC_LOG
) {
697 if( $row->rc_deleted
& LogPage
::DELETED_ACTION
) {
698 $actiontext = wfMsgHtml('rev-deleted-event');
700 $actiontext = LogPage
::actionText( $row->rc_log_type
, $row->rc_log_action
,
701 $titleObj, $wgUser->getSkin(), LogPage
::extractParams($row->rc_params
,true,true) );
704 return rcFormatDiffRow( $titleObj,
705 $row->rc_last_oldid
, $row->rc_this_oldid
,
707 ($row->rc_deleted
& Revision
::DELETED_COMMENT
) ?
wfMsgHtml('rev-deleted-comment') : $row->rc_comment
,
711 function rcFormatDiffRow( $title, $oldid, $newid, $timestamp, $comment, $actiontext='' ) {
712 global $wgFeedDiffCutoff, $wgContLang, $wgUser;
713 $fname = 'rcFormatDiff';
714 wfProfileIn( $fname );
716 $skin = $wgUser->getSkin();
719 $comment = "$actiontext $comment";
721 $completeText = '<p>' . $skin->formatComment( $comment ) . "</p>\n";
723 //NOTE: Check permissions for anonymous users, not current user.
724 // No "privileged" version should end up in the cache.
725 // Most feed readers will not log in anway.
727 $accErrors = $title->getUserPermissionsErrors( 'read', $anon, true );
729 if( $title->getNamespace() >= 0 && !$accErrors ) {
731 wfProfileIn( "$fname-dodiff" );
733 $de = new DifferenceEngine( $title, $oldid, $newid );
734 #$diffText = $de->getDiff( wfMsg( 'revisionasof',
735 # $wgContLang->timeanddate( $timestamp ) ),
736 # wfMsg( 'currentrev' ) );
737 $diffText = $de->getDiff(
738 wfMsg( 'previousrevision' ), // hack
739 wfMsg( 'revisionasof',
740 $wgContLang->timeanddate( $timestamp ) ) );
743 if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
745 $diffLink = $title->escapeFullUrl(
747 '&oldid=' . $oldid );
748 $diffText = '<a href="' .
751 htmlspecialchars( wfMsgForContent( 'difference' ) ) .
753 } elseif ( $diffText === false ) {
754 // Error in diff engine, probably a missing revision
755 $diffText = "<p>Can't load revision $newid</p>";
757 // Diff output fine, clean up any illegal UTF-8
758 $diffText = UtfNormal
::cleanUp( $diffText );
759 $diffText = rcApplyDiffStyle( $diffText );
761 wfProfileOut( "$fname-dodiff" );
763 $rev = Revision
::newFromId( $newid );
764 if( is_null( $rev ) ) {
767 $newtext = $rev->getText();
769 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
770 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
772 $completeText .= $diffText;
775 wfProfileOut( $fname );
776 return $completeText;
780 * Hacky application of diff styles for the feeds.
781 * Might be 'cleaner' to use DOM or XSLT or something,
782 * but *gack* it's a pain in the ass.
784 * @param $text String:
788 function rcApplyDiffStyle( $text ) {
790 'diff' => 'background-color: white; color:black;',
791 'diff-otitle' => 'background-color: white; color:black;',
792 'diff-ntitle' => 'background-color: white; color:black;',
793 'diff-addedline' => 'background: #cfc; color:black; font-size: smaller;',
794 'diff-deletedline' => 'background: #ffa; color:black; font-size: smaller;',
795 'diff-context' => 'background: #eee; color:black; font-size: smaller;',
796 'diffchange' => 'color: red; font-weight: bold; text-decoration: none;',
799 foreach( $styles as $class => $style ) {
800 $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
801 "\\1style=\"$style\"\\3", $text );