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' ) && $user->isAllowed( 'suppressrevision' );
106 $this->mToken
= $request->getVal( 'token' );
108 $block = $user->getBlock();
109 if ( $this->isAllowed( 'undelete' ) && !( $block && $block->isSitewide() ) ) {
110 $this->mAllowed
= true; // user can restore
111 $this->mCanView
= true; // user can view content
112 } elseif ( $this->isAllowed( 'deletedtext' ) ) {
113 $this->mAllowed
= false; // user cannot restore
114 $this->mCanView
= true; // user can view content
115 $this->mRestore
= false;
116 } else { // user can only view the list of revisions
117 $this->mAllowed
= false;
118 $this->mCanView
= false;
119 $this->mTimestamp
= '';
120 $this->mRestore
= false;
123 if ( $this->mRestore ||
$this->mInvert
) {
125 $this->mFileVersions
= [];
126 foreach ( $request->getValues() as $key => $val ) {
128 if ( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
129 array_push( $timestamps, $matches[1] );
132 if ( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
133 $this->mFileVersions
[] = intval( $matches[1] );
136 rsort( $timestamps );
137 $this->mTargetTimestamp
= $timestamps;
142 * Checks whether a user is allowed the permission for the
143 * specific title if one is set.
145 * @param string $permission
146 * @param User|null $user
149 protected function isAllowed( $permission, User
$user = null ) {
150 $user = $user ?
: $this->getUser();
151 $permissionManager = MediaWikiServices
::getInstance()->getPermissionManager();
153 if ( $this->mTargetObj
!== null ) {
154 return $permissionManager->userCan( $permission, $user, $this->mTargetObj
);
156 return $user->isAllowed( $permission );
160 function userCanExecute( User
$user ) {
161 return $this->isAllowed( $this->mRestriction
, $user );
164 function execute( $par ) {
165 $this->useTransactionalTimeLimit();
167 $user = $this->getUser();
170 $this->outputHeader();
171 $this->addHelpLink( 'Help:Deletion_and_undeletion' );
173 $this->loadRequest( $par );
174 $this->checkPermissions(); // Needs to be after mTargetObj is set
176 $out = $this->getOutput();
178 if ( is_null( $this->mTargetObj
) ) {
179 $out->addWikiMsg( 'undelete-header' );
181 # Not all users can just browse every deleted page from the list
182 if ( $user->isAllowed( 'browsearchive' ) ) {
183 $this->showSearchForm();
189 $this->addHelpLink( 'Help:Undelete' );
190 if ( $this->mAllowed
) {
191 $out->setPageTitle( $this->msg( 'undeletepage' ) );
193 $out->setPageTitle( $this->msg( 'viewdeletedpage' ) );
196 $this->getSkin()->setRelevantTitle( $this->mTargetObj
);
198 if ( $this->mTimestamp
!== '' ) {
199 $this->showRevision( $this->mTimestamp
);
200 } elseif ( $this->mFilename
!== null && $this->mTargetObj
->inNamespace( NS_FILE
) ) {
201 $file = new ArchivedFile( $this->mTargetObj
, 0, $this->mFilename
);
202 // Check if user is allowed to see this file
203 if ( !$file->exists() ) {
204 $out->addWikiMsg( 'filedelete-nofile', $this->mFilename
);
205 } elseif ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
206 if ( $file->isDeleted( File
::DELETED_RESTRICTED
) ) {
207 throw new PermissionsError( 'suppressrevision' );
209 throw new PermissionsError( 'deletedtext' );
211 } elseif ( !$user->matchEditToken( $this->mToken
, $this->mFilename
) ) {
212 $this->showFileConfirmationForm( $this->mFilename
);
214 $this->showFile( $this->mFilename
);
216 } elseif ( $this->mAction
=== 'submit' ) {
217 if ( $this->mRestore
) {
219 } elseif ( $this->mRevdel
) {
220 $this->redirectToRevDel();
224 $this->showHistory();
229 * Convert submitted form data to format expected by RevisionDelete and
230 * redirect the request
232 private function redirectToRevDel() {
233 $archive = new PageArchive( $this->mTargetObj
);
237 foreach ( $this->getRequest()->getValues() as $key => $val ) {
239 if ( preg_match( "/^ts(\d{14})$/", $key, $matches ) ) {
240 $revisions[$archive->getRevision( $matches[1] )->getId()] = 1;
245 'type' => 'revision',
247 'target' => $this->mTargetObj
->getPrefixedText()
249 $url = SpecialPage
::getTitleFor( 'Revisiondelete' )->getFullURL( $query );
250 $this->getOutput()->redirect( $url );
253 function showSearchForm() {
254 $out = $this->getOutput();
255 $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
256 $fuzzySearch = $this->getRequest()->getVal( 'fuzzy', true );
261 $fields[] = new OOUI\
ActionFieldLayout(
262 new OOUI\
TextInputWidget( [
264 'inputId' => 'prefix',
266 'value' => $this->mSearchPrefix
,
269 new OOUI\
ButtonInputWidget( [
270 'label' => $this->msg( 'undelete-search-submit' )->text(),
271 'flags' => [ 'primary', 'progressive' ],
272 'inputId' => 'searchUndelete',
276 'label' => new OOUI\
HtmlSnippet(
278 $fuzzySearch ?
'undelete-search-full' : 'undelete-search-prefix'
285 $fieldset = new OOUI\
FieldsetLayout( [
286 'label' => $this->msg( 'undelete-search-box' )->text(),
290 $form = new OOUI\
FormLayout( [
292 'action' => wfScript(),
295 $form->appendContent(
297 new OOUI\
HtmlSnippet(
298 Html
::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
299 Html
::hidden( 'fuzzy', $fuzzySearch )
304 new OOUI\
PanelLayout( [
312 # List undeletable articles
313 if ( $this->mSearchPrefix
) {
314 // For now, we enable search engine match only when specifically asked to
315 // by using fuzzy=1 parameter.
316 if ( $fuzzySearch ) {
317 $result = PageArchive
::listPagesBySearch( $this->mSearchPrefix
);
319 $result = PageArchive
::listPagesByPrefix( $this->mSearchPrefix
);
321 $this->showList( $result );
326 * Generic list of deleted pages
328 * @param IResultWrapper $result
331 private function showList( $result ) {
332 $out = $this->getOutput();
334 if ( $result->numRows() == 0 ) {
335 $out->addWikiMsg( 'undelete-no-results' );
340 $out->addWikiMsg( 'undeletepagetext', $this->getLanguage()->formatNum( $result->numRows() ) );
342 $linkRenderer = $this->getLinkRenderer();
343 $undelete = $this->getPageTitle();
344 $out->addHTML( "<ul id='undeleteResultsList'>\n" );
345 foreach ( $result as $row ) {
346 $title = Title
::makeTitleSafe( $row->ar_namespace
, $row->ar_title
);
347 if ( $title !== null ) {
348 $item = $linkRenderer->makeKnownLink(
350 $title->getPrefixedText(),
352 [ 'target' => $title->getPrefixedText() ]
355 // The title is no longer valid, show as text
356 $item = Html
::element(
358 [ 'class' => 'mw-invalidtitle' ],
359 Linker
::getInvalidTitleDescription(
366 $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count
)->parse();
370 [ 'class' => 'undeleteResult' ],
376 $out->addHTML( "</ul>\n" );
381 private function showRevision( $timestamp ) {
382 if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
386 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
387 if ( !Hooks
::run( 'UndeleteForm::showRevision', [ &$archive, $this->mTargetObj
] ) ) {
390 $rev = $archive->getRevision( $timestamp );
392 $out = $this->getOutput();
393 $user = $this->getUser();
396 $out->addWikiMsg( 'undeleterevision-missing' );
401 if ( $rev->isDeleted( RevisionRecord
::DELETED_TEXT
) ) {
402 if ( !$rev->userCan( RevisionRecord
::DELETED_TEXT
, $user ) ) {
404 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
405 $rev->isDeleted( RevisionRecord
::DELETED_RESTRICTED
) ?
406 'rev-suppressed-text-permission' : 'rev-deleted-text-permission'
413 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
414 $rev->isDeleted( RevisionRecord
::DELETED_RESTRICTED
) ?
415 'rev-suppressed-text-view' : 'rev-deleted-text-view'
417 $out->addHTML( '<br />' );
418 // and we are allowed to see...
421 if ( $this->mDiff
) {
422 $previousRev = $archive->getPreviousRevision( $timestamp );
423 if ( $previousRev ) {
424 $this->showDiff( $previousRev, $rev );
425 if ( $this->mDiffOnly
) {
429 $out->addHTML( '<hr />' );
431 $out->addWikiMsg( 'undelete-nodiff' );
435 $link = $this->getLinkRenderer()->makeKnownLink(
436 $this->getPageTitle( $this->mTargetObj
->getPrefixedDBkey() ),
437 $this->mTargetObj
->getPrefixedText()
440 $lang = $this->getLanguage();
442 // date and time are separate parameters to facilitate localisation.
443 // $time is kept for backward compat reasons.
444 $time = $lang->userTimeAndDate( $timestamp, $user );
445 $d = $lang->userDate( $timestamp, $user );
446 $t = $lang->userTime( $timestamp, $user );
447 $userLink = Linker
::revUserTools( $rev );
449 $content = $rev->getContent( RevisionRecord
::FOR_THIS_USER
, $user );
451 // TODO: MCR: this will have to become something like $hasTextSlots and $hasNonTextSlots
452 $isText = ( $content instanceof TextContent
);
454 if ( $this->mPreview ||
$isText ) {
455 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
457 $openDiv = '<div id="mw-undelete-revision">';
459 $out->addHTML( $openDiv );
461 // Revision delete links
462 if ( !$this->mDiff
) {
463 $revdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
465 $out->addHTML( "$revdel " );
471 Message
::rawParam( $link ), $time,
472 Message
::rawParam( $userLink ), $d, $t
474 $out->addHTML( '</div>' );
476 if ( !Hooks
::run( 'UndeleteShowRevision', [ $this->mTargetObj
, $rev ] ) ) {
480 if ( $this->mPreview ||
!$isText ) {
481 // NOTE: non-text content has no source view, so always use rendered preview
483 $popts = $out->parserOptions();
484 $renderer = MediaWikiServices
::getInstance()->getRevisionRenderer();
486 $rendered = $renderer->getRenderedRevision(
487 $rev->getRevisionRecord(),
490 [ 'audience' => RevisionRecord
::FOR_THIS_USER
]
493 // Fail hard if the audience check fails, since we already checked
494 // at the beginning of this method.
495 $pout = $rendered->getRevisionParserOutput();
497 $out->addParserOutput( $pout, [
498 'enableSectionEditLinks' => false,
506 '@phan-var TextContent $content';
507 // TODO: MCR: make this work for multiple slots
508 // source view for textual content
509 $sourceView = Xml
::element( 'textarea', [
510 'readonly' => 'readonly',
513 ], $content->getText() . "\n" );
515 $buttonFields[] = new OOUI\
ButtonInputWidget( [
518 'label' => $this->msg( 'showpreview' )->text()
524 $buttonFields[] = new OOUI\
ButtonInputWidget( [
527 'label' => $this->msg( 'showdiff' )->text()
532 Xml
::openElement( 'div', [
533 'style' => 'clear: both' ] ) .
534 Xml
::openElement( 'form', [
536 'action' => $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] ) ] ) .
537 Xml
::element( 'input', [
540 'value' => $this->mTargetObj
->getPrefixedDBkey() ] ) .
541 Xml
::element( 'input', [
543 'name' => 'timestamp',
544 'value' => $timestamp ] ) .
545 Xml
::element( 'input', [
547 'name' => 'wpEditToken',
548 'value' => $user->getEditToken() ] ) .
549 new OOUI\
FieldLayout(
551 'content' => new OOUI\
HorizontalLayout( [
552 'items' => $buttonFields
556 Xml
::closeElement( 'form' ) .
557 Xml
::closeElement( 'div' )
562 * Build a diff display between this and the previous either deleted
563 * or non-deleted edit.
565 * @param Revision $previousRev
566 * @param Revision $currentRev
568 function showDiff( $previousRev, $currentRev ) {
569 $diffContext = clone $this->getContext();
570 $diffContext->setTitle( $currentRev->getTitle() );
571 $diffContext->setWikiPage( WikiPage
::factory( $currentRev->getTitle() ) );
573 $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
574 $diffEngine->setRevisions( $previousRev->getRevisionRecord(), $currentRev->getRevisionRecord() );
575 $diffEngine->showDiffStyle();
576 $formattedDiff = $diffEngine->getDiff(
577 $this->diffHeader( $previousRev, 'o' ),
578 $this->diffHeader( $currentRev, 'n' )
581 $this->getOutput()->addHTML( "<div>$formattedDiff</div>\n" );
585 * @param Revision $rev
586 * @param string $prefix
589 private function diffHeader( $rev, $prefix ) {
590 $isDeleted = !( $rev->getId() && $rev->getTitle() );
592 /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
593 $targetPage = $this->getPageTitle();
595 'target' => $this->mTargetObj
->getPrefixedText(),
596 'timestamp' => wfTimestamp( TS_MW
, $rev->getTimestamp() )
599 /// @todo FIXME: getId() may return non-zero for deleted revs...
600 $targetPage = $rev->getTitle();
601 $targetQuery = [ 'oldid' => $rev->getId() ];
604 // Add show/hide deletion links if available
605 $user = $this->getUser();
606 $lang = $this->getLanguage();
607 $rdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
613 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
615 $tagIds = wfGetDB( DB_REPLICA
)->selectFieldValues(
618 [ 'ct_rev_id' => $rev->getId() ],
622 $changeTagDefStore = MediaWikiServices
::getInstance()->getChangeTagDefStore();
623 foreach ( $tagIds as $tagId ) {
625 $tags[] = $changeTagDefStore->getName( (int)$tagId );
626 } catch ( NameTableAccessException
$exception ) {
630 $tags = implode( ',', $tags );
631 $tagSummary = ChangeTags
::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() );
633 // FIXME This is reimplementing DifferenceEngine#getRevisionHeader
634 // and partially #showDiffPage, but worse
635 return '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
636 $this->getLinkRenderer()->makeLink(
640 $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
641 $lang->userDate( $rev->getTimestamp(), $user ),
642 $lang->userTime( $rev->getTimestamp(), $user )
648 '<div id="mw-diff-' . $prefix . 'title2">' .
649 Linker
::revUserTools( $rev ) . '<br />' .
651 '<div id="mw-diff-' . $prefix . 'title3">' .
652 $minor . Linker
::revComment( $rev ) . $rdel . '<br />' .
654 '<div id="mw-diff-' . $prefix . 'title5">' .
655 $tagSummary[0] . '<br />' .
660 * Show a form confirming whether a tokenless user really wants to see a file
663 private function showFileConfirmationForm( $key ) {
664 $out = $this->getOutput();
665 $lang = $this->getLanguage();
666 $user = $this->getUser();
667 $file = new ArchivedFile( $this->mTargetObj
, 0, $this->mFilename
);
668 $out->addWikiMsg( 'undelete-show-file-confirm',
669 $this->mTargetObj
->getText(),
670 $lang->userDate( $file->getTimestamp(), $user ),
671 $lang->userTime( $file->getTimestamp(), $user ) );
673 Xml
::openElement( 'form', [
675 'action' => $this->getPageTitle()->getLocalURL( [
676 'target' => $this->mTarget
,
678 'token' => $user->getEditToken( $key ),
682 Xml
::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
688 * Show a deleted file version requested by the visitor.
691 private function showFile( $key ) {
692 $this->getOutput()->disable();
694 # We mustn't allow the output to be CDN cached, otherwise
695 # if an admin previews a deleted image, and it's cached, then
696 # a user without appropriate permissions can toddle off and
697 # nab the image, and CDN will serve it
698 $response = $this->getRequest()->response();
699 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
700 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
701 $response->header( 'Pragma: no-cache' );
703 $repo = RepoGroup
::singleton()->getLocalRepo();
704 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
705 $repo->streamFileWithStatus( $path );
708 protected function showHistory() {
709 $this->checkReadOnly();
711 $out = $this->getOutput();
712 if ( $this->mAllowed
) {
713 $out->addModules( 'mediawiki.special.undelete' );
716 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
717 [ 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj
->getPrefixedText() ) ]
720 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
721 Hooks
::run( 'UndeleteForm::showHistory', [ &$archive, $this->mTargetObj
] );
723 $out->addHTML( '<div class="mw-undelete-history">' );
724 if ( $this->mAllowed
) {
725 $out->addWikiMsg( 'undeletehistory' );
726 $out->addWikiMsg( 'undeleterevdel' );
728 $out->addWikiMsg( 'undeletehistorynoadmin' );
730 $out->addHTML( '</div>' );
732 # List all stored revisions
733 $revisions = $archive->listRevisions();
734 $files = $archive->listFiles();
736 $haveRevisions = $revisions && $revisions->numRows() > 0;
737 $haveFiles = $files && $files->numRows() > 0;
739 # Batch existence check on user and talk pages
740 if ( $haveRevisions ) {
741 $batch = new LinkBatch();
742 foreach ( $revisions as $row ) {
743 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
744 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
747 $revisions->seek( 0 );
750 $batch = new LinkBatch();
751 foreach ( $files as $row ) {
752 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
753 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
759 if ( $this->mAllowed
) {
762 $action = $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] );
763 # Start the form here
764 $form = new OOUI\
FormLayout( [
771 # Show relevant lines from the deletion log:
772 $deleteLogPage = new LogPage( 'delete' );
773 $out->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) . "\n" );
774 LogEventsList
::showLogExtract( $out, 'delete', $this->mTargetObj
);
775 # Show relevant lines from the suppression log:
776 $suppressLogPage = new LogPage( 'suppress' );
777 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
778 $out->addHTML( Xml
::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
779 LogEventsList
::showLogExtract( $out, 'suppress', $this->mTargetObj
);
782 if ( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
784 $fields[] = new OOUI\
Layout( [
785 'content' => new OOUI\
HtmlSnippet( $this->msg( 'undeleteextrahelp' )->parseAsBlock() )
788 $fields[] = new OOUI\
FieldLayout(
789 new OOUI\
TextInputWidget( [
790 'name' => 'wpComment',
791 'inputId' => 'wpComment',
793 'value' => $this->mComment
,
795 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
796 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
797 // Unicode codepoints.
798 'maxLength' => CommentStore
::COMMENT_CHARACTER_LIMIT
,
801 'label' => $this->msg( 'undeletecomment' )->text(),
806 $fields[] = new OOUI\
FieldLayout(
808 'content' => new OOUI\
HorizontalLayout( [
810 new OOUI\
ButtonInputWidget( [
812 'inputId' => 'mw-undelete-submit',
814 'label' => $this->msg( 'undeletebtn' )->text(),
815 'flags' => [ 'primary', 'progressive' ],
818 new OOUI\
ButtonInputWidget( [
820 'inputId' => 'mw-undelete-invert',
822 'label' => $this->msg( 'undeleteinvert' )->text()
829 if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
830 $fields[] = new OOUI\
FieldLayout(
831 new OOUI\
CheckboxInputWidget( [
832 'name' => 'wpUnsuppress',
833 'inputId' => 'mw-undelete-unsuppress',
837 'label' => $this->msg( 'revdelete-unsuppress' )->text(),
843 $fieldset = new OOUI\
FieldsetLayout( [
844 'label' => $this->msg( 'undelete-fieldset-title' )->text(),
845 'id' => 'mw-undelete-table',
849 $form->appendContent(
850 new OOUI\
PanelLayout( [
854 'content' => $fieldset,
856 new OOUI\
HtmlSnippet(
857 Html
::hidden( 'target', $this->mTarget
) .
858 Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() )
864 $history .= Xml
::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n";
866 if ( $haveRevisions ) {
867 # Show the page's stored (deleted) history
869 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
870 $history .= Html
::element(
875 'class' => 'deleterevision-log-submit mw-log-deleterevision-button'
877 $this->msg( 'showhideselectedversions' )->text()
881 $history .= '<ul class="mw-undelete-revlist">';
882 $remaining = $revisions->numRows();
883 $earliestLiveTime = $this->mTargetObj
->getEarliestRevTime();
885 foreach ( $revisions as $row ) {
887 $history .= $this->formatRevisionRow( $row, $earliestLiveTime, $remaining );
892 $out->addWikiMsg( 'nohistory' );
896 $history .= Xml
::element( 'h2', null, $this->msg( 'filehist' )->text() ) . "\n";
897 $history .= '<ul class="mw-undelete-revlist">';
898 foreach ( $files as $row ) {
899 $history .= $this->formatFileRow( $row );
905 if ( $this->mAllowed
) {
906 # Slip in the hidden controls here
907 $misc = Html
::hidden( 'target', $this->mTarget
);
908 $misc .= Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
911 $form->appendContent( new OOUI\
HtmlSnippet( $history ) );
912 $out->addHTML( $form );
914 $out->addHTML( $history );
920 protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
921 $rev = Revision
::newFromArchiveRow( $row,
923 'title' => $this->mTargetObj
927 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
928 // Build checkboxen...
929 if ( $this->mAllowed
) {
930 if ( $this->mInvert
) {
931 if ( in_array( $ts, $this->mTargetTimestamp
) ) {
932 $checkBox = Xml
::check( "ts$ts" );
934 $checkBox = Xml
::check( "ts$ts", true );
937 $checkBox = Xml
::check( "ts$ts" );
943 // Build page & diff links...
944 $user = $this->getUser();
945 if ( $this->mCanView
) {
946 $titleObj = $this->getPageTitle();
948 if ( !$rev->userCan( RevisionRecord
::DELETED_TEXT
, $this->getUser() ) ) {
949 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
950 $last = $this->msg( 'diff' )->escaped();
951 } elseif ( $remaining > 0 ||
( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
952 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
953 $last = $this->getLinkRenderer()->makeKnownLink(
955 $this->msg( 'diff' )->text(),
958 'target' => $this->mTargetObj
->getPrefixedText(),
964 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
965 $last = $this->msg( 'diff' )->escaped();
968 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
969 $last = $this->msg( 'diff' )->escaped();
973 $userLink = Linker
::revUserTools( $rev );
976 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
978 // Revision text size
979 $size = $row->ar_len
;
980 if ( !is_null( $size ) ) {
981 $revTextSize = Linker
::formatRevisionSize( $size );
985 $comment = Linker
::revComment( $rev );
989 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
995 $attribs['class'] = implode( ' ', $classes );
998 $revisionRow = $this->msg( 'undelete-revision-row2' )
1011 return Xml
::tags( 'li', $attribs, $revisionRow ) . "\n";
1014 private function formatFileRow( $row ) {
1015 $file = ArchivedFile
::newFromRow( $row );
1016 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
1017 $user = $this->getUser();
1020 if ( $this->mCanView
&& $row->fa_storage_key
) {
1021 if ( $this->mAllowed
) {
1022 $checkBox = Xml
::check( 'fileid' . $row->fa_id
);
1024 $key = urlencode( $row->fa_storage_key
);
1025 $pageLink = $this->getFileLink( $file, $this->getPageTitle(), $ts, $key );
1027 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
1029 $userLink = $this->getFileUser( $file );
1030 $data = $this->msg( 'widthheight' )->numParams( $row->fa_width
, $row->fa_height
)->text();
1031 $bytes = $this->msg( 'parentheses' )
1032 ->plaintextParams( $this->msg( 'nbytes' )->numParams( $row->fa_size
)->text() )
1034 $data = htmlspecialchars( $data . ' ' . $bytes );
1035 $comment = $this->getFileComment( $file );
1037 // Add show/hide deletion links if available
1038 $canHide = $this->isAllowed( 'deleterevision' );
1039 if ( $canHide ||
( $file->getVisibility() && $this->isAllowed( 'deletedhistory' ) ) ) {
1040 if ( !$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
1041 // Revision was hidden from sysops
1042 $revdlink = Linker
::revDeleteLinkDisabled( $canHide );
1045 'type' => 'filearchive',
1046 'target' => $this->mTargetObj
->getPrefixedDBkey(),
1047 'ids' => $row->fa_id
1049 $revdlink = Linker
::revDeleteLink( $query,
1050 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1056 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1060 * Fetch revision text link if it's available to all users
1062 * @param Revision $rev
1063 * @param Title $titleObj
1064 * @param string $ts Timestamp
1067 function getPageLink( $rev, $titleObj, $ts ) {
1068 $user = $this->getUser();
1069 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1071 if ( !$rev->userCan( RevisionRecord
::DELETED_TEXT
, $user ) ) {
1072 return '<span class="history-deleted">' . $time . '</span>';
1075 $link = $this->getLinkRenderer()->makeKnownLink(
1080 'target' => $this->mTargetObj
->getPrefixedText(),
1085 if ( $rev->isDeleted( RevisionRecord
::DELETED_TEXT
) ) {
1086 $link = '<span class="history-deleted">' . $link . '</span>';
1093 * Fetch image view link if it's available to all users
1095 * @param File|ArchivedFile $file
1096 * @param Title $titleObj
1097 * @param string $ts A timestamp
1098 * @param string $key A storage key
1100 * @return string HTML fragment
1102 function getFileLink( $file, $titleObj, $ts, $key ) {
1103 $user = $this->getUser();
1104 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1106 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
1107 return '<span class="history-deleted">' . htmlspecialchars( $time ) . '</span>';
1110 $link = $this->getLinkRenderer()->makeKnownLink(
1115 'target' => $this->mTargetObj
->getPrefixedText(),
1117 'token' => $user->getEditToken( $key )
1121 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
1122 $link = '<span class="history-deleted">' . $link . '</span>';
1129 * Fetch file's user id if it's available to this user
1131 * @param File|ArchivedFile $file
1132 * @return string HTML fragment
1134 function getFileUser( $file ) {
1135 if ( !$file->userCan( File
::DELETED_USER
, $this->getUser() ) ) {
1136 return '<span class="history-deleted">' .
1137 $this->msg( 'rev-deleted-user' )->escaped() .
1141 $link = Linker
::userLink( $file->getRawUser(), $file->getRawUserText() ) .
1142 Linker
::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1144 if ( $file->isDeleted( File
::DELETED_USER
) ) {
1145 $link = '<span class="history-deleted">' . $link . '</span>';
1152 * Fetch file upload comment if it's available to this user
1154 * @param File|ArchivedFile $file
1155 * @return string HTML fragment
1157 function getFileComment( $file ) {
1158 if ( !$file->userCan( File
::DELETED_COMMENT
, $this->getUser() ) ) {
1159 return '<span class="history-deleted"><span class="comment">' .
1160 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></span>';
1163 $link = Linker
::commentBlock( $file->getRawDescription() );
1165 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
1166 $link = '<span class="history-deleted">' . $link . '</span>';
1172 function undelete() {
1173 if ( $this->getConfig()->get( 'UploadMaintenance' )
1174 && $this->mTargetObj
->getNamespace() == NS_FILE
1176 throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
1179 $this->checkReadOnly();
1181 $out = $this->getOutput();
1182 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1183 Hooks
::run( 'UndeleteForm::undelete', [ &$archive, $this->mTargetObj
] );
1184 $ok = $archive->undelete(
1185 $this->mTargetTimestamp
,
1187 $this->mFileVersions
,
1192 if ( is_array( $ok ) ) {
1193 if ( $ok[1] ) { // Undeleted file count
1194 Hooks
::run( 'FileUndeleteComplete', [
1195 $this->mTargetObj
, $this->mFileVersions
,
1196 $this->getUser(), $this->mComment
] );
1199 $link = $this->getLinkRenderer()->makeKnownLink( $this->mTargetObj
);
1200 $out->addWikiMsg( 'undeletedpage', Message
::rawParam( $link ) );
1202 $out->setPageTitle( $this->msg( 'undelete-error' ) );
1205 // Show revision undeletion warnings and errors
1206 $status = $archive->getRevisionStatus();
1207 if ( $status && !$status->isGood() ) {
1208 $out->wrapWikiTextAsInterface(
1210 '<div id="mw-error-cannotundelete">' .
1211 $status->getWikiText(
1218 // Show file undeletion warnings and errors
1219 $status = $archive->getFileStatus();
1220 if ( $status && !$status->isGood() ) {
1221 $out->wrapWikiTextAsInterface(
1223 $status->getWikiText(
1224 'undelete-error-short',
1225 'undelete-error-long'
1232 * Return an array of subpages beginning with $search that this special page will accept.
1234 * @param string $search Prefix to search for
1235 * @param int $limit Maximum number of results to return (usually 10)
1236 * @param int $offset Number of results to skip (usually 0)
1237 * @return string[] Matching subpages
1239 public function prefixSearchSubpages( $search, $limit, $offset ) {
1240 return $this->prefixSearchString( $search, $limit, $offset );
1243 protected function getGroupName() {