b34a33fdcfe8598ac95dab3fc545ddc556b0437a
[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 // @todo FIXME: Hardcoded '×'. Should be a message.
247 $formattedCount = $this->getLanguage()->formatNum( $count ) . '×';
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 // give the hook a chance to modify the data
451 $success = Hooks::run( 'EnhancedChangesListModifyLineData',
452 [ $this, &$data, $block, $rcObj, &$classes ] );
453 if ( !$success ) {
454 // skip entry if hook aborted it
455 return [];
456 }
457
458 $lineParams['recentChangesFlagsRaw'] = [];
459 if ( isset( $data['recentChangesFlags'] ) ) {
460 $lineParams['recentChangesFlags'] = $this->recentChangesFlags( $data['recentChangesFlags'] );
461 # FIXME: This is used by logic, don't return it in the template params.
462 $lineParams['recentChangesFlagsRaw'] = $data['recentChangesFlags'];
463 unset( $data['recentChangesFlags'] );
464 }
465
466 if ( isset( $data['timestampLink'] ) ) {
467 $lineParams['timestampLink'] = $data['timestampLink'];
468 unset( $data['timestampLink'] );
469 }
470
471 $lineParams['classes'] = array_values( $classes );
472
473 // everything else: makes it easier for extensions to add or remove data
474 $lineParams['data'] = array_values( $data );
475
476 return $lineParams;
477 }
478
479 /**
480 * Generates amount of changes (linking to diff ) & link to history.
481 *
482 * @param array $block
483 * @param array $queryParams
484 * @param bool $allLogs
485 * @param bool $isnew
486 * @param bool $namehidden
487 * @return string
488 */
489 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
490 if ( empty( $block ) ) {
491 return '';
492 }
493
494 # Changes message
495 static $nchanges = [];
496 static $sinceLastVisitMsg = [];
497
498 $n = count( $block );
499 if ( !isset( $nchanges[$n] ) ) {
500 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
501 }
502
503 $sinceLast = 0;
504 $unvisitedOldid = null;
505 /** @var $rcObj RCCacheEntry */
506 foreach ( $block as $rcObj ) {
507 // Same logic as below inside main foreach
508 if ( $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched ) {
509 $sinceLast++;
510 $unvisitedOldid = $rcObj->mAttribs['rc_last_oldid'];
511 }
512 }
513 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
514 $sinceLastVisitMsg[$sinceLast] =
515 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
516 }
517
518 $currentRevision = 0;
519 foreach ( $block as $rcObj ) {
520 if ( !$currentRevision ) {
521 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
522 }
523 }
524
525 # Total change link
526 $links = [];
527 /** @var $block0 RecentChange */
528 $block0 = $block[0];
529 $last = $block[count( $block ) - 1];
530 if ( !$allLogs ) {
531 if ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ||
532 $isnew ||
533 $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE
534 ) {
535 $links['total-changes'] = $nchanges[$n];
536 } else {
537 $links['total-changes'] = $this->linkRenderer->makeKnownLink(
538 $block0->getTitle(),
539 new HtmlArmor( $nchanges[$n] ),
540 [ 'class' => 'mw-changeslist-groupdiff' ],
541 $queryParams + [
542 'diff' => $currentRevision,
543 'oldid' => $last->mAttribs['rc_last_oldid'],
544 ]
545 );
546 if ( $sinceLast > 0 && $sinceLast < $n ) {
547 $links['total-changes-since-last'] = $this->linkRenderer->makeKnownLink(
548 $block0->getTitle(),
549 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
550 [ 'class' => 'mw-changeslist-groupdiff' ],
551 $queryParams + [
552 'diff' => $currentRevision,
553 'oldid' => $unvisitedOldid,
554 ]
555 );
556 }
557 }
558 }
559
560 # History
561 if ( $allLogs || $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE ) {
562 // don't show history link for logs
563 } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
564 $links['history'] = $this->message['enhancedrc-history'];
565 } else {
566 $params = $queryParams;
567 $params['action'] = 'history';
568
569 $links['history'] = $this->linkRenderer->makeKnownLink(
570 $block0->getTitle(),
571 new HtmlArmor( $this->message['enhancedrc-history'] ),
572 [ 'class' => 'mw-changeslist-history' ],
573 $params
574 );
575 }
576
577 # Allow others to alter, remove or add to these links
578 Hooks::run( 'EnhancedChangesList::getLogText',
579 [ $this, &$links, $block ] );
580
581 if ( !$links ) {
582 return '';
583 }
584
585 $logtext = implode( $this->message['pipe-separator'], $links );
586 $logtext = $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
587 return ' ' . $logtext;
588 }
589
590 /**
591 * Enhanced RC ungrouped line.
592 *
593 * @param RecentChange|RCCacheEntry $rcObj
594 * @return string A HTML formatted line (generated using $r)
595 */
596 protected function recentChangesBlockLine( $rcObj ) {
597 $data = [];
598
599 $query['curid'] = $rcObj->mAttribs['rc_cur_id'];
600
601 $type = $rcObj->mAttribs['rc_type'];
602 $logType = $rcObj->mAttribs['rc_log_type'];
603 $classes = $this->getHTMLClasses( $rcObj, $rcObj->watched );
604 $classes[] = 'mw-enhanced-rc';
605
606 if ( $logType ) {
607 # Log entry
608 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-' . $logType );
609 } else {
610 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' .
611 $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
612 }
613
614 # Flag and Timestamp
615 $data['recentChangesFlags'] = [
616 'newpage' => $type == RC_NEW,
617 'minor' => $rcObj->mAttribs['rc_minor'],
618 'unpatrolled' => $rcObj->unpatrolled,
619 'bot' => $rcObj->mAttribs['rc_bot'],
620 ];
621 // timestamp is not really a link here, but is called timestampLink
622 // for consistency with EnhancedChangesListModifyLineData
623 $data['timestampLink'] = $rcObj->timestamp;
624
625 # Article or log link
626 if ( $logType ) {
627 $logPage = new LogPage( $logType );
628 $logTitle = SpecialPage::getTitleFor( 'Log', $logType );
629 $logName = $logPage->getName()->text();
630 $data['logLink'] = $this->msg( 'parentheses' )
631 ->rawParams(
632 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
633 )->escaped();
634 } else {
635 $data['articleLink'] = $this->getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
636 }
637
638 # Diff and hist links
639 if ( $type != RC_LOG && $type != RC_CATEGORIZE ) {
640 $query['action'] = 'history';
641 $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
642 }
643 $data['separatorAfterLinks'] = ' <span class="mw-changeslist-separator">. .</span> ';
644
645 # Character diff
646 if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) {
647 $cd = $this->formatCharacterDifference( $rcObj );
648 if ( $cd !== '' ) {
649 $data['characterDiff'] = $cd;
650 $data['separatorAftercharacterDiff'] = ' <span class="mw-changeslist-separator">. .</span> ';
651 }
652 }
653
654 if ( $type == RC_LOG ) {
655 $data['logEntry'] = $this->insertLogEntry( $rcObj );
656 } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) {
657 $data['comment'] = $this->insertComment( $rcObj );
658 } else {
659 $data['userLink'] = $rcObj->userlink;
660 $data['userTalkLink'] = $rcObj->usertalklink;
661 $data['comment'] = $this->insertComment( $rcObj );
662 if ( $type == RC_CATEGORIZE ) {
663 $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
664 }
665 $data['rollback'] = $this->getRollback( $rcObj );
666 }
667
668 # Tags
669 $data['tags'] = $this->getTags( $rcObj, $classes );
670
671 # Show how many people are watching this if enabled
672 $data['watchingUsers'] = $this->numberofWatchingusers( $rcObj->numberofWatchingusers );
673
674 // give the hook a chance to modify the data
675 $success = Hooks::run( 'EnhancedChangesListModifyBlockLineData',
676 [ $this, &$data, $rcObj ] );
677 if ( !$success ) {
678 // skip entry if hook aborted it
679 return '';
680 }
681
682 $line = Html::openElement( 'table', [ 'class' => $classes ] ) .
683 Html::openElement( 'tr' );
684 $line .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
685
686 if ( isset( $data['recentChangesFlags'] ) ) {
687 $line .= $this->recentChangesFlags( $data['recentChangesFlags'] );
688 unset( $data['recentChangesFlags'] );
689 }
690
691 if ( isset( $data['timestampLink'] ) ) {
692 $line .= '&#160;' . $data['timestampLink'];
693 unset( $data['timestampLink'] );
694 }
695 $line .= '&#160;</td><td>';
696
697 // everything else: makes it easier for extensions to add or remove data
698 $line .= implode( '', $data );
699
700 $line .= "</td></tr></table>\n";
701
702 return $line;
703 }
704
705 /**
706 * Returns value to be used in 'historyLink' element of $data param in
707 * EnhancedChangesListModifyBlockLineData hook.
708 *
709 * @since 1.27
710 *
711 * @param RCCacheEntry $rc
712 * @param array $query array of key/value pairs to append as a query string
713 * @return string HTML
714 */
715 public function getDiffHistLinks( RCCacheEntry $rc, array $query ) {
716 $pageTitle = $rc->getTitle();
717 if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) {
718 // For categorizations we must swap the category title with the page title!
719 $pageTitle = Title::newFromID( $rc->getAttribute( 'rc_cur_id' ) );
720 if ( !$pageTitle ) {
721 // The page has been deleted, but the RC entry
722 // deletion job has not run yet. Just skip.
723 return '';
724 }
725 }
726
727 $retVal = ' ' . $this->msg( 'parentheses' )
728 ->rawParams( $rc->difflink . $this->message['pipe-separator']
729 . $this->linkRenderer->makeKnownLink(
730 $pageTitle,
731 new HtmlArmor( $this->message['hist'] ),
732 [ 'class' => 'mw-changeslist-history' ],
733 $query
734 ) )->escaped();
735 return $retVal;
736 }
737
738 /**
739 * If enhanced RC is in use, this function takes the previously cached
740 * RC lines, arranges them, and outputs the HTML
741 *
742 * @return string
743 */
744 protected function recentChangesBlock() {
745 if ( count( $this->rc_cache ) == 0 ) {
746 return '';
747 }
748
749 $blockOut = '';
750 foreach ( $this->rc_cache as $block ) {
751 if ( count( $block ) < 2 ) {
752 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
753 } else {
754 $blockOut .= $this->recentChangesBlockGroup( $block );
755 }
756 }
757
758 return '<div>' . $blockOut . '</div>';
759 }
760
761 /**
762 * Returns text for the end of RC
763 * If enhanced RC is in use, returns pretty much all the text
764 * @return string
765 */
766 public function endRecentChangesList() {
767 return $this->recentChangesBlock() . '</div>';
768 }
769 }