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
24 use MediaWiki\MediaWikiServices
;
25 use MediaWiki\Revision\RevisionRecord
;
26 use MediaWiki\Storage\NameTableAccessException
;
27 use Wikimedia\Rdbms\IResultWrapper
;
30 * Special page allowing users with the appropriate permissions to view
31 * and restore deleted content.
33 * @ingroup SpecialPage
35 class SpecialUndelete
extends SpecialPage
{
43 private $mTargetTimestamp;
52 * @var string Search prefix
54 private $mSearchPrefix;
56 function __construct() {
57 parent
::__construct( 'Undelete', 'deletedhistory' );
60 public function doesWrites() {
64 function loadRequest( $par ) {
65 $request = $this->getRequest();
66 $user = $this->getUser();
68 $this->mAction
= $request->getVal( 'action' );
69 if ( $par !== null && $par !== '' ) {
70 $this->mTarget
= $par;
72 $this->mTarget
= $request->getVal( 'target' );
75 $this->mTargetObj
= null;
77 if ( $this->mTarget
!== null && $this->mTarget
!== '' ) {
78 $this->mTargetObj
= Title
::newFromText( $this->mTarget
);
81 $this->mSearchPrefix
= $request->getText( 'prefix' );
82 $time = $request->getVal( 'timestamp' );
83 $this->mTimestamp
= $time ?
wfTimestamp( TS_MW
, $time ) : '';
84 $this->mFilename
= $request->getVal( 'file' );
86 $posted = $request->wasPosted() &&
87 $user->matchEditToken( $request->getVal( 'wpEditToken' ) );
88 $this->mRestore
= $request->getCheck( 'restore' ) && $posted;
89 $this->mRevdel
= $request->getCheck( 'revdel' ) && $posted;
90 $this->mInvert
= $request->getCheck( 'invert' ) && $posted;
91 $this->mPreview
= $request->getCheck( 'preview' ) && $posted;
92 $this->mDiff
= $request->getCheck( 'diff' );
93 $this->mDiffOnly
= $request->getBool( 'diffonly', $this->getUser()->getOption( 'diffonly' ) );
94 $this->mComment
= $request->getText( 'wpComment' );
95 $this->mUnsuppress
= $request->getVal( 'wpUnsuppress' ) && $user->isAllowed( 'suppressrevision' );
96 $this->mToken
= $request->getVal( 'token' );
98 $block = $user->getBlock();
99 if ( $this->isAllowed( 'undelete' ) && !( $block && $block->isSitewide() ) ) {
100 $this->mAllowed
= true; // user can restore
101 $this->mCanView
= true; // user can view content
102 } elseif ( $this->isAllowed( 'deletedtext' ) ) {
103 $this->mAllowed
= false; // user cannot restore
104 $this->mCanView
= true; // user can view content
105 $this->mRestore
= false;
106 } else { // user can only view the list of revisions
107 $this->mAllowed
= false;
108 $this->mCanView
= false;
109 $this->mTimestamp
= '';
110 $this->mRestore
= false;
113 if ( $this->mRestore ||
$this->mInvert
) {
115 $this->mFileVersions
= [];
116 foreach ( $request->getValues() as $key => $val ) {
118 if ( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
119 array_push( $timestamps, $matches[1] );
122 if ( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
123 $this->mFileVersions
[] = intval( $matches[1] );
126 rsort( $timestamps );
127 $this->mTargetTimestamp
= $timestamps;
132 * Checks whether a user is allowed the permission for the
133 * specific title if one is set.
135 * @param string $permission
136 * @param User|null $user
139 protected function isAllowed( $permission, User
$user = null ) {
140 $user = $user ?
: $this->getUser();
141 $permissionManager = MediaWikiServices
::getInstance()->getPermissionManager();
143 if ( $this->mTargetObj
!== null ) {
144 return $permissionManager->userCan( $permission, $user, $this->mTargetObj
);
146 return $user->isAllowed( $permission );
150 function userCanExecute( User
$user ) {
151 return $this->isAllowed( $this->mRestriction
, $user );
154 function execute( $par ) {
155 $this->useTransactionalTimeLimit();
157 $user = $this->getUser();
160 $this->outputHeader();
161 $this->addHelpLink( 'Help:Deletion_and_undeletion' );
163 $this->loadRequest( $par );
164 $this->checkPermissions(); // Needs to be after mTargetObj is set
166 $out = $this->getOutput();
168 if ( is_null( $this->mTargetObj
) ) {
169 $out->addWikiMsg( 'undelete-header' );
171 # Not all users can just browse every deleted page from the list
172 if ( $user->isAllowed( 'browsearchive' ) ) {
173 $this->showSearchForm();
179 $this->addHelpLink( 'Help:Undelete' );
180 if ( $this->mAllowed
) {
181 $out->setPageTitle( $this->msg( 'undeletepage' ) );
183 $out->setPageTitle( $this->msg( 'viewdeletedpage' ) );
186 $this->getSkin()->setRelevantTitle( $this->mTargetObj
);
188 if ( $this->mTimestamp
!== '' ) {
189 $this->showRevision( $this->mTimestamp
);
190 } elseif ( $this->mFilename
!== null && $this->mTargetObj
->inNamespace( NS_FILE
) ) {
191 $file = new ArchivedFile( $this->mTargetObj
, 0, $this->mFilename
);
192 // Check if user is allowed to see this file
193 if ( !$file->exists() ) {
194 $out->addWikiMsg( 'filedelete-nofile', $this->mFilename
);
195 } elseif ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
196 if ( $file->isDeleted( File
::DELETED_RESTRICTED
) ) {
197 throw new PermissionsError( 'suppressrevision' );
199 throw new PermissionsError( 'deletedtext' );
201 } elseif ( !$user->matchEditToken( $this->mToken
, $this->mFilename
) ) {
202 $this->showFileConfirmationForm( $this->mFilename
);
204 $this->showFile( $this->mFilename
);
206 } elseif ( $this->mAction
=== 'submit' ) {
207 if ( $this->mRestore
) {
209 } elseif ( $this->mRevdel
) {
210 $this->redirectToRevDel();
214 $this->showHistory();
219 * Convert submitted form data to format expected by RevisionDelete and
220 * redirect the request
222 private function redirectToRevDel() {
223 $archive = new PageArchive( $this->mTargetObj
);
227 foreach ( $this->getRequest()->getValues() as $key => $val ) {
229 if ( preg_match( "/^ts(\d{14})$/", $key, $matches ) ) {
230 $revisions[$archive->getRevision( $matches[1] )->getId()] = 1;
235 'type' => 'revision',
237 'target' => $this->mTargetObj
->getPrefixedText()
239 $url = SpecialPage
::getTitleFor( 'Revisiondelete' )->getFullURL( $query );
240 $this->getOutput()->redirect( $url );
243 function showSearchForm() {
244 $out = $this->getOutput();
245 $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
246 $fuzzySearch = $this->getRequest()->getVal( 'fuzzy', true );
251 $fields[] = new OOUI\
ActionFieldLayout(
252 new OOUI\
TextInputWidget( [
254 'inputId' => 'prefix',
256 'value' => $this->mSearchPrefix
,
259 new OOUI\
ButtonInputWidget( [
260 'label' => $this->msg( 'undelete-search-submit' )->text(),
261 'flags' => [ 'primary', 'progressive' ],
262 'inputId' => 'searchUndelete',
266 'label' => new OOUI\
HtmlSnippet(
268 $fuzzySearch ?
'undelete-search-full' : 'undelete-search-prefix'
275 $fieldset = new OOUI\
FieldsetLayout( [
276 'label' => $this->msg( 'undelete-search-box' )->text(),
280 $form = new OOUI\
FormLayout( [
282 'action' => wfScript(),
285 $form->appendContent(
287 new OOUI\
HtmlSnippet(
288 Html
::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
289 Html
::hidden( 'fuzzy', $fuzzySearch )
294 new OOUI\
PanelLayout( [
302 # List undeletable articles
303 if ( $this->mSearchPrefix
) {
304 // For now, we enable search engine match only when specifically asked to
305 // by using fuzzy=1 parameter.
306 if ( $fuzzySearch ) {
307 $result = PageArchive
::listPagesBySearch( $this->mSearchPrefix
);
309 $result = PageArchive
::listPagesByPrefix( $this->mSearchPrefix
);
311 $this->showList( $result );
316 * Generic list of deleted pages
318 * @param IResultWrapper $result
321 private function showList( $result ) {
322 $out = $this->getOutput();
324 if ( $result->numRows() == 0 ) {
325 $out->addWikiMsg( 'undelete-no-results' );
330 $out->addWikiMsg( 'undeletepagetext', $this->getLanguage()->formatNum( $result->numRows() ) );
332 $linkRenderer = $this->getLinkRenderer();
333 $undelete = $this->getPageTitle();
334 $out->addHTML( "<ul id='undeleteResultsList'>\n" );
335 foreach ( $result as $row ) {
336 $title = Title
::makeTitleSafe( $row->ar_namespace
, $row->ar_title
);
337 if ( $title !== null ) {
338 $item = $linkRenderer->makeKnownLink(
340 $title->getPrefixedText(),
342 [ 'target' => $title->getPrefixedText() ]
345 // The title is no longer valid, show as text
346 $item = Html
::element(
348 [ 'class' => 'mw-invalidtitle' ],
349 Linker
::getInvalidTitleDescription(
356 $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count
)->parse();
360 [ 'class' => 'undeleteResult' ],
366 $out->addHTML( "</ul>\n" );
371 private function showRevision( $timestamp ) {
372 if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
376 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
377 if ( !Hooks
::run( 'UndeleteForm::showRevision', [ &$archive, $this->mTargetObj
] ) ) {
380 $rev = $archive->getRevision( $timestamp );
382 $out = $this->getOutput();
383 $user = $this->getUser();
386 $out->addWikiMsg( 'undeleterevision-missing' );
391 if ( $rev->isDeleted( RevisionRecord
::DELETED_TEXT
) ) {
392 if ( !$rev->userCan( RevisionRecord
::DELETED_TEXT
, $user ) ) {
394 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
395 $rev->isDeleted( RevisionRecord
::DELETED_RESTRICTED
) ?
396 'rev-suppressed-text-permission' : 'rev-deleted-text-permission'
403 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
404 $rev->isDeleted( RevisionRecord
::DELETED_RESTRICTED
) ?
405 'rev-suppressed-text-view' : 'rev-deleted-text-view'
407 $out->addHTML( '<br />' );
408 // and we are allowed to see...
411 if ( $this->mDiff
) {
412 $previousRev = $archive->getPreviousRevision( $timestamp );
413 if ( $previousRev ) {
414 $this->showDiff( $previousRev, $rev );
415 if ( $this->mDiffOnly
) {
419 $out->addHTML( '<hr />' );
421 $out->addWikiMsg( 'undelete-nodiff' );
425 $link = $this->getLinkRenderer()->makeKnownLink(
426 $this->getPageTitle( $this->mTargetObj
->getPrefixedDBkey() ),
427 $this->mTargetObj
->getPrefixedText()
430 $lang = $this->getLanguage();
432 // date and time are separate parameters to facilitate localisation.
433 // $time is kept for backward compat reasons.
434 $time = $lang->userTimeAndDate( $timestamp, $user );
435 $d = $lang->userDate( $timestamp, $user );
436 $t = $lang->userTime( $timestamp, $user );
437 $userLink = Linker
::revUserTools( $rev );
439 $content = $rev->getContent( RevisionRecord
::FOR_THIS_USER
, $user );
441 // TODO: MCR: this will have to become something like $hasTextSlots and $hasNonTextSlots
442 $isText = ( $content instanceof TextContent
);
444 if ( $this->mPreview ||
$isText ) {
445 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
447 $openDiv = '<div id="mw-undelete-revision">';
449 $out->addHTML( $openDiv );
451 // Revision delete links
452 if ( !$this->mDiff
) {
453 $revdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
455 $out->addHTML( "$revdel " );
461 Message
::rawParam( $link ), $time,
462 Message
::rawParam( $userLink ), $d, $t
464 $out->addHTML( '</div>' );
466 if ( !Hooks
::run( 'UndeleteShowRevision', [ $this->mTargetObj
, $rev ] ) ) {
470 if ( $this->mPreview ||
!$isText ) {
471 // NOTE: non-text content has no source view, so always use rendered preview
473 $popts = $out->parserOptions();
474 $renderer = MediaWikiServices
::getInstance()->getRevisionRenderer();
476 $rendered = $renderer->getRenderedRevision(
477 $rev->getRevisionRecord(),
480 [ 'audience' => RevisionRecord
::FOR_THIS_USER
]
483 // Fail hard if the audience check fails, since we already checked
484 // at the beginning of this method.
485 $pout = $rendered->getRevisionParserOutput();
487 $out->addParserOutput( $pout, [
488 'enableSectionEditLinks' => false,
496 '@phan-var TextContent $content';
497 // TODO: MCR: make this work for multiple slots
498 // source view for textual content
499 $sourceView = Xml
::element( 'textarea', [
500 'readonly' => 'readonly',
503 ], $content->getText() . "\n" );
505 $buttonFields[] = new OOUI\
ButtonInputWidget( [
508 'label' => $this->msg( 'showpreview' )->text()
514 $buttonFields[] = new OOUI\
ButtonInputWidget( [
517 'label' => $this->msg( 'showdiff' )->text()
522 Xml
::openElement( 'div', [
523 'style' => 'clear: both' ] ) .
524 Xml
::openElement( 'form', [
526 'action' => $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] ) ] ) .
527 Xml
::element( 'input', [
530 'value' => $this->mTargetObj
->getPrefixedDBkey() ] ) .
531 Xml
::element( 'input', [
533 'name' => 'timestamp',
534 'value' => $timestamp ] ) .
535 Xml
::element( 'input', [
537 'name' => 'wpEditToken',
538 'value' => $user->getEditToken() ] ) .
539 new OOUI\
FieldLayout(
541 'content' => new OOUI\
HorizontalLayout( [
542 'items' => $buttonFields
546 Xml
::closeElement( 'form' ) .
547 Xml
::closeElement( 'div' )
552 * Build a diff display between this and the previous either deleted
553 * or non-deleted edit.
555 * @param Revision $previousRev
556 * @param Revision $currentRev
558 function showDiff( $previousRev, $currentRev ) {
559 $diffContext = clone $this->getContext();
560 $diffContext->setTitle( $currentRev->getTitle() );
561 $diffContext->setWikiPage( WikiPage
::factory( $currentRev->getTitle() ) );
563 $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
564 $diffEngine->setRevisions( $previousRev->getRevisionRecord(), $currentRev->getRevisionRecord() );
565 $diffEngine->showDiffStyle();
566 $formattedDiff = $diffEngine->getDiff(
567 $this->diffHeader( $previousRev, 'o' ),
568 $this->diffHeader( $currentRev, 'n' )
571 $this->getOutput()->addHTML( "<div>$formattedDiff</div>\n" );
575 * @param Revision $rev
576 * @param string $prefix
579 private function diffHeader( $rev, $prefix ) {
580 $isDeleted = !( $rev->getId() && $rev->getTitle() );
582 /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
583 $targetPage = $this->getPageTitle();
585 'target' => $this->mTargetObj
->getPrefixedText(),
586 'timestamp' => wfTimestamp( TS_MW
, $rev->getTimestamp() )
589 /// @todo FIXME: getId() may return non-zero for deleted revs...
590 $targetPage = $rev->getTitle();
591 $targetQuery = [ 'oldid' => $rev->getId() ];
594 // Add show/hide deletion links if available
595 $user = $this->getUser();
596 $lang = $this->getLanguage();
597 $rdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
603 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
605 $tagIds = wfGetDB( DB_REPLICA
)->selectFieldValues(
608 [ 'ct_rev_id' => $rev->getId() ],
612 $changeTagDefStore = MediaWikiServices
::getInstance()->getChangeTagDefStore();
613 foreach ( $tagIds as $tagId ) {
615 $tags[] = $changeTagDefStore->getName( (int)$tagId );
616 } catch ( NameTableAccessException
$exception ) {
620 $tags = implode( ',', $tags );
621 $tagSummary = ChangeTags
::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() );
623 // FIXME This is reimplementing DifferenceEngine#getRevisionHeader
624 // and partially #showDiffPage, but worse
625 return '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
626 $this->getLinkRenderer()->makeLink(
630 $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
631 $lang->userDate( $rev->getTimestamp(), $user ),
632 $lang->userTime( $rev->getTimestamp(), $user )
638 '<div id="mw-diff-' . $prefix . 'title2">' .
639 Linker
::revUserTools( $rev ) . '<br />' .
641 '<div id="mw-diff-' . $prefix . 'title3">' .
642 $minor . Linker
::revComment( $rev ) . $rdel . '<br />' .
644 '<div id="mw-diff-' . $prefix . 'title5">' .
645 $tagSummary[0] . '<br />' .
650 * Show a form confirming whether a tokenless user really wants to see a file
653 private function showFileConfirmationForm( $key ) {
654 $out = $this->getOutput();
655 $lang = $this->getLanguage();
656 $user = $this->getUser();
657 $file = new ArchivedFile( $this->mTargetObj
, 0, $this->mFilename
);
658 $out->addWikiMsg( 'undelete-show-file-confirm',
659 $this->mTargetObj
->getText(),
660 $lang->userDate( $file->getTimestamp(), $user ),
661 $lang->userTime( $file->getTimestamp(), $user ) );
663 Xml
::openElement( 'form', [
665 'action' => $this->getPageTitle()->getLocalURL( [
666 'target' => $this->mTarget
,
668 'token' => $user->getEditToken( $key ),
672 Xml
::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
678 * Show a deleted file version requested by the visitor.
681 private function showFile( $key ) {
682 $this->getOutput()->disable();
684 # We mustn't allow the output to be CDN cached, otherwise
685 # if an admin previews a deleted image, and it's cached, then
686 # a user without appropriate permissions can toddle off and
687 # nab the image, and CDN will serve it
688 $response = $this->getRequest()->response();
689 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
690 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
691 $response->header( 'Pragma: no-cache' );
693 $repo = RepoGroup
::singleton()->getLocalRepo();
694 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
695 $repo->streamFileWithStatus( $path );
698 protected function showHistory() {
699 $this->checkReadOnly();
701 $out = $this->getOutput();
702 if ( $this->mAllowed
) {
703 $out->addModules( 'mediawiki.special.undelete' );
706 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
707 [ 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj
->getPrefixedText() ) ]
710 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
711 Hooks
::run( 'UndeleteForm::showHistory', [ &$archive, $this->mTargetObj
] );
713 $out->addHTML( '<div class="mw-undelete-history">' );
714 if ( $this->mAllowed
) {
715 $out->addWikiMsg( 'undeletehistory' );
716 $out->addWikiMsg( 'undeleterevdel' );
718 $out->addWikiMsg( 'undeletehistorynoadmin' );
720 $out->addHTML( '</div>' );
722 # List all stored revisions
723 $revisions = $archive->listRevisions();
724 $files = $archive->listFiles();
726 $haveRevisions = $revisions && $revisions->numRows() > 0;
727 $haveFiles = $files && $files->numRows() > 0;
729 # Batch existence check on user and talk pages
730 if ( $haveRevisions ) {
731 $batch = new LinkBatch();
732 foreach ( $revisions as $row ) {
733 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
734 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
737 $revisions->seek( 0 );
740 $batch = new LinkBatch();
741 foreach ( $files as $row ) {
742 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
743 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
749 if ( $this->mAllowed
) {
752 $action = $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] );
753 # Start the form here
754 $form = new OOUI\
FormLayout( [
761 # Show relevant lines from the deletion log:
762 $deleteLogPage = new LogPage( 'delete' );
763 $out->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) . "\n" );
764 LogEventsList
::showLogExtract( $out, 'delete', $this->mTargetObj
);
765 # Show relevant lines from the suppression log:
766 $suppressLogPage = new LogPage( 'suppress' );
767 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
768 $out->addHTML( Xml
::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
769 LogEventsList
::showLogExtract( $out, 'suppress', $this->mTargetObj
);
772 if ( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
774 $fields[] = new OOUI\
Layout( [
775 'content' => new OOUI\
HtmlSnippet( $this->msg( 'undeleteextrahelp' )->parseAsBlock() )
778 $fields[] = new OOUI\
FieldLayout(
779 new OOUI\
TextInputWidget( [
780 'name' => 'wpComment',
781 'inputId' => 'wpComment',
783 'value' => $this->mComment
,
785 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
786 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
787 // Unicode codepoints.
788 'maxLength' => CommentStore
::COMMENT_CHARACTER_LIMIT
,
791 'label' => $this->msg( 'undeletecomment' )->text(),
796 $fields[] = new OOUI\
FieldLayout(
798 'content' => new OOUI\
HorizontalLayout( [
800 new OOUI\
ButtonInputWidget( [
802 'inputId' => 'mw-undelete-submit',
804 'label' => $this->msg( 'undeletebtn' )->text(),
805 'flags' => [ 'primary', 'progressive' ],
808 new OOUI\
ButtonInputWidget( [
810 'inputId' => 'mw-undelete-invert',
812 'label' => $this->msg( 'undeleteinvert' )->text()
819 if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
820 $fields[] = new OOUI\
FieldLayout(
821 new OOUI\
CheckboxInputWidget( [
822 'name' => 'wpUnsuppress',
823 'inputId' => 'mw-undelete-unsuppress',
827 'label' => $this->msg( 'revdelete-unsuppress' )->text(),
833 $fieldset = new OOUI\
FieldsetLayout( [
834 'label' => $this->msg( 'undelete-fieldset-title' )->text(),
835 'id' => 'mw-undelete-table',
839 $form->appendContent(
840 new OOUI\
PanelLayout( [
844 'content' => $fieldset,
846 new OOUI\
HtmlSnippet(
847 Html
::hidden( 'target', $this->mTarget
) .
848 Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() )
854 $history .= Xml
::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n";
856 if ( $haveRevisions ) {
857 # Show the page's stored (deleted) history
859 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
860 $history .= Html
::element(
865 'class' => 'deleterevision-log-submit mw-log-deleterevision-button'
867 $this->msg( 'showhideselectedversions' )->text()
871 $history .= '<ul class="mw-undelete-revlist">';
872 $remaining = $revisions->numRows();
873 $earliestLiveTime = $this->mTargetObj
->getEarliestRevTime();
875 foreach ( $revisions as $row ) {
877 $history .= $this->formatRevisionRow( $row, $earliestLiveTime, $remaining );
882 $out->addWikiMsg( 'nohistory' );
886 $history .= Xml
::element( 'h2', null, $this->msg( 'filehist' )->text() ) . "\n";
887 $history .= '<ul class="mw-undelete-revlist">';
888 foreach ( $files as $row ) {
889 $history .= $this->formatFileRow( $row );
895 if ( $this->mAllowed
) {
896 # Slip in the hidden controls here
897 $misc = Html
::hidden( 'target', $this->mTarget
);
898 $misc .= Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
901 $form->appendContent( new OOUI\
HtmlSnippet( $history ) );
902 $out->addHTML( $form );
904 $out->addHTML( $history );
910 protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
911 $rev = Revision
::newFromArchiveRow( $row,
913 'title' => $this->mTargetObj
917 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
918 // Build checkboxen...
919 if ( $this->mAllowed
) {
920 if ( $this->mInvert
) {
921 if ( in_array( $ts, $this->mTargetTimestamp
) ) {
922 $checkBox = Xml
::check( "ts$ts" );
924 $checkBox = Xml
::check( "ts$ts", true );
927 $checkBox = Xml
::check( "ts$ts" );
933 // Build page & diff links...
934 $user = $this->getUser();
935 if ( $this->mCanView
) {
936 $titleObj = $this->getPageTitle();
938 if ( !$rev->userCan( RevisionRecord
::DELETED_TEXT
, $this->getUser() ) ) {
939 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
940 $last = $this->msg( 'diff' )->escaped();
941 } elseif ( $remaining > 0 ||
( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
942 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
943 $last = $this->getLinkRenderer()->makeKnownLink(
945 $this->msg( 'diff' )->text(),
948 'target' => $this->mTargetObj
->getPrefixedText(),
954 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
955 $last = $this->msg( 'diff' )->escaped();
958 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
959 $last = $this->msg( 'diff' )->escaped();
963 $userLink = Linker
::revUserTools( $rev );
966 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
968 // Revision text size
969 $size = $row->ar_len
;
970 if ( !is_null( $size ) ) {
971 $revTextSize = Linker
::formatRevisionSize( $size );
975 $comment = Linker
::revComment( $rev );
979 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
985 $attribs['class'] = implode( ' ', $classes );
988 $revisionRow = $this->msg( 'undelete-revision-row2' )
1001 return Xml
::tags( 'li', $attribs, $revisionRow ) . "\n";
1004 private function formatFileRow( $row ) {
1005 $file = ArchivedFile
::newFromRow( $row );
1006 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
1007 $user = $this->getUser();
1010 if ( $this->mCanView
&& $row->fa_storage_key
) {
1011 if ( $this->mAllowed
) {
1012 $checkBox = Xml
::check( 'fileid' . $row->fa_id
);
1014 $key = urlencode( $row->fa_storage_key
);
1015 $pageLink = $this->getFileLink( $file, $this->getPageTitle(), $ts, $key );
1017 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
1019 $userLink = $this->getFileUser( $file );
1020 $data = $this->msg( 'widthheight' )->numParams( $row->fa_width
, $row->fa_height
)->text();
1021 $bytes = $this->msg( 'parentheses' )
1022 ->plaintextParams( $this->msg( 'nbytes' )->numParams( $row->fa_size
)->text() )
1024 $data = htmlspecialchars( $data . ' ' . $bytes );
1025 $comment = $this->getFileComment( $file );
1027 // Add show/hide deletion links if available
1028 $canHide = $this->isAllowed( 'deleterevision' );
1029 if ( $canHide ||
( $file->getVisibility() && $this->isAllowed( 'deletedhistory' ) ) ) {
1030 if ( !$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
1031 // Revision was hidden from sysops
1032 $revdlink = Linker
::revDeleteLinkDisabled( $canHide );
1035 'type' => 'filearchive',
1036 'target' => $this->mTargetObj
->getPrefixedDBkey(),
1037 'ids' => $row->fa_id
1039 $revdlink = Linker
::revDeleteLink( $query,
1040 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1046 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1050 * Fetch revision text link if it's available to all users
1052 * @param Revision $rev
1053 * @param Title $titleObj
1054 * @param string $ts Timestamp
1057 function getPageLink( $rev, $titleObj, $ts ) {
1058 $user = $this->getUser();
1059 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1061 if ( !$rev->userCan( RevisionRecord
::DELETED_TEXT
, $user ) ) {
1062 return '<span class="history-deleted">' . $time . '</span>';
1065 $link = $this->getLinkRenderer()->makeKnownLink(
1070 'target' => $this->mTargetObj
->getPrefixedText(),
1075 if ( $rev->isDeleted( RevisionRecord
::DELETED_TEXT
) ) {
1076 $link = '<span class="history-deleted">' . $link . '</span>';
1083 * Fetch image view link if it's available to all users
1085 * @param File|ArchivedFile $file
1086 * @param Title $titleObj
1087 * @param string $ts A timestamp
1088 * @param string $key A storage key
1090 * @return string HTML fragment
1092 function getFileLink( $file, $titleObj, $ts, $key ) {
1093 $user = $this->getUser();
1094 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1096 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
1097 return '<span class="history-deleted">' . htmlspecialchars( $time ) . '</span>';
1100 $link = $this->getLinkRenderer()->makeKnownLink(
1105 'target' => $this->mTargetObj
->getPrefixedText(),
1107 'token' => $user->getEditToken( $key )
1111 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
1112 $link = '<span class="history-deleted">' . $link . '</span>';
1119 * Fetch file's user id if it's available to this user
1121 * @param File|ArchivedFile $file
1122 * @return string HTML fragment
1124 function getFileUser( $file ) {
1125 if ( !$file->userCan( File
::DELETED_USER
, $this->getUser() ) ) {
1126 return '<span class="history-deleted">' .
1127 $this->msg( 'rev-deleted-user' )->escaped() .
1131 $link = Linker
::userLink( $file->getRawUser(), $file->getRawUserText() ) .
1132 Linker
::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1134 if ( $file->isDeleted( File
::DELETED_USER
) ) {
1135 $link = '<span class="history-deleted">' . $link . '</span>';
1142 * Fetch file upload comment if it's available to this user
1144 * @param File|ArchivedFile $file
1145 * @return string HTML fragment
1147 function getFileComment( $file ) {
1148 if ( !$file->userCan( File
::DELETED_COMMENT
, $this->getUser() ) ) {
1149 return '<span class="history-deleted"><span class="comment">' .
1150 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></span>';
1153 $link = Linker
::commentBlock( $file->getRawDescription() );
1155 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
1156 $link = '<span class="history-deleted">' . $link . '</span>';
1162 function undelete() {
1163 if ( $this->getConfig()->get( 'UploadMaintenance' )
1164 && $this->mTargetObj
->getNamespace() == NS_FILE
1166 throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
1169 $this->checkReadOnly();
1171 $out = $this->getOutput();
1172 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1173 Hooks
::run( 'UndeleteForm::undelete', [ &$archive, $this->mTargetObj
] );
1174 $ok = $archive->undelete(
1175 $this->mTargetTimestamp
,
1177 $this->mFileVersions
,
1182 if ( is_array( $ok ) ) {
1183 if ( $ok[1] ) { // Undeleted file count
1184 Hooks
::run( 'FileUndeleteComplete', [
1185 $this->mTargetObj
, $this->mFileVersions
,
1186 $this->getUser(), $this->mComment
] );
1189 $link = $this->getLinkRenderer()->makeKnownLink( $this->mTargetObj
);
1190 $out->addWikiMsg( 'undeletedpage', Message
::rawParam( $link ) );
1192 $out->setPageTitle( $this->msg( 'undelete-error' ) );
1195 // Show revision undeletion warnings and errors
1196 $status = $archive->getRevisionStatus();
1197 if ( $status && !$status->isGood() ) {
1198 $out->wrapWikiTextAsInterface(
1200 '<div id="mw-error-cannotundelete">' .
1201 $status->getWikiText(
1208 // Show file undeletion warnings and errors
1209 $status = $archive->getFileStatus();
1210 if ( $status && !$status->isGood() ) {
1211 $out->wrapWikiTextAsInterface(
1213 $status->getWikiText(
1214 'undelete-error-short',
1215 'undelete-error-long'
1222 * Return an array of subpages beginning with $search that this special page will accept.
1224 * @param string $search Prefix to search for
1225 * @param int $limit Maximum number of results to return (usually 10)
1226 * @param int $offset Number of results to skip (usually 0)
1227 * @return string[] Matching subpages
1229 public function prefixSearchSubpages( $search, $limit, $offset ) {
1230 return $this->prefixSearchString( $search, $limit, $offset );
1233 protected function getGroupName() {