| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Context\IContextSource; |
| 22 |
use MediaWiki\Html\Html; |
| 23 |
use MediaWiki\Html\TemplateParser; |
| 24 |
use MediaWiki\MainConfigNames; |
| 25 |
use MediaWiki\Parser\Sanitizer; |
| 26 |
use MediaWiki\Revision\RevisionRecord; |
| 27 |
use MediaWiki\SpecialPage\SpecialPage; |
| 28 |
use MediaWiki\Title\Title; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class EnhancedChangesList extends ChangesList { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
protected $cacheEntryFactory; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
protected $rc_cache; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
protected $templateParser; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public function __construct( $context, array $filterGroups = [] ) { |
| 57 |
parent::__construct( $context, $filterGroups ); |
| 58 |
|
| 59 |
|
| 60 |
$this->cacheEntryFactory = new RCCacheEntryFactory( |
| 61 |
$context, |
| 62 |
$this->message, |
| 63 |
$this->linkRenderer |
| 64 |
); |
| 65 |
$this->templateParser = new TemplateParser(); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public function beginRecentChangesList() { |
| 73 |
$this->getOutput()->addModuleStyles( [ |
| 74 |
'mediawiki.special.changeslist.enhanced', |
| 75 |
] ); |
| 76 |
|
| 77 |
parent::beginRecentChangesList(); |
| 78 |
return '<div class="mw-changeslist" aria-live="polite">'; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) { |
| 91 |
$date = $this->getLanguage()->userDate( |
| 92 |
$rc->mAttribs['rc_timestamp'], |
| 93 |
$this->getUser() |
| 94 |
); |
| 95 |
if ( $this->lastdate === '' ) { |
| 96 |
$this->lastdate = $date; |
| 97 |
} |
| 98 |
|
| 99 |
$ret = ''; |
| 100 |
|
| 101 |
|
| 102 |
if ( $date !== $this->lastdate ) { |
| 103 |
|
| 104 |
$ret = $this->recentChangesBlock(); |
| 105 |
$this->rc_cache = []; |
| 106 |
$this->lastdate = $date; |
| 107 |
} |
| 108 |
|
| 109 |
$cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $rc, $watched ); |
| 110 |
$this->addCacheEntry( $cacheEntry ); |
| 111 |
|
| 112 |
return $ret; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
protected function addCacheEntry( RCCacheEntry $cacheEntry ) { |
| 122 |
$cacheGroupingKey = $this->makeCacheGroupingKey( $cacheEntry ); |
| 123 |
$this->rc_cache[$cacheGroupingKey][] = $cacheEntry; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
protected function makeCacheGroupingKey( RCCacheEntry $cacheEntry ) { |
| 134 |
$title = $cacheEntry->getTitle(); |
| 135 |
$cacheGroupingKey = $title->getPrefixedDBkey(); |
| 136 |
|
| 137 |
$type = $cacheEntry->mAttribs['rc_type']; |
| 138 |
|
| 139 |
if ( $type == RC_LOG ) { |
| 140 |
|
| 141 |
$cacheGroupingKey = SpecialPage::getTitleFor( |
| 142 |
'Log', |
| 143 |
$cacheEntry->mAttribs['rc_log_type'] |
| 144 |
)->getPrefixedDBkey(); |
| 145 |
} |
| 146 |
|
| 147 |
return $cacheGroupingKey; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
protected function recentChangesBlockGroup( $block ) { |
| 156 |
$recentChangesFlags = $this->getConfig()->get( MainConfigNames::RecentChangesFlags ); |
| 157 |
|
| 158 |
|
| 159 |
$tableClasses = [ 'mw-enhanced-rc', 'mw-changeslist-line' ]; |
| 160 |
if ( $block[0]->mAttribs['rc_log_type'] ) { |
| 161 |
|
| 162 |
$tableClasses[] = 'mw-changeslist-log'; |
| 163 |
$tableClasses[] = Sanitizer::escapeClass( 'mw-changeslist-log-' |
| 164 |
. $block[0]->mAttribs['rc_log_type'] ); |
| 165 |
} else { |
| 166 |
$tableClasses[] = 'mw-changeslist-edit'; |
| 167 |
$tableClasses[] = Sanitizer::escapeClass( 'mw-changeslist-ns' |
| 168 |
. $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] ); |
| 169 |
} |
| 170 |
if ( $block[0]->watched ) { |
| 171 |
$tableClasses[] = 'mw-changeslist-line-watched'; |
| 172 |
} else { |
| 173 |
$tableClasses[] = 'mw-changeslist-line-not-watched'; |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
$usercounts = []; |
| 178 |
$userlinks = []; |
| 179 |
|
| 180 |
$namehidden = true; |
| 181 |
$allLogs = true; |
| 182 |
$RCShowChangedSize = $this->getConfig()->get( MainConfigNames::RCShowChangedSize ); |
| 183 |
|
| 184 |
|
| 185 |
$collectedRcFlags = []; |
| 186 |
foreach ( $recentChangesFlags as $key => $value ) { |
| 187 |
$flagGrouping = $value['grouping'] ?? 'any'; |
| 188 |
switch ( $flagGrouping ) { |
| 189 |
case 'all': |
| 190 |
$collectedRcFlags[$key] = true; |
| 191 |
break; |
| 192 |
case 'any': |
| 193 |
$collectedRcFlags[$key] = false; |
| 194 |
break; |
| 195 |
default: |
| 196 |
throw new DomainException( "Unknown grouping type \"{$flagGrouping}\"" ); |
| 197 |
} |
| 198 |
} |
| 199 |
foreach ( $block as $rcObj ) { |
| 200 |
|
| 201 |
|
| 202 |
if ( !static::isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) { |
| 203 |
$namehidden = false; |
| 204 |
} |
| 205 |
$username = $rcObj->getPerformerIdentity()->getName(); |
| 206 |
$userlink = $rcObj->userlink; |
| 207 |
if ( !isset( $usercounts[$username] ) ) { |
| 208 |
$usercounts[$username] = 0; |
| 209 |
$userlinks[$username] = $userlink; |
| 210 |
} |
| 211 |
if ( $rcObj->mAttribs['rc_type'] != RC_LOG ) { |
| 212 |
$allLogs = false; |
| 213 |
} |
| 214 |
|
| 215 |
$usercounts[$username]++; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
krsort( $usercounts ); |
| 220 |
asort( $usercounts ); |
| 221 |
$users = []; |
| 222 |
foreach ( $usercounts as $username => $count ) { |
| 223 |
$text = (string)$userlinks[$username]; |
| 224 |
if ( $count > 1 ) { |
| 225 |
$formattedCount = $this->msg( 'ntimes' )->numParams( $count )->escaped(); |
| 226 |
$text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped(); |
| 227 |
} |
| 228 |
$users[] = $text; |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
$articleLink = ''; |
| 233 |
$revDeletedMsg = false; |
| 234 |
if ( $namehidden ) { |
| 235 |
$revDeletedMsg = $this->msg( 'rev-deleted-event' )->escaped(); |
| 236 |
} elseif ( $allLogs ) { |
| 237 |
$articleLink = $this->maybeWatchedLink( $block[0]->link, $block[0]->watched ); |
| 238 |
} else { |
| 239 |
$articleLink = $this->getArticleLink( |
| 240 |
$block[0], $block[0]->unpatrolled, $block[0]->watched ); |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
$lines = []; |
| 245 |
$filterClasses = []; |
| 246 |
foreach ( $block as $i => $rcObj ) { |
| 247 |
$line = $this->getLineData( $block, $rcObj ); |
| 248 |
if ( !$line ) { |
| 249 |
|
| 250 |
unset( $block[$i] ); |
| 251 |
continue; |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
foreach ( $line['recentChangesFlagsRaw'] as $key => $value ) { |
| 256 |
$flagGrouping = ( $recentChangesFlags[$key]['grouping'] ?? 'any' ); |
| 257 |
switch ( $flagGrouping ) { |
| 258 |
case 'all': |
| 259 |
if ( !$value ) { |
| 260 |
$collectedRcFlags[$key] = false; |
| 261 |
} |
| 262 |
break; |
| 263 |
case 'any': |
| 264 |
if ( $value ) { |
| 265 |
$collectedRcFlags[$key] = true; |
| 266 |
} |
| 267 |
break; |
| 268 |
default: |
| 269 |
throw new DomainException( "Unknown grouping type \"{$flagGrouping}\"" ); |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
$filterClasses = array_merge( $filterClasses, $this->getHTMLClassesForFilters( $rcObj ) ); |
| 275 |
|
| 276 |
$this->getTags( $rcObj, $filterClasses ); |
| 277 |
$filterClasses = array_unique( $filterClasses ); |
| 278 |
|
| 279 |
$lines[] = $line; |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
$block = array_values( $block ); |
| 285 |
$filterClasses = array_values( $filterClasses ); |
| 286 |
|
| 287 |
if ( !$block || !$lines ) { |
| 288 |
|
| 289 |
return ''; |
| 290 |
} |
| 291 |
|
| 292 |
$logText = $this->getLogText( $block, [], $allLogs, |
| 293 |
$collectedRcFlags['newpage'], $namehidden |
| 294 |
); |
| 295 |
|
| 296 |
|
| 297 |
$charDifference = false; |
| 298 |
if ( $RCShowChangedSize && !$allLogs ) { |
| 299 |
$last = 0; |
| 300 |
$first = count( $block ) - 1; |
| 301 |
|
| 302 |
while ( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) { |
| 303 |
$last++; |
| 304 |
} |
| 305 |
while ( $last < $first && $block[$first]->mAttribs['rc_old_len'] === null ) { |
| 306 |
$first--; |
| 307 |
} |
| 308 |
|
| 309 |
$charDifference = $this->formatCharacterDifference( $block[$first], $block[$last] ) ?: false; |
| 310 |
} |
| 311 |
|
| 312 |
$numberofWatchingusers = $this->numberofWatchingusers( $block[0]->numberofWatchingusers ); |
| 313 |
$usersList = $this->msg( 'brackets' )->rawParams( |
| 314 |
implode( $this->message['semicolon-separator'], $users ) |
| 315 |
)->escaped(); |
| 316 |
|
| 317 |
$prefix = ''; |
| 318 |
if ( is_callable( $this->changeLinePrefixer ) ) { |
| 319 |
$prefix = call_user_func( $this->changeLinePrefixer, $block[0], $this, true ); |
| 320 |
} |
| 321 |
|
| 322 |
$templateParams = [ |
| 323 |
'checkboxId' => 'mw-checkbox-' . base64_encode( random_bytes( 3 ) ), |
| 324 |
'articleLink' => $articleLink, |
| 325 |
'charDifference' => $charDifference, |
| 326 |
'collectedRcFlags' => $this->recentChangesFlags( $collectedRcFlags ), |
| 327 |
'filterClasses' => $filterClasses, |
| 328 |
'lines' => $lines, |
| 329 |
'logText' => $logText, |
| 330 |
'numberofWatchingusers' => $numberofWatchingusers, |
| 331 |
'prefix' => $prefix, |
| 332 |
'rev-deleted-event' => $revDeletedMsg, |
| 333 |
'tableClasses' => $tableClasses, |
| 334 |
'timestamp' => $block[0]->timestamp, |
| 335 |
'fullTimestamp' => $block[0]->getAttribute( 'rc_timestamp' ), |
| 336 |
'users' => $usersList, |
| 337 |
]; |
| 338 |
|
| 339 |
$this->rcCacheIndex++; |
| 340 |
|
| 341 |
return $this->templateParser->processTemplate( |
| 342 |
'EnhancedChangesListGroup', |
| 343 |
$templateParams |
| 344 |
); |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
protected function getLineData( array $block, RCCacheEntry $rcObj, array $queryParams = [] ) { |
| 354 |
$RCShowChangedSize = $this->getConfig()->get( MainConfigNames::RCShowChangedSize ); |
| 355 |
|
| 356 |
$type = $rcObj->mAttribs['rc_type']; |
| 357 |
$data = []; |
| 358 |
$titleText = $rcObj->getTitle(); |
| 359 |
if ( !ChangesList::userCan( $rcObj, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) { |
| 360 |
$titleText = $this->msg( 'rev-deleted-event' ); |
| 361 |
} |
| 362 |
$lineParams = [ 'targetTitle' => $titleText ]; |
| 363 |
|
| 364 |
$classes = [ 'mw-enhanced-rc' ]; |
| 365 |
if ( $rcObj->watched ) { |
| 366 |
$classes[] = 'mw-enhanced-watched'; |
| 367 |
} |
| 368 |
$classes = array_merge( $classes, $this->getHTMLClasses( $rcObj, $rcObj->watched ) ); |
| 369 |
|
| 370 |
$separator = ' <span class="mw-changeslist-separator"></span> '; |
| 371 |
|
| 372 |
$data['recentChangesFlags'] = [ |
| 373 |
'newpage' => $type == RC_NEW, |
| 374 |
'minor' => $rcObj->mAttribs['rc_minor'], |
| 375 |
'unpatrolled' => $rcObj->unpatrolled, |
| 376 |
'bot' => $rcObj->mAttribs['rc_bot'], |
| 377 |
]; |
| 378 |
|
| 379 |
|
| 380 |
if ( $type == RC_LOG ) { |
| 381 |
$link = htmlspecialchars( $rcObj->timestamp ); |
| 382 |
|
| 383 |
} elseif ( !ChangesList::userCan( $rcObj, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) { |
| 384 |
$link = Html::element( 'span', [ 'class' => 'history-deleted' ], $rcObj->timestamp ); |
| 385 |
} else { |
| 386 |
$params = []; |
| 387 |
$params['curid'] = $rcObj->mAttribs['rc_cur_id']; |
| 388 |
if ( $rcObj->mAttribs['rc_this_oldid'] != 0 ) { |
| 389 |
$params['oldid'] = $rcObj->mAttribs['rc_this_oldid']; |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
$link = $this->linkRenderer->makeKnownLink( |
| 395 |
$rcObj->getTitle(), |
| 396 |
$rcObj->timestamp, |
| 397 |
[], |
| 398 |
$params + $queryParams |
| 399 |
); |
| 400 |
if ( static::isDeleted( $rcObj, RevisionRecord::DELETED_TEXT ) ) { |
| 401 |
$link = '<span class="history-deleted">' . $link . '</span> '; |
| 402 |
} |
| 403 |
} |
| 404 |
$data['timestampLink'] = $link; |
| 405 |
|
| 406 |
$currentAndLastLinks = ''; |
| 407 |
if ( $type == RC_EDIT || $type == RC_NEW ) { |
| 408 |
$currentAndLastLinks .= ' ' . $this->msg( 'parentheses' )->rawParams( |
| 409 |
$rcObj->curlink . |
| 410 |
$this->message['pipe-separator'] . |
| 411 |
$rcObj->lastlink |
| 412 |
)->escaped(); |
| 413 |
} |
| 414 |
$data['currentAndLastLinks'] = $currentAndLastLinks; |
| 415 |
$data['separatorAfterCurrentAndLastLinks'] = $separator; |
| 416 |
|
| 417 |
|
| 418 |
if ( $RCShowChangedSize ) { |
| 419 |
$cd = $this->formatCharacterDifference( $rcObj ); |
| 420 |
if ( $cd !== '' ) { |
| 421 |
$data['characterDiff'] = $cd; |
| 422 |
$data['separatorAfterCharacterDiff'] = $separator; |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
if ( $type == RC_LOG ) { |
| 427 |
$data['logEntry'] = $this->insertLogEntry( $rcObj ); |
| 428 |
} elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) { |
| 429 |
$data['comment'] = $this->insertComment( $rcObj ); |
| 430 |
} else { |
| 431 |
|
| 432 |
$data['userLink'] = $rcObj->userlink; |
| 433 |
$data['userTalkLink'] = $rcObj->usertalklink; |
| 434 |
$data['comment'] = $this->insertComment( $rcObj ); |
| 435 |
if ( $type == RC_CATEGORIZE ) { |
| 436 |
$data['historyLink'] = $this->getDiffHistLinks( $rcObj, false ); |
| 437 |
} |
| 438 |
|
| 439 |
$data['rollback'] = $this->getRollback( $rcObj ); |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
$data['tags'] = $this->getTags( $rcObj, $classes ); |
| 444 |
|
| 445 |
$attribs = $this->getDataAttributes( $rcObj ); |
| 446 |
|
| 447 |
|
| 448 |
$success = $this->getHookRunner()->onEnhancedChangesListModifyLineData( |
| 449 |
$this, $data, $block, $rcObj, $classes, $attribs ); |
| 450 |
if ( !$success ) { |
| 451 |
|
| 452 |
return []; |
| 453 |
} |
| 454 |
$attribs = array_filter( $attribs, |
| 455 |
[ Sanitizer::class, 'isReservedDataAttribute' ], |
| 456 |
ARRAY_FILTER_USE_KEY |
| 457 |
); |
| 458 |
|
| 459 |
$lineParams['recentChangesFlagsRaw'] = []; |
| 460 |
if ( isset( $data['recentChangesFlags'] ) ) { |
| 461 |
$lineParams['recentChangesFlags'] = $this->recentChangesFlags( $data['recentChangesFlags'] ); |
| 462 |
|
| 463 |
$lineParams['recentChangesFlagsRaw'] = $data['recentChangesFlags']; |
| 464 |
unset( $data['recentChangesFlags'] ); |
| 465 |
} |
| 466 |
|
| 467 |
if ( isset( $data['timestampLink'] ) ) { |
| 468 |
$lineParams['timestampLink'] = $data['timestampLink']; |
| 469 |
unset( $data['timestampLink'] ); |
| 470 |
} |
| 471 |
|
| 472 |
$lineParams['classes'] = array_values( $classes ); |
| 473 |
$lineParams['attribs'] = Html::expandAttributes( $attribs ); |
| 474 |
|
| 475 |
|
| 476 |
$lineParams['data'] = array_values( $data ); |
| 477 |
|
| 478 |
return $lineParams; |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) { |
| 492 |
if ( !$block ) { |
| 493 |
return ''; |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
static $nchanges = []; |
| 498 |
static $sinceLastVisitMsg = []; |
| 499 |
|
| 500 |
$n = count( $block ); |
| 501 |
if ( !isset( $nchanges[$n] ) ) { |
| 502 |
$nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped(); |
| 503 |
} |
| 504 |
|
| 505 |
$sinceLast = 0; |
| 506 |
$unvisitedOldid = null; |
| 507 |
$currentRevision = 0; |
| 508 |
$previousRevision = 0; |
| 509 |
$curId = 0; |
| 510 |
$allCategorization = true; |
| 511 |
|
| 512 |
foreach ( $block as $rcObj ) { |
| 513 |
|
| 514 |
|
| 515 |
if ( $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE ) { |
| 516 |
continue; |
| 517 |
} |
| 518 |
|
| 519 |
$allCategorization = false; |
| 520 |
$previousRevision = $rcObj->mAttribs['rc_last_oldid']; |
| 521 |
|
| 522 |
if ( $rcObj->watched ) { |
| 523 |
$sinceLast++; |
| 524 |
$unvisitedOldid = $previousRevision; |
| 525 |
} |
| 526 |
if ( !$currentRevision ) { |
| 527 |
$currentRevision = $rcObj->mAttribs['rc_this_oldid']; |
| 528 |
} |
| 529 |
if ( !$curId ) { |
| 530 |
$curId = $rcObj->mAttribs['rc_cur_id']; |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
$links = []; |
| 536 |
$title = $block[0]->getTitle(); |
| 537 |
if ( !$allLogs ) { |
| 538 |
|
| 539 |
|
| 540 |
if ( $isnew || $allCategorization ) { |
| 541 |
$links['total-changes'] = Html::rawElement( 'span', [], $nchanges[$n] ); |
| 542 |
} else { |
| 543 |
$links['total-changes'] = Html::rawElement( 'span', [], |
| 544 |
$this->linkRenderer->makeKnownLink( |
| 545 |
$title, |
| 546 |
new HtmlArmor( $nchanges[$n] ), |
| 547 |
[ 'class' => 'mw-changeslist-groupdiff' ], |
| 548 |
$queryParams + [ |
| 549 |
'curid' => $curId, |
| 550 |
'diff' => $currentRevision, |
| 551 |
'oldid' => $previousRevision, |
| 552 |
] |
| 553 |
) |
| 554 |
); |
| 555 |
} |
| 556 |
|
| 557 |
if ( |
| 558 |
!$allCategorization && |
| 559 |
$sinceLast > 0 && |
| 560 |
$sinceLast < $n |
| 561 |
) { |
| 562 |
if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) { |
| 563 |
$sinceLastVisitMsg[$sinceLast] = |
| 564 |
$this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped(); |
| 565 |
} |
| 566 |
$links['total-changes-since-last'] = Html::rawElement( 'span', [], |
| 567 |
$this->linkRenderer->makeKnownLink( |
| 568 |
$title, |
| 569 |
new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ), |
| 570 |
[ 'class' => 'mw-changeslist-groupdiff' ], |
| 571 |
$queryParams + [ |
| 572 |
'curid' => $curId, |
| 573 |
'diff' => $currentRevision, |
| 574 |
'oldid' => $unvisitedOldid, |
| 575 |
] |
| 576 |
) |
| 577 |
); |
| 578 |
} |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
if ( $allLogs || $allCategorization ) { |
| 583 |
|
| 584 |
} elseif ( $namehidden || !$title->exists() ) { |
| 585 |
$links['history'] = Html::rawElement( 'span', [], $this->message['enhancedrc-history'] ); |
| 586 |
} else { |
| 587 |
$links['history'] = Html::rawElement( 'span', [], |
| 588 |
$this->linkRenderer->makeKnownLink( |
| 589 |
$title, |
| 590 |
new HtmlArmor( $this->message['enhancedrc-history'] ), |
| 591 |
[ 'class' => 'mw-changeslist-history' ], |
| 592 |
[ |
| 593 |
'curid' => $curId, |
| 594 |
'action' => 'history', |
| 595 |
] + $queryParams |
| 596 |
) |
| 597 |
); |
| 598 |
} |
| 599 |
|
| 600 |
|
| 601 |
$this->getHookRunner()->onEnhancedChangesList__getLogText( $this, $links, $block ); |
| 602 |
|
| 603 |
if ( !$links ) { |
| 604 |
return ''; |
| 605 |
} |
| 606 |
|
| 607 |
$logtext = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ], |
| 608 |
implode( ' ', $links ) ); |
| 609 |
return ' ' . $logtext; |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
protected function recentChangesBlockLine( $rcObj ) { |
| 619 |
$data = []; |
| 620 |
|
| 621 |
$type = $rcObj->mAttribs['rc_type']; |
| 622 |
$logType = $rcObj->mAttribs['rc_log_type']; |
| 623 |
$classes = $this->getHTMLClasses( $rcObj, $rcObj->watched ); |
| 624 |
$classes[] = 'mw-enhanced-rc'; |
| 625 |
|
| 626 |
if ( $logType ) { |
| 627 |
|
| 628 |
$classes[] = 'mw-changeslist-log'; |
| 629 |
$classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-' . $logType ); |
| 630 |
} else { |
| 631 |
$classes[] = 'mw-changeslist-edit'; |
| 632 |
$classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' . |
| 633 |
$rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] ); |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
$data['recentChangesFlags'] = [ |
| 638 |
'newpage' => $type == RC_NEW, |
| 639 |
'minor' => $rcObj->mAttribs['rc_minor'], |
| 640 |
'unpatrolled' => $rcObj->unpatrolled, |
| 641 |
'bot' => $rcObj->mAttribs['rc_bot'], |
| 642 |
]; |
| 643 |
|
| 644 |
|
| 645 |
$data['timestampLink'] = htmlspecialchars( $rcObj->timestamp ); |
| 646 |
|
| 647 |
|
| 648 |
if ( $logType ) { |
| 649 |
$logPage = new LogPage( $logType ); |
| 650 |
$logTitle = SpecialPage::getTitleFor( 'Log', $logType ); |
| 651 |
$logName = $logPage->getName()->text(); |
| 652 |
$data['logLink'] = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ], |
| 653 |
$this->linkRenderer->makeKnownLink( $logTitle, $logName ) |
| 654 |
); |
| 655 |
} else { |
| 656 |
$data['articleLink'] = $this->getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched ); |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
if ( $type != RC_LOG && $type != RC_CATEGORIZE ) { |
| 661 |
$data['historyLink'] = $this->getDiffHistLinks( $rcObj, false ); |
| 662 |
} |
| 663 |
$data['separatorAfterLinks'] = ' <span class="mw-changeslist-separator"></span> '; |
| 664 |
|
| 665 |
|
| 666 |
if ( $this->getConfig()->get( MainConfigNames::RCShowChangedSize ) ) { |
| 667 |
$cd = $this->formatCharacterDifference( $rcObj ); |
| 668 |
if ( $cd !== '' ) { |
| 669 |
$data['characterDiff'] = $cd; |
| 670 |
$data['separatorAftercharacterDiff'] = ' <span class="mw-changeslist-separator"></span> '; |
| 671 |
} |
| 672 |
} |
| 673 |
|
| 674 |
if ( $type == RC_LOG ) { |
| 675 |
$data['logEntry'] = $this->insertLogEntry( $rcObj ); |
| 676 |
} elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) { |
| 677 |
$data['comment'] = $this->insertComment( $rcObj ); |
| 678 |
} else { |
| 679 |
$data['userLink'] = $rcObj->userlink; |
| 680 |
$data['userTalkLink'] = $rcObj->usertalklink; |
| 681 |
$data['comment'] = $this->insertComment( $rcObj ); |
| 682 |
if ( $type == RC_CATEGORIZE ) { |
| 683 |
$data['historyLink'] = $this->getDiffHistLinks( $rcObj, false ); |
| 684 |
} |
| 685 |
$data['rollback'] = $this->getRollback( $rcObj ); |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
$data['tags'] = $this->getTags( $rcObj, $classes ); |
| 690 |
|
| 691 |
|
| 692 |
$data['watchingUsers'] = $this->numberofWatchingusers( $rcObj->numberofWatchingusers ); |
| 693 |
|
| 694 |
$data['attribs'] = array_merge( $this->getDataAttributes( $rcObj ), [ 'class' => $classes ] ); |
| 695 |
|
| 696 |
|
| 697 |
$success = $this->getHookRunner()->onEnhancedChangesListModifyBlockLineData( |
| 698 |
$this, $data, $rcObj ); |
| 699 |
if ( !$success ) { |
| 700 |
|
| 701 |
return ''; |
| 702 |
} |
| 703 |
$attribs = $data['attribs']; |
| 704 |
unset( $data['attribs'] ); |
| 705 |
$attribs = array_filter( $attribs, static function ( $key ) { |
| 706 |
return $key === 'class' || Sanitizer::isReservedDataAttribute( $key ); |
| 707 |
}, ARRAY_FILTER_USE_KEY ); |
| 708 |
|
| 709 |
$prefix = ''; |
| 710 |
if ( is_callable( $this->changeLinePrefixer ) ) { |
| 711 |
$prefix = call_user_func( $this->changeLinePrefixer, $rcObj, $this, false ); |
| 712 |
} |
| 713 |
|
| 714 |
$line = Html::openElement( 'table', $attribs ) . Html::openElement( 'tr' ); |
| 715 |
|
| 716 |
$line .= Html::rawElement( 'td', [], |
| 717 |
$this->getHighlightsContainerDiv() |
| 718 |
); |
| 719 |
|
| 720 |
$line .= Html::rawElement( 'td', [], '<span class="mw-enhancedchanges-arrow-space"></span>' ); |
| 721 |
$line .= Html::rawElement( 'td', [ 'class' => 'mw-changeslist-line-prefix' ], $prefix ); |
| 722 |
$line .= '<td class="mw-enhanced-rc" colspan="2">'; |
| 723 |
|
| 724 |
if ( isset( $data['recentChangesFlags'] ) ) { |
| 725 |
$line .= $this->recentChangesFlags( $data['recentChangesFlags'] ); |
| 726 |
unset( $data['recentChangesFlags'] ); |
| 727 |
} |
| 728 |
|
| 729 |
if ( isset( $data['timestampLink'] ) ) { |
| 730 |
$line .= "\u{00A0}" . $data['timestampLink']; |
| 731 |
unset( $data['timestampLink'] ); |
| 732 |
} |
| 733 |
|
| 734 |
$titleText = $rcObj->getTitle(); |
| 735 |
if ( !ChangesList::userCan( $rcObj, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) { |
| 736 |
$titleText = $this->msg( 'rev-deleted-event' )->escaped(); |
| 737 |
} |
| 738 |
$line .= "\u{00A0}</td>"; |
| 739 |
$line .= Html::openElement( 'td', [ |
| 740 |
'class' => 'mw-changeslist-line-inner', |
| 741 |
|
| 742 |
'data-target-page' => $titleText, |
| 743 |
] ); |
| 744 |
|
| 745 |
|
| 746 |
foreach ( $data as $key => $dataItem ) { |
| 747 |
$line .= Html::rawElement( 'span', [ |
| 748 |
'class' => 'mw-changeslist-line-inner-' . $key, |
| 749 |
], $dataItem ); |
| 750 |
} |
| 751 |
|
| 752 |
$line .= "</td></tr></table>\n"; |
| 753 |
|
| 754 |
return $line; |
| 755 |
} |
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
public function getDiffHistLinks( RCCacheEntry $rc, $query = null, $useParentheses = null ) { |
| 769 |
if ( is_bool( $query ) ) { |
| 770 |
$useParentheses = $query; |
| 771 |
} elseif ( $query !== null ) { |
| 772 |
wfDeprecated( __METHOD__ . ' with $query parameter', '1.36' ); |
| 773 |
} |
| 774 |
$pageTitle = $rc->getTitle(); |
| 775 |
if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) { |
| 776 |
|
| 777 |
$pageTitle = Title::newFromID( $rc->getAttribute( 'rc_cur_id' ) ); |
| 778 |
if ( !$pageTitle ) { |
| 779 |
|
| 780 |
|
| 781 |
return ''; |
| 782 |
} |
| 783 |
} |
| 784 |
|
| 785 |
$histLink = $this->linkRenderer->makeKnownLink( |
| 786 |
$pageTitle, |
| 787 |
new HtmlArmor( $this->message['hist'] ), |
| 788 |
[ 'class' => 'mw-changeslist-history' ], |
| 789 |
[ |
| 790 |
'curid' => $rc->getAttribute( 'rc_cur_id' ), |
| 791 |
'action' => 'history' |
| 792 |
] |
| 793 |
); |
| 794 |
if ( $useParentheses !== false ) { |
| 795 |
$retVal = $this->msg( 'parentheses' ) |
| 796 |
->rawParams( $rc->difflink . $this->message['pipe-separator'] |
| 797 |
. $histLink )->escaped(); |
| 798 |
} else { |
| 799 |
$retVal = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ], |
| 800 |
Html::rawElement( 'span', [], $rc->difflink ) . |
| 801 |
Html::rawElement( 'span', [], $histLink ) |
| 802 |
); |
| 803 |
} |
| 804 |
return ' ' . $retVal; |
| 805 |
} |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
protected function recentChangesBlock() { |
| 814 |
if ( count( $this->rc_cache ) == 0 ) { |
| 815 |
return ''; |
| 816 |
} |
| 817 |
|
| 818 |
$blockOut = ''; |
| 819 |
foreach ( $this->rc_cache as $block ) { |
| 820 |
$visibleBlock = []; |
| 821 |
$hiddenBlock = []; |
| 822 |
|
| 823 |
|
| 824 |
foreach ( $block as $rcObj ) { |
| 825 |
if ( static::isDeleted( $rcObj, RevisionRecord::DELETED_USER ) ) { |
| 826 |
$hiddenBlock[] = $rcObj; |
| 827 |
} else { |
| 828 |
$visibleBlock[] = $rcObj; |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
$visibleCount = count( $visibleBlock ); |
| 833 |
|
| 834 |
if ( $visibleCount > 0 ) { |
| 835 |
$blockOut .= $visibleCount > 1 ? |
| 836 |
$this->recentChangesBlockGroup( $visibleBlock ) : |
| 837 |
$this->recentChangesBlockLine( array_shift( $visibleBlock ) ); |
| 838 |
|
| 839 |
} |
| 840 |
|
| 841 |
$hiddenCount = count( $hiddenBlock ); |
| 842 |
|
| 843 |
if ( $hiddenCount > 0 ) { |
| 844 |
$blockOut .= $hiddenCount > 1 ? |
| 845 |
$this->recentChangesBlockGroup( $hiddenBlock ) : |
| 846 |
$this->recentChangesBlockLine( array_shift( $hiddenBlock ) ); |
| 847 |
} |
| 848 |
} |
| 849 |
|
| 850 |
if ( $blockOut === '' ) { |
| 851 |
return ''; |
| 852 |
} |
| 853 |
|
| 854 |
return Html::element( 'h4', [], $this->lastdate ) . "\n<div>" . $blockOut . '</div>'; |
| 855 |
} |
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
public function endRecentChangesList() { |
| 863 |
return $this->recentChangesBlock() . '</div>'; |
| 864 |
} |
| 865 |
} |