| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
> |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
namespace MediaWiki\Page; |
| 25 |
|
| 26 |
use InvalidArgumentException; |
| 27 |
use ManualLogEntry; |
| 28 |
use MediaWiki; |
| 29 |
use MediaWiki\CommentStore\CommentStoreComment; |
| 30 |
use MediaWiki\Content\Content; |
| 31 |
use MediaWiki\Content\IContentHandlerFactory; |
| 32 |
use MediaWiki\EditPage\SpamChecker; |
| 33 |
use MediaWiki\HookContainer\HookContainer; |
| 34 |
use MediaWiki\HookContainer\HookRunner; |
| 35 |
use MediaWiki\Linker\LinkTargetLookup; |
| 36 |
use MediaWiki\MainConfigNames; |
| 37 |
use MediaWiki\MediaWikiServices; |
| 38 |
use MediaWiki\Message\Message; |
| 39 |
use MediaWiki\Permissions\Authority; |
| 40 |
use MediaWiki\Permissions\PermissionStatus; |
| 41 |
use MediaWiki\Revision\MutableRevisionRecord; |
| 42 |
use MediaWiki\Revision\RevisionStore; |
| 43 |
use MediaWiki\Revision\SlotRecord; |
| 44 |
use MediaWiki\Status\Status; |
| 45 |
use MediaWiki\Title\TitleFactory; |
| 46 |
use MediaWiki\Title\TitleFormatter; |
| 47 |
use MediaWiki\Title\TitleValue; |
| 48 |
use MediaWiki\Utils\MWTimestamp; |
| 49 |
use MediaWiki\Watchlist\WatchedItemStoreInterface; |
| 50 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 51 |
use Wikimedia\Rdbms\IDatabase; |
| 52 |
use Wikimedia\Timestamp\TimestampException; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
class MergeHistory { |
| 61 |
|
| 62 |
|
| 63 |
public const REVISION_LIMIT = 5000; |
| 64 |
|
| 65 |
|
| 66 |
protected $source; |
| 67 |
|
| 68 |
|
| 69 |
protected $dest; |
| 70 |
|
| 71 |
|
| 72 |
protected $dbw; |
| 73 |
|
| 74 |
|
| 75 |
private $timestamp; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
protected $maxTimestamp = false; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
protected $timeWhere = false; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
protected $timestampLimit = false; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
private $revidLimit = null; |
| 99 |
|
| 100 |
|
| 101 |
protected $revisionsMerged; |
| 102 |
|
| 103 |
private IContentHandlerFactory $contentHandlerFactory; |
| 104 |
private RevisionStore $revisionStore; |
| 105 |
private WatchedItemStoreInterface $watchedItemStore; |
| 106 |
private SpamChecker $spamChecker; |
| 107 |
private HookRunner $hookRunner; |
| 108 |
private WikiPageFactory $wikiPageFactory; |
| 109 |
private TitleFormatter $titleFormatter; |
| 110 |
private TitleFactory $titleFactory; |
| 111 |
private LinkTargetLookup $linkTargetLookup; |
| 112 |
private DeletePageFactory $deletePageFactory; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
public function __construct( |
| 131 |
PageIdentity $source, |
| 132 |
PageIdentity $dest, |
| 133 |
?string $timestamp, |
| 134 |
IConnectionProvider $dbProvider, |
| 135 |
IContentHandlerFactory $contentHandlerFactory, |
| 136 |
RevisionStore $revisionStore, |
| 137 |
WatchedItemStoreInterface $watchedItemStore, |
| 138 |
SpamChecker $spamChecker, |
| 139 |
HookContainer $hookContainer, |
| 140 |
WikiPageFactory $wikiPageFactory, |
| 141 |
TitleFormatter $titleFormatter, |
| 142 |
TitleFactory $titleFactory, |
| 143 |
LinkTargetLookup $linkTargetLookup, |
| 144 |
DeletePageFactory $deletePageFactory |
| 145 |
) { |
| 146 |
|
| 147 |
$this->source = $source; |
| 148 |
$this->dest = $dest; |
| 149 |
$this->timestamp = $timestamp; |
| 150 |
|
| 151 |
|
| 152 |
$this->dbw = $dbProvider->getPrimaryDatabase(); |
| 153 |
|
| 154 |
$this->contentHandlerFactory = $contentHandlerFactory; |
| 155 |
$this->revisionStore = $revisionStore; |
| 156 |
$this->watchedItemStore = $watchedItemStore; |
| 157 |
$this->spamChecker = $spamChecker; |
| 158 |
$this->hookRunner = new HookRunner( $hookContainer ); |
| 159 |
$this->wikiPageFactory = $wikiPageFactory; |
| 160 |
$this->titleFormatter = $titleFormatter; |
| 161 |
$this->titleFactory = $titleFactory; |
| 162 |
$this->linkTargetLookup = $linkTargetLookup; |
| 163 |
$this->deletePageFactory = $deletePageFactory; |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public function getRevisionCount() { |
| 171 |
$count = $this->dbw->newSelectQueryBuilder() |
| 172 |
->select( '1' ) |
| 173 |
->from( 'revision' ) |
| 174 |
->where( [ 'rev_page' => $this->source->getId(), $this->getTimeWhere() ] ) |
| 175 |
->limit( self::REVISION_LIMIT + 1 ) |
| 176 |
->caller( __METHOD__ )->fetchRowCount(); |
| 177 |
|
| 178 |
return $count; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
public function getMergedRevisionCount() { |
| 187 |
return $this->revisionsMerged; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
private function authorizeInternal( |
| 197 |
callable $authorizer, |
| 198 |
Authority $performer, |
| 199 |
string $reason |
| 200 |
) { |
| 201 |
$status = PermissionStatus::newEmpty(); |
| 202 |
|
| 203 |
$authorizer( 'edit', $this->source, $status ); |
| 204 |
$authorizer( 'edit', $this->dest, $status ); |
| 205 |
|
| 206 |
|
| 207 |
if ( $this->spamChecker->checkSummary( $reason ) !== false ) { |
| 208 |
|
| 209 |
$status->fatal( 'spamprotectiontext' ); |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
if ( !$performer->isAllowed( 'mergehistory' ) ) { |
| 214 |
|
| 215 |
$status->fatal( 'mergehistory-fail-permission' ); |
| 216 |
} |
| 217 |
return $status; |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
public function probablyCanMerge( Authority $performer, ?string $reason = null ): PermissionStatus { |
| 232 |
return $this->authorizeInternal( |
| 233 |
static function ( string $action, PageIdentity $target, PermissionStatus $status ) use ( $performer ) { |
| 234 |
return $performer->probablyCan( $action, $target, $status ); |
| 235 |
}, |
| 236 |
$performer, |
| 237 |
$reason |
| 238 |
); |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
public function authorizeMerge( Authority $performer, ?string $reason = null ): PermissionStatus { |
| 253 |
return $this->authorizeInternal( |
| 254 |
static function ( string $action, PageIdentity $target, PermissionStatus $status ) use ( $performer ) { |
| 255 |
return $performer->authorizeWrite( $action, $target, $status ); |
| 256 |
}, |
| 257 |
$performer, |
| 258 |
$reason |
| 259 |
); |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
public function isValidMerge() { |
| 270 |
$status = new Status(); |
| 271 |
|
| 272 |
|
| 273 |
if ( $this->source->getId() === 0 ) { |
| 274 |
$status->fatal( 'mergehistory-fail-invalid-source' ); |
| 275 |
} |
| 276 |
if ( $this->dest->getId() === 0 ) { |
| 277 |
$status->fatal( 'mergehistory-fail-invalid-dest' ); |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
if ( $this->source->isSamePageAs( $this->dest ) ) { |
| 282 |
$status->fatal( 'mergehistory-fail-self-merge' ); |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
if ( !$this->getTimestampLimit() ) { |
| 287 |
$status->fatal( 'mergehistory-fail-bad-timestamp' ); |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
if ( $this->getTimestampLimit() > $this->getMaxTimestamp() ) { |
| 292 |
$status->fatal( 'mergehistory-fail-timestamps-overlap' ); |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
if ( $this->getTimestampLimit() && $this->getRevisionCount() > self::REVISION_LIMIT ) { |
| 297 |
$status->fatal( 'mergehistory-fail-toobig', Message::numParam( self::REVISION_LIMIT ) ); |
| 298 |
} |
| 299 |
|
| 300 |
return $status; |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
public function merge( Authority $performer, $reason = '' ) { |
| 318 |
$status = new Status(); |
| 319 |
|
| 320 |
|
| 321 |
$validCheck = $this->isValidMerge(); |
| 322 |
if ( !$validCheck->isOK() ) { |
| 323 |
return $validCheck; |
| 324 |
} |
| 325 |
$permCheck = $this->authorizeMerge( $performer, $reason ); |
| 326 |
if ( !$permCheck->isOK() ) { |
| 327 |
return Status::wrap( $permCheck ); |
| 328 |
} |
| 329 |
|
| 330 |
$this->dbw->startAtomic( __METHOD__ ); |
| 331 |
|
| 332 |
$this->dbw->newUpdateQueryBuilder() |
| 333 |
->update( 'revision' ) |
| 334 |
->set( [ 'rev_page' => $this->dest->getId() ] ) |
| 335 |
->where( [ 'rev_page' => $this->source->getId(), $this->getTimeWhere() ] ) |
| 336 |
->caller( __METHOD__ )->execute(); |
| 337 |
|
| 338 |
|
| 339 |
$this->revisionsMerged = $this->dbw->affectedRows(); |
| 340 |
if ( $this->revisionsMerged < 1 ) { |
| 341 |
$this->dbw->endAtomic( __METHOD__ ); |
| 342 |
return $status->fatal( 'mergehistory-fail-no-change' ); |
| 343 |
} |
| 344 |
|
| 345 |
$haveRevisions = $this->dbw->newSelectQueryBuilder() |
| 346 |
->from( 'revision' ) |
| 347 |
->where( [ 'rev_page' => $this->source->getId() ] ) |
| 348 |
->forUpdate() |
| 349 |
->caller( __METHOD__ ) |
| 350 |
->fetchRowCount(); |
| 351 |
|
| 352 |
$legacySource = $this->titleFactory->newFromPageIdentity( $this->source ); |
| 353 |
$legacyDest = $this->titleFactory->newFromPageIdentity( $this->dest ); |
| 354 |
|
| 355 |
|
| 356 |
if ( !$haveRevisions ) { |
| 357 |
if ( $reason ) { |
| 358 |
$revisionComment = wfMessage( |
| 359 |
'mergehistory-comment', |
| 360 |
$this->titleFormatter->getPrefixedText( $this->source ), |
| 361 |
$this->titleFormatter->getPrefixedText( $this->dest ), |
| 362 |
$reason |
| 363 |
)->inContentLanguage()->text(); |
| 364 |
} else { |
| 365 |
$revisionComment = wfMessage( |
| 366 |
'mergehistory-autocomment', |
| 367 |
$this->titleFormatter->getPrefixedText( $this->source ), |
| 368 |
$this->titleFormatter->getPrefixedText( $this->dest ) |
| 369 |
)->inContentLanguage()->text(); |
| 370 |
} |
| 371 |
|
| 372 |
$this->updateSourcePage( $status, $performer, $revisionComment ); |
| 373 |
|
| 374 |
} else { |
| 375 |
$legacySource->invalidateCache(); |
| 376 |
} |
| 377 |
$legacyDest->invalidateCache(); |
| 378 |
|
| 379 |
|
| 380 |
$this->watchedItemStore->duplicateAllAssociatedEntries( $this->source, $this->dest ); |
| 381 |
|
| 382 |
|
| 383 |
$logEntry = new ManualLogEntry( 'merge', 'merge' ); |
| 384 |
$logEntry->setPerformer( $performer->getUser() ); |
| 385 |
$logEntry->setComment( $reason ); |
| 386 |
$logEntry->setTarget( $this->source ); |
| 387 |
$logEntry->setParameters( [ |
| 388 |
'4::dest' => $this->titleFormatter->getPrefixedText( $this->dest ), |
| 389 |
'5::mergepoint' => $this->getTimestampLimit()->getTimestamp( TS_MW ), |
| 390 |
'6::mergerevid' => $this->revidLimit |
| 391 |
] ); |
| 392 |
$logId = $logEntry->insert(); |
| 393 |
$logEntry->publish( $logId ); |
| 394 |
|
| 395 |
$this->hookRunner->onArticleMergeComplete( $legacySource, $legacyDest ); |
| 396 |
|
| 397 |
$this->dbw->endAtomic( __METHOD__ ); |
| 398 |
|
| 399 |
return $status; |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
private function updateSourcePage( $status, $performer, $revisionComment ): void { |
| 415 |
$deleteSource = false; |
| 416 |
$legacySourceTitle = $this->titleFactory->newFromPageIdentity( $this->source ); |
| 417 |
$legacyDestTitle = $this->titleFactory->newFromPageIdentity( $this->dest ); |
| 418 |
$sourceModel = $legacySourceTitle->getContentModel(); |
| 419 |
$contentHandler = $this->contentHandlerFactory->getContentHandler( $sourceModel ); |
| 420 |
|
| 421 |
if ( !$contentHandler->supportsRedirects() || ( |
| 422 |
|
| 423 |
|
| 424 |
$legacySourceTitle->getNamespace() === NS_MEDIAWIKI && |
| 425 |
$legacySourceTitle->getContentModel() === CONTENT_MODEL_WIKITEXT |
| 426 |
) ) { |
| 427 |
$deleteSource = true; |
| 428 |
$newContent = $contentHandler->makeEmptyContent(); |
| 429 |
} else { |
| 430 |
$msg = wfMessage( 'mergehistory-redirect-text' )->inContentLanguage()->plain(); |
| 431 |
$newContent = $contentHandler->makeRedirectContent( $legacyDestTitle, $msg ); |
| 432 |
} |
| 433 |
|
| 434 |
if ( !$newContent instanceof Content ) { |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
$logger = MediaWiki\Logger\LoggerFactory::getInstance( 'ContentHandler' ); |
| 444 |
$logger->warning( |
| 445 |
'ContentHandler for {model} says it supports redirects but failed ' |
| 446 |
. 'to return Content object from ContentHandler::makeRedirectContent().' |
| 447 |
. ' {value} returned instead.', |
| 448 |
[ |
| 449 |
'value' => get_debug_type( $newContent ), |
| 450 |
'model' => $sourceModel |
| 451 |
] |
| 452 |
); |
| 453 |
|
| 454 |
throw new InvalidArgumentException( |
| 455 |
"ContentHandler for '$sourceModel' supports redirects" . |
| 456 |
' but cannot create redirect content during History merge.' |
| 457 |
); |
| 458 |
} |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
$comment = CommentStoreComment::newUnsavedComment( $revisionComment ); |
| 466 |
$revRecord = new MutableRevisionRecord( $this->source ); |
| 467 |
$revRecord->setContent( SlotRecord::MAIN, $newContent ) |
| 468 |
->setPageId( $this->source->getId() ) |
| 469 |
->setComment( $comment ) |
| 470 |
->setUser( $performer->getUser() ) |
| 471 |
->setTimestamp( wfTimestampNow() ); |
| 472 |
|
| 473 |
$insertedRevRecord = $this->revisionStore->insertRevisionOn( $revRecord, $this->dbw ); |
| 474 |
|
| 475 |
$newPage = $this->wikiPageFactory->newFromTitle( $this->source ); |
| 476 |
$newPage->updateRevisionOn( $this->dbw, $insertedRevRecord ); |
| 477 |
|
| 478 |
if ( !$deleteSource ) { |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
$this->dbw->newDeleteQueryBuilder() |
| 484 |
->deleteFrom( 'pagelinks' ) |
| 485 |
->where( [ 'pl_from' => $this->source->getId() ] ) |
| 486 |
->caller( __METHOD__ )->execute(); |
| 487 |
$migrationStage = MediaWikiServices::getInstance()->getMainConfig()->get( |
| 488 |
MainConfigNames::PageLinksSchemaMigrationStage |
| 489 |
); |
| 490 |
$row = [ |
| 491 |
'pl_from' => $this->source->getId(), |
| 492 |
'pl_from_namespace' => $this->source->getNamespace(), |
| 493 |
]; |
| 494 |
if ( $migrationStage & SCHEMA_COMPAT_WRITE_OLD ) { |
| 495 |
$row['pl_namespace'] = $this->dest->getNamespace(); |
| 496 |
$row['pl_title'] = $this->dest->getDBkey(); |
| 497 |
} |
| 498 |
if ( $migrationStage & SCHEMA_COMPAT_WRITE_NEW ) { |
| 499 |
$row['pl_target_id'] = $this->linkTargetLookup->acquireLinkTargetId( |
| 500 |
new TitleValue( $this->dest->getNamespace(), $this->dest->getDBkey() ), |
| 501 |
$this->dbw |
| 502 |
); |
| 503 |
} |
| 504 |
$this->dbw->newInsertQueryBuilder() |
| 505 |
->insertInto( 'pagelinks' ) |
| 506 |
->row( $row ) |
| 507 |
->caller( __METHOD__ )->execute(); |
| 508 |
|
| 509 |
} else { |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
$reason = wfMessage( 'mergehistory-source-deleted-reason' )->inContentLanguage()->plain(); |
| 516 |
$delPage = $this->deletePageFactory->newDeletePage( $newPage, $performer ); |
| 517 |
$deletionStatus = $delPage->deleteUnsafe( $reason ); |
| 518 |
if ( $deletionStatus->isGood() && $delPage->deletionsWereScheduled()[DeletePage::PAGE_BASE] ) { |
| 519 |
$deletionStatus->warning( |
| 520 |
'delete-scheduled', |
| 521 |
wfEscapeWikiText( $newPage->getTitle()->getPrefixedText() ) |
| 522 |
); |
| 523 |
} |
| 524 |
|
| 525 |
$status->value = 'source-deleted'; |
| 526 |
$status->merge( $deletionStatus ); |
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
private function getMaxTimestamp(): MWTimestamp { |
| 536 |
if ( $this->maxTimestamp === false ) { |
| 537 |
$this->initTimestampLimits(); |
| 538 |
} |
| 539 |
return $this->maxTimestamp; |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
private function getTimestampLimit(): ?MWTimestamp { |
| 549 |
if ( $this->timestampLimit === false ) { |
| 550 |
$this->initTimestampLimits(); |
| 551 |
} |
| 552 |
return $this->timestampLimit; |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
private function getTimeWhere(): ?string { |
| 562 |
if ( $this->timeWhere === false ) { |
| 563 |
$this->initTimestampLimits(); |
| 564 |
} |
| 565 |
return $this->timeWhere; |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
private function initTimestampLimits() { |
| 572 |
|
| 573 |
$firstDestTimestamp = $this->dbw->newSelectQueryBuilder() |
| 574 |
->select( 'MIN(rev_timestamp)' ) |
| 575 |
->from( 'revision' ) |
| 576 |
->where( [ 'rev_page' => $this->dest->getId() ] ) |
| 577 |
->caller( __METHOD__ )->fetchField(); |
| 578 |
$this->maxTimestamp = new MWTimestamp( $firstDestTimestamp ); |
| 579 |
$this->revidLimit = null; |
| 580 |
|
| 581 |
try { |
| 582 |
if ( $this->timestamp ) { |
| 583 |
$parts = explode( '|', $this->timestamp ); |
| 584 |
if ( count( $parts ) == 2 ) { |
| 585 |
$timestamp = $parts[0]; |
| 586 |
$this->revidLimit = $parts[1]; |
| 587 |
} else { |
| 588 |
$timestamp = $this->timestamp; |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
$mwTimestamp = new MWTimestamp( $timestamp ); |
| 593 |
|
| 594 |
$lastWorkingTimestamp = $this->dbw->newSelectQueryBuilder() |
| 595 |
->select( 'MAX(rev_timestamp)' ) |
| 596 |
->from( 'revision' ) |
| 597 |
->where( [ |
| 598 |
$this->dbw->expr( 'rev_timestamp', '<=', $this->dbw->timestamp( $mwTimestamp ) ), |
| 599 |
'rev_page' => $this->source->getId() |
| 600 |
] ) |
| 601 |
->caller( __METHOD__ )->fetchField(); |
| 602 |
$mwLastWorkingTimestamp = new MWTimestamp( $lastWorkingTimestamp ); |
| 603 |
|
| 604 |
$timeInsert = $mwLastWorkingTimestamp; |
| 605 |
$this->timestampLimit = $mwLastWorkingTimestamp; |
| 606 |
} else { |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
$row = $this->dbw->newSelectQueryBuilder() |
| 612 |
->select( [ 'rev_timestamp', 'rev_id' ] ) |
| 613 |
->from( 'page' ) |
| 614 |
->join( 'revision', null, 'page_latest = rev_id' ) |
| 615 |
->where( [ 'page_id' => $this->source->getId() ] ) |
| 616 |
->caller( __METHOD__ )->fetchRow(); |
| 617 |
$timeInsert = $this->maxTimestamp; |
| 618 |
if ( $row ) { |
| 619 |
$lasttimestamp = new MWTimestamp( $row->rev_timestamp ); |
| 620 |
$this->timestampLimit = $lasttimestamp; |
| 621 |
$this->revidLimit = $row->rev_id; |
| 622 |
} else { |
| 623 |
$this->timestampLimit = null; |
| 624 |
} |
| 625 |
} |
| 626 |
$dbLimit = $this->dbw->timestamp( $timeInsert ); |
| 627 |
if ( $this->revidLimit ) { |
| 628 |
$this->timeWhere = $this->dbw->buildComparison( '<=', |
| 629 |
[ 'rev_timestamp' => $dbLimit, 'rev_id' => $this->revidLimit ] |
| 630 |
); |
| 631 |
} else { |
| 632 |
$this->timeWhere = $this->dbw->buildComparison( '<=', |
| 633 |
[ 'rev_timestamp' => $dbLimit ] |
| 634 |
); |
| 635 |
} |
| 636 |
} catch ( TimestampException $ex ) { |
| 637 |
|
| 638 |
|
| 639 |
$this->timestampLimit = null; |
| 640 |
$this->timeWhere = null; |
| 641 |
} |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
class_alias( MergeHistory::class, 'MergeHistory' ); |