Use formatNum for counts on category page.
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
1 <?php
2 /**
3 *
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 *
9 */
10 require_once( dirname(__FILE__) . '/ChangesList.php' );
11
12 /**
13 * Constructor
14 */
15 function wfSpecialRecentchanges( $par, $specialPage ) {
16 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
17 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
18 global $wgAllowCategorizedRecentChanges ;
19 $fname = 'wfSpecialRecentchanges';
20
21 # Get query parameters
22 $feedFormat = $wgRequest->getVal( 'feed' );
23
24 /* Checkbox values can't be true by default, because
25 * we cannot differentiate between unset and not set at all
26 */
27 $defaults = array(
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,
40 );
41
42 extract($defaults);
43
44
45 $days = $wgUser->getOption( 'rcdays', $defaults['days']);
46 $days = $wgRequest->getInt( 'days', $days );
47
48 $limit = $wgUser->getOption( 'rclimit', $defaults['limit'] );
49
50 # list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
51 $limit = $wgRequest->getInt( 'limit', $limit );
52
53 /* order of selection: url > preferences > default */
54 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor') ? true : $defaults['hideminor'] );
55
56 # As a feed, use limited settings only
57 if( $feedFormat ) {
58 global $wgFeedLimit;
59 if( $limit > $wgFeedLimit ) {
60 $limit = $wgFeedLimit;
61 }
62
63 } else {
64
65 $namespace = $wgRequest->getIntOrNull( 'namespace' );
66 $invert = $wgRequest->getBool( 'invert', $defaults['invert'] );
67 $hidebots = $wgRequest->getBool( 'hidebots', $defaults['hidebots'] );
68 $hideanons = $wgRequest->getBool( 'hideanons', $defaults['hideanons'] );
69 $hideliu = $wgRequest->getBool( 'hideliu', $defaults['hideliu'] );
70 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', $defaults['hidepatrolled'] );
71 $hidemyself = $wgRequest->getBool ( 'hidemyself', $defaults['hidemyself'] );
72 $from = $wgRequest->getVal( 'from', $defaults['from'] );
73
74 # Get query parameters from path
75 if( $par ) {
76 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
77 foreach ( $bits as $bit ) {
78 if ( 'hidebots' == $bit ) $hidebots = 1;
79 if ( 'bots' == $bit ) $hidebots = 0;
80 if ( 'hideminor' == $bit ) $hideminor = 1;
81 if ( 'minor' == $bit ) $hideminor = 0;
82 if ( 'hideliu' == $bit ) $hideliu = 1;
83 if ( 'hidepatrolled' == $bit ) $hidepatrolled = 1;
84 if ( 'hideanons' == $bit ) $hideanons = 1;
85 if ( 'hidemyself' == $bit ) $hidemyself = 1;
86
87 if ( is_numeric( $bit ) ) {
88 $limit = $bit;
89 }
90
91 $m = array();
92 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
93 $limit = $m[1];
94 }
95
96 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
97 $days = $m[1];
98 }
99 }
100 }
101 }
102
103 if ( $limit < 0 || $limit > 5000 ) $limit = $defaults['limit'];
104
105
106 # Database connection and caching
107 $dbr = wfGetDB( DB_SLAVE );
108 list( $recentchanges, $watchlist ) = $dbr->tableNamesN( 'recentchanges', 'watchlist' );
109
110
111 $cutoff_unixtime = time() - ( $days * 86400 );
112 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
113 $cutoff = $dbr->timestamp( $cutoff_unixtime );
114 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW,$cutoff)) {
115 $cutoff = $dbr->timestamp($from);
116 } else {
117 $from = $defaults['from'];
118 }
119
120 # 10 seconds server-side caching max
121 $wgOut->setSquidMaxage( 10 );
122
123 # Get last modified date, for client caching
124 # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
125 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
126 if ( $feedFormat || !$wgUseRCPatrol ) {
127 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
128 # Client cache fresh and headers sent, nothing more to do.
129 return;
130 }
131 }
132
133 # It makes no sense to hide both anons and logged-in users
134 # Where this occurs, force anons to be shown
135 if( $hideanons && $hideliu )
136 $hideanons = false;
137
138 # Form WHERE fragments for all the options
139 $hidem = $hideminor ? 'AND rc_minor = 0' : '';
140 $hidem .= $hidebots ? ' AND rc_bot = 0' : '';
141 $hidem .= $hideliu ? ' AND rc_user = 0' : '';
142 $hidem .= ( $wgUseRCPatrol && $hidepatrolled ) ? ' AND rc_patrolled = 0' : '';
143 $hidem .= $hideanons ? ' AND rc_user != 0' : '';
144
145 if( $hidemyself ) {
146 if( $wgUser->getID() ) {
147 $hidem .= ' AND rc_user != ' . $wgUser->getID();
148 } else {
149 $hidem .= ' AND rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() );
150 }
151 }
152
153 # Namespace filtering
154 $hidem .= is_null( $namespace ) ? '' : ' AND rc_namespace' . ($invert ? '!=' : '=') . $namespace;
155
156 // This is the big thing!
157
158 $uid = $wgUser->getID();
159
160 // Perform query
161 $forceclause = $dbr->useIndexClause("rc_timestamp");
162 $sql2 = "SELECT * FROM $recentchanges $forceclause".
163 ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") .
164 "WHERE rc_timestamp >= '{$cutoff}' {$hidem} " .
165 "ORDER BY rc_timestamp DESC";
166 $sql2 = $dbr->limitResult($sql2, $limit, 0);
167 $res = $dbr->query( $sql2, $fname );
168
169 // Fetch results, prepare a batch link existence check query
170 $rows = array();
171 $batch = new LinkBatch;
172 while( $row = $dbr->fetchObject( $res ) ){
173 $rows[] = $row;
174 if ( !$feedFormat ) {
175 // User page and talk links
176 $batch->add( NS_USER, $row->rc_user_text );
177 $batch->add( NS_USER_TALK, $row->rc_user_text );
178 }
179
180 }
181 $dbr->freeResult( $res );
182
183 if( $feedFormat ) {
184 rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod );
185 } else {
186
187 # Web output...
188
189 // Run existence checks
190 $batch->execute();
191 $any = $wgRequest->getBool( 'categories_any', $defaults['categories_any']);
192
193 // Output header
194 if ( !$specialPage->including() ) {
195 $wgOut->addWikiText( wfMsgForContentNoTrans( "recentchangestext" ) );
196
197 // Dump everything here
198 $nondefaults = array();
199
200 wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults);
201 wfAppendToArrayIfNotDefault( 'limit', $limit , $defaults, $nondefaults);
202 wfAppendToArrayIfNotDefault( 'hideminor', $hideminor, $defaults, $nondefaults);
203 wfAppendToArrayIfNotDefault( 'hidebots', $hidebots, $defaults, $nondefaults);
204 wfAppendToArrayIfNotDefault( 'hideanons', $hideanons, $defaults, $nondefaults );
205 wfAppendToArrayIfNotDefault( 'hideliu', $hideliu, $defaults, $nondefaults);
206 wfAppendToArrayIfNotDefault( 'hidepatrolled', $hidepatrolled, $defaults, $nondefaults);
207 wfAppendToArrayIfNotDefault( 'hidemyself', $hidemyself, $defaults, $nondefaults);
208 wfAppendToArrayIfNotDefault( 'from', $from, $defaults, $nondefaults);
209 wfAppendToArrayIfNotDefault( 'namespace', $namespace, $defaults, $nondefaults);
210 wfAppendToArrayIfNotDefault( 'invert', $invert, $defaults, $nondefaults);
211 wfAppendToArrayIfNotDefault( 'categories_any', $any, $defaults, $nondefaults);
212
213 // Add end of the texts
214 $wgOut->addHTML( '<div class="rcoptions">' . rcOptionsPanel( $defaults, $nondefaults ) . "\n" );
215 $wgOut->addHTML( rcNamespaceForm( $namespace, $invert, $nondefaults, $any ) . '</div>'."\n");
216 }
217
218 // And now for the content
219 $wgOut->setSyndicated( true );
220
221 $list = ChangesList::newFromUser( $wgUser );
222
223 if ( $wgAllowCategorizedRecentChanges ) {
224 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
225 $categories = str_replace ( "|" , "\n" , $categories ) ;
226 $categories = explode ( "\n" , $categories ) ;
227 rcFilterByCategories ( $rows , $categories , $any ) ;
228 }
229
230 $s = $list->beginRecentChangesList();
231 $counter = 1;
232
233 $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' );
234 $watcherCache = array();
235
236 foreach( $rows as $obj ){
237 if( $limit == 0) {
238 break;
239 }
240
241 if ( ! ( $hideminor && $obj->rc_minor ) &&
242 ! ( $hidepatrolled && $obj->rc_patrolled ) ) {
243 $rc = RecentChange::newFromRow( $obj );
244 $rc->counter = $counter++;
245
246 if ($wgShowUpdatedMarker
247 && !empty( $obj->wl_notificationtimestamp )
248 && ($obj->rc_timestamp >= $obj->wl_notificationtimestamp)) {
249 $rc->notificationtimestamp = true;
250 } else {
251 $rc->notificationtimestamp = false;
252 }
253
254 $rc->numberofWatchingusers = 0; // Default
255 if ($showWatcherCount && $obj->rc_namespace >= 0) {
256 if (!isset($watcherCache[$obj->rc_namespace][$obj->rc_title])) {
257 $watcherCache[$obj->rc_namespace][$obj->rc_title] =
258 $dbr->selectField( 'watchlist',
259 'COUNT(*)',
260 array(
261 'wl_namespace' => $obj->rc_namespace,
262 'wl_title' => $obj->rc_title,
263 ),
264 __METHOD__ . '-watchers' );
265 }
266 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
267 }
268 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ) );
269 --$limit;
270 }
271 }
272 $s .= $list->endRecentChangesList();
273 $wgOut->addHTML( $s );
274 }
275 }
276
277 function rcFilterByCategories ( &$rows , $categories , $any ) {
278 if( empty( $categories ) ) {
279 return;
280 }
281
282 # Filter categories
283 $cats = array () ;
284 foreach ( $categories AS $cat ) {
285 $cat = trim ( $cat ) ;
286 if ( $cat == "" ) continue ;
287 $cats[] = $cat ;
288 }
289
290 # Filter articles
291 $articles = array () ;
292 $a2r = array () ;
293 foreach ( $rows AS $k => $r ) {
294 $nt = Title::makeTitle( $r->rc_title , $r->rc_namespace );
295 $id = $nt->getArticleID() ;
296 if ( $id == 0 ) continue ; # Page might have been deleted...
297 if ( !in_array ( $id , $articles ) ) {
298 $articles[] = $id ;
299 }
300 if ( !isset ( $a2r[$id] ) ) {
301 $a2r[$id] = array() ;
302 }
303 $a2r[$id][] = $k ;
304 }
305
306 # Shortcut?
307 if ( count ( $articles ) == 0 OR count ( $cats ) == 0 )
308 return ;
309
310 # Look up
311 $c = new Categoryfinder ;
312 $c->seed ( $articles , $cats , $any ? "OR" : "AND" ) ;
313 $match = $c->run () ;
314
315 # Filter
316 $newrows = array () ;
317 foreach ( $match AS $id ) {
318 foreach ( $a2r[$id] AS $rev ) {
319 $k = $rev ;
320 $newrows[$k] = $rows[$k] ;
321 }
322 }
323 $rows = $newrows ;
324 }
325
326 function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
327 global $messageMemc, $wgFeedCacheTimeout;
328 global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
329 global $wgFeed;
330
331 if ( !$wgFeed ) {
332 global $wgOut;
333 $wgOut->addWikiMsg( 'feed-unavailable' );
334 return;
335 }
336
337 if( !isset( $wgFeedClasses[$feedFormat] ) ) {
338 wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
339 return false;
340 }
341
342 $timekey = wfMemcKey( 'rcfeed', $feedFormat, 'timestamp' );
343 $key = wfMemcKey( 'rcfeed', $feedFormat, 'limit', $limit, 'minor', $hideminor );
344
345 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchanges' ) .
346 ' [' . $wgContLanguageCode . ']';
347 $feed = new $wgFeedClasses[$feedFormat](
348 $feedTitle,
349 htmlspecialchars( wfMsgForContent( 'recentchanges-feed-description' ) ),
350 $wgTitle->getFullUrl() );
351
352 //purge cache if requested
353 global $wgRequest, $wgUser;
354 $purge = $wgRequest->getVal( 'action' ) == 'purge';
355 if ( $purge && $wgUser->isAllowed('purge') ) {
356 $messageMemc->delete( $timekey );
357 $messageMemc->delete( $key );
358 }
359
360 /**
361 * Bumping around loading up diffs can be pretty slow, so where
362 * possible we want to cache the feed output so the next visitor
363 * gets it quick too.
364 */
365 $cachedFeed = false;
366 if( ( $wgFeedCacheTimeout > 0 ) && ( $feedLastmod = $messageMemc->get( $timekey ) ) ) {
367 /**
368 * If the cached feed was rendered very recently, we may
369 * go ahead and use it even if there have been edits made
370 * since it was rendered. This keeps a swarm of requests
371 * from being too bad on a super-frequently edited wiki.
372 */
373 if( time() - wfTimestamp( TS_UNIX, $feedLastmod )
374 < $wgFeedCacheTimeout
375 || wfTimestamp( TS_UNIX, $feedLastmod )
376 > wfTimestamp( TS_UNIX, $lastmod ) ) {
377 wfDebug( "RC: loading feed from cache ($key; $feedLastmod; $lastmod)...\n" );
378 $cachedFeed = $messageMemc->get( $key );
379 } else {
380 wfDebug( "RC: cached feed timestamp check failed ($feedLastmod; $lastmod)\n" );
381 }
382 }
383 if( is_string( $cachedFeed ) ) {
384 wfDebug( "RC: Outputting cached feed\n" );
385 $feed->httpHeaders();
386 echo $cachedFeed;
387 } else {
388 wfDebug( "RC: rendering new feed and caching it\n" );
389 ob_start();
390 rcDoOutputFeed( $rows, $feed );
391 $cachedFeed = ob_get_contents();
392 ob_end_flush();
393
394 $expire = 3600 * 24; # One day
395 $messageMemc->set( $key, $cachedFeed );
396 $messageMemc->set( $timekey, wfTimestamp( TS_MW ), $expire );
397 }
398 return true;
399 }
400
401 /**
402 * @todo document
403 * @param $rows Database resource with recentchanges rows
404 */
405 function rcDoOutputFeed( $rows, &$feed ) {
406 wfProfileIn( __METHOD__ );
407
408 $feed->outHeader();
409
410 # Merge adjacent edits by one user
411 $sorted = array();
412 $n = 0;
413 foreach( $rows as $obj ) {
414 if( $n > 0 &&
415 $obj->rc_namespace >= 0 &&
416 $obj->rc_cur_id == $sorted[$n-1]->rc_cur_id &&
417 $obj->rc_user_text == $sorted[$n-1]->rc_user_text ) {
418 $sorted[$n-1]->rc_last_oldid = $obj->rc_last_oldid;
419 } else {
420 $sorted[$n] = $obj;
421 $n++;
422 }
423 }
424
425 foreach( $sorted as $obj ) {
426 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
427 $talkpage = $title->getTalkPage();
428 $item = new FeedItem(
429 $title->getPrefixedText(),
430 rcFormatDiff( $obj ),
431 $title->getFullURL( 'diff=' . $obj->rc_this_oldid . '&oldid=prev' ),
432 $obj->rc_timestamp,
433 ($obj->rc_deleted & Revision::DELETED_USER) ? wfMsgHtml('rev-deleted-user') : $obj->rc_user_text,
434 $talkpage->getFullURL()
435 );
436 $feed->outItem( $item );
437 }
438 $feed->outFooter();
439 wfProfileOut( __METHOD__ );
440 }
441
442 /**
443 *
444 */
445 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
446 global $wgUser, $wgLang, $wgContLang;
447 $sk = $wgUser->getSkin();
448 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
449 ($lim ? $wgLang->formatNum( "{$lim}" ) : wfMsg( 'recentchangesall' ) ), "{$more}" .
450 ($d ? "days={$d}&" : '') . 'limit='.$lim );
451 return $s;
452 }
453
454 /**
455 *
456 */
457 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
458 global $wgUser, $wgLang, $wgContLang;
459 $sk = $wgUser->getSkin();
460 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
461 ($d ? $wgLang->formatNum( "{$d}" ) : wfMsg( 'recentchangesall' ) ), $more.'days='.$d .
462 ($lim ? '&limit='.$lim : '') );
463 return $s;
464 }
465
466 /**
467 * Used by Recentchangeslinked
468 */
469 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
470 $botLink = '', $liuLink = '', $patrLink = '', $myselfLink = '' ) {
471 if ($more != '') $more .= '&';
472 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
473 rcCountLink( 100, $days, $page, $more ) . ' | ' .
474 rcCountLink( 250, $days, $page, $more ) . ' | ' .
475 rcCountLink( 500, $days, $page, $more ) .
476 ( $doall ? ( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
477 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
478 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
479 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
480 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
481 rcDaysLink( $limit, 30, $page, $more ) .
482 ( $doall ? ( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
483
484 $linkParts = array( 'minorLink' => 'minor', 'botLink' => 'bots', 'liuLink' => 'liu', 'patrLink' => 'patr', 'myselfLink' => 'mine' );
485 foreach( $linkParts as $linkVar => $linkMsg ) {
486 if( $$linkVar != '' )
487 $links[] = wfMsgHtml( 'rcshowhide' . $linkMsg, $$linkVar );
488 }
489
490 $shm = implode( ' | ', $links );
491 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
492 return $note;
493 }
494
495
496 /**
497 * Makes change an option link which carries all the other options
498 * @param $title see Title
499 * @param $override
500 * @param $options
501 */
502 function makeOptionsLink( $title, $override, $options ) {
503 global $wgUser, $wgContLang;
504 $sk = $wgUser->getSkin();
505 return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
506 htmlspecialchars( $title ), wfArrayToCGI( $override, $options ) );
507 }
508
509 /**
510 * Creates the options panel.
511 * @param $defaults
512 * @param $nondefaults
513 */
514 function rcOptionsPanel( $defaults, $nondefaults ) {
515 global $wgLang, $wgUseRCPatrol;
516
517 $options = $nondefaults + $defaults;
518
519 if( $options['from'] )
520 $note = wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
521 $wgLang->formatNum( $options['limit'] ),
522 $wgLang->timeanddate( $options['from'], true ) );
523 else
524 $note = wfMsgExt( 'rcnote', array( 'parseinline' ),
525 $wgLang->formatNum( $options['limit'] ),
526 $wgLang->formatNum( $options['days'] ),
527 $wgLang->timeAndDate( wfTimestampNow(), true ) );
528
529 // limit links
530 $options_limit = array(50, 100, 250, 500);
531 foreach( $options_limit as $value ) {
532 $cl[] = makeOptionsLink( $wgLang->formatNum( $value ),
533 array( 'limit' => $value ), $nondefaults) ;
534 }
535 $cl = implode( ' | ', $cl);
536
537 // day links, reset 'from' to none
538 $options_days = array(1, 3, 7, 14, 30);
539 foreach( $options_days as $value ) {
540 $dl[] = makeOptionsLink( $wgLang->formatNum( $value ),
541 array( 'days' => $value, 'from' => '' ), $nondefaults) ;
542 }
543 $dl = implode( ' | ', $dl);
544
545
546 // show/hide links
547 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
548 $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
549 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
550 $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
551 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
552 $anonsLink = makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
553 array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
554 $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
555 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
556 $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
557 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
558 $myselfLink = makeOptionsLink( $showhide[1-$options['hidemyself']],
559 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
560
561 $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
562 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
563 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
564 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
565 if( $wgUseRCPatrol )
566 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
567 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
568 $hl = implode( ' | ', $links );
569
570 // show from this onward link
571 $now = $wgLang->timeanddate( wfTimestampNow(), true );
572 $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
573
574 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter'),
575 $cl, $dl, $hl );
576 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter'), $tl );
577 return "$note<br />$rclinks<br />$rclistfrom";
578
579 }
580
581 /**
582 * Creates the choose namespace selection
583 *
584 * @private
585 *
586 * @param $namespace Mixed: the key of the currently selected namespace, empty string
587 * if there is none
588 * @param $invert Bool: whether to invert the namespace selection
589 * @param $nondefaults Array: an array of non default options to be remembered
590 * @param $categories_any Bool: Default value for the checkbox
591 *
592 * @return string
593 */
594 function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
595 global $wgScript, $wgAllowCategorizedRecentChanges, $wgRequest;
596 $t = SpecialPage::getTitleFor( 'Recentchanges' );
597
598 $namespaceselect = HTMLnamespaceselector($namespace, '');
599 $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
600 $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ? ' checked="checked"' : '' ) . ' />';
601
602 if ( $wgAllowCategorizedRecentChanges ) {
603 $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
604 $cb_arr = array( 'type' => 'checkbox', 'name' => 'categories_any', 'value' => "1" ) ;
605 if ( $categories_any ) $cb_arr['checked'] = "checked" ;
606 $catbox = "<br />" ;
607 $catbox .= wfMsgExt('rc_categories', array('parseinline')) . " ";
608 $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
609 $catbox .= " &nbsp;" ;
610 $catbox .= wfElement('input', $cb_arr );
611 $catbox .= wfMsgExt('rc_categories_any', array('parseinline'));
612 } else {
613 $catbox = "" ;
614 }
615
616 $out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
617
618 foreach ( $nondefaults as $key => $value ) {
619 if ($key != 'namespace' && $key != 'invert')
620 $out .= wfElement('input', array( 'type' => 'hidden', 'name' => $key, 'value' => $value));
621 }
622
623 $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
624 $out .= "
625 <div id='nsselect' class='recentchanges'>
626 <label for='namespace'>" . wfMsgHtml('namespace') . "</label>
627 {$namespaceselect}{$submitbutton}{$invertbox} <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>{$catbox}\n</div>";
628 $out .= '</form></div>';
629 return $out;
630 }
631
632
633 /**
634 * Format a diff for the newsfeed
635 */
636 function rcFormatDiff( $row ) {
637 global $wgUser;
638
639 $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title );
640 $timestamp = wfTimestamp( TS_MW, $row->rc_timestamp );
641 $actiontext = '';
642 if( $row->rc_type == RC_LOG ) {
643 if( $row->rc_deleted & LogPage::DELETED_ACTION ) {
644 $actiontext = wfMsgHtml('rev-deleted-event');
645 } else {
646 $actiontext = LogPage::actionText( $row->rc_log_type, $row->rc_log_action,
647 $titleObj, $wgUser->getSkin(), LogPage::extractParams($row->rc_params,true,true) );
648 }
649 }
650 return rcFormatDiffRow( $titleObj,
651 $row->rc_last_oldid, $row->rc_this_oldid,
652 $timestamp,
653 ($row->rc_deleted & Revision::DELETED_COMMENT) ? wfMsgHtml('rev-deleted-comment') : $row->rc_comment,
654 $actiontext );
655 }
656
657 function rcFormatDiffRow( $title, $oldid, $newid, $timestamp, $comment, $actiontext='' ) {
658 global $wgFeedDiffCutoff, $wgContLang, $wgUser;
659 $fname = 'rcFormatDiff';
660 wfProfileIn( $fname );
661
662 $skin = $wgUser->getSkin();
663 # log enties
664 if( $actiontext ) {
665 $comment = "$actiontext $comment";
666 }
667 $completeText = '<p>' . $skin->formatComment( $comment ) . "</p>\n";
668
669 //NOTE: Check permissions for anonymous users, not current user.
670 // No "privileged" version should end up in the cache.
671 // Most feed readers will not log in anway.
672 $anon = new User();
673 $accErrors = $title->getUserPermissionsErrors( 'read', $anon, true );
674
675 if( $title->getNamespace() >= 0 && !$accErrors ) {
676 if( $oldid ) {
677 wfProfileIn( "$fname-dodiff" );
678
679 $de = new DifferenceEngine( $title, $oldid, $newid );
680 #$diffText = $de->getDiff( wfMsg( 'revisionasof',
681 # $wgContLang->timeanddate( $timestamp ) ),
682 # wfMsg( 'currentrev' ) );
683 $diffText = $de->getDiff(
684 wfMsg( 'previousrevision' ), // hack
685 wfMsg( 'revisionasof',
686 $wgContLang->timeanddate( $timestamp ) ) );
687
688
689 if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
690 // Omit large diffs
691 $diffLink = $title->escapeFullUrl(
692 'diff=' . $newid .
693 '&oldid=' . $oldid );
694 $diffText = '<a href="' .
695 $diffLink .
696 '">' .
697 htmlspecialchars( wfMsgForContent( 'difference' ) ) .
698 '</a>';
699 } elseif ( $diffText === false ) {
700 // Error in diff engine, probably a missing revision
701 $diffText = "<p>Can't load revision $newid</p>";
702 } else {
703 // Diff output fine, clean up any illegal UTF-8
704 $diffText = UtfNormal::cleanUp( $diffText );
705 $diffText = rcApplyDiffStyle( $diffText );
706 }
707 wfProfileOut( "$fname-dodiff" );
708 } else {
709 $rev = Revision::newFromId( $newid );
710 if( is_null( $rev ) ) {
711 $newtext = '';
712 } else {
713 $newtext = $rev->getText();
714 }
715 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
716 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
717 }
718 $completeText .= $diffText;
719 }
720
721 wfProfileOut( $fname );
722 return $completeText;
723 }
724
725 /**
726 * Hacky application of diff styles for the feeds.
727 * Might be 'cleaner' to use DOM or XSLT or something,
728 * but *gack* it's a pain in the ass.
729 *
730 * @param $text String:
731 * @return string
732 * @private
733 */
734 function rcApplyDiffStyle( $text ) {
735 $styles = array(
736 'diff' => 'background-color: white; color:black;',
737 'diff-otitle' => 'background-color: white; color:black;',
738 'diff-ntitle' => 'background-color: white; color:black;',
739 'diff-addedline' => 'background: #cfc; color:black; font-size: smaller;',
740 'diff-deletedline' => 'background: #ffa; color:black; font-size: smaller;',
741 'diff-context' => 'background: #eee; color:black; font-size: smaller;',
742 'diffchange' => 'color: red; font-weight: bold; text-decoration: none;',
743 );
744
745 foreach( $styles as $class => $style ) {
746 $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
747 "\\1style=\"$style\"\\3", $text );
748 }
749
750 return $text;
751 }
752
753