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