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