| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Page; |
| 22 |
|
| 23 |
use ChangeTags; |
| 24 |
use HTMLCacheUpdateJob; |
| 25 |
use JobQueueGroup; |
| 26 |
use LocalFile; |
| 27 |
use ManualLogEntry; |
| 28 |
use MediaWiki\Content\IContentHandlerFactory; |
| 29 |
use MediaWiki\Content\ValidationParams; |
| 30 |
use MediaWiki\HookContainer\HookContainer; |
| 31 |
use MediaWiki\HookContainer\HookRunner; |
| 32 |
use MediaWiki\Permissions\Authority; |
| 33 |
use MediaWiki\Permissions\PermissionStatus; |
| 34 |
use MediaWiki\Revision\ArchivedRevisionLookup; |
| 35 |
use MediaWiki\Revision\RevisionRecord; |
| 36 |
use MediaWiki\Revision\RevisionStore; |
| 37 |
use MediaWiki\Status\Status; |
| 38 |
use MediaWiki\Storage\PageUpdaterFactory; |
| 39 |
use MediaWiki\Title\NamespaceInfo; |
| 40 |
use Psr\Log\LoggerInterface; |
| 41 |
use ReadOnlyError; |
| 42 |
use RepoGroup; |
| 43 |
use StatusValue; |
| 44 |
use Wikimedia\Message\ITextFormatter; |
| 45 |
use Wikimedia\Message\MessageValue; |
| 46 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 47 |
use Wikimedia\Rdbms\IDatabase; |
| 48 |
use Wikimedia\Rdbms\IDBAccessObject; |
| 49 |
use Wikimedia\Rdbms\ReadOnlyMode; |
| 50 |
use WikiPage; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
class UndeletePage { |
| 58 |
|
| 59 |
|
| 60 |
public const FILES_RESTORED = 'files'; |
| 61 |
public const REVISIONS_RESTORED = 'revs'; |
| 62 |
|
| 63 |
|
| 64 |
private $fileStatus; |
| 65 |
|
| 66 |
private $revisionStatus; |
| 67 |
|
| 68 |
private $timestamps = []; |
| 69 |
|
| 70 |
private $fileVersions = []; |
| 71 |
|
| 72 |
private $unsuppress = false; |
| 73 |
|
| 74 |
private $tags = []; |
| 75 |
|
| 76 |
private $associatedTalk; |
| 77 |
|
| 78 |
private HookRunner $hookRunner; |
| 79 |
private JobQueueGroup $jobQueueGroup; |
| 80 |
private IConnectionProvider $dbProvider; |
| 81 |
private ReadOnlyMode $readOnlyMode; |
| 82 |
private RepoGroup $repoGroup; |
| 83 |
private LoggerInterface $logger; |
| 84 |
private RevisionStore $revisionStore; |
| 85 |
private WikiPageFactory $wikiPageFactory; |
| 86 |
private PageUpdaterFactory $pageUpdaterFactory; |
| 87 |
private IContentHandlerFactory $contentHandlerFactory; |
| 88 |
private ArchivedRevisionLookup $archivedRevisionLookup; |
| 89 |
private NamespaceInfo $namespaceInfo; |
| 90 |
private ITextFormatter $contLangMsgTextFormatter; |
| 91 |
private ProperPageIdentity $page; |
| 92 |
private Authority $performer; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public function __construct( |
| 98 |
HookContainer $hookContainer, |
| 99 |
JobQueueGroup $jobQueueGroup, |
| 100 |
IConnectionProvider $dbProvider, |
| 101 |
ReadOnlyMode $readOnlyMode, |
| 102 |
RepoGroup $repoGroup, |
| 103 |
LoggerInterface $logger, |
| 104 |
RevisionStore $revisionStore, |
| 105 |
WikiPageFactory $wikiPageFactory, |
| 106 |
PageUpdaterFactory $pageUpdaterFactory, |
| 107 |
IContentHandlerFactory $contentHandlerFactory, |
| 108 |
ArchivedRevisionLookup $archivedRevisionLookup, |
| 109 |
NamespaceInfo $namespaceInfo, |
| 110 |
ITextFormatter $contLangMsgTextFormatter, |
| 111 |
ProperPageIdentity $page, |
| 112 |
Authority $performer |
| 113 |
) { |
| 114 |
$this->hookRunner = new HookRunner( $hookContainer ); |
| 115 |
$this->jobQueueGroup = $jobQueueGroup; |
| 116 |
$this->dbProvider = $dbProvider; |
| 117 |
$this->readOnlyMode = $readOnlyMode; |
| 118 |
$this->repoGroup = $repoGroup; |
| 119 |
$this->logger = $logger; |
| 120 |
$this->revisionStore = $revisionStore; |
| 121 |
$this->wikiPageFactory = $wikiPageFactory; |
| 122 |
$this->pageUpdaterFactory = $pageUpdaterFactory; |
| 123 |
$this->contentHandlerFactory = $contentHandlerFactory; |
| 124 |
$this->archivedRevisionLookup = $archivedRevisionLookup; |
| 125 |
$this->namespaceInfo = $namespaceInfo; |
| 126 |
$this->contLangMsgTextFormatter = $contLangMsgTextFormatter; |
| 127 |
|
| 128 |
$this->page = $page; |
| 129 |
$this->performer = $performer; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
public function setUnsuppress( bool $unsuppress ): self { |
| 139 |
$this->unsuppress = $unsuppress; |
| 140 |
return $this; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
public function setTags( array $tags ): self { |
| 150 |
$this->tags = $tags; |
| 151 |
return $this; |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
public function setUndeleteOnlyTimestamps( array $timestamps ): self { |
| 161 |
$this->timestamps = $timestamps; |
| 162 |
return $this; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
public function setUndeleteOnlyFileVersions( array $fileVersions ): self { |
| 172 |
$this->fileVersions = $fileVersions; |
| 173 |
return $this; |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
public function canProbablyUndeleteAssociatedTalk(): StatusValue { |
| 183 |
if ( $this->namespaceInfo->isTalk( $this->page->getNamespace() ) ) { |
| 184 |
return StatusValue::newFatal( 'undelete-error-associated-alreadytalk' ); |
| 185 |
} |
| 186 |
|
| 187 |
$thisWikiPage = $this->wikiPageFactory->newFromTitle( $this->page ); |
| 188 |
$talkPage = $this->wikiPageFactory->newFromLinkTarget( |
| 189 |
$this->namespaceInfo->getTalkPage( $thisWikiPage->getTitle() ) |
| 190 |
); |
| 191 |
|
| 192 |
if ( !$this->archivedRevisionLookup->hasArchivedRevisions( $talkPage ) ) { |
| 193 |
return StatusValue::newFatal( 'undelete-error-associated-notdeleted' ); |
| 194 |
} |
| 195 |
return StatusValue::newGood(); |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
public function setUndeleteAssociatedTalk( bool $undelete ): self { |
| 205 |
if ( !$undelete ) { |
| 206 |
$this->associatedTalk = null; |
| 207 |
return $this; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
$thisWikiPage = $this->wikiPageFactory->newFromTitle( $this->page ); |
| 212 |
$this->associatedTalk = $this->wikiPageFactory->newFromLinkTarget( |
| 213 |
$this->namespaceInfo->getTalkPage( $thisWikiPage->getTitle() ) |
| 214 |
); |
| 215 |
return $this; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
public function undeleteIfAllowed( string $comment ): StatusValue { |
| 225 |
$status = $this->authorizeUndeletion(); |
| 226 |
if ( !$status->isGood() ) { |
| 227 |
return $status; |
| 228 |
} |
| 229 |
|
| 230 |
return $this->undeleteUnsafe( $comment ); |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
private function authorizeUndeletion(): PermissionStatus { |
| 237 |
$status = PermissionStatus::newEmpty(); |
| 238 |
$this->performer->authorizeWrite( 'undelete', $this->page, $status ); |
| 239 |
if ( $this->associatedTalk ) { |
| 240 |
$this->performer->authorizeWrite( 'undelete', $this->associatedTalk, $status ); |
| 241 |
} |
| 242 |
if ( $this->tags ) { |
| 243 |
$status->merge( ChangeTags::canAddTagsAccompanyingChange( $this->tags, $this->performer ) ); |
| 244 |
} |
| 245 |
return $status; |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
public function undeleteUnsafe( string $comment ): StatusValue { |
| 267 |
$hookStatus = $this->runPreUndeleteHook( $comment ); |
| 268 |
if ( !$hookStatus->isGood() ) { |
| 269 |
return $hookStatus; |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
$restoreAll = $this->timestamps === [] && $this->fileVersions === []; |
| 274 |
|
| 275 |
$restoreText = $restoreAll || $this->timestamps !== []; |
| 276 |
$restoreFiles = $restoreAll || $this->fileVersions !== []; |
| 277 |
|
| 278 |
$resStatus = StatusValue::newGood(); |
| 279 |
$filesRestored = 0; |
| 280 |
if ( $restoreFiles && $this->page->getNamespace() === NS_FILE ) { |
| 281 |
|
| 282 |
$img = $this->repoGroup->getLocalRepo()->newFile( $this->page ); |
| 283 |
$img->load( IDBAccessObject::READ_LATEST ); |
| 284 |
$this->fileStatus = $img->restore( $this->fileVersions, $this->unsuppress ); |
| 285 |
if ( !$this->fileStatus->isOK() ) { |
| 286 |
return $this->fileStatus; |
| 287 |
} |
| 288 |
$filesRestored = $this->fileStatus->successCount; |
| 289 |
$resStatus->merge( $this->fileStatus ); |
| 290 |
} |
| 291 |
|
| 292 |
$textRestored = 0; |
| 293 |
$pageCreated = false; |
| 294 |
$restoredRevision = null; |
| 295 |
$restoredPageIds = []; |
| 296 |
if ( $restoreText ) { |
| 297 |
$this->revisionStatus = $this->undeleteRevisions( $this->page, $this->timestamps, $comment ); |
| 298 |
if ( !$this->revisionStatus->isOK() ) { |
| 299 |
return $this->revisionStatus; |
| 300 |
} |
| 301 |
|
| 302 |
[ $textRestored, $pageCreated, $restoredRevision, $restoredPageIds ] = $this->revisionStatus->getValue(); |
| 303 |
$resStatus->merge( $this->revisionStatus ); |
| 304 |
} |
| 305 |
|
| 306 |
$talkRestored = 0; |
| 307 |
$talkCreated = false; |
| 308 |
$restoredTalkRevision = null; |
| 309 |
$restoredTalkPageIds = []; |
| 310 |
if ( $this->associatedTalk ) { |
| 311 |
$talkStatus = $this->canProbablyUndeleteAssociatedTalk(); |
| 312 |
|
| 313 |
if ( $talkStatus->isGood() && $resStatus->isGood() ) { |
| 314 |
$talkStatus = $this->undeleteRevisions( $this->associatedTalk, [], $comment ); |
| 315 |
if ( !$talkStatus->isOK() ) { |
| 316 |
return $talkStatus; |
| 317 |
} |
| 318 |
[ $talkRestored, $talkCreated, $restoredTalkRevision, $restoredTalkPageIds ] = $talkStatus->getValue(); |
| 319 |
|
| 320 |
} else { |
| 321 |
|
| 322 |
foreach ( $talkStatus->getMessages() as $msg ) { |
| 323 |
$resStatus->warning( $msg ); |
| 324 |
} |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
$resStatus->value = [ |
| 329 |
self::REVISIONS_RESTORED => $textRestored + $talkRestored, |
| 330 |
self::FILES_RESTORED => $filesRestored |
| 331 |
]; |
| 332 |
|
| 333 |
if ( !$textRestored && !$filesRestored && !$talkRestored ) { |
| 334 |
$this->logger->debug( "Undelete: nothing undeleted..." ); |
| 335 |
return $resStatus; |
| 336 |
} |
| 337 |
|
| 338 |
if ( $textRestored || $filesRestored ) { |
| 339 |
$logEntry = $this->addLogEntry( $this->page, $comment, $textRestored, $filesRestored ); |
| 340 |
|
| 341 |
if ( $textRestored ) { |
| 342 |
$this->hookRunner->onPageUndeleteComplete( |
| 343 |
$this->page, |
| 344 |
$this->performer, |
| 345 |
$comment, |
| 346 |
$restoredRevision, |
| 347 |
$logEntry, |
| 348 |
$textRestored, |
| 349 |
$pageCreated, |
| 350 |
$restoredPageIds |
| 351 |
); |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
if ( $talkRestored ) { |
| 356 |
$talkRestoredComment = $this->contLangMsgTextFormatter->format( |
| 357 |
MessageValue::new( 'undelete-talk-summary-prefix' )->plaintextParams( $comment ) |
| 358 |
); |
| 359 |
$logEntry = $this->addLogEntry( $this->associatedTalk, $talkRestoredComment, $talkRestored, 0 ); |
| 360 |
|
| 361 |
$this->hookRunner->onPageUndeleteComplete( |
| 362 |
$this->associatedTalk, |
| 363 |
$this->performer, |
| 364 |
$talkRestoredComment, |
| 365 |
$restoredTalkRevision, |
| 366 |
$logEntry, |
| 367 |
$talkRestored, |
| 368 |
$talkCreated, |
| 369 |
$restoredTalkPageIds |
| 370 |
); |
| 371 |
} |
| 372 |
|
| 373 |
return $resStatus; |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
private function runPreUndeleteHook( string $comment ): StatusValue { |
| 381 |
$checkPages = [ $this->page ]; |
| 382 |
if ( $this->associatedTalk ) { |
| 383 |
$checkPages[] = $this->associatedTalk; |
| 384 |
} |
| 385 |
foreach ( $checkPages as $page ) { |
| 386 |
$hookStatus = StatusValue::newGood(); |
| 387 |
$hookRes = $this->hookRunner->onPageUndelete( |
| 388 |
$page, |
| 389 |
$this->performer, |
| 390 |
$comment, |
| 391 |
$this->unsuppress, |
| 392 |
$this->timestamps, |
| 393 |
$this->fileVersions, |
| 394 |
$hookStatus |
| 395 |
); |
| 396 |
if ( !$hookRes && !$hookStatus->isGood() ) { |
| 397 |
|
| 398 |
return $hookStatus; |
| 399 |
} |
| 400 |
} |
| 401 |
return Status::newGood(); |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
private function addLogEntry( |
| 413 |
ProperPageIdentity $page, |
| 414 |
string $comment, |
| 415 |
int $textRestored, |
| 416 |
int $filesRestored |
| 417 |
): ManualLogEntry { |
| 418 |
$logEntry = new ManualLogEntry( 'delete', 'restore' ); |
| 419 |
$logEntry->setPerformer( $this->performer->getUser() ); |
| 420 |
$logEntry->setTarget( $page ); |
| 421 |
$logEntry->setComment( $comment ); |
| 422 |
$logEntry->addTags( $this->tags ); |
| 423 |
$logEntry->setParameters( [ |
| 424 |
':assoc:count' => [ |
| 425 |
'revisions' => $textRestored, |
| 426 |
'files' => $filesRestored, |
| 427 |
], |
| 428 |
] ); |
| 429 |
|
| 430 |
$logid = $logEntry->insert(); |
| 431 |
$logEntry->publish( $logid ); |
| 432 |
|
| 433 |
return $logEntry; |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
private function undeleteRevisions( ProperPageIdentity $page, array $timestamps, string $comment ): StatusValue { |
| 447 |
if ( $this->readOnlyMode->isReadOnly() ) { |
| 448 |
throw new ReadOnlyError(); |
| 449 |
} |
| 450 |
|
| 451 |
$dbw = $this->dbProvider->getPrimaryDatabase(); |
| 452 |
$dbw->startAtomic( __METHOD__, IDatabase::ATOMIC_CANCELABLE ); |
| 453 |
|
| 454 |
$oldWhere = [ |
| 455 |
'ar_namespace' => $page->getNamespace(), |
| 456 |
'ar_title' => $page->getDBkey(), |
| 457 |
]; |
| 458 |
if ( $timestamps ) { |
| 459 |
$oldWhere['ar_timestamp'] = array_map( [ $dbw, 'timestamp' ], $timestamps ); |
| 460 |
} |
| 461 |
|
| 462 |
$revisionStore = $this->revisionStore; |
| 463 |
$result = $revisionStore->newArchiveSelectQueryBuilder( $dbw ) |
| 464 |
->joinComment() |
| 465 |
->leftJoin( 'revision', null, 'ar_rev_id=rev_id' ) |
| 466 |
->field( 'rev_id' ) |
| 467 |
->where( $oldWhere ) |
| 468 |
->orderBy( 'ar_timestamp' ) |
| 469 |
->caller( __METHOD__ )->fetchResultSet(); |
| 470 |
|
| 471 |
$rev_count = $result->numRows(); |
| 472 |
if ( !$rev_count ) { |
| 473 |
$this->logger->debug( __METHOD__ . ": no revisions to restore" ); |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
$status = Status::newGood( [ 0, false, null, [] ] ); |
| 478 |
$status->error( "undelete-no-results" ); |
| 479 |
$dbw->endAtomic( __METHOD__ ); |
| 480 |
|
| 481 |
return $status; |
| 482 |
} |
| 483 |
|
| 484 |
$result->seek( $rev_count - 1 ); |
| 485 |
$latestRestorableRow = $result->current(); |
| 486 |
|
| 487 |
|
| 488 |
$result->seek( 0 ); |
| 489 |
|
| 490 |
$wikiPage = $this->wikiPageFactory->newFromTitle( $page ); |
| 491 |
|
| 492 |
$created = true; |
| 493 |
$oldcountable = false; |
| 494 |
$updatedCurrentRevision = false; |
| 495 |
$restoredRevCount = 0; |
| 496 |
$restoredPages = []; |
| 497 |
|
| 498 |
|
| 499 |
$oldPageId = (int)$latestRestorableRow->ar_page_id; |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
$revision = $revisionStore->newRevisionFromArchiveRow( |
| 505 |
$latestRestorableRow, |
| 506 |
0, |
| 507 |
$page |
| 508 |
); |
| 509 |
|
| 510 |
foreach ( $revision->getSlotRoles() as $role ) { |
| 511 |
$content = $revision->getContent( $role, RevisionRecord::RAW ); |
| 512 |
|
| 513 |
$contentHandler = $this->contentHandlerFactory->getContentHandler( $content->getModel() ); |
| 514 |
$validationParams = new ValidationParams( $wikiPage, 0 ); |
| 515 |
|
| 516 |
$status = $contentHandler->validateSave( $content, $validationParams ); |
| 517 |
if ( !$status->isOK() ) { |
| 518 |
$dbw->endAtomic( __METHOD__ ); |
| 519 |
|
| 520 |
return $status; |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
$pageId = $wikiPage->insertOn( $dbw, $latestRestorableRow->ar_page_id ); |
| 525 |
if ( $pageId === false ) { |
| 526 |
|
| 527 |
$pageId = $wikiPage->insertOn( $dbw ); |
| 528 |
if ( $pageId === false ) { |
| 529 |
|
| 530 |
$created = false; |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
if ( !$created ) { |
| 536 |
|
| 537 |
$wikiPage->loadPageData( IDBAccessObject::READ_EXCLUSIVE ); |
| 538 |
$pageId = $wikiPage->getId(); |
| 539 |
$oldcountable = $wikiPage->isCountable(); |
| 540 |
|
| 541 |
$previousTimestamp = false; |
| 542 |
$latestRevId = $wikiPage->getLatest(); |
| 543 |
if ( $latestRevId ) { |
| 544 |
$previousTimestamp = $revisionStore->getTimestampFromId( |
| 545 |
$latestRevId, |
| 546 |
IDBAccessObject::READ_LATEST |
| 547 |
); |
| 548 |
} |
| 549 |
if ( $previousTimestamp === false ) { |
| 550 |
$this->logger->debug( __METHOD__ . ": existing page refers to a page_latest that does not exist" ); |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
$status = Status::newGood( [ 0, false, null, [] ] ); |
| 555 |
$status->error( 'undeleterevision-missing' ); |
| 556 |
$dbw->cancelAtomic( __METHOD__ ); |
| 557 |
|
| 558 |
return $status; |
| 559 |
} |
| 560 |
} else { |
| 561 |
$previousTimestamp = 0; |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
if ( $latestRestorableRow->ar_timestamp > $previousTimestamp ) { |
| 566 |
|
| 567 |
if ( !$this->unsuppress |
| 568 |
&& ( $latestRestorableRow->ar_deleted & RevisionRecord::DELETED_TEXT ) |
| 569 |
) { |
| 570 |
$dbw->cancelAtomic( __METHOD__ ); |
| 571 |
|
| 572 |
return Status::newFatal( "undeleterevdel" ); |
| 573 |
} |
| 574 |
$updatedCurrentRevision = true; |
| 575 |
} |
| 576 |
|
| 577 |
foreach ( $result as $row ) { |
| 578 |
|
| 579 |
|
| 580 |
$revision = $revisionStore->newRevisionFromArchiveRow( |
| 581 |
$row, |
| 582 |
0, |
| 583 |
$page, |
| 584 |
[ |
| 585 |
'page_id' => $pageId, |
| 586 |
'deleted' => $this->unsuppress ? 0 : $row->ar_deleted |
| 587 |
] |
| 588 |
); |
| 589 |
|
| 590 |
|
| 591 |
$revision = $revisionStore->insertRevisionOn( $revision, $dbw ); |
| 592 |
|
| 593 |
$restoredRevCount++; |
| 594 |
|
| 595 |
$this->hookRunner->onRevisionUndeleted( $revision, $row->ar_page_id ); |
| 596 |
|
| 597 |
$restoredPages[$row->ar_page_id] = true; |
| 598 |
} |
| 599 |
|
| 600 |
|
| 601 |
$dbw->newDeleteQueryBuilder() |
| 602 |
->deleteFrom( 'archive' ) |
| 603 |
->where( $oldWhere ) |
| 604 |
->caller( __METHOD__ )->execute(); |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
$status = Status::newGood( [ $restoredRevCount, $created, $revision, $restoredPages ] ); |
| 609 |
|
| 610 |
|
| 611 |
if ( $restoredRevCount ) { |
| 612 |
|
| 613 |
if ( $updatedCurrentRevision ) { |
| 614 |
|
| 615 |
|
| 616 |
$wasnew = $wikiPage->updateRevisionOn( |
| 617 |
$dbw, |
| 618 |
$revision, |
| 619 |
$created ? 0 : $wikiPage->getLatest() |
| 620 |
); |
| 621 |
} else { |
| 622 |
$wasnew = false; |
| 623 |
} |
| 624 |
|
| 625 |
if ( $created || $wasnew ) { |
| 626 |
|
| 627 |
$user = $revision->getUser( RevisionRecord::RAW ); |
| 628 |
$options = [ |
| 629 |
'created' => $created, |
| 630 |
'oldcountable' => $oldcountable, |
| 631 |
'restored' => true, |
| 632 |
'causeAction' => 'undelete-page', |
| 633 |
'causeAgent' => $user->getName(), |
| 634 |
]; |
| 635 |
|
| 636 |
$updater = $this->pageUpdaterFactory->newDerivedPageDataUpdater( $wikiPage ); |
| 637 |
$updater->prepareUpdate( $revision, $options ); |
| 638 |
$updater->doUpdates(); |
| 639 |
} |
| 640 |
|
| 641 |
$this->hookRunner->onArticleUndelete( |
| 642 |
$wikiPage->getTitle(), $created, $comment, $oldPageId, $restoredPages ); |
| 643 |
|
| 644 |
if ( $page->getNamespace() === NS_FILE ) { |
| 645 |
$job = HTMLCacheUpdateJob::newForBacklinks( |
| 646 |
$page, |
| 647 |
'imagelinks', |
| 648 |
[ 'causeAction' => 'undelete-file' ] |
| 649 |
); |
| 650 |
$this->jobQueueGroup->lazyPush( $job ); |
| 651 |
} |
| 652 |
} |
| 653 |
|
| 654 |
$dbw->endAtomic( __METHOD__ ); |
| 655 |
|
| 656 |
return $status; |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
public function getFileStatus(): ?Status { |
| 664 |
return $this->fileStatus; |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
public function getRevisionStatus(): ?StatusValue { |
| 672 |
return $this->revisionStatus; |
| 673 |
} |
| 674 |
} |