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