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