Enhanced RC: Add a "view changes since my last visit" link
[lhc/web/wiklou.git] / includes / ChangesList.php
1 <?php
2 /**
3 * Classes to show lists of changes.
4 *
5 * These can be:
6 * - watchlist
7 * - related changes
8 * - recent changes
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
24 *
25 * @file
26 */
27
28 /**
29 * @todo document
30 */
31 class RCCacheEntry extends RecentChange {
32 var $secureName, $link;
33 var $curlink, $difflink, $lastlink, $usertalklink, $versionlink;
34 var $userlink, $timestamp, $watched;
35
36 /**
37 * @param $rc RecentChange
38 * @return RCCacheEntry
39 */
40 static function newFromParent( $rc ) {
41 $rc2 = new RCCacheEntry;
42 $rc2->mAttribs = $rc->mAttribs;
43 $rc2->mExtra = $rc->mExtra;
44 return $rc2;
45 }
46 }
47
48 /**
49 * Base class for all changes lists
50 */
51 class ChangesList extends ContextSource {
52
53 /**
54 * @var Skin
55 */
56 public $skin;
57
58 protected $watchlist = false;
59
60 protected $message;
61
62 /**
63 * Changeslist constructor
64 *
65 * @param $obj Skin or IContextSource
66 */
67 public function __construct( $obj ) {
68 if ( $obj instanceof IContextSource ) {
69 $this->setContext( $obj );
70 $this->skin = $obj->getSkin();
71 } else {
72 $this->setContext( $obj->getContext() );
73 $this->skin = $obj;
74 }
75 $this->preCacheMessages();
76 }
77
78 /**
79 * Fetch an appropriate changes list class for the main context
80 * This first argument used to be an User object.
81 *
82 * @deprecated in 1.18; use newFromContext() instead
83 * @param string|User $unused Unused
84 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
85 */
86 public static function newFromUser( $unused ) {
87 wfDeprecated( __METHOD__, '1.18' );
88 return self::newFromContext( RequestContext::getMain() );
89 }
90
91 /**
92 * Fetch an appropriate changes list class for the specified context
93 * Some users might want to use an enhanced list format, for instance
94 *
95 * @param $context IContextSource to use
96 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
97 */
98 public static function newFromContext( IContextSource $context ) {
99 $user = $context->getUser();
100 $sk = $context->getSkin();
101 $list = null;
102 if ( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
103 $new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
104 return $new ? new EnhancedChangesList( $context ) : new OldChangesList( $context );
105 } else {
106 return $list;
107 }
108 }
109
110 /**
111 * Sets the list to use a "<li class='watchlist-(namespace)-(page)'>" tag
112 * @param $value Boolean
113 */
114 public function setWatchlistDivs( $value = true ) {
115 $this->watchlist = $value;
116 }
117
118 /**
119 * As we use the same small set of messages in various methods and that
120 * they are called often, we call them once and save them in $this->message
121 */
122 private function preCacheMessages() {
123 if ( !isset( $this->message ) ) {
124 foreach ( array(
125 'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
126 'semicolon-separator', 'pipe-separator' ) as $msg
127 ) {
128 $this->message[$msg] = $this->msg( $msg )->escaped();
129 }
130 }
131 }
132
133 /**
134 * Returns the appropriate flags for new page, minor change and patrolling
135 * @param array $flags Associative array of 'flag' => Bool
136 * @param string $nothing to use for empty space
137 * @return String
138 */
139 public function recentChangesFlags( $flags, $nothing = '&#160;' ) {
140 global $wgRecentChangesFlags;
141 $f = '';
142 foreach ( array_keys( $wgRecentChangesFlags ) as $flag ) {
143 $f .= isset( $flags[$flag] ) && $flags[$flag]
144 ? self::flag( $flag )
145 : $nothing;
146 }
147 return $f;
148 }
149
150 /**
151 * Provide the "<abbr>" element appropriate to a given abbreviated flag,
152 * namely the flag indicating a new page, a minor edit, a bot edit, or an
153 * unpatrolled edit. By default in English it will contain "N", "m", "b",
154 * "!" respectively, plus it will have an appropriate title and class.
155 *
156 * @param string $flag One key of $wgRecentChangesFlags
157 * @return String: Raw HTML
158 */
159 public static function flag( $flag ) {
160 static $flagInfos = null;
161 if ( is_null( $flagInfos ) ) {
162 global $wgRecentChangesFlags;
163 $flagInfos = array();
164 foreach ( $wgRecentChangesFlags as $key => $value ) {
165 $flagInfos[$key]['letter'] = wfMessage( $value['letter'] )->escaped();
166 $flagInfos[$key]['title'] = wfMessage( $value['title'] )->escaped();
167 // Allow customized class name, fall back to flag name
168 $flagInfos[$key]['class'] = Sanitizer::escapeClass(
169 isset( $value['class'] ) ? $value['class'] : $key );
170 }
171 }
172
173 // Inconsistent naming, bleh, kepted for b/c
174 $map = array(
175 'minoredit' => 'minor',
176 'botedit' => 'bot',
177 );
178 if ( isset( $map[$flag] ) ) {
179 $flag = $map[$flag];
180 }
181
182 return "<abbr class='" . $flagInfos[$flag]['class'] . "' title='" . $flagInfos[$flag]['title'] . "'>" .
183 $flagInfos[$flag]['letter'] .
184 '</abbr>';
185 }
186
187 /**
188 * Returns text for the start of the tabular part of RC
189 * @return String
190 */
191 public function beginRecentChangesList() {
192 $this->rc_cache = array();
193 $this->rcMoveIndex = 0;
194 $this->rcCacheIndex = 0;
195 $this->lastdate = '';
196 $this->rclistOpen = false;
197 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
198 return '';
199 }
200
201 /**
202 * Show formatted char difference
203 * @param $old Integer: bytes
204 * @param $new Integer: bytes
205 * @param $context IContextSource context to use
206 * @return String
207 */
208 public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
209 global $wgRCChangedSizeThreshold, $wgMiserMode;
210
211 if ( !$context ) {
212 $context = RequestContext::getMain();
213 }
214
215 $new = (int)$new;
216 $old = (int)$old;
217 $szdiff = $new - $old;
218
219 $lang = $context->getLanguage();
220 $code = $lang->getCode();
221 static $fastCharDiff = array();
222 if ( !isset( $fastCharDiff[$code] ) ) {
223 $fastCharDiff[$code] = $wgMiserMode || $context->msg( 'rc-change-size' )->plain() === '$1';
224 }
225
226 $formattedSize = $lang->formatNum( $szdiff );
227
228 if ( !$fastCharDiff[$code] ) {
229 $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
230 }
231
232 if ( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
233 $tag = 'strong';
234 } else {
235 $tag = 'span';
236 }
237
238 if ( $szdiff === 0 ) {
239 $formattedSizeClass = 'mw-plusminus-null';
240 }
241 if ( $szdiff > 0 ) {
242 $formattedSize = '+' . $formattedSize;
243 $formattedSizeClass = 'mw-plusminus-pos';
244 }
245 if ( $szdiff < 0 ) {
246 $formattedSizeClass = 'mw-plusminus-neg';
247 }
248
249 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
250
251 return Html::element( $tag,
252 array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ),
253 $context->msg( 'parentheses', $formattedSize )->plain() ) . $lang->getDirMark();
254 }
255
256 /**
257 * Format the character difference of one or several changes.
258 *
259 * @param $old RecentChange
260 * @param $new RecentChange last change to use, if not provided, $old will be used
261 * @return string HTML fragment
262 */
263 public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
264 $oldlen = $old->mAttribs['rc_old_len'];
265
266 if ( $new ) {
267 $newlen = $new->mAttribs['rc_new_len'];
268 } else {
269 $newlen = $old->mAttribs['rc_new_len'];
270 }
271
272 if ( $oldlen === null || $newlen === null ) {
273 return '';
274 }
275
276 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
277 }
278
279 /**
280 * Returns text for the end of RC
281 * @return String
282 */
283 public function endRecentChangesList() {
284 if ( $this->rclistOpen ) {
285 return "</ul>\n";
286 } else {
287 return '';
288 }
289 }
290
291 /**
292 * @param string $s HTML to update
293 * @param $rc_timestamp mixed
294 */
295 public function insertDateHeader( &$s, $rc_timestamp ) {
296 # Make date header if necessary
297 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
298 if ( $date != $this->lastdate ) {
299 if ( $this->lastdate != '' ) {
300 $s .= "</ul>\n";
301 }
302 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
303 $this->lastdate = $date;
304 $this->rclistOpen = true;
305 }
306 }
307
308 /**
309 * @param string $s HTML to update
310 * @param $title Title
311 * @param $logtype string
312 */
313 public function insertLog( &$s, $title, $logtype ) {
314 $page = new LogPage( $logtype );
315 $logname = $page->getName()->escaped();
316 $s .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $title, $logname ) )->escaped();
317 }
318
319 /**
320 * @param string $s HTML to update
321 * @param $rc RecentChange
322 * @param $unpatrolled
323 */
324 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
325 # Diff link
326 if ( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
327 $diffLink = $this->message['diff'];
328 } elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
329 $diffLink = $this->message['diff'];
330 } else {
331 $query = array(
332 'curid' => $rc->mAttribs['rc_cur_id'],
333 'diff' => $rc->mAttribs['rc_this_oldid'],
334 'oldid' => $rc->mAttribs['rc_last_oldid']
335 );
336
337 $diffLink = Linker::linkKnown(
338 $rc->getTitle(),
339 $this->message['diff'],
340 array( 'tabindex' => $rc->counter ),
341 $query
342 );
343 }
344 $diffhist = $diffLink . $this->message['pipe-separator'];
345 # History link
346 $diffhist .= Linker::linkKnown(
347 $rc->getTitle(),
348 $this->message['hist'],
349 array(),
350 array(
351 'curid' => $rc->mAttribs['rc_cur_id'],
352 'action' => 'history'
353 )
354 );
355 $s .= $this->msg( 'parentheses' )->rawParams( $diffhist )->escaped() . ' <span class="mw-changeslist-separator">. .</span> ';
356 }
357
358 /**
359 * @param string $s HTML to update
360 * @param $rc RecentChange
361 * @param $unpatrolled
362 * @param $watched
363 */
364 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
365 $params = array();
366
367 $articlelink = Linker::linkKnown(
368 $rc->getTitle(),
369 null,
370 array( 'class' => 'mw-changeslist-title' ),
371 $params
372 );
373 if ( $this->isDeleted( $rc, Revision::DELETED_TEXT ) ) {
374 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
375 }
376 # To allow for boldening pages watched by this user
377 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
378 # RTL/LTR marker
379 $articlelink .= $this->getLanguage()->getDirMark();
380
381 wfRunHooks( 'ChangesListInsertArticleLink',
382 array( &$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched ) );
383
384 $s .= " $articlelink";
385 }
386
387 /**
388 * Get the timestamp from $rc formatted with current user's settings
389 * and a separator
390 *
391 * @param $rc RecentChange
392 * @return string HTML fragment
393 */
394 public function getTimestamp( $rc ) {
395 return $this->message['semicolon-separator'] . '<span class="mw-changeslist-date">' .
396 $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() ) . '</span> <span class="mw-changeslist-separator">. .</span> ';
397 }
398
399 /**
400 * Insert time timestamp string from $rc into $s
401 *
402 * @param string $s HTML to update
403 * @param $rc RecentChange
404 */
405 public function insertTimestamp( &$s, $rc ) {
406 $s .= $this->getTimestamp( $rc );
407 }
408
409 /**
410 * Insert links to user page, user talk page and eventually a blocking link
411 *
412 * @param &$s String HTML to update
413 * @param &$rc RecentChange
414 */
415 public function insertUserRelatedLinks( &$s, &$rc ) {
416 if ( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
417 $s .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
418 } else {
419 $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'],
420 $rc->mAttribs['rc_user_text'] );
421 $s .= Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
422 }
423 }
424
425 /**
426 * Insert a formatted action
427 *
428 * @param $rc RecentChange
429 * @return string
430 */
431 public function insertLogEntry( $rc ) {
432 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
433 $formatter->setContext( $this->getContext() );
434 $formatter->setShowUserToolLinks( true );
435 $mark = $this->getLanguage()->getDirMark();
436 return $formatter->getActionText() . " $mark" . $formatter->getComment();
437 }
438
439 /**
440 * Insert a formatted comment
441 * @param $rc RecentChange
442 * @return string
443 */
444 public function insertComment( $rc ) {
445 if ( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
446 if ( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
447 return ' <span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
448 } else {
449 return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
450 }
451 }
452 return '';
453 }
454
455 /**
456 * Check whether to enable recent changes patrol features
457 *
458 * @deprecated since 1.22
459 * @return Boolean
460 */
461 public static function usePatrol() {
462 global $wgUser;
463
464 wfDeprecated( __METHOD__, '1.22' );
465
466 return $wgUser->useRCPatrol();
467 }
468
469 /**
470 * Returns the string which indicates the number of watching users
471 * @return string
472 */
473 protected function numberofWatchingusers( $count ) {
474 static $cache = array();
475 if ( $count > 0 ) {
476 if ( !isset( $cache[$count] ) ) {
477 $cache[$count] = $this->msg( 'number_of_watching_users_RCview' )->numParams( $count )->escaped();
478 }
479 return $cache[$count];
480 } else {
481 return '';
482 }
483 }
484
485 /**
486 * Determine if said field of a revision is hidden
487 * @param $rc RCCacheEntry
488 * @param $field Integer: one of DELETED_* bitfield constants
489 * @return Boolean
490 */
491 public static function isDeleted( $rc, $field ) {
492 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
493 }
494
495 /**
496 * Determine if the current user is allowed to view a particular
497 * field of this revision, if it's marked as deleted.
498 * @param $rc RCCacheEntry
499 * @param $field Integer
500 * @param $user User object to check, or null to use $wgUser
501 * @return Boolean
502 */
503 public static function userCan( $rc, $field, User $user = null ) {
504 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
505 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
506 } else {
507 return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
508 }
509 }
510
511 /**
512 * @param $link string
513 * @param $watched bool
514 * @return string
515 */
516 protected function maybeWatchedLink( $link, $watched = false ) {
517 if ( $watched ) {
518 return '<strong class="mw-watched">' . $link . '</strong>';
519 } else {
520 return '<span class="mw-rc-unwatched">' . $link . '</span>';
521 }
522 }
523
524 /** Inserts a rollback link
525 *
526 * @param $s string
527 * @param $rc RecentChange
528 */
529 public function insertRollback( &$s, &$rc ) {
530 if ( $rc->mAttribs['rc_type'] == RC_EDIT && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) {
531 $page = $rc->getTitle();
532 /** Check for rollback and edit permissions, disallow special pages, and only
533 * show a link on the top-most revision */
534 if ( $this->getUser()->isAllowed( 'rollback' ) && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] )
535 {
536 $rev = new Revision( array(
537 'title' => $page,
538 'id' => $rc->mAttribs['rc_this_oldid'],
539 'user' => $rc->mAttribs['rc_user'],
540 'user_text' => $rc->mAttribs['rc_user_text'],
541 'deleted' => $rc->mAttribs['rc_deleted']
542 ) );
543 $s .= ' ' . Linker::generateRollback( $rev, $this->getContext() );
544 }
545 }
546 }
547
548 /**
549 * @param $s string
550 * @param $rc RecentChange
551 * @param $classes
552 */
553 public function insertTags( &$s, &$rc, &$classes ) {
554 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
555 return;
556 }
557
558 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' );
559 $classes = array_merge( $classes, $newClasses );
560 $s .= ' ' . $tagSummary;
561 }
562
563 public function insertExtra( &$s, &$rc, &$classes ) {
564 // Empty, used for subclasses to add anything special.
565 }
566
567 protected function showAsUnpatrolled( RecentChange $rc ) {
568 $unpatrolled = false;
569 if ( !$rc->mAttribs['rc_patrolled'] ) {
570 if ( $this->getUser()->useRCPatrol() ) {
571 $unpatrolled = true;
572 } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs['rc_type'] == RC_NEW ) {
573 $unpatrolled = true;
574 }
575 }
576 return $unpatrolled;
577 }
578 }
579
580 /**
581 * Generate a list of changes using the good old system (no javascript)
582 */
583 class OldChangesList extends ChangesList {
584 /**
585 * Format a line using the old system (aka without any javascript).
586 *
587 * @param $rc RecentChange, passed by reference
588 * @param bool $watched (default false)
589 * @param int $linenumber (default null)
590 *
591 * @return string|bool
592 */
593 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
594 global $wgRCShowChangedSize;
595 wfProfileIn( __METHOD__ );
596
597 # Should patrol-related stuff be shown?
598 $unpatrolled = $this->showAsUnpatrolled( $rc );
599
600 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
601 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
602
603 $s = '';
604 $classes = array();
605 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
606 if ( $linenumber ) {
607 if ( $linenumber & 1 ) {
608 $classes[] = 'mw-line-odd';
609 } else {
610 $classes[] = 'mw-line-even';
611 }
612 }
613
614 // Indicate watched status on the line to allow for more
615 // comprehensive styling.
616 $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
617 ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
618
619 // Moved pages (very very old, not supported anymore)
620 if ( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
621 // Log entries
622 } elseif ( $rc->mAttribs['rc_log_type'] ) {
623 $logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] );
624 $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] );
625 // Log entries (old format) or log targets, and special pages
626 } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
627 list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $rc->mAttribs['rc_title'] );
628 if ( $name == 'Log' ) {
629 $this->insertLog( $s, $rc->getTitle(), $subpage );
630 }
631 // Regular entries
632 } else {
633 $this->insertDiffHist( $s, $rc, $unpatrolled );
634 # M, N, b and ! (minor, new, bot and unpatrolled)
635 $s .= $this->recentChangesFlags(
636 array(
637 'newpage' => $rc->mAttribs['rc_type'] == RC_NEW,
638 'minor' => $rc->mAttribs['rc_minor'],
639 'unpatrolled' => $unpatrolled,
640 'bot' => $rc->mAttribs['rc_bot']
641 ),
642 ''
643 );
644 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
645 }
646 # Edit/log timestamp
647 $this->insertTimestamp( $s, $rc );
648 # Bytes added or removed
649 if ( $wgRCShowChangedSize ) {
650 $cd = $this->formatCharacterDifference( $rc );
651 if ( $cd !== '' ) {
652 $s .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
653 }
654 }
655
656 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
657 $s .= $this->insertLogEntry( $rc );
658 } else {
659 # User tool links
660 $this->insertUserRelatedLinks( $s, $rc );
661 # LTR/RTL direction mark
662 $s .= $this->getLanguage()->getDirMark();
663 $s .= $this->insertComment( $rc );
664 }
665
666 # Tags
667 $this->insertTags( $s, $rc, $classes );
668 # Rollback
669 $this->insertRollback( $s, $rc );
670 # For subclasses
671 $this->insertExtra( $s, $rc, $classes );
672
673 # How many users watch this page
674 if ( $rc->numberofWatchingusers > 0 ) {
675 $s .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers );
676 }
677
678 if ( $this->watchlist ) {
679 $classes[] = Sanitizer::escapeClass( 'watchlist-' . $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
680 }
681
682 if ( !wfRunHooks( 'OldChangesListRecentChangesLine', array( &$this, &$s, $rc, &$classes ) ) ) {
683 wfProfileOut( __METHOD__ );
684 return false;
685 }
686
687 wfProfileOut( __METHOD__ );
688 return "$dateheader<li class=\"" . implode( ' ', $classes ) . "\">" . $s . "</li>\n";
689 }
690 }
691
692 /**
693 * Generate a list of changes using an Enhanced system (uses javascript).
694 */
695 class EnhancedChangesList extends ChangesList {
696
697 protected $rc_cache;
698
699 /**
700 * Add the JavaScript file for enhanced changeslist
701 * @return String
702 */
703 public function beginRecentChangesList() {
704 $this->rc_cache = array();
705 $this->rcMoveIndex = 0;
706 $this->rcCacheIndex = 0;
707 $this->lastdate = '';
708 $this->rclistOpen = false;
709 $this->getOutput()->addModuleStyles( array(
710 'mediawiki.special.changeslist',
711 'mediawiki.special.changeslist.enhanced',
712 ) );
713 $this->getOutput()->addModules( array(
714 'jquery.makeCollapsible',
715 'mediawiki.icon',
716 ) );
717 return '';
718 }
719 /**
720 * Format a line for enhanced recentchange (aka with javascript and block of lines).
721 *
722 * @param $baseRC RecentChange
723 * @param $watched bool
724 *
725 * @return string
726 */
727 public function recentChangesLine( &$baseRC, $watched = false ) {
728 wfProfileIn( __METHOD__ );
729
730 # Create a specialised object
731 $rc = RCCacheEntry::newFromParent( $baseRC );
732
733 $curIdEq = array( 'curid' => $rc->mAttribs['rc_cur_id'] );
734
735 # If it's a new day, add the headline and flush the cache
736 $date = $this->getLanguage()->userDate( $rc->mAttribs['rc_timestamp'], $this->getUser() );
737 $ret = '';
738 if ( $date != $this->lastdate ) {
739 # Process current cache
740 $ret = $this->recentChangesBlock();
741 $this->rc_cache = array();
742 $ret .= Xml::element( 'h4', null, $date ) . "\n";
743 $this->lastdate = $date;
744 }
745
746 # Should patrol-related stuff be shown?
747 $rc->unpatrolled = $this->showAsUnpatrolled( $rc );
748
749 $showdifflinks = true;
750 # Make article link
751 $type = $rc->mAttribs['rc_type'];
752 $logType = $rc->mAttribs['rc_log_type'];
753 // Page moves, very old style, not supported anymore
754 if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
755 // New unpatrolled pages
756 } elseif ( $rc->unpatrolled && $type == RC_NEW ) {
757 $clink = Linker::linkKnown( $rc->getTitle() );
758 // Log entries
759 } elseif ( $type == RC_LOG ) {
760 if ( $logType ) {
761 $logtitle = SpecialPage::getTitleFor( 'Log', $logType );
762 $logpage = new LogPage( $logType );
763 $logname = $logpage->getName()->escaped();
764 $clink = $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logtitle, $logname ) )->escaped();
765 } else {
766 $clink = Linker::link( $rc->getTitle() );
767 }
768 $watched = false;
769 // Log entries (old format) and special pages
770 } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
771 wfDebug( "Unexpected special page in recentchanges\n" );
772 $clink = '';
773 // Edits
774 } else {
775 $clink = Linker::linkKnown( $rc->getTitle() );
776 }
777
778 # Don't show unusable diff links
779 if ( !ChangesList::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
780 $showdifflinks = false;
781 }
782
783 $time = $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() );
784 $rc->watched = $watched;
785 $rc->link = $clink;
786 $rc->timestamp = $time;
787 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
788
789 # Make "cur" and "diff" links. Do not use link(), it is too slow if
790 # called too many times (50% of CPU time on RecentChanges!).
791 $thisOldid = $rc->mAttribs['rc_this_oldid'];
792 $lastOldid = $rc->mAttribs['rc_last_oldid'];
793
794 $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $thisOldid );
795 $querydiff = $curIdEq + array( 'diff' => $thisOldid, 'oldid' => $lastOldid );
796
797 if ( !$showdifflinks ) {
798 $curLink = $this->message['cur'];
799 $diffLink = $this->message['diff'];
800 } elseif ( in_array( $type, array( RC_NEW, RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
801 if ( $type != RC_NEW ) {
802 $curLink = $this->message['cur'];
803 } else {
804 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
805 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
806 }
807 $diffLink = $this->message['diff'];
808 } else {
809 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
810 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
811 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
812 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
813 }
814
815 # Make "last" link
816 if ( !$showdifflinks || !$lastOldid ) {
817 $lastLink = $this->message['last'];
818 } elseif ( in_array( $type, array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
819 $lastLink = $this->message['last'];
820 } else {
821 $lastLink = Linker::linkKnown( $rc->getTitle(), $this->message['last'],
822 array(), $curIdEq + array( 'diff' => $thisOldid, 'oldid' => $lastOldid ) );
823 }
824
825 # Make user links
826 if ( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
827 $rc->userlink = ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
828 } else {
829 $rc->userlink = Linker::userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
830 $rc->usertalklink = Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
831 }
832
833 $rc->lastlink = $lastLink;
834 $rc->curlink = $curLink;
835 $rc->difflink = $diffLink;
836
837 # Put accumulated information into the cache, for later display
838 # Page moves go on their own line
839 $title = $rc->getTitle();
840 $secureName = $title->getPrefixedDBkey();
841 if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
842 # Use an @ character to prevent collision with page names
843 $this->rc_cache['@@' . ( $this->rcMoveIndex++ )] = array( $rc );
844 } else {
845 # Logs are grouped by type
846 if ( $type == RC_LOG ) {
847 $secureName = SpecialPage::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
848 }
849 if ( !isset( $this->rc_cache[$secureName] ) ) {
850 $this->rc_cache[$secureName] = array();
851 }
852
853 array_push( $this->rc_cache[$secureName], $rc );
854 }
855
856 wfProfileOut( __METHOD__ );
857
858 return $ret;
859 }
860
861 /**
862 * Enhanced RC group
863 * @return string
864 */
865 protected function recentChangesBlockGroup( $block ) {
866 global $wgRCShowChangedSize;
867
868 wfProfileIn( __METHOD__ );
869
870 # Add the namespace and title of the block as part of the class
871 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
872 if ( $block[0]->mAttribs['rc_log_type'] ) {
873 # Log entry
874 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
875 . $block[0]->mAttribs['rc_log_type'] . '-' . $block[0]->mAttribs['rc_title'] );
876 } else {
877 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns'
878 . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
879 }
880 $classes[] = $block[0]->watched && $block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched
881 ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
882 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
883 Html::openElement( 'tr' );
884
885 # Collate list of users
886 $userlinks = array();
887 # Other properties
888 $unpatrolled = false;
889 $isnew = false;
890 $allBots = true;
891 $allMinors = true;
892 $curId = $currentRevision = 0;
893 # Some catalyst variables...
894 $namehidden = true;
895 $allLogs = true;
896 foreach ( $block as $rcObj ) {
897 $oldid = $rcObj->mAttribs['rc_last_oldid'];
898 if ( $rcObj->mAttribs['rc_type'] == RC_NEW ) {
899 $isnew = true;
900 }
901 // If all log actions to this page were hidden, then don't
902 // give the name of the affected page for this block!
903 if ( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
904 $namehidden = false;
905 }
906 $u = $rcObj->userlink;
907 if ( !isset( $userlinks[$u] ) ) {
908 $userlinks[$u] = 0;
909 }
910 if ( $rcObj->unpatrolled ) {
911 $unpatrolled = true;
912 }
913 if ( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
914 $allLogs = false;
915 }
916 # Get the latest entry with a page_id and oldid
917 # since logs may not have these.
918 if ( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
919 $curId = $rcObj->mAttribs['rc_cur_id'];
920 }
921 if ( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
922 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
923 }
924
925 if ( !$rcObj->mAttribs['rc_bot'] ) {
926 $allBots = false;
927 }
928 if ( !$rcObj->mAttribs['rc_minor'] ) {
929 $allMinors = false;
930 }
931
932 $userlinks[$u]++;
933 }
934
935 # Sort the list and convert to text
936 krsort( $userlinks );
937 asort( $userlinks );
938 $users = array();
939 foreach ( $userlinks as $userlink => $count ) {
940 $text = $userlink;
941 $text .= $this->getLanguage()->getDirMark();
942 if ( $count > 1 ) {
943 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->formatNum( $count ) . '×' )->escaped();
944 }
945 array_push( $users, $text );
946 }
947
948 $users = ' <span class="changedby">'
949 . $this->msg( 'brackets' )->rawParams(
950 implode( $this->message['semicolon-separator'], $users )
951 )->escaped() . '</span>';
952
953 $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
954 $r .= "<td>$tl</td>";
955
956 # Main line
957 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
958 'newpage' => $isnew, # show, when one have this flag
959 'minor' => $allMinors, # show only, when all have this flag
960 'unpatrolled' => $unpatrolled, # show, when one have this flag
961 'bot' => $allBots, # show only, when all have this flag
962 ) );
963
964 # Timestamp
965 $r .= '&#160;' . $block[0]->timestamp . '&#160;</td><td>';
966
967 # Article link
968 if ( $namehidden ) {
969 $r .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
970 } elseif ( $allLogs ) {
971 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
972 } else {
973 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
974 }
975
976 $r .= $this->getLanguage()->getDirMark();
977
978 $queryParams['curid'] = $curId;
979
980 # Changes message
981 static $nchanges = array();
982 static $sinceLastVisitMsg = array();
983
984 $n = count( $block );
985 if ( !isset( $nchanges[$n] ) ) {
986 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
987 }
988
989 $sinceLast = 0;
990 $unvisitedOldid = null;
991 foreach ( $block as $rcObj ) {
992 // Same logic as below inside main foreach
993 if ( $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched ) {
994 $sinceLast++;
995 $unvisitedOldid = $rcObj->mAttribs['rc_last_oldid'];
996 }
997 }
998 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
999 $sinceLastVisitMsg[$sinceLast] =
1000 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
1001 }
1002
1003 # Total change link
1004 $r .= ' ';
1005 $logtext = '';
1006 if ( !$allLogs ) {
1007 if ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
1008 $logtext .= $nchanges[$n];
1009 } elseif ( $isnew ) {
1010 $logtext .= $nchanges[$n];
1011 } else {
1012 $logtext .= Linker::link(
1013 $block[0]->getTitle(),
1014 $nchanges[$n],
1015 array(),
1016 $queryParams + array(
1017 'diff' => $currentRevision,
1018 'oldid' => $oldid,
1019 ),
1020 array( 'known', 'noclasses' )
1021 );
1022 if ( $sinceLast > 0 && $sinceLast < $n ) {
1023 $logtext .= $this->message['pipe-separator'] . Linker::link(
1024 $block[0]->getTitle(),
1025 $sinceLastVisitMsg[$sinceLast],
1026 array(),
1027 $queryParams + array(
1028 'diff' => $currentRevision,
1029 'oldid' => $unvisitedOldid,
1030 ),
1031 array( 'known', 'noclasses' )
1032 );
1033 }
1034 }
1035 }
1036
1037 # History
1038 if ( $allLogs ) {
1039 // don't show history link for logs
1040 } elseif ( $namehidden || !$block[0]->getTitle()->exists() ) {
1041 $logtext .= $this->message['pipe-separator'] . $this->message['enhancedrc-history'];
1042 } else {
1043 $params = $queryParams;
1044 $params['action'] = 'history';
1045
1046 $logtext .= $this->message['pipe-separator'] .
1047 Linker::linkKnown(
1048 $block[0]->getTitle(),
1049 $this->message['enhancedrc-history'],
1050 array(),
1051 $params
1052 );
1053 }
1054
1055 if ( $logtext !== '' ) {
1056 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
1057 }
1058
1059 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1060
1061 # Character difference (does not apply if only log items)
1062 if ( $wgRCShowChangedSize && !$allLogs ) {
1063 $last = 0;
1064 $first = count( $block ) - 1;
1065 # Some events (like logs) have an "empty" size, so we need to skip those...
1066 while ( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) {
1067 $last++;
1068 }
1069 while ( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) {
1070 $first--;
1071 }
1072 # Get net change
1073 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
1074
1075 if ( $chardiff == '' ) {
1076 $r .= ' ';
1077 } else {
1078 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
1079 }
1080 }
1081
1082 $r .= $users;
1083 $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers );
1084
1085 # Sub-entries
1086 foreach ( $block as $rcObj ) {
1087 # Classes to apply -- TODO implement
1088 $classes = array();
1089 $type = $rcObj->mAttribs['rc_type'];
1090
1091 $trClass = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
1092 ? ' class="mw-enhanced-watched"' : '';
1093
1094 $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
1095 $r .= $this->recentChangesFlags( array(
1096 'newpage' => $type == RC_NEW,
1097 'minor' => $rcObj->mAttribs['rc_minor'],
1098 'unpatrolled' => $rcObj->unpatrolled,
1099 'bot' => $rcObj->mAttribs['rc_bot'],
1100 ) );
1101 $r .= '&#160;</td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1102
1103 $params = $queryParams;
1104
1105 if ( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
1106 $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
1107 }
1108
1109 # Log timestamp
1110 if ( $type == RC_LOG ) {
1111 $link = $rcObj->timestamp;
1112 # Revision link
1113 } elseif ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
1114 $link = '<span class="history-deleted">' . $rcObj->timestamp . '</span> ';
1115 } else {
1116
1117 $link = Linker::linkKnown(
1118 $rcObj->getTitle(),
1119 $rcObj->timestamp,
1120 array(),
1121 $params
1122 );
1123 if ( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
1124 $link = '<span class="history-deleted">' . $link . '</span> ';
1125 }
1126 }
1127 $r .= $link . '</span>';
1128
1129 if ( !$type == RC_LOG || $type == RC_NEW ) {
1130 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink . $this->message['pipe-separator'] . $rcObj->lastlink )->escaped();
1131 }
1132 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1133
1134 # Character diff
1135 if ( $wgRCShowChangedSize ) {
1136 $cd = $this->formatCharacterDifference( $rcObj );
1137 if ( $cd !== '' ) {
1138 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
1139 }
1140 }
1141
1142 if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
1143 $r .= $this->insertLogEntry( $rcObj );
1144 } else {
1145 # User links
1146 $r .= $rcObj->userlink;
1147 $r .= $rcObj->usertalklink;
1148 $r .= $this->insertComment( $rcObj );
1149 }
1150
1151 # Rollback
1152 $this->insertRollback( $r, $rcObj );
1153 # Tags
1154 $this->insertTags( $r, $rcObj, $classes );
1155
1156 $r .= "</td></tr>\n";
1157 }
1158 $r .= "</table>\n";
1159
1160 $this->rcCacheIndex++;
1161
1162 wfProfileOut( __METHOD__ );
1163
1164 return $r;
1165 }
1166
1167 /**
1168 * Generate HTML for an arrow or placeholder graphic
1169 * @param string $dir one of '', 'd', 'l', 'r'
1170 * @param string $alt text
1171 * @param string $title text
1172 * @return String: HTML "<img>" tag
1173 */
1174 protected function arrow( $dir, $alt = '', $title = '' ) {
1175 global $wgStylePath;
1176 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1177 $encAlt = htmlspecialchars( $alt );
1178 $encTitle = htmlspecialchars( $title );
1179 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1180 }
1181
1182 /**
1183 * Generate HTML for a right- or left-facing arrow,
1184 * depending on language direction.
1185 * @return String: HTML "<img>" tag
1186 */
1187 protected function sideArrow() {
1188 $dir = $this->getLanguage()->isRTL() ? 'l' : 'r';
1189 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
1190 }
1191
1192 /**
1193 * Generate HTML for a down-facing arrow
1194 * depending on language direction.
1195 * @return String: HTML "<img>" tag
1196 */
1197 protected function downArrow() {
1198 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
1199 }
1200
1201 /**
1202 * Generate HTML for a spacer image
1203 * @return String: HTML "<img>" tag
1204 */
1205 protected function spacerArrow() {
1206 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1207 }
1208
1209 /**
1210 * Enhanced RC ungrouped line.
1211 *
1212 * @param $rcObj RecentChange
1213 * @return String: a HTML formatted line (generated using $r)
1214 */
1215 protected function recentChangesBlockLine( $rcObj ) {
1216 global $wgRCShowChangedSize;
1217
1218 wfProfileIn( __METHOD__ );
1219 $query['curid'] = $rcObj->mAttribs['rc_cur_id'];
1220
1221 $type = $rcObj->mAttribs['rc_type'];
1222 $logType = $rcObj->mAttribs['rc_log_type'];
1223 $classes = array( 'mw-enhanced-rc' );
1224 if ( $logType ) {
1225 # Log entry
1226 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
1227 . $logType . '-' . $rcObj->mAttribs['rc_title'] );
1228 } else {
1229 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' .
1230 $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
1231 }
1232 $classes[] = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
1233 ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
1234 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
1235 Html::openElement( 'tr' );
1236
1237 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
1238 # Flag and Timestamp
1239 if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
1240 $r .= $this->recentChangesFlags( array() ); // no flags, but need the placeholders
1241 } else {
1242 $r .= $this->recentChangesFlags( array(
1243 'newpage' => $type == RC_NEW,
1244 'minor' => $rcObj->mAttribs['rc_minor'],
1245 'unpatrolled' => $rcObj->unpatrolled,
1246 'bot' => $rcObj->mAttribs['rc_bot'],
1247 ) );
1248 }
1249 $r .= '&#160;' . $rcObj->timestamp . '&#160;</td><td>';
1250 # Article or log link
1251 if ( $logType ) {
1252 $logPage = new LogPage( $logType );
1253 $logTitle = SpecialPage::getTitleFor( 'Log', $logType );
1254 $logName = $logPage->getName()->escaped();
1255 $r .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logTitle, $logName ) )->escaped();
1256 } else {
1257 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
1258 }
1259 # Diff and hist links
1260 if ( $type != RC_LOG ) {
1261 $query['action'] = 'history';
1262 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown(
1263 $rcObj->getTitle(),
1264 $this->message['hist'],
1265 array(),
1266 $query
1267 ) )->escaped();
1268 }
1269 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1270 # Character diff
1271 if ( $wgRCShowChangedSize ) {
1272 $cd = $this->formatCharacterDifference( $rcObj );
1273 if ( $cd !== '' ) {
1274 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
1275 }
1276 }
1277
1278 if ( $type == RC_LOG ) {
1279 $r .= $this->insertLogEntry( $rcObj );
1280 } else {
1281 $r .= ' ' . $rcObj->userlink . $rcObj->usertalklink;
1282 $r .= $this->insertComment( $rcObj );
1283 $this->insertRollback( $r, $rcObj );
1284 }
1285
1286 # Tags
1287 $this->insertTags( $r, $rcObj, $classes );
1288 # Show how many people are watching this if enabled
1289 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers );
1290
1291 $r .= "</td></tr></table>\n";
1292
1293 wfProfileOut( __METHOD__ );
1294
1295 return $r;
1296 }
1297
1298 /**
1299 * If enhanced RC is in use, this function takes the previously cached
1300 * RC lines, arranges them, and outputs the HTML
1301 *
1302 * @return string
1303 */
1304 protected function recentChangesBlock() {
1305 if ( count ( $this->rc_cache ) == 0 ) {
1306 return '';
1307 }
1308
1309 wfProfileIn( __METHOD__ );
1310
1311 $blockOut = '';
1312 foreach ( $this->rc_cache as $block ) {
1313 if ( count( $block ) < 2 ) {
1314 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1315 } else {
1316 $blockOut .= $this->recentChangesBlockGroup( $block );
1317 }
1318 }
1319
1320 wfProfileOut( __METHOD__ );
1321
1322 return '<div>' . $blockOut . '</div>';
1323 }
1324
1325 /**
1326 * Returns text for the end of RC
1327 * If enhanced RC is in use, returns pretty much all the text
1328 * @return string
1329 */
1330 public function endRecentChangesList() {
1331 return $this->recentChangesBlock() . parent::endRecentChangesList();
1332 }
1333
1334 }