| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\CommentFormatter\RowCommentFormatter; |
| 22 |
use MediaWiki\Context\ContextSource; |
| 23 |
use MediaWiki\Context\IContextSource; |
| 24 |
use MediaWiki\Context\RequestContext; |
| 25 |
use MediaWiki\HookContainer\HookRunner; |
| 26 |
use MediaWiki\HookContainer\ProtectedHookAccessorTrait; |
| 27 |
use MediaWiki\Html\Html; |
| 28 |
use MediaWiki\Language\Language; |
| 29 |
use MediaWiki\Linker\Linker; |
| 30 |
use MediaWiki\Linker\LinkRenderer; |
| 31 |
use MediaWiki\MainConfigNames; |
| 32 |
use MediaWiki\MediaWikiServices; |
| 33 |
use MediaWiki\Pager\PagerTools; |
| 34 |
use MediaWiki\Parser\Sanitizer; |
| 35 |
use MediaWiki\Permissions\Authority; |
| 36 |
use MediaWiki\Revision\MutableRevisionRecord; |
| 37 |
use MediaWiki\Revision\RevisionRecord; |
| 38 |
use MediaWiki\Title\Title; |
| 39 |
use MediaWiki\User\User; |
| 40 |
use MediaWiki\User\UserIdentityValue; |
| 41 |
use MediaWiki\Watchlist\WatchedItem; |
| 42 |
use OOUI\IconWidget; |
| 43 |
use Wikimedia\Rdbms\IResultWrapper; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
class ChangesList extends ContextSource { |
| 54 |
use ProtectedHookAccessorTrait; |
| 55 |
|
| 56 |
public const CSS_CLASS_PREFIX = 'mw-changeslist-'; |
| 57 |
|
| 58 |
|
| 59 |
protected $watchlist = false; |
| 60 |
|
| 61 |
protected $lastdate; |
| 62 |
|
| 63 |
protected $message; |
| 64 |
|
| 65 |
protected $rc_cache; |
| 66 |
|
| 67 |
protected $rcCacheIndex; |
| 68 |
|
| 69 |
protected $rclistOpen; |
| 70 |
|
| 71 |
protected $rcMoveIndex; |
| 72 |
|
| 73 |
|
| 74 |
protected $changeLinePrefixer; |
| 75 |
|
| 76 |
|
| 77 |
protected $watchMsgCache; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
protected $linkRenderer; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
protected $commentFormatter; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
protected $formattedComments; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
protected $filterGroups; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
protected $tagsCache; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
protected $userLinkCache; |
| 108 |
|
| 109 |
private LogFormatterFactory $logFormatterFactory; |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public function __construct( $context, array $filterGroups = [] ) { |
| 116 |
$this->setContext( $context ); |
| 117 |
$this->preCacheMessages(); |
| 118 |
$this->watchMsgCache = new MapCacheLRU( 50 ); |
| 119 |
$this->filterGroups = $filterGroups; |
| 120 |
|
| 121 |
$services = MediaWikiServices::getInstance(); |
| 122 |
$this->linkRenderer = $services->getLinkRenderer(); |
| 123 |
$this->commentFormatter = $services->getRowCommentFormatter(); |
| 124 |
$this->logFormatterFactory = $services->getLogFormatterFactory(); |
| 125 |
$this->tagsCache = new MapCacheLRU( 50 ); |
| 126 |
$this->userLinkCache = new MapCacheLRU( 50 ); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public static function newFromContext( IContextSource $context, array $groups = [] ) { |
| 138 |
$user = $context->getUser(); |
| 139 |
$sk = $context->getSkin(); |
| 140 |
$services = MediaWikiServices::getInstance(); |
| 141 |
$list = null; |
| 142 |
if ( ( new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) { |
| 143 |
$userOptionsLookup = $services->getUserOptionsLookup(); |
| 144 |
$new = $context->getRequest()->getBool( |
| 145 |
'enhanced', |
| 146 |
$userOptionsLookup->getBoolOption( $user, 'usenewrc' ) |
| 147 |
); |
| 148 |
|
| 149 |
return $new ? |
| 150 |
new EnhancedChangesList( $context, $groups ) : |
| 151 |
new OldChangesList( $context, $groups ); |
| 152 |
} else { |
| 153 |
return $list; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) { |
| 169 |
throw new RuntimeException( 'recentChangesLine should be implemented' ); |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
protected function getHighlightsContainerDiv() { |
| 179 |
$highlightColorDivs = ''; |
| 180 |
foreach ( [ 'none', 'c1', 'c2', 'c3', 'c4', 'c5' ] as $color ) { |
| 181 |
$highlightColorDivs .= Html::rawElement( |
| 182 |
'div', |
| 183 |
[ |
| 184 |
'class' => 'mw-rcfilters-ui-highlights-color-' . $color, |
| 185 |
'data-color' => $color |
| 186 |
] |
| 187 |
); |
| 188 |
} |
| 189 |
|
| 190 |
return Html::rawElement( |
| 191 |
'div', |
| 192 |
[ 'class' => 'mw-rcfilters-ui-highlights' ], |
| 193 |
$highlightColorDivs |
| 194 |
); |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
public function setWatchlistDivs( $value = true ) { |
| 202 |
$this->watchlist = $value; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
public function isWatchlist() { |
| 210 |
return (bool)$this->watchlist; |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
private function preCacheMessages() { |
| 218 |
if ( !isset( $this->message ) ) { |
| 219 |
$this->message = []; |
| 220 |
foreach ( [ |
| 221 |
'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history', |
| 222 |
'semicolon-separator', 'pipe-separator', 'word-separator' ] as $msg |
| 223 |
) { |
| 224 |
$this->message[$msg] = $this->msg( $msg )->escaped(); |
| 225 |
} |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
public function recentChangesFlags( $flags, $nothing = "\u{00A0}" ) { |
| 236 |
$f = ''; |
| 237 |
foreach ( |
| 238 |
$this->getConfig()->get( MainConfigNames::RecentChangesFlags ) as $flag => $_ |
| 239 |
) { |
| 240 |
$f .= isset( $flags[$flag] ) && $flags[$flag] |
| 241 |
? self::flag( $flag, $this->getContext() ) |
| 242 |
: $nothing; |
| 243 |
} |
| 244 |
|
| 245 |
return $f; |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
protected function getHTMLClasses( $rc, $watched ) { |
| 257 |
$classes = [ self::CSS_CLASS_PREFIX . 'line' ]; |
| 258 |
$logType = $rc->mAttribs['rc_log_type']; |
| 259 |
|
| 260 |
if ( $logType ) { |
| 261 |
$classes[] = self::CSS_CLASS_PREFIX . 'log'; |
| 262 |
$classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'log-' . $logType ); |
| 263 |
} else { |
| 264 |
$classes[] = self::CSS_CLASS_PREFIX . 'edit'; |
| 265 |
$classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' . |
| 266 |
$rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] ); |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
$classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched |
| 272 |
? self::CSS_CLASS_PREFIX . 'line-watched' |
| 273 |
: self::CSS_CLASS_PREFIX . 'line-not-watched'; |
| 274 |
|
| 275 |
$classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rc ) ); |
| 276 |
|
| 277 |
return $classes; |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
protected function getHTMLClassesForFilters( $rc ) { |
| 288 |
$classes = []; |
| 289 |
|
| 290 |
$classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' . |
| 291 |
$rc->mAttribs['rc_namespace'] ); |
| 292 |
|
| 293 |
$nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); |
| 294 |
$classes[] = Sanitizer::escapeClass( |
| 295 |
self::CSS_CLASS_PREFIX . |
| 296 |
'ns-' . |
| 297 |
( $nsInfo->isTalk( $rc->mAttribs['rc_namespace'] ) ? 'talk' : 'subject' ) |
| 298 |
); |
| 299 |
|
| 300 |
foreach ( $this->filterGroups as $filterGroup ) { |
| 301 |
foreach ( $filterGroup->getFilters() as $filter ) { |
| 302 |
$filter->applyCssClassIfNeeded( $this, $rc, $classes ); |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
return $classes; |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
public static function flag( $flag, ?IContextSource $context = null ) { |
| 320 |
static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ]; |
| 321 |
static $flagInfos = null; |
| 322 |
|
| 323 |
if ( $flagInfos === null ) { |
| 324 |
$recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig() |
| 325 |
->get( MainConfigNames::RecentChangesFlags ); |
| 326 |
$flagInfos = []; |
| 327 |
foreach ( $recentChangesFlags as $key => $value ) { |
| 328 |
$flagInfos[$key]['letter'] = $value['letter']; |
| 329 |
$flagInfos[$key]['title'] = $value['title']; |
| 330 |
|
| 331 |
$flagInfos[$key]['class'] = $value['class'] ?? $key; |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
$context = $context ?: RequestContext::getMain(); |
| 336 |
|
| 337 |
|
| 338 |
if ( isset( $map[$flag] ) ) { |
| 339 |
$flag = $map[$flag]; |
| 340 |
} |
| 341 |
|
| 342 |
$info = $flagInfos[$flag]; |
| 343 |
return Html::element( 'abbr', [ |
| 344 |
'class' => $info['class'], |
| 345 |
'title' => wfMessage( $info['title'] )->setContext( $context )->text(), |
| 346 |
], wfMessage( $info['letter'] )->setContext( $context )->text() ); |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
public function beginRecentChangesList() { |
| 354 |
$this->rc_cache = []; |
| 355 |
$this->rcMoveIndex = 0; |
| 356 |
$this->rcCacheIndex = 0; |
| 357 |
$this->lastdate = ''; |
| 358 |
$this->rclistOpen = false; |
| 359 |
$this->getOutput()->addModuleStyles( [ |
| 360 |
'mediawiki.interface.helpers.styles', |
| 361 |
'mediawiki.special.changeslist' |
| 362 |
] ); |
| 363 |
|
| 364 |
return '<div class="mw-changeslist">'; |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
public function initChangesListRows( $rows ) { |
| 371 |
$this->getHookRunner()->onChangesListInitRows( $this, $rows ); |
| 372 |
$this->formattedComments = $this->commentFormatter->createBatch() |
| 373 |
->comments( |
| 374 |
$this->commentFormatter->rows( $rows ) |
| 375 |
->commentKey( 'rc_comment' ) |
| 376 |
->namespaceField( 'rc_namespace' ) |
| 377 |
->titleField( 'rc_title' ) |
| 378 |
->indexField( 'rc_id' ) |
| 379 |
) |
| 380 |
->useBlock() |
| 381 |
->execute(); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
public static function showCharacterDifference( $old, $new, ?IContextSource $context = null ) { |
| 395 |
if ( !$context ) { |
| 396 |
$context = RequestContext::getMain(); |
| 397 |
} |
| 398 |
|
| 399 |
$new = (int)$new; |
| 400 |
$old = (int)$old; |
| 401 |
$szdiff = $new - $old; |
| 402 |
|
| 403 |
$lang = $context->getLanguage(); |
| 404 |
$config = $context->getConfig(); |
| 405 |
$code = $lang->getCode(); |
| 406 |
static $fastCharDiff = []; |
| 407 |
if ( !isset( $fastCharDiff[$code] ) ) { |
| 408 |
$fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode ) |
| 409 |
|| $context->msg( 'rc-change-size' )->plain() === '$1'; |
| 410 |
} |
| 411 |
|
| 412 |
$formattedSize = $lang->formatNum( $szdiff ); |
| 413 |
|
| 414 |
if ( !$fastCharDiff[$code] ) { |
| 415 |
$formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text(); |
| 416 |
} |
| 417 |
|
| 418 |
if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) { |
| 419 |
$tag = 'strong'; |
| 420 |
} else { |
| 421 |
$tag = 'span'; |
| 422 |
} |
| 423 |
|
| 424 |
if ( $szdiff === 0 ) { |
| 425 |
$formattedSizeClass = 'mw-plusminus-null'; |
| 426 |
} elseif ( $szdiff > 0 ) { |
| 427 |
$formattedSize = '+' . $formattedSize; |
| 428 |
$formattedSizeClass = 'mw-plusminus-pos'; |
| 429 |
} else { |
| 430 |
$formattedSizeClass = 'mw-plusminus-neg'; |
| 431 |
} |
| 432 |
$formattedSizeClass .= ' mw-diff-bytes'; |
| 433 |
|
| 434 |
$formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text(); |
| 435 |
|
| 436 |
return Html::element( $tag, |
| 437 |
[ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ], |
| 438 |
$formattedSize ); |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
public function formatCharacterDifference( RecentChange $old, ?RecentChange $new = null ) { |
| 449 |
$oldlen = $old->mAttribs['rc_old_len']; |
| 450 |
|
| 451 |
if ( $new ) { |
| 452 |
$newlen = $new->mAttribs['rc_new_len']; |
| 453 |
} else { |
| 454 |
$newlen = $old->mAttribs['rc_new_len']; |
| 455 |
} |
| 456 |
|
| 457 |
if ( $oldlen === null || $newlen === null ) { |
| 458 |
return ''; |
| 459 |
} |
| 460 |
|
| 461 |
return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() ); |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
public function endRecentChangesList() { |
| 469 |
$out = $this->rclistOpen ? "</ul>\n" : ''; |
| 470 |
$out .= '</div>'; |
| 471 |
|
| 472 |
return $out; |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
public static function revDateLink( |
| 489 |
RevisionRecord $rev, |
| 490 |
Authority $performer, |
| 491 |
Language $lang, |
| 492 |
$title = null, |
| 493 |
$className = '' |
| 494 |
) { |
| 495 |
$ts = $rev->getTimestamp(); |
| 496 |
$time = $lang->userTime( $ts, $performer->getUser() ); |
| 497 |
$date = $lang->userTimeAndDate( $ts, $performer->getUser() ); |
| 498 |
$class = trim( 'mw-changeslist-date ' . $className ); |
| 499 |
if ( $rev->userCan( RevisionRecord::DELETED_TEXT, $performer ) ) { |
| 500 |
$link = Html::rawElement( 'bdi', [ 'dir' => $lang->getDir() ], |
| 501 |
MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink( |
| 502 |
$title ?? $rev->getPageAsLinkTarget(), |
| 503 |
$date, |
| 504 |
[ 'class' => $class ], |
| 505 |
[ 'oldid' => $rev->getId() ] |
| 506 |
) |
| 507 |
); |
| 508 |
} else { |
| 509 |
$link = htmlspecialchars( $date ); |
| 510 |
} |
| 511 |
if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) { |
| 512 |
$class = Linker::getRevisionDeletedClass( $rev ) . " $class"; |
| 513 |
$link = "<span class=\"$class\">$link</span>"; |
| 514 |
} |
| 515 |
return Html::element( 'span', [ |
| 516 |
'class' => 'mw-changeslist-time' |
| 517 |
], $time ) . $link; |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
public function insertDateHeader( &$s, $rc_timestamp ) { |
| 525 |
|
| 526 |
$date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() ); |
| 527 |
if ( $date != $this->lastdate ) { |
| 528 |
if ( $this->lastdate != '' ) { |
| 529 |
$s .= "</ul>\n"; |
| 530 |
} |
| 531 |
$s .= Html::element( 'h4', [], $date ) . "\n<ul class=\"special\">"; |
| 532 |
$this->lastdate = $date; |
| 533 |
$this->rclistOpen = true; |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
public function insertLog( &$s, $title, $logtype, $useParentheses = true ) { |
| 544 |
$page = new LogPage( $logtype ); |
| 545 |
$logname = $page->getName()->setContext( $this->getContext() )->text(); |
| 546 |
$link = $this->linkRenderer->makeKnownLink( $title, $logname, [ |
| 547 |
'class' => $useParentheses ? '' : 'mw-changeslist-links' |
| 548 |
] ); |
| 549 |
if ( $useParentheses ) { |
| 550 |
$s .= $this->msg( 'parentheses' )->rawParams( |
| 551 |
$link |
| 552 |
)->escaped(); |
| 553 |
} else { |
| 554 |
$s .= $link; |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) { |
| 564 |
|
| 565 |
if ( |
| 566 |
$rc->mAttribs['rc_type'] == RC_NEW || |
| 567 |
$rc->mAttribs['rc_type'] == RC_LOG || |
| 568 |
$rc->mAttribs['rc_type'] == RC_CATEGORIZE |
| 569 |
) { |
| 570 |
$diffLink = $this->message['diff']; |
| 571 |
} elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) { |
| 572 |
$diffLink = $this->message['diff']; |
| 573 |
} else { |
| 574 |
$query = [ |
| 575 |
'curid' => $rc->mAttribs['rc_cur_id'], |
| 576 |
'diff' => $rc->mAttribs['rc_this_oldid'], |
| 577 |
'oldid' => $rc->mAttribs['rc_last_oldid'] |
| 578 |
]; |
| 579 |
|
| 580 |
$diffLink = $this->linkRenderer->makeKnownLink( |
| 581 |
$rc->getTitle(), |
| 582 |
new HtmlArmor( $this->message['diff'] ), |
| 583 |
[ 'class' => 'mw-changeslist-diff' ], |
| 584 |
$query |
| 585 |
); |
| 586 |
} |
| 587 |
if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) { |
| 588 |
$histLink = $this->message['hist']; |
| 589 |
} else { |
| 590 |
$histLink = $this->linkRenderer->makeKnownLink( |
| 591 |
$rc->getTitle(), |
| 592 |
new HtmlArmor( $this->message['hist'] ), |
| 593 |
[ 'class' => 'mw-changeslist-history' ], |
| 594 |
[ |
| 595 |
'curid' => $rc->mAttribs['rc_cur_id'], |
| 596 |
'action' => 'history' |
| 597 |
] |
| 598 |
); |
| 599 |
} |
| 600 |
|
| 601 |
$s .= Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ], |
| 602 |
Html::rawElement( 'span', [], $diffLink ) . |
| 603 |
Html::rawElement( 'span', [], $histLink ) |
| 604 |
) . |
| 605 |
' <span class="mw-changeslist-separator"></span> '; |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
public function getArticleLink( &$rc, $unpatrolled, $watched ) { |
| 619 |
$params = []; |
| 620 |
if ( $rc->getTitle()->isRedirect() ) { |
| 621 |
$params = [ 'redirect' => 'no' ]; |
| 622 |
} |
| 623 |
|
| 624 |
$articlelink = $this->linkRenderer->makeLink( |
| 625 |
$rc->getTitle(), |
| 626 |
null, |
| 627 |
[ 'class' => 'mw-changeslist-title' ], |
| 628 |
$params |
| 629 |
); |
| 630 |
if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) { |
| 631 |
$class = 'history-deleted'; |
| 632 |
if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) { |
| 633 |
$class .= ' mw-history-suppressed'; |
| 634 |
} |
| 635 |
$articlelink = '<span class="' . $class . '">' . $articlelink . '</span>'; |
| 636 |
} |
| 637 |
$dir = $this->getLanguage()->getDir(); |
| 638 |
$articlelink = Html::rawElement( 'bdi', [ 'dir' => $dir ], $articlelink ); |
| 639 |
|
| 640 |
|
| 641 |
$articlelink = "<span class=\"mw-title\">{$articlelink}</span>"; |
| 642 |
|
| 643 |
|
| 644 |
$s = ''; |
| 645 |
$this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink, |
| 646 |
$s, $rc, $unpatrolled, $watched ); |
| 647 |
|
| 648 |
|
| 649 |
$watchlistExpiry = ''; |
| 650 |
if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) { |
| 651 |
$watchlistExpiry = $this->getWatchlistExpiry( $rc ); |
| 652 |
} |
| 653 |
|
| 654 |
return "{$s} {$articlelink}{$watchlistExpiry}"; |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
public function getWatchlistExpiry( RecentChange $recentChange ): string { |
| 664 |
$item = WatchedItem::newFromRecentChange( $recentChange, $this->getUser() ); |
| 665 |
|
| 666 |
if ( $item->isExpired() ) { |
| 667 |
return ''; |
| 668 |
} |
| 669 |
$daysLeftText = $item->getExpiryInDaysText( $this->getContext() ); |
| 670 |
|
| 671 |
$widget = new IconWidget( [ |
| 672 |
'icon' => 'clock', |
| 673 |
'title' => $daysLeftText, |
| 674 |
'classes' => [ 'mw-changesList-watchlistExpiry' ], |
| 675 |
] ); |
| 676 |
$widget->setAttributes( [ |
| 677 |
|
| 678 |
'role' => 'img', |
| 679 |
'aria-label' => $this->msg( 'watchlist-expires-in-aria-label' )->text(), |
| 680 |
|
| 681 |
'data-days-left' => $item->getExpiryInDays(), |
| 682 |
] ); |
| 683 |
|
| 684 |
|
| 685 |
return " $widget "; |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
public function getTimestamp( $rc ) { |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
$separatorClass = $rc->watchlistExpiry ? 'mw-changeslist-separator' : 'mw-changeslist-separator--semicolon'; |
| 709 |
return Html::element( 'span', [ 'class' => $separatorClass ] ) . ' ' . |
| 710 |
'<span class="mw-changeslist-date mw-changeslist-time">' . |
| 711 |
htmlspecialchars( $this->getLanguage()->userTime( |
| 712 |
$rc->mAttribs['rc_timestamp'], |
| 713 |
$this->getUser() |
| 714 |
) ) . '</span> <span class="mw-changeslist-separator"></span> '; |
| 715 |
} |
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
public function insertTimestamp( &$s, $rc ) { |
| 724 |
$s .= $this->getTimestamp( $rc ); |
| 725 |
} |
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
public function insertUserRelatedLinks( &$s, &$rc ) { |
| 734 |
if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) { |
| 735 |
$deletedClass = 'history-deleted'; |
| 736 |
if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) { |
| 737 |
$deletedClass .= ' mw-history-suppressed'; |
| 738 |
} |
| 739 |
$s .= ' <span class="' . $deletedClass . '">' . |
| 740 |
$this->msg( 'rev-deleted-user' )->escaped() . '</span>'; |
| 741 |
} else { |
| 742 |
|
| 743 |
$s .= $this->userLinkCache->getWithSetCallback( |
| 744 |
$this->userLinkCache->makeKey( |
| 745 |
$rc->mAttribs['rc_user_text'], |
| 746 |
$this->getUser()->getName(), |
| 747 |
$this->getLanguage()->getCode() |
| 748 |
), |
| 749 |
static function () use ( $rc ) { |
| 750 |
return Linker::userLink( |
| 751 |
$rc->mAttribs['rc_user'], |
| 752 |
$rc->mAttribs['rc_user_text'] |
| 753 |
) . Linker::userToolLinks( |
| 754 |
$rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'], |
| 755 |
false, 0, null, |
| 756 |
|
| 757 |
|
| 758 |
false |
| 759 |
); |
| 760 |
} |
| 761 |
); |
| 762 |
} |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
public function insertLogEntry( $rc ) { |
| 772 |
$formatter = $this->logFormatterFactory->newFromRow( $rc->mAttribs ); |
| 773 |
$formatter->setContext( $this->getContext() ); |
| 774 |
$formatter->setShowUserToolLinks( true ); |
| 775 |
|
| 776 |
$comment = $formatter->getComment(); |
| 777 |
if ( $comment !== '' ) { |
| 778 |
$dir = $this->getLanguage()->getDir(); |
| 779 |
$comment = Html::rawElement( 'bdi', [ 'dir' => $dir ], $comment ); |
| 780 |
} |
| 781 |
|
| 782 |
return Html::openElement( 'span', [ 'class' => 'mw-changeslist-log-entry' ] ) |
| 783 |
. $formatter->getActionText() |
| 784 |
. ' ' |
| 785 |
. $comment |
| 786 |
. $this->message['word-separator'] |
| 787 |
. $formatter->getActionLinks() |
| 788 |
. Html::closeElement( 'span' ); |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
public function insertComment( $rc ) { |
| 797 |
if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) { |
| 798 |
$deletedClass = 'history-deleted'; |
| 799 |
if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) { |
| 800 |
$deletedClass .= ' mw-history-suppressed'; |
| 801 |
} |
| 802 |
return ' <span class="' . $deletedClass . ' comment">' . |
| 803 |
$this->msg( 'rev-deleted-comment' )->escaped() . '</span>'; |
| 804 |
} elseif ( isset( $rc->mAttribs['rc_id'] ) |
| 805 |
&& isset( $this->formattedComments[$rc->mAttribs['rc_id']] ) |
| 806 |
) { |
| 807 |
return $this->formattedComments[$rc->mAttribs['rc_id']]; |
| 808 |
} else { |
| 809 |
return $this->commentFormatter->formatBlock( |
| 810 |
$rc->mAttribs['rc_comment'], |
| 811 |
$rc->getTitle(), |
| 812 |
|
| 813 |
false, |
| 814 |
|
| 815 |
null, |
| 816 |
|
| 817 |
false |
| 818 |
); |
| 819 |
} |
| 820 |
} |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
protected function numberofWatchingusers( $count ) { |
| 828 |
if ( $count <= 0 ) { |
| 829 |
return ''; |
| 830 |
} |
| 831 |
|
| 832 |
return $this->watchMsgCache->getWithSetCallback( |
| 833 |
$this->watchMsgCache->makeKey( |
| 834 |
'watching-users-msg', |
| 835 |
strval( $count ), |
| 836 |
$this->getUser()->getName(), |
| 837 |
$this->getLanguage()->getCode() |
| 838 |
), |
| 839 |
function () use ( $count ) { |
| 840 |
return $this->msg( 'number-of-watching-users-for-recent-changes' ) |
| 841 |
->numParams( $count )->escaped(); |
| 842 |
} |
| 843 |
); |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
public static function isDeleted( $rc, $field ) { |
| 853 |
return ( $rc->mAttribs['rc_deleted'] & $field ) == $field; |
| 854 |
} |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
public static function userCan( $rc, $field, ?Authority $performer = null ) { |
| 866 |
$performer ??= RequestContext::getMain()->getAuthority(); |
| 867 |
|
| 868 |
if ( $rc->mAttribs['rc_type'] == RC_LOG ) { |
| 869 |
return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer ); |
| 870 |
} |
| 871 |
|
| 872 |
return RevisionRecord::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer ); |
| 873 |
} |
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
protected function maybeWatchedLink( $link, $watched = false ) { |
| 881 |
if ( $watched ) { |
| 882 |
return '<strong class="mw-watched">' . $link . '</strong>'; |
| 883 |
} else { |
| 884 |
return '<span class="mw-rc-unwatched">' . $link . '</span>'; |
| 885 |
} |
| 886 |
} |
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
public function insertRollback( &$s, &$rc ) { |
| 895 |
$this->insertPageTools( $s, $rc ); |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
private function insertPageTools( &$s, &$rc ) { |
| 907 |
|
| 908 |
if ( !in_array( $rc->mAttribs['rc_type'], [ RC_EDIT, RC_NEW ] ) |
| 909 |
|
| 910 |
|| !$rc->mAttribs['rc_this_oldid'] |
| 911 |
|| !$rc->mAttribs['rc_cur_id'] |
| 912 |
) { |
| 913 |
return; |
| 914 |
} |
| 915 |
|
| 916 |
|
| 917 |
$title = $rc->getTitle(); |
| 918 |
$revRecord = new MutableRevisionRecord( $title ); |
| 919 |
$revRecord->setId( (int)$rc->mAttribs['rc_this_oldid'] ); |
| 920 |
$revRecord->setVisibility( (int)$rc->mAttribs['rc_deleted'] ); |
| 921 |
$user = new UserIdentityValue( |
| 922 |
(int)$rc->mAttribs['rc_user'], |
| 923 |
$rc->mAttribs['rc_user_text'] |
| 924 |
); |
| 925 |
$revRecord->setUser( $user ); |
| 926 |
|
| 927 |
$tools = new PagerTools( |
| 928 |
$revRecord, |
| 929 |
null, |
| 930 |
|
| 931 |
$rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid'] |
| 932 |
&& $rc->mAttribs['rc_type'] != RC_NEW, |
| 933 |
$this->getHookRunner(), |
| 934 |
$title, |
| 935 |
$this->getContext(), |
| 936 |
|
| 937 |
MediaWikiServices::getInstance()->getLinkRenderer() |
| 938 |
); |
| 939 |
|
| 940 |
$s .= $tools->toHTML(); |
| 941 |
} |
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
public function getRollback( RecentChange $rc ) { |
| 949 |
$s = ''; |
| 950 |
$this->insertRollback( $s, $rc ); |
| 951 |
return $s; |
| 952 |
} |
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
public function insertTags( &$s, &$rc, &$classes ) { |
| 960 |
if ( empty( $rc->mAttribs['ts_tags'] ) ) { |
| 961 |
return; |
| 962 |
} |
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
[ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback( |
| 970 |
$this->tagsCache->makeKey( |
| 971 |
$rc->mAttribs['ts_tags'], |
| 972 |
$this->getUser()->getName(), |
| 973 |
$this->getLanguage()->getCode() |
| 974 |
), |
| 975 |
fn () => ChangeTags::formatSummaryRow( |
| 976 |
$rc->mAttribs['ts_tags'], |
| 977 |
'changeslist', |
| 978 |
$this->getContext() |
| 979 |
) |
| 980 |
); |
| 981 |
$classes = array_merge( $classes, $newClasses ); |
| 982 |
$s .= ' ' . $tagSummary; |
| 983 |
} |
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
public function getTags( RecentChange $rc, array &$classes ) { |
| 992 |
$s = ''; |
| 993 |
$this->insertTags( $s, $rc, $classes ); |
| 994 |
return $s; |
| 995 |
} |
| 996 |
|
| 997 |
public function insertExtra( &$s, &$rc, &$classes ) { |
| 998 |
|
| 999 |
} |
| 1000 |
|
| 1001 |
protected function showAsUnpatrolled( RecentChange $rc ) { |
| 1002 |
return self::isUnpatrolled( $rc, $this->getUser() ); |
| 1003 |
} |
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
public static function isUnpatrolled( $rc, User $user ) { |
| 1011 |
if ( $rc instanceof RecentChange ) { |
| 1012 |
$isPatrolled = $rc->mAttribs['rc_patrolled']; |
| 1013 |
$rcType = $rc->mAttribs['rc_type']; |
| 1014 |
$rcLogType = $rc->mAttribs['rc_log_type']; |
| 1015 |
} else { |
| 1016 |
$isPatrolled = $rc->rc_patrolled; |
| 1017 |
$rcType = $rc->rc_type; |
| 1018 |
$rcLogType = $rc->rc_log_type; |
| 1019 |
} |
| 1020 |
|
| 1021 |
if ( $isPatrolled ) { |
| 1022 |
return false; |
| 1023 |
} |
| 1024 |
|
| 1025 |
return $user->useRCPatrol() || |
| 1026 |
( $rcType == RC_NEW && $user->useNPPatrol() ) || |
| 1027 |
( $rcLogType === 'upload' && $user->useFilePatrol() ); |
| 1028 |
} |
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
protected function isCategorizationWithoutRevision( $rcObj ) { |
| 1040 |
return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE |
| 1041 |
&& intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0; |
| 1042 |
} |
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
protected function getDataAttributes( RecentChange $rc ) { |
| 1050 |
$attrs = []; |
| 1051 |
|
| 1052 |
$type = $rc->getAttribute( 'rc_source' ); |
| 1053 |
switch ( $type ) { |
| 1054 |
case RecentChange::SRC_EDIT: |
| 1055 |
case RecentChange::SRC_CATEGORIZE: |
| 1056 |
case RecentChange::SRC_NEW: |
| 1057 |
$attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid']; |
| 1058 |
break; |
| 1059 |
case RecentChange::SRC_LOG: |
| 1060 |
$attrs['data-mw-logid'] = $rc->mAttribs['rc_logid']; |
| 1061 |
$attrs['data-mw-logaction'] = |
| 1062 |
$rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action']; |
| 1063 |
break; |
| 1064 |
} |
| 1065 |
|
| 1066 |
$attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' ); |
| 1067 |
|
| 1068 |
return $attrs; |
| 1069 |
} |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
public function setChangeLinePrefixer( callable $prefixer ) { |
| 1079 |
$this->changeLinePrefixer = $prefixer; |
| 1080 |
} |
| 1081 |
} |