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
25 * Used to show archived pages and eventually restore them.
27 * @ingroup SpecialPage
34 protected $fileStatus;
37 protected $revisionStatus;
42 function __construct( $title, Config
$config = null ) {
43 if ( is_null( $title ) ) {
44 throw new MWException( __METHOD__
. ' given a null title.' );
46 $this->title
= $title;
47 if ( $config === null ) {
48 wfDebug( __METHOD__
. ' did not have a Config object passed to it' );
49 $config = ConfigFactory
::getDefaultInstance()->makeConfig( 'main' );
51 $this->config
= $config;
54 public function doesWrites() {
59 * List all deleted pages recorded in the archive table. Returns result
60 * wrapper with (ar_namespace, ar_title, count) fields, ordered by page
63 * @return ResultWrapper
65 public static function listAllPages() {
66 $dbr = wfGetDB( DB_REPLICA
);
68 return self
::listPages( $dbr, '' );
72 * List deleted pages recorded in the archive table matching the
74 * Returns result wrapper with (ar_namespace, ar_title, count) fields.
76 * @param string $prefix Title prefix
77 * @return ResultWrapper
79 public static function listPagesByPrefix( $prefix ) {
80 $dbr = wfGetDB( DB_REPLICA
);
82 $title = Title
::newFromText( $prefix );
84 $ns = $title->getNamespace();
85 $prefix = $title->getDBkey();
87 // Prolly won't work too good
88 // @todo handle bare namespace names cleanly?
93 'ar_namespace' => $ns,
94 'ar_title' . $dbr->buildLike( $prefix, $dbr->anyString() ),
97 return self
::listPages( $dbr, $conds );
101 * @param IDatabase $dbr
102 * @param string|array $condition
103 * @return bool|ResultWrapper
105 protected static function listPages( $dbr, $condition ) {
111 'count' => 'COUNT(*)'
116 'GROUP BY' => [ 'ar_namespace', 'ar_title' ],
117 'ORDER BY' => [ 'ar_namespace', 'ar_title' ],
124 * List the revisions of the given page. Returns result wrapper with
125 * (ar_minor_edit, ar_timestamp, ar_user, ar_user_text, ar_comment) fields.
127 * @return ResultWrapper
129 function listRevisions() {
130 $dbr = wfGetDB( DB_REPLICA
);
132 $tables = [ 'archive' ];
135 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text',
136 'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1',
139 if ( $this->config
->get( 'ContentHandlerUseDB' ) ) {
140 $fields[] = 'ar_content_format';
141 $fields[] = 'ar_content_model';
144 $conds = [ 'ar_namespace' => $this->title
->getNamespace(),
145 'ar_title' => $this->title
->getDBkey() ];
147 $options = [ 'ORDER BY' => 'ar_timestamp DESC' ];
151 ChangeTags
::modifyDisplayQuery(
160 return $dbr->select( $tables,
170 * List the deleted file revisions for this page, if it's a file page.
171 * Returns a result wrapper with various filearchive fields, or null
172 * if not a file page.
174 * @return ResultWrapper
175 * @todo Does this belong in Image for fuller encapsulation?
177 function listFiles() {
178 if ( $this->title
->getNamespace() != NS_FILE
) {
182 $dbr = wfGetDB( DB_REPLICA
);
185 ArchivedFile
::selectFields(),
186 [ 'fa_name' => $this->title
->getDBkey() ],
188 [ 'ORDER BY' => 'fa_timestamp DESC' ]
193 * Return a Revision object containing data for the deleted revision.
194 * Note that the result *may* or *may not* have a null page ID.
196 * @param string $timestamp
197 * @return Revision|null
199 function getRevision( $timestamp ) {
200 $dbr = wfGetDB( DB_REPLICA
);
217 if ( $this->config
->get( 'ContentHandlerUseDB' ) ) {
218 $fields[] = 'ar_content_format';
219 $fields[] = 'ar_content_model';
222 $row = $dbr->selectRow( 'archive',
224 [ 'ar_namespace' => $this->title
->getNamespace(),
225 'ar_title' => $this->title
->getDBkey(),
226 'ar_timestamp' => $dbr->timestamp( $timestamp ) ],
230 return Revision
::newFromArchiveRow( $row, [ 'title' => $this->title
] );
237 * Return the most-previous revision, either live or deleted, against
238 * the deleted revision given by timestamp.
240 * May produce unexpected results in case of history merges or other
241 * unusual time issues.
243 * @param string $timestamp
244 * @return Revision|null Null when there is no previous revision
246 function getPreviousRevision( $timestamp ) {
247 $dbr = wfGetDB( DB_REPLICA
);
249 // Check the previous deleted revision...
250 $row = $dbr->selectRow( 'archive',
252 [ 'ar_namespace' => $this->title
->getNamespace(),
253 'ar_title' => $this->title
->getDBkey(),
255 $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ],
258 'ORDER BY' => 'ar_timestamp DESC',
260 $prevDeleted = $row ?
wfTimestamp( TS_MW
, $row->ar_timestamp
) : false;
262 $row = $dbr->selectRow( [ 'page', 'revision' ],
263 [ 'rev_id', 'rev_timestamp' ],
265 'page_namespace' => $this->title
->getNamespace(),
266 'page_title' => $this->title
->getDBkey(),
267 'page_id = rev_page',
269 $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ],
272 'ORDER BY' => 'rev_timestamp DESC',
274 $prevLive = $row ?
wfTimestamp( TS_MW
, $row->rev_timestamp
) : false;
275 $prevLiveId = $row ?
intval( $row->rev_id
) : null;
277 if ( $prevLive && $prevLive > $prevDeleted ) {
278 // Most prior revision was live
279 return Revision
::newFromId( $prevLiveId );
280 } elseif ( $prevDeleted ) {
281 // Most prior revision was deleted
282 return $this->getRevision( $prevDeleted );
285 // No prior revision on this page.
290 * Get the text from an archive row containing ar_text, ar_flags and ar_text_id
292 * @param object $row Database row
295 function getTextFromRow( $row ) {
296 if ( is_null( $row->ar_text_id
) ) {
297 // An old row from MediaWiki 1.4 or previous.
298 // Text is embedded in this row in classic compression format.
299 return Revision
::getRevisionText( $row, 'ar_' );
302 // New-style: keyed to the text storage backend.
303 $dbr = wfGetDB( DB_REPLICA
);
304 $text = $dbr->selectRow( 'text',
305 [ 'old_text', 'old_flags' ],
306 [ 'old_id' => $row->ar_text_id
],
309 return Revision
::getRevisionText( $text );
313 * Fetch (and decompress if necessary) the stored text of the most
314 * recently edited deleted revision of the page.
316 * If there are no archived revisions for the page, returns NULL.
318 * @return string|null
320 function getLastRevisionText() {
321 $dbr = wfGetDB( DB_REPLICA
);
322 $row = $dbr->selectRow( 'archive',
323 [ 'ar_text', 'ar_flags', 'ar_text_id' ],
324 [ 'ar_namespace' => $this->title
->getNamespace(),
325 'ar_title' => $this->title
->getDBkey() ],
327 [ 'ORDER BY' => 'ar_timestamp DESC' ] );
330 return $this->getTextFromRow( $row );
337 * Quick check if any archived revisions are present for the page.
341 function isDeleted() {
342 $dbr = wfGetDB( DB_REPLICA
);
343 $n = $dbr->selectField( 'archive', 'COUNT(ar_title)',
344 [ 'ar_namespace' => $this->title
->getNamespace(),
345 'ar_title' => $this->title
->getDBkey() ],
353 * Restore the given (or all) text and file revisions for the page.
354 * Once restored, the items will be removed from the archive tables.
355 * The deletion log will be updated with an undeletion notice.
357 * This also sets Status objects, $this->fileStatus and $this->revisionStatus
358 * (depending what operations are attempted).
360 * @param array $timestamps Pass an empty array to restore all revisions,
361 * otherwise list the ones to undelete.
362 * @param string $comment
363 * @param array $fileVersions
364 * @param bool $unsuppress
365 * @param User $user User performing the action, or null to use $wgUser
366 * @param string|string[] $tags Change tags to add to log entry
367 * ($user should be able to add the specified tags before this is called)
368 * @return array(number of file revisions restored, number of image revisions
369 * restored, log message) on success, false on failure.
371 function undelete( $timestamps, $comment = '', $fileVersions = [],
372 $unsuppress = false, User
$user = null, $tags = null
374 // If both the set of text revisions and file revisions are empty,
375 // restore everything. Otherwise, just restore the requested items.
376 $restoreAll = empty( $timestamps ) && empty( $fileVersions );
378 $restoreText = $restoreAll ||
!empty( $timestamps );
379 $restoreFiles = $restoreAll ||
!empty( $fileVersions );
381 if ( $restoreFiles && $this->title
->getNamespace() == NS_FILE
) {
382 $img = wfLocalFile( $this->title
);
383 $img->load( File
::READ_LATEST
);
384 $this->fileStatus
= $img->restore( $fileVersions, $unsuppress );
385 if ( !$this->fileStatus
->isOK() ) {
388 $filesRestored = $this->fileStatus
->successCount
;
393 if ( $restoreText ) {
394 $this->revisionStatus
= $this->undeleteRevisions( $timestamps, $unsuppress, $comment );
395 if ( !$this->revisionStatus
->isOK() ) {
399 $textRestored = $this->revisionStatus
->getValue();
406 if ( $textRestored && $filesRestored ) {
407 $reason = wfMessage( 'undeletedrevisions-files' )
408 ->numParams( $textRestored, $filesRestored )->inContentLanguage()->text();
409 } elseif ( $textRestored ) {
410 $reason = wfMessage( 'undeletedrevisions' )->numParams( $textRestored )
411 ->inContentLanguage()->text();
412 } elseif ( $filesRestored ) {
413 $reason = wfMessage( 'undeletedfiles' )->numParams( $filesRestored )
414 ->inContentLanguage()->text();
416 wfDebug( "Undelete: nothing undeleted...\n" );
421 if ( trim( $comment ) != '' ) {
422 $reason .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $comment;
425 if ( $user === null ) {
430 $logEntry = new ManualLogEntry( 'delete', 'restore' );
431 $logEntry->setPerformer( $user );
432 $logEntry->setTarget( $this->title
);
433 $logEntry->setComment( $reason );
434 $logEntry->setTags( $tags );
436 Hooks
::run( 'ArticleUndeleteLogEntry', [ $this, &$logEntry, $user ] );
438 $logid = $logEntry->insert();
439 $logEntry->publish( $logid );
441 return [ $textRestored, $filesRestored, $reason ];
445 * This is the meaty bit -- It restores archived revisions of the given page
446 * to the revision table.
448 * @param array $timestamps Pass an empty array to restore all revisions,
449 * otherwise list the ones to undelete.
450 * @param bool $unsuppress Remove all ar_deleted/fa_deleted restrictions of seletected revs
451 * @param string $comment
452 * @throws ReadOnlyError
453 * @return Status Status object containing the number of revisions restored on success
455 private function undeleteRevisions( $timestamps, $unsuppress = false, $comment = '' ) {
456 if ( wfReadOnly() ) {
457 throw new ReadOnlyError();
460 $dbw = wfGetDB( DB_MASTER
);
461 $dbw->startAtomic( __METHOD__
);
463 $restoreAll = empty( $timestamps );
465 # Does this page already exist? We'll have to update it...
466 $article = WikiPage
::factory( $this->title
);
467 # Load latest data for the current page (bug 31179)
468 $article->loadPageData( 'fromdbmaster' );
469 $oldcountable = $article->isCountable();
471 $page = $dbw->selectRow( 'page',
472 [ 'page_id', 'page_latest' ],
473 [ 'page_namespace' => $this->title
->getNamespace(),
474 'page_title' => $this->title
->getDBkey() ],
476 [ 'FOR UPDATE' ] // lock page
481 # Page already exists. Import the history, and if necessary
482 # we'll update the latest revision field in the record.
484 # Get the time span of this page
485 $previousTimestamp = $dbw->selectField( 'revision', 'rev_timestamp',
486 [ 'rev_id' => $page->page_latest
],
489 if ( $previousTimestamp === false ) {
490 wfDebug( __METHOD__
. ": existing page refers to a page_latest that does not exist\n" );
492 $status = Status
::newGood( 0 );
493 $status->warning( 'undeleterevision-missing' );
494 $dbw->endAtomic( __METHOD__
);
499 # Have to create a new article...
501 $previousTimestamp = 0;
505 'ar_namespace' => $this->title
->getNamespace(),
506 'ar_title' => $this->title
->getDBkey(),
508 if ( !$restoreAll ) {
509 $oldWhere['ar_timestamp'] = array_map( [ &$dbw, 'timestamp' ], $timestamps );
530 if ( $this->config
->get( 'ContentHandlerUseDB' ) ) {
531 $fields[] = 'ar_content_format';
532 $fields[] = 'ar_content_model';
536 * Select each archived revision...
538 $result = $dbw->select(
539 [ 'archive', 'revision' ],
544 [ 'ORDER BY' => 'ar_timestamp' ],
545 [ 'revision' => [ 'LEFT JOIN', 'ar_rev_id=rev_id' ] ]
548 $rev_count = $result->numRows();
550 wfDebug( __METHOD__
. ": no revisions to restore\n" );
552 $status = Status
::newGood( 0 );
553 $status->warning( "undelete-no-results" );
554 $dbw->endAtomic( __METHOD__
);
559 // We use ar_id because there can be duplicate ar_rev_id even for the same
560 // page. In this case, we may be able to restore the first one.
561 $restoreFailedArIds = [];
563 // Map rev_id to the ar_id that is allowed to use it. When checking later,
564 // if it doesn't match, the current ar_id can not be restored.
566 // Value can be an ar_id or -1 (-1 means no ar_id can use it, since the
567 // rev_id is taken before we even start the restore).
568 $allowedRevIdToArIdMap = [];
570 $latestRestorableRow = null;
572 foreach ( $result as $row ) {
573 if ( $row->ar_rev_id
) {
574 // rev_id is taken even before we start restoring.
575 if ( $row->ar_rev_id
=== $row->rev_id
) {
576 $restoreFailedArIds[] = $row->ar_id
;
577 $allowedRevIdToArIdMap[$row->ar_rev_id
] = -1;
579 // rev_id is not taken yet in the DB, but it might be taken
580 // by a prior revision in the same restore operation. If
581 // not, we need to reserve it.
582 if ( isset( $allowedRevIdToArIdMap[$row->ar_rev_id
] ) ) {
583 $restoreFailedArIds[] = $row->ar_id
;
585 $allowedRevIdToArIdMap[$row->ar_rev_id
] = $row->ar_id
;
586 $latestRestorableRow = $row;
590 // If ar_rev_id is null, there can't be a collision, and a
591 // rev_id will be chosen automatically.
592 $latestRestorableRow = $row;
596 $result->seek( 0 ); // move back
599 if ( $latestRestorableRow !== null ) {
600 $oldPageId = (int)$latestRestorableRow->ar_page_id
; // pass this to ArticleUndelete hook
602 // grab the content to check consistency with global state before restoring the page.
603 $revision = Revision
::newFromArchiveRow( $latestRestorableRow,
605 'title' => $article->getTitle(), // used to derive default content model
608 $user = User
::newFromName( $revision->getUserText( Revision
::RAW
), false );
609 $content = $revision->getContent( Revision
::RAW
);
611 // NOTE: article ID may not be known yet. prepareSave() should not modify the database.
612 $status = $content->prepareSave( $article, 0, -1, $user );
613 if ( !$status->isOK() ) {
614 $dbw->endAtomic( __METHOD__
);
620 $newid = false; // newly created page ID
621 $restored = 0; // number of revisions restored
622 /** @var Revision $revision */
625 // If there are no restorable revisions, we can skip most of the steps.
626 if ( $latestRestorableRow === null ) {
627 $failedRevisionCount = $rev_count;
630 // Check the state of the newest to-be version...
632 && ( $latestRestorableRow->ar_deleted
& Revision
::DELETED_TEXT
)
634 $dbw->endAtomic( __METHOD__
);
636 return Status
::newFatal( "undeleterevdel" );
638 // Safe to insert now...
639 $newid = $article->insertOn( $dbw, $latestRestorableRow->ar_page_id
);
640 if ( $newid === false ) {
641 // The old ID is reserved; let's pick another
642 $newid = $article->insertOn( $dbw );
646 // Check if a deleted revision will become the current revision...
647 if ( $latestRestorableRow->ar_timestamp
> $previousTimestamp ) {
648 // Check the state of the newest to-be version...
650 && ( $latestRestorableRow->ar_deleted
& Revision
::DELETED_TEXT
)
652 $dbw->endAtomic( __METHOD__
);
654 return Status
::newFatal( "undeleterevdel" );
659 $pageId = $article->getId();
662 foreach ( $result as $row ) {
663 // Check for key dupes due to needed archive integrity.
664 if ( $row->ar_rev_id
&& $allowedRevIdToArIdMap[$row->ar_rev_id
] !== $row->ar_id
) {
667 // Insert one revision at a time...maintaining deletion status
668 // unless we are specifically removing all restrictions...
669 $revision = Revision
::newFromArchiveRow( $row,
672 'title' => $this->title
,
673 'deleted' => $unsuppress ?
0 : $row->ar_deleted
676 $revision->insertOn( $dbw );
679 Hooks
::run( 'ArticleRevisionUndeleted',
680 [ &$this->title
, $revision, $row->ar_page_id
] );
683 // Now that it's safely stored, take it out of the archive
684 // Don't delete rows that we failed to restore
685 $toDeleteConds = $oldWhere;
686 $failedRevisionCount = count( $restoreFailedArIds );
687 if ( $failedRevisionCount > 0 ) {
688 $toDeleteConds[] = 'ar_id NOT IN ( ' . $dbw->makeList( $restoreFailedArIds ) . ' )';
691 $dbw->delete( 'archive',
696 $status = Status
::newGood( $restored );
698 if ( $failedRevisionCount > 0 ) {
700 wfMessage( 'undeleterevision-duplicate-revid', $failedRevisionCount ) );
703 // Was anything restored at all?
705 $created = (bool)$newid;
706 // Attach the latest revision to the page...
707 $wasnew = $article->updateIfNewerOn( $dbw, $revision );
708 if ( $created ||
$wasnew ) {
709 // Update site stats, link tables, etc
710 $article->doEditUpdates(
712 User
::newFromName( $revision->getUserText( Revision
::RAW
), false ),
714 'created' => $created,
715 'oldcountable' => $oldcountable,
721 Hooks
::run( 'ArticleUndelete', [ &$this->title
, $created, $comment, $oldPageId ] );
722 if ( $this->title
->getNamespace() == NS_FILE
) {
723 DeferredUpdates
::addUpdate( new HTMLCacheUpdate( $this->title
, 'imagelinks' ) );
727 $dbw->endAtomic( __METHOD__
);
735 function getFileStatus() {
736 return $this->fileStatus
;
742 function getRevisionStatus() {
743 return $this->revisionStatus
;
748 * Special page allowing users with the appropriate permissions to view
749 * and restore deleted content.
751 * @ingroup SpecialPage
753 class SpecialUndelete
extends SpecialPage
{
761 private $mTargetTimestamp;
770 function __construct() {
771 parent
::__construct( 'Undelete', 'deletedhistory' );
774 public function doesWrites() {
778 function loadRequest( $par ) {
779 $request = $this->getRequest();
780 $user = $this->getUser();
782 $this->mAction
= $request->getVal( 'action' );
783 if ( $par !== null && $par !== '' ) {
784 $this->mTarget
= $par;
786 $this->mTarget
= $request->getVal( 'target' );
789 $this->mTargetObj
= null;
791 if ( $this->mTarget
!== null && $this->mTarget
!== '' ) {
792 $this->mTargetObj
= Title
::newFromText( $this->mTarget
);
795 $this->mSearchPrefix
= $request->getText( 'prefix' );
796 $time = $request->getVal( 'timestamp' );
797 $this->mTimestamp
= $time ?
wfTimestamp( TS_MW
, $time ) : '';
798 $this->mFilename
= $request->getVal( 'file' );
800 $posted = $request->wasPosted() &&
801 $user->matchEditToken( $request->getVal( 'wpEditToken' ) );
802 $this->mRestore
= $request->getCheck( 'restore' ) && $posted;
803 $this->mRevdel
= $request->getCheck( 'revdel' ) && $posted;
804 $this->mInvert
= $request->getCheck( 'invert' ) && $posted;
805 $this->mPreview
= $request->getCheck( 'preview' ) && $posted;
806 $this->mDiff
= $request->getCheck( 'diff' );
807 $this->mDiffOnly
= $request->getBool( 'diffonly', $this->getUser()->getOption( 'diffonly' ) );
808 $this->mComment
= $request->getText( 'wpComment' );
809 $this->mUnsuppress
= $request->getVal( 'wpUnsuppress' ) && $user->isAllowed( 'suppressrevision' );
810 $this->mToken
= $request->getVal( 'token' );
812 if ( $this->isAllowed( 'undelete' ) && !$user->isBlocked() ) {
813 $this->mAllowed
= true; // user can restore
814 $this->mCanView
= true; // user can view content
815 } elseif ( $this->isAllowed( 'deletedtext' ) ) {
816 $this->mAllowed
= false; // user cannot restore
817 $this->mCanView
= true; // user can view content
818 $this->mRestore
= false;
819 } else { // user can only view the list of revisions
820 $this->mAllowed
= false;
821 $this->mCanView
= false;
822 $this->mTimestamp
= '';
823 $this->mRestore
= false;
826 if ( $this->mRestore ||
$this->mInvert
) {
828 $this->mFileVersions
= [];
829 foreach ( $request->getValues() as $key => $val ) {
831 if ( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
832 array_push( $timestamps, $matches[1] );
835 if ( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
836 $this->mFileVersions
[] = intval( $matches[1] );
839 rsort( $timestamps );
840 $this->mTargetTimestamp
= $timestamps;
845 * Checks whether a user is allowed the permission for the
846 * specific title if one is set.
848 * @param string $permission
852 protected function isAllowed( $permission, User
$user = null ) {
853 $user = $user ?
: $this->getUser();
854 if ( $this->mTargetObj
!== null ) {
855 return $this->mTargetObj
->userCan( $permission, $user );
857 return $user->isAllowed( $permission );
861 function userCanExecute( User
$user ) {
862 return $this->isAllowed( $this->mRestriction
, $user );
865 function execute( $par ) {
866 $this->useTransactionalTimeLimit();
868 $user = $this->getUser();
871 $this->outputHeader();
873 $this->loadRequest( $par );
874 $this->checkPermissions(); // Needs to be after mTargetObj is set
876 $out = $this->getOutput();
878 if ( is_null( $this->mTargetObj
) ) {
879 $out->addWikiMsg( 'undelete-header' );
881 # Not all users can just browse every deleted page from the list
882 if ( $user->isAllowed( 'browsearchive' ) ) {
883 $this->showSearchForm();
889 $this->addHelpLink( 'Help:Undelete' );
890 if ( $this->mAllowed
) {
891 $out->setPageTitle( $this->msg( 'undeletepage' ) );
893 $out->setPageTitle( $this->msg( 'viewdeletedpage' ) );
896 $this->getSkin()->setRelevantTitle( $this->mTargetObj
);
898 if ( $this->mTimestamp
!== '' ) {
899 $this->showRevision( $this->mTimestamp
);
900 } elseif ( $this->mFilename
!== null && $this->mTargetObj
->inNamespace( NS_FILE
) ) {
901 $file = new ArchivedFile( $this->mTargetObj
, '', $this->mFilename
);
902 // Check if user is allowed to see this file
903 if ( !$file->exists() ) {
904 $out->addWikiMsg( 'filedelete-nofile', $this->mFilename
);
905 } elseif ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
906 if ( $file->isDeleted( File
::DELETED_RESTRICTED
) ) {
907 throw new PermissionsError( 'suppressrevision' );
909 throw new PermissionsError( 'deletedtext' );
911 } elseif ( !$user->matchEditToken( $this->mToken
, $this->mFilename
) ) {
912 $this->showFileConfirmationForm( $this->mFilename
);
914 $this->showFile( $this->mFilename
);
916 } elseif ( $this->mAction
=== "submit" ) {
917 if ( $this->mRestore
) {
919 } elseif ( $this->mRevdel
) {
920 $this->redirectToRevDel();
924 $this->showHistory();
929 * Convert submitted form data to format expected by RevisionDelete and
930 * redirect the request
932 private function redirectToRevDel() {
933 $archive = new PageArchive( $this->mTargetObj
);
937 foreach ( $this->getRequest()->getValues() as $key => $val ) {
939 if ( preg_match( "/^ts(\d{14})$/", $key, $matches ) ) {
940 $revisions[ $archive->getRevision( $matches[1] )->getId() ] = 1;
944 "type" => "revision",
946 "target" => $this->mTargetObj
->getPrefixedText()
948 $url = SpecialPage
::getTitleFor( 'Revisiondelete' )->getFullURL( $query );
949 $this->getOutput()->redirect( $url );
952 function showSearchForm() {
953 $out = $this->getOutput();
954 $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
956 Xml
::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] ) .
957 Xml
::fieldset( $this->msg( 'undelete-search-box' )->text() ) .
958 Html
::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
961 [ 'for' => 'prefix' ],
962 $this->msg( 'undelete-search-prefix' )->parse()
967 $this->mSearchPrefix
,
968 [ 'id' => 'prefix', 'autofocus' => '' ]
970 Xml
::submitButton( $this->msg( 'undelete-search-submit' )->text() ) .
971 Xml
::closeElement( 'fieldset' ) .
972 Xml
::closeElement( 'form' )
975 # List undeletable articles
976 if ( $this->mSearchPrefix
) {
977 $result = PageArchive
::listPagesByPrefix( $this->mSearchPrefix
);
978 $this->showList( $result );
983 * Generic list of deleted pages
985 * @param ResultWrapper $result
988 private function showList( $result ) {
989 $out = $this->getOutput();
991 if ( $result->numRows() == 0 ) {
992 $out->addWikiMsg( 'undelete-no-results' );
997 $out->addWikiMsg( 'undeletepagetext', $this->getLanguage()->formatNum( $result->numRows() ) );
999 $undelete = $this->getPageTitle();
1000 $out->addHTML( "<ul>\n" );
1001 foreach ( $result as $row ) {
1002 $title = Title
::makeTitleSafe( $row->ar_namespace
, $row->ar_title
);
1003 if ( $title !== null ) {
1004 $item = Linker
::linkKnown(
1006 htmlspecialchars( $title->getPrefixedText() ),
1008 [ 'target' => $title->getPrefixedText() ]
1011 // The title is no longer valid, show as text
1012 $item = Html
::element(
1014 [ 'class' => 'mw-invalidtitle' ],
1015 Linker
::getInvalidTitleDescription(
1016 $this->getContext(),
1022 $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count
)->parse();
1023 $out->addHTML( "<li>{$item} ({$revs})</li>\n" );
1026 $out->addHTML( "</ul>\n" );
1031 private function showRevision( $timestamp ) {
1032 if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
1036 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1037 if ( !Hooks
::run( 'UndeleteForm::showRevision', [ &$archive, $this->mTargetObj
] ) ) {
1040 $rev = $archive->getRevision( $timestamp );
1042 $out = $this->getOutput();
1043 $user = $this->getUser();
1046 $out->addWikiMsg( 'undeleterevision-missing' );
1051 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1052 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1054 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1055 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1056 'rev-suppressed-text-permission' : 'rev-deleted-text-permission'
1063 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1064 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1065 'rev-suppressed-text-view' : 'rev-deleted-text-view'
1067 $out->addHTML( '<br />' );
1068 // and we are allowed to see...
1071 if ( $this->mDiff
) {
1072 $previousRev = $archive->getPreviousRevision( $timestamp );
1073 if ( $previousRev ) {
1074 $this->showDiff( $previousRev, $rev );
1075 if ( $this->mDiffOnly
) {
1079 $out->addHTML( '<hr />' );
1081 $out->addWikiMsg( 'undelete-nodiff' );
1085 $link = Linker
::linkKnown(
1086 $this->getPageTitle( $this->mTargetObj
->getPrefixedDBkey() ),
1087 htmlspecialchars( $this->mTargetObj
->getPrefixedText() )
1090 $lang = $this->getLanguage();
1092 // date and time are separate parameters to facilitate localisation.
1093 // $time is kept for backward compat reasons.
1094 $time = $lang->userTimeAndDate( $timestamp, $user );
1095 $d = $lang->userDate( $timestamp, $user );
1096 $t = $lang->userTime( $timestamp, $user );
1097 $userLink = Linker
::revUserTools( $rev );
1099 $content = $rev->getContent( Revision
::FOR_THIS_USER
, $user );
1101 $isText = ( $content instanceof TextContent
);
1103 if ( $this->mPreview ||
$isText ) {
1104 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
1106 $openDiv = '<div id="mw-undelete-revision">';
1108 $out->addHTML( $openDiv );
1110 // Revision delete links
1111 if ( !$this->mDiff
) {
1112 $revdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
1114 $out->addHTML( "$revdel " );
1118 $out->addHTML( $this->msg( 'undelete-revision' )->rawParams( $link )->params(
1119 $time )->rawParams( $userLink )->params( $d, $t )->parse() . '</div>' );
1121 if ( !Hooks
::run( 'UndeleteShowRevision', [ $this->mTargetObj
, $rev ] ) ) {
1125 if ( ( $this->mPreview ||
!$isText ) && $content ) {
1126 // NOTE: non-text content has no source view, so always use rendered preview
1129 $popts = $out->parserOptions();
1130 $popts->setEditSection( false );
1132 $pout = $content->getParserOutput( $this->mTargetObj
, $rev->getId(), $popts, true );
1133 $out->addParserOutput( $pout );
1137 // source view for textual content
1138 $sourceView = Xml
::element(
1141 'readonly' => 'readonly',
1142 'cols' => $user->getIntOption( 'cols' ),
1143 'rows' => $user->getIntOption( 'rows' )
1145 $content->getNativeData() . "\n"
1148 $previewButton = Xml
::element( 'input', [
1150 'name' => 'preview',
1151 'value' => $this->msg( 'showpreview' )->text()
1155 $previewButton = '';
1158 $diffButton = Xml
::element( 'input', [
1161 'value' => $this->msg( 'showdiff' )->text() ] );
1165 Xml
::openElement( 'div', [
1166 'style' => 'clear: both' ] ) .
1167 Xml
::openElement( 'form', [
1169 'action' => $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] ) ] ) .
1170 Xml
::element( 'input', [
1173 'value' => $this->mTargetObj
->getPrefixedDBkey() ] ) .
1174 Xml
::element( 'input', [
1176 'name' => 'timestamp',
1177 'value' => $timestamp ] ) .
1178 Xml
::element( 'input', [
1180 'name' => 'wpEditToken',
1181 'value' => $user->getEditToken() ] ) .
1184 Xml
::closeElement( 'form' ) .
1185 Xml
::closeElement( 'div' )
1190 * Build a diff display between this and the previous either deleted
1191 * or non-deleted edit.
1193 * @param Revision $previousRev
1194 * @param Revision $currentRev
1195 * @return string HTML
1197 function showDiff( $previousRev, $currentRev ) {
1198 $diffContext = clone $this->getContext();
1199 $diffContext->setTitle( $currentRev->getTitle() );
1200 $diffContext->setWikiPage( WikiPage
::factory( $currentRev->getTitle() ) );
1202 $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
1203 $diffEngine->showDiffStyle();
1205 $formattedDiff = $diffEngine->generateContentDiffBody(
1206 $previousRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() ),
1207 $currentRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() )
1210 $formattedDiff = $diffEngine->addHeader(
1212 $this->diffHeader( $previousRev, 'o' ),
1213 $this->diffHeader( $currentRev, 'n' )
1216 $this->getOutput()->addHTML( "<div>$formattedDiff</div>\n" );
1220 * @param Revision $rev
1221 * @param string $prefix
1224 private function diffHeader( $rev, $prefix ) {
1225 $isDeleted = !( $rev->getId() && $rev->getTitle() );
1227 /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
1228 $targetPage = $this->getPageTitle();
1230 'target' => $this->mTargetObj
->getPrefixedText(),
1231 'timestamp' => wfTimestamp( TS_MW
, $rev->getTimestamp() )
1234 /// @todo FIXME: getId() may return non-zero for deleted revs...
1235 $targetPage = $rev->getTitle();
1236 $targetQuery = [ 'oldid' => $rev->getId() ];
1239 // Add show/hide deletion links if available
1240 $user = $this->getUser();
1241 $lang = $this->getLanguage();
1242 $rdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
1248 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
1250 $tags = wfGetDB( DB_REPLICA
)->selectField(
1253 [ 'ts_rev_id' => $rev->getId() ],
1256 $tagSummary = ChangeTags
::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() );
1258 // FIXME This is reimplementing DifferenceEngine#getRevisionHeader
1259 // and partially #showDiffPage, but worse
1260 return '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
1265 $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
1266 $lang->userDate( $rev->getTimestamp(), $user ),
1267 $lang->userTime( $rev->getTimestamp(), $user )
1273 '<div id="mw-diff-' . $prefix . 'title2">' .
1274 Linker
::revUserTools( $rev ) . '<br />' .
1276 '<div id="mw-diff-' . $prefix . 'title3">' .
1277 $minor . Linker
::revComment( $rev ) . $rdel . '<br />' .
1279 '<div id="mw-diff-' . $prefix . 'title5">' .
1280 $tagSummary[0] . '<br />' .
1285 * Show a form confirming whether a tokenless user really wants to see a file
1286 * @param string $key
1288 private function showFileConfirmationForm( $key ) {
1289 $out = $this->getOutput();
1290 $lang = $this->getLanguage();
1291 $user = $this->getUser();
1292 $file = new ArchivedFile( $this->mTargetObj
, '', $this->mFilename
);
1293 $out->addWikiMsg( 'undelete-show-file-confirm',
1294 $this->mTargetObj
->getText(),
1295 $lang->userDate( $file->getTimestamp(), $user ),
1296 $lang->userTime( $file->getTimestamp(), $user ) );
1298 Xml
::openElement( 'form', [
1300 'action' => $this->getPageTitle()->getLocalURL( [
1301 'target' => $this->mTarget
,
1303 'token' => $user->getEditToken( $key ),
1307 Xml
::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
1313 * Show a deleted file version requested by the visitor.
1314 * @param string $key
1316 private function showFile( $key ) {
1317 $this->getOutput()->disable();
1319 # We mustn't allow the output to be CDN cached, otherwise
1320 # if an admin previews a deleted image, and it's cached, then
1321 # a user without appropriate permissions can toddle off and
1322 # nab the image, and CDN will serve it
1323 $response = $this->getRequest()->response();
1324 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1325 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
1326 $response->header( 'Pragma: no-cache' );
1328 $repo = RepoGroup
::singleton()->getLocalRepo();
1329 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
1330 $repo->streamFile( $path );
1333 protected function showHistory() {
1334 $this->checkReadOnly();
1336 $out = $this->getOutput();
1337 if ( $this->mAllowed
) {
1338 $out->addModules( 'mediawiki.special.undelete' );
1341 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
1342 [ 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj
->getPrefixedText() ) ]
1345 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1346 Hooks
::run( 'UndeleteForm::showHistory', [ &$archive, $this->mTargetObj
] );
1348 $text = $archive->getLastRevisionText();
1349 if( is_null( $text ) ) {
1350 $out->addWikiMsg( 'nohistory' );
1354 $out->addHTML( '<div class="mw-undelete-history">' );
1355 if ( $this->mAllowed
) {
1356 $out->addWikiMsg( 'undeletehistory' );
1357 $out->addWikiMsg( 'undeleterevdel' );
1359 $out->addWikiMsg( 'undeletehistorynoadmin' );
1361 $out->addHTML( '</div>' );
1363 # List all stored revisions
1364 $revisions = $archive->listRevisions();
1365 $files = $archive->listFiles();
1367 $haveRevisions = $revisions && $revisions->numRows() > 0;
1368 $haveFiles = $files && $files->numRows() > 0;
1370 # Batch existence check on user and talk pages
1371 if ( $haveRevisions ) {
1372 $batch = new LinkBatch();
1373 foreach ( $revisions as $row ) {
1374 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
1375 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
1378 $revisions->seek( 0 );
1381 $batch = new LinkBatch();
1382 foreach ( $files as $row ) {
1383 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
1384 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
1390 if ( $this->mAllowed
) {
1391 $action = $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] );
1392 # Start the form here
1393 $top = Xml
::openElement(
1395 [ 'method' => 'post', 'action' => $action, 'id' => 'undelete' ]
1397 $out->addHTML( $top );
1400 # Show relevant lines from the deletion log:
1401 $deleteLogPage = new LogPage( 'delete' );
1402 $out->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) . "\n" );
1403 LogEventsList
::showLogExtract( $out, 'delete', $this->mTargetObj
);
1404 # Show relevant lines from the suppression log:
1405 $suppressLogPage = new LogPage( 'suppress' );
1406 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
1407 $out->addHTML( Xml
::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
1408 LogEventsList
::showLogExtract( $out, 'suppress', $this->mTargetObj
);
1411 if ( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
1412 # Format the user-visible controls (comment field, submission button)
1413 # in a nice little table
1414 if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
1418 <td class='mw-input'>" .
1419 Xml
::checkLabel( $this->msg( 'revdelete-unsuppress' )->text(),
1420 'wpUnsuppress', 'mw-undelete-unsuppress', $this->mUnsuppress
) .
1424 $unsuppressBox = '';
1427 $table = Xml
::fieldset( $this->msg( 'undelete-fieldset-title' )->text() ) .
1428 Xml
::openElement( 'table', [ 'id' => 'mw-undelete-table' ] ) .
1430 <td colspan='2' class='mw-undelete-extrahelp'>" .
1431 $this->msg( 'undeleteextrahelp' )->parseAsBlock() .
1435 <td class='mw-label'>" .
1436 Xml
::label( $this->msg( 'undeletecomment' )->text(), 'wpComment' ) .
1438 <td class='mw-input'>" .
1443 [ 'id' => 'wpComment', 'autofocus' => '' ]
1449 <td class='mw-submit'>" .
1451 $this->msg( 'undeletebtn' )->text(),
1452 [ 'name' => 'restore', 'id' => 'mw-undelete-submit' ]
1455 $this->msg( 'undeleteinvert' )->text(),
1456 [ 'name' => 'invert', 'id' => 'mw-undelete-invert' ]
1461 Xml
::closeElement( 'table' ) .
1462 Xml
::closeElement( 'fieldset' );
1464 $out->addHTML( $table );
1467 $out->addHTML( Xml
::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n" );
1469 if ( $haveRevisions ) {
1470 # Show the page's stored (deleted) history
1472 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
1473 $out->addHTML( Html
::element(
1478 'class' => 'deleterevision-log-submit mw-log-deleterevision-button'
1480 $this->msg( 'showhideselectedversions' )->text()
1484 $out->addHTML( '<ul>' );
1485 $remaining = $revisions->numRows();
1486 $earliestLiveTime = $this->mTargetObj
->getEarliestRevTime();
1488 foreach ( $revisions as $row ) {
1490 $out->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining ) );
1493 $out->addHTML( '</ul>' );
1495 $out->addWikiMsg( 'nohistory' );
1499 $out->addHTML( Xml
::element( 'h2', null, $this->msg( 'filehist' )->text() ) . "\n" );
1500 $out->addHTML( '<ul>' );
1501 foreach ( $files as $row ) {
1502 $out->addHTML( $this->formatFileRow( $row ) );
1505 $out->addHTML( '</ul>' );
1508 if ( $this->mAllowed
) {
1509 # Slip in the hidden controls here
1510 $misc = Html
::hidden( 'target', $this->mTarget
);
1511 $misc .= Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
1512 $misc .= Xml
::closeElement( 'form' );
1513 $out->addHTML( $misc );
1519 protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
1520 $rev = Revision
::newFromArchiveRow( $row,
1522 'title' => $this->mTargetObj
1526 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
1527 // Build checkboxen...
1528 if ( $this->mAllowed
) {
1529 if ( $this->mInvert
) {
1530 if ( in_array( $ts, $this->mTargetTimestamp
) ) {
1531 $checkBox = Xml
::check( "ts$ts" );
1533 $checkBox = Xml
::check( "ts$ts", true );
1536 $checkBox = Xml
::check( "ts$ts" );
1542 // Build page & diff links...
1543 $user = $this->getUser();
1544 if ( $this->mCanView
) {
1545 $titleObj = $this->getPageTitle();
1547 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
1548 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
1549 $last = $this->msg( 'diff' )->escaped();
1550 } elseif ( $remaining > 0 ||
( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
1551 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
1552 $last = Linker
::linkKnown(
1554 $this->msg( 'diff' )->escaped(),
1557 'target' => $this->mTargetObj
->getPrefixedText(),
1563 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
1564 $last = $this->msg( 'diff' )->escaped();
1567 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
1568 $last = $this->msg( 'diff' )->escaped();
1572 $userLink = Linker
::revUserTools( $rev );
1575 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
1577 // Revision text size
1578 $size = $row->ar_len
;
1579 if ( !is_null( $size ) ) {
1580 $revTextSize = Linker
::formatRevisionSize( $size );
1584 $comment = Linker
::revComment( $rev );
1588 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
1594 $attribs['class'] = implode( ' ', $classes );
1597 $revisionRow = $this->msg( 'undelete-revision-row2' )
1610 return Xml
::tags( 'li', $attribs, $revisionRow ) . "\n";
1613 private function formatFileRow( $row ) {
1614 $file = ArchivedFile
::newFromRow( $row );
1615 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
1616 $user = $this->getUser();
1619 if ( $this->mCanView
&& $row->fa_storage_key
) {
1620 if ( $this->mAllowed
) {
1621 $checkBox = Xml
::check( 'fileid' . $row->fa_id
);
1623 $key = urlencode( $row->fa_storage_key
);
1624 $pageLink = $this->getFileLink( $file, $this->getPageTitle(), $ts, $key );
1626 $pageLink = $this->getLanguage()->userTimeAndDate( $ts, $user );
1628 $userLink = $this->getFileUser( $file );
1629 $data = $this->msg( 'widthheight' )->numParams( $row->fa_width
, $row->fa_height
)->text();
1630 $bytes = $this->msg( 'parentheses' )
1631 ->rawParams( $this->msg( 'nbytes' )->numParams( $row->fa_size
)->text() )
1633 $data = htmlspecialchars( $data . ' ' . $bytes );
1634 $comment = $this->getFileComment( $file );
1636 // Add show/hide deletion links if available
1637 $canHide = $this->isAllowed( 'deleterevision' );
1638 if ( $canHide ||
( $file->getVisibility() && $this->isAllowed( 'deletedhistory' ) ) ) {
1639 if ( !$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
1640 // Revision was hidden from sysops
1641 $revdlink = Linker
::revDeleteLinkDisabled( $canHide );
1644 'type' => 'filearchive',
1645 'target' => $this->mTargetObj
->getPrefixedDBkey(),
1646 'ids' => $row->fa_id
1648 $revdlink = Linker
::revDeleteLink( $query,
1649 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1655 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1659 * Fetch revision text link if it's available to all users
1661 * @param Revision $rev
1662 * @param Title $titleObj
1663 * @param string $ts Timestamp
1666 function getPageLink( $rev, $titleObj, $ts ) {
1667 $user = $this->getUser();
1668 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1670 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1671 return '<span class="history-deleted">' . $time . '</span>';
1674 $link = Linker
::linkKnown(
1676 htmlspecialchars( $time ),
1679 'target' => $this->mTargetObj
->getPrefixedText(),
1684 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1685 $link = '<span class="history-deleted">' . $link . '</span>';
1692 * Fetch image view link if it's available to all users
1694 * @param File|ArchivedFile $file
1695 * @param Title $titleObj
1696 * @param string $ts A timestamp
1697 * @param string $key A storage key
1699 * @return string HTML fragment
1701 function getFileLink( $file, $titleObj, $ts, $key ) {
1702 $user = $this->getUser();
1703 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1705 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
1706 return '<span class="history-deleted">' . $time . '</span>';
1709 $link = Linker
::linkKnown(
1711 htmlspecialchars( $time ),
1714 'target' => $this->mTargetObj
->getPrefixedText(),
1716 'token' => $user->getEditToken( $key )
1720 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
1721 $link = '<span class="history-deleted">' . $link . '</span>';
1728 * Fetch file's user id if it's available to this user
1730 * @param File|ArchivedFile $file
1731 * @return string HTML fragment
1733 function getFileUser( $file ) {
1734 if ( !$file->userCan( File
::DELETED_USER
, $this->getUser() ) ) {
1735 return '<span class="history-deleted">' .
1736 $this->msg( 'rev-deleted-user' )->escaped() .
1740 $link = Linker
::userLink( $file->getRawUser(), $file->getRawUserText() ) .
1741 Linker
::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1743 if ( $file->isDeleted( File
::DELETED_USER
) ) {
1744 $link = '<span class="history-deleted">' . $link . '</span>';
1751 * Fetch file upload comment if it's available to this user
1753 * @param File|ArchivedFile $file
1754 * @return string HTML fragment
1756 function getFileComment( $file ) {
1757 if ( !$file->userCan( File
::DELETED_COMMENT
, $this->getUser() ) ) {
1758 return '<span class="history-deleted"><span class="comment">' .
1759 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></span>';
1762 $link = Linker
::commentBlock( $file->getRawDescription() );
1764 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
1765 $link = '<span class="history-deleted">' . $link . '</span>';
1771 function undelete() {
1772 if ( $this->getConfig()->get( 'UploadMaintenance' )
1773 && $this->mTargetObj
->getNamespace() == NS_FILE
1775 throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
1778 $this->checkReadOnly();
1780 $out = $this->getOutput();
1781 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1782 Hooks
::run( 'UndeleteForm::undelete', [ &$archive, $this->mTargetObj
] );
1783 $ok = $archive->undelete(
1784 $this->mTargetTimestamp
,
1786 $this->mFileVersions
,
1791 if ( is_array( $ok ) ) {
1792 if ( $ok[1] ) { // Undeleted file count
1793 Hooks
::run( 'FileUndeleteComplete', [
1794 $this->mTargetObj
, $this->mFileVersions
,
1795 $this->getUser(), $this->mComment
] );
1798 $link = Linker
::linkKnown( $this->mTargetObj
);
1799 $out->addHTML( $this->msg( 'undeletedpage' )->rawParams( $link )->parse() );
1801 $out->setPageTitle( $this->msg( 'undelete-error' ) );
1804 // Show revision undeletion warnings and errors
1805 $status = $archive->getRevisionStatus();
1806 if ( $status && !$status->isGood() ) {
1807 $out->addWikiText( '<div class="error">' .
1808 $status->getWikiText(
1815 // Show file undeletion warnings and errors
1816 $status = $archive->getFileStatus();
1817 if ( $status && !$status->isGood() ) {
1818 $out->addWikiText( '<div class="error">' .
1819 $status->getWikiText(
1820 'undelete-error-short',
1821 'undelete-error-long'
1828 * Return an array of subpages beginning with $search that this special page will accept.
1830 * @param string $search Prefix to search for
1831 * @param int $limit Maximum number of results to return (usually 10)
1832 * @param int $offset Number of results to skip (usually 0)
1833 * @return string[] Matching subpages
1835 public function prefixSearchSubpages( $search, $limit, $offset ) {
1836 return $this->prefixSearchString( $search, $limit, $offset );
1839 protected function getGroupName() {