3 * Implements Special:Undelete
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
23 use MediaWiki\MediaWikiServices
;
24 use Wikimedia\Rdbms\ResultWrapper
;
27 * Used to show archived pages and eventually restore them.
29 * @ingroup SpecialPage
36 protected $fileStatus;
39 protected $revisionStatus;
44 function __construct( $title, Config
$config = null ) {
45 if ( is_null( $title ) ) {
46 throw new MWException( __METHOD__
. ' given a null title.' );
48 $this->title
= $title;
49 if ( $config === null ) {
50 wfDebug( __METHOD__
. ' did not have a Config object passed to it' );
51 $config = MediaWikiServices
::getInstance()->getMainConfig();
53 $this->config
= $config;
56 public function doesWrites() {
61 * List all deleted pages recorded in the archive table. Returns result
62 * wrapper with (ar_namespace, ar_title, count) fields, ordered by page
65 * @return ResultWrapper
67 public static function listAllPages() {
68 $dbr = wfGetDB( DB_REPLICA
);
70 return self
::listPages( $dbr, '' );
74 * List deleted pages recorded in the archive table matching the
76 * Returns result wrapper with (ar_namespace, ar_title, count) fields.
78 * @param string $prefix Title prefix
79 * @return ResultWrapper
81 public static function listPagesByPrefix( $prefix ) {
82 $dbr = wfGetDB( DB_REPLICA
);
84 $title = Title
::newFromText( $prefix );
86 $ns = $title->getNamespace();
87 $prefix = $title->getDBkey();
89 // Prolly won't work too good
90 // @todo handle bare namespace names cleanly?
95 'ar_namespace' => $ns,
96 'ar_title' . $dbr->buildLike( $prefix, $dbr->anyString() ),
99 return self
::listPages( $dbr, $conds );
103 * @param IDatabase $dbr
104 * @param string|array $condition
105 * @return bool|ResultWrapper
107 protected static function listPages( $dbr, $condition ) {
113 'count' => 'COUNT(*)'
118 'GROUP BY' => [ 'ar_namespace', 'ar_title' ],
119 'ORDER BY' => [ 'ar_namespace', 'ar_title' ],
126 * List the revisions of the given page. Returns result wrapper with
127 * (ar_minor_edit, ar_timestamp, ar_user, ar_user_text, ar_comment) fields.
129 * @return ResultWrapper
131 function listRevisions() {
132 $dbr = wfGetDB( DB_REPLICA
);
134 $tables = [ 'archive' ];
137 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text',
138 'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1',
141 if ( $this->config
->get( 'ContentHandlerUseDB' ) ) {
142 $fields[] = 'ar_content_format';
143 $fields[] = 'ar_content_model';
146 $conds = [ 'ar_namespace' => $this->title
->getNamespace(),
147 'ar_title' => $this->title
->getDBkey() ];
149 $options = [ 'ORDER BY' => 'ar_timestamp DESC' ];
153 ChangeTags
::modifyDisplayQuery(
162 return $dbr->select( $tables,
172 * List the deleted file revisions for this page, if it's a file page.
173 * Returns a result wrapper with various filearchive fields, or null
174 * if not a file page.
176 * @return ResultWrapper
177 * @todo Does this belong in Image for fuller encapsulation?
179 function listFiles() {
180 if ( $this->title
->getNamespace() != NS_FILE
) {
184 $dbr = wfGetDB( DB_REPLICA
);
187 ArchivedFile
::selectFields(),
188 [ 'fa_name' => $this->title
->getDBkey() ],
190 [ 'ORDER BY' => 'fa_timestamp DESC' ]
195 * Return a Revision object containing data for the deleted revision.
196 * Note that the result *may* or *may not* have a null page ID.
198 * @param string $timestamp
199 * @return Revision|null
201 function getRevision( $timestamp ) {
202 $dbr = wfGetDB( DB_REPLICA
);
219 if ( $this->config
->get( 'ContentHandlerUseDB' ) ) {
220 $fields[] = 'ar_content_format';
221 $fields[] = 'ar_content_model';
224 $row = $dbr->selectRow( 'archive',
226 [ 'ar_namespace' => $this->title
->getNamespace(),
227 'ar_title' => $this->title
->getDBkey(),
228 'ar_timestamp' => $dbr->timestamp( $timestamp ) ],
232 return Revision
::newFromArchiveRow( $row, [ 'title' => $this->title
] );
239 * Return the most-previous revision, either live or deleted, against
240 * the deleted revision given by timestamp.
242 * May produce unexpected results in case of history merges or other
243 * unusual time issues.
245 * @param string $timestamp
246 * @return Revision|null Null when there is no previous revision
248 function getPreviousRevision( $timestamp ) {
249 $dbr = wfGetDB( DB_REPLICA
);
251 // Check the previous deleted revision...
252 $row = $dbr->selectRow( 'archive',
254 [ 'ar_namespace' => $this->title
->getNamespace(),
255 'ar_title' => $this->title
->getDBkey(),
257 $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ],
260 'ORDER BY' => 'ar_timestamp DESC',
262 $prevDeleted = $row ?
wfTimestamp( TS_MW
, $row->ar_timestamp
) : false;
264 $row = $dbr->selectRow( [ 'page', 'revision' ],
265 [ 'rev_id', 'rev_timestamp' ],
267 'page_namespace' => $this->title
->getNamespace(),
268 'page_title' => $this->title
->getDBkey(),
269 'page_id = rev_page',
271 $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ],
274 'ORDER BY' => 'rev_timestamp DESC',
276 $prevLive = $row ?
wfTimestamp( TS_MW
, $row->rev_timestamp
) : false;
277 $prevLiveId = $row ?
intval( $row->rev_id
) : null;
279 if ( $prevLive && $prevLive > $prevDeleted ) {
280 // Most prior revision was live
281 return Revision
::newFromId( $prevLiveId );
282 } elseif ( $prevDeleted ) {
283 // Most prior revision was deleted
284 return $this->getRevision( $prevDeleted );
287 // No prior revision on this page.
292 * Get the text from an archive row containing ar_text, ar_flags and ar_text_id
294 * @param object $row Database row
297 function getTextFromRow( $row ) {
298 if ( is_null( $row->ar_text_id
) ) {
299 // An old row from MediaWiki 1.4 or previous.
300 // Text is embedded in this row in classic compression format.
301 return Revision
::getRevisionText( $row, 'ar_' );
304 // New-style: keyed to the text storage backend.
305 $dbr = wfGetDB( DB_REPLICA
);
306 $text = $dbr->selectRow( 'text',
307 [ 'old_text', 'old_flags' ],
308 [ 'old_id' => $row->ar_text_id
],
311 return Revision
::getRevisionText( $text );
315 * Fetch (and decompress if necessary) the stored text of the most
316 * recently edited deleted revision of the page.
318 * If there are no archived revisions for the page, returns NULL.
320 * @return string|null
322 function getLastRevisionText() {
323 $dbr = wfGetDB( DB_REPLICA
);
324 $row = $dbr->selectRow( 'archive',
325 [ 'ar_text', 'ar_flags', 'ar_text_id' ],
326 [ 'ar_namespace' => $this->title
->getNamespace(),
327 'ar_title' => $this->title
->getDBkey() ],
329 [ 'ORDER BY' => 'ar_timestamp DESC' ] );
332 return $this->getTextFromRow( $row );
339 * Quick check if any archived revisions are present for the page.
343 function isDeleted() {
344 $dbr = wfGetDB( DB_REPLICA
);
345 $n = $dbr->selectField( 'archive', 'COUNT(ar_title)',
346 [ 'ar_namespace' => $this->title
->getNamespace(),
347 'ar_title' => $this->title
->getDBkey() ],
355 * Restore the given (or all) text and file revisions for the page.
356 * Once restored, the items will be removed from the archive tables.
357 * The deletion log will be updated with an undeletion notice.
359 * This also sets Status objects, $this->fileStatus and $this->revisionStatus
360 * (depending what operations are attempted).
362 * @param array $timestamps Pass an empty array to restore all revisions,
363 * otherwise list the ones to undelete.
364 * @param string $comment
365 * @param array $fileVersions
366 * @param bool $unsuppress
367 * @param User $user User performing the action, or null to use $wgUser
368 * @param string|string[] $tags Change tags to add to log entry
369 * ($user should be able to add the specified tags before this is called)
370 * @return array(number of file revisions restored, number of image revisions
371 * restored, log message) on success, false on failure.
373 function undelete( $timestamps, $comment = '', $fileVersions = [],
374 $unsuppress = false, User
$user = null, $tags = null
376 // If both the set of text revisions and file revisions are empty,
377 // restore everything. Otherwise, just restore the requested items.
378 $restoreAll = empty( $timestamps ) && empty( $fileVersions );
380 $restoreText = $restoreAll ||
!empty( $timestamps );
381 $restoreFiles = $restoreAll ||
!empty( $fileVersions );
383 if ( $restoreFiles && $this->title
->getNamespace() == NS_FILE
) {
384 $img = wfLocalFile( $this->title
);
385 $img->load( File
::READ_LATEST
);
386 $this->fileStatus
= $img->restore( $fileVersions, $unsuppress );
387 if ( !$this->fileStatus
->isOK() ) {
390 $filesRestored = $this->fileStatus
->successCount
;
395 if ( $restoreText ) {
396 $this->revisionStatus
= $this->undeleteRevisions( $timestamps, $unsuppress, $comment );
397 if ( !$this->revisionStatus
->isOK() ) {
401 $textRestored = $this->revisionStatus
->getValue();
408 if ( $textRestored && $filesRestored ) {
409 $reason = wfMessage( 'undeletedrevisions-files' )
410 ->numParams( $textRestored, $filesRestored )->inContentLanguage()->text();
411 } elseif ( $textRestored ) {
412 $reason = wfMessage( 'undeletedrevisions' )->numParams( $textRestored )
413 ->inContentLanguage()->text();
414 } elseif ( $filesRestored ) {
415 $reason = wfMessage( 'undeletedfiles' )->numParams( $filesRestored )
416 ->inContentLanguage()->text();
418 wfDebug( "Undelete: nothing undeleted...\n" );
423 if ( trim( $comment ) != '' ) {
424 $reason .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $comment;
427 if ( $user === null ) {
432 $logEntry = new ManualLogEntry( 'delete', 'restore' );
433 $logEntry->setPerformer( $user );
434 $logEntry->setTarget( $this->title
);
435 $logEntry->setComment( $reason );
436 $logEntry->setTags( $tags );
438 Hooks
::run( 'ArticleUndeleteLogEntry', [ $this, &$logEntry, $user ] );
440 $logid = $logEntry->insert();
441 $logEntry->publish( $logid );
443 return [ $textRestored, $filesRestored, $reason ];
447 * This is the meaty bit -- It restores archived revisions of the given page
448 * to the revision table.
450 * @param array $timestamps Pass an empty array to restore all revisions,
451 * otherwise list the ones to undelete.
452 * @param bool $unsuppress Remove all ar_deleted/fa_deleted restrictions of seletected revs
453 * @param string $comment
454 * @throws ReadOnlyError
455 * @return Status Status object containing the number of revisions restored on success
457 private function undeleteRevisions( $timestamps, $unsuppress = false, $comment = '' ) {
458 if ( wfReadOnly() ) {
459 throw new ReadOnlyError();
462 $dbw = wfGetDB( DB_MASTER
);
463 $dbw->startAtomic( __METHOD__
);
465 $restoreAll = empty( $timestamps );
467 # Does this page already exist? We'll have to update it...
468 $article = WikiPage
::factory( $this->title
);
469 # Load latest data for the current page (T33179)
470 $article->loadPageData( 'fromdbmaster' );
471 $oldcountable = $article->isCountable();
473 $page = $dbw->selectRow( 'page',
474 [ 'page_id', 'page_latest' ],
475 [ 'page_namespace' => $this->title
->getNamespace(),
476 'page_title' => $this->title
->getDBkey() ],
478 [ 'FOR UPDATE' ] // lock page
483 # Page already exists. Import the history, and if necessary
484 # we'll update the latest revision field in the record.
486 # Get the time span of this page
487 $previousTimestamp = $dbw->selectField( 'revision', 'rev_timestamp',
488 [ 'rev_id' => $page->page_latest
],
491 if ( $previousTimestamp === false ) {
492 wfDebug( __METHOD__
. ": existing page refers to a page_latest that does not exist\n" );
494 $status = Status
::newGood( 0 );
495 $status->warning( 'undeleterevision-missing' );
496 $dbw->endAtomic( __METHOD__
);
501 # Have to create a new article...
503 $previousTimestamp = 0;
507 'ar_namespace' => $this->title
->getNamespace(),
508 'ar_title' => $this->title
->getDBkey(),
510 if ( !$restoreAll ) {
511 $oldWhere['ar_timestamp'] = array_map( [ &$dbw, 'timestamp' ], $timestamps );
532 if ( $this->config
->get( 'ContentHandlerUseDB' ) ) {
533 $fields[] = 'ar_content_format';
534 $fields[] = 'ar_content_model';
538 * Select each archived revision...
540 $result = $dbw->select(
541 [ 'archive', 'revision' ],
546 [ 'ORDER BY' => 'ar_timestamp' ],
547 [ 'revision' => [ 'LEFT JOIN', 'ar_rev_id=rev_id' ] ]
550 $rev_count = $result->numRows();
552 wfDebug( __METHOD__
. ": no revisions to restore\n" );
554 $status = Status
::newGood( 0 );
555 $status->warning( "undelete-no-results" );
556 $dbw->endAtomic( __METHOD__
);
561 // We use ar_id because there can be duplicate ar_rev_id even for the same
562 // page. In this case, we may be able to restore the first one.
563 $restoreFailedArIds = [];
565 // Map rev_id to the ar_id that is allowed to use it. When checking later,
566 // if it doesn't match, the current ar_id can not be restored.
568 // Value can be an ar_id or -1 (-1 means no ar_id can use it, since the
569 // rev_id is taken before we even start the restore).
570 $allowedRevIdToArIdMap = [];
572 $latestRestorableRow = null;
574 foreach ( $result as $row ) {
575 if ( $row->ar_rev_id
) {
576 // rev_id is taken even before we start restoring.
577 if ( $row->ar_rev_id
=== $row->rev_id
) {
578 $restoreFailedArIds[] = $row->ar_id
;
579 $allowedRevIdToArIdMap[$row->ar_rev_id
] = -1;
581 // rev_id is not taken yet in the DB, but it might be taken
582 // by a prior revision in the same restore operation. If
583 // not, we need to reserve it.
584 if ( isset( $allowedRevIdToArIdMap[$row->ar_rev_id
] ) ) {
585 $restoreFailedArIds[] = $row->ar_id
;
587 $allowedRevIdToArIdMap[$row->ar_rev_id
] = $row->ar_id
;
588 $latestRestorableRow = $row;
592 // If ar_rev_id is null, there can't be a collision, and a
593 // rev_id will be chosen automatically.
594 $latestRestorableRow = $row;
598 $result->seek( 0 ); // move back
601 if ( $latestRestorableRow !== null ) {
602 $oldPageId = (int)$latestRestorableRow->ar_page_id
; // pass this to ArticleUndelete hook
604 // grab the content to check consistency with global state before restoring the page.
605 $revision = Revision
::newFromArchiveRow( $latestRestorableRow,
607 'title' => $article->getTitle(), // used to derive default content model
610 $user = User
::newFromName( $revision->getUserText( Revision
::RAW
), false );
611 $content = $revision->getContent( Revision
::RAW
);
613 // NOTE: article ID may not be known yet. prepareSave() should not modify the database.
614 $status = $content->prepareSave( $article, 0, -1, $user );
615 if ( !$status->isOK() ) {
616 $dbw->endAtomic( __METHOD__
);
622 $newid = false; // newly created page ID
623 $restored = 0; // number of revisions restored
624 /** @var Revision $revision */
627 // If there are no restorable revisions, we can skip most of the steps.
628 if ( $latestRestorableRow === null ) {
629 $failedRevisionCount = $rev_count;
632 // Check the state of the newest to-be version...
634 && ( $latestRestorableRow->ar_deleted
& Revision
::DELETED_TEXT
)
636 $dbw->endAtomic( __METHOD__
);
638 return Status
::newFatal( "undeleterevdel" );
640 // Safe to insert now...
641 $newid = $article->insertOn( $dbw, $latestRestorableRow->ar_page_id
);
642 if ( $newid === false ) {
643 // The old ID is reserved; let's pick another
644 $newid = $article->insertOn( $dbw );
648 // Check if a deleted revision will become the current revision...
649 if ( $latestRestorableRow->ar_timestamp
> $previousTimestamp ) {
650 // Check the state of the newest to-be version...
652 && ( $latestRestorableRow->ar_deleted
& Revision
::DELETED_TEXT
)
654 $dbw->endAtomic( __METHOD__
);
656 return Status
::newFatal( "undeleterevdel" );
661 $pageId = $article->getId();
664 foreach ( $result as $row ) {
665 // Check for key dupes due to needed archive integrity.
666 if ( $row->ar_rev_id
&& $allowedRevIdToArIdMap[$row->ar_rev_id
] !== $row->ar_id
) {
669 // Insert one revision at a time...maintaining deletion status
670 // unless we are specifically removing all restrictions...
671 $revision = Revision
::newFromArchiveRow( $row,
674 'title' => $this->title
,
675 'deleted' => $unsuppress ?
0 : $row->ar_deleted
678 $revision->insertOn( $dbw );
681 Hooks
::run( 'ArticleRevisionUndeleted',
682 [ &$this->title
, $revision, $row->ar_page_id
] );
685 // Now that it's safely stored, take it out of the archive
686 // Don't delete rows that we failed to restore
687 $toDeleteConds = $oldWhere;
688 $failedRevisionCount = count( $restoreFailedArIds );
689 if ( $failedRevisionCount > 0 ) {
690 $toDeleteConds[] = 'ar_id NOT IN ( ' . $dbw->makeList( $restoreFailedArIds ) . ' )';
693 $dbw->delete( 'archive',
698 $status = Status
::newGood( $restored );
700 if ( $failedRevisionCount > 0 ) {
702 wfMessage( 'undeleterevision-duplicate-revid', $failedRevisionCount ) );
705 // Was anything restored at all?
707 $created = (bool)$newid;
708 // Attach the latest revision to the page...
709 $wasnew = $article->updateIfNewerOn( $dbw, $revision );
710 if ( $created ||
$wasnew ) {
711 // Update site stats, link tables, etc
712 $article->doEditUpdates(
714 User
::newFromName( $revision->getUserText( Revision
::RAW
), false ),
716 'created' => $created,
717 'oldcountable' => $oldcountable,
723 Hooks
::run( 'ArticleUndelete', [ &$this->title
, $created, $comment, $oldPageId ] );
724 if ( $this->title
->getNamespace() == NS_FILE
) {
725 DeferredUpdates
::addUpdate( new HTMLCacheUpdate( $this->title
, 'imagelinks' ) );
729 $dbw->endAtomic( __METHOD__
);
737 function getFileStatus() {
738 return $this->fileStatus
;
744 function getRevisionStatus() {
745 return $this->revisionStatus
;
750 * Special page allowing users with the appropriate permissions to view
751 * and restore deleted content.
753 * @ingroup SpecialPage
755 class SpecialUndelete
extends SpecialPage
{
763 private $mTargetTimestamp;
772 function __construct() {
773 parent
::__construct( 'Undelete', 'deletedhistory' );
776 public function doesWrites() {
780 function loadRequest( $par ) {
781 $request = $this->getRequest();
782 $user = $this->getUser();
784 $this->mAction
= $request->getVal( 'action' );
785 if ( $par !== null && $par !== '' ) {
786 $this->mTarget
= $par;
788 $this->mTarget
= $request->getVal( 'target' );
791 $this->mTargetObj
= null;
793 if ( $this->mTarget
!== null && $this->mTarget
!== '' ) {
794 $this->mTargetObj
= Title
::newFromText( $this->mTarget
);
797 $this->mSearchPrefix
= $request->getText( 'prefix' );
798 $time = $request->getVal( 'timestamp' );
799 $this->mTimestamp
= $time ?
wfTimestamp( TS_MW
, $time ) : '';
800 $this->mFilename
= $request->getVal( 'file' );
802 $posted = $request->wasPosted() &&
803 $user->matchEditToken( $request->getVal( 'wpEditToken' ) );
804 $this->mRestore
= $request->getCheck( 'restore' ) && $posted;
805 $this->mRevdel
= $request->getCheck( 'revdel' ) && $posted;
806 $this->mInvert
= $request->getCheck( 'invert' ) && $posted;
807 $this->mPreview
= $request->getCheck( 'preview' ) && $posted;
808 $this->mDiff
= $request->getCheck( 'diff' );
809 $this->mDiffOnly
= $request->getBool( 'diffonly', $this->getUser()->getOption( 'diffonly' ) );
810 $this->mComment
= $request->getText( 'wpComment' );
811 $this->mUnsuppress
= $request->getVal( 'wpUnsuppress' ) && $user->isAllowed( 'suppressrevision' );
812 $this->mToken
= $request->getVal( 'token' );
814 if ( $this->isAllowed( 'undelete' ) && !$user->isBlocked() ) {
815 $this->mAllowed
= true; // user can restore
816 $this->mCanView
= true; // user can view content
817 } elseif ( $this->isAllowed( 'deletedtext' ) ) {
818 $this->mAllowed
= false; // user cannot restore
819 $this->mCanView
= true; // user can view content
820 $this->mRestore
= false;
821 } else { // user can only view the list of revisions
822 $this->mAllowed
= false;
823 $this->mCanView
= false;
824 $this->mTimestamp
= '';
825 $this->mRestore
= false;
828 if ( $this->mRestore ||
$this->mInvert
) {
830 $this->mFileVersions
= [];
831 foreach ( $request->getValues() as $key => $val ) {
833 if ( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
834 array_push( $timestamps, $matches[1] );
837 if ( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
838 $this->mFileVersions
[] = intval( $matches[1] );
841 rsort( $timestamps );
842 $this->mTargetTimestamp
= $timestamps;
847 * Checks whether a user is allowed the permission for the
848 * specific title if one is set.
850 * @param string $permission
854 protected function isAllowed( $permission, User
$user = null ) {
855 $user = $user ?
: $this->getUser();
856 if ( $this->mTargetObj
!== null ) {
857 return $this->mTargetObj
->userCan( $permission, $user );
859 return $user->isAllowed( $permission );
863 function userCanExecute( User
$user ) {
864 return $this->isAllowed( $this->mRestriction
, $user );
867 function execute( $par ) {
868 $this->useTransactionalTimeLimit();
870 $user = $this->getUser();
873 $this->outputHeader();
875 $this->loadRequest( $par );
876 $this->checkPermissions(); // Needs to be after mTargetObj is set
878 $out = $this->getOutput();
880 if ( is_null( $this->mTargetObj
) ) {
881 $out->addWikiMsg( 'undelete-header' );
883 # Not all users can just browse every deleted page from the list
884 if ( $user->isAllowed( 'browsearchive' ) ) {
885 $this->showSearchForm();
891 $this->addHelpLink( 'Help:Undelete' );
892 if ( $this->mAllowed
) {
893 $out->setPageTitle( $this->msg( 'undeletepage' ) );
895 $out->setPageTitle( $this->msg( 'viewdeletedpage' ) );
898 $this->getSkin()->setRelevantTitle( $this->mTargetObj
);
900 if ( $this->mTimestamp
!== '' ) {
901 $this->showRevision( $this->mTimestamp
);
902 } elseif ( $this->mFilename
!== null && $this->mTargetObj
->inNamespace( NS_FILE
) ) {
903 $file = new ArchivedFile( $this->mTargetObj
, '', $this->mFilename
);
904 // Check if user is allowed to see this file
905 if ( !$file->exists() ) {
906 $out->addWikiMsg( 'filedelete-nofile', $this->mFilename
);
907 } elseif ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
908 if ( $file->isDeleted( File
::DELETED_RESTRICTED
) ) {
909 throw new PermissionsError( 'suppressrevision' );
911 throw new PermissionsError( 'deletedtext' );
913 } elseif ( !$user->matchEditToken( $this->mToken
, $this->mFilename
) ) {
914 $this->showFileConfirmationForm( $this->mFilename
);
916 $this->showFile( $this->mFilename
);
918 } elseif ( $this->mAction
=== "submit" ) {
919 if ( $this->mRestore
) {
921 } elseif ( $this->mRevdel
) {
922 $this->redirectToRevDel();
926 $this->showHistory();
931 * Convert submitted form data to format expected by RevisionDelete and
932 * redirect the request
934 private function redirectToRevDel() {
935 $archive = new PageArchive( $this->mTargetObj
);
939 foreach ( $this->getRequest()->getValues() as $key => $val ) {
941 if ( preg_match( "/^ts(\d{14})$/", $key, $matches ) ) {
942 $revisions[ $archive->getRevision( $matches[1] )->getId() ] = 1;
946 "type" => "revision",
948 "target" => $this->mTargetObj
->getPrefixedText()
950 $url = SpecialPage
::getTitleFor( 'Revisiondelete' )->getFullURL( $query );
951 $this->getOutput()->redirect( $url );
954 function showSearchForm() {
955 $out = $this->getOutput();
956 $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
958 Xml
::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] ) .
959 Xml
::fieldset( $this->msg( 'undelete-search-box' )->text() ) .
960 Html
::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
963 [ 'for' => 'prefix' ],
964 $this->msg( 'undelete-search-prefix' )->parse()
969 $this->mSearchPrefix
,
970 [ 'id' => 'prefix', 'autofocus' => '' ]
972 Xml
::submitButton( $this->msg( 'undelete-search-submit' )->text() ) .
973 Xml
::closeElement( 'fieldset' ) .
974 Xml
::closeElement( 'form' )
977 # List undeletable articles
978 if ( $this->mSearchPrefix
) {
979 $result = PageArchive
::listPagesByPrefix( $this->mSearchPrefix
);
980 $this->showList( $result );
985 * Generic list of deleted pages
987 * @param ResultWrapper $result
990 private function showList( $result ) {
991 $out = $this->getOutput();
993 if ( $result->numRows() == 0 ) {
994 $out->addWikiMsg( 'undelete-no-results' );
999 $out->addWikiMsg( 'undeletepagetext', $this->getLanguage()->formatNum( $result->numRows() ) );
1001 $linkRenderer = $this->getLinkRenderer();
1002 $undelete = $this->getPageTitle();
1003 $out->addHTML( "<ul>\n" );
1004 foreach ( $result as $row ) {
1005 $title = Title
::makeTitleSafe( $row->ar_namespace
, $row->ar_title
);
1006 if ( $title !== null ) {
1007 $item = $linkRenderer->makeKnownLink(
1009 $title->getPrefixedText(),
1011 [ 'target' => $title->getPrefixedText() ]
1014 // The title is no longer valid, show as text
1015 $item = Html
::element(
1017 [ 'class' => 'mw-invalidtitle' ],
1018 Linker
::getInvalidTitleDescription(
1019 $this->getContext(),
1025 $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count
)->parse();
1026 $out->addHTML( "<li>{$item} ({$revs})</li>\n" );
1029 $out->addHTML( "</ul>\n" );
1034 private function showRevision( $timestamp ) {
1035 if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
1039 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1040 if ( !Hooks
::run( 'UndeleteForm::showRevision', [ &$archive, $this->mTargetObj
] ) ) {
1043 $rev = $archive->getRevision( $timestamp );
1045 $out = $this->getOutput();
1046 $user = $this->getUser();
1049 $out->addWikiMsg( 'undeleterevision-missing' );
1054 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1055 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1057 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1058 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1059 'rev-suppressed-text-permission' : 'rev-deleted-text-permission'
1066 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1067 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1068 'rev-suppressed-text-view' : 'rev-deleted-text-view'
1070 $out->addHTML( '<br />' );
1071 // and we are allowed to see...
1074 if ( $this->mDiff
) {
1075 $previousRev = $archive->getPreviousRevision( $timestamp );
1076 if ( $previousRev ) {
1077 $this->showDiff( $previousRev, $rev );
1078 if ( $this->mDiffOnly
) {
1082 $out->addHTML( '<hr />' );
1084 $out->addWikiMsg( 'undelete-nodiff' );
1088 $link = $this->getLinkRenderer()->makeKnownLink(
1089 $this->getPageTitle( $this->mTargetObj
->getPrefixedDBkey() ),
1090 $this->mTargetObj
->getPrefixedText()
1093 $lang = $this->getLanguage();
1095 // date and time are separate parameters to facilitate localisation.
1096 // $time is kept for backward compat reasons.
1097 $time = $lang->userTimeAndDate( $timestamp, $user );
1098 $d = $lang->userDate( $timestamp, $user );
1099 $t = $lang->userTime( $timestamp, $user );
1100 $userLink = Linker
::revUserTools( $rev );
1102 $content = $rev->getContent( Revision
::FOR_THIS_USER
, $user );
1104 $isText = ( $content instanceof TextContent
);
1106 if ( $this->mPreview ||
$isText ) {
1107 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
1109 $openDiv = '<div id="mw-undelete-revision">';
1111 $out->addHTML( $openDiv );
1113 // Revision delete links
1114 if ( !$this->mDiff
) {
1115 $revdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
1117 $out->addHTML( "$revdel " );
1121 $out->addHTML( $this->msg( 'undelete-revision' )->rawParams( $link )->params(
1122 $time )->rawParams( $userLink )->params( $d, $t )->parse() . '</div>' );
1124 if ( !Hooks
::run( 'UndeleteShowRevision', [ $this->mTargetObj
, $rev ] ) ) {
1128 if ( ( $this->mPreview ||
!$isText ) && $content ) {
1129 // NOTE: non-text content has no source view, so always use rendered preview
1132 $popts = $out->parserOptions();
1133 $popts->setEditSection( false );
1135 $pout = $content->getParserOutput( $this->mTargetObj
, $rev->getId(), $popts, true );
1136 $out->addParserOutput( $pout );
1140 // source view for textual content
1141 $sourceView = Xml
::element(
1144 'readonly' => 'readonly',
1148 $content->getNativeData() . "\n"
1151 $previewButton = Xml
::element( 'input', [
1153 'name' => 'preview',
1154 'value' => $this->msg( 'showpreview' )->text()
1158 $previewButton = '';
1161 $diffButton = Xml
::element( 'input', [
1164 'value' => $this->msg( 'showdiff' )->text() ] );
1168 Xml
::openElement( 'div', [
1169 'style' => 'clear: both' ] ) .
1170 Xml
::openElement( 'form', [
1172 'action' => $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] ) ] ) .
1173 Xml
::element( 'input', [
1176 'value' => $this->mTargetObj
->getPrefixedDBkey() ] ) .
1177 Xml
::element( 'input', [
1179 'name' => 'timestamp',
1180 'value' => $timestamp ] ) .
1181 Xml
::element( 'input', [
1183 'name' => 'wpEditToken',
1184 'value' => $user->getEditToken() ] ) .
1187 Xml
::closeElement( 'form' ) .
1188 Xml
::closeElement( 'div' )
1193 * Build a diff display between this and the previous either deleted
1194 * or non-deleted edit.
1196 * @param Revision $previousRev
1197 * @param Revision $currentRev
1198 * @return string HTML
1200 function showDiff( $previousRev, $currentRev ) {
1201 $diffContext = clone $this->getContext();
1202 $diffContext->setTitle( $currentRev->getTitle() );
1203 $diffContext->setWikiPage( WikiPage
::factory( $currentRev->getTitle() ) );
1205 $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
1206 $diffEngine->showDiffStyle();
1208 $formattedDiff = $diffEngine->generateContentDiffBody(
1209 $previousRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() ),
1210 $currentRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() )
1213 $formattedDiff = $diffEngine->addHeader(
1215 $this->diffHeader( $previousRev, 'o' ),
1216 $this->diffHeader( $currentRev, 'n' )
1219 $this->getOutput()->addHTML( "<div>$formattedDiff</div>\n" );
1223 * @param Revision $rev
1224 * @param string $prefix
1227 private function diffHeader( $rev, $prefix ) {
1228 $isDeleted = !( $rev->getId() && $rev->getTitle() );
1230 /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
1231 $targetPage = $this->getPageTitle();
1233 'target' => $this->mTargetObj
->getPrefixedText(),
1234 'timestamp' => wfTimestamp( TS_MW
, $rev->getTimestamp() )
1237 /// @todo FIXME: getId() may return non-zero for deleted revs...
1238 $targetPage = $rev->getTitle();
1239 $targetQuery = [ 'oldid' => $rev->getId() ];
1242 // Add show/hide deletion links if available
1243 $user = $this->getUser();
1244 $lang = $this->getLanguage();
1245 $rdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
1251 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
1253 $tags = wfGetDB( DB_REPLICA
)->selectField(
1256 [ 'ts_rev_id' => $rev->getId() ],
1259 $tagSummary = ChangeTags
::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() );
1261 // FIXME This is reimplementing DifferenceEngine#getRevisionHeader
1262 // and partially #showDiffPage, but worse
1263 return '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
1264 $this->getLinkRenderer()->makeLink(
1268 $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
1269 $lang->userDate( $rev->getTimestamp(), $user ),
1270 $lang->userTime( $rev->getTimestamp(), $user )
1276 '<div id="mw-diff-' . $prefix . 'title2">' .
1277 Linker
::revUserTools( $rev ) . '<br />' .
1279 '<div id="mw-diff-' . $prefix . 'title3">' .
1280 $minor . Linker
::revComment( $rev ) . $rdel . '<br />' .
1282 '<div id="mw-diff-' . $prefix . 'title5">' .
1283 $tagSummary[0] . '<br />' .
1288 * Show a form confirming whether a tokenless user really wants to see a file
1289 * @param string $key
1291 private function showFileConfirmationForm( $key ) {
1292 $out = $this->getOutput();
1293 $lang = $this->getLanguage();
1294 $user = $this->getUser();
1295 $file = new ArchivedFile( $this->mTargetObj
, '', $this->mFilename
);
1296 $out->addWikiMsg( 'undelete-show-file-confirm',
1297 $this->mTargetObj
->getText(),
1298 $lang->userDate( $file->getTimestamp(), $user ),
1299 $lang->userTime( $file->getTimestamp(), $user ) );
1301 Xml
::openElement( 'form', [
1303 'action' => $this->getPageTitle()->getLocalURL( [
1304 'target' => $this->mTarget
,
1306 'token' => $user->getEditToken( $key ),
1310 Xml
::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
1316 * Show a deleted file version requested by the visitor.
1317 * @param string $key
1319 private function showFile( $key ) {
1320 $this->getOutput()->disable();
1322 # We mustn't allow the output to be CDN cached, otherwise
1323 # if an admin previews a deleted image, and it's cached, then
1324 # a user without appropriate permissions can toddle off and
1325 # nab the image, and CDN will serve it
1326 $response = $this->getRequest()->response();
1327 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1328 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
1329 $response->header( 'Pragma: no-cache' );
1331 $repo = RepoGroup
::singleton()->getLocalRepo();
1332 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
1333 $repo->streamFile( $path );
1336 protected function showHistory() {
1337 $this->checkReadOnly();
1339 $out = $this->getOutput();
1340 if ( $this->mAllowed
) {
1341 $out->addModules( 'mediawiki.special.undelete' );
1344 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
1345 [ 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj
->getPrefixedText() ) ]
1348 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1349 Hooks
::run( 'UndeleteForm::showHistory', [ &$archive, $this->mTargetObj
] );
1351 $text = $archive->getLastRevisionText();
1352 if( is_null( $text ) ) {
1353 $out->addWikiMsg( 'nohistory' );
1357 $out->addHTML( '<div class="mw-undelete-history">' );
1358 if ( $this->mAllowed
) {
1359 $out->addWikiMsg( 'undeletehistory' );
1360 $out->addWikiMsg( 'undeleterevdel' );
1362 $out->addWikiMsg( 'undeletehistorynoadmin' );
1364 $out->addHTML( '</div>' );
1366 # List all stored revisions
1367 $revisions = $archive->listRevisions();
1368 $files = $archive->listFiles();
1370 $haveRevisions = $revisions && $revisions->numRows() > 0;
1371 $haveFiles = $files && $files->numRows() > 0;
1373 # Batch existence check on user and talk pages
1374 if ( $haveRevisions ) {
1375 $batch = new LinkBatch();
1376 foreach ( $revisions as $row ) {
1377 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
1378 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
1381 $revisions->seek( 0 );
1384 $batch = new LinkBatch();
1385 foreach ( $files as $row ) {
1386 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
1387 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
1393 if ( $this->mAllowed
) {
1394 $action = $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] );
1395 # Start the form here
1396 $top = Xml
::openElement(
1398 [ 'method' => 'post', 'action' => $action, 'id' => 'undelete' ]
1400 $out->addHTML( $top );
1403 # Show relevant lines from the deletion log:
1404 $deleteLogPage = new LogPage( 'delete' );
1405 $out->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) . "\n" );
1406 LogEventsList
::showLogExtract( $out, 'delete', $this->mTargetObj
);
1407 # Show relevant lines from the suppression log:
1408 $suppressLogPage = new LogPage( 'suppress' );
1409 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
1410 $out->addHTML( Xml
::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
1411 LogEventsList
::showLogExtract( $out, 'suppress', $this->mTargetObj
);
1414 if ( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
1415 # Format the user-visible controls (comment field, submission button)
1416 # in a nice little table
1417 if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
1421 <td class='mw-input'>" .
1422 Xml
::checkLabel( $this->msg( 'revdelete-unsuppress' )->text(),
1423 'wpUnsuppress', 'mw-undelete-unsuppress', $this->mUnsuppress
) .
1427 $unsuppressBox = '';
1430 $table = Xml
::fieldset( $this->msg( 'undelete-fieldset-title' )->text() ) .
1431 Xml
::openElement( 'table', [ 'id' => 'mw-undelete-table' ] ) .
1433 <td colspan='2' class='mw-undelete-extrahelp'>" .
1434 $this->msg( 'undeleteextrahelp' )->parseAsBlock() .
1438 <td class='mw-label'>" .
1439 Xml
::label( $this->msg( 'undeletecomment' )->text(), 'wpComment' ) .
1441 <td class='mw-input'>" .
1446 [ 'id' => 'wpComment', 'autofocus' => '' ]
1452 <td class='mw-submit'>" .
1454 $this->msg( 'undeletebtn' )->text(),
1455 [ 'name' => 'restore', 'id' => 'mw-undelete-submit' ]
1458 $this->msg( 'undeleteinvert' )->text(),
1459 [ 'name' => 'invert', 'id' => 'mw-undelete-invert' ]
1464 Xml
::closeElement( 'table' ) .
1465 Xml
::closeElement( 'fieldset' );
1467 $out->addHTML( $table );
1470 $out->addHTML( Xml
::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n" );
1472 if ( $haveRevisions ) {
1473 # Show the page's stored (deleted) history
1475 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
1476 $out->addHTML( Html
::element(
1481 'class' => 'deleterevision-log-submit mw-log-deleterevision-button'
1483 $this->msg( 'showhideselectedversions' )->text()
1487 $out->addHTML( '<ul>' );
1488 $remaining = $revisions->numRows();
1489 $earliestLiveTime = $this->mTargetObj
->getEarliestRevTime();
1491 foreach ( $revisions as $row ) {
1493 $out->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining ) );
1496 $out->addHTML( '</ul>' );
1498 $out->addWikiMsg( 'nohistory' );
1502 $out->addHTML( Xml
::element( 'h2', null, $this->msg( 'filehist' )->text() ) . "\n" );
1503 $out->addHTML( '<ul>' );
1504 foreach ( $files as $row ) {
1505 $out->addHTML( $this->formatFileRow( $row ) );
1508 $out->addHTML( '</ul>' );
1511 if ( $this->mAllowed
) {
1512 # Slip in the hidden controls here
1513 $misc = Html
::hidden( 'target', $this->mTarget
);
1514 $misc .= Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
1515 $misc .= Xml
::closeElement( 'form' );
1516 $out->addHTML( $misc );
1522 protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
1523 $rev = Revision
::newFromArchiveRow( $row,
1525 'title' => $this->mTargetObj
1529 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
1530 // Build checkboxen...
1531 if ( $this->mAllowed
) {
1532 if ( $this->mInvert
) {
1533 if ( in_array( $ts, $this->mTargetTimestamp
) ) {
1534 $checkBox = Xml
::check( "ts$ts" );
1536 $checkBox = Xml
::check( "ts$ts", true );
1539 $checkBox = Xml
::check( "ts$ts" );
1545 // Build page & diff links...
1546 $user = $this->getUser();
1547 if ( $this->mCanView
) {
1548 $titleObj = $this->getPageTitle();
1550 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
1551 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
1552 $last = $this->msg( 'diff' )->escaped();
1553 } elseif ( $remaining > 0 ||
( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
1554 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
1555 $last = $this->getLinkRenderer()->makeKnownLink(
1557 $this->msg( 'diff' )->text(),
1560 'target' => $this->mTargetObj
->getPrefixedText(),
1566 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
1567 $last = $this->msg( 'diff' )->escaped();
1570 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
1571 $last = $this->msg( 'diff' )->escaped();
1575 $userLink = Linker
::revUserTools( $rev );
1578 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
1580 // Revision text size
1581 $size = $row->ar_len
;
1582 if ( !is_null( $size ) ) {
1583 $revTextSize = Linker
::formatRevisionSize( $size );
1587 $comment = Linker
::revComment( $rev );
1591 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
1597 $attribs['class'] = implode( ' ', $classes );
1600 $revisionRow = $this->msg( 'undelete-revision-row2' )
1613 return Xml
::tags( 'li', $attribs, $revisionRow ) . "\n";
1616 private function formatFileRow( $row ) {
1617 $file = ArchivedFile
::newFromRow( $row );
1618 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
1619 $user = $this->getUser();
1622 if ( $this->mCanView
&& $row->fa_storage_key
) {
1623 if ( $this->mAllowed
) {
1624 $checkBox = Xml
::check( 'fileid' . $row->fa_id
);
1626 $key = urlencode( $row->fa_storage_key
);
1627 $pageLink = $this->getFileLink( $file, $this->getPageTitle(), $ts, $key );
1629 $pageLink = $this->getLanguage()->userTimeAndDate( $ts, $user );
1631 $userLink = $this->getFileUser( $file );
1632 $data = $this->msg( 'widthheight' )->numParams( $row->fa_width
, $row->fa_height
)->text();
1633 $bytes = $this->msg( 'parentheses' )
1634 ->rawParams( $this->msg( 'nbytes' )->numParams( $row->fa_size
)->text() )
1636 $data = htmlspecialchars( $data . ' ' . $bytes );
1637 $comment = $this->getFileComment( $file );
1639 // Add show/hide deletion links if available
1640 $canHide = $this->isAllowed( 'deleterevision' );
1641 if ( $canHide ||
( $file->getVisibility() && $this->isAllowed( 'deletedhistory' ) ) ) {
1642 if ( !$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
1643 // Revision was hidden from sysops
1644 $revdlink = Linker
::revDeleteLinkDisabled( $canHide );
1647 'type' => 'filearchive',
1648 'target' => $this->mTargetObj
->getPrefixedDBkey(),
1649 'ids' => $row->fa_id
1651 $revdlink = Linker
::revDeleteLink( $query,
1652 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1658 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1662 * Fetch revision text link if it's available to all users
1664 * @param Revision $rev
1665 * @param Title $titleObj
1666 * @param string $ts Timestamp
1669 function getPageLink( $rev, $titleObj, $ts ) {
1670 $user = $this->getUser();
1671 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1673 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1674 return '<span class="history-deleted">' . $time . '</span>';
1677 $link = $this->getLinkRenderer()->makeKnownLink(
1682 'target' => $this->mTargetObj
->getPrefixedText(),
1687 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1688 $link = '<span class="history-deleted">' . $link . '</span>';
1695 * Fetch image view link if it's available to all users
1697 * @param File|ArchivedFile $file
1698 * @param Title $titleObj
1699 * @param string $ts A timestamp
1700 * @param string $key A storage key
1702 * @return string HTML fragment
1704 function getFileLink( $file, $titleObj, $ts, $key ) {
1705 $user = $this->getUser();
1706 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1708 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
1709 return '<span class="history-deleted">' . $time . '</span>';
1712 $link = $this->getLinkRenderer()->makeKnownLink(
1717 'target' => $this->mTargetObj
->getPrefixedText(),
1719 'token' => $user->getEditToken( $key )
1723 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
1724 $link = '<span class="history-deleted">' . $link . '</span>';
1731 * Fetch file's user id if it's available to this user
1733 * @param File|ArchivedFile $file
1734 * @return string HTML fragment
1736 function getFileUser( $file ) {
1737 if ( !$file->userCan( File
::DELETED_USER
, $this->getUser() ) ) {
1738 return '<span class="history-deleted">' .
1739 $this->msg( 'rev-deleted-user' )->escaped() .
1743 $link = Linker
::userLink( $file->getRawUser(), $file->getRawUserText() ) .
1744 Linker
::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1746 if ( $file->isDeleted( File
::DELETED_USER
) ) {
1747 $link = '<span class="history-deleted">' . $link . '</span>';
1754 * Fetch file upload comment if it's available to this user
1756 * @param File|ArchivedFile $file
1757 * @return string HTML fragment
1759 function getFileComment( $file ) {
1760 if ( !$file->userCan( File
::DELETED_COMMENT
, $this->getUser() ) ) {
1761 return '<span class="history-deleted"><span class="comment">' .
1762 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></span>';
1765 $link = Linker
::commentBlock( $file->getRawDescription() );
1767 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
1768 $link = '<span class="history-deleted">' . $link . '</span>';
1774 function undelete() {
1775 if ( $this->getConfig()->get( 'UploadMaintenance' )
1776 && $this->mTargetObj
->getNamespace() == NS_FILE
1778 throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
1781 $this->checkReadOnly();
1783 $out = $this->getOutput();
1784 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1785 Hooks
::run( 'UndeleteForm::undelete', [ &$archive, $this->mTargetObj
] );
1786 $ok = $archive->undelete(
1787 $this->mTargetTimestamp
,
1789 $this->mFileVersions
,
1794 if ( is_array( $ok ) ) {
1795 if ( $ok[1] ) { // Undeleted file count
1796 Hooks
::run( 'FileUndeleteComplete', [
1797 $this->mTargetObj
, $this->mFileVersions
,
1798 $this->getUser(), $this->mComment
] );
1801 $link = $this->getLinkRenderer()->makeKnownLink( $this->mTargetObj
);
1802 $out->addHTML( $this->msg( 'undeletedpage' )->rawParams( $link )->parse() );
1804 $out->setPageTitle( $this->msg( 'undelete-error' ) );
1807 // Show revision undeletion warnings and errors
1808 $status = $archive->getRevisionStatus();
1809 if ( $status && !$status->isGood() ) {
1811 "<div class=\"error\" id=\"mw-error-cannotundelete\">\n$1\n</div>",
1816 // Show file undeletion warnings and errors
1817 $status = $archive->getFileStatus();
1818 if ( $status && !$status->isGood() ) {
1819 $out->addWikiText( '<div class="error">' .
1820 $status->getWikiText(
1821 'undelete-error-short',
1822 'undelete-error-long'
1829 * Return an array of subpages beginning with $search that this special page will accept.
1831 * @param string $search Prefix to search for
1832 * @param int $limit Maximum number of results to return (usually 10)
1833 * @param int $offset Number of results to skip (usually 0)
1834 * @return string[] Matching subpages
1836 public function prefixSearchSubpages( $search, $limit, $offset ) {
1837 return $this->prefixSearchString( $search, $limit, $offset );
1840 protected function getGroupName() {