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;
56 /** @var int[]|null */
57 private $mFileVersions;
62 * @var string Search prefix
64 private $mSearchPrefix;
66 function __construct() {
67 parent
::__construct( 'Undelete', 'deletedhistory' );
70 public function doesWrites() {
74 function loadRequest( $par ) {
75 $request = $this->getRequest();
76 $user = $this->getUser();
78 $this->mAction
= $request->getVal( 'action' );
79 if ( $par !== null && $par !== '' ) {
80 $this->mTarget
= $par;
82 $this->mTarget
= $request->getVal( 'target' );
85 $this->mTargetObj
= null;
87 if ( $this->mTarget
!== null && $this->mTarget
!== '' ) {
88 $this->mTargetObj
= Title
::newFromText( $this->mTarget
);
91 $this->mSearchPrefix
= $request->getText( 'prefix' );
92 $time = $request->getVal( 'timestamp' );
93 $this->mTimestamp
= $time ?
wfTimestamp( TS_MW
, $time ) : '';
94 $this->mFilename
= $request->getVal( 'file' );
96 $posted = $request->wasPosted() &&
97 $user->matchEditToken( $request->getVal( 'wpEditToken' ) );
98 $this->mRestore
= $request->getCheck( 'restore' ) && $posted;
99 $this->mRevdel
= $request->getCheck( 'revdel' ) && $posted;
100 $this->mInvert
= $request->getCheck( 'invert' ) && $posted;
101 $this->mPreview
= $request->getCheck( 'preview' ) && $posted;
102 $this->mDiff
= $request->getCheck( 'diff' );
103 $this->mDiffOnly
= $request->getBool( 'diffonly', $this->getUser()->getOption( 'diffonly' ) );
104 $this->mComment
= $request->getText( 'wpComment' );
105 $this->mUnsuppress
= $request->getVal( 'wpUnsuppress' ) && MediaWikiServices
::getInstance()
106 ->getPermissionManager()
107 ->userHasRight( $user, 'suppressrevision' );
108 $this->mToken
= $request->getVal( 'token' );
110 $block = $user->getBlock();
111 if ( $this->isAllowed( 'undelete' ) && !( $block && $block->isSitewide() ) ) {
112 $this->mAllowed
= true; // user can restore
113 $this->mCanView
= true; // user can view content
114 } elseif ( $this->isAllowed( 'deletedtext' ) ) {
115 $this->mAllowed
= false; // user cannot restore
116 $this->mCanView
= true; // user can view content
117 $this->mRestore
= false;
118 } else { // user can only view the list of revisions
119 $this->mAllowed
= false;
120 $this->mCanView
= false;
121 $this->mTimestamp
= '';
122 $this->mRestore
= false;
125 if ( $this->mRestore ||
$this->mInvert
) {
127 $this->mFileVersions
= [];
128 foreach ( $request->getValues() as $key => $val ) {
130 if ( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
131 array_push( $timestamps, $matches[1] );
134 if ( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
135 $this->mFileVersions
[] = intval( $matches[1] );
138 rsort( $timestamps );
139 $this->mTargetTimestamp
= $timestamps;
144 * Checks whether a user is allowed the permission for the
145 * specific title if one is set.
147 * @param string $permission
148 * @param User|null $user
151 protected function isAllowed( $permission, User
$user = null ) {
152 $user = $user ?
: $this->getUser();
153 $permissionManager = MediaWikiServices
::getInstance()->getPermissionManager();
155 if ( $this->mTargetObj
!== null ) {
156 return $permissionManager->userCan( $permission, $user, $this->mTargetObj
);
158 return $permissionManager->userHasRight( $user, $permission );
162 function userCanExecute( User
$user ) {
163 return $this->isAllowed( $this->mRestriction
, $user );
166 function execute( $par ) {
167 $this->useTransactionalTimeLimit();
169 $user = $this->getUser();
172 $this->outputHeader();
173 $this->addHelpLink( 'Help:Deletion_and_undeletion' );
175 $this->loadRequest( $par );
176 $this->checkPermissions(); // Needs to be after mTargetObj is set
178 $out = $this->getOutput();
180 if ( is_null( $this->mTargetObj
) ) {
181 $out->addWikiMsg( 'undelete-header' );
183 # Not all users can just browse every deleted page from the list
184 if ( MediaWikiServices
::getInstance()
185 ->getPermissionManager()
186 ->userHasRight( $user, 'browsearchive' )
188 $this->showSearchForm();
194 $this->addHelpLink( 'Help:Undelete' );
195 if ( $this->mAllowed
) {
196 $out->setPageTitle( $this->msg( 'undeletepage' ) );
198 $out->setPageTitle( $this->msg( 'viewdeletedpage' ) );
201 $this->getSkin()->setRelevantTitle( $this->mTargetObj
);
203 if ( $this->mTimestamp
!== '' ) {
204 $this->showRevision( $this->mTimestamp
);
205 } elseif ( $this->mFilename
!== null && $this->mTargetObj
->inNamespace( NS_FILE
) ) {
206 $file = new ArchivedFile( $this->mTargetObj
, 0, $this->mFilename
);
207 // Check if user is allowed to see this file
208 if ( !$file->exists() ) {
209 $out->addWikiMsg( 'filedelete-nofile', $this->mFilename
);
210 } elseif ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
211 if ( $file->isDeleted( File
::DELETED_RESTRICTED
) ) {
212 throw new PermissionsError( 'suppressrevision' );
214 throw new PermissionsError( 'deletedtext' );
216 } elseif ( !$user->matchEditToken( $this->mToken
, $this->mFilename
) ) {
217 $this->showFileConfirmationForm( $this->mFilename
);
219 $this->showFile( $this->mFilename
);
221 } elseif ( $this->mAction
=== 'submit' ) {
222 if ( $this->mRestore
) {
224 } elseif ( $this->mRevdel
) {
225 $this->redirectToRevDel();
229 $this->showHistory();
234 * Convert submitted form data to format expected by RevisionDelete and
235 * redirect the request
237 private function redirectToRevDel() {
238 $archive = new PageArchive( $this->mTargetObj
);
242 foreach ( $this->getRequest()->getValues() as $key => $val ) {
244 if ( preg_match( "/^ts(\d{14})$/", $key, $matches ) ) {
245 $revisions[$archive->getRevision( $matches[1] )->getId()] = 1;
250 'type' => 'revision',
252 'target' => $this->mTargetObj
->getPrefixedText()
254 $url = SpecialPage
::getTitleFor( 'Revisiondelete' )->getFullURL( $query );
255 $this->getOutput()->redirect( $url );
258 function showSearchForm() {
259 $out = $this->getOutput();
260 $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
261 $fuzzySearch = $this->getRequest()->getVal( 'fuzzy', true );
266 $fields[] = new OOUI\
ActionFieldLayout(
267 new OOUI\
TextInputWidget( [
269 'inputId' => 'prefix',
271 'value' => $this->mSearchPrefix
,
274 new OOUI\
ButtonInputWidget( [
275 'label' => $this->msg( 'undelete-search-submit' )->text(),
276 'flags' => [ 'primary', 'progressive' ],
277 'inputId' => 'searchUndelete',
281 'label' => new OOUI\
HtmlSnippet(
283 $fuzzySearch ?
'undelete-search-full' : 'undelete-search-prefix'
290 $fieldset = new OOUI\
FieldsetLayout( [
291 'label' => $this->msg( 'undelete-search-box' )->text(),
295 $form = new OOUI\
FormLayout( [
297 'action' => wfScript(),
300 $form->appendContent(
302 new OOUI\
HtmlSnippet(
303 Html
::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
304 Html
::hidden( 'fuzzy', $fuzzySearch )
309 new OOUI\
PanelLayout( [
317 # List undeletable articles
318 if ( $this->mSearchPrefix
) {
319 // For now, we enable search engine match only when specifically asked to
320 // by using fuzzy=1 parameter.
321 if ( $fuzzySearch ) {
322 $result = PageArchive
::listPagesBySearch( $this->mSearchPrefix
);
324 $result = PageArchive
::listPagesByPrefix( $this->mSearchPrefix
);
326 $this->showList( $result );
331 * Generic list of deleted pages
333 * @param IResultWrapper $result
336 private function showList( $result ) {
337 $out = $this->getOutput();
339 if ( $result->numRows() == 0 ) {
340 $out->addWikiMsg( 'undelete-no-results' );
345 $out->addWikiMsg( 'undeletepagetext', $this->getLanguage()->formatNum( $result->numRows() ) );
347 $linkRenderer = $this->getLinkRenderer();
348 $undelete = $this->getPageTitle();
349 $out->addHTML( "<ul id='undeleteResultsList'>\n" );
350 foreach ( $result as $row ) {
351 $title = Title
::makeTitleSafe( $row->ar_namespace
, $row->ar_title
);
352 if ( $title !== null ) {
353 $item = $linkRenderer->makeKnownLink(
355 $title->getPrefixedText(),
357 [ 'target' => $title->getPrefixedText() ]
360 // The title is no longer valid, show as text
361 $item = Html
::element(
363 [ 'class' => 'mw-invalidtitle' ],
364 Linker
::getInvalidTitleDescription(
371 $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count
)->parse();
375 [ 'class' => 'undeleteResult' ],
381 $out->addHTML( "</ul>\n" );
386 private function showRevision( $timestamp ) {
387 if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
391 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
392 if ( !Hooks
::run( 'UndeleteForm::showRevision', [ &$archive, $this->mTargetObj
] ) ) {
395 $rev = $archive->getRevision( $timestamp );
397 $out = $this->getOutput();
398 $user = $this->getUser();
401 $out->addWikiMsg( 'undeleterevision-missing' );
406 if ( $rev->isDeleted( RevisionRecord
::DELETED_TEXT
) ) {
407 if ( !$rev->userCan( RevisionRecord
::DELETED_TEXT
, $user ) ) {
409 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
410 $rev->isDeleted( RevisionRecord
::DELETED_RESTRICTED
) ?
411 'rev-suppressed-text-permission' : 'rev-deleted-text-permission'
418 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
419 $rev->isDeleted( RevisionRecord
::DELETED_RESTRICTED
) ?
420 'rev-suppressed-text-view' : 'rev-deleted-text-view'
422 $out->addHTML( '<br />' );
423 // and we are allowed to see...
426 if ( $this->mDiff
) {
427 $previousRev = $archive->getPreviousRevision( $timestamp );
428 if ( $previousRev ) {
429 $this->showDiff( $previousRev, $rev );
430 if ( $this->mDiffOnly
) {
434 $out->addHTML( '<hr />' );
436 $out->addWikiMsg( 'undelete-nodiff' );
440 $link = $this->getLinkRenderer()->makeKnownLink(
441 $this->getPageTitle( $this->mTargetObj
->getPrefixedDBkey() ),
442 $this->mTargetObj
->getPrefixedText()
445 $lang = $this->getLanguage();
447 // date and time are separate parameters to facilitate localisation.
448 // $time is kept for backward compat reasons.
449 $time = $lang->userTimeAndDate( $timestamp, $user );
450 $d = $lang->userDate( $timestamp, $user );
451 $t = $lang->userTime( $timestamp, $user );
452 $userLink = Linker
::revUserTools( $rev );
454 $content = $rev->getContent( RevisionRecord
::FOR_THIS_USER
, $user );
456 // TODO: MCR: this will have to become something like $hasTextSlots and $hasNonTextSlots
457 $isText = ( $content instanceof TextContent
);
459 if ( $this->mPreview ||
$isText ) {
460 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
462 $openDiv = '<div id="mw-undelete-revision">';
464 $out->addHTML( $openDiv );
466 // Revision delete links
467 if ( !$this->mDiff
) {
468 $revdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
470 $out->addHTML( "$revdel " );
476 Message
::rawParam( $link ), $time,
477 Message
::rawParam( $userLink ), $d, $t
479 $out->addHTML( '</div>' );
481 if ( !Hooks
::run( 'UndeleteShowRevision', [ $this->mTargetObj
, $rev ] ) ) {
485 if ( $this->mPreview ||
!$isText ) {
486 // NOTE: non-text content has no source view, so always use rendered preview
488 $popts = $out->parserOptions();
489 $renderer = MediaWikiServices
::getInstance()->getRevisionRenderer();
491 $rendered = $renderer->getRenderedRevision(
492 $rev->getRevisionRecord(),
495 [ 'audience' => RevisionRecord
::FOR_THIS_USER
]
498 // Fail hard if the audience check fails, since we already checked
499 // at the beginning of this method.
500 $pout = $rendered->getRevisionParserOutput();
502 $out->addParserOutput( $pout, [
503 'enableSectionEditLinks' => false,
511 '@phan-var TextContent $content';
512 // TODO: MCR: make this work for multiple slots
513 // source view for textual content
514 $sourceView = Xml
::element( 'textarea', [
515 'readonly' => 'readonly',
518 ], $content->getText() . "\n" );
520 $buttonFields[] = new OOUI\
ButtonInputWidget( [
523 'label' => $this->msg( 'showpreview' )->text()
529 $buttonFields[] = new OOUI\
ButtonInputWidget( [
532 'label' => $this->msg( 'showdiff' )->text()
537 Xml
::openElement( 'div', [
538 'style' => 'clear: both' ] ) .
539 Xml
::openElement( 'form', [
541 'action' => $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] ) ] ) .
542 Xml
::element( 'input', [
545 'value' => $this->mTargetObj
->getPrefixedDBkey() ] ) .
546 Xml
::element( 'input', [
548 'name' => 'timestamp',
549 'value' => $timestamp ] ) .
550 Xml
::element( 'input', [
552 'name' => 'wpEditToken',
553 'value' => $user->getEditToken() ] ) .
554 new OOUI\
FieldLayout(
556 'content' => new OOUI\
HorizontalLayout( [
557 'items' => $buttonFields
561 Xml
::closeElement( 'form' ) .
562 Xml
::closeElement( 'div' )
567 * Build a diff display between this and the previous either deleted
568 * or non-deleted edit.
570 * @param Revision $previousRev
571 * @param Revision $currentRev
573 function showDiff( $previousRev, $currentRev ) {
574 $diffContext = clone $this->getContext();
575 $diffContext->setTitle( $currentRev->getTitle() );
576 $diffContext->setWikiPage( WikiPage
::factory( $currentRev->getTitle() ) );
578 $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
579 $diffEngine->setRevisions( $previousRev->getRevisionRecord(), $currentRev->getRevisionRecord() );
580 $diffEngine->showDiffStyle();
581 $formattedDiff = $diffEngine->getDiff(
582 $this->diffHeader( $previousRev, 'o' ),
583 $this->diffHeader( $currentRev, 'n' )
586 $this->getOutput()->addHTML( "<div>$formattedDiff</div>\n" );
590 * @param Revision $rev
591 * @param string $prefix
594 private function diffHeader( $rev, $prefix ) {
595 $isDeleted = !( $rev->getId() && $rev->getTitle() );
597 /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
598 $targetPage = $this->getPageTitle();
600 'target' => $this->mTargetObj
->getPrefixedText(),
601 'timestamp' => wfTimestamp( TS_MW
, $rev->getTimestamp() )
604 /// @todo FIXME: getId() may return non-zero for deleted revs...
605 $targetPage = $rev->getTitle();
606 $targetQuery = [ 'oldid' => $rev->getId() ];
609 // Add show/hide deletion links if available
610 $user = $this->getUser();
611 $lang = $this->getLanguage();
612 $rdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
618 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
620 $tagIds = wfGetDB( DB_REPLICA
)->selectFieldValues(
623 [ 'ct_rev_id' => $rev->getId() ],
627 $changeTagDefStore = MediaWikiServices
::getInstance()->getChangeTagDefStore();
628 foreach ( $tagIds as $tagId ) {
630 $tags[] = $changeTagDefStore->getName( (int)$tagId );
631 } catch ( NameTableAccessException
$exception ) {
635 $tags = implode( ',', $tags );
636 $tagSummary = ChangeTags
::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() );
638 // FIXME This is reimplementing DifferenceEngine#getRevisionHeader
639 // and partially #showDiffPage, but worse
640 return '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
641 $this->getLinkRenderer()->makeLink(
645 $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
646 $lang->userDate( $rev->getTimestamp(), $user ),
647 $lang->userTime( $rev->getTimestamp(), $user )
653 '<div id="mw-diff-' . $prefix . 'title2">' .
654 Linker
::revUserTools( $rev ) . '<br />' .
656 '<div id="mw-diff-' . $prefix . 'title3">' .
657 $minor . Linker
::revComment( $rev ) . $rdel . '<br />' .
659 '<div id="mw-diff-' . $prefix . 'title5">' .
660 $tagSummary[0] . '<br />' .
665 * Show a form confirming whether a tokenless user really wants to see a file
668 private function showFileConfirmationForm( $key ) {
669 $out = $this->getOutput();
670 $lang = $this->getLanguage();
671 $user = $this->getUser();
672 $file = new ArchivedFile( $this->mTargetObj
, 0, $this->mFilename
);
673 $out->addWikiMsg( 'undelete-show-file-confirm',
674 $this->mTargetObj
->getText(),
675 $lang->userDate( $file->getTimestamp(), $user ),
676 $lang->userTime( $file->getTimestamp(), $user ) );
678 Xml
::openElement( 'form', [
680 'action' => $this->getPageTitle()->getLocalURL( [
681 'target' => $this->mTarget
,
683 'token' => $user->getEditToken( $key ),
687 Xml
::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
693 * Show a deleted file version requested by the visitor.
696 private function showFile( $key ) {
697 $this->getOutput()->disable();
699 # We mustn't allow the output to be CDN cached, otherwise
700 # if an admin previews a deleted image, and it's cached, then
701 # a user without appropriate permissions can toddle off and
702 # nab the image, and CDN will serve it
703 $response = $this->getRequest()->response();
704 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
705 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
706 $response->header( 'Pragma: no-cache' );
708 $repo = RepoGroup
::singleton()->getLocalRepo();
709 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
710 $repo->streamFileWithStatus( $path );
713 protected function showHistory() {
714 $this->checkReadOnly();
716 $out = $this->getOutput();
717 if ( $this->mAllowed
) {
718 $out->addModules( 'mediawiki.special.undelete' );
721 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
722 [ 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj
->getPrefixedText() ) ]
725 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
726 Hooks
::run( 'UndeleteForm::showHistory', [ &$archive, $this->mTargetObj
] );
728 $out->addHTML( '<div class="mw-undelete-history">' );
729 if ( $this->mAllowed
) {
730 $out->addWikiMsg( 'undeletehistory' );
731 $out->addWikiMsg( 'undeleterevdel' );
733 $out->addWikiMsg( 'undeletehistorynoadmin' );
735 $out->addHTML( '</div>' );
737 # List all stored revisions
738 $revisions = $archive->listRevisions();
739 $files = $archive->listFiles();
741 $haveRevisions = $revisions && $revisions->numRows() > 0;
742 $haveFiles = $files && $files->numRows() > 0;
744 # Batch existence check on user and talk pages
745 if ( $haveRevisions ) {
746 $batch = new LinkBatch();
747 foreach ( $revisions as $row ) {
748 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
749 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
752 $revisions->seek( 0 );
755 $batch = new LinkBatch();
756 foreach ( $files as $row ) {
757 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
758 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
764 if ( $this->mAllowed
) {
767 $action = $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] );
768 # Start the form here
769 $form = new OOUI\
FormLayout( [
776 # Show relevant lines from the deletion log:
777 $deleteLogPage = new LogPage( 'delete' );
778 $out->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) . "\n" );
779 LogEventsList
::showLogExtract( $out, 'delete', $this->mTargetObj
);
780 # Show relevant lines from the suppression log:
781 $suppressLogPage = new LogPage( 'suppress' );
782 $permissionManager = MediaWikiServices
::getInstance()->getPermissionManager();
783 if ( $permissionManager->userHasRight( $this->getUser(), 'suppressionlog' ) ) {
784 $out->addHTML( Xml
::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
785 LogEventsList
::showLogExtract( $out, 'suppress', $this->mTargetObj
);
788 if ( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
790 $fields[] = new OOUI\
Layout( [
791 'content' => new OOUI\
HtmlSnippet( $this->msg( 'undeleteextrahelp' )->parseAsBlock() )
794 $fields[] = new OOUI\
FieldLayout(
795 new OOUI\
TextInputWidget( [
796 'name' => 'wpComment',
797 'inputId' => 'wpComment',
799 'value' => $this->mComment
,
801 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
802 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
803 // Unicode codepoints.
804 'maxLength' => CommentStore
::COMMENT_CHARACTER_LIMIT
,
807 'label' => $this->msg( 'undeletecomment' )->text(),
812 $fields[] = new OOUI\
FieldLayout(
814 'content' => new OOUI\
HorizontalLayout( [
816 new OOUI\
ButtonInputWidget( [
818 'inputId' => 'mw-undelete-submit',
820 'label' => $this->msg( 'undeletebtn' )->text(),
821 'flags' => [ 'primary', 'progressive' ],
824 new OOUI\
ButtonInputWidget( [
826 'inputId' => 'mw-undelete-invert',
828 'label' => $this->msg( 'undeleteinvert' )->text()
835 if ( $permissionManager->userHasRight( $this->getUser(), 'suppressrevision' ) ) {
836 $fields[] = new OOUI\
FieldLayout(
837 new OOUI\
CheckboxInputWidget( [
838 'name' => 'wpUnsuppress',
839 'inputId' => 'mw-undelete-unsuppress',
843 'label' => $this->msg( 'revdelete-unsuppress' )->text(),
849 $fieldset = new OOUI\
FieldsetLayout( [
850 'label' => $this->msg( 'undelete-fieldset-title' )->text(),
851 'id' => 'mw-undelete-table',
855 $form->appendContent(
856 new OOUI\
PanelLayout( [
860 'content' => $fieldset,
862 new OOUI\
HtmlSnippet(
863 Html
::hidden( 'target', $this->mTarget
) .
864 Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() )
870 $history .= Xml
::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n";
872 if ( $haveRevisions ) {
873 # Show the page's stored (deleted) history
875 if ( $permissionManager->userHasRight( $this->getUser(), 'deleterevision' ) ) {
876 $history .= Html
::element(
881 'class' => 'deleterevision-log-submit mw-log-deleterevision-button'
883 $this->msg( 'showhideselectedversions' )->text()
887 $history .= '<ul class="mw-undelete-revlist">';
888 $remaining = $revisions->numRows();
889 $earliestLiveTime = $this->mTargetObj
->getEarliestRevTime();
891 foreach ( $revisions as $row ) {
893 $history .= $this->formatRevisionRow( $row, $earliestLiveTime, $remaining );
898 $out->addWikiMsg( 'nohistory' );
902 $history .= Xml
::element( 'h2', null, $this->msg( 'filehist' )->text() ) . "\n";
903 $history .= '<ul class="mw-undelete-revlist">';
904 foreach ( $files as $row ) {
905 $history .= $this->formatFileRow( $row );
911 if ( $this->mAllowed
) {
912 # Slip in the hidden controls here
913 $misc = Html
::hidden( 'target', $this->mTarget
);
914 $misc .= Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
917 $form->appendContent( new OOUI\
HtmlSnippet( $history ) );
918 $out->addHTML( $form );
920 $out->addHTML( $history );
926 protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
927 $rev = Revision
::newFromArchiveRow( $row,
929 'title' => $this->mTargetObj
933 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
934 // Build checkboxen...
935 if ( $this->mAllowed
) {
936 if ( $this->mInvert
) {
937 if ( in_array( $ts, $this->mTargetTimestamp
) ) {
938 $checkBox = Xml
::check( "ts$ts" );
940 $checkBox = Xml
::check( "ts$ts", true );
943 $checkBox = Xml
::check( "ts$ts" );
949 // Build page & diff links...
950 $user = $this->getUser();
951 if ( $this->mCanView
) {
952 $titleObj = $this->getPageTitle();
954 if ( !$rev->userCan( RevisionRecord
::DELETED_TEXT
, $this->getUser() ) ) {
955 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
956 $last = $this->msg( 'diff' )->escaped();
957 } elseif ( $remaining > 0 ||
( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
958 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
959 $last = $this->getLinkRenderer()->makeKnownLink(
961 $this->msg( 'diff' )->text(),
964 'target' => $this->mTargetObj
->getPrefixedText(),
970 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
971 $last = $this->msg( 'diff' )->escaped();
974 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
975 $last = $this->msg( 'diff' )->escaped();
979 $userLink = Linker
::revUserTools( $rev );
982 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
984 // Revision text size
985 $size = $row->ar_len
;
986 if ( !is_null( $size ) ) {
987 $revTextSize = Linker
::formatRevisionSize( $size );
991 $comment = Linker
::revComment( $rev );
995 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
1001 $attribs['class'] = implode( ' ', $classes );
1004 $revisionRow = $this->msg( 'undelete-revision-row2' )
1017 return Xml
::tags( 'li', $attribs, $revisionRow ) . "\n";
1020 private function formatFileRow( $row ) {
1021 $file = ArchivedFile
::newFromRow( $row );
1022 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
1023 $user = $this->getUser();
1026 if ( $this->mCanView
&& $row->fa_storage_key
) {
1027 if ( $this->mAllowed
) {
1028 $checkBox = Xml
::check( 'fileid' . $row->fa_id
);
1030 $key = urlencode( $row->fa_storage_key
);
1031 $pageLink = $this->getFileLink( $file, $this->getPageTitle(), $ts, $key );
1033 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
1035 $userLink = $this->getFileUser( $file );
1036 $data = $this->msg( 'widthheight' )->numParams( $row->fa_width
, $row->fa_height
)->text();
1037 $bytes = $this->msg( 'parentheses' )
1038 ->plaintextParams( $this->msg( 'nbytes' )->numParams( $row->fa_size
)->text() )
1040 $data = htmlspecialchars( $data . ' ' . $bytes );
1041 $comment = $this->getFileComment( $file );
1043 // Add show/hide deletion links if available
1044 $canHide = $this->isAllowed( 'deleterevision' );
1045 if ( $canHide ||
( $file->getVisibility() && $this->isAllowed( 'deletedhistory' ) ) ) {
1046 if ( !$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
1047 // Revision was hidden from sysops
1048 $revdlink = Linker
::revDeleteLinkDisabled( $canHide );
1051 'type' => 'filearchive',
1052 'target' => $this->mTargetObj
->getPrefixedDBkey(),
1053 'ids' => $row->fa_id
1055 $revdlink = Linker
::revDeleteLink( $query,
1056 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1062 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1066 * Fetch revision text link if it's available to all users
1068 * @param Revision $rev
1069 * @param Title $titleObj
1070 * @param string $ts Timestamp
1073 function getPageLink( $rev, $titleObj, $ts ) {
1074 $user = $this->getUser();
1075 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1077 if ( !$rev->userCan( RevisionRecord
::DELETED_TEXT
, $user ) ) {
1078 return '<span class="history-deleted">' . $time . '</span>';
1081 $link = $this->getLinkRenderer()->makeKnownLink(
1086 'target' => $this->mTargetObj
->getPrefixedText(),
1091 if ( $rev->isDeleted( RevisionRecord
::DELETED_TEXT
) ) {
1092 $link = '<span class="history-deleted">' . $link . '</span>';
1099 * Fetch image view link if it's available to all users
1101 * @param File|ArchivedFile $file
1102 * @param Title $titleObj
1103 * @param string $ts A timestamp
1104 * @param string $key A storage key
1106 * @return string HTML fragment
1108 function getFileLink( $file, $titleObj, $ts, $key ) {
1109 $user = $this->getUser();
1110 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1112 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
1113 return '<span class="history-deleted">' . htmlspecialchars( $time ) . '</span>';
1116 $link = $this->getLinkRenderer()->makeKnownLink(
1121 'target' => $this->mTargetObj
->getPrefixedText(),
1123 'token' => $user->getEditToken( $key )
1127 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
1128 $link = '<span class="history-deleted">' . $link . '</span>';
1135 * Fetch file's user id if it's available to this user
1137 * @param File|ArchivedFile $file
1138 * @return string HTML fragment
1140 function getFileUser( $file ) {
1141 if ( !$file->userCan( File
::DELETED_USER
, $this->getUser() ) ) {
1142 return '<span class="history-deleted">' .
1143 $this->msg( 'rev-deleted-user' )->escaped() .
1147 $link = Linker
::userLink( $file->getRawUser(), $file->getRawUserText() ) .
1148 Linker
::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1150 if ( $file->isDeleted( File
::DELETED_USER
) ) {
1151 $link = '<span class="history-deleted">' . $link . '</span>';
1158 * Fetch file upload comment if it's available to this user
1160 * @param File|ArchivedFile $file
1161 * @return string HTML fragment
1163 function getFileComment( $file ) {
1164 if ( !$file->userCan( File
::DELETED_COMMENT
, $this->getUser() ) ) {
1165 return '<span class="history-deleted"><span class="comment">' .
1166 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></span>';
1169 $link = Linker
::commentBlock( $file->getRawDescription() );
1171 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
1172 $link = '<span class="history-deleted">' . $link . '</span>';
1178 function undelete() {
1179 if ( $this->getConfig()->get( 'UploadMaintenance' )
1180 && $this->mTargetObj
->getNamespace() == NS_FILE
1182 throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
1185 $this->checkReadOnly();
1187 $out = $this->getOutput();
1188 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1189 Hooks
::run( 'UndeleteForm::undelete', [ &$archive, $this->mTargetObj
] );
1190 $ok = $archive->undelete(
1191 $this->mTargetTimestamp
,
1193 $this->mFileVersions
,
1198 if ( is_array( $ok ) ) {
1199 if ( $ok[1] ) { // Undeleted file count
1200 Hooks
::run( 'FileUndeleteComplete', [
1201 $this->mTargetObj
, $this->mFileVersions
,
1202 $this->getUser(), $this->mComment
] );
1205 $link = $this->getLinkRenderer()->makeKnownLink( $this->mTargetObj
);
1206 $out->addWikiMsg( 'undeletedpage', Message
::rawParam( $link ) );
1208 $out->setPageTitle( $this->msg( 'undelete-error' ) );
1211 // Show revision undeletion warnings and errors
1212 $status = $archive->getRevisionStatus();
1213 if ( $status && !$status->isGood() ) {
1214 $out->wrapWikiTextAsInterface(
1216 '<div id="mw-error-cannotundelete">' .
1217 $status->getWikiText(
1224 // Show file undeletion warnings and errors
1225 $status = $archive->getFileStatus();
1226 if ( $status && !$status->isGood() ) {
1227 $out->wrapWikiTextAsInterface(
1229 $status->getWikiText(
1230 'undelete-error-short',
1231 'undelete-error-long'
1238 * Return an array of subpages beginning with $search that this special page will accept.
1240 * @param string $search Prefix to search for
1241 * @param int $limit Maximum number of results to return (usually 10)
1242 * @param int $offset Number of results to skip (usually 0)
1243 * @return string[] Matching subpages
1245 public function prefixSearchSubpages( $search, $limit, $offset ) {
1246 return $this->prefixSearchString( $search, $limit, $offset );
1249 protected function getGroupName() {