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_SLAVE
);
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_SLAVE
);
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_SLAVE
);
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_SLAVE
);
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_SLAVE
);
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_SLAVE
);
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_SLAVE
);
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_SLAVE
);
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_SLAVE
);
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 * @param array $timestamps Pass an empty array to restore all revisions,
358 * otherwise list the ones to undelete.
359 * @param string $comment
360 * @param array $fileVersions
361 * @param bool $unsuppress
362 * @param User $user User performing the action, or null to use $wgUser
363 * @param string|string[] $tags Change tags to add to log entry
364 * ($user should be able to add the specified tags before this is called)
365 * @return array(number of file revisions restored, number of image revisions
366 * restored, log message) on success, false on failure.
368 function undelete( $timestamps, $comment = '', $fileVersions = [],
369 $unsuppress = false, User
$user = null, $tags = null
371 // If both the set of text revisions and file revisions are empty,
372 // restore everything. Otherwise, just restore the requested items.
373 $restoreAll = empty( $timestamps ) && empty( $fileVersions );
375 $restoreText = $restoreAll ||
!empty( $timestamps );
376 $restoreFiles = $restoreAll ||
!empty( $fileVersions );
378 if ( $restoreFiles && $this->title
->getNamespace() == NS_FILE
) {
379 $img = wfLocalFile( $this->title
);
380 $img->load( File
::READ_LATEST
);
381 $this->fileStatus
= $img->restore( $fileVersions, $unsuppress );
382 if ( !$this->fileStatus
->isOK() ) {
385 $filesRestored = $this->fileStatus
->successCount
;
390 if ( $restoreText ) {
391 $this->revisionStatus
= $this->undeleteRevisions( $timestamps, $unsuppress, $comment );
392 if ( !$this->revisionStatus
->isOK() ) {
396 $textRestored = $this->revisionStatus
->getValue();
403 if ( $textRestored && $filesRestored ) {
404 $reason = wfMessage( 'undeletedrevisions-files' )
405 ->numParams( $textRestored, $filesRestored )->inContentLanguage()->text();
406 } elseif ( $textRestored ) {
407 $reason = wfMessage( 'undeletedrevisions' )->numParams( $textRestored )
408 ->inContentLanguage()->text();
409 } elseif ( $filesRestored ) {
410 $reason = wfMessage( 'undeletedfiles' )->numParams( $filesRestored )
411 ->inContentLanguage()->text();
413 wfDebug( "Undelete: nothing undeleted...\n" );
418 if ( trim( $comment ) != '' ) {
419 $reason .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $comment;
422 if ( $user === null ) {
427 $logEntry = new ManualLogEntry( 'delete', 'restore' );
428 $logEntry->setPerformer( $user );
429 $logEntry->setTarget( $this->title
);
430 $logEntry->setComment( $reason );
431 $logEntry->setTags( $tags );
433 Hooks
::run( 'ArticleUndeleteLogEntry', [ $this, &$logEntry, $user ] );
435 $logid = $logEntry->insert();
436 $logEntry->publish( $logid );
438 return [ $textRestored, $filesRestored, $reason ];
442 * This is the meaty bit -- restores archived revisions of the given page
443 * to the cur/old tables. If the page currently exists, all revisions will
444 * be stuffed into old, otherwise the most recent will go into cur.
446 * @param array $timestamps Pass an empty array to restore all revisions,
447 * otherwise list the ones to undelete.
448 * @param bool $unsuppress Remove all ar_deleted/fa_deleted restrictions of seletected revs
449 * @param string $comment
450 * @throws ReadOnlyError
451 * @return Status Status object containing the number of revisions restored on success
453 private function undeleteRevisions( $timestamps, $unsuppress = false, $comment = '' ) {
454 if ( wfReadOnly() ) {
455 throw new ReadOnlyError();
458 $restoreAll = empty( $timestamps );
459 $dbw = wfGetDB( DB_MASTER
);
461 # Does this page already exist? We'll have to update it...
462 $article = WikiPage
::factory( $this->title
);
463 # Load latest data for the current page (bug 31179)
464 $article->loadPageData( 'fromdbmaster' );
465 $oldcountable = $article->isCountable();
467 $page = $dbw->selectRow( 'page',
468 [ 'page_id', 'page_latest' ],
469 [ 'page_namespace' => $this->title
->getNamespace(),
470 'page_title' => $this->title
->getDBkey() ],
472 [ 'FOR UPDATE' ] // lock page
477 # Page already exists. Import the history, and if necessary
478 # we'll update the latest revision field in the record.
480 $previousRevId = $page->page_latest
;
482 # Get the time span of this page
483 $previousTimestamp = $dbw->selectField( 'revision', 'rev_timestamp',
484 [ 'rev_id' => $previousRevId ],
487 if ( $previousTimestamp === false ) {
488 wfDebug( __METHOD__
. ": existing page refers to a page_latest that does not exist\n" );
490 $status = Status
::newGood( 0 );
491 $status->warning( 'undeleterevision-missing' );
496 # Have to create a new article...
499 $previousTimestamp = 0;
503 'ar_namespace' => $this->title
->getNamespace(),
504 'ar_title' => $this->title
->getDBkey(),
506 if ( !$restoreAll ) {
507 $oldWhere['ar_timestamp'] = array_map( [ &$dbw, 'timestamp' ], $timestamps );
526 if ( $this->config
->get( 'ContentHandlerUseDB' ) ) {
527 $fields[] = 'ar_content_format';
528 $fields[] = 'ar_content_model';
532 * Select each archived revision...
534 $result = $dbw->select( 'archive',
538 /* options */ [ 'ORDER BY' => 'ar_timestamp' ]
541 $rev_count = $result->numRows();
543 wfDebug( __METHOD__
. ": no revisions to restore\n" );
545 $status = Status
::newGood( 0 );
546 $status->warning( "undelete-no-results" );
551 $result->seek( $rev_count - 1 ); // move to last
552 $row = $result->fetchObject(); // get newest archived rev
553 $oldPageId = (int)$row->ar_page_id
; // pass this to ArticleUndelete hook
554 $result->seek( 0 ); // move back
556 // grab the content to check consistency with global state before restoring the page.
557 $revision = Revision
::newFromArchiveRow( $row,
559 'title' => $article->getTitle(), // used to derive default content model
562 $user = User
::newFromName( $revision->getUserText( Revision
::RAW
), false );
563 $content = $revision->getContent( Revision
::RAW
);
565 // NOTE: article ID may not be known yet. prepareSave() should not modify the database.
566 $status = $content->prepareSave( $article, 0, -1, $user );
568 if ( !$status->isOK() ) {
573 // Check the state of the newest to-be version...
574 if ( !$unsuppress && ( $row->ar_deleted
& Revision
::DELETED_TEXT
) ) {
575 return Status
::newFatal( "undeleterevdel" );
577 // Safe to insert now...
578 $newid = $article->insertOn( $dbw, $row->ar_page_id
);
579 if ( $newid === false ) {
580 // The old ID is reserved; let's pick another
581 $newid = $article->insertOn( $dbw );
585 // Check if a deleted revision will become the current revision...
586 if ( $row->ar_timestamp
> $previousTimestamp ) {
587 // Check the state of the newest to-be version...
588 if ( !$unsuppress && ( $row->ar_deleted
& Revision
::DELETED_TEXT
) ) {
589 return Status
::newFatal( "undeleterevdel" );
594 $pageId = $article->getId();
600 foreach ( $result as $row ) {
601 // Check for key dupes due to needed archive integrity.
602 if ( $row->ar_rev_id
) {
603 $exists = $dbw->selectField( 'revision', '1',
604 [ 'rev_id' => $row->ar_rev_id
], __METHOD__
);
606 continue; // don't throw DB errors
609 // Insert one revision at a time...maintaining deletion status
610 // unless we are specifically removing all restrictions...
611 $revision = Revision
::newFromArchiveRow( $row,
614 'title' => $this->title
,
615 'deleted' => $unsuppress ?
0 : $row->ar_deleted
618 $revision->insertOn( $dbw );
621 Hooks
::run( 'ArticleRevisionUndeleted', [ &$this->title
, $revision, $row->ar_page_id
] );
623 # Now that it's safely stored, take it out of the archive
624 $dbw->delete( 'archive',
628 // Was anything restored at all?
629 if ( $restored == 0 ) {
630 return Status
::newGood( 0 );
633 $created = (bool)$newid;
635 // Attach the latest revision to the page...
636 $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId );
637 if ( $created ||
$wasnew ) {
638 // Update site stats, link tables, etc
639 $article->doEditUpdates(
641 User
::newFromName( $revision->getUserText( Revision
::RAW
), false ),
643 'created' => $created,
644 'oldcountable' => $oldcountable,
650 Hooks
::run( 'ArticleUndelete', [ &$this->title
, $created, $comment, $oldPageId ] );
652 if ( $this->title
->getNamespace() == NS_FILE
) {
653 DeferredUpdates
::addUpdate( new HTMLCacheUpdate( $this->title
, 'imagelinks' ) );
656 return Status
::newGood( $restored );
662 function getFileStatus() {
663 return $this->fileStatus
;
669 function getRevisionStatus() {
670 return $this->revisionStatus
;
675 * Special page allowing users with the appropriate permissions to view
676 * and restore deleted content.
678 * @ingroup SpecialPage
680 class SpecialUndelete
extends SpecialPage
{
688 private $mTargetTimestamp;
697 function __construct() {
698 parent
::__construct( 'Undelete', 'deletedhistory' );
701 function loadRequest( $par ) {
702 $request = $this->getRequest();
703 $user = $this->getUser();
705 $this->mAction
= $request->getVal( 'action' );
706 if ( $par !== null && $par !== '' ) {
707 $this->mTarget
= $par;
709 $this->mTarget
= $request->getVal( 'target' );
712 $this->mTargetObj
= null;
714 if ( $this->mTarget
!== null && $this->mTarget
!== '' ) {
715 $this->mTargetObj
= Title
::newFromText( $this->mTarget
);
718 $this->mSearchPrefix
= $request->getText( 'prefix' );
719 $time = $request->getVal( 'timestamp' );
720 $this->mTimestamp
= $time ?
wfTimestamp( TS_MW
, $time ) : '';
721 $this->mFilename
= $request->getVal( 'file' );
723 $posted = $request->wasPosted() &&
724 $user->matchEditToken( $request->getVal( 'wpEditToken' ) );
725 $this->mRestore
= $request->getCheck( 'restore' ) && $posted;
726 $this->mRevdel
= $request->getCheck( 'revdel' ) && $posted;
727 $this->mInvert
= $request->getCheck( 'invert' ) && $posted;
728 $this->mPreview
= $request->getCheck( 'preview' ) && $posted;
729 $this->mDiff
= $request->getCheck( 'diff' );
730 $this->mDiffOnly
= $request->getBool( 'diffonly', $this->getUser()->getOption( 'diffonly' ) );
731 $this->mComment
= $request->getText( 'wpComment' );
732 $this->mUnsuppress
= $request->getVal( 'wpUnsuppress' ) && $user->isAllowed( 'suppressrevision' );
733 $this->mToken
= $request->getVal( 'token' );
735 if ( $this->isAllowed( 'undelete' ) && !$user->isBlocked() ) {
736 $this->mAllowed
= true; // user can restore
737 $this->mCanView
= true; // user can view content
738 } elseif ( $this->isAllowed( 'deletedtext' ) ) {
739 $this->mAllowed
= false; // user cannot restore
740 $this->mCanView
= true; // user can view content
741 $this->mRestore
= false;
742 } else { // user can only view the list of revisions
743 $this->mAllowed
= false;
744 $this->mCanView
= false;
745 $this->mTimestamp
= '';
746 $this->mRestore
= false;
749 if ( $this->mRestore ||
$this->mInvert
) {
751 $this->mFileVersions
= [];
752 foreach ( $request->getValues() as $key => $val ) {
754 if ( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
755 array_push( $timestamps, $matches[1] );
758 if ( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
759 $this->mFileVersions
[] = intval( $matches[1] );
762 rsort( $timestamps );
763 $this->mTargetTimestamp
= $timestamps;
768 * Checks whether a user is allowed the permission for the
769 * specific title if one is set.
771 * @param string $permission
775 protected function isAllowed( $permission, User
$user = null ) {
776 $user = $user ?
: $this->getUser();
777 if ( $this->mTargetObj
!== null ) {
778 return $this->mTargetObj
->userCan( $permission, $user );
780 return $user->isAllowed( $permission );
784 function userCanExecute( User
$user ) {
785 return $this->isAllowed( $this->mRestriction
, $user );
788 function execute( $par ) {
789 $this->useTransactionalTimeLimit();
791 $user = $this->getUser();
794 $this->outputHeader();
796 $this->loadRequest( $par );
797 $this->checkPermissions(); // Needs to be after mTargetObj is set
799 $out = $this->getOutput();
801 if ( is_null( $this->mTargetObj
) ) {
802 $out->addWikiMsg( 'undelete-header' );
804 # Not all users can just browse every deleted page from the list
805 if ( $user->isAllowed( 'browsearchive' ) ) {
806 $this->showSearchForm();
812 $this->addHelpLink( 'Help:Undelete' );
813 if ( $this->mAllowed
) {
814 $out->setPageTitle( $this->msg( 'undeletepage' ) );
816 $out->setPageTitle( $this->msg( 'viewdeletedpage' ) );
819 $this->getSkin()->setRelevantTitle( $this->mTargetObj
);
821 if ( $this->mTimestamp
!== '' ) {
822 $this->showRevision( $this->mTimestamp
);
823 } elseif ( $this->mFilename
!== null && $this->mTargetObj
->inNamespace( NS_FILE
) ) {
824 $file = new ArchivedFile( $this->mTargetObj
, '', $this->mFilename
);
825 // Check if user is allowed to see this file
826 if ( !$file->exists() ) {
827 $out->addWikiMsg( 'filedelete-nofile', $this->mFilename
);
828 } elseif ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
829 if ( $file->isDeleted( File
::DELETED_RESTRICTED
) ) {
830 throw new PermissionsError( 'suppressrevision' );
832 throw new PermissionsError( 'deletedtext' );
834 } elseif ( !$user->matchEditToken( $this->mToken
, $this->mFilename
) ) {
835 $this->showFileConfirmationForm( $this->mFilename
);
837 $this->showFile( $this->mFilename
);
839 } elseif ( $this->mAction
=== "submit" ) {
840 if ( $this->mRestore
) {
842 } elseif ( $this->mRevdel
) {
843 $this->redirectToRevDel();
847 $this->showHistory();
852 * Convert submitted form data to format expected by RevisionDelete and
853 * redirect the request
855 private function redirectToRevDel() {
856 $archive = new PageArchive( $this->mTargetObj
);
860 foreach ( $this->getRequest()->getValues() as $key => $val ) {
862 if ( preg_match( "/^ts(\d{14})$/", $key, $matches ) ) {
863 $revisions[ $archive->getRevision( $matches[1] )->getId() ] = 1;
867 "type" => "revision",
869 "target" => $this->mTargetObj
->getPrefixedText()
871 $url = SpecialPage
::getTitleFor( "RevisionDelete" )->getFullURL( $query );
872 $this->getOutput()->redirect( $url );
875 function showSearchForm() {
876 $out = $this->getOutput();
877 $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
879 Xml
::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] ) .
880 Xml
::fieldset( $this->msg( 'undelete-search-box' )->text() ) .
881 Html
::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
884 [ 'for' => 'prefix' ],
885 $this->msg( 'undelete-search-prefix' )->parse()
890 $this->mSearchPrefix
,
891 [ 'id' => 'prefix', 'autofocus' => '' ]
893 Xml
::submitButton( $this->msg( 'undelete-search-submit' )->text() ) .
894 Xml
::closeElement( 'fieldset' ) .
895 Xml
::closeElement( 'form' )
898 # List undeletable articles
899 if ( $this->mSearchPrefix
) {
900 $result = PageArchive
::listPagesByPrefix( $this->mSearchPrefix
);
901 $this->showList( $result );
906 * Generic list of deleted pages
908 * @param ResultWrapper $result
911 private function showList( $result ) {
912 $out = $this->getOutput();
914 if ( $result->numRows() == 0 ) {
915 $out->addWikiMsg( 'undelete-no-results' );
920 $out->addWikiMsg( 'undeletepagetext', $this->getLanguage()->formatNum( $result->numRows() ) );
922 $undelete = $this->getPageTitle();
923 $out->addHTML( "<ul>\n" );
924 foreach ( $result as $row ) {
925 $title = Title
::makeTitleSafe( $row->ar_namespace
, $row->ar_title
);
926 if ( $title !== null ) {
927 $item = Linker
::linkKnown(
929 htmlspecialchars( $title->getPrefixedText() ),
931 [ 'target' => $title->getPrefixedText() ]
934 // The title is no longer valid, show as text
935 $item = Html
::element(
937 [ 'class' => 'mw-invalidtitle' ],
938 Linker
::getInvalidTitleDescription(
945 $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count
)->parse();
946 $out->addHTML( "<li>{$item} ({$revs})</li>\n" );
949 $out->addHTML( "</ul>\n" );
954 private function showRevision( $timestamp ) {
955 if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
959 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
960 if ( !Hooks
::run( 'UndeleteForm::showRevision', [ &$archive, $this->mTargetObj
] ) ) {
963 $rev = $archive->getRevision( $timestamp );
965 $out = $this->getOutput();
966 $user = $this->getUser();
969 $out->addWikiMsg( 'undeleterevision-missing' );
974 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
975 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
977 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
978 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
979 'rev-suppressed-text-permission' : 'rev-deleted-text-permission'
986 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
987 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
988 'rev-suppressed-text-view' : 'rev-deleted-text-view'
990 $out->addHTML( '<br />' );
991 // and we are allowed to see...
994 if ( $this->mDiff
) {
995 $previousRev = $archive->getPreviousRevision( $timestamp );
996 if ( $previousRev ) {
997 $this->showDiff( $previousRev, $rev );
998 if ( $this->mDiffOnly
) {
1002 $out->addHTML( '<hr />' );
1004 $out->addWikiMsg( 'undelete-nodiff' );
1008 $link = Linker
::linkKnown(
1009 $this->getPageTitle( $this->mTargetObj
->getPrefixedDBkey() ),
1010 htmlspecialchars( $this->mTargetObj
->getPrefixedText() )
1013 $lang = $this->getLanguage();
1015 // date and time are separate parameters to facilitate localisation.
1016 // $time is kept for backward compat reasons.
1017 $time = $lang->userTimeAndDate( $timestamp, $user );
1018 $d = $lang->userDate( $timestamp, $user );
1019 $t = $lang->userTime( $timestamp, $user );
1020 $userLink = Linker
::revUserTools( $rev );
1022 $content = $rev->getContent( Revision
::FOR_THIS_USER
, $user );
1024 $isText = ( $content instanceof TextContent
);
1026 if ( $this->mPreview ||
$isText ) {
1027 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
1029 $openDiv = '<div id="mw-undelete-revision">';
1031 $out->addHTML( $openDiv );
1033 // Revision delete links
1034 if ( !$this->mDiff
) {
1035 $revdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
1037 $out->addHTML( "$revdel " );
1041 $out->addHTML( $this->msg( 'undelete-revision' )->rawParams( $link )->params(
1042 $time )->rawParams( $userLink )->params( $d, $t )->parse() . '</div>' );
1044 if ( !Hooks
::run( 'UndeleteShowRevision', [ $this->mTargetObj
, $rev ] ) ) {
1048 if ( ( $this->mPreview ||
!$isText ) && $content ) {
1049 // NOTE: non-text content has no source view, so always use rendered preview
1052 $popts = $out->parserOptions();
1053 $popts->setEditSection( false );
1055 $pout = $content->getParserOutput( $this->mTargetObj
, $rev->getId(), $popts, true );
1056 $out->addParserOutput( $pout );
1060 // source view for textual content
1061 $sourceView = Xml
::element(
1064 'readonly' => 'readonly',
1065 'cols' => $user->getIntOption( 'cols' ),
1066 'rows' => $user->getIntOption( 'rows' )
1068 $content->getNativeData() . "\n"
1071 $previewButton = Xml
::element( 'input', [
1073 'name' => 'preview',
1074 'value' => $this->msg( 'showpreview' )->text()
1078 $previewButton = '';
1081 $diffButton = Xml
::element( 'input', [
1084 'value' => $this->msg( 'showdiff' )->text() ] );
1088 Xml
::openElement( 'div', [
1089 'style' => 'clear: both' ] ) .
1090 Xml
::openElement( 'form', [
1092 'action' => $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] ) ] ) .
1093 Xml
::element( 'input', [
1096 'value' => $this->mTargetObj
->getPrefixedDBkey() ] ) .
1097 Xml
::element( 'input', [
1099 'name' => 'timestamp',
1100 'value' => $timestamp ] ) .
1101 Xml
::element( 'input', [
1103 'name' => 'wpEditToken',
1104 'value' => $user->getEditToken() ] ) .
1107 Xml
::closeElement( 'form' ) .
1108 Xml
::closeElement( 'div' )
1113 * Build a diff display between this and the previous either deleted
1114 * or non-deleted edit.
1116 * @param Revision $previousRev
1117 * @param Revision $currentRev
1118 * @return string HTML
1120 function showDiff( $previousRev, $currentRev ) {
1121 $diffContext = clone $this->getContext();
1122 $diffContext->setTitle( $currentRev->getTitle() );
1123 $diffContext->setWikiPage( WikiPage
::factory( $currentRev->getTitle() ) );
1125 $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
1126 $diffEngine->showDiffStyle();
1128 $formattedDiff = $diffEngine->generateContentDiffBody(
1129 $previousRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() ),
1130 $currentRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() )
1133 $formattedDiff = $diffEngine->addHeader(
1135 $this->diffHeader( $previousRev, 'o' ),
1136 $this->diffHeader( $currentRev, 'n' )
1139 $this->getOutput()->addHTML( "<div>$formattedDiff</div>\n" );
1143 * @param Revision $rev
1144 * @param string $prefix
1147 private function diffHeader( $rev, $prefix ) {
1148 $isDeleted = !( $rev->getId() && $rev->getTitle() );
1150 /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
1151 $targetPage = $this->getPageTitle();
1153 'target' => $this->mTargetObj
->getPrefixedText(),
1154 'timestamp' => wfTimestamp( TS_MW
, $rev->getTimestamp() )
1157 /// @todo FIXME: getId() may return non-zero for deleted revs...
1158 $targetPage = $rev->getTitle();
1159 $targetQuery = [ 'oldid' => $rev->getId() ];
1162 // Add show/hide deletion links if available
1163 $user = $this->getUser();
1164 $lang = $this->getLanguage();
1165 $rdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
1171 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
1173 $tags = wfGetDB( DB_SLAVE
)->selectField(
1176 [ 'ts_rev_id' => $rev->getId() ],
1179 $tagSummary = ChangeTags
::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() );
1181 // FIXME This is reimplementing DifferenceEngine#getRevisionHeader
1182 // and partially #showDiffPage, but worse
1183 return '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
1188 $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
1189 $lang->userDate( $rev->getTimestamp(), $user ),
1190 $lang->userTime( $rev->getTimestamp(), $user )
1196 '<div id="mw-diff-' . $prefix . 'title2">' .
1197 Linker
::revUserTools( $rev ) . '<br />' .
1199 '<div id="mw-diff-' . $prefix . 'title3">' .
1200 $minor . Linker
::revComment( $rev ) . $rdel . '<br />' .
1202 '<div id="mw-diff-' . $prefix . 'title5">' .
1203 $tagSummary[0] . '<br />' .
1208 * Show a form confirming whether a tokenless user really wants to see a file
1209 * @param string $key
1211 private function showFileConfirmationForm( $key ) {
1212 $out = $this->getOutput();
1213 $lang = $this->getLanguage();
1214 $user = $this->getUser();
1215 $file = new ArchivedFile( $this->mTargetObj
, '', $this->mFilename
);
1216 $out->addWikiMsg( 'undelete-show-file-confirm',
1217 $this->mTargetObj
->getText(),
1218 $lang->userDate( $file->getTimestamp(), $user ),
1219 $lang->userTime( $file->getTimestamp(), $user ) );
1221 Xml
::openElement( 'form', [
1223 'action' => $this->getPageTitle()->getLocalURL( [
1224 'target' => $this->mTarget
,
1226 'token' => $user->getEditToken( $key ),
1230 Xml
::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
1236 * Show a deleted file version requested by the visitor.
1237 * @param string $key
1239 private function showFile( $key ) {
1240 $this->getOutput()->disable();
1242 # We mustn't allow the output to be CDN cached, otherwise
1243 # if an admin previews a deleted image, and it's cached, then
1244 # a user without appropriate permissions can toddle off and
1245 # nab the image, and CDN will serve it
1246 $response = $this->getRequest()->response();
1247 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1248 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
1249 $response->header( 'Pragma: no-cache' );
1251 $repo = RepoGroup
::singleton()->getLocalRepo();
1252 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
1253 $repo->streamFile( $path );
1256 protected function showHistory() {
1257 $this->checkReadOnly();
1259 $out = $this->getOutput();
1260 if ( $this->mAllowed
) {
1261 $out->addModules( 'mediawiki.special.undelete' );
1264 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
1265 [ 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj
->getPrefixedText() ) ]
1268 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1269 Hooks
::run( 'UndeleteForm::showHistory', [ &$archive, $this->mTargetObj
] );
1271 $text = $archive->getLastRevisionText();
1272 if( is_null( $text ) ) {
1273 $out->addWikiMsg( 'nohistory' );
1277 $out->addHTML( '<div class="mw-undelete-history">' );
1278 if ( $this->mAllowed
) {
1279 $out->addWikiMsg( 'undeletehistory' );
1280 $out->addWikiMsg( 'undeleterevdel' );
1282 $out->addWikiMsg( 'undeletehistorynoadmin' );
1284 $out->addHTML( '</div>' );
1286 # List all stored revisions
1287 $revisions = $archive->listRevisions();
1288 $files = $archive->listFiles();
1290 $haveRevisions = $revisions && $revisions->numRows() > 0;
1291 $haveFiles = $files && $files->numRows() > 0;
1293 # Batch existence check on user and talk pages
1294 if ( $haveRevisions ) {
1295 $batch = new LinkBatch();
1296 foreach ( $revisions as $row ) {
1297 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
1298 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
1301 $revisions->seek( 0 );
1304 $batch = new LinkBatch();
1305 foreach ( $files as $row ) {
1306 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
1307 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
1313 if ( $this->mAllowed
) {
1314 $action = $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] );
1315 # Start the form here
1316 $top = Xml
::openElement(
1318 [ 'method' => 'post', 'action' => $action, 'id' => 'undelete' ]
1320 $out->addHTML( $top );
1323 # Show relevant lines from the deletion log:
1324 $deleteLogPage = new LogPage( 'delete' );
1325 $out->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) . "\n" );
1326 LogEventsList
::showLogExtract( $out, 'delete', $this->mTargetObj
);
1327 # Show relevant lines from the suppression log:
1328 $suppressLogPage = new LogPage( 'suppress' );
1329 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
1330 $out->addHTML( Xml
::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
1331 LogEventsList
::showLogExtract( $out, 'suppress', $this->mTargetObj
);
1334 if ( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
1335 # Format the user-visible controls (comment field, submission button)
1336 # in a nice little table
1337 if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
1341 <td class='mw-input'>" .
1342 Xml
::checkLabel( $this->msg( 'revdelete-unsuppress' )->text(),
1343 'wpUnsuppress', 'mw-undelete-unsuppress', $this->mUnsuppress
) .
1347 $unsuppressBox = '';
1350 $table = Xml
::fieldset( $this->msg( 'undelete-fieldset-title' )->text() ) .
1351 Xml
::openElement( 'table', [ 'id' => 'mw-undelete-table' ] ) .
1353 <td colspan='2' class='mw-undelete-extrahelp'>" .
1354 $this->msg( 'undeleteextrahelp' )->parseAsBlock() .
1358 <td class='mw-label'>" .
1359 Xml
::label( $this->msg( 'undeletecomment' )->text(), 'wpComment' ) .
1361 <td class='mw-input'>" .
1366 [ 'id' => 'wpComment', 'autofocus' => '' ]
1372 <td class='mw-submit'>" .
1374 $this->msg( 'undeletebtn' )->text(),
1375 [ 'name' => 'restore', 'id' => 'mw-undelete-submit' ]
1378 $this->msg( 'undeleteinvert' )->text(),
1379 [ 'name' => 'invert', 'id' => 'mw-undelete-invert' ]
1384 Xml
::closeElement( 'table' ) .
1385 Xml
::closeElement( 'fieldset' );
1387 $out->addHTML( $table );
1390 $out->addHTML( Xml
::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n" );
1392 if ( $haveRevisions ) {
1393 # Show the page's stored (deleted) history
1395 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
1396 $out->addHTML( Html
::element(
1401 'class' => 'deleterevision-log-submit mw-log-deleterevision-button'
1403 $this->msg( 'showhideselectedversions' )->text()
1407 $out->addHTML( '<ul>' );
1408 $remaining = $revisions->numRows();
1409 $earliestLiveTime = $this->mTargetObj
->getEarliestRevTime();
1411 foreach ( $revisions as $row ) {
1413 $out->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining ) );
1416 $out->addHTML( '</ul>' );
1418 $out->addWikiMsg( 'nohistory' );
1422 $out->addHTML( Xml
::element( 'h2', null, $this->msg( 'filehist' )->text() ) . "\n" );
1423 $out->addHTML( '<ul>' );
1424 foreach ( $files as $row ) {
1425 $out->addHTML( $this->formatFileRow( $row ) );
1428 $out->addHTML( '</ul>' );
1431 if ( $this->mAllowed
) {
1432 # Slip in the hidden controls here
1433 $misc = Html
::hidden( 'target', $this->mTarget
);
1434 $misc .= Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
1435 $misc .= Xml
::closeElement( 'form' );
1436 $out->addHTML( $misc );
1442 protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
1443 $rev = Revision
::newFromArchiveRow( $row,
1445 'title' => $this->mTargetObj
1449 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
1450 // Build checkboxen...
1451 if ( $this->mAllowed
) {
1452 if ( $this->mInvert
) {
1453 if ( in_array( $ts, $this->mTargetTimestamp
) ) {
1454 $checkBox = Xml
::check( "ts$ts" );
1456 $checkBox = Xml
::check( "ts$ts", true );
1459 $checkBox = Xml
::check( "ts$ts" );
1465 // Build page & diff links...
1466 $user = $this->getUser();
1467 if ( $this->mCanView
) {
1468 $titleObj = $this->getPageTitle();
1470 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
1471 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
1472 $last = $this->msg( 'diff' )->escaped();
1473 } elseif ( $remaining > 0 ||
( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
1474 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
1475 $last = Linker
::linkKnown(
1477 $this->msg( 'diff' )->escaped(),
1480 'target' => $this->mTargetObj
->getPrefixedText(),
1486 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
1487 $last = $this->msg( 'diff' )->escaped();
1490 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
1491 $last = $this->msg( 'diff' )->escaped();
1495 $userLink = Linker
::revUserTools( $rev );
1498 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
1500 // Revision text size
1501 $size = $row->ar_len
;
1502 if ( !is_null( $size ) ) {
1503 $revTextSize = Linker
::formatRevisionSize( $size );
1507 $comment = Linker
::revComment( $rev );
1511 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
1517 $attribs['class'] = implode( ' ', $classes );
1520 $revisionRow = $this->msg( 'undelete-revision-row2' )
1533 return Xml
::tags( 'li', $attribs, $revisionRow ) . "\n";
1536 private function formatFileRow( $row ) {
1537 $file = ArchivedFile
::newFromRow( $row );
1538 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
1539 $user = $this->getUser();
1542 if ( $this->mCanView
&& $row->fa_storage_key
) {
1543 if ( $this->mAllowed
) {
1544 $checkBox = Xml
::check( 'fileid' . $row->fa_id
);
1546 $key = urlencode( $row->fa_storage_key
);
1547 $pageLink = $this->getFileLink( $file, $this->getPageTitle(), $ts, $key );
1549 $pageLink = $this->getLanguage()->userTimeAndDate( $ts, $user );
1551 $userLink = $this->getFileUser( $file );
1552 $data = $this->msg( 'widthheight' )->numParams( $row->fa_width
, $row->fa_height
)->text();
1553 $bytes = $this->msg( 'parentheses' )
1554 ->rawParams( $this->msg( 'nbytes' )->numParams( $row->fa_size
)->text() )
1556 $data = htmlspecialchars( $data . ' ' . $bytes );
1557 $comment = $this->getFileComment( $file );
1559 // Add show/hide deletion links if available
1560 $canHide = $this->isAllowed( 'deleterevision' );
1561 if ( $canHide ||
( $file->getVisibility() && $this->isAllowed( 'deletedhistory' ) ) ) {
1562 if ( !$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
1563 // Revision was hidden from sysops
1564 $revdlink = Linker
::revDeleteLinkDisabled( $canHide );
1567 'type' => 'filearchive',
1568 'target' => $this->mTargetObj
->getPrefixedDBkey(),
1569 'ids' => $row->fa_id
1571 $revdlink = Linker
::revDeleteLink( $query,
1572 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1578 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1582 * Fetch revision text link if it's available to all users
1584 * @param Revision $rev
1585 * @param Title $titleObj
1586 * @param string $ts Timestamp
1589 function getPageLink( $rev, $titleObj, $ts ) {
1590 $user = $this->getUser();
1591 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1593 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1594 return '<span class="history-deleted">' . $time . '</span>';
1597 $link = Linker
::linkKnown(
1599 htmlspecialchars( $time ),
1602 'target' => $this->mTargetObj
->getPrefixedText(),
1607 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1608 $link = '<span class="history-deleted">' . $link . '</span>';
1615 * Fetch image view link if it's available to all users
1617 * @param File|ArchivedFile $file
1618 * @param Title $titleObj
1619 * @param string $ts A timestamp
1620 * @param string $key A storage key
1622 * @return string HTML fragment
1624 function getFileLink( $file, $titleObj, $ts, $key ) {
1625 $user = $this->getUser();
1626 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1628 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
1629 return '<span class="history-deleted">' . $time . '</span>';
1632 $link = Linker
::linkKnown(
1634 htmlspecialchars( $time ),
1637 'target' => $this->mTargetObj
->getPrefixedText(),
1639 'token' => $user->getEditToken( $key )
1643 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
1644 $link = '<span class="history-deleted">' . $link . '</span>';
1651 * Fetch file's user id if it's available to this user
1653 * @param File|ArchivedFile $file
1654 * @return string HTML fragment
1656 function getFileUser( $file ) {
1657 if ( !$file->userCan( File
::DELETED_USER
, $this->getUser() ) ) {
1658 return '<span class="history-deleted">' .
1659 $this->msg( 'rev-deleted-user' )->escaped() .
1663 $link = Linker
::userLink( $file->getRawUser(), $file->getRawUserText() ) .
1664 Linker
::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1666 if ( $file->isDeleted( File
::DELETED_USER
) ) {
1667 $link = '<span class="history-deleted">' . $link . '</span>';
1674 * Fetch file upload comment if it's available to this user
1676 * @param File|ArchivedFile $file
1677 * @return string HTML fragment
1679 function getFileComment( $file ) {
1680 if ( !$file->userCan( File
::DELETED_COMMENT
, $this->getUser() ) ) {
1681 return '<span class="history-deleted"><span class="comment">' .
1682 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></span>';
1685 $link = Linker
::commentBlock( $file->getRawDescription() );
1687 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
1688 $link = '<span class="history-deleted">' . $link . '</span>';
1694 function undelete() {
1695 if ( $this->getConfig()->get( 'UploadMaintenance' )
1696 && $this->mTargetObj
->getNamespace() == NS_FILE
1698 throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
1701 $this->checkReadOnly();
1703 $out = $this->getOutput();
1704 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1705 Hooks
::run( 'UndeleteForm::undelete', [ &$archive, $this->mTargetObj
] );
1706 $ok = $archive->undelete(
1707 $this->mTargetTimestamp
,
1709 $this->mFileVersions
,
1714 if ( is_array( $ok ) ) {
1715 if ( $ok[1] ) { // Undeleted file count
1716 Hooks
::run( 'FileUndeleteComplete', [
1717 $this->mTargetObj
, $this->mFileVersions
,
1718 $this->getUser(), $this->mComment
] );
1721 $link = Linker
::linkKnown( $this->mTargetObj
);
1722 $out->addHTML( $this->msg( 'undeletedpage' )->rawParams( $link )->parse() );
1724 $out->setPageTitle( $this->msg( 'undelete-error' ) );
1727 // Show revision undeletion warnings and errors
1728 $status = $archive->getRevisionStatus();
1729 if ( $status && !$status->isGood() ) {
1730 $out->addWikiText( '<div class="error">' .
1731 $status->getWikiText(
1738 // Show file undeletion warnings and errors
1739 $status = $archive->getFileStatus();
1740 if ( $status && !$status->isGood() ) {
1741 $out->addWikiText( '<div class="error">' .
1742 $status->getWikiText(
1743 'undelete-error-short',
1744 'undelete-error-long'
1751 * Return an array of subpages beginning with $search that this special page will accept.
1753 * @param string $search Prefix to search for
1754 * @param int $limit Maximum number of results to return (usually 10)
1755 * @param int $offset Number of results to skip (usually 0)
1756 * @return string[] Matching subpages
1758 public function prefixSearchSubpages( $search, $limit, $offset ) {
1759 return $this->prefixSearchString( $search, $limit, $offset );
1762 protected function getGroupName() {