213 $updater = $this->wikiPageFactory->newFromTitle( $this->page )->newPageUpdater( $this->performer );
214 $currentRevision = $updater->grabParentRevision();
216 if ( !$currentRevision ) {
218 return StatusValue::newFatal(
'notanarticle' );
221 $currentEditor = $currentRevision->getUser( RevisionRecord::RAW );
222 $currentEditorForPublic = $currentRevision->getUser( RevisionRecord::FOR_PUBLIC );
224 if ( !$this->byUser->equals( $currentEditor ) ) {
225 $result = StatusValue::newGood( [
226 'current-revision-record' => $currentRevision
230 htmlspecialchars( $this->titleFormatter->getPrefixedText( $this->page ) ),
231 htmlspecialchars( $this->byUser->getName() ),
232 htmlspecialchars( $currentEditorForPublic ? $currentEditorForPublic->getName() :
'' )
237 $dbw = $this->dbProvider->getPrimaryDatabase();
241 $actorWhere = $this->actorMigration->getWhere( $dbw,
'rev_user', $currentEditor );
243 ->where( [
'rev_page' => $currentRevision->getPageId(),
'NOT(' . $actorWhere[
'conds'] .
')' ] )
244 ->useIndex( [
'revision' =>
'rev_page_timestamp' ] )
245 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_DESC );
246 $targetRevisionRow = $queryBuilder->caller( __METHOD__ )->fetchRow();
248 if ( $targetRevisionRow ===
false ) {
250 return StatusValue::newFatal(
'cantrollback' );
251 } elseif ( $targetRevisionRow->rev_deleted & RevisionRecord::DELETED_TEXT
252 || $targetRevisionRow->rev_deleted & RevisionRecord::DELETED_USER
255 return StatusValue::newFatal(
'notvisiblerev' );
259 $targetRevision = $this->revisionStore
260 ->getRevisionById( $targetRevisionRow->rev_id, IDBAccessObject::READ_LATEST );
265 if ( $this->performer->isAllowed(
'minoredit' ) ) {
274 $currentContent = $currentRevision->getContent( SlotRecord::MAIN );
275 $targetContent = $targetRevision->getContent( SlotRecord::MAIN );
276 $changingContentModel = $targetContent->getModel() !== $currentContent->getModel();
281 foreach ( $targetRevision->getSlots()->getSlots() as $slot ) {
282 $updater->inheritSlot( $slot );
287 foreach ( $currentRevision->getSlotRoles() as $role ) {
288 if ( !$targetRevision->hasSlot( $role ) ) {
289 $updater->removeSlot( $role );
293 $updater->markAsRevert(
294 EditResult::REVERT_ROLLBACK,
295 $currentRevision->getId(),
296 $targetRevision->getId()
302 if ( $this->options->get( MainConfigNames::UseRCPatrol ) &&
303 $this->performer->authorizeWrite(
'autopatrol', $this->page )
305 $updater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED );
308 $summary = $this->getSummary( $currentRevision, $targetRevision );
311 $rev = $updater->addTags( $this->tags )->saveRevision(
312 CommentStoreComment::newUnsavedComment( $summary ),
317 $this->updateRecentChange( $dbw, $currentRevision, $targetRevision );
319 if ( !$updater->wasSuccessful() ) {
320 return $updater->getStatus();
324 if ( !$updater->wasRevisionCreated() ) {
325 $result = StatusValue::newGood( [
326 'current-revision-record' => $currentRevision
330 htmlspecialchars( $this->titleFormatter->getPrefixedText( $this->page ) ),
331 htmlspecialchars( $this->byUser->getName() ),
332 htmlspecialchars( $currentEditorForPublic ? $currentEditorForPublic->getName() :
'' )
337 if ( $changingContentModel ) {
341 $log->setPerformer( $this->performer->getUser() );
342 $log->setTarget(
new TitleValue( $this->page->getNamespace(), $this->page->getDBkey() ) );
343 $log->setComment( $summary );
344 $log->setParameters( [
345 '4::oldmodel' => $currentContent->getModel(),
346 '5::newmodel' => $targetContent->getModel(),
349 $logId = $log->insert( $dbw );
350 $log->publish( $logId );
353 $wikiPage = $this->wikiPageFactory->newFromTitle( $this->page );
355 $this->hookRunner->onRollbackComplete(
357 $this->performer->getUser(),
362 return StatusValue::newGood( [
363 'summary' => $summary,
364 'current-revision-record' => $currentRevision,
365 'target-revision-record' => $targetRevision,
366 'newid' => $rev->getId(),
367 'tags' => array_merge( $this->tags, $updater->getEditResult()->getRevertTags() )