Introducing ContentGetParserOutput hook.
[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', '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 protected function recentChangesFlags( $flags, $nothing = '&#160;' ) {
140 $f = '';
141 foreach ( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ) {
142 $f .= isset( $flags[$flag] ) && $flags[$flag]
143 ? self::flag( $flag )
144 : $nothing;
145 }
146 return $f;
147 }
148
149 /**
150 * Provide the "<abbr>" element appropriate to a given abbreviated flag,
151 * namely the flag indicating a new page, a minor edit, a bot edit, or an
152 * unpatrolled edit. By default in English it will contain "N", "m", "b",
153 * "!" respectively, plus it will have an appropriate title and class.
154 *
155 * @param string $flag 'newpage', 'unpatrolled', 'minor', or 'bot'
156 * @return String: Raw HTML
157 */
158 public static function flag( $flag ) {
159 static $messages = null;
160 if ( is_null( $messages ) ) {
161 $messages = array(
162 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
163 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
164 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
165 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
166 );
167 foreach ( $messages as &$value ) {
168 $value[0] = wfMessage( $value[0] )->escaped();
169 $value[1] = wfMessage( $value[1] )->escaped();
170 }
171 }
172
173 # Inconsistent naming, bleh
174 $map = array(
175 'newpage' => 'newpage',
176 'minor' => 'minoredit',
177 'bot' => 'botedit',
178 'unpatrolled' => 'unpatrolled',
179 'minoredit' => 'minoredit',
180 'botedit' => 'botedit',
181 );
182 $flag = $map[$flag];
183
184 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</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 global $wgUseRCPatrol;
366
367 $params = array();
368
369 // In case we got a page creation which is yet unpatrolled and
370 // recent changes patrolling is enabled, the user probably rather
371 // wants to patrol the whole page (first revision) instead of seeing
372 // a patrollink for the current revision.
373 if ( $wgUseRCPatrol && $unpatrolled && $rc->getAttribute( 'rc_type' ) == RC_NEW ) {
374 $params['patrolpage'] = 1;
375 }
376
377 $articlelink = Linker::linkKnown(
378 $rc->getTitle(),
379 null,
380 array( 'class' => 'mw-changeslist-title' ),
381 $params
382 );
383 if ( $this->isDeleted( $rc, Revision::DELETED_TEXT ) ) {
384 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
385 }
386 # To allow for boldening pages watched by this user
387 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
388 # RTL/LTR marker
389 $articlelink .= $this->getLanguage()->getDirMark();
390
391 wfRunHooks( 'ChangesListInsertArticleLink',
392 array( &$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched ) );
393
394 $s .= " $articlelink";
395 }
396
397 /**
398 * Get the timestamp from $rc formatted with current user's settings
399 * and a separator
400 *
401 * @param $rc RecentChange
402 * @return string HTML fragment
403 */
404 public function getTimestamp( $rc ) {
405 return $this->message['semicolon-separator'] . '<span class="mw-changeslist-date">' .
406 $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() ) . '</span> <span class="mw-changeslist-separator">. .</span> ';
407 }
408
409 /**
410 * Insert time timestamp string from $rc into $s
411 *
412 * @param string $s HTML to update
413 * @param $rc RecentChange
414 */
415 public function insertTimestamp( &$s, $rc ) {
416 $s .= $this->getTimestamp( $rc );
417 }
418
419 /**
420 * Insert links to user page, user talk page and eventually a blocking link
421 *
422 * @param &$s String HTML to update
423 * @param &$rc RecentChange
424 */
425 public function insertUserRelatedLinks( &$s, &$rc ) {
426 if ( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
427 $s .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
428 } else {
429 $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'],
430 $rc->mAttribs['rc_user_text'] );
431 $s .= Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
432 }
433 }
434
435 /**
436 * Insert a formatted action
437 *
438 * @param $rc RecentChange
439 * @return string
440 */
441 public function insertLogEntry( $rc ) {
442 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
443 $formatter->setContext( $this->getContext() );
444 $formatter->setShowUserToolLinks( true );
445 $mark = $this->getLanguage()->getDirMark();
446 return $formatter->getActionText() . " $mark" . $formatter->getComment();
447 }
448
449 /**
450 * Insert a formatted comment
451 * @param $rc RecentChange
452 * @return string
453 */
454 public function insertComment( $rc ) {
455 if ( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
456 if ( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
457 return ' <span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
458 } else {
459 return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
460 }
461 }
462 return '';
463 }
464
465 /**
466 * Check whether to enable recent changes patrol features
467 * @return Boolean
468 */
469 public static function usePatrol() {
470 global $wgUser;
471 return $wgUser->useRCPatrol();
472 }
473
474 /**
475 * Returns the string which indicates the number of watching users
476 * @return string
477 */
478 protected function numberofWatchingusers( $count ) {
479 static $cache = array();
480 if ( $count > 0 ) {
481 if ( !isset( $cache[$count] ) ) {
482 $cache[$count] = $this->msg( 'number_of_watching_users_RCview' )->numParams( $count )->escaped();
483 }
484 return $cache[$count];
485 } else {
486 return '';
487 }
488 }
489
490 /**
491 * Determine if said field of a revision is hidden
492 * @param $rc RCCacheEntry
493 * @param $field Integer: one of DELETED_* bitfield constants
494 * @return Boolean
495 */
496 public static function isDeleted( $rc, $field ) {
497 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
498 }
499
500 /**
501 * Determine if the current user is allowed to view a particular
502 * field of this revision, if it's marked as deleted.
503 * @param $rc RCCacheEntry
504 * @param $field Integer
505 * @param $user User object to check, or null to use $wgUser
506 * @return Boolean
507 */
508 public static function userCan( $rc, $field, User $user = null ) {
509 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
510 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
511 } else {
512 return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
513 }
514 }
515
516 /**
517 * @param $link string
518 * @param $watched bool
519 * @return string
520 */
521 protected function maybeWatchedLink( $link, $watched = false ) {
522 if ( $watched ) {
523 return '<strong class="mw-watched">' . $link . '</strong>';
524 } else {
525 return '<span class="mw-rc-unwatched">' . $link . '</span>';
526 }
527 }
528
529 /** Inserts a rollback link
530 *
531 * @param $s string
532 * @param $rc RecentChange
533 */
534 public function insertRollback( &$s, &$rc ) {
535 if ( $rc->mAttribs['rc_type'] != RC_NEW && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) {
536 $page = $rc->getTitle();
537 /** Check for rollback and edit permissions, disallow special pages, and only
538 * show a link on the top-most revision */
539 if ( $this->getUser()->isAllowed( 'rollback' ) && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] )
540 {
541 $rev = new Revision( array(
542 'title' => $page,
543 'id' => $rc->mAttribs['rc_this_oldid'],
544 'user' => $rc->mAttribs['rc_user'],
545 'user_text' => $rc->mAttribs['rc_user_text'],
546 'deleted' => $rc->mAttribs['rc_deleted']
547 ) );
548 $s .= ' ' . Linker::generateRollback( $rev, $this->getContext() );
549 }
550 }
551 }
552
553 /**
554 * @param $s string
555 * @param $rc RecentChange
556 * @param $classes
557 */
558 public function insertTags( &$s, &$rc, &$classes ) {
559 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
560 return;
561 }
562
563 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' );
564 $classes = array_merge( $classes, $newClasses );
565 $s .= ' ' . $tagSummary;
566 }
567
568 public function insertExtra( &$s, &$rc, &$classes ) {
569 // Empty, used for subclasses to add anything special.
570 }
571
572 protected function showAsUnpatrolled( RecentChange $rc ) {
573 $unpatrolled = false;
574 if ( !$rc->mAttribs['rc_patrolled'] ) {
575 if ( $this->getUser()->useRCPatrol() ) {
576 $unpatrolled = true;
577 } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs['rc_type'] == RC_NEW ) {
578 $unpatrolled = true;
579 }
580 }
581 return $unpatrolled;
582 }
583 }
584
585 /**
586 * Generate a list of changes using the good old system (no javascript)
587 */
588 class OldChangesList extends ChangesList {
589 /**
590 * Format a line using the old system (aka without any javascript).
591 *
592 * @param $rc RecentChange, passed by reference
593 * @param bool $watched (default false)
594 * @param int $linenumber (default null)
595 *
596 * @return string|bool
597 */
598 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
599 global $wgRCShowChangedSize;
600 wfProfileIn( __METHOD__ );
601
602 # Should patrol-related stuff be shown?
603 $unpatrolled = $this->showAsUnpatrolled( $rc );
604
605 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
606 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
607
608 $s = '';
609 $classes = array();
610 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
611 if ( $linenumber ) {
612 if ( $linenumber & 1 ) {
613 $classes[] = 'mw-line-odd';
614 } else {
615 $classes[] = 'mw-line-even';
616 }
617 }
618
619 // Indicate watched status on the line to allow for more
620 // comprehensive styling.
621 $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
622 ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
623
624 // Moved pages (very very old, not supported anymore)
625 if ( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
626 // Log entries
627 } elseif ( $rc->mAttribs['rc_log_type'] ) {
628 $logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] );
629 $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] );
630 // Log entries (old format) or log targets, and special pages
631 } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
632 list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $rc->mAttribs['rc_title'] );
633 if ( $name == 'Log' ) {
634 $this->insertLog( $s, $rc->getTitle(), $subpage );
635 }
636 // Regular entries
637 } else {
638 $this->insertDiffHist( $s, $rc, $unpatrolled );
639 # M, N, b and ! (minor, new, bot and unpatrolled)
640 $s .= $this->recentChangesFlags(
641 array(
642 'newpage' => $rc->mAttribs['rc_type'] == RC_NEW,
643 'minor' => $rc->mAttribs['rc_minor'],
644 'unpatrolled' => $unpatrolled,
645 'bot' => $rc->mAttribs['rc_bot']
646 ),
647 ''
648 );
649 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
650 }
651 # Edit/log timestamp
652 $this->insertTimestamp( $s, $rc );
653 # Bytes added or removed
654 if ( $wgRCShowChangedSize ) {
655 $cd = $this->formatCharacterDifference( $rc );
656 if ( $cd !== '' ) {
657 $s .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
658 }
659 }
660
661 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
662 $s .= $this->insertLogEntry( $rc );
663 } else {
664 # User tool links
665 $this->insertUserRelatedLinks( $s, $rc );
666 # LTR/RTL direction mark
667 $s .= $this->getLanguage()->getDirMark();
668 $s .= $this->insertComment( $rc );
669 }
670
671 # Tags
672 $this->insertTags( $s, $rc, $classes );
673 # Rollback
674 $this->insertRollback( $s, $rc );
675 # For subclasses
676 $this->insertExtra( $s, $rc, $classes );
677
678 # How many users watch this page
679 if ( $rc->numberofWatchingusers > 0 ) {
680 $s .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers );
681 }
682
683 if ( $this->watchlist ) {
684 $classes[] = Sanitizer::escapeClass( 'watchlist-' . $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
685 }
686
687 if ( !wfRunHooks( 'OldChangesListRecentChangesLine', array( &$this, &$s, $rc, &$classes ) ) ) {
688 wfProfileOut( __METHOD__ );
689 return false;
690 }
691
692 wfProfileOut( __METHOD__ );
693 return "$dateheader<li class=\"" . implode( ' ', $classes ) . "\">" . $s . "</li>\n";
694 }
695 }
696
697 /**
698 * Generate a list of changes using an Enhanced system (uses javascript).
699 */
700 class EnhancedChangesList extends ChangesList {
701
702 protected $rc_cache;
703
704 /**
705 * Add the JavaScript file for enhanced changeslist
706 * @return String
707 */
708 public function beginRecentChangesList() {
709 $this->rc_cache = array();
710 $this->rcMoveIndex = 0;
711 $this->rcCacheIndex = 0;
712 $this->lastdate = '';
713 $this->rclistOpen = false;
714 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
715 return '';
716 }
717 /**
718 * Format a line for enhanced recentchange (aka with javascript and block of lines).
719 *
720 * @param $baseRC RecentChange
721 * @param $watched bool
722 *
723 * @return string
724 */
725 public function recentChangesLine( &$baseRC, $watched = false ) {
726 wfProfileIn( __METHOD__ );
727
728 # Create a specialised object
729 $rc = RCCacheEntry::newFromParent( $baseRC );
730
731 $curIdEq = array( 'curid' => $rc->mAttribs['rc_cur_id'] );
732
733 # If it's a new day, add the headline and flush the cache
734 $date = $this->getLanguage()->userDate( $rc->mAttribs['rc_timestamp'], $this->getUser() );
735 $ret = '';
736 if ( $date != $this->lastdate ) {
737 # Process current cache
738 $ret = $this->recentChangesBlock();
739 $this->rc_cache = array();
740 $ret .= Xml::element( 'h4', null, $date ) . "\n";
741 $this->lastdate = $date;
742 }
743
744 # Should patrol-related stuff be shown?
745 $rc->unpatrolled = $this->showAsUnpatrolled( $rc );
746
747 $showdifflinks = true;
748 # Make article link
749 $type = $rc->mAttribs['rc_type'];
750 $logType = $rc->mAttribs['rc_log_type'];
751 // Page moves, very old style, not supported anymore
752 if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
753 // New unpatrolled pages
754 } elseif ( $rc->unpatrolled && $type == RC_NEW ) {
755 $clink = Linker::linkKnown( $rc->getTitle() );
756 // Log entries
757 } elseif ( $type == RC_LOG ) {
758 if ( $logType ) {
759 $logtitle = SpecialPage::getTitleFor( 'Log', $logType );
760 $logpage = new LogPage( $logType );
761 $logname = $logpage->getName()->escaped();
762 $clink = $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logtitle, $logname ) )->escaped();
763 } else {
764 $clink = Linker::link( $rc->getTitle() );
765 }
766 $watched = false;
767 // Log entries (old format) and special pages
768 } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
769 wfDebug( "Unexpected special page in recentchanges\n" );
770 $clink = '';
771 // Edits
772 } else {
773 $clink = Linker::linkKnown( $rc->getTitle() );
774 }
775
776 # Don't show unusable diff links
777 if ( !ChangesList::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
778 $showdifflinks = false;
779 }
780
781 $time = $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() );
782 $rc->watched = $watched;
783 $rc->link = $clink;
784 $rc->timestamp = $time;
785 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
786
787 # Make "cur" and "diff" links. Do not use link(), it is too slow if
788 # called too many times (50% of CPU time on RecentChanges!).
789 $thisOldid = $rc->mAttribs['rc_this_oldid'];
790 $lastOldid = $rc->mAttribs['rc_last_oldid'];
791
792 $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $thisOldid );
793 $querydiff = $curIdEq + array( 'diff' => $thisOldid, 'oldid' => $lastOldid );
794
795 if ( !$showdifflinks ) {
796 $curLink = $this->message['cur'];
797 $diffLink = $this->message['diff'];
798 } elseif ( in_array( $type, array( RC_NEW, RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
799 if ( $type != RC_NEW ) {
800 $curLink = $this->message['cur'];
801 } else {
802 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
803 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
804 }
805 $diffLink = $this->message['diff'];
806 } else {
807 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
808 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
809 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
810 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
811 }
812
813 # Make "last" link
814 if ( !$showdifflinks || !$lastOldid ) {
815 $lastLink = $this->message['last'];
816 } elseif ( in_array( $type, array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
817 $lastLink = $this->message['last'];
818 } else {
819 $lastLink = Linker::linkKnown( $rc->getTitle(), $this->message['last'],
820 array(), $curIdEq + array( 'diff' => $thisOldid, 'oldid' => $lastOldid ) );
821 }
822
823 # Make user links
824 if ( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
825 $rc->userlink = ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
826 } else {
827 $rc->userlink = Linker::userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
828 $rc->usertalklink = Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
829 }
830
831 $rc->lastlink = $lastLink;
832 $rc->curlink = $curLink;
833 $rc->difflink = $diffLink;
834
835 # Put accumulated information into the cache, for later display
836 # Page moves go on their own line
837 $title = $rc->getTitle();
838 $secureName = $title->getPrefixedDBkey();
839 if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
840 # Use an @ character to prevent collision with page names
841 $this->rc_cache['@@' . ( $this->rcMoveIndex++ )] = array( $rc );
842 } else {
843 # Logs are grouped by type
844 if ( $type == RC_LOG ) {
845 $secureName = SpecialPage::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
846 }
847 if ( !isset( $this->rc_cache[$secureName] ) ) {
848 $this->rc_cache[$secureName] = array();
849 }
850
851 array_push( $this->rc_cache[$secureName], $rc );
852 }
853
854 wfProfileOut( __METHOD__ );
855
856 return $ret;
857 }
858
859 /**
860 * Enhanced RC group
861 * @return string
862 */
863 protected function recentChangesBlockGroup( $block ) {
864 global $wgRCShowChangedSize;
865
866 wfProfileIn( __METHOD__ );
867
868 # Add the namespace and title of the block as part of the class
869 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
870 if ( $block[0]->mAttribs['rc_log_type'] ) {
871 # Log entry
872 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
873 . $block[0]->mAttribs['rc_log_type'] . '-' . $block[0]->mAttribs['rc_title'] );
874 } else {
875 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns'
876 . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
877 }
878 $classes[] = $block[0]->watched && $block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched
879 ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
880 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
881 Html::openElement( 'tr' );
882
883 # Collate list of users
884 $userlinks = array();
885 # Other properties
886 $unpatrolled = false;
887 $isnew = false;
888 $allBots = true;
889 $allMinors = true;
890 $curId = $currentRevision = 0;
891 # Some catalyst variables...
892 $namehidden = true;
893 $allLogs = true;
894 foreach ( $block as $rcObj ) {
895 $oldid = $rcObj->mAttribs['rc_last_oldid'];
896 if ( $rcObj->mAttribs['rc_type'] == RC_NEW ) {
897 $isnew = true;
898 }
899 // If all log actions to this page were hidden, then don't
900 // give the name of the affected page for this block!
901 if ( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
902 $namehidden = false;
903 }
904 $u = $rcObj->userlink;
905 if ( !isset( $userlinks[$u] ) ) {
906 $userlinks[$u] = 0;
907 }
908 if ( $rcObj->unpatrolled ) {
909 $unpatrolled = true;
910 }
911 if ( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
912 $allLogs = false;
913 }
914 # Get the latest entry with a page_id and oldid
915 # since logs may not have these.
916 if ( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
917 $curId = $rcObj->mAttribs['rc_cur_id'];
918 }
919 if ( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
920 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
921 }
922
923 if ( !$rcObj->mAttribs['rc_bot'] ) {
924 $allBots = false;
925 }
926 if ( !$rcObj->mAttribs['rc_minor'] ) {
927 $allMinors = false;
928 }
929
930 $userlinks[$u]++;
931 }
932
933 # Sort the list and convert to text
934 krsort( $userlinks );
935 asort( $userlinks );
936 $users = array();
937 foreach ( $userlinks as $userlink => $count ) {
938 $text = $userlink;
939 $text .= $this->getLanguage()->getDirMark();
940 if ( $count > 1 ) {
941 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->formatNum( $count ) . '×' )->escaped();
942 }
943 array_push( $users, $text );
944 }
945
946 $users = ' <span class="changedby">'
947 . $this->msg( 'brackets' )->rawParams(
948 implode( $this->message['semicolon-separator'], $users )
949 )->escaped() . '</span>';
950
951 $tl = '<span class="mw-collapsible-toggle mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
952 $r .= "<td>$tl</td>";
953
954 # Main line
955 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
956 'newpage' => $isnew, # show, when one have this flag
957 'minor' => $allMinors, # show only, when all have this flag
958 'unpatrolled' => $unpatrolled, # show, when one have this flag
959 'bot' => $allBots, # show only, when all have this flag
960 ) );
961
962 # Timestamp
963 $r .= '&#160;' . $block[0]->timestamp . '&#160;</td><td>';
964
965 # Article link
966 if ( $namehidden ) {
967 $r .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
968 } elseif ( $allLogs ) {
969 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
970 } else {
971 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
972 }
973
974 $r .= $this->getLanguage()->getDirMark();
975
976 $queryParams['curid'] = $curId;
977 # Changes message
978 $n = count( $block );
979 static $nchanges = array();
980 if ( !isset( $nchanges[$n] ) ) {
981 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
982 }
983 # Total change link
984 $r .= ' ';
985 $logtext = '';
986 if ( !$allLogs ) {
987 if ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
988 $logtext .= $nchanges[$n];
989 } elseif ( $isnew ) {
990 $logtext .= $nchanges[$n];
991 } else {
992 $params = $queryParams;
993 $params['diff'] = $currentRevision;
994 $params['oldid'] = $oldid;
995
996 $logtext .= Linker::link(
997 $block[0]->getTitle(),
998 $nchanges[$n],
999 array(),
1000 $params,
1001 array( 'known', 'noclasses' )
1002 );
1003 }
1004 }
1005
1006 # History
1007 if ( $allLogs ) {
1008 // don't show history link for logs
1009 } elseif ( $namehidden || !$block[0]->getTitle()->exists() ) {
1010 $logtext .= $this->message['pipe-separator'] . $this->message['hist'];
1011 } else {
1012 $params = $queryParams;
1013 $params['action'] = 'history';
1014
1015 $logtext .= $this->message['pipe-separator'] .
1016 Linker::linkKnown(
1017 $block[0]->getTitle(),
1018 $this->message['hist'],
1019 array(),
1020 $params
1021 );
1022 }
1023
1024 if ( $logtext !== '' ) {
1025 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
1026 }
1027
1028 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1029
1030 # Character difference (does not apply if only log items)
1031 if ( $wgRCShowChangedSize && !$allLogs ) {
1032 $last = 0;
1033 $first = count( $block ) - 1;
1034 # Some events (like logs) have an "empty" size, so we need to skip those...
1035 while ( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) {
1036 $last++;
1037 }
1038 while ( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) {
1039 $first--;
1040 }
1041 # Get net change
1042 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
1043
1044 if ( $chardiff == '' ) {
1045 $r .= ' ';
1046 } else {
1047 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
1048 }
1049 }
1050
1051 $r .= $users;
1052 $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers );
1053
1054 # Sub-entries
1055 foreach ( $block as $rcObj ) {
1056 # Classes to apply -- TODO implement
1057 $classes = array();
1058 $type = $rcObj->mAttribs['rc_type'];
1059
1060 $trClass = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
1061 ? ' class="mw-enhanced-watched"' : '';
1062
1063 $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
1064 $r .= $this->recentChangesFlags( array(
1065 'newpage' => $type == RC_NEW,
1066 'minor' => $rcObj->mAttribs['rc_minor'],
1067 'unpatrolled' => $rcObj->unpatrolled,
1068 'bot' => $rcObj->mAttribs['rc_bot'],
1069 ) );
1070 $r .= '&#160;</td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1071
1072 $params = $queryParams;
1073
1074 if ( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
1075 $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
1076 }
1077
1078 # Log timestamp
1079 if ( $type == RC_LOG ) {
1080 $link = $rcObj->timestamp;
1081 # Revision link
1082 } elseif ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
1083 $link = '<span class="history-deleted">' . $rcObj->timestamp . '</span> ';
1084 } else {
1085
1086 $link = Linker::linkKnown(
1087 $rcObj->getTitle(),
1088 $rcObj->timestamp,
1089 array(),
1090 $params
1091 );
1092 if ( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
1093 $link = '<span class="history-deleted">' . $link . '</span> ';
1094 }
1095 }
1096 $r .= $link . '</span>';
1097
1098 if ( !$type == RC_LOG || $type == RC_NEW ) {
1099 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink . $this->message['pipe-separator'] . $rcObj->lastlink )->escaped();
1100 }
1101 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1102
1103 # Character diff
1104 if ( $wgRCShowChangedSize ) {
1105 $cd = $this->formatCharacterDifference( $rcObj );
1106 if ( $cd !== '' ) {
1107 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
1108 }
1109 }
1110
1111 if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
1112 $r .= $this->insertLogEntry( $rcObj );
1113 } else {
1114 # User links
1115 $r .= $rcObj->userlink;
1116 $r .= $rcObj->usertalklink;
1117 $r .= $this->insertComment( $rcObj );
1118 }
1119
1120 # Rollback
1121 $this->insertRollback( $r, $rcObj );
1122 # Tags
1123 $this->insertTags( $r, $rcObj, $classes );
1124
1125 $r .= "</td></tr>\n";
1126 }
1127 $r .= "</table>\n";
1128
1129 $this->rcCacheIndex++;
1130
1131 wfProfileOut( __METHOD__ );
1132
1133 return $r;
1134 }
1135
1136 /**
1137 * Generate HTML for an arrow or placeholder graphic
1138 * @param string $dir one of '', 'd', 'l', 'r'
1139 * @param string $alt text
1140 * @param string $title text
1141 * @return String: HTML "<img>" tag
1142 */
1143 protected function arrow( $dir, $alt = '', $title = '' ) {
1144 global $wgStylePath;
1145 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1146 $encAlt = htmlspecialchars( $alt );
1147 $encTitle = htmlspecialchars( $title );
1148 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1149 }
1150
1151 /**
1152 * Generate HTML for a right- or left-facing arrow,
1153 * depending on language direction.
1154 * @return String: HTML "<img>" tag
1155 */
1156 protected function sideArrow() {
1157 $dir = $this->getLanguage()->isRTL() ? 'l' : 'r';
1158 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
1159 }
1160
1161 /**
1162 * Generate HTML for a down-facing arrow
1163 * depending on language direction.
1164 * @return String: HTML "<img>" tag
1165 */
1166 protected function downArrow() {
1167 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
1168 }
1169
1170 /**
1171 * Generate HTML for a spacer image
1172 * @return String: HTML "<img>" tag
1173 */
1174 protected function spacerArrow() {
1175 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1176 }
1177
1178 /**
1179 * Enhanced RC ungrouped line.
1180 *
1181 * @param $rcObj RecentChange
1182 * @return String: a HTML formatted line (generated using $r)
1183 */
1184 protected function recentChangesBlockLine( $rcObj ) {
1185 global $wgRCShowChangedSize;
1186
1187 wfProfileIn( __METHOD__ );
1188 $query['curid'] = $rcObj->mAttribs['rc_cur_id'];
1189
1190 $type = $rcObj->mAttribs['rc_type'];
1191 $logType = $rcObj->mAttribs['rc_log_type'];
1192 $classes = array( 'mw-enhanced-rc' );
1193 if ( $logType ) {
1194 # Log entry
1195 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
1196 . $logType . '-' . $rcObj->mAttribs['rc_title'] );
1197 } else {
1198 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' .
1199 $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
1200 }
1201 $classes[] = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
1202 ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
1203 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
1204 Html::openElement( 'tr' );
1205
1206 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
1207 # Flag and Timestamp
1208 if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
1209 $r .= '&#160;&#160;&#160;&#160;'; // 4 flags -> 4 spaces
1210 } else {
1211 $r .= $this->recentChangesFlags( array(
1212 'newpage' => $type == RC_NEW,
1213 'minor' => $rcObj->mAttribs['rc_minor'],
1214 'unpatrolled' => $rcObj->unpatrolled,
1215 'bot' => $rcObj->mAttribs['rc_bot'],
1216 ) );
1217 }
1218 $r .= '&#160;' . $rcObj->timestamp . '&#160;</td><td>';
1219 # Article or log link
1220 if ( $logType ) {
1221 $logPage = new LogPage( $logType );
1222 $logTitle = SpecialPage::getTitleFor( 'Log', $logType );
1223 $logName = $logPage->getName()->escaped();
1224 $r .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logTitle, $logName ) )->escaped();
1225 } else {
1226 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
1227 }
1228 # Diff and hist links
1229 if ( $type != RC_LOG ) {
1230 $query['action'] = 'history';
1231 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown(
1232 $rcObj->getTitle(),
1233 $this->message['hist'],
1234 array(),
1235 $query
1236 ) )->escaped();
1237 }
1238 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1239 # Character diff
1240 if ( $wgRCShowChangedSize ) {
1241 $cd = $this->formatCharacterDifference( $rcObj );
1242 if ( $cd !== '' ) {
1243 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
1244 }
1245 }
1246
1247 if ( $type == RC_LOG ) {
1248 $r .= $this->insertLogEntry( $rcObj );
1249 } else {
1250 $r .= ' ' . $rcObj->userlink . $rcObj->usertalklink;
1251 $r .= $this->insertComment( $rcObj );
1252 $this->insertRollback( $r, $rcObj );
1253 }
1254
1255 # Tags
1256 $this->insertTags( $r, $rcObj, $classes );
1257 # Show how many people are watching this if enabled
1258 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers );
1259
1260 $r .= "</td></tr></table>\n";
1261
1262 wfProfileOut( __METHOD__ );
1263
1264 return $r;
1265 }
1266
1267 /**
1268 * If enhanced RC is in use, this function takes the previously cached
1269 * RC lines, arranges them, and outputs the HTML
1270 *
1271 * @return string
1272 */
1273 protected function recentChangesBlock() {
1274 if ( count ( $this->rc_cache ) == 0 ) {
1275 return '';
1276 }
1277
1278 wfProfileIn( __METHOD__ );
1279
1280 $blockOut = '';
1281 foreach ( $this->rc_cache as $block ) {
1282 if ( count( $block ) < 2 ) {
1283 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1284 } else {
1285 $blockOut .= $this->recentChangesBlockGroup( $block );
1286 }
1287 }
1288
1289 wfProfileOut( __METHOD__ );
1290
1291 return '<div>' . $blockOut . '</div>';
1292 }
1293
1294 /**
1295 * Returns text for the end of RC
1296 * If enhanced RC is in use, returns pretty much all the text
1297 * @return string
1298 */
1299 public function endRecentChangesList() {
1300 return $this->recentChangesBlock() . parent::endRecentChangesList();
1301 }
1302
1303 }