MediaWiki  master
EnhancedChangesList.php
Go to the documentation of this file.
1 <?php
2 
5 
28 
32  protected $cacheEntryFactory;
33 
37  protected $rc_cache;
38 
42  protected $templateParser;
43 
49  public function __construct( $context, array $filterGroups = [] ) {
50  parent::__construct( $context, $filterGroups );
51 
52  // message is set by the parent ChangesList class
53  $this->cacheEntryFactory = new RCCacheEntryFactory(
54  $context,
55  $this->message,
56  $this->linkRenderer
57  );
58  $this->templateParser = new TemplateParser();
59  }
60 
65  public function beginRecentChangesList() {
66  $this->getOutput()->addModuleStyles( [
67  'mediawiki.icon',
68  'mediawiki.special.changeslist.enhanced',
69  ] );
70  $this->getOutput()->addModules( [
71  'jquery.makeCollapsible',
72  ] );
73 
74  parent::beginRecentChangesList();
75  return '<div class="mw-changeslist" aria-live="polite">';
76  }
77 
87  public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
88  $date = $this->getLanguage()->userDate(
89  $rc->mAttribs['rc_timestamp'],
90  $this->getUser()
91  );
92  if ( $this->lastdate === '' ) {
93  $this->lastdate = $date;
94  }
95 
96  $ret = '';
97 
98  # If it's a new day, flush the cache and update $this->lastdate
99  if ( $date !== $this->lastdate ) {
100  # Process current cache (uses $this->lastdate to generate a heading)
101  $ret = $this->recentChangesBlock();
102  $this->rc_cache = [];
103  $this->lastdate = $date;
104  }
105 
106  $cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $rc, $watched );
107  $this->addCacheEntry( $cacheEntry );
108 
109  return $ret;
110  }
111 
118  protected function addCacheEntry( RCCacheEntry $cacheEntry ) {
119  $cacheGroupingKey = $this->makeCacheGroupingKey( $cacheEntry );
120 
121  if ( !isset( $this->rc_cache[$cacheGroupingKey] ) ) {
122  $this->rc_cache[$cacheGroupingKey] = [];
123  }
124 
125  array_push( $this->rc_cache[$cacheGroupingKey], $cacheEntry );
126  }
127 
135  protected function makeCacheGroupingKey( RCCacheEntry $cacheEntry ) {
136  $title = $cacheEntry->getTitle();
137  $cacheGroupingKey = $title->getPrefixedDBkey();
138 
139  $type = $cacheEntry->mAttribs['rc_type'];
140 
141  if ( $type == RC_LOG ) {
142  // Group by log type
143  $cacheGroupingKey = SpecialPage::getTitleFor(
144  'Log',
145  $cacheEntry->mAttribs['rc_log_type']
146  )->getPrefixedDBkey();
147  }
148 
149  return $cacheGroupingKey;
150  }
151 
158  protected function recentChangesBlockGroup( $block ) {
159  $recentChangesFlags = $this->getConfig()->get( MainConfigNames::RecentChangesFlags );
160 
161  # Add the namespace and title of the block as part of the class
162  $tableClasses = [ 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc', 'mw-changeslist-line' ];
163  if ( $block[0]->mAttribs['rc_log_type'] ) {
164  # Log entry
165  $tableClasses[] = 'mw-changeslist-log';
166  $tableClasses[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
167  . $block[0]->mAttribs['rc_log_type'] );
168  } else {
169  $tableClasses[] = 'mw-changeslist-edit';
170  $tableClasses[] = Sanitizer::escapeClass( 'mw-changeslist-ns'
171  . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
172  }
173  if ( $block[0]->watched ) {
174  $tableClasses[] = 'mw-changeslist-line-watched';
175  } else {
176  $tableClasses[] = 'mw-changeslist-line-not-watched';
177  }
178 
179  # Collate list of users
180  $userlinks = [];
181  # Other properties
182  $curId = 0;
183  # Some catalyst variables...
184  $namehidden = true;
185  $allLogs = true;
186  $RCShowChangedSize = $this->getConfig()->get( MainConfigNames::RCShowChangedSize );
187 
188  # Default values for RC flags
189  $collectedRcFlags = [];
190  foreach ( $recentChangesFlags as $key => $value ) {
191  $flagGrouping = $value['grouping'] ?? 'any';
192  switch ( $flagGrouping ) {
193  case 'all':
194  $collectedRcFlags[$key] = true;
195  break;
196  case 'any':
197  $collectedRcFlags[$key] = false;
198  break;
199  default:
200  throw new DomainException( "Unknown grouping type \"{$flagGrouping}\"" );
201  }
202  }
203  foreach ( $block as $rcObj ) {
204  // If all log actions to this page were hidden, then don't
205  // give the name of the affected page for this block!
206  if ( !static::isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
207  $namehidden = false;
208  }
209  $u = $rcObj->userlink;
210  if ( !isset( $userlinks[$u] ) ) {
211  $userlinks[$u] = 0;
212  }
213  if ( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
214  $allLogs = false;
215  }
216  # Get the latest entry with a page_id and oldid
217  # since logs may not have these.
218  if ( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
219  $curId = $rcObj->mAttribs['rc_cur_id'];
220  }
221 
222  $userlinks[$u]++;
223  }
224 
225  # Sort the list and convert to text
226  krsort( $userlinks );
227  asort( $userlinks );
228  $users = [];
229  foreach ( $userlinks as $userlink => $count ) {
230  $text = $userlink;
231  $text .= $this->getLanguage()->getDirMark();
232  if ( $count > 1 ) {
233  $formattedCount = $this->msg( 'ntimes' )->numParams( $count )->escaped();
234  $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
235  }
236  array_push( $users, $text );
237  }
238 
239  # Article link
240  $articleLink = '';
241  $revDeletedMsg = false;
242  if ( $namehidden ) {
243  $revDeletedMsg = $this->msg( 'rev-deleted-event' )->escaped();
244  } elseif ( $allLogs ) {
245  $articleLink = $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
246  } else {
247  $articleLink = $this->getArticleLink(
248  $block[0], $block[0]->unpatrolled, $block[0]->watched );
249  }
250 
251  $queryParams = [ 'curid' => $curId ];
252 
253  # Sub-entries
254  $lines = [];
255  $filterClasses = [];
256  foreach ( $block as $i => $rcObj ) {
257  $line = $this->getLineData( $block, $rcObj, $queryParams );
258  if ( !$line ) {
259  // completely ignore this RC entry if we don't want to render it
260  unset( $block[$i] );
261  continue;
262  }
263 
264  // Roll up flags
265  foreach ( $line['recentChangesFlagsRaw'] as $key => $value ) {
266  $flagGrouping = ( $recentChangesFlags[$key]['grouping'] ?? 'any' );
267  switch ( $flagGrouping ) {
268  case 'all':
269  if ( !$value ) {
270  $collectedRcFlags[$key] = false;
271  }
272  break;
273  case 'any':
274  if ( $value ) {
275  $collectedRcFlags[$key] = true;
276  }
277  break;
278  default:
279  throw new DomainException( "Unknown grouping type \"{$flagGrouping}\"" );
280  }
281  }
282 
283  // Roll up filter-based CSS classes
284  $filterClasses = array_merge( $filterClasses, $this->getHTMLClassesForFilters( $rcObj ) );
285  // Add classes for change tags separately, getHTMLClassesForFilters() doesn't add them
286  $this->getTags( $rcObj, $filterClasses );
287  $filterClasses = array_unique( $filterClasses );
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  $filterClasses = array_values( $filterClasses );
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] ) ?: false;
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  $prefix = '';
328  if ( is_callable( $this->changeLinePrefixer ) ) {
329  $prefix = call_user_func( $this->changeLinePrefixer, $block[0], $this, true );
330  }
331 
332  $templateParams = [
333  'articleLink' => $articleLink,
334  'charDifference' => $charDifference,
335  'collectedRcFlags' => $this->recentChangesFlags( $collectedRcFlags ),
336  'filterClasses' => $filterClasses,
337  'languageDirMark' => $this->getLanguage()->getDirMark(),
338  'lines' => $lines,
339  'logText' => $logText,
340  'numberofWatchingusers' => $numberofWatchingusers,
341  'prefix' => $prefix,
342  'rev-deleted-event' => $revDeletedMsg,
343  'tableClasses' => $tableClasses,
344  'timestamp' => $block[0]->timestamp,
345  'fullTimestamp' => $block[0]->getAttribute( 'rc_timestamp' ),
346  'users' => $usersList,
347  ];
348 
349  $this->rcCacheIndex++;
350 
351  return $this->templateParser->processTemplate(
352  'EnhancedChangesListGroup',
353  $templateParams
354  );
355  }
356 
366  protected function getLineData( array $block, RCCacheEntry $rcObj, array $queryParams = [] ) {
367  $RCShowChangedSize = $this->getConfig()->get( MainConfigNames::RCShowChangedSize );
368 
369  $type = $rcObj->mAttribs['rc_type'];
370  $data = [];
371  $lineParams = [ 'targetTitle' => $rcObj->getTitle() ];
372 
373  $classes = [ 'mw-enhanced-rc' ];
374  if ( $rcObj->watched ) {
375  $classes[] = 'mw-enhanced-watched';
376  }
377  $classes = array_merge( $classes, $this->getHTMLClasses( $rcObj, $rcObj->watched ) );
378 
379  $separator = ' <span class="mw-changeslist-separator"></span> ';
380 
381  $data['recentChangesFlags'] = [
382  'newpage' => $type == RC_NEW,
383  'minor' => $rcObj->mAttribs['rc_minor'],
384  'unpatrolled' => $rcObj->unpatrolled,
385  'bot' => $rcObj->mAttribs['rc_bot'],
386  ];
387 
388  $params = $queryParams;
389 
390  if ( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
391  $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
392  }
393 
394  # Log timestamp
395  if ( $type == RC_LOG ) {
396  $link = htmlspecialchars( $rcObj->timestamp );
397  # Revision link
398  } elseif ( !ChangesList::userCan( $rcObj, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
399  $link = Html::element( 'span', [ 'class' => 'history-deleted' ], $rcObj->timestamp );
400  } else {
401  $link = $this->linkRenderer->makeKnownLink(
402  $rcObj->getTitle(),
403  $rcObj->timestamp,
404  [],
405  $params
406  );
407  if ( static::isDeleted( $rcObj, RevisionRecord::DELETED_TEXT ) ) {
408  $link = '<span class="history-deleted">' . $link . '</span> ';
409  }
410  }
411  $data['timestampLink'] = $link;
412 
413  $currentAndLastLinks = '';
414  if ( !$type == RC_LOG || $type == RC_NEW ) {
415  $currentAndLastLinks .= ' ' . $this->msg( 'parentheses' )->rawParams(
416  $rcObj->curlink .
417  $this->message['pipe-separator'] .
418  $rcObj->lastlink
419  )->escaped();
420  }
421  $data['currentAndLastLinks'] = $currentAndLastLinks;
422  $data['separatorAfterCurrentAndLastLinks'] = $separator;
423 
424  # Character diff
425  if ( $RCShowChangedSize ) {
426  $cd = $this->formatCharacterDifference( $rcObj );
427  if ( $cd !== '' ) {
428  $data['characterDiff'] = $cd;
429  $data['separatorAfterCharacterDiff'] = $separator;
430  }
431  }
432 
433  if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
434  $data['logEntry'] = $this->insertLogEntry( $rcObj );
435  } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) {
436  $data['comment'] = $this->insertComment( $rcObj );
437  } else {
438  # User links
439  $data['userLink'] = $rcObj->userlink;
440  $data['userTalkLink'] = $rcObj->usertalklink;
441  $data['comment'] = $this->insertComment( $rcObj );
442  }
443 
444  # Rollback
445  $data['rollback'] = $this->getRollback( $rcObj );
446 
447  # Tags
448  $data['tags'] = $this->getTags( $rcObj, $classes );
449 
450  $attribs = $this->getDataAttributes( $rcObj );
451 
452  // give the hook a chance to modify the data
453  $success = $this->getHookRunner()->onEnhancedChangesListModifyLineData(
454  $this, $data, $block, $rcObj, $classes, $attribs );
455  if ( !$success ) {
456  // skip entry if hook aborted it
457  return [];
458  }
459  $attribs = array_filter( $attribs,
460  [ Sanitizer::class, 'isReservedDataAttribute' ],
461  ARRAY_FILTER_USE_KEY
462  );
463 
464  $lineParams['recentChangesFlagsRaw'] = [];
465  if ( isset( $data['recentChangesFlags'] ) ) {
466  $lineParams['recentChangesFlags'] = $this->recentChangesFlags( $data['recentChangesFlags'] );
467  # FIXME: This is used by logic, don't return it in the template params.
468  $lineParams['recentChangesFlagsRaw'] = $data['recentChangesFlags'];
469  unset( $data['recentChangesFlags'] );
470  }
471 
472  if ( isset( $data['timestampLink'] ) ) {
473  $lineParams['timestampLink'] = $data['timestampLink'];
474  unset( $data['timestampLink'] );
475  }
476 
477  $lineParams['classes'] = array_values( $classes );
478  $lineParams['attribs'] = Html::expandAttributes( $attribs );
479 
480  // everything else: makes it easier for extensions to add or remove data
481  $lineParams['data'] = array_values( $data );
482 
483  return $lineParams;
484  }
485 
496  protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
497  if ( empty( $block ) ) {
498  return '';
499  }
500 
501  # Changes message
502  static $nchanges = [];
503  static $sinceLastVisitMsg = [];
504 
505  $n = count( $block );
506  if ( !isset( $nchanges[$n] ) ) {
507  $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
508  }
509 
510  $sinceLast = 0;
511  $unvisitedOldid = null;
513  foreach ( $block as $rcObj ) {
514  // Same logic as below inside main foreach
515  if ( $rcObj->watched ) {
516  $sinceLast++;
517  $unvisitedOldid = $rcObj->mAttribs['rc_last_oldid'];
518  }
519  }
520  if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
521  $sinceLastVisitMsg[$sinceLast] =
522  $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
523  }
524 
525  $currentRevision = 0;
526  foreach ( $block as $rcObj ) {
527  if ( !$currentRevision ) {
528  $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
529  }
530  }
531 
532  # Total change link
533  $links = [];
535  $block0 = $block[0];
536  $last = $block[count( $block ) - 1];
537  if ( !$allLogs ) {
538  if (
539  $isnew ||
540  $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE ||
541  !ChangesList::userCan( $rcObj, RevisionRecord::DELETED_TEXT, $this->getAuthority() )
542  ) {
543  $links['total-changes'] = Html::rawElement( 'span', [], $nchanges[$n] );
544  } else {
545  $links['total-changes'] = Html::rawElement( 'span', [],
546  $this->linkRenderer->makeKnownLink(
547  $block0->getTitle(),
548  new HtmlArmor( $nchanges[$n] ),
549  [ 'class' => 'mw-changeslist-groupdiff' ],
550  $queryParams + [
551  'diff' => $currentRevision,
552  'oldid' => $last->mAttribs['rc_last_oldid'],
553  ]
554  )
555  );
556  }
557 
558  if (
559  $rcObj->mAttribs['rc_type'] != RC_CATEGORIZE &&
560  $sinceLast > 0 &&
561  $sinceLast < $n
562  ) {
563  $links['total-changes-since-last'] = Html::rawElement( 'span', [],
564  $this->linkRenderer->makeKnownLink(
565  $block0->getTitle(),
566  new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
567  [ 'class' => 'mw-changeslist-groupdiff' ],
568  $queryParams + [
569  'diff' => $currentRevision,
570  'oldid' => $unvisitedOldid,
571  ]
572  )
573  );
574  }
575  }
576 
577  # History
578  if ( $allLogs || $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE ) {
579  // don't show history link for logs
580  } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
581  $links['history'] = Html::rawElement( 'span', [], $this->message['enhancedrc-history'] );
582  } else {
583  $params = $queryParams;
584  $params['action'] = 'history';
585 
586  $links['history'] = Html::rawElement( 'span', [],
587  $this->linkRenderer->makeKnownLink(
588  $block0->getTitle(),
589  new HtmlArmor( $this->message['enhancedrc-history'] ),
590  [ 'class' => 'mw-changeslist-history' ],
591  $params
592  )
593  );
594  }
595 
596  # Allow others to alter, remove or add to these links
597  $this->getHookRunner()->onEnhancedChangesList__getLogText( $this, $links, $block );
598 
599  if ( !$links ) {
600  return '';
601  }
602 
603  $logtext = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
604  implode( ' ', $links ) );
605  return ' ' . $logtext;
606  }
607 
614  protected function recentChangesBlockLine( $rcObj ) {
615  $data = [];
616 
617  $type = $rcObj->mAttribs['rc_type'];
618  $logType = $rcObj->mAttribs['rc_log_type'];
619  $classes = $this->getHTMLClasses( $rcObj, $rcObj->watched );
620  $classes[] = 'mw-enhanced-rc';
621 
622  if ( $logType ) {
623  # Log entry
624  $classes[] = 'mw-changeslist-log';
625  $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-' . $logType );
626  } else {
627  $classes[] = 'mw-changeslist-edit';
628  $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' .
629  $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
630  }
631 
632  # Flag and Timestamp
633  $data['recentChangesFlags'] = [
634  'newpage' => $type == RC_NEW,
635  'minor' => $rcObj->mAttribs['rc_minor'],
636  'unpatrolled' => $rcObj->unpatrolled,
637  'bot' => $rcObj->mAttribs['rc_bot'],
638  ];
639  // timestamp is not really a link here, but is called timestampLink
640  // for consistency with EnhancedChangesListModifyLineData
641  $data['timestampLink'] = htmlspecialchars( $rcObj->timestamp );
642 
643  # Article or log link
644  if ( $logType ) {
645  $logPage = new LogPage( $logType );
646  $logTitle = SpecialPage::getTitleFor( 'Log', $logType );
647  $logName = $logPage->getName()->text();
648  $data['logLink'] = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
649  $this->linkRenderer->makeKnownLink( $logTitle, $logName )
650  );
651  } else {
652  $data['articleLink'] = $this->getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
653  }
654 
655  # Diff and hist links
656  if ( $type != RC_LOG && $type != RC_CATEGORIZE ) {
657  $data['historyLink'] = $this->getDiffHistLinks( $rcObj, false );
658  }
659  $data['separatorAfterLinks'] = ' <span class="mw-changeslist-separator"></span> ';
660 
661  # Character diff
662  if ( $this->getConfig()->get( MainConfigNames::RCShowChangedSize ) ) {
663  $cd = $this->formatCharacterDifference( $rcObj );
664  if ( $cd !== '' ) {
665  $data['characterDiff'] = $cd;
666  $data['separatorAftercharacterDiff'] = ' <span class="mw-changeslist-separator"></span> ';
667  }
668  }
669 
670  if ( $type == RC_LOG ) {
671  $data['logEntry'] = $this->insertLogEntry( $rcObj );
672  } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) {
673  $data['comment'] = $this->insertComment( $rcObj );
674  } else {
675  $data['userLink'] = $rcObj->userlink;
676  $data['userTalkLink'] = $rcObj->usertalklink;
677  $data['comment'] = $this->insertComment( $rcObj );
678  if ( $type == RC_CATEGORIZE ) {
679  $data['historyLink'] = $this->getDiffHistLinks( $rcObj, false );
680  }
681  $data['rollback'] = $this->getRollback( $rcObj );
682  }
683 
684  # Tags
685  $data['tags'] = $this->getTags( $rcObj, $classes );
686 
687  # Show how many people are watching this if enabled
688  $data['watchingUsers'] = $this->numberofWatchingusers( $rcObj->numberofWatchingusers );
689 
690  $data['attribs'] = array_merge( $this->getDataAttributes( $rcObj ), [ 'class' => $classes ] );
691 
692  // give the hook a chance to modify the data
693  $success = $this->getHookRunner()->onEnhancedChangesListModifyBlockLineData(
694  $this, $data, $rcObj );
695  if ( !$success ) {
696  // skip entry if hook aborted it
697  return '';
698  }
699  $attribs = $data['attribs'];
700  unset( $data['attribs'] );
701  $attribs = array_filter( $attribs, static function ( $key ) {
702  return $key === 'class' || Sanitizer::isReservedDataAttribute( $key );
703  }, ARRAY_FILTER_USE_KEY );
704 
705  $prefix = '';
706  if ( is_callable( $this->changeLinePrefixer ) ) {
707  $prefix = call_user_func( $this->changeLinePrefixer, $rcObj, $this, false );
708  }
709 
710  $line = Html::openElement( 'table', $attribs ) . Html::openElement( 'tr' );
711  // Highlight block
712  $line .= Html::rawElement( 'td', [],
714  );
715 
716  $line .= Html::rawElement( 'td', [], '<span class="mw-enhancedchanges-arrow-space"></span>' );
717  $line .= Html::rawElement( 'td', [ 'class' => 'mw-changeslist-line-prefix' ], $prefix );
718  $line .= '<td class="mw-enhanced-rc" colspan="2">';
719 
720  if ( isset( $data['recentChangesFlags'] ) ) {
721  $line .= $this->recentChangesFlags( $data['recentChangesFlags'] );
722  unset( $data['recentChangesFlags'] );
723  }
724 
725  if ( isset( $data['timestampLink'] ) ) {
726  $line .= "\u{00A0}" . $data['timestampLink'];
727  unset( $data['timestampLink'] );
728  }
729  $line .= "\u{00A0}</td>";
730  $line .= Html::openElement( 'td', [
731  'class' => 'mw-changeslist-line-inner',
732  // Used for reliable determination of the affiliated page
733  'data-target-page' => $rcObj->getTitle(),
734  ] );
735 
736  // everything else: makes it easier for extensions to add or remove data
737  foreach ( $data as $key => $dataItem ) {
738  $line .= Html::rawElement( 'span', [
739  'class' => 'mw-changeslist-line-inner-' . $key,
740  ], $dataItem );
741  }
742 
743  $line .= "</td></tr></table>\n";
744 
745  return $line;
746  }
747 
759  public function getDiffHistLinks( RCCacheEntry $rc, $query = null, $useParentheses = null ) {
760  if ( is_bool( $query ) ) {
761  $useParentheses = $query;
762  } elseif ( $query !== null ) {
763  wfDeprecated( __METHOD__ . ' with $query parameter', '1.36' );
764  }
765  if ( $useParentheses === null ) {
766  $useParentheses = true;
767  }
768  $pageTitle = $rc->getTitle();
769  if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) {
770  // For categorizations we must swap the category title with the page title!
771  $pageTitle = Title::newFromID( $rc->getAttribute( 'rc_cur_id' ) );
772  if ( !$pageTitle ) {
773  // The page has been deleted, but the RC entry
774  // deletion job has not run yet. Just skip.
775  return '';
776  }
777  }
778 
779  $histLink = $this->linkRenderer->makeKnownLink(
780  $pageTitle,
781  new HtmlArmor( $this->message['hist'] ),
782  [ 'class' => 'mw-changeslist-history' ],
783  [
784  'action' => 'history',
785  'curid' => $rc->getAttribute( 'rc_cur_id' )
786  ]
787  );
788  if ( $useParentheses ) {
789  $retVal = $this->msg( 'parentheses' )
790  ->rawParams( $rc->difflink . $this->message['pipe-separator']
791  . $histLink )->escaped();
792  } else {
793  $retVal = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
794  Html::rawElement( 'span', [], $rc->difflink ) .
795  Html::rawElement( 'span', [], $histLink )
796  );
797  }
798  return ' ' . $retVal;
799  }
800 
807  protected function recentChangesBlock() {
808  if ( count( $this->rc_cache ) == 0 ) {
809  return '';
810  }
811 
812  $blockOut = '';
813  foreach ( $this->rc_cache as $block ) {
814  if ( count( $block ) < 2 ) {
815  $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
816  } else {
817  $blockOut .= $this->recentChangesBlockGroup( $block );
818  }
819  }
820 
821  if ( $blockOut === '' ) {
822  return '';
823  }
824  // $this->lastdate is kept up to date by recentChangesLine()
825  return Xml::element( 'h4', null, $this->lastdate ) . "\n<div>" . $blockOut . '</div>';
826  }
827 
833  public function endRecentChangesList() {
834  return $this->recentChangesBlock() . '</div>';
835  }
836 }
const RC_NEW
Definition: Defines.php:116
const RC_LOG
Definition: Defines.php:117
const RC_CATEGORIZE
Definition: Defines.php:119
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
$success
maybeWatchedLink( $link, $watched=false)
formatCharacterDifference(RecentChange $old, RecentChange $new=null)
Format the character difference of one or several changes.
getHighlightsContainerDiv()
Get the container for highlights that are used in the new StructuredFilters system.
recentChangesFlags( $flags, $nothing="\u{00A0}")
Returns the appropriate flags for new page, minor change and patrolling.
getDataAttributes(RecentChange $rc)
Get recommended data attributes for a change line.
numberofWatchingusers( $count)
Returns the string which indicates the number of watching users.
getHTMLClasses( $rc, $watched)
Get an array of default HTML class attributes for the change.
getTags(RecentChange $rc, array &$classes)
getArticleLink(&$rc, $unpatrolled, $watched)
Get the HTML link to the changed page, possibly with a prefix from hook handlers, and a suffix for te...
getRollback(RecentChange $rc)
insertLogEntry( $rc)
Insert a formatted action.
ChangesListFilterGroup[] $filterGroups
Definition: ChangesList.php:74
insertComment( $rc)
Insert a formatted comment.
static userCan( $rc, $field, Authority $performer=null)
Determine if the current user is allowed to view a particular field of this revision,...
isCategorizationWithoutRevision( $rcObj)
Determines whether a revision is linked to this change; this may not be the case when the categorizat...
getHTMLClassesForFilters( $rc)
Get an array of CSS classes attributed to filters for this row.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
IContextSource $context
RCCacheEntry[][] $rc_cache
TemplateParser $templateParser
recentChangesBlock()
If enhanced RC is in use, this function takes the previously cached RC lines, arranges them,...
getDiffHistLinks(RCCacheEntry $rc, $query=null, $useParentheses=null)
Returns value to be used in 'historyLink' element of $data param in EnhancedChangesListModifyBlockLin...
makeCacheGroupingKey(RCCacheEntry $cacheEntry)
beginRecentChangesList()
Add the JavaScript file for enhanced changeslist.
__construct( $context, array $filterGroups=[])
endRecentChangesList()
Returns text for the end of RC If enhanced RC is in use, returns pretty much all the text.
addCacheEntry(RCCacheEntry $cacheEntry)
Put accumulated information into the cache, for later display.
RCCacheEntryFactory $cacheEntryFactory
recentChangesBlockGroup( $block)
Enhanced RC group.
getLineData(array $block, RCCacheEntry $rcObj, array $queryParams=[])
recentChangesBlockLine( $rcObj)
Enhanced RC ungrouped line.
recentChangesLine(&$rc, $watched=false, $linenumber=null)
Format a line for enhanced recentchange (aka with javascript and block of lines).
getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden)
Generates amount of changes (linking to diff ) & link to history.
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:30
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:236
static expandAttributes(array $attribs)
Given an associative array of element attributes, generate a string to stick after the element name i...
Definition: Html.php:480
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:214
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:256
Class to simplify the use of log pages.
Definition: LogPage.php:39
const DELETED_ACTION
Definition: LogPage.php:40
A class containing constants representing the names of configuration variables.
Page revision base class.
getAttribute( $name)
Get an attribute value.
static isReservedDataAttribute( $attr)
Given an attribute name, checks whether it is a reserved data attribute (such as data-mw-foo) which i...
Definition: Sanitizer.php:654
static escapeClass( $class)
Given a value, escape it so that it can be used as a CSS class and return it.
Definition: Sanitizer.php:1106
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:518
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:43
$line
Definition: mcc.php:119
if(!file_exists( $CREDITS)) $lines