219 $updater = $this->wikiPageFactory->newFromTitle( $this->page )->newPageUpdater( $this->performer );
220 $currentRevision = $updater->grabParentRevision();
222 if ( !$currentRevision ) {
224 return StatusValue::newFatal(
'notanarticle' );
227 $currentEditor = $currentRevision->getUser( RevisionRecord::RAW );
228 $currentEditorForPublic = $currentRevision->getUser( RevisionRecord::FOR_PUBLIC );
230 if ( !$this->byUser->equals( $currentEditor ) ) {
231 $result = StatusValue::newGood( [
232 'current-revision-record' => $currentRevision
236 htmlspecialchars( $this->titleFormatter->getPrefixedText( $this->page ) ),
237 htmlspecialchars( $this->byUser->getName() ),
238 htmlspecialchars( $currentEditorForPublic ? $currentEditorForPublic->getName() :
'' )
243 $dbw = $this->dbProvider->getPrimaryDatabase();
247 $actorWhere = $this->actorMigration->getWhere( $dbw,
'rev_user', $currentEditor );
249 ->where( [
'rev_page' => $currentRevision->getPageId(),
'NOT(' . $actorWhere[
'conds'] .
')' ] )
250 ->useIndex( [
'revision' =>
'rev_page_timestamp' ] )
251 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_DESC );
252 $targetRevisionRow = $queryBuilder->caller( __METHOD__ )->fetchRow();
254 if ( $targetRevisionRow ===
false ) {
256 return StatusValue::newFatal(
'cantrollback' );
257 } elseif ( $targetRevisionRow->rev_deleted & RevisionRecord::DELETED_TEXT
258 || $targetRevisionRow->rev_deleted & RevisionRecord::DELETED_USER
261 return StatusValue::newFatal(
'notvisiblerev' );
265 $targetRevision = $this->revisionStore
266 ->getRevisionById( $targetRevisionRow->rev_id, IDBAccessObject::READ_LATEST );
271 if ( $this->performer->isAllowed(
'minoredit' ) ) {
280 $currentContent = $currentRevision->getContent( SlotRecord::MAIN );
281 $targetContent = $targetRevision->getContent( SlotRecord::MAIN );
282 $changingContentModel = $targetContent->getModel() !== $currentContent->getModel();
287 foreach ( $targetRevision->getSlots()->getSlots() as $slot ) {
288 $updater->inheritSlot( $slot );
293 foreach ( $currentRevision->getSlotRoles() as $role ) {
294 if ( !$targetRevision->hasSlot( $role ) ) {
295 $updater->removeSlot( $role );
299 $updater->markAsRevert(
300 EditResult::REVERT_ROLLBACK,
301 $currentRevision->getId(),
302 $targetRevision->getId()
308 if ( $this->options->get( MainConfigNames::UseRCPatrol ) &&
309 $this->performer->authorizeWrite(
'autopatrol', $this->page )
311 $updater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED );
314 $summary = $this->getSummary( $currentRevision, $targetRevision );
317 $rev = $updater->addTags( $this->tags )->saveRevision(
318 CommentStoreComment::newUnsavedComment( $summary ),
323 $this->updateRecentChange( $dbw, $currentRevision, $targetRevision );
325 if ( !$updater->wasSuccessful() ) {
326 return $updater->getStatus();
330 if ( !$updater->wasRevisionCreated() ) {
331 $result = StatusValue::newGood( [
332 'current-revision-record' => $currentRevision
336 htmlspecialchars( $this->titleFormatter->getPrefixedText( $this->page ) ),
337 htmlspecialchars( $this->byUser->getName() ),
338 htmlspecialchars( $currentEditorForPublic ? $currentEditorForPublic->getName() :
'' )
343 if ( $changingContentModel ) {
347 $log->setPerformer( $this->performer->getUser() );
348 $log->setTarget(
new TitleValue( $this->page->getNamespace(), $this->page->getDBkey() ) );
349 $log->setComment( $summary );
350 $log->setParameters( [
351 '4::oldmodel' => $currentContent->getModel(),
352 '5::newmodel' => $targetContent->getModel(),
355 $logId = $log->insert( $dbw );
356 $log->publish( $logId );
359 $wikiPage = $this->wikiPageFactory->newFromTitle( $this->page );
361 $this->hookRunner->onRollbackComplete(
363 $this->performer->getUser(),
368 return StatusValue::newGood( [
369 'summary' => $summary,
370 'current-revision-record' => $currentRevision,
371 'target-revision-record' => $targetRevision,
372 'newid' => $rev->getId(),
373 'tags' => array_merge( $this->tags, $updater->getEditResult()->getRevertTags() )