200 $updater = $this->wikiPageFactory->newFromTitle( $this->page )->newPageUpdater( $this->performer );
201 $currentRevision = $updater->grabParentRevision();
203 if ( !$currentRevision ) {
205 return StatusValue::newFatal(
'notanarticle' );
208 $currentEditor = $currentRevision->getUser( RevisionRecord::RAW );
209 $currentEditorForPublic = $currentRevision->getUser( RevisionRecord::FOR_PUBLIC );
211 if ( !$this->byUser->equals( $currentEditor ) ) {
212 $result = StatusValue::newGood( [
213 'current-revision-record' => $currentRevision
217 htmlspecialchars( $this->titleFormatter->getPrefixedText( $this->page ) ),
218 htmlspecialchars( $this->byUser->getName() ),
219 htmlspecialchars( $currentEditorForPublic ? $currentEditorForPublic->getName() :
'' )
224 $dbw = $this->dbProvider->getPrimaryDatabase();
228 $actorWhere = $this->actorMigration->getWhere( $dbw,
'rev_user', $currentEditor );
230 ->where( [
'rev_page' => $currentRevision->getPageId(),
'NOT(' . $actorWhere[
'conds'] .
')' ] )
231 ->useIndex( [
'revision' =>
'rev_page_timestamp' ] )
232 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_DESC );
233 $targetRevisionRow = $queryBuilder->caller( __METHOD__ )->fetchRow();
235 if ( $targetRevisionRow ===
false ) {
237 return StatusValue::newFatal(
'cantrollback' );
238 } elseif ( $targetRevisionRow->rev_deleted & RevisionRecord::DELETED_TEXT
239 || $targetRevisionRow->rev_deleted & RevisionRecord::DELETED_USER
242 return StatusValue::newFatal(
'notvisiblerev' );
246 $targetRevision = $this->revisionStore
247 ->getRevisionById( $targetRevisionRow->rev_id, IDBAccessObject::READ_LATEST );
252 if ( $this->performer->isAllowed(
'minoredit' ) ) {
261 $currentContent = $currentRevision->getContent( SlotRecord::MAIN );
262 $targetContent = $targetRevision->getContent( SlotRecord::MAIN );
263 $changingContentModel = $targetContent->getModel() !== $currentContent->getModel();
268 foreach ( $targetRevision->getSlots()->getSlots() as $slot ) {
269 $updater->inheritSlot( $slot );
274 foreach ( $currentRevision->getSlotRoles() as $role ) {
275 if ( !$targetRevision->hasSlot( $role ) ) {
276 $updater->removeSlot( $role );
280 $updater->setCause( PageUpdateCauses::CAUSE_ROLLBACK );
281 $updater->markAsRevert(
282 EditResult::REVERT_ROLLBACK,
283 $currentRevision->getId(),
284 $targetRevision->getId()
290 if ( $this->options->get( MainConfigNames::UseRCPatrol ) &&
291 $this->performer->authorizeWrite(
'autopatrol', $this->page )
293 $updater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED );
296 $summary = $this->getSummary( $currentRevision, $targetRevision );
299 $rev = $updater->addTags( $this->tags )->saveRevision(
300 CommentStoreComment::newUnsavedComment( $summary ),
305 $this->updateRecentChange( $dbw, $currentRevision, $targetRevision );
307 if ( !$updater->wasSuccessful() ) {
308 return $updater->getStatus();
312 if ( !$updater->wasRevisionCreated() ) {
313 $result = StatusValue::newGood( [
314 'current-revision-record' => $currentRevision
318 htmlspecialchars( $this->titleFormatter->getPrefixedText( $this->page ) ),
319 htmlspecialchars( $this->byUser->getName() ),
320 htmlspecialchars( $currentEditorForPublic ? $currentEditorForPublic->getName() :
'' )
325 if ( $changingContentModel ) {
329 $log->setPerformer( $this->performer->getUser() );
330 $log->setTarget(
new TitleValue( $this->page->getNamespace(), $this->page->getDBkey() ) );
331 $log->setComment( $summary );
332 $log->setParameters( [
333 '4::oldmodel' => $currentContent->getModel(),
334 '5::newmodel' => $targetContent->getModel(),
337 $logId = $log->insert( $dbw );
338 $log->publish( $logId );
341 $wikiPage = $this->wikiPageFactory->newFromTitle( $this->page );
343 $this->hookRunner->onRollbackComplete(
345 $this->performer->getUser(),
350 return StatusValue::newGood( [
351 'summary' => $summary,
352 'current-revision-record' => $currentRevision,
353 'target-revision-record' => $targetRevision,
354 'newid' => $rev->getId(),
355 'tags' => array_merge( $this->tags, $updater->getEditResult()->getRevertTags() )