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