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