Merge "Rename autonym for 'no' from 'norsk bokmål' to 'norsk'"
[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 'users' => $usersList,
345 ];
346
347 $this->rcCacheIndex++;
348
349 return $this->templateParser->processTemplate(
350 'EnhancedChangesListGroup',
351 $templateParams
352 );
353 }
354
355 /**
356 * @param RCCacheEntry[] $block
357 * @param RCCacheEntry $rcObj
358 * @param array $queryParams
359 * @return array
360 * @throws Exception
361 * @throws FatalError
362 * @throws MWException
363 */
364 protected function getLineData( array $block, RCCacheEntry $rcObj, array $queryParams = [] ) {
365 $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' );
366
367 $type = $rcObj->mAttribs['rc_type'];
368 $data = [];
369 $lineParams = [];
370
371 $classes = [ 'mw-enhanced-rc' ];
372 if ( $rcObj->watched
373 && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
374 ) {
375 $classes[] = 'mw-enhanced-watched';
376 }
377 $classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rcObj ) );
378
379 $separator = ' <span class="mw-changeslist-separator">. .</span> ';
380
381 $data['recentChangesFlags'] = [
382 'newpage' => $type == RC_NEW,
383 'minor' => $rcObj->mAttribs['rc_minor'],
384 'unpatrolled' => $rcObj->unpatrolled,
385 'bot' => $rcObj->mAttribs['rc_bot'],
386 ];
387
388 $params = $queryParams;
389
390 if ( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
391 $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
392 }
393
394 # Log timestamp
395 if ( $type == RC_LOG ) {
396 $link = $rcObj->timestamp;
397 # Revision link
398 } elseif ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
399 $link = '<span class="history-deleted">' . $rcObj->timestamp . '</span> ';
400 } else {
401 $link = $this->linkRenderer->makeKnownLink(
402 $rcObj->getTitle(),
403 new HtmlArmor( $rcObj->timestamp ),
404 [],
405 $params
406 );
407 if ( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
408 $link = '<span class="history-deleted">' . $link . '</span> ';
409 }
410 }
411 $data['timestampLink'] = $link;
412
413 $currentAndLastLinks = '';
414 if ( !$type == RC_LOG || $type == RC_NEW ) {
415 $currentAndLastLinks .= ' ' . $this->msg( 'parentheses' )->rawParams(
416 $rcObj->curlink .
417 $this->message['pipe-separator'] .
418 $rcObj->lastlink
419 )->escaped();
420 }
421 $data['currentAndLastLinks'] = $currentAndLastLinks;
422 $data['separatorAfterCurrentAndLastLinks'] = $separator;
423
424 # Character diff
425 if ( $RCShowChangedSize ) {
426 $cd = $this->formatCharacterDifference( $rcObj );
427 if ( $cd !== '' ) {
428 $data['characterDiff'] = $cd;
429 $data['separatorAfterCharacterDiff'] = $separator;
430 }
431 }
432
433 if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
434 $data['logEntry'] = $this->insertLogEntry( $rcObj );
435 } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) {
436 $data['comment'] = $this->insertComment( $rcObj );
437 } else {
438 # User links
439 $data['userLink'] = $rcObj->userlink;
440 $data['userTalkLink'] = $rcObj->usertalklink;
441 $data['comment'] = $this->insertComment( $rcObj );
442 }
443
444 # Rollback
445 $data['rollback'] = $this->getRollback( $rcObj );
446
447 # Tags
448 $data['tags'] = $this->getTags( $rcObj, $classes );
449
450 $attribs = $this->getDataAttributes( $rcObj );
451
452 // give the hook a chance to modify the data
453 $success = Hooks::run( 'EnhancedChangesListModifyLineData',
454 [ $this, &$data, $block, $rcObj, &$classes, &$attribs ] );
455 if ( !$success ) {
456 // skip entry if hook aborted it
457 return [];
458 }
459 $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
460
461 $lineParams['recentChangesFlagsRaw'] = [];
462 if ( isset( $data['recentChangesFlags'] ) ) {
463 $lineParams['recentChangesFlags'] = $this->recentChangesFlags( $data['recentChangesFlags'] );
464 # FIXME: This is used by logic, don't return it in the template params.
465 $lineParams['recentChangesFlagsRaw'] = $data['recentChangesFlags'];
466 unset( $data['recentChangesFlags'] );
467 }
468
469 if ( isset( $data['timestampLink'] ) ) {
470 $lineParams['timestampLink'] = $data['timestampLink'];
471 unset( $data['timestampLink'] );
472 }
473
474 $lineParams['classes'] = array_values( $classes );
475 $lineParams['attribs'] = Html::expandAttributes( $attribs );
476
477 // everything else: makes it easier for extensions to add or remove data
478 $lineParams['data'] = array_values( $data );
479
480 return $lineParams;
481 }
482
483 /**
484 * Generates amount of changes (linking to diff ) & link to history.
485 *
486 * @param array $block
487 * @param array $queryParams
488 * @param bool $allLogs
489 * @param bool $isnew
490 * @param bool $namehidden
491 * @return string
492 */
493 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
494 if ( empty( $block ) ) {
495 return '';
496 }
497
498 # Changes message
499 static $nchanges = [];
500 static $sinceLastVisitMsg = [];
501
502 $n = count( $block );
503 if ( !isset( $nchanges[$n] ) ) {
504 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
505 }
506
507 $sinceLast = 0;
508 $unvisitedOldid = null;
509 /** @var $rcObj RCCacheEntry */
510 foreach ( $block as $rcObj ) {
511 // Same logic as below inside main foreach
512 if ( $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched ) {
513 $sinceLast++;
514 $unvisitedOldid = $rcObj->mAttribs['rc_last_oldid'];
515 }
516 }
517 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
518 $sinceLastVisitMsg[$sinceLast] =
519 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
520 }
521
522 $currentRevision = 0;
523 foreach ( $block as $rcObj ) {
524 if ( !$currentRevision ) {
525 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
526 }
527 }
528
529 # Total change link
530 $links = [];
531 /** @var $block0 RecentChange */
532 $block0 = $block[0];
533 $last = $block[count( $block ) - 1];
534 if ( !$allLogs ) {
535 if ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ||
536 $isnew ||
537 $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE
538 ) {
539 $links['total-changes'] = $nchanges[$n];
540 } else {
541 $links['total-changes'] = $this->linkRenderer->makeKnownLink(
542 $block0->getTitle(),
543 new HtmlArmor( $nchanges[$n] ),
544 [ 'class' => 'mw-changeslist-groupdiff' ],
545 $queryParams + [
546 'diff' => $currentRevision,
547 'oldid' => $last->mAttribs['rc_last_oldid'],
548 ]
549 );
550 if ( $sinceLast > 0 && $sinceLast < $n ) {
551 $links['total-changes-since-last'] = $this->linkRenderer->makeKnownLink(
552 $block0->getTitle(),
553 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
554 [ 'class' => 'mw-changeslist-groupdiff' ],
555 $queryParams + [
556 'diff' => $currentRevision,
557 'oldid' => $unvisitedOldid,
558 ]
559 );
560 }
561 }
562 }
563
564 # History
565 if ( $allLogs || $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE ) {
566 // don't show history link for logs
567 } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
568 $links['history'] = $this->message['enhancedrc-history'];
569 } else {
570 $params = $queryParams;
571 $params['action'] = 'history';
572
573 $links['history'] = $this->linkRenderer->makeKnownLink(
574 $block0->getTitle(),
575 new HtmlArmor( $this->message['enhancedrc-history'] ),
576 [ 'class' => 'mw-changeslist-history' ],
577 $params
578 );
579 }
580
581 # Allow others to alter, remove or add to these links
582 Hooks::run( 'EnhancedChangesList::getLogText',
583 [ $this, &$links, $block ] );
584
585 if ( !$links ) {
586 return '';
587 }
588
589 $logtext = implode( $this->message['pipe-separator'], $links );
590 $logtext = $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
591 return ' ' . $logtext;
592 }
593
594 /**
595 * Enhanced RC ungrouped line.
596 *
597 * @param RecentChange|RCCacheEntry $rcObj
598 * @return string A HTML formatted line (generated using $r)
599 */
600 protected function recentChangesBlockLine( $rcObj ) {
601 $data = [];
602
603 $query['curid'] = $rcObj->mAttribs['rc_cur_id'];
604
605 $type = $rcObj->mAttribs['rc_type'];
606 $logType = $rcObj->mAttribs['rc_log_type'];
607 $classes = $this->getHTMLClasses( $rcObj, $rcObj->watched );
608 $classes[] = 'mw-enhanced-rc';
609
610 if ( $logType ) {
611 # Log entry
612 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-' . $logType );
613 } else {
614 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' .
615 $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
616 }
617
618 # Flag and Timestamp
619 $data['recentChangesFlags'] = [
620 'newpage' => $type == RC_NEW,
621 'minor' => $rcObj->mAttribs['rc_minor'],
622 'unpatrolled' => $rcObj->unpatrolled,
623 'bot' => $rcObj->mAttribs['rc_bot'],
624 ];
625 // timestamp is not really a link here, but is called timestampLink
626 // for consistency with EnhancedChangesListModifyLineData
627 $data['timestampLink'] = $rcObj->timestamp;
628
629 # Article or log link
630 if ( $logType ) {
631 $logPage = new LogPage( $logType );
632 $logTitle = SpecialPage::getTitleFor( 'Log', $logType );
633 $logName = $logPage->getName()->text();
634 $data['logLink'] = $this->msg( 'parentheses' )
635 ->rawParams(
636 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
637 )->escaped();
638 } else {
639 $data['articleLink'] = $this->getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
640 }
641
642 # Diff and hist links
643 if ( $type != RC_LOG && $type != RC_CATEGORIZE ) {
644 $query['action'] = 'history';
645 $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
646 }
647 $data['separatorAfterLinks'] = ' <span class="mw-changeslist-separator">. .</span> ';
648
649 # Character diff
650 if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) {
651 $cd = $this->formatCharacterDifference( $rcObj );
652 if ( $cd !== '' ) {
653 $data['characterDiff'] = $cd;
654 $data['separatorAftercharacterDiff'] = ' <span class="mw-changeslist-separator">. .</span> ';
655 }
656 }
657
658 if ( $type == RC_LOG ) {
659 $data['logEntry'] = $this->insertLogEntry( $rcObj );
660 } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) {
661 $data['comment'] = $this->insertComment( $rcObj );
662 } else {
663 $data['userLink'] = $rcObj->userlink;
664 $data['userTalkLink'] = $rcObj->usertalklink;
665 $data['comment'] = $this->insertComment( $rcObj );
666 if ( $type == RC_CATEGORIZE ) {
667 $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
668 }
669 $data['rollback'] = $this->getRollback( $rcObj );
670 }
671
672 # Tags
673 $data['tags'] = $this->getTags( $rcObj, $classes );
674
675 # Show how many people are watching this if enabled
676 $data['watchingUsers'] = $this->numberofWatchingusers( $rcObj->numberofWatchingusers );
677
678 $data['attribs'] = array_merge( $this->getDataAttributes( $rcObj ), [ 'class' => $classes ] );
679
680 // give the hook a chance to modify the data
681 $success = Hooks::run( 'EnhancedChangesListModifyBlockLineData',
682 [ $this, &$data, $rcObj ] );
683 if ( !$success ) {
684 // skip entry if hook aborted it
685 return '';
686 }
687 $attribs = $data['attribs'];
688 unset( $data['attribs'] );
689 $attribs = wfArrayFilterByKey( $attribs, function ( $key ) {
690 return $key === 'class' || Sanitizer::isReservedDataAttribute( $key );
691 } );
692
693 $line = Html::openElement( 'table', $attribs ) . Html::openElement( 'tr' );
694 $line .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
695
696 if ( isset( $data['recentChangesFlags'] ) ) {
697 $line .= $this->recentChangesFlags( $data['recentChangesFlags'] );
698 unset( $data['recentChangesFlags'] );
699 }
700
701 if ( isset( $data['timestampLink'] ) ) {
702 $line .= '&#160;' . $data['timestampLink'];
703 unset( $data['timestampLink'] );
704 }
705 $line .= '&#160;</td><td>';
706
707 // everything else: makes it easier for extensions to add or remove data
708 $line .= implode( '', $data );
709
710 $line .= "</td></tr></table>\n";
711
712 return $line;
713 }
714
715 /**
716 * Returns value to be used in 'historyLink' element of $data param in
717 * EnhancedChangesListModifyBlockLineData hook.
718 *
719 * @since 1.27
720 *
721 * @param RCCacheEntry $rc
722 * @param array $query array of key/value pairs to append as a query string
723 * @return string HTML
724 */
725 public function getDiffHistLinks( RCCacheEntry $rc, array $query ) {
726 $pageTitle = $rc->getTitle();
727 if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) {
728 // For categorizations we must swap the category title with the page title!
729 $pageTitle = Title::newFromID( $rc->getAttribute( 'rc_cur_id' ) );
730 if ( !$pageTitle ) {
731 // The page has been deleted, but the RC entry
732 // deletion job has not run yet. Just skip.
733 return '';
734 }
735 }
736
737 $retVal = ' ' . $this->msg( 'parentheses' )
738 ->rawParams( $rc->difflink . $this->message['pipe-separator']
739 . $this->linkRenderer->makeKnownLink(
740 $pageTitle,
741 new HtmlArmor( $this->message['hist'] ),
742 [ 'class' => 'mw-changeslist-history' ],
743 $query
744 ) )->escaped();
745 return $retVal;
746 }
747
748 /**
749 * If enhanced RC is in use, this function takes the previously cached
750 * RC lines, arranges them, and outputs the HTML
751 *
752 * @return string
753 */
754 protected function recentChangesBlock() {
755 if ( count( $this->rc_cache ) == 0 ) {
756 return '';
757 }
758
759 $blockOut = '';
760 foreach ( $this->rc_cache as $block ) {
761 if ( count( $block ) < 2 ) {
762 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
763 } else {
764 $blockOut .= $this->recentChangesBlockGroup( $block );
765 }
766 }
767
768 if ( $blockOut === '' ) {
769 return '';
770 }
771 // $this->lastdate is kept up to date by recentChangesLine()
772 return Xml::element( 'h4', null, $this->lastdate ) . "\n<div>" . $blockOut . '</div>';
773 }
774
775 /**
776 * Returns text for the end of RC
777 * If enhanced RC is in use, returns pretty much all the text
778 * @return string
779 */
780 public function endRecentChangesList() {
781 return $this->recentChangesBlock() . '</div>';
782 }
783 }