bad5c5a1e5443005dad75784e55354785f77252c
[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', 'mw-changeslist-line' ];
176 if ( $block[0]->mAttribs['rc_log_type'] ) {
177 # Log entry
178 $tableClasses[] = 'mw-changeslist-log';
179 $tableClasses[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
180 . $block[0]->mAttribs['rc_log_type'] );
181 } else {
182 $tableClasses[] = 'mw-changeslist-edit';
183 $tableClasses[] = Sanitizer::escapeClass( 'mw-changeslist-ns'
184 . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
185 }
186 if ( $block[0]->watched
187 && $block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched
188 ) {
189 $tableClasses[] = 'mw-changeslist-line-watched';
190 } else {
191 $tableClasses[] = 'mw-changeslist-line-not-watched';
192 }
193
194 # Collate list of users
195 $userlinks = [];
196 # Other properties
197 $curId = 0;
198 # Some catalyst variables...
199 $namehidden = true;
200 $allLogs = true;
201 $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' );
202
203 # Default values for RC flags
204 $collectedRcFlags = [];
205 foreach ( $recentChangesFlags as $key => $value ) {
206 $flagGrouping = ( $recentChangesFlags[$key]['grouping'] ?? 'any' );
207 switch ( $flagGrouping ) {
208 case 'all':
209 $collectedRcFlags[$key] = true;
210 break;
211 case 'any':
212 $collectedRcFlags[$key] = false;
213 break;
214 default:
215 throw new DomainException( "Unknown grouping type \"{$flagGrouping}\"" );
216 }
217 }
218 foreach ( $block as $rcObj ) {
219 // If all log actions to this page were hidden, then don't
220 // give the name of the affected page for this block!
221 if ( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
222 $namehidden = false;
223 }
224 $u = $rcObj->userlink;
225 if ( !isset( $userlinks[$u] ) ) {
226 $userlinks[$u] = 0;
227 }
228 if ( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
229 $allLogs = false;
230 }
231 # Get the latest entry with a page_id and oldid
232 # since logs may not have these.
233 if ( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
234 $curId = $rcObj->mAttribs['rc_cur_id'];
235 }
236
237 $userlinks[$u]++;
238 }
239
240 # Sort the list and convert to text
241 krsort( $userlinks );
242 asort( $userlinks );
243 $users = [];
244 foreach ( $userlinks as $userlink => $count ) {
245 $text = $userlink;
246 $text .= $this->getLanguage()->getDirMark();
247 if ( $count > 1 ) {
248 $formattedCount = $this->msg( 'ntimes' )->numParams( $count )->escaped();
249 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
250 }
251 array_push( $users, $text );
252 }
253
254 # Article link
255 $articleLink = '';
256 $revDeletedMsg = false;
257 if ( $namehidden ) {
258 $revDeletedMsg = $this->msg( 'rev-deleted-event' )->escaped();
259 } elseif ( $allLogs ) {
260 $articleLink = $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
261 } else {
262 $articleLink = $this->getArticleLink( $block[0], $block[0]->unpatrolled, $block[0]->watched );
263 }
264
265 $queryParams['curid'] = $curId;
266
267 # Sub-entries
268 $lines = [];
269 foreach ( $block as $i => $rcObj ) {
270 $line = $this->getLineData( $block, $rcObj, $queryParams );
271 if ( !$line ) {
272 // completely ignore this RC entry if we don't want to render it
273 unset( $block[$i] );
274 continue;
275 }
276
277 // Roll up flags
278 foreach ( $line['recentChangesFlagsRaw'] as $key => $value ) {
279 $flagGrouping = ( $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] ) ?: false;
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 $prefix = '';
334 if ( is_callable( $this->changeLinePrefixer ) ) {
335 $prefix = call_user_func( $this->changeLinePrefixer, $block[0], $this, true );
336 }
337
338 $templateParams = [
339 'articleLink' => $articleLink,
340 'charDifference' => $charDifference,
341 'collectedRcFlags' => $this->recentChangesFlags( $collectedRcFlags ),
342 'languageDirMark' => $this->getLanguage()->getDirMark(),
343 'lines' => $lines,
344 'logText' => $logText,
345 'numberofWatchingusers' => $numberofWatchingusers,
346 'prefix' => $prefix,
347 'rev-deleted-event' => $revDeletedMsg,
348 'tableClasses' => $tableClasses,
349 'timestamp' => $block[0]->timestamp,
350 'fullTimestamp' => $block[0]->getAttribute( 'rc_timestamp' ),
351 'users' => $usersList,
352 ];
353
354 $this->rcCacheIndex++;
355
356 return $this->templateParser->processTemplate(
357 'EnhancedChangesListGroup',
358 $templateParams
359 );
360 }
361
362 /**
363 * @param RCCacheEntry[] $block
364 * @param RCCacheEntry $rcObj
365 * @param array $queryParams
366 * @return array
367 * @throws Exception
368 * @throws FatalError
369 * @throws MWException
370 */
371 protected function getLineData( array $block, RCCacheEntry $rcObj, array $queryParams = [] ) {
372 $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' );
373
374 $type = $rcObj->mAttribs['rc_type'];
375 $data = [];
376 $lineParams = [ 'targetTitle' => $rcObj->getTitle() ];
377
378 $classes = [ 'mw-enhanced-rc' ];
379 if ( $rcObj->watched
380 && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
381 ) {
382 $classes[] = 'mw-enhanced-watched';
383 }
384 $classes = array_merge( $classes, $this->getHTMLClasses( $rcObj, $rcObj->watched ) );
385
386 $separator = ' <span class="mw-changeslist-separator">. .</span> ';
387
388 $data['recentChangesFlags'] = [
389 'newpage' => $type == RC_NEW,
390 'minor' => $rcObj->mAttribs['rc_minor'],
391 'unpatrolled' => $rcObj->unpatrolled,
392 'bot' => $rcObj->mAttribs['rc_bot'],
393 ];
394
395 $params = $queryParams;
396
397 if ( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
398 $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
399 }
400
401 # Log timestamp
402 if ( $type == RC_LOG ) {
403 $link = $rcObj->timestamp;
404 # Revision link
405 } elseif ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
406 $link = '<span class="history-deleted">' . $rcObj->timestamp . '</span> ';
407 } else {
408 $link = $this->linkRenderer->makeKnownLink(
409 $rcObj->getTitle(),
410 new HtmlArmor( $rcObj->timestamp ),
411 [],
412 $params
413 );
414 if ( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
415 $link = '<span class="history-deleted">' . $link . '</span> ';
416 }
417 }
418 $data['timestampLink'] = $link;
419
420 $currentAndLastLinks = '';
421 if ( !$type == RC_LOG || $type == RC_NEW ) {
422 $currentAndLastLinks .= ' ' . $this->msg( 'parentheses' )->rawParams(
423 $rcObj->curlink .
424 $this->message['pipe-separator'] .
425 $rcObj->lastlink
426 )->escaped();
427 }
428 $data['currentAndLastLinks'] = $currentAndLastLinks;
429 $data['separatorAfterCurrentAndLastLinks'] = $separator;
430
431 # Character diff
432 if ( $RCShowChangedSize ) {
433 $cd = $this->formatCharacterDifference( $rcObj );
434 if ( $cd !== '' ) {
435 $data['characterDiff'] = $cd;
436 $data['separatorAfterCharacterDiff'] = $separator;
437 }
438 }
439
440 if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
441 $data['logEntry'] = $this->insertLogEntry( $rcObj );
442 } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) {
443 $data['comment'] = $this->insertComment( $rcObj );
444 } else {
445 # User links
446 $data['userLink'] = $rcObj->userlink;
447 $data['userTalkLink'] = $rcObj->usertalklink;
448 $data['comment'] = $this->insertComment( $rcObj );
449 }
450
451 # Rollback
452 $data['rollback'] = $this->getRollback( $rcObj );
453
454 # Tags
455 $data['tags'] = $this->getTags( $rcObj, $classes );
456
457 $attribs = $this->getDataAttributes( $rcObj );
458
459 // give the hook a chance to modify the data
460 $success = Hooks::run( 'EnhancedChangesListModifyLineData',
461 [ $this, &$data, $block, $rcObj, &$classes, &$attribs ] );
462 if ( !$success ) {
463 // skip entry if hook aborted it
464 return [];
465 }
466 $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
467
468 $lineParams['recentChangesFlagsRaw'] = [];
469 if ( isset( $data['recentChangesFlags'] ) ) {
470 $lineParams['recentChangesFlags'] = $this->recentChangesFlags( $data['recentChangesFlags'] );
471 # FIXME: This is used by logic, don't return it in the template params.
472 $lineParams['recentChangesFlagsRaw'] = $data['recentChangesFlags'];
473 unset( $data['recentChangesFlags'] );
474 }
475
476 if ( isset( $data['timestampLink'] ) ) {
477 $lineParams['timestampLink'] = $data['timestampLink'];
478 unset( $data['timestampLink'] );
479 }
480
481 $lineParams['classes'] = array_values( $classes );
482 $lineParams['attribs'] = Html::expandAttributes( $attribs );
483
484 // everything else: makes it easier for extensions to add or remove data
485 $lineParams['data'] = array_values( $data );
486
487 return $lineParams;
488 }
489
490 /**
491 * Generates amount of changes (linking to diff ) & link to history.
492 *
493 * @param array $block
494 * @param array $queryParams
495 * @param bool $allLogs
496 * @param bool $isnew
497 * @param bool $namehidden
498 * @return string
499 */
500 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
501 if ( empty( $block ) ) {
502 return '';
503 }
504
505 # Changes message
506 static $nchanges = [];
507 static $sinceLastVisitMsg = [];
508
509 $n = count( $block );
510 if ( !isset( $nchanges[$n] ) ) {
511 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
512 }
513
514 $sinceLast = 0;
515 $unvisitedOldid = null;
516 /** @var RCCacheEntry $rcObj */
517 foreach ( $block as $rcObj ) {
518 // Same logic as below inside main foreach
519 if ( $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched ) {
520 $sinceLast++;
521 $unvisitedOldid = $rcObj->mAttribs['rc_last_oldid'];
522 }
523 }
524 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
525 $sinceLastVisitMsg[$sinceLast] =
526 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
527 }
528
529 $currentRevision = 0;
530 foreach ( $block as $rcObj ) {
531 if ( !$currentRevision ) {
532 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
533 }
534 }
535
536 # Total change link
537 $links = [];
538 /** @var RecentChange $block0 */
539 $block0 = $block[0];
540 $last = $block[count( $block ) - 1];
541 if ( !$allLogs ) {
542 if ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ||
543 $isnew ||
544 $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE
545 ) {
546 $links['total-changes'] = $nchanges[$n];
547 } else {
548 $links['total-changes'] = $this->linkRenderer->makeKnownLink(
549 $block0->getTitle(),
550 new HtmlArmor( $nchanges[$n] ),
551 [ 'class' => 'mw-changeslist-groupdiff' ],
552 $queryParams + [
553 'diff' => $currentRevision,
554 'oldid' => $last->mAttribs['rc_last_oldid'],
555 ]
556 );
557 if ( $sinceLast > 0 && $sinceLast < $n ) {
558 $links['total-changes-since-last'] = $this->linkRenderer->makeKnownLink(
559 $block0->getTitle(),
560 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
561 [ 'class' => 'mw-changeslist-groupdiff' ],
562 $queryParams + [
563 'diff' => $currentRevision,
564 'oldid' => $unvisitedOldid,
565 ]
566 );
567 }
568 }
569 }
570
571 # History
572 if ( $allLogs || $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE ) {
573 // don't show history link for logs
574 } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
575 $links['history'] = $this->message['enhancedrc-history'];
576 } else {
577 $params = $queryParams;
578 $params['action'] = 'history';
579
580 $links['history'] = $this->linkRenderer->makeKnownLink(
581 $block0->getTitle(),
582 new HtmlArmor( $this->message['enhancedrc-history'] ),
583 [ 'class' => 'mw-changeslist-history' ],
584 $params
585 );
586 }
587
588 # Allow others to alter, remove or add to these links
589 Hooks::run( 'EnhancedChangesList::getLogText',
590 [ $this, &$links, $block ] );
591
592 if ( !$links ) {
593 return '';
594 }
595
596 $logtext = implode( $this->message['pipe-separator'], $links );
597 $logtext = $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
598 return ' ' . $logtext;
599 }
600
601 /**
602 * Enhanced RC ungrouped line.
603 *
604 * @param RecentChange|RCCacheEntry $rcObj
605 * @return string A HTML formatted line (generated using $r)
606 */
607 protected function recentChangesBlockLine( $rcObj ) {
608 $data = [];
609
610 $query['curid'] = $rcObj->mAttribs['rc_cur_id'];
611
612 $type = $rcObj->mAttribs['rc_type'];
613 $logType = $rcObj->mAttribs['rc_log_type'];
614 $classes = $this->getHTMLClasses( $rcObj, $rcObj->watched );
615 $classes[] = 'mw-enhanced-rc';
616
617 if ( $logType ) {
618 # Log entry
619 $classes[] = 'mw-changeslist-log';
620 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-' . $logType );
621 } else {
622 $classes[] = 'mw-changeslist-edit';
623 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' .
624 $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
625 }
626
627 # Flag and Timestamp
628 $data['recentChangesFlags'] = [
629 'newpage' => $type == RC_NEW,
630 'minor' => $rcObj->mAttribs['rc_minor'],
631 'unpatrolled' => $rcObj->unpatrolled,
632 'bot' => $rcObj->mAttribs['rc_bot'],
633 ];
634 // timestamp is not really a link here, but is called timestampLink
635 // for consistency with EnhancedChangesListModifyLineData
636 $data['timestampLink'] = $rcObj->timestamp;
637
638 # Article or log link
639 if ( $logType ) {
640 $logPage = new LogPage( $logType );
641 $logTitle = SpecialPage::getTitleFor( 'Log', $logType );
642 $logName = $logPage->getName()->text();
643 $data['logLink'] = $this->msg( 'parentheses' )
644 ->rawParams(
645 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
646 )->escaped();
647 } else {
648 $data['articleLink'] = $this->getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
649 }
650
651 # Diff and hist links
652 if ( $type != RC_LOG && $type != RC_CATEGORIZE ) {
653 $query['action'] = 'history';
654 $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
655 }
656 $data['separatorAfterLinks'] = ' <span class="mw-changeslist-separator">. .</span> ';
657
658 # Character diff
659 if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) {
660 $cd = $this->formatCharacterDifference( $rcObj );
661 if ( $cd !== '' ) {
662 $data['characterDiff'] = $cd;
663 $data['separatorAftercharacterDiff'] = ' <span class="mw-changeslist-separator">. .</span> ';
664 }
665 }
666
667 if ( $type == RC_LOG ) {
668 $data['logEntry'] = $this->insertLogEntry( $rcObj );
669 } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) {
670 $data['comment'] = $this->insertComment( $rcObj );
671 } else {
672 $data['userLink'] = $rcObj->userlink;
673 $data['userTalkLink'] = $rcObj->usertalklink;
674 $data['comment'] = $this->insertComment( $rcObj );
675 if ( $type == RC_CATEGORIZE ) {
676 $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
677 }
678 $data['rollback'] = $this->getRollback( $rcObj );
679 }
680
681 # Tags
682 $data['tags'] = $this->getTags( $rcObj, $classes );
683
684 # Show how many people are watching this if enabled
685 $data['watchingUsers'] = $this->numberofWatchingusers( $rcObj->numberofWatchingusers );
686
687 $data['attribs'] = array_merge( $this->getDataAttributes( $rcObj ), [ 'class' => $classes ] );
688
689 // give the hook a chance to modify the data
690 $success = Hooks::run( 'EnhancedChangesListModifyBlockLineData',
691 [ $this, &$data, $rcObj ] );
692 if ( !$success ) {
693 // skip entry if hook aborted it
694 return '';
695 }
696 $attribs = $data['attribs'];
697 unset( $data['attribs'] );
698 $attribs = wfArrayFilterByKey( $attribs, function ( $key ) {
699 return $key === 'class' || Sanitizer::isReservedDataAttribute( $key );
700 } );
701
702 $prefix = '';
703 if ( is_callable( $this->changeLinePrefixer ) ) {
704 $prefix = call_user_func( $this->changeLinePrefixer, $rcObj, $this, false );
705 }
706
707 $line = Html::openElement( 'table', $attribs ) . Html::openElement( 'tr' );
708 $line .= Html::rawElement( 'td', [], '<span class="mw-enhancedchanges-arrow-space"></span>' );
709 $line .= Html::rawElement( 'td', [ 'class' => 'mw-changeslist-line-prefix' ], $prefix );
710 $line .= '<td class="mw-enhanced-rc">';
711
712 if ( isset( $data['recentChangesFlags'] ) ) {
713 $line .= $this->recentChangesFlags( $data['recentChangesFlags'] );
714 unset( $data['recentChangesFlags'] );
715 }
716
717 if ( isset( $data['timestampLink'] ) ) {
718 $line .= '&#160;' . $data['timestampLink'];
719 unset( $data['timestampLink'] );
720 }
721 $line .= '&#160;</td>';
722 $line .= Html::openElement( 'td', [
723 'class' => 'mw-changeslist-line-inner',
724 // Used for reliable determination of the affiliated page
725 'data-target-page' => $rcObj->getTitle(),
726 ] );
727
728 // everything else: makes it easier for extensions to add or remove data
729 $line .= implode( '', $data );
730
731 $line .= "</td></tr></table>\n";
732
733 return $line;
734 }
735
736 /**
737 * Returns value to be used in 'historyLink' element of $data param in
738 * EnhancedChangesListModifyBlockLineData hook.
739 *
740 * @since 1.27
741 *
742 * @param RCCacheEntry $rc
743 * @param array $query array of key/value pairs to append as a query string
744 * @return string HTML
745 */
746 public function getDiffHistLinks( RCCacheEntry $rc, array $query ) {
747 $pageTitle = $rc->getTitle();
748 if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) {
749 // For categorizations we must swap the category title with the page title!
750 $pageTitle = Title::newFromID( $rc->getAttribute( 'rc_cur_id' ) );
751 if ( !$pageTitle ) {
752 // The page has been deleted, but the RC entry
753 // deletion job has not run yet. Just skip.
754 return '';
755 }
756 }
757
758 $retVal = ' ' . $this->msg( 'parentheses' )
759 ->rawParams( $rc->difflink . $this->message['pipe-separator']
760 . $this->linkRenderer->makeKnownLink(
761 $pageTitle,
762 new HtmlArmor( $this->message['hist'] ),
763 [ 'class' => 'mw-changeslist-history' ],
764 $query
765 ) )->escaped();
766 return $retVal;
767 }
768
769 /**
770 * If enhanced RC is in use, this function takes the previously cached
771 * RC lines, arranges them, and outputs the HTML
772 *
773 * @return string
774 */
775 protected function recentChangesBlock() {
776 if ( count( $this->rc_cache ) == 0 ) {
777 return '';
778 }
779
780 $blockOut = '';
781 foreach ( $this->rc_cache as $block ) {
782 if ( count( $block ) < 2 ) {
783 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
784 } else {
785 $blockOut .= $this->recentChangesBlockGroup( $block );
786 }
787 }
788
789 if ( $blockOut === '' ) {
790 return '';
791 }
792 // $this->lastdate is kept up to date by recentChangesLine()
793 return Xml::element( 'h4', null, $this->lastdate ) . "\n<div>" . $blockOut . '</div>';
794 }
795
796 /**
797 * Returns text for the end of RC
798 * If enhanced RC is in use, returns pretty much all the text
799 * @return string
800 */
801 public function endRecentChangesList() {
802 return $this->recentChangesBlock() . '</div>';
803 }
804 }