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