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