220 $updater = $this->wikiPageFactory->newFromTitle( $this->page )->newPageUpdater( $this->performer );
221 $currentRevision = $updater->grabParentRevision();
223 if ( !$currentRevision ) {
225 return StatusValue::newFatal(
'notanarticle' );
228 $currentEditor = $currentRevision->getUser( RevisionRecord::RAW );
229 $currentEditorForPublic = $currentRevision->getUser( RevisionRecord::FOR_PUBLIC );
231 if ( !$this->byUser->equals( $currentEditor ) ) {
232 $result = StatusValue::newGood( [
233 'current-revision-record' => $currentRevision
237 htmlspecialchars( $this->titleFormatter->getPrefixedText( $this->page ) ),
238 htmlspecialchars( $this->byUser->getName() ),
239 htmlspecialchars( $currentEditorForPublic ? $currentEditorForPublic->getName() :
'' )
244 $dbw = $this->dbProvider->getPrimaryDatabase();
248 $actorWhere = $this->actorMigration->getWhere( $dbw,
'rev_user', $currentEditor );
250 ->where( [
'rev_page' => $currentRevision->getPageId(),
'NOT(' . $actorWhere[
'conds'] .
')' ] )
251 ->useIndex( [
'revision' =>
'rev_page_timestamp' ] )
252 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_DESC );
253 $targetRevisionRow = $queryBuilder->caller( __METHOD__ )->fetchRow();
255 if ( $targetRevisionRow ===
false ) {
257 return StatusValue::newFatal(
'cantrollback' );
258 } elseif ( $targetRevisionRow->rev_deleted & RevisionRecord::DELETED_TEXT
259 || $targetRevisionRow->rev_deleted & RevisionRecord::DELETED_USER
262 return StatusValue::newFatal(
'notvisiblerev' );
266 $targetRevision = $this->revisionStore
267 ->getRevisionById( $targetRevisionRow->rev_id, IDBAccessObject::READ_LATEST );
272 if ( $this->performer->isAllowed(
'minoredit' ) ) {
281 $currentContent = $currentRevision->getContent( SlotRecord::MAIN );
282 $targetContent = $targetRevision->getContent( SlotRecord::MAIN );
283 $changingContentModel = $targetContent->getModel() !== $currentContent->getModel();
288 foreach ( $targetRevision->getSlots()->getSlots() as $slot ) {
289 $updater->inheritSlot( $slot );
294 foreach ( $currentRevision->getSlotRoles() as $role ) {
295 if ( !$targetRevision->hasSlot( $role ) ) {
296 $updater->removeSlot( $role );
300 $updater->markAsRevert(
301 EditResult::REVERT_ROLLBACK,
302 $currentRevision->getId(),
303 $targetRevision->getId()
309 if ( $this->options->get( MainConfigNames::UseRCPatrol ) &&
310 $this->performer->authorizeWrite(
'autopatrol', $this->page )
312 $updater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED );
315 $summary = $this->getSummary( $currentRevision, $targetRevision );
318 $rev = $updater->addTags( $this->tags )->saveRevision(
319 CommentStoreComment::newUnsavedComment( $summary ),
324 $this->updateRecentChange( $dbw, $currentRevision, $targetRevision );
326 if ( !$updater->wasSuccessful() ) {
327 return $updater->getStatus();
331 if ( !$updater->wasRevisionCreated() ) {
332 $result = StatusValue::newGood( [
333 'current-revision-record' => $currentRevision
337 htmlspecialchars( $this->titleFormatter->getPrefixedText( $this->page ) ),
338 htmlspecialchars( $this->byUser->getName() ),
339 htmlspecialchars( $currentEditorForPublic ? $currentEditorForPublic->getName() :
'' )
344 if ( $changingContentModel ) {
348 $log->setPerformer( $this->performer->getUser() );
349 $log->setTarget(
new TitleValue( $this->page->getNamespace(), $this->page->getDBkey() ) );
350 $log->setComment( $summary );
351 $log->setParameters( [
352 '4::oldmodel' => $currentContent->getModel(),
353 '5::newmodel' => $targetContent->getModel(),
356 $logId = $log->insert( $dbw );
357 $log->publish( $logId );
360 $wikiPage = $this->wikiPageFactory->newFromTitle( $this->page );
362 $this->hookRunner->onRollbackComplete(
364 $this->performer->getUser(),
369 return StatusValue::newGood( [
370 'summary' => $summary,
371 'current-revision-record' => $currentRevision,
372 'target-revision-record' => $targetRevision,
373 'newid' => $rev->getId(),
374 'tags' => array_merge( $this->tags, $updater->getEditResult()->getRevertTags() )