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