| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\ChangeTags\Taggable; |
| 22 |
use MediaWiki\Config\Config; |
| 23 |
use MediaWiki\Debug\DeprecationHelper; |
| 24 |
use MediaWiki\Deferred\DeferredUpdates; |
| 25 |
use MediaWiki\HookContainer\HookRunner; |
| 26 |
use MediaWiki\Json\FormatJson; |
| 27 |
use MediaWiki\MainConfigNames; |
| 28 |
use MediaWiki\MediaWikiServices; |
| 29 |
use MediaWiki\Page\PageIdentity; |
| 30 |
use MediaWiki\Page\PageReference; |
| 31 |
use MediaWiki\Page\PageReferenceValue; |
| 32 |
use MediaWiki\Permissions\Authority; |
| 33 |
use MediaWiki\Permissions\PermissionStatus; |
| 34 |
use MediaWiki\RCFeed\RCFeed; |
| 35 |
use MediaWiki\Storage\EditResult; |
| 36 |
use MediaWiki\Title\Title; |
| 37 |
use MediaWiki\User\UserIdentity; |
| 38 |
use MediaWiki\User\UserIdentityValue; |
| 39 |
use MediaWiki\Utils\MWTimestamp; |
| 40 |
use Wikimedia\Assert\Assert; |
| 41 |
use Wikimedia\IPUtils; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
class RecentChange implements Taggable { |
| 111 |
use DeprecationHelper; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public const SRC_EDIT = 'mw.edit'; |
| 116 |
public const SRC_NEW = 'mw.new'; |
| 117 |
public const SRC_LOG = 'mw.log'; |
| 118 |
public const SRC_EXTERNAL = 'mw.external'; |
| 119 |
public const SRC_CATEGORIZE = 'mw.categorize'; |
| 120 |
|
| 121 |
public const PRC_UNPATROLLED = 0; |
| 122 |
public const PRC_PATROLLED = 1; |
| 123 |
public const PRC_AUTOPATROLLED = 2; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
public const SEND_NONE = true; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public const SEND_FEED = false; |
| 134 |
|
| 135 |
|
| 136 |
public $mAttribs = []; |
| 137 |
|
| 138 |
public $mExtra = []; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
private $mPage = null; |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
private $mPerformer = null; |
| 149 |
|
| 150 |
|
| 151 |
public $numberofWatchingusers = 0; |
| 152 |
|
| 153 |
public $notificationtimestamp; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
public $watchlistExpiry; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public $counter = -1; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
private $tags = []; |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
private $editResult = null; |
| 174 |
|
| 175 |
private const CHANGE_TYPES = [ |
| 176 |
'edit' => RC_EDIT, |
| 177 |
'new' => RC_NEW, |
| 178 |
'log' => RC_LOG, |
| 179 |
'external' => RC_EXTERNAL, |
| 180 |
'categorize' => RC_CATEGORIZE, |
| 181 |
]; |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
public static function newFromRow( $row ) { |
| 190 |
$rc = new RecentChange; |
| 191 |
$rc->loadFromRow( $row ); |
| 192 |
|
| 193 |
return $rc; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
public static function parseToRCType( $type ) { |
| 203 |
if ( is_array( $type ) ) { |
| 204 |
$retval = []; |
| 205 |
foreach ( $type as $t ) { |
| 206 |
$retval[] = self::parseToRCType( $t ); |
| 207 |
} |
| 208 |
|
| 209 |
return $retval; |
| 210 |
} |
| 211 |
|
| 212 |
if ( !array_key_exists( $type, self::CHANGE_TYPES ) ) { |
| 213 |
throw new InvalidArgumentException( "Unknown type '$type'" ); |
| 214 |
} |
| 215 |
return self::CHANGE_TYPES[$type]; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
public static function parseFromRCType( $rcType ) { |
| 225 |
return array_search( $rcType, self::CHANGE_TYPES, true ) ?: "$rcType"; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
public static function getChangeTypes() { |
| 236 |
return array_keys( self::CHANGE_TYPES ); |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
public static function newFromId( $rcid ) { |
| 246 |
return self::newFromConds( [ 'rc_id' => $rcid ], __METHOD__ ); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
public static function newFromConds( |
| 259 |
$conds, |
| 260 |
$fname = __METHOD__, |
| 261 |
$dbType = DB_REPLICA |
| 262 |
) { |
| 263 |
$icp = MediaWikiServices::getInstance()->getConnectionProvider(); |
| 264 |
|
| 265 |
$db = ( $dbType === DB_REPLICA ) ? $icp->getReplicaDatabase() : $icp->getPrimaryDatabase(); |
| 266 |
|
| 267 |
$rcQuery = self::getQueryInfo(); |
| 268 |
$row = $db->newSelectQueryBuilder() |
| 269 |
->queryInfo( $rcQuery ) |
| 270 |
->where( $conds ) |
| 271 |
->caller( $fname ) |
| 272 |
->fetchRow(); |
| 273 |
if ( $row !== false ) { |
| 274 |
return self::newFromRow( $row ); |
| 275 |
} else { |
| 276 |
return null; |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
public static function getQueryInfo() { |
| 296 |
$commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin( 'rc_comment' ); |
| 297 |
|
| 298 |
$commentQuery['joins']['comment_rc_comment'][0] = 'STRAIGHT_JOIN'; |
| 299 |
return [ |
| 300 |
'tables' => [ |
| 301 |
'recentchanges', |
| 302 |
'recentchanges_actor' => 'actor' |
| 303 |
] + $commentQuery['tables'], |
| 304 |
'fields' => [ |
| 305 |
'rc_id', |
| 306 |
'rc_timestamp', |
| 307 |
'rc_namespace', |
| 308 |
'rc_title', |
| 309 |
'rc_minor', |
| 310 |
'rc_bot', |
| 311 |
'rc_new', |
| 312 |
'rc_cur_id', |
| 313 |
'rc_this_oldid', |
| 314 |
'rc_last_oldid', |
| 315 |
'rc_type', |
| 316 |
'rc_source', |
| 317 |
'rc_patrolled', |
| 318 |
'rc_ip', |
| 319 |
'rc_old_len', |
| 320 |
'rc_new_len', |
| 321 |
'rc_deleted', |
| 322 |
'rc_logid', |
| 323 |
'rc_log_type', |
| 324 |
'rc_log_action', |
| 325 |
'rc_params', |
| 326 |
'rc_actor', |
| 327 |
'rc_user' => 'recentchanges_actor.actor_user', |
| 328 |
'rc_user_text' => 'recentchanges_actor.actor_name', |
| 329 |
] + $commentQuery['fields'], |
| 330 |
'joins' => [ |
| 331 |
'recentchanges_actor' => [ 'STRAIGHT_JOIN', 'actor_id=rc_actor' ] |
| 332 |
] + $commentQuery['joins'], |
| 333 |
]; |
| 334 |
} |
| 335 |
|
| 336 |
public function __construct() { |
| 337 |
$this->deprecatePublicPropertyFallback( |
| 338 |
'mTitle', |
| 339 |
'1.37', |
| 340 |
function () { |
| 341 |
return Title::castFromPageReference( $this->mPage ); |
| 342 |
}, |
| 343 |
function ( ?Title $title ) { |
| 344 |
$this->mPage = $title; |
| 345 |
} |
| 346 |
); |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
public function setAttribs( $attribs ) { |
| 355 |
$this->mAttribs = $attribs; |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
public function setExtra( $extra ) { |
| 362 |
$this->mExtra = $extra; |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
public function getTitle() { |
| 370 |
$this->mPage = Title::castFromPageReference( $this->getPage() ); |
| 371 |
return $this->mPage ?: Title::makeTitle( NS_SPECIAL, 'BadTitle' ); |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
public function getPage(): ?PageReference { |
| 379 |
if ( !$this->mPage ) { |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
if ( ( $this->mAttribs['rc_title'] ?? '' ) === '' ) { |
| 385 |
return null; |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
$this->mPage = new PageReferenceValue( |
| 393 |
(int)$this->mAttribs['rc_namespace'], |
| 394 |
$this->mAttribs['rc_title'], |
| 395 |
PageReference::LOCAL |
| 396 |
); |
| 397 |
} |
| 398 |
|
| 399 |
return $this->mPage; |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
public function getPerformerIdentity(): UserIdentity { |
| 410 |
if ( !$this->mPerformer ) { |
| 411 |
$this->mPerformer = $this->getUserIdentityFromAnyId( |
| 412 |
$this->mAttribs['rc_user'] ?? null, |
| 413 |
$this->mAttribs['rc_user_text'] ?? null, |
| 414 |
$this->mAttribs['rc_actor'] ?? null |
| 415 |
); |
| 416 |
} |
| 417 |
|
| 418 |
return $this->mPerformer; |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
public function save( $send = self::SEND_FEED ) { |
| 431 |
$services = MediaWikiServices::getInstance(); |
| 432 |
$mainConfig = $services->getMainConfig(); |
| 433 |
$putIPinRC = $mainConfig->get( MainConfigNames::PutIPinRC ); |
| 434 |
$dbw = $services->getConnectionProvider()->getPrimaryDatabase(); |
| 435 |
if ( !is_array( $this->mExtra ) ) { |
| 436 |
$this->mExtra = []; |
| 437 |
} |
| 438 |
|
| 439 |
if ( !$putIPinRC ) { |
| 440 |
$this->mAttribs['rc_ip'] = ''; |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
foreach ( [ 'minor', 'bot', 'new', 'patrolled', 'deleted' ] as $field ) { |
| 445 |
$this->mAttribs["rc_$field"] = (int)$this->mAttribs["rc_$field"]; |
| 446 |
} |
| 447 |
|
| 448 |
foreach ( [ 'old_len', 'new_len' ] as $field ) { |
| 449 |
$this->mAttribs["rc_$field"] = isset( $this->mAttribs["rc_$field"] ) |
| 450 |
? (int)$this->mAttribs["rc_$field"] |
| 451 |
: null; |
| 452 |
} |
| 453 |
|
| 454 |
$row = $this->mAttribs; |
| 455 |
|
| 456 |
|
| 457 |
$row['rc_comment'] = trim( $row['rc_comment'] ?? '' ); |
| 458 |
|
| 459 |
|
| 460 |
$row['rc_timestamp'] = $dbw->timestamp( $row['rc_timestamp'] ); |
| 461 |
|
| 462 |
|
| 463 |
if ( $row['rc_cur_id'] == 0 ) { |
| 464 |
unset( $row['rc_cur_id'] ); |
| 465 |
} |
| 466 |
|
| 467 |
|
| 468 |
$comment = $row['rc_comment']; |
| 469 |
unset( $row['rc_comment'], $row['rc_comment_text'], $row['rc_comment_data'] ); |
| 470 |
$row += $services->getCommentStore()->insert( $dbw, 'rc_comment', $comment ); |
| 471 |
|
| 472 |
|
| 473 |
$user = $this->getPerformerIdentity(); |
| 474 |
if ( array_key_exists( 'forImport', $this->mExtra ) && $this->mExtra['forImport'] ) { |
| 475 |
$actorStore = $services->getActorStoreFactory()->getActorStoreForImport(); |
| 476 |
} else { |
| 477 |
$actorStore = $services->getActorStoreFactory()->getActorStore(); |
| 478 |
} |
| 479 |
$row['rc_actor'] = $actorStore->acquireActorId( $user, $dbw ); |
| 480 |
unset( $row['rc_user'], $row['rc_user_text'] ); |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
unset( $row['rc_id'] ); |
| 485 |
|
| 486 |
|
| 487 |
$dbw->newInsertQueryBuilder() |
| 488 |
->insertInto( 'recentchanges' ) |
| 489 |
->row( $row ) |
| 490 |
->caller( __METHOD__ )->execute(); |
| 491 |
|
| 492 |
|
| 493 |
$this->mAttribs['rc_id'] = $dbw->insertId(); |
| 494 |
|
| 495 |
|
| 496 |
$hookRunner = new HookRunner( $services->getHookContainer() ); |
| 497 |
$hookRunner->onRecentChange_save( $this ); |
| 498 |
|
| 499 |
|
| 500 |
if ( $this->editResult !== null && count( $this->editResult->getRevertTags() ) ) { |
| 501 |
MediaWikiServices::getInstance()->getChangeTagsStore()->addTags( |
| 502 |
$this->editResult->getRevertTags(), |
| 503 |
$this->mAttribs['rc_id'], |
| 504 |
$this->mAttribs['rc_this_oldid'], |
| 505 |
$this->mAttribs['rc_logid'], |
| 506 |
FormatJson::encode( $this->editResult ), |
| 507 |
$this |
| 508 |
); |
| 509 |
} |
| 510 |
|
| 511 |
if ( count( $this->tags ) ) { |
| 512 |
|
| 513 |
|
| 514 |
MediaWikiServices::getInstance()->getChangeTagsStore()->addTags( |
| 515 |
$this->tags, |
| 516 |
$this->mAttribs['rc_id'], |
| 517 |
$this->mAttribs['rc_this_oldid'], |
| 518 |
$this->mAttribs['rc_logid'], |
| 519 |
null, |
| 520 |
$this |
| 521 |
); |
| 522 |
} |
| 523 |
|
| 524 |
if ( $send === self::SEND_FEED ) { |
| 525 |
|
| 526 |
$this->notifyRCFeeds(); |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
if ( self::isEnotifEnabled( $mainConfig ) ) { |
| 531 |
$userFactory = $services->getUserFactory(); |
| 532 |
$editor = $userFactory->newFromUserIdentity( $this->getPerformerIdentity() ); |
| 533 |
$page = $this->getPage(); |
| 534 |
$title = Title::castFromPageReference( $page ); |
| 535 |
|
| 536 |
|
| 537 |
if ( |
| 538 |
$title && |
| 539 |
$hookRunner->onAbortEmailNotification( $editor, $title, $this ) && |
| 540 |
$this->mAttribs['rc_type'] != RC_CATEGORIZE |
| 541 |
) { |
| 542 |
|
| 543 |
|
| 544 |
$dbw->onTransactionCommitOrIdle( |
| 545 |
function () use ( $editor, $title ) { |
| 546 |
$enotif = new EmailNotification(); |
| 547 |
$enotif->notifyOnPageChange( |
| 548 |
$editor, |
| 549 |
$title, |
| 550 |
$this->mAttribs['rc_timestamp'], |
| 551 |
$this->mAttribs['rc_comment'], |
| 552 |
$this->mAttribs['rc_minor'], |
| 553 |
$this->mAttribs['rc_last_oldid'], |
| 554 |
$this->mExtra['pageStatus'] |
| 555 |
); |
| 556 |
}, |
| 557 |
__METHOD__ |
| 558 |
); |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
$jobs = []; |
| 563 |
|
| 564 |
if ( mt_rand( 0, 9 ) == 0 ) { |
| 565 |
$jobs[] = RecentChangesUpdateJob::newPurgeJob(); |
| 566 |
} |
| 567 |
|
| 568 |
if ( $this->mAttribs['rc_user'] > 0 ) { |
| 569 |
$jobs[] = RecentChangesUpdateJob::newCacheUpdateJob(); |
| 570 |
} |
| 571 |
$services->getJobQueueGroup()->lazyPush( $jobs ); |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
public function notifyRCFeeds( ?array $feeds = null ) { |
| 579 |
|
| 580 |
|
| 581 |
if ( $this->mAttribs['rc_deleted'] != 0 ) { |
| 582 |
return; |
| 583 |
} |
| 584 |
|
| 585 |
$feeds ??= |
| 586 |
MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::RCFeeds ); |
| 587 |
|
| 588 |
$performer = $this->getPerformerIdentity(); |
| 589 |
|
| 590 |
foreach ( $feeds as $params ) { |
| 591 |
$params += [ |
| 592 |
'omit_bots' => false, |
| 593 |
'omit_anon' => false, |
| 594 |
'omit_user' => false, |
| 595 |
'omit_minor' => false, |
| 596 |
'omit_patrolled' => false, |
| 597 |
]; |
| 598 |
|
| 599 |
if ( |
| 600 |
( $params['omit_bots'] && $this->mAttribs['rc_bot'] ) || |
| 601 |
( $params['omit_anon'] && !$performer->isRegistered() ) || |
| 602 |
( $params['omit_user'] && $performer->isRegistered() ) || |
| 603 |
( $params['omit_minor'] && $this->mAttribs['rc_minor'] ) || |
| 604 |
( $params['omit_patrolled'] && $this->mAttribs['rc_patrolled'] ) || |
| 605 |
$this->mAttribs['rc_type'] == RC_EXTERNAL |
| 606 |
) { |
| 607 |
continue; |
| 608 |
} |
| 609 |
|
| 610 |
$actionComment = $this->mExtra['actionCommentIRC'] ?? null; |
| 611 |
|
| 612 |
$feed = RCFeed::factory( $params ); |
| 613 |
$feed->notify( $this, $actionComment ); |
| 614 |
} |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
public function doMarkPatrolled( Authority $performer, $auto = null, $tags = null ) { |
| 632 |
wfDeprecated( __METHOD__, '1.43' ); |
| 633 |
if ( $auto ) { |
| 634 |
wfWarn( __METHOD__ . ' with $auto = true' ); |
| 635 |
return []; |
| 636 |
} |
| 637 |
return $this->markPatrolled( $performer, $tags )->toLegacyErrorArray(); |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
public function markPatrolled( Authority $performer, $tags = null ): PermissionStatus { |
| 652 |
$services = MediaWikiServices::getInstance(); |
| 653 |
$mainConfig = $services->getMainConfig(); |
| 654 |
$useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol ); |
| 655 |
$useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol ); |
| 656 |
$useFilePatrol = $mainConfig->get( MainConfigNames::UseFilePatrol ); |
| 657 |
|
| 658 |
if ( $tags === null ) { |
| 659 |
$tags = []; |
| 660 |
} elseif ( is_string( $tags ) ) { |
| 661 |
$tags = [ $tags ]; |
| 662 |
} |
| 663 |
|
| 664 |
$status = PermissionStatus::newEmpty(); |
| 665 |
|
| 666 |
|
| 667 |
if ( !$useRCPatrol && ( !$useNPPatrol || $this->getAttribute( 'rc_type' ) != RC_NEW ) && |
| 668 |
( !$useFilePatrol || !( $this->getAttribute( 'rc_type' ) == RC_LOG && |
| 669 |
$this->getAttribute( 'rc_log_type' ) == 'upload' ) ) ) { |
| 670 |
$status->fatal( 'rcpatroldisabled' ); |
| 671 |
} |
| 672 |
$performer->authorizeWrite( 'patrol', $this->getTitle(), $status ); |
| 673 |
$user = $services->getUserFactory()->newFromAuthority( $performer ); |
| 674 |
$hookRunner = new HookRunner( $services->getHookContainer() ); |
| 675 |
if ( !$hookRunner->onMarkPatrolled( |
| 676 |
$this->getAttribute( 'rc_id' ), $user, false, false, $tags ) |
| 677 |
) { |
| 678 |
$status->fatal( 'hookaborted' ); |
| 679 |
} |
| 680 |
|
| 681 |
if ( $performer->getUser()->getName() === $this->getAttribute( 'rc_user_text' ) && |
| 682 |
!$performer->isAllowed( 'autopatrol' ) |
| 683 |
) { |
| 684 |
$status->fatal( 'markedaspatrollederror-noautopatrol' ); |
| 685 |
} |
| 686 |
if ( !$status->isGood() ) { |
| 687 |
return $status; |
| 688 |
} |
| 689 |
|
| 690 |
if ( $this->getAttribute( 'rc_patrolled' ) ) { |
| 691 |
return $status; |
| 692 |
} |
| 693 |
|
| 694 |
$affectedRowCount = $this->reallyMarkPatrolled(); |
| 695 |
|
| 696 |
if ( $affectedRowCount === 0 ) { |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
return $status; |
| 701 |
} |
| 702 |
|
| 703 |
|
| 704 |
PatrolLog::record( $this, false, $performer->getUser(), $tags ); |
| 705 |
|
| 706 |
$hookRunner->onMarkPatrolledComplete( |
| 707 |
$this->getAttribute( 'rc_id' ), $user, false, false ); |
| 708 |
|
| 709 |
return $status; |
| 710 |
} |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
public function reallyMarkPatrolled() { |
| 719 |
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); |
| 720 |
$dbw->newUpdateQueryBuilder() |
| 721 |
->update( 'recentchanges' ) |
| 722 |
->set( [ 'rc_patrolled' => self::PRC_PATROLLED ] ) |
| 723 |
->where( [ |
| 724 |
'rc_id' => $this->getAttribute( 'rc_id' ), |
| 725 |
'rc_patrolled' => self::PRC_UNPATROLLED, |
| 726 |
] ) |
| 727 |
->caller( __METHOD__ )->execute(); |
| 728 |
$affectedRowCount = $dbw->affectedRows(); |
| 729 |
|
| 730 |
if ( $affectedRowCount === 0 ) { |
| 731 |
return 0; |
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
$this->getTitle()->invalidateCache(); |
| 736 |
|
| 737 |
|
| 738 |
$revisionId = $this->getAttribute( 'rc_this_oldid' ); |
| 739 |
if ( $revisionId ) { |
| 740 |
$revertedTagUpdateManager = |
| 741 |
MediaWikiServices::getInstance()->getRevertedTagUpdateManager(); |
| 742 |
$revertedTagUpdateManager->approveRevertedTagForRevision( $revisionId ); |
| 743 |
} |
| 744 |
|
| 745 |
return $affectedRowCount; |
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
public static function notifyEdit( |
| 773 |
$timestamp, $page, $minor, $user, $comment, $oldId, $lastTimestamp, |
| 774 |
$bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0, |
| 775 |
$tags = [], ?EditResult $editResult = null |
| 776 |
) { |
| 777 |
Assert::parameter( $page->exists(), '$page', 'must represent an existing page' ); |
| 778 |
|
| 779 |
$rc = new RecentChange; |
| 780 |
$rc->mPage = $page; |
| 781 |
$rc->mPerformer = $user; |
| 782 |
$rc->mAttribs = [ |
| 783 |
'rc_timestamp' => $timestamp, |
| 784 |
'rc_namespace' => $page->getNamespace(), |
| 785 |
'rc_title' => $page->getDBkey(), |
| 786 |
'rc_type' => RC_EDIT, |
| 787 |
'rc_source' => self::SRC_EDIT, |
| 788 |
'rc_minor' => $minor ? 1 : 0, |
| 789 |
'rc_cur_id' => $page->getId(), |
| 790 |
'rc_user' => $user->getId(), |
| 791 |
'rc_user_text' => $user->getName(), |
| 792 |
'rc_comment' => &$comment, |
| 793 |
'rc_comment_text' => &$comment, |
| 794 |
'rc_comment_data' => null, |
| 795 |
'rc_this_oldid' => (int)$newId, |
| 796 |
'rc_last_oldid' => $oldId, |
| 797 |
'rc_bot' => $bot ? 1 : 0, |
| 798 |
'rc_ip' => self::checkIPAddress( $ip ), |
| 799 |
'rc_patrolled' => intval( $patrol ), |
| 800 |
'rc_new' => 0, |
| 801 |
'rc_old_len' => $oldSize, |
| 802 |
'rc_new_len' => $newSize, |
| 803 |
'rc_deleted' => 0, |
| 804 |
'rc_logid' => 0, |
| 805 |
'rc_log_type' => null, |
| 806 |
'rc_log_action' => '', |
| 807 |
'rc_params' => '' |
| 808 |
]; |
| 809 |
|
| 810 |
|
| 811 |
$formatter = MediaWikiServices::getInstance()->getTitleFormatter(); |
| 812 |
|
| 813 |
$rc->mExtra = [ |
| 814 |
'prefixedDBkey' => $formatter->getPrefixedDBkey( $page ), |
| 815 |
'lastTimestamp' => $lastTimestamp, |
| 816 |
'oldSize' => $oldSize, |
| 817 |
'newSize' => $newSize, |
| 818 |
'pageStatus' => 'changed' |
| 819 |
]; |
| 820 |
|
| 821 |
DeferredUpdates::addCallableUpdate( |
| 822 |
static function () use ( $rc, $tags, $editResult ) { |
| 823 |
$rc->addTags( $tags ); |
| 824 |
$rc->setEditResult( $editResult ); |
| 825 |
$rc->save(); |
| 826 |
}, |
| 827 |
DeferredUpdates::POSTSEND, |
| 828 |
MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase() |
| 829 |
); |
| 830 |
|
| 831 |
return $rc; |
| 832 |
} |
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
public static function notifyNew( |
| 854 |
$timestamp, |
| 855 |
$page, $minor, $user, $comment, $bot, |
| 856 |
$ip = '', $size = 0, $newId = 0, $patrol = 0, $tags = [] |
| 857 |
) { |
| 858 |
Assert::parameter( $page->exists(), '$page', 'must represent an existing page' ); |
| 859 |
|
| 860 |
$rc = new RecentChange; |
| 861 |
$rc->mPage = $page; |
| 862 |
$rc->mPerformer = $user; |
| 863 |
$rc->mAttribs = [ |
| 864 |
'rc_timestamp' => $timestamp, |
| 865 |
'rc_namespace' => $page->getNamespace(), |
| 866 |
'rc_title' => $page->getDBkey(), |
| 867 |
'rc_type' => RC_NEW, |
| 868 |
'rc_source' => self::SRC_NEW, |
| 869 |
'rc_minor' => $minor ? 1 : 0, |
| 870 |
'rc_cur_id' => $page->getId(), |
| 871 |
'rc_user' => $user->getId(), |
| 872 |
'rc_user_text' => $user->getName(), |
| 873 |
'rc_comment' => &$comment, |
| 874 |
'rc_comment_text' => &$comment, |
| 875 |
'rc_comment_data' => null, |
| 876 |
'rc_this_oldid' => (int)$newId, |
| 877 |
'rc_last_oldid' => 0, |
| 878 |
'rc_bot' => $bot ? 1 : 0, |
| 879 |
'rc_ip' => self::checkIPAddress( $ip ), |
| 880 |
'rc_patrolled' => intval( $patrol ), |
| 881 |
'rc_new' => 1, |
| 882 |
'rc_old_len' => 0, |
| 883 |
'rc_new_len' => $size, |
| 884 |
'rc_deleted' => 0, |
| 885 |
'rc_logid' => 0, |
| 886 |
'rc_log_type' => null, |
| 887 |
'rc_log_action' => '', |
| 888 |
'rc_params' => '' |
| 889 |
]; |
| 890 |
|
| 891 |
|
| 892 |
$formatter = MediaWikiServices::getInstance()->getTitleFormatter(); |
| 893 |
|
| 894 |
$rc->mExtra = [ |
| 895 |
'prefixedDBkey' => $formatter->getPrefixedDBkey( $page ), |
| 896 |
'lastTimestamp' => 0, |
| 897 |
'oldSize' => 0, |
| 898 |
'newSize' => $size, |
| 899 |
'pageStatus' => 'created' |
| 900 |
]; |
| 901 |
|
| 902 |
DeferredUpdates::addCallableUpdate( |
| 903 |
static function () use ( $rc, $tags ) { |
| 904 |
$rc->addTags( $tags ); |
| 905 |
$rc->save(); |
| 906 |
}, |
| 907 |
DeferredUpdates::POSTSEND, |
| 908 |
MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase() |
| 909 |
); |
| 910 |
|
| 911 |
return $rc; |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
public static function notifyLog( $timestamp, |
| 931 |
$logPage, $user, $actionComment, $ip, $type, |
| 932 |
$action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' |
| 933 |
) { |
| 934 |
$logRestrictions = MediaWikiServices::getInstance()->getMainConfig() |
| 935 |
->get( MainConfigNames::LogRestrictions ); |
| 936 |
|
| 937 |
|
| 938 |
if ( isset( $logRestrictions[$type] ) && $logRestrictions[$type] != '*' ) { |
| 939 |
return false; |
| 940 |
} |
| 941 |
$rc = self::newLogEntry( $timestamp, |
| 942 |
$logPage, $user, $actionComment, $ip, $type, $action, |
| 943 |
$target, $logComment, $params, $newId, $actionCommentIRC ); |
| 944 |
$rc->save(); |
| 945 |
|
| 946 |
return true; |
| 947 |
} |
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
public static function newLogEntry( $timestamp, |
| 971 |
$logPage, $user, $actionComment, $ip, |
| 972 |
$type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '', |
| 973 |
$revId = 0, $isPatrollable = false, $forceBotFlag = null, $deleted = 0 |
| 974 |
) { |
| 975 |
global $wgRequest; |
| 976 |
|
| 977 |
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); |
| 978 |
|
| 979 |
|
| 980 |
switch ( $type . '-' . $action ) { |
| 981 |
case 'delete-delete': |
| 982 |
case 'delete-delete_redir': |
| 983 |
case 'delete-delete_redir2': |
| 984 |
$pageStatus = 'deleted'; |
| 985 |
break; |
| 986 |
case 'move-move': |
| 987 |
case 'move-move_redir': |
| 988 |
$pageStatus = 'moved'; |
| 989 |
break; |
| 990 |
case 'delete-restore': |
| 991 |
$pageStatus = 'restored'; |
| 992 |
break; |
| 993 |
case 'upload-upload': |
| 994 |
$pageStatus = 'created'; |
| 995 |
break; |
| 996 |
case 'upload-overwrite': |
| 997 |
default: |
| 998 |
$pageStatus = 'changed'; |
| 999 |
break; |
| 1000 |
} |
| 1001 |
|
| 1002 |
|
| 1003 |
$canAutopatrol = $permissionManager->userHasRight( $user, 'autopatrol' ); |
| 1004 |
$markPatrolled = $isPatrollable ? $canAutopatrol : true; |
| 1005 |
|
| 1006 |
if ( $target instanceof PageIdentity && $target->canExist() ) { |
| 1007 |
$pageId = $target->getId(); |
| 1008 |
} else { |
| 1009 |
$pageId = 0; |
| 1010 |
} |
| 1011 |
|
| 1012 |
if ( $forceBotFlag !== null ) { |
| 1013 |
$bot = (int)$forceBotFlag; |
| 1014 |
} else { |
| 1015 |
$bot = $permissionManager->userHasRight( $user, 'bot' ) ? |
| 1016 |
(int)$wgRequest->getBool( 'bot', true ) : 0; |
| 1017 |
} |
| 1018 |
|
| 1019 |
$rc = new RecentChange; |
| 1020 |
$rc->mPage = $target; |
| 1021 |
$rc->mPerformer = $user; |
| 1022 |
$rc->mAttribs = [ |
| 1023 |
'rc_timestamp' => $timestamp, |
| 1024 |
'rc_namespace' => $target->getNamespace(), |
| 1025 |
'rc_title' => $target->getDBkey(), |
| 1026 |
'rc_type' => RC_LOG, |
| 1027 |
'rc_source' => self::SRC_LOG, |
| 1028 |
'rc_minor' => 0, |
| 1029 |
'rc_cur_id' => $pageId, |
| 1030 |
'rc_user' => $user->getId(), |
| 1031 |
'rc_user_text' => $user->getName(), |
| 1032 |
'rc_comment' => &$logComment, |
| 1033 |
'rc_comment_text' => &$logComment, |
| 1034 |
'rc_comment_data' => null, |
| 1035 |
'rc_this_oldid' => (int)$revId, |
| 1036 |
'rc_last_oldid' => 0, |
| 1037 |
'rc_bot' => $bot, |
| 1038 |
'rc_ip' => self::checkIPAddress( $ip ), |
| 1039 |
'rc_patrolled' => $markPatrolled ? self::PRC_AUTOPATROLLED : self::PRC_UNPATROLLED, |
| 1040 |
'rc_new' => 0, |
| 1041 |
'rc_old_len' => null, |
| 1042 |
'rc_new_len' => null, |
| 1043 |
'rc_deleted' => $deleted, |
| 1044 |
'rc_logid' => $newId, |
| 1045 |
'rc_log_type' => $type, |
| 1046 |
'rc_log_action' => $action, |
| 1047 |
'rc_params' => $params |
| 1048 |
]; |
| 1049 |
|
| 1050 |
|
| 1051 |
$formatter = MediaWikiServices::getInstance()->getTitleFormatter(); |
| 1052 |
|
| 1053 |
$rc->mExtra = [ |
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
'prefixedDBkey' => $formatter->getPrefixedDBkey( $logPage ), |
| 1058 |
'lastTimestamp' => 0, |
| 1059 |
'actionComment' => $actionComment, |
| 1060 |
'pageStatus' => $pageStatus, |
| 1061 |
'actionCommentIRC' => $actionCommentIRC |
| 1062 |
]; |
| 1063 |
|
| 1064 |
return $rc; |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
public static function newForCategorization( |
| 1090 |
$timestamp, |
| 1091 |
PageIdentity $categoryTitle, |
| 1092 |
?UserIdentity $user, |
| 1093 |
$comment, |
| 1094 |
PageIdentity $pageTitle, |
| 1095 |
$oldRevId, |
| 1096 |
$newRevId, |
| 1097 |
$lastTimestamp, |
| 1098 |
$bot, |
| 1099 |
$ip = '', |
| 1100 |
$deleted = 0, |
| 1101 |
$added = null, |
| 1102 |
bool $forImport = false |
| 1103 |
) { |
| 1104 |
|
| 1105 |
$categoryWikiPage = MediaWikiServices::getInstance()->getWikiPageFactory() |
| 1106 |
->newFromTitle( $categoryTitle ); |
| 1107 |
|
| 1108 |
'@phan-var WikiCategoryPage $categoryWikiPage'; |
| 1109 |
$params = [ |
| 1110 |
'hidden-cat' => $categoryWikiPage->isHidden() |
| 1111 |
]; |
| 1112 |
if ( $added !== null ) { |
| 1113 |
$params['added'] = $added; |
| 1114 |
} |
| 1115 |
|
| 1116 |
if ( !$user ) { |
| 1117 |
|
| 1118 |
$user = MediaWikiServices::getInstance()->getActorStore()->getUnknownActor(); |
| 1119 |
} |
| 1120 |
|
| 1121 |
$rc = new RecentChange; |
| 1122 |
$rc->mPage = $categoryTitle; |
| 1123 |
$rc->mPerformer = $user; |
| 1124 |
$rc->mAttribs = [ |
| 1125 |
'rc_timestamp' => MWTimestamp::convert( TS_MW, $timestamp ), |
| 1126 |
'rc_namespace' => $categoryTitle->getNamespace(), |
| 1127 |
'rc_title' => $categoryTitle->getDBkey(), |
| 1128 |
'rc_type' => RC_CATEGORIZE, |
| 1129 |
'rc_source' => self::SRC_CATEGORIZE, |
| 1130 |
'rc_minor' => 0, |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
'rc_cur_id' => $pageTitle->getId(), |
| 1135 |
'rc_user' => $user->getId(), |
| 1136 |
'rc_user_text' => $user->getName(), |
| 1137 |
'rc_comment' => &$comment, |
| 1138 |
'rc_comment_text' => &$comment, |
| 1139 |
'rc_comment_data' => null, |
| 1140 |
'rc_this_oldid' => (int)$newRevId, |
| 1141 |
'rc_last_oldid' => $oldRevId, |
| 1142 |
'rc_bot' => $bot ? 1 : 0, |
| 1143 |
'rc_ip' => self::checkIPAddress( $ip ), |
| 1144 |
'rc_patrolled' => self::PRC_AUTOPATROLLED, |
| 1145 |
'rc_new' => 0, |
| 1146 |
'rc_old_len' => null, |
| 1147 |
'rc_new_len' => null, |
| 1148 |
'rc_deleted' => $deleted, |
| 1149 |
'rc_logid' => 0, |
| 1150 |
'rc_log_type' => null, |
| 1151 |
'rc_log_action' => '', |
| 1152 |
'rc_params' => serialize( $params ) |
| 1153 |
]; |
| 1154 |
|
| 1155 |
|
| 1156 |
$formatter = MediaWikiServices::getInstance()->getTitleFormatter(); |
| 1157 |
|
| 1158 |
$rc->mExtra = [ |
| 1159 |
'prefixedDBkey' => $formatter->getPrefixedDBkey( $categoryTitle ), |
| 1160 |
'lastTimestamp' => $lastTimestamp, |
| 1161 |
'oldSize' => 0, |
| 1162 |
'newSize' => 0, |
| 1163 |
'pageStatus' => 'changed', |
| 1164 |
'forImport' => $forImport, |
| 1165 |
]; |
| 1166 |
|
| 1167 |
return $rc; |
| 1168 |
} |
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
public function getParam( $name ) { |
| 1179 |
$params = $this->parseParams(); |
| 1180 |
return $params[$name] ?? null; |
| 1181 |
} |
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
public function loadFromRow( $row ) { |
| 1189 |
$this->mAttribs = get_object_vars( $row ); |
| 1190 |
$this->mAttribs['rc_timestamp'] = wfTimestamp( TS_MW, $this->mAttribs['rc_timestamp'] ); |
| 1191 |
|
| 1192 |
$this->mAttribs['rc_deleted'] = $row->rc_deleted; |
| 1193 |
|
| 1194 |
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
| 1195 |
$comment = MediaWikiServices::getInstance()->getCommentStore() |
| 1196 |
|
| 1197 |
->getCommentLegacy( $dbr, 'rc_comment', $row, true ) |
| 1198 |
->text; |
| 1199 |
$this->mAttribs['rc_comment'] = &$comment; |
| 1200 |
$this->mAttribs['rc_comment_text'] = &$comment; |
| 1201 |
$this->mAttribs['rc_comment_data'] = null; |
| 1202 |
|
| 1203 |
$this->mPerformer = $this->getUserIdentityFromAnyId( |
| 1204 |
$row->rc_user ?? null, |
| 1205 |
$row->rc_user_text ?? null, |
| 1206 |
$row->rc_actor ?? null |
| 1207 |
); |
| 1208 |
$this->mAttribs['rc_user'] = $this->mPerformer->getId(); |
| 1209 |
$this->mAttribs['rc_user_text'] = $this->mPerformer->getName(); |
| 1210 |
|
| 1211 |
|
| 1212 |
if ( isset( $row->we_expiry ) && $row->we_expiry ) { |
| 1213 |
$this->watchlistExpiry = wfTimestamp( TS_MW, $row->we_expiry ); |
| 1214 |
} |
| 1215 |
} |
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
public function getAttribute( $name ) { |
| 1224 |
if ( $name === 'rc_comment' ) { |
| 1225 |
return MediaWikiServices::getInstance()->getCommentStore() |
| 1226 |
->getComment( 'rc_comment', $this->mAttribs, true )->text; |
| 1227 |
} |
| 1228 |
|
| 1229 |
if ( $name === 'rc_user' || $name === 'rc_user_text' || $name === 'rc_actor' ) { |
| 1230 |
$user = $this->getPerformerIdentity(); |
| 1231 |
|
| 1232 |
if ( $name === 'rc_user' ) { |
| 1233 |
return $user->getId(); |
| 1234 |
} |
| 1235 |
if ( $name === 'rc_user_text' ) { |
| 1236 |
return $user->getName(); |
| 1237 |
} |
| 1238 |
if ( $name === 'rc_actor' ) { |
| 1239 |
|
| 1240 |
wfDeprecatedMsg( 'Accessing deprecated field rc_actor', '1.36' ); |
| 1241 |
$actorStore = MediaWikiServices::getInstance()->getActorStore(); |
| 1242 |
$db = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
| 1243 |
return $actorStore->findActorId( $user, $db ); |
| 1244 |
} |
| 1245 |
} |
| 1246 |
|
| 1247 |
return $this->mAttribs[$name] ?? null; |
| 1248 |
} |
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
public function getAttributes() { |
| 1254 |
return $this->mAttribs; |
| 1255 |
} |
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
public function diffLinkTrail( $forceCur ) { |
| 1264 |
if ( $this->mAttribs['rc_type'] == RC_EDIT ) { |
| 1265 |
$trail = "curid=" . (int)( $this->mAttribs['rc_cur_id'] ) . |
| 1266 |
"&oldid=" . (int)( $this->mAttribs['rc_last_oldid'] ); |
| 1267 |
if ( $forceCur ) { |
| 1268 |
$trail .= '&diff=0'; |
| 1269 |
} else { |
| 1270 |
$trail .= '&diff=' . (int)( $this->mAttribs['rc_this_oldid'] ); |
| 1271 |
} |
| 1272 |
} else { |
| 1273 |
$trail = ''; |
| 1274 |
} |
| 1275 |
|
| 1276 |
return $trail; |
| 1277 |
} |
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
public function getCharacterDifference( $old = 0, $new = 0 ) { |
| 1287 |
if ( $old === 0 ) { |
| 1288 |
$old = $this->mAttribs['rc_old_len']; |
| 1289 |
} |
| 1290 |
if ( $new === 0 ) { |
| 1291 |
$new = $this->mAttribs['rc_new_len']; |
| 1292 |
} |
| 1293 |
if ( $old === null || $new === null ) { |
| 1294 |
return ''; |
| 1295 |
} |
| 1296 |
|
| 1297 |
return ChangesList::showCharacterDifference( $old, $new ); |
| 1298 |
} |
| 1299 |
|
| 1300 |
private static function checkIPAddress( $ip ) { |
| 1301 |
global $wgRequest; |
| 1302 |
|
| 1303 |
if ( $ip ) { |
| 1304 |
if ( !IPUtils::isIPAddress( $ip ) ) { |
| 1305 |
throw new RuntimeException( "Attempt to write \"" . $ip . |
| 1306 |
"\" as an IP address into recent changes" ); |
| 1307 |
} |
| 1308 |
} else { |
| 1309 |
$ip = $wgRequest->getIP(); |
| 1310 |
if ( !$ip ) { |
| 1311 |
$ip = ''; |
| 1312 |
} |
| 1313 |
} |
| 1314 |
|
| 1315 |
return $ip; |
| 1316 |
} |
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
public static function isInRCLifespan( $timestamp, $tolerance = 0 ) { |
| 1328 |
$rcMaxAge = |
| 1329 |
MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::RCMaxAge ); |
| 1330 |
|
| 1331 |
return (int)wfTimestamp( TS_UNIX, $timestamp ) > time() - $tolerance - $rcMaxAge; |
| 1332 |
} |
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
public static function isEnotifEnabled( Config $conf ): bool { |
| 1361 |
return $conf->get( MainConfigNames::EnotifUserTalk ) || |
| 1362 |
$conf->get( MainConfigNames::EnotifWatchlist ) || |
| 1363 |
$conf->get( MainConfigNames::ShowUpdatedMarker ); |
| 1364 |
} |
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
public function getNotifyUrl() { |
| 1375 |
$services = MediaWikiServices::getInstance(); |
| 1376 |
$mainConfig = $services->getMainConfig(); |
| 1377 |
$useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol ); |
| 1378 |
$useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol ); |
| 1379 |
$localInterwikis = $mainConfig->get( MainConfigNames::LocalInterwikis ); |
| 1380 |
$canonicalServer = $mainConfig->get( MainConfigNames::CanonicalServer ); |
| 1381 |
$script = $mainConfig->get( MainConfigNames::Script ); |
| 1382 |
|
| 1383 |
$type = $this->getAttribute( 'rc_type' ); |
| 1384 |
if ( $type == RC_LOG ) { |
| 1385 |
$url = null; |
| 1386 |
} else { |
| 1387 |
$url = $canonicalServer . $script; |
| 1388 |
if ( $type == RC_NEW ) { |
| 1389 |
$query = '?oldid=' . $this->getAttribute( 'rc_this_oldid' ); |
| 1390 |
} else { |
| 1391 |
$query = '?diff=' . $this->getAttribute( 'rc_this_oldid' ) |
| 1392 |
. '&oldid=' . $this->getAttribute( 'rc_last_oldid' ); |
| 1393 |
} |
| 1394 |
if ( $useRCPatrol || ( $this->getAttribute( 'rc_type' ) == RC_NEW && $useNPPatrol ) ) { |
| 1395 |
$query .= '&rcid=' . $this->getAttribute( 'rc_id' ); |
| 1396 |
} |
| 1397 |
|
| 1398 |
( new HookRunner( $services->getHookContainer() ) )->onIRCLineURL( $url, $query, $this ); |
| 1399 |
$url .= $query; |
| 1400 |
} |
| 1401 |
|
| 1402 |
return $url; |
| 1403 |
} |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
public function parseParams() { |
| 1412 |
return LogEntryBase::extractParams( $this->getAttribute( 'rc_params' ), |
| 1413 |
$this->getAttribute( 'rc_log_type' ) . '/' . $this->getAttribute( 'rc_log_action' ) ); |
| 1414 |
} |
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
public function addTags( $tags ) { |
| 1425 |
if ( is_string( $tags ) ) { |
| 1426 |
$this->tags[] = $tags; |
| 1427 |
} else { |
| 1428 |
$this->tags = array_merge( $tags, $this->tags ); |
| 1429 |
} |
| 1430 |
} |
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
public function setEditResult( ?EditResult $editResult ) { |
| 1440 |
$this->editResult = $editResult; |
| 1441 |
} |
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
private function getUserIdentityFromAnyId( |
| 1451 |
$userId, |
| 1452 |
$userName, |
| 1453 |
$actorId = null |
| 1454 |
): UserIdentity { |
| 1455 |
|
| 1456 |
|
| 1457 |
$userId = isset( $userId ) ? (int)$userId : null; |
| 1458 |
$actorId = isset( $actorId ) ? (int)$actorId : 0; |
| 1459 |
|
| 1460 |
$actorStore = MediaWikiServices::getInstance()->getActorStore(); |
| 1461 |
if ( $userName && $actorId ) { |
| 1462 |
|
| 1463 |
|
| 1464 |
return $actorStore->newActorFromRowFields( $userId, $userName, $actorId ); |
| 1465 |
} |
| 1466 |
if ( $userId !== null ) { |
| 1467 |
if ( $userName !== null ) { |
| 1468 |
|
| 1469 |
$user = new UserIdentityValue( $userId, $userName ); |
| 1470 |
} else { |
| 1471 |
$user = $actorStore->getUserIdentityByUserId( $userId ); |
| 1472 |
|
| 1473 |
if ( !$user ) { |
| 1474 |
throw new RuntimeException( "User not found by ID: $userId" ); |
| 1475 |
} |
| 1476 |
} |
| 1477 |
} elseif ( $actorId > 0 ) { |
| 1478 |
$db = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
| 1479 |
$user = $actorStore->getActorById( $actorId, $db ); |
| 1480 |
|
| 1481 |
if ( !$user ) { |
| 1482 |
throw new RuntimeException( "User not found by actor ID: $actorId" ); |
| 1483 |
} |
| 1484 |
} elseif ( $userName !== null ) { |
| 1485 |
$user = $actorStore->getUserIdentityByName( $userName ); |
| 1486 |
|
| 1487 |
if ( !$user ) { |
| 1488 |
throw new RuntimeException( "User not found by name: $userName" ); |
| 1489 |
} |
| 1490 |
} else { |
| 1491 |
throw new RuntimeException( 'At least one of user ID, actor ID or user name must be given' ); |
| 1492 |
} |
| 1493 |
|
| 1494 |
return $user; |
| 1495 |
} |
| 1496 |
} |