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