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