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