Enable users to watch category membership changes #2
[lhc/web/wiklou.git] / includes / changes / EnhancedChangesList.php
1 <?php
2 /**
3 * Generates a list of changes using an Enhanced system (uses javascript).
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 class EnhancedChangesList extends ChangesList {
24
25 /**
26 * @var RCCacheEntryFactory
27 */
28 protected $cacheEntryFactory;
29
30 /**
31 * @var array Array of array of RCCacheEntry
32 */
33 protected $rc_cache;
34
35 /**
36 * @param IContextSource|Skin $obj
37 * @throws MWException
38 */
39 public function __construct( $obj ) {
40 if ( $obj instanceof Skin ) {
41 // @todo: deprecate constructing with Skin
42 $context = $obj->getContext();
43 } else {
44 if ( !$obj instanceof IContextSource ) {
45 throw new MWException( 'EnhancedChangesList must be constructed with a '
46 . 'context source or skin.' );
47 }
48
49 $context = $obj;
50 }
51
52 parent::__construct( $context );
53
54 // message is set by the parent ChangesList class
55 $this->cacheEntryFactory = new RCCacheEntryFactory(
56 $context,
57 $this->message
58 );
59 }
60
61 /**
62 * Add the JavaScript file for enhanced changeslist
63 * @return string
64 */
65 public function beginRecentChangesList() {
66 $this->rc_cache = array();
67 $this->rcMoveIndex = 0;
68 $this->rcCacheIndex = 0;
69 $this->lastdate = '';
70 $this->rclistOpen = false;
71 $this->getOutput()->addModuleStyles( array(
72 'mediawiki.special.changeslist',
73 'mediawiki.special.changeslist.enhanced',
74 ) );
75 $this->getOutput()->addModules( array(
76 'jquery.makeCollapsible',
77 'mediawiki.icon',
78 ) );
79
80 return '<div class="mw-changeslist">';
81 }
82
83 /**
84 * Format a line for enhanced recentchange (aka with javascript and block of lines).
85 *
86 * @param RecentChange $baseRC
87 * @param bool $watched
88 *
89 * @return string
90 */
91 public function recentChangesLine( &$baseRC, $watched = false ) {
92
93 $date = $this->getLanguage()->userDate(
94 $baseRC->mAttribs['rc_timestamp'],
95 $this->getUser()
96 );
97
98 $ret = '';
99
100 # If it's a new day, add the headline and flush the cache
101 if ( $date != $this->lastdate ) {
102 # Process current cache
103 $ret = $this->recentChangesBlock();
104 $this->rc_cache = array();
105 $ret .= Xml::element( 'h4', null, $date ) . "\n";
106 $this->lastdate = $date;
107 }
108
109 $cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $baseRC, $watched );
110 $this->addCacheEntry( $cacheEntry );
111
112 return $ret;
113 }
114
115 /**
116 * Put accumulated information into the cache, for later display.
117 * Page moves go on their own line.
118 *
119 * @param RCCacheEntry $cacheEntry
120 */
121 protected function addCacheEntry( RCCacheEntry $cacheEntry ) {
122 $cacheGroupingKey = $this->makeCacheGroupingKey( $cacheEntry );
123
124 if ( !isset( $this->rc_cache[$cacheGroupingKey] ) ) {
125 $this->rc_cache[$cacheGroupingKey] = array();
126 }
127
128 array_push( $this->rc_cache[$cacheGroupingKey], $cacheEntry );
129 }
130
131 /**
132 * @todo use rc_source to group, if set; fallback to rc_type
133 *
134 * @param RCCacheEntry $cacheEntry
135 *
136 * @return string
137 */
138 protected function makeCacheGroupingKey( RCCacheEntry $cacheEntry ) {
139 $title = $cacheEntry->getTitle();
140 $cacheGroupingKey = $title->getPrefixedDBkey();
141
142 $type = $cacheEntry->mAttribs['rc_type'];
143
144 if ( $type == RC_LOG ) {
145 // Group by log type
146 $cacheGroupingKey = SpecialPage::getTitleFor(
147 'Log',
148 $cacheEntry->mAttribs['rc_log_type']
149 )->getPrefixedDBkey();
150 }
151
152 return $cacheGroupingKey;
153 }
154
155 /**
156 * Enhanced RC group
157 * @param RCCacheEntry[] $block
158 * @return string
159 */
160 protected function recentChangesBlockGroup( $block ) {
161
162 # Add the namespace and title of the block as part of the class
163 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
164 if ( $block[0]->mAttribs['rc_log_type'] ) {
165 # Log entry
166 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
167 . $block[0]->mAttribs['rc_log_type'] );
168 } else {
169 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns'
170 . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
171 }
172 $classes[] = $block[0]->watched && $block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched
173 ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
174 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
175 Html::openElement( 'tr' );
176
177 # Collate list of users
178 $userlinks = array();
179 # Other properties
180 $unpatrolled = false;
181 $isnew = false;
182 $allBots = true;
183 $allMinors = true;
184 $curId = 0;
185 # Some catalyst variables...
186 $namehidden = true;
187 $allLogs = true;
188 $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' );
189 foreach ( $block as $rcObj ) {
190 if ( $rcObj->mAttribs['rc_type'] == RC_NEW ) {
191 $isnew = true;
192 }
193 // If all log actions to this page were hidden, then don't
194 // give the name of the affected page for this block!
195 if ( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
196 $namehidden = false;
197 }
198 $u = $rcObj->userlink;
199 if ( !isset( $userlinks[$u] ) ) {
200 $userlinks[$u] = 0;
201 }
202 if ( $rcObj->unpatrolled ) {
203 $unpatrolled = true;
204 }
205 if ( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
206 $allLogs = false;
207 }
208 # Get the latest entry with a page_id and oldid
209 # since logs may not have these.
210 if ( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
211 $curId = $rcObj->mAttribs['rc_cur_id'];
212 }
213
214 if ( !$rcObj->mAttribs['rc_bot'] ) {
215 $allBots = false;
216 }
217 if ( !$rcObj->mAttribs['rc_minor'] ) {
218 $allMinors = false;
219 }
220
221 $userlinks[$u]++;
222 }
223
224 # Sort the list and convert to text
225 krsort( $userlinks );
226 asort( $userlinks );
227 $users = array();
228 foreach ( $userlinks as $userlink => $count ) {
229 $text = $userlink;
230 $text .= $this->getLanguage()->getDirMark();
231 if ( $count > 1 ) {
232 // @todo FIXME: Hardcoded '×'. Should be a message.
233 $formattedCount = $this->getLanguage()->formatNum( $count ) . '×';
234 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
235 }
236 array_push( $users, $text );
237 }
238
239 $users = ' <span class="changedby">'
240 . $this->msg( 'brackets' )->rawParams(
241 implode( $this->message['semicolon-separator'], $users )
242 )->escaped() . '</span>';
243
244 $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow ' .
245 'mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
246 $r .= "<td>$tl</td>";
247
248 # Main line
249 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
250 'newpage' => $isnew, # show, when one have this flag
251 'minor' => $allMinors, # show only, when all have this flag
252 'unpatrolled' => $unpatrolled, # show, when one have this flag
253 'bot' => $allBots, # show only, when all have this flag
254 ) );
255
256 # Timestamp
257 $r .= '&#160;' . $block[0]->timestamp . '&#160;</td><td>';
258
259 # Article link
260 if ( $namehidden ) {
261 $r .= ' <span class="history-deleted">' .
262 $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
263 } elseif ( $allLogs ) {
264 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
265 } else {
266 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
267 }
268
269 $r .= $this->getLanguage()->getDirMark();
270
271 $queryParams['curid'] = $curId;
272
273 # Sub-entries
274 $lines = '';
275 foreach ( $block as $i => $rcObj ) {
276 $line = $this->getLineData( $block, $rcObj, $queryParams );
277 $lines .= $line;
278 if ( !$line ) {
279 // completely ignore this RC entry if we don't want to render it
280 unset( $block[$i] );
281 }
282 }
283 // Further down are some assumptions that $block is a 0-indexed array
284 // with (count-1) as last key. Let's make sure it is.
285 $block = array_values( $block );
286 if ( empty( $block ) ) {
287 // if we can't show anything, don't display this block altogether
288 return '';
289 }
290
291 $r .= $this->getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden );
292
293 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
294
295 # Character difference (does not apply if only log items)
296 if ( $RCShowChangedSize && !$allLogs ) {
297 $last = 0;
298 $first = count( $block ) - 1;
299 # Some events (like logs) have an "empty" size, so we need to skip those...
300 while ( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) {
301 $last++;
302 }
303 while ( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) {
304 $first--;
305 }
306 # Get net change
307 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
308
309 if ( $chardiff == '' ) {
310 $r .= ' ';
311 } else {
312 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
313 }
314 }
315
316 $r .= $users;
317 $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers );
318 $r .= '</td></tr>';
319
320 if ( !$lines ) {
321 // if there are no lines to be rendered (all aborted by hook), don't render the block
322 return '';
323 }
324
325 $r .= $lines;
326 $r .= "</table>\n";
327
328 $this->rcCacheIndex++;
329
330 return $r;
331 }
332
333 /**
334 * @param RCCacheEntry[] $block
335 * @param RCCacheEntry $rcObj
336 * @param array $queryParams
337 * @return string
338 * @throws Exception
339 * @throws FatalError
340 * @throws MWException
341 */
342 protected function getLineData( array $block, RCCacheEntry $rcObj, array $queryParams = array() ) {
343 $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' );
344
345 # Classes to apply -- TODO implement
346 $classes = array();
347 $type = $rcObj->mAttribs['rc_type'];
348 $data = array();
349
350 $trClass = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
351 ? ' class="mw-enhanced-watched"' : '';
352 $separator = ' <span class="mw-changeslist-separator">. .</span> ';
353
354 $data['recentChangesFlags'] = array(
355 'newpage' => $type == RC_NEW,
356 'minor' => $rcObj->mAttribs['rc_minor'],
357 'unpatrolled' => $rcObj->unpatrolled,
358 'bot' => $rcObj->mAttribs['rc_bot'],
359 );
360
361 $params = $queryParams;
362
363 if ( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
364 $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
365 }
366
367 # Log timestamp
368 if ( $type == RC_LOG ) {
369 $link = $rcObj->timestamp;
370 # Revision link
371 } elseif ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
372 $link = '<span class="history-deleted">' . $rcObj->timestamp . '</span> ';
373 } else {
374 $link = Linker::linkKnown(
375 $rcObj->getTitle(),
376 $rcObj->timestamp,
377 array(),
378 $params
379 );
380 if ( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
381 $link = '<span class="history-deleted">' . $link . '</span> ';
382 }
383 }
384 $data['timestampLink'] = $link;
385
386 $currentAndLastLinks = '';
387 if ( !$type == RC_LOG || $type == RC_NEW ) {
388 $currentAndLastLinks .= ' ' . $this->msg( 'parentheses' )->rawParams(
389 $rcObj->curlink .
390 $this->message['pipe-separator'] .
391 $rcObj->lastlink
392 )->escaped();
393 }
394 $data['currentAndLastLinks'] = $currentAndLastLinks;
395 $data['separatorAfterCurrentAndLastLinks'] = $separator;
396
397 # Character diff
398 if ( $RCShowChangedSize ) {
399 $cd = $this->formatCharacterDifference( $rcObj );
400 if ( $cd !== '' ) {
401 $data['characterDiff'] = $cd;
402 $data['separatorAfterCharacterDiff'] = $separator;
403 }
404 }
405
406 if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
407 $data['logEntry'] = $this->insertLogEntry( $rcObj );
408 } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) {
409 $data['comment'] = $this->insertComment( $rcObj );
410 } else {
411 # User links
412 $data['userLink'] = $rcObj->userlink;
413 $data['userTalkLink'] = $rcObj->usertalklink;
414 $data['comment'] = $this->insertComment( $rcObj );
415 }
416
417 # Rollback
418 $data['rollback'] = $this->getRollback( $rcObj );
419
420 # Tags
421 $data['tags'] = $this->getTags( $rcObj, $classes );
422
423 // give the hook a chance to modify the data
424 $success = Hooks::run( 'EnhancedChangesListModifyLineData',
425 array( $this, &$data, $block, $rcObj ) );
426 if ( !$success ) {
427 // skip entry if hook aborted it
428 return '';
429 }
430
431 $line = '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
432 if ( isset( $data['recentChangesFlags'] ) ) {
433 $line .= $this->recentChangesFlags( $data['recentChangesFlags'] );
434 unset( $data['recentChangesFlags'] );
435 }
436 $line .= '&#160;</td><td class="mw-enhanced-rc-nested">';
437
438 if ( isset( $data['timestampLink'] ) ) {
439 $line .= '<span class="mw-enhanced-rc-time">' . $data['timestampLink'] . '</span>';
440 unset( $data['timestampLink'] );
441 }
442
443 // everything else: makes it easier for extensions to add or remove data
444 $line .= implode( '', $data );
445
446 $line .= "</td></tr>\n";
447
448 return $line;
449 }
450
451 /**
452 * Generates amount of changes (linking to diff ) & link to history.
453 *
454 * @param array $block
455 * @param array $queryParams
456 * @param bool $allLogs
457 * @param bool $isnew
458 * @param bool $namehidden
459 * @return string
460 */
461 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
462 if ( empty( $block ) ) {
463 return '';
464 }
465
466 # Changes message
467 static $nchanges = array();
468 static $sinceLastVisitMsg = array();
469
470 $n = count( $block );
471 if ( !isset( $nchanges[$n] ) ) {
472 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
473 }
474
475 $sinceLast = 0;
476 $unvisitedOldid = null;
477 /** @var $rcObj RCCacheEntry */
478 foreach ( $block as $rcObj ) {
479 // Same logic as below inside main foreach
480 if ( $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched ) {
481 $sinceLast++;
482 $unvisitedOldid = $rcObj->mAttribs['rc_last_oldid'];
483 }
484 }
485 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
486 $sinceLastVisitMsg[$sinceLast] =
487 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
488 }
489
490 $currentRevision = 0;
491 foreach ( $block as $rcObj ) {
492 if ( !$currentRevision ) {
493 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
494 }
495 }
496
497 # Total change link
498 $links = array();
499 /** @var $block0 RecentChange */
500 $block0 = $block[0];
501 $last = $block[count( $block ) - 1];
502 if ( !$allLogs && $rcObj->mAttribs['rc_type'] != RC_CATEGORIZE ) {
503 if ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
504 $links['total-changes'] = $nchanges[$n];
505 } elseif ( $isnew ) {
506 $links['total-changes'] = $nchanges[$n];
507 } else {
508 $links['total-changes'] = Linker::link(
509 $block0->getTitle(),
510 $nchanges[$n],
511 array(),
512 $queryParams + array(
513 'diff' => $currentRevision,
514 'oldid' => $last->mAttribs['rc_last_oldid'],
515 ),
516 array( 'known', 'noclasses' )
517 );
518 if ( $sinceLast > 0 && $sinceLast < $n ) {
519 $links['total-changes-since-last'] = Linker::link(
520 $block0->getTitle(),
521 $sinceLastVisitMsg[$sinceLast],
522 array(),
523 $queryParams + array(
524 'diff' => $currentRevision,
525 'oldid' => $unvisitedOldid,
526 ),
527 array( 'known', 'noclasses' )
528 );
529 }
530 }
531 }
532
533 # History
534 if ( $allLogs || $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE ) {
535 // don't show history link for logs
536 } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
537 $links['history'] = $this->message['enhancedrc-history'];
538 } else {
539 $params = $queryParams;
540 $params['action'] = 'history';
541
542 $links['history'] = Linker::linkKnown(
543 $block0->getTitle(),
544 $this->message['enhancedrc-history'],
545 array(),
546 $params
547 );
548 }
549
550 # Allow others to alter, remove or add to these links
551 Hooks::run( 'EnhancedChangesList::getLogText',
552 array( $this, &$links, $block ) );
553
554 if ( !$links ) {
555 return '';
556 }
557
558 $logtext = implode( $this->message['pipe-separator'], $links );
559 $logtext = $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
560 return ' ' . $logtext;
561 }
562
563 /**
564 * Enhanced RC ungrouped line.
565 *
566 * @param RecentChange|RCCacheEntry $rcObj
567 * @return string A HTML formatted line (generated using $r)
568 */
569 protected function recentChangesBlockLine( $rcObj ) {
570 $data = array();
571
572 $query['curid'] = $rcObj->mAttribs['rc_cur_id'];
573
574 $type = $rcObj->mAttribs['rc_type'];
575 $logType = $rcObj->mAttribs['rc_log_type'];
576 $classes = array( 'mw-enhanced-rc' );
577 if ( $logType ) {
578 # Log entry
579 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-' . $logType );
580 } else {
581 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' .
582 $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
583 }
584 $classes[] = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
585 ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
586
587 # Flag and Timestamp
588 $data['recentChangesFlags'] = array(
589 'newpage' => $type == RC_NEW,
590 'minor' => $rcObj->mAttribs['rc_minor'],
591 'unpatrolled' => $rcObj->unpatrolled,
592 'bot' => $rcObj->mAttribs['rc_bot'],
593 );
594 // timestamp is not really a link here, but is called timestampLink
595 // for consistency with EnhancedChangesListModifyLineData
596 $data['timestampLink'] = $rcObj->timestamp;
597
598 # Article or log link
599 if ( $logType ) {
600 $logPage = new LogPage( $logType );
601 $logTitle = SpecialPage::getTitleFor( 'Log', $logType );
602 $logName = $logPage->getName()->escaped();
603 $data['logLink'] = $this->msg( 'parentheses' )
604 ->rawParams( Linker::linkKnown( $logTitle, $logName ) )->escaped();
605 } else {
606 $data['articleLink'] = $this->getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
607 }
608
609 # Diff and hist links
610 if ( $type == RC_LOG && $type != RC_CATEGORIZE ) {
611 $query['action'] = 'history';
612 $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
613 }
614 $data['separatorAfterLinks'] = ' <span class="mw-changeslist-separator">. .</span> ';
615
616 # Character diff
617 if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) {
618 $cd = $this->formatCharacterDifference( $rcObj );
619 if ( $cd !== '' ) {
620 $data['characterDiff'] = $cd;
621 $data['separatorAftercharacterDiff'] = ' <span class="mw-changeslist-separator">. .</span> ';
622 }
623 }
624
625 if ( $type == RC_LOG ) {
626 $data['logEntry'] = $this->insertLogEntry( $rcObj );
627 } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) {
628 $data['comment'] = $this->insertComment( $rcObj );
629 } else {
630 $data['userLink'] = $rcObj->userlink;
631 $data['userTalkLink'] = $rcObj->usertalklink;
632 $data['comment'] = $this->insertComment( $rcObj );
633 if ( $type == RC_CATEGORIZE ) {
634 $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
635 }
636 $data['rollback'] = $this->getRollback( $rcObj );
637 }
638
639 # Tags
640 $data['tags'] = $this->getTags( $rcObj, $classes );
641
642 # Show how many people are watching this if enabled
643 $data['watchingUsers'] = $this->numberofWatchingusers( $rcObj->numberofWatchingusers );
644
645 // give the hook a chance to modify the data
646 $success = Hooks::run( 'EnhancedChangesListModifyBlockLineData',
647 array( $this, &$data, $rcObj ) );
648 if ( !$success ) {
649 // skip entry if hook aborted it
650 return '';
651 }
652
653 $line = Html::openElement( 'table', array( 'class' => $classes ) ) .
654 Html::openElement( 'tr' );
655 $line .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
656
657 if ( isset( $data['recentChangesFlags'] ) ) {
658 $line .= $this->recentChangesFlags( $data['recentChangesFlags'] );
659 unset( $data['recentChangesFlags'] );
660 }
661
662 if ( isset( $data['timestampLink'] ) ) {
663 $line .= '&#160;' . $data['timestampLink'];
664 unset( $data['timestampLink'] );
665 }
666 $line .= '&#160;</td><td>';
667
668 // everything else: makes it easier for extensions to add or remove data
669 $line .= implode( '', $data );
670
671 $line .= "</td></tr></table>\n";
672
673 return $line;
674 }
675
676 /**
677 * Returns value to be used in 'historyLink' element of $data param in
678 * EnhancedChangesListModifyBlockLineData hook.
679 *
680 * @since 1.27
681 *
682 * @param RCCacheEntry $rc
683 * @param array $query array of key/value pairs to append as a query string
684 * @return string HTML
685 */
686 public function getDiffHistLinks( RCCacheEntry $rc, array $query ) {
687 $pageTitle = $rc->getTitle();
688 if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) {
689 // For categorizations we must swap the category title with the page title!
690 $pageTitle = Title::newFromID( $rc->getAttribute( 'rc_cur_id' ) );
691 }
692
693 $retVal = ' ' . $this->msg( 'parentheses' )
694 ->rawParams( $rc->difflink . $this->message['pipe-separator'] . Linker::linkKnown(
695 $pageTitle,
696 $this->message['hist'],
697 array(),
698 $query
699 ) )->escaped();
700 return $retVal;
701 }
702
703 /**
704 * If enhanced RC is in use, this function takes the previously cached
705 * RC lines, arranges them, and outputs the HTML
706 *
707 * @return string
708 */
709 protected function recentChangesBlock() {
710 if ( count( $this->rc_cache ) == 0 ) {
711 return '';
712 }
713
714 $blockOut = '';
715 foreach ( $this->rc_cache as $block ) {
716 if ( count( $block ) < 2 ) {
717 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
718 } else {
719 $blockOut .= $this->recentChangesBlockGroup( $block );
720 }
721 }
722
723 return '<div>' . $blockOut . '</div>';
724 }
725
726 /**
727 * Returns text for the end of RC
728 * If enhanced RC is in use, returns pretty much all the text
729 * @return string
730 */
731 public function endRecentChangesList() {
732 return $this->recentChangesBlock() . '</div>';
733 }
734 }