257 $updater = $this->wikiPageFactory->newFromTitle( $this->page )->newPageUpdater( $this->performer );
258 $currentRevision = $updater->grabParentRevision();
260 if ( !$currentRevision ) {
262 return StatusValue::newFatal(
'notanarticle' );
265 $currentEditor = $currentRevision->getUser( RevisionRecord::RAW );
266 $currentEditorForPublic = $currentRevision->getUser( RevisionRecord::FOR_PUBLIC );
268 if ( !$this->byUser->equals( $currentEditor ) ) {
269 $result = StatusValue::newGood( [
270 'current-revision-record' => $currentRevision
274 htmlspecialchars( $this->titleFormatter->getPrefixedText( $this->page ) ),
275 htmlspecialchars( $this->byUser->getName() ),
276 htmlspecialchars( $currentEditorForPublic ? $currentEditorForPublic->getName() :
'' )
281 $dbw = $this->dbProvider->getPrimaryDatabase();
285 $actorWhere = $this->actorMigration->getWhere( $dbw,
'rev_user', $currentEditor );
287 ->where( [
'rev_page' => $currentRevision->getPageId(),
'NOT(' . $actorWhere[
'conds'] .
')' ] )
288 ->useIndex( [
'revision' =>
'rev_page_timestamp' ] )
289 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_DESC );
290 $targetRevisionRow = $queryBuilder->caller( __METHOD__ )->fetchRow();
292 if ( $targetRevisionRow ===
false ) {
294 return StatusValue::newFatal(
'cantrollback' );
295 } elseif ( $targetRevisionRow->rev_deleted & RevisionRecord::DELETED_TEXT
296 || $targetRevisionRow->rev_deleted & RevisionRecord::DELETED_USER
299 return StatusValue::newFatal(
'notvisiblerev' );
303 $targetRevision = $this->revisionStore
304 ->getRevisionById( $targetRevisionRow->rev_id, IDBAccessObject::READ_LATEST );
309 if ( $this->performer->isAllowed(
'minoredit' ) ) {
318 $currentContent = $currentRevision->getContent( SlotRecord::MAIN );
319 $targetContent = $targetRevision->getContent( SlotRecord::MAIN );
320 $changingContentModel = $targetContent->getModel() !== $currentContent->getModel();
325 foreach ( $targetRevision->getSlots()->getSlots() as $slot ) {
326 $updater->inheritSlot( $slot );
331 foreach ( $currentRevision->getSlotRoles() as $role ) {
332 if ( !$targetRevision->hasSlot( $role ) ) {
333 $updater->removeSlot( $role );
337 $updater->markAsRevert(
338 EditResult::REVERT_ROLLBACK,
339 $currentRevision->getId(),
340 $targetRevision->getId()
346 if ( $this->options->get( MainConfigNames::UseRCPatrol ) &&
347 $this->performer->authorizeWrite(
'autopatrol', $this->page )
349 $updater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED );
352 $summary = $this->getSummary( $currentRevision, $targetRevision );
355 $rev = $updater->addTags( $this->tags )->saveRevision(
356 CommentStoreComment::newUnsavedComment( $summary ),
361 $this->updateRecentChange( $dbw, $currentRevision, $targetRevision );
363 if ( !$updater->wasSuccessful() ) {
364 return $updater->getStatus();
368 if ( !$updater->wasRevisionCreated() ) {
369 $result = StatusValue::newGood( [
370 'current-revision-record' => $currentRevision
374 htmlspecialchars( $this->titleFormatter->getPrefixedText( $this->page ) ),
375 htmlspecialchars( $this->byUser->getName() ),
376 htmlspecialchars( $currentEditorForPublic ? $currentEditorForPublic->getName() :
'' )
381 if ( $changingContentModel ) {
385 $log->setPerformer( $this->performer->getUser() );
386 $log->setTarget(
new TitleValue( $this->page->getNamespace(), $this->page->getDBkey() ) );
387 $log->setComment( $summary );
388 $log->setParameters( [
389 '4::oldmodel' => $currentContent->getModel(),
390 '5::newmodel' => $targetContent->getModel(),
393 $logId = $log->insert( $dbw );
394 $log->publish( $logId );
397 $wikiPage = $this->wikiPageFactory->newFromTitle( $this->page );
399 $this->hookRunner->onRollbackComplete(
401 $this->performer->getUser(),
406 return StatusValue::newGood( [
407 'summary' => $summary,
408 'current-revision-record' => $currentRevision,
409 'target-revision-record' => $targetRevision,
410 'newid' => $rev->getId(),
411 'tags' => array_merge( $this->tags, $updater->getEditResult()->getRevertTags() )