| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
namespace MediaWiki\Pager; |
| 23 |
|
| 24 |
use ChangesList; |
| 25 |
use ChangeTags; |
| 26 |
use HtmlArmor; |
| 27 |
use InvalidArgumentException; |
| 28 |
use MapCacheLRU; |
| 29 |
use MediaWiki\Cache\LinkBatchFactory; |
| 30 |
use MediaWiki\CommentFormatter\CommentFormatter; |
| 31 |
use MediaWiki\Context\IContextSource; |
| 32 |
use MediaWiki\HookContainer\HookContainer; |
| 33 |
use MediaWiki\HookContainer\HookRunner; |
| 34 |
use MediaWiki\Html\Html; |
| 35 |
use MediaWiki\Html\TemplateParser; |
| 36 |
use MediaWiki\Linker\Linker; |
| 37 |
use MediaWiki\Linker\LinkRenderer; |
| 38 |
use MediaWiki\MainConfigNames; |
| 39 |
use MediaWiki\MediaWikiServices; |
| 40 |
use MediaWiki\Parser\Sanitizer; |
| 41 |
use MediaWiki\Revision\RevisionRecord; |
| 42 |
use MediaWiki\Revision\RevisionStore; |
| 43 |
use MediaWiki\SpecialPage\SpecialPage; |
| 44 |
use MediaWiki\Title\NamespaceInfo; |
| 45 |
use MediaWiki\Title\Title; |
| 46 |
use MediaWiki\User\UserFactory; |
| 47 |
use MediaWiki\User\UserIdentity; |
| 48 |
use MediaWiki\User\UserRigorOptions; |
| 49 |
use stdClass; |
| 50 |
use Wikimedia\Rdbms\FakeResultWrapper; |
| 51 |
use Wikimedia\Rdbms\IResultWrapper; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
abstract class ContributionsPager extends RangeChronologicalPager { |
| 58 |
|
| 59 |
|
| 60 |
public $mGroupByDate = true; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
protected $messages; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
protected $isArchive; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
protected $target; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
private $namespace; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
private $tagFilter; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
private $tagInvert; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
private $nsInvert; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
private $associated; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
private $deletedOnly; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
private $topOnly; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
private $newOnly; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
private $hideMinor; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
private $revisionsOnly; |
| 128 |
|
| 129 |
|
| 130 |
private $preventClickjacking = false; |
| 131 |
|
| 132 |
protected ?Title $currentPage; |
| 133 |
protected ?RevisionRecord $currentRevRecord; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
private $mParentLens; |
| 139 |
|
| 140 |
|
| 141 |
protected $targetUser; |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
protected TemplateParser $templateParser; |
| 147 |
|
| 148 |
private CommentFormatter $commentFormatter; |
| 149 |
private HookRunner $hookRunner; |
| 150 |
private LinkBatchFactory $linkBatchFactory; |
| 151 |
private NamespaceInfo $namespaceInfo; |
| 152 |
protected RevisionStore $revisionStore; |
| 153 |
|
| 154 |
|
| 155 |
private $formattedComments = []; |
| 156 |
|
| 157 |
|
| 158 |
private $revisions = []; |
| 159 |
|
| 160 |
|
| 161 |
private $tagsCache; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
protected string $revisionIdField = 'rev_id'; |
| 168 |
protected string $revisionParentIdField = 'rev_parent_id'; |
| 169 |
protected string $revisionTimestampField = 'rev_timestamp'; |
| 170 |
protected string $revisionLengthField = 'rev_len'; |
| 171 |
protected string $revisionDeletedField = 'rev_deleted'; |
| 172 |
protected string $revisionMinorField = 'rev_minor_edit'; |
| 173 |
protected string $userNameField = 'rev_user_text'; |
| 174 |
protected string $pageNamespaceField = 'page_namespace'; |
| 175 |
protected string $pageTitleField = 'page_title'; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
public function __construct( |
| 190 |
LinkRenderer $linkRenderer, |
| 191 |
LinkBatchFactory $linkBatchFactory, |
| 192 |
HookContainer $hookContainer, |
| 193 |
RevisionStore $revisionStore, |
| 194 |
NamespaceInfo $namespaceInfo, |
| 195 |
CommentFormatter $commentFormatter, |
| 196 |
UserFactory $userFactory, |
| 197 |
IContextSource $context, |
| 198 |
array $options, |
| 199 |
?UserIdentity $targetUser |
| 200 |
) { |
| 201 |
$this->isArchive = $options['isArchive'] ?? false; |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
if ( $targetUser ) { |
| 207 |
$this->target = $options['target'] ?? $targetUser->getName(); |
| 208 |
$this->targetUser = $targetUser; |
| 209 |
} else { |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
$this->target = $options['target'] ?? ''; |
| 215 |
|
| 216 |
$this->targetUser = $userFactory->newFromName( |
| 217 |
$this->target, UserRigorOptions::RIGOR_NONE |
| 218 |
); |
| 219 |
if ( !$this->targetUser ) { |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
throw new InvalidArgumentException( __METHOD__ . ': the user name is too ' . |
| 224 |
'broken to use even with validation disabled.' ); |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
$this->namespace = $options['namespace'] ?? ''; |
| 229 |
$this->tagFilter = $options['tagfilter'] ?? false; |
| 230 |
$this->tagInvert = $options['tagInvert'] ?? false; |
| 231 |
$this->nsInvert = $options['nsInvert'] ?? false; |
| 232 |
$this->associated = $options['associated'] ?? false; |
| 233 |
|
| 234 |
$this->deletedOnly = !empty( $options['deletedOnly'] ); |
| 235 |
$this->topOnly = !empty( $options['topOnly'] ); |
| 236 |
$this->newOnly = !empty( $options['newOnly'] ); |
| 237 |
$this->hideMinor = !empty( $options['hideMinor'] ); |
| 238 |
$this->revisionsOnly = !empty( $options['revisionsOnly'] ); |
| 239 |
|
| 240 |
parent::__construct( $context, $linkRenderer ); |
| 241 |
|
| 242 |
$msgs = [ |
| 243 |
'diff', |
| 244 |
'hist', |
| 245 |
'pipe-separator', |
| 246 |
'uctop', |
| 247 |
'changeslist-nocomment', |
| 248 |
'undeleteviewlink', |
| 249 |
'undeleteviewlink', |
| 250 |
'deletionlog', |
| 251 |
]; |
| 252 |
|
| 253 |
foreach ( $msgs as $msg ) { |
| 254 |
$this->messages[$msg] = $this->msg( $msg )->escaped(); |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
$startTimestamp = ''; |
| 259 |
$endTimestamp = ''; |
| 260 |
if ( isset( $options['start'] ) && $options['start'] ) { |
| 261 |
$startTimestamp = $options['start'] . ' 00:00:00'; |
| 262 |
} |
| 263 |
if ( isset( $options['end'] ) && $options['end'] ) { |
| 264 |
$endTimestamp = $options['end'] . ' 23:59:59'; |
| 265 |
} |
| 266 |
$this->getDateRangeCond( $startTimestamp, $endTimestamp ); |
| 267 |
|
| 268 |
$this->templateParser = new TemplateParser(); |
| 269 |
$this->linkBatchFactory = $linkBatchFactory; |
| 270 |
$this->hookRunner = new HookRunner( $hookContainer ); |
| 271 |
$this->revisionStore = $revisionStore; |
| 272 |
$this->namespaceInfo = $namespaceInfo; |
| 273 |
$this->commentFormatter = $commentFormatter; |
| 274 |
$this->tagsCache = new MapCacheLRU( 50 ); |
| 275 |
} |
| 276 |
|
| 277 |
public function getDefaultQuery() { |
| 278 |
$query = parent::getDefaultQuery(); |
| 279 |
$query['target'] = $this->target; |
| 280 |
|
| 281 |
return $query; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
public function reallyDoQuery( $offset, $limit, $order ) { |
| 294 |
[ $tables, $fields, $conds, $fname, $options, $join_conds ] = $this->buildQueryInfo( |
| 295 |
$offset, |
| 296 |
$limit, |
| 297 |
$order |
| 298 |
); |
| 299 |
|
| 300 |
$options['MAX_EXECUTION_TIME'] = |
| 301 |
$this->getConfig()->get( MainConfigNames::MaxExecutionTimeForExpensiveQueries ); |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
$dbr = $this->getDatabase(); |
| 321 |
$data = [ $dbr->newSelectQueryBuilder() |
| 322 |
->tables( is_array( $tables ) ? $tables : [ $tables ] ) |
| 323 |
->fields( $fields ) |
| 324 |
->conds( $conds ) |
| 325 |
->caller( $fname ) |
| 326 |
->options( $options ) |
| 327 |
->joinConds( $join_conds ) |
| 328 |
->setMaxExecutionTime( $this->getConfig()->get( MainConfigNames::MaxExecutionTimeForExpensiveQueries ) ) |
| 329 |
->fetchResultSet() ]; |
| 330 |
if ( !$this->revisionsOnly ) { |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
$reallyDoQueryHook = $this->isArchive ? |
| 335 |
'onDeletedContribsPager__reallyDoQuery' : |
| 336 |
'onContribsPager__reallyDoQuery'; |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
$this->hookRunner->$reallyDoQueryHook( $data, $this, $offset, $limit, $order ); |
| 341 |
} |
| 342 |
|
| 343 |
$result = []; |
| 344 |
|
| 345 |
|
| 346 |
foreach ( $data as $query ) { |
| 347 |
foreach ( $query as $i => $row ) { |
| 348 |
|
| 349 |
$index = $order === self::QUERY_ASCENDING ? $i : $limit - 1 - $i; |
| 350 |
|
| 351 |
$index = str_pad( (string)$index, strlen( (string)$limit ), '0', STR_PAD_LEFT ); |
| 352 |
|
| 353 |
$result[$row->{$this->getIndexField()} . "-$index"] = $row; |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
if ( $order === self::QUERY_ASCENDING ) { |
| 359 |
ksort( $result ); |
| 360 |
} else { |
| 361 |
krsort( $result ); |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
$result = array_slice( $result, 0, $limit ); |
| 366 |
|
| 367 |
|
| 368 |
$result = array_values( $result ); |
| 369 |
|
| 370 |
return new FakeResultWrapper( $result ); |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
abstract protected function getRevisionQuery(); |
| 380 |
|
| 381 |
public function getQueryInfo() { |
| 382 |
$queryInfo = $this->getRevisionQuery(); |
| 383 |
|
| 384 |
if ( $this->deletedOnly ) { |
| 385 |
$queryInfo['conds'][] = $this->revisionDeletedField . ' != 0'; |
| 386 |
} |
| 387 |
|
| 388 |
if ( !$this->isArchive && $this->topOnly ) { |
| 389 |
$queryInfo['conds'][] = $this->revisionIdField . ' = page_latest'; |
| 390 |
} |
| 391 |
|
| 392 |
if ( $this->newOnly ) { |
| 393 |
$queryInfo['conds'][] = $this->revisionParentIdField . ' = 0'; |
| 394 |
} |
| 395 |
|
| 396 |
if ( $this->hideMinor ) { |
| 397 |
$queryInfo['conds'][] = $this->revisionMinorField . ' = 0'; |
| 398 |
} |
| 399 |
|
| 400 |
$queryInfo['conds'] = array_merge( $queryInfo['conds'], $this->getNamespaceCond() ); |
| 401 |
|
| 402 |
|
| 403 |
$dbr = $this->getDatabase(); |
| 404 |
if ( !$this->getAuthority()->isAllowed( 'deletedhistory' ) ) { |
| 405 |
$queryInfo['conds'][] = $dbr->bitAnd( |
| 406 |
$this->revisionDeletedField, RevisionRecord::DELETED_USER |
| 407 |
) . ' = 0'; |
| 408 |
} elseif ( !$this->getAuthority()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) { |
| 409 |
$queryInfo['conds'][] = $dbr->bitAnd( |
| 410 |
$this->revisionDeletedField, RevisionRecord::SUPPRESSED_USER |
| 411 |
) . ' != ' . RevisionRecord::SUPPRESSED_USER; |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
$indexField = $this->getIndexField(); |
| 416 |
if ( $indexField !== $this->revisionTimestampField ) { |
| 417 |
$queryInfo['fields'][] = $indexField; |
| 418 |
} |
| 419 |
|
| 420 |
MediaWikiServices::getInstance()->getChangeTagsStore()->modifyDisplayQuery( |
| 421 |
$queryInfo['tables'], |
| 422 |
$queryInfo['fields'], |
| 423 |
$queryInfo['conds'], |
| 424 |
$queryInfo['join_conds'], |
| 425 |
$queryInfo['options'], |
| 426 |
$this->tagFilter, |
| 427 |
$this->tagInvert, |
| 428 |
); |
| 429 |
|
| 430 |
if ( !$this->isArchive ) { |
| 431 |
$this->hookRunner->onContribsPager__getQueryInfo( $this, $queryInfo ); |
| 432 |
} |
| 433 |
|
| 434 |
return $queryInfo; |
| 435 |
} |
| 436 |
|
| 437 |
protected function getNamespaceCond() { |
| 438 |
if ( $this->namespace !== '' ) { |
| 439 |
$dbr = $this->getDatabase(); |
| 440 |
$namespaces = [ $this->namespace ]; |
| 441 |
$eq_op = $this->nsInvert ? '!=' : '='; |
| 442 |
if ( $this->associated ) { |
| 443 |
$namespaces[] = $this->namespaceInfo->getAssociated( $this->namespace ); |
| 444 |
} |
| 445 |
return [ $dbr->expr( $this->pageNamespaceField, $eq_op, $namespaces ) ]; |
| 446 |
} |
| 447 |
|
| 448 |
return []; |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
public function getTagFilter() { |
| 455 |
return $this->tagFilter; |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
public function getTagInvert() { |
| 462 |
return $this->tagInvert; |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
public function getTarget() { |
| 469 |
return $this->target; |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
public function isNewOnly() { |
| 476 |
return $this->newOnly; |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
public function getNamespace() { |
| 483 |
return $this->namespace; |
| 484 |
} |
| 485 |
|
| 486 |
protected function doBatchLookups() { |
| 487 |
|
| 488 |
$this->mResult->seek( 0 ); |
| 489 |
$parentRevIds = []; |
| 490 |
$this->mParentLens = []; |
| 491 |
$revisions = []; |
| 492 |
$linkBatch = $this->linkBatchFactory->newLinkBatch(); |
| 493 |
|
| 494 |
foreach ( $this->mResult as $row ) { |
| 495 |
$revisionRecord = $this->tryCreatingRevisionRecord( $row ); |
| 496 |
if ( !$revisionRecord ) { |
| 497 |
continue; |
| 498 |
} |
| 499 |
if ( isset( $row->{$this->revisionParentIdField} ) && $row->{$this->revisionParentIdField} ) { |
| 500 |
$parentRevIds[] = (int)$row->{$this->revisionParentIdField}; |
| 501 |
} |
| 502 |
$this->mParentLens[(int)$row->{$this->revisionIdField}] = $row->{$this->revisionLengthField}; |
| 503 |
if ( $this->target !== $row->{$this->userNameField} ) { |
| 504 |
|
| 505 |
$linkBatch->add( NS_USER_TALK, $row->{$this->userNameField} ); |
| 506 |
} |
| 507 |
$linkBatch->add( $row->{$this->pageNamespaceField}, $row->{$this->pageTitleField} ); |
| 508 |
$revisions[$row->{$this->revisionIdField}] = $this->createRevisionRecord( $row ); |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
if ( $this->isArchive ) { |
| 513 |
$parentRevIds = array_diff( $parentRevIds, array_keys( $this->mParentLens ) ); |
| 514 |
if ( $parentRevIds ) { |
| 515 |
$result = $this->revisionStore |
| 516 |
->newArchiveSelectQueryBuilder( $this->getDatabase() ) |
| 517 |
->clearFields() |
| 518 |
->fields( [ $this->revisionIdField, $this->revisionLengthField ] ) |
| 519 |
->where( [ $this->revisionIdField => $parentRevIds ] ) |
| 520 |
->caller( __METHOD__ ) |
| 521 |
->fetchResultSet(); |
| 522 |
foreach ( $result as $row ) { |
| 523 |
$this->mParentLens[(int)$row->{$this->revisionIdField}] = $row->{$this->revisionLengthField}; |
| 524 |
} |
| 525 |
} |
| 526 |
} |
| 527 |
$this->mParentLens += $this->revisionStore->getRevisionSizes( |
| 528 |
array_diff( $parentRevIds, array_keys( $this->mParentLens ) ) |
| 529 |
); |
| 530 |
$linkBatch->execute(); |
| 531 |
|
| 532 |
$revisionBatch = $this->commentFormatter->createRevisionBatch() |
| 533 |
->authority( $this->getAuthority() ) |
| 534 |
->revisions( $revisions ); |
| 535 |
|
| 536 |
if ( !$this->isArchive ) { |
| 537 |
|
| 538 |
$revisionBatch = $revisionBatch->hideIfDeleted(); |
| 539 |
} |
| 540 |
|
| 541 |
$this->formattedComments = $revisionBatch->execute(); |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
$this->revisions += $revisions; |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
protected function getStartBody() { |
| 554 |
return "<section class='mw-pager-body'>\n"; |
| 555 |
} |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
protected function getEndBody() { |
| 561 |
return "</section>\n"; |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
protected function getEmptyBody() { |
| 568 |
return $this->msg( 'nocontribs' )->parse(); |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
public function tryCreatingRevisionRecord( $row, $title = null ) { |
| 582 |
if ( $row instanceof stdClass && isset( $row->{$this->revisionIdField} ) |
| 583 |
&& isset( $this->revisions[$row->{$this->revisionIdField}] ) |
| 584 |
) { |
| 585 |
return $this->revisions[$row->{$this->revisionIdField}]; |
| 586 |
} |
| 587 |
|
| 588 |
if ( |
| 589 |
$this->isArchive && |
| 590 |
$this->revisionStore->isRevisionRow( $row, 'archive' ) |
| 591 |
) { |
| 592 |
return $this->revisionStore->newRevisionFromArchiveRow( $row, 0, $title ); |
| 593 |
} |
| 594 |
|
| 595 |
if ( |
| 596 |
!$this->isArchive && |
| 597 |
$this->revisionStore->isRevisionRow( $row ) |
| 598 |
) { |
| 599 |
return $this->revisionStore->newRevisionFromRow( $row, 0, $title ); |
| 600 |
} |
| 601 |
|
| 602 |
return null; |
| 603 |
} |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
public function createRevisionRecord( $row, $title = null ) { |
| 613 |
if ( $this->isArchive ) { |
| 614 |
return $this->revisionStore->newRevisionFromArchiveRow( $row, 0, $title ); |
| 615 |
} |
| 616 |
|
| 617 |
return $this->revisionStore->newRevisionFromRow( $row, 0, $title ); |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
protected function populateAttributes( $row, &$attributes ) { |
| 627 |
$attributes['data-mw-revid'] = $this->currentRevRecord->getId(); |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
protected function formatArticleLink( $row ) { |
| 637 |
if ( !$this->currentPage ) { |
| 638 |
return ''; |
| 639 |
} |
| 640 |
$dir = $this->getLanguage()->getDir(); |
| 641 |
return Html::rawElement( 'bdi', [ 'dir' => $dir ], $this->getLinkRenderer()->makeLink( |
| 642 |
$this->currentPage, |
| 643 |
$this->currentPage->getPrefixedText(), |
| 644 |
[ 'class' => 'mw-contributions-title' ], |
| 645 |
$this->currentPage->isRedirect() ? [ 'redirect' => 'no' ] : [] |
| 646 |
) ); |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
protected function formatDiffHistLinks( $row ) { |
| 656 |
if ( !$this->currentPage || !$this->currentRevRecord ) { |
| 657 |
return ''; |
| 658 |
} |
| 659 |
if ( $this->isArchive ) { |
| 660 |
|
| 661 |
$undelete = SpecialPage::getTitleFor( 'Undelete' ); |
| 662 |
if ( $this->getAuthority()->isAllowed( 'deletedtext' ) ) { |
| 663 |
$last = $this->getLinkRenderer()->makeKnownLink( |
| 664 |
$undelete, |
| 665 |
new HtmlArmor( $this->messages['diff'] ), |
| 666 |
[], |
| 667 |
[ |
| 668 |
'target' => $this->currentPage->getPrefixedText(), |
| 669 |
'timestamp' => $this->currentRevRecord->getTimestamp(), |
| 670 |
'diff' => 'prev' |
| 671 |
] |
| 672 |
); |
| 673 |
} else { |
| 674 |
$last = $this->messages['diff']; |
| 675 |
} |
| 676 |
|
| 677 |
$logs = SpecialPage::getTitleFor( 'Log' ); |
| 678 |
$dellog = $this->getLinkRenderer()->makeKnownLink( |
| 679 |
$logs, |
| 680 |
new HtmlArmor( $this->messages['deletionlog'] ), |
| 681 |
[], |
| 682 |
[ |
| 683 |
'type' => 'delete', |
| 684 |
'page' => $this->currentPage->getPrefixedText() |
| 685 |
] |
| 686 |
); |
| 687 |
|
| 688 |
$reviewlink = $this->getLinkRenderer()->makeKnownLink( |
| 689 |
SpecialPage::getTitleFor( 'Undelete', $this->currentPage->getPrefixedDBkey() ), |
| 690 |
new HtmlArmor( $this->messages['undeleteviewlink'] ) |
| 691 |
); |
| 692 |
|
| 693 |
return Html::rawElement( |
| 694 |
'span', |
| 695 |
[ 'class' => 'mw-deletedcontribs-tools' ], |
| 696 |
$this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList( |
| 697 |
[ $last, $dellog, $reviewlink ] ) )->escaped() |
| 698 |
); |
| 699 |
} else { |
| 700 |
|
| 701 |
if ( $this->currentRevRecord->getParentId() !== 0 && |
| 702 |
$this->currentRevRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getAuthority() ) |
| 703 |
) { |
| 704 |
$difftext = $this->getLinkRenderer()->makeKnownLink( |
| 705 |
$this->currentPage, |
| 706 |
new HtmlArmor( $this->messages['diff'] ), |
| 707 |
[ 'class' => 'mw-changeslist-diff' ], |
| 708 |
[ |
| 709 |
'diff' => 'prev', |
| 710 |
'oldid' => $row->{$this->revisionIdField}, |
| 711 |
] |
| 712 |
); |
| 713 |
} else { |
| 714 |
$difftext = $this->messages['diff']; |
| 715 |
} |
| 716 |
$histlink = $this->getLinkRenderer()->makeKnownLink( |
| 717 |
$this->currentPage, |
| 718 |
new HtmlArmor( $this->messages['hist'] ), |
| 719 |
[ 'class' => 'mw-changeslist-history' ], |
| 720 |
[ 'action' => 'history' ] |
| 721 |
); |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
return Html::rawElement( 'span', |
| 728 |
[ 'class' => 'mw-changeslist-links' ], |
| 729 |
|
| 730 |
|
| 731 |
Html::rawElement( 'span', [], $difftext ) . |
| 732 |
' ' . |
| 733 |
Html::rawElement( 'span', [], $histlink ) |
| 734 |
); |
| 735 |
} |
| 736 |
} |
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
protected function formatDateLink( $row ) { |
| 745 |
if ( !$this->currentPage || !$this->currentRevRecord ) { |
| 746 |
return ''; |
| 747 |
} |
| 748 |
if ( $this->isArchive ) { |
| 749 |
$date = $this->getLanguage()->userTimeAndDate( |
| 750 |
$this->currentRevRecord->getTimestamp(), |
| 751 |
$this->getUser() |
| 752 |
); |
| 753 |
|
| 754 |
if ( $this->getAuthority()->isAllowed( 'undelete' ) && |
| 755 |
$this->currentRevRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getAuthority() ) |
| 756 |
) { |
| 757 |
$dateLink = $this->getLinkRenderer()->makeKnownLink( |
| 758 |
SpecialPage::getTitleFor( 'Undelete' ), |
| 759 |
$date, |
| 760 |
[ 'class' => 'mw-changeslist-date' ], |
| 761 |
[ |
| 762 |
'target' => $this->currentPage->getPrefixedText(), |
| 763 |
'timestamp' => $this->currentRevRecord->getTimestamp() |
| 764 |
] |
| 765 |
); |
| 766 |
} else { |
| 767 |
$dateLink = htmlspecialchars( $date ); |
| 768 |
} |
| 769 |
if ( $this->currentRevRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) { |
| 770 |
$class = Linker::getRevisionDeletedClass( $this->currentRevRecord ); |
| 771 |
$dateLink = Html::rawElement( |
| 772 |
'span', |
| 773 |
[ 'class' => $class ], |
| 774 |
$dateLink |
| 775 |
); |
| 776 |
} |
| 777 |
} else { |
| 778 |
$dateLink = ChangesList::revDateLink( |
| 779 |
$this->currentRevRecord, |
| 780 |
$this->getAuthority(), |
| 781 |
$this->getLanguage(), |
| 782 |
$this->currentPage |
| 783 |
); |
| 784 |
} |
| 785 |
return $dateLink; |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
protected function formatTopMarkText( $row, &$classes ) { |
| 796 |
if ( !$this->currentPage || !$this->currentRevRecord ) { |
| 797 |
return ''; |
| 798 |
} |
| 799 |
$topmarktext = ''; |
| 800 |
if ( !$this->isArchive ) { |
| 801 |
$pagerTools = new PagerTools( |
| 802 |
$this->currentRevRecord, |
| 803 |
null, |
| 804 |
$row->{$this->revisionIdField} === $row->page_latest && !$row->page_is_new, |
| 805 |
$this->hookRunner, |
| 806 |
$this->currentPage, |
| 807 |
$this->getContext(), |
| 808 |
$this->getLinkRenderer() |
| 809 |
); |
| 810 |
if ( $row->{$this->revisionIdField} === $row->page_latest ) { |
| 811 |
$topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>'; |
| 812 |
$classes[] = 'mw-contributions-current'; |
| 813 |
} |
| 814 |
if ( $pagerTools->shouldPreventClickjacking() ) { |
| 815 |
$this->setPreventClickjacking( true ); |
| 816 |
} |
| 817 |
$topmarktext .= $pagerTools->toHTML(); |
| 818 |
} |
| 819 |
return $topmarktext; |
| 820 |
} |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
protected function formatCharDiff( $row ) { |
| 829 |
if ( $row->{$this->revisionParentIdField} === null ) { |
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
$chardiff = ' <span class="mw-changeslist-separator"></span> '; |
| 834 |
$chardiff .= Linker::formatRevisionSize( $row->{$this->revisionLengthField} ); |
| 835 |
$chardiff .= ' <span class="mw-changeslist-separator"></span> '; |
| 836 |
} else { |
| 837 |
$parentLen = 0; |
| 838 |
if ( isset( $this->mParentLens[$row->{$this->revisionParentIdField}] ) ) { |
| 839 |
$parentLen = $this->mParentLens[$row->{$this->revisionParentIdField}]; |
| 840 |
} |
| 841 |
|
| 842 |
$chardiff = ' <span class="mw-changeslist-separator"></span> '; |
| 843 |
$chardiff .= ChangesList::showCharacterDifference( |
| 844 |
$parentLen, |
| 845 |
$row->{$this->revisionLengthField}, |
| 846 |
$this->getContext() |
| 847 |
); |
| 848 |
$chardiff .= ' <span class="mw-changeslist-separator"></span> '; |
| 849 |
} |
| 850 |
return $chardiff; |
| 851 |
} |
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
protected function formatComment( $row ) { |
| 860 |
$comment = $this->formattedComments[$row->{$this->revisionIdField}]; |
| 861 |
|
| 862 |
if ( $comment === '' ) { |
| 863 |
$defaultComment = $this->messages['changeslist-nocomment']; |
| 864 |
$comment = "<span class=\"comment mw-comment-none\">$defaultComment</span>"; |
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
return $comment; |
| 869 |
} |
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
protected function formatUserLink( $row ) { |
| 878 |
if ( !$this->currentRevRecord ) { |
| 879 |
return ''; |
| 880 |
} |
| 881 |
$dir = $this->getLanguage()->getDir(); |
| 882 |
|
| 883 |
|
| 884 |
$userlink = ''; |
| 885 |
$revUser = $this->currentRevRecord->getUser(); |
| 886 |
$revUserId = $revUser ? $revUser->getId() : 0; |
| 887 |
$revUserText = $revUser ? $revUser->getName() : ''; |
| 888 |
if ( $this->target !== $revUserText ) { |
| 889 |
$userlink = ' <span class="mw-changeslist-separator"></span> ' |
| 890 |
. Html::rawElement( 'bdi', [ 'dir' => $dir ], |
| 891 |
Linker::userLink( $revUserId, $revUserText ) ); |
| 892 |
$userlink .= ' ' . $this->msg( 'parentheses' )->rawParams( |
| 893 |
Linker::userTalkLink( $revUserId, $revUserText ) )->escaped() . ' '; |
| 894 |
} |
| 895 |
return $userlink; |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
protected function formatFlags( $row ) { |
| 903 |
if ( !$this->currentRevRecord ) { |
| 904 |
return []; |
| 905 |
} |
| 906 |
$flags = []; |
| 907 |
if ( $this->currentRevRecord->getParentId() === 0 ) { |
| 908 |
$flags[] = ChangesList::flag( 'newpage' ); |
| 909 |
} |
| 910 |
|
| 911 |
if ( $this->currentRevRecord->isMinor() ) { |
| 912 |
$flags[] = ChangesList::flag( 'minor' ); |
| 913 |
} |
| 914 |
return $flags; |
| 915 |
} |
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
protected function formatVisibilityLink( $row ) { |
| 924 |
if ( !$this->currentPage || !$this->currentRevRecord ) { |
| 925 |
return ''; |
| 926 |
} |
| 927 |
$del = Linker::getRevDeleteLink( |
| 928 |
$this->getAuthority(), |
| 929 |
$this->currentRevRecord, |
| 930 |
$this->currentPage |
| 931 |
); |
| 932 |
if ( $del !== '' ) { |
| 933 |
$del .= ' '; |
| 934 |
} |
| 935 |
return $del; |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
protected function formatTags( $row, &$classes ) { |
| 944 |
|
| 945 |
[ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback( |
| 946 |
$this->tagsCache->makeKey( |
| 947 |
$row->ts_tags ?? '', |
| 948 |
$this->getUser()->getName(), |
| 949 |
$this->getLanguage()->getCode() |
| 950 |
), |
| 951 |
fn () => ChangeTags::formatSummaryRow( |
| 952 |
$row->ts_tags, |
| 953 |
null, |
| 954 |
$this->getContext() |
| 955 |
) |
| 956 |
); |
| 957 |
$classes = array_merge( $classes, $newClasses ); |
| 958 |
return $tagSummary; |
| 959 |
} |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
public function revisionUserIsDeleted( $row ) { |
| 968 |
return $this->currentRevRecord->isDeleted( RevisionRecord::DELETED_USER ); |
| 969 |
} |
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
public function formatRow( $row ) { |
| 984 |
$ret = ''; |
| 985 |
$classes = []; |
| 986 |
$attribs = []; |
| 987 |
|
| 988 |
$this->currentPage = null; |
| 989 |
$this->currentRevRecord = null; |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
if ( isset( $row->{$this->pageNamespaceField} ) && isset( $row->{$this->pageTitleField} ) ) { |
| 994 |
$this->currentPage = Title::makeTitle( $row->{$this->pageNamespaceField}, $row->{$this->pageTitleField} ); |
| 995 |
} |
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
$this->currentRevRecord = $this->tryCreatingRevisionRecord( $row, $this->currentPage ); |
| 1003 |
if ( $this->revisionsOnly || ( $this->currentRevRecord && $this->currentPage ) ) { |
| 1004 |
$this->populateAttributes( $row, $attribs ); |
| 1005 |
|
| 1006 |
$templateParams = $this->getTemplateParams( $row, $classes ); |
| 1007 |
$ret = $this->getProcessedTemplate( $templateParams ); |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
$lineEndingsHook = $this->isArchive ? |
| 1012 |
'onDeletedContributionsLineEnding' : |
| 1013 |
'onContributionsLineEnding'; |
| 1014 |
$this->hookRunner->$lineEndingsHook( $this, $ret, $row, $classes, $attribs ); |
| 1015 |
$attribs = array_filter( $attribs, |
| 1016 |
[ Sanitizer::class, 'isReservedDataAttribute' ], |
| 1017 |
ARRAY_FILTER_USE_KEY |
| 1018 |
); |
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
if ( $classes === [] && $attribs === [] && $ret === '' ) { |
| 1024 |
wfDebug( "Dropping ContributionsSpecialPage row that could not be formatted" ); |
| 1025 |
return "<!-- Could not format ContributionsSpecialPage row. -->\n"; |
| 1026 |
} |
| 1027 |
$attribs['class'] = $classes; |
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
return Html::rawElement( 'li', $attribs, $ret ) . "\n"; |
| 1032 |
} |
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
public function getTemplateParams( $row, &$classes ) { |
| 1045 |
$link = $this->formatArticleLink( $row ); |
| 1046 |
$topmarktext = $this->formatTopMarkText( $row, $classes ); |
| 1047 |
$diffHistLinks = $this->formatDiffHistLinks( $row ); |
| 1048 |
$dateLink = $this->formatDateLink( $row ); |
| 1049 |
$chardiff = $this->formatCharDiff( $row ); |
| 1050 |
$comment = $this->formatComment( $row ); |
| 1051 |
$userlink = $this->formatUserLink( $row ); |
| 1052 |
$flags = $this->formatFlags( $row ); |
| 1053 |
$del = $this->formatVisibilityLink( $row ); |
| 1054 |
$tagSummary = $this->formatTags( $row, $classes ); |
| 1055 |
|
| 1056 |
if ( !$this->isArchive ) { |
| 1057 |
$this->hookRunner->onSpecialContributions__formatRow__flags( |
| 1058 |
$this->getContext(), $row, $flags ); |
| 1059 |
} |
| 1060 |
|
| 1061 |
$templateParams = [ |
| 1062 |
'del' => $del, |
| 1063 |
'timestamp' => $dateLink, |
| 1064 |
'diffHistLinks' => $diffHistLinks, |
| 1065 |
'charDifference' => $chardiff, |
| 1066 |
'flags' => $flags, |
| 1067 |
'articleLink' => $link, |
| 1068 |
'userlink' => $userlink, |
| 1069 |
'logText' => $comment, |
| 1070 |
'topmarktext' => $topmarktext, |
| 1071 |
'tagSummary' => $tagSummary, |
| 1072 |
]; |
| 1073 |
|
| 1074 |
|
| 1075 |
if ( $this->revisionUserIsDeleted( $row ) ) { |
| 1076 |
$templateParams['rev-deleted-user-contribs'] = |
| 1077 |
$this->msg( 'rev-deleted-user-contribs' )->escaped(); |
| 1078 |
} |
| 1079 |
|
| 1080 |
return $templateParams; |
| 1081 |
} |
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
public function getProcessedTemplate( $templateParams ) { |
| 1093 |
return $this->templateParser->processTemplate( |
| 1094 |
'SpecialContributionsLine', |
| 1095 |
$templateParams |
| 1096 |
); |
| 1097 |
} |
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
protected function getSqlComment() { |
| 1104 |
if ( $this->namespace || $this->deletedOnly ) { |
| 1105 |
|
| 1106 |
return 'contributions page filtered for namespace or RevisionDeleted edits'; |
| 1107 |
} else { |
| 1108 |
return 'contributions page unfiltered'; |
| 1109 |
} |
| 1110 |
} |
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
protected function preventClickjacking() { |
| 1116 |
$this->setPreventClickjacking( true ); |
| 1117 |
} |
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
protected function setPreventClickjacking( bool $enable ) { |
| 1124 |
$this->preventClickjacking = $enable; |
| 1125 |
} |
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
public function getPreventClickjacking() { |
| 1131 |
return $this->preventClickjacking; |
| 1132 |
} |
| 1133 |
|
| 1134 |
} |