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 // TODO: MCR: make this work for multiple slots
497 // source view for textual content
498 $sourceView = Xml
::element( 'textarea', [
499 'readonly' => 'readonly',
502 ], $content->getText() . "\n" );
504 $buttonFields[] = new OOUI\
ButtonInputWidget( [
507 'label' => $this->msg( 'showpreview' )->text()
513 $buttonFields[] = new OOUI\
ButtonInputWidget( [
516 'label' => $this->msg( 'showdiff' )->text()
521 Xml
::openElement( 'div', [
522 'style' => 'clear: both' ] ) .
523 Xml
::openElement( 'form', [
525 'action' => $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] ) ] ) .
526 Xml
::element( 'input', [
529 'value' => $this->mTargetObj
->getPrefixedDBkey() ] ) .
530 Xml
::element( 'input', [
532 'name' => 'timestamp',
533 'value' => $timestamp ] ) .
534 Xml
::element( 'input', [
536 'name' => 'wpEditToken',
537 'value' => $user->getEditToken() ] ) .
538 new OOUI\
FieldLayout(
540 'content' => new OOUI\
HorizontalLayout( [
541 'items' => $buttonFields
545 Xml
::closeElement( 'form' ) .
546 Xml
::closeElement( 'div' )
551 * Build a diff display between this and the previous either deleted
552 * or non-deleted edit.
554 * @param Revision $previousRev
555 * @param Revision $currentRev
557 function showDiff( $previousRev, $currentRev ) {
558 $diffContext = clone $this->getContext();
559 $diffContext->setTitle( $currentRev->getTitle() );
560 $diffContext->setWikiPage( WikiPage
::factory( $currentRev->getTitle() ) );
562 $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
563 $diffEngine->setRevisions( $previousRev->getRevisionRecord(), $currentRev->getRevisionRecord() );
564 $diffEngine->showDiffStyle();
565 $formattedDiff = $diffEngine->getDiff(
566 $this->diffHeader( $previousRev, 'o' ),
567 $this->diffHeader( $currentRev, 'n' )
570 $this->getOutput()->addHTML( "<div>$formattedDiff</div>\n" );
574 * @param Revision $rev
575 * @param string $prefix
578 private function diffHeader( $rev, $prefix ) {
579 $isDeleted = !( $rev->getId() && $rev->getTitle() );
581 /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
582 $targetPage = $this->getPageTitle();
584 'target' => $this->mTargetObj
->getPrefixedText(),
585 'timestamp' => wfTimestamp( TS_MW
, $rev->getTimestamp() )
588 /// @todo FIXME: getId() may return non-zero for deleted revs...
589 $targetPage = $rev->getTitle();
590 $targetQuery = [ 'oldid' => $rev->getId() ];
593 // Add show/hide deletion links if available
594 $user = $this->getUser();
595 $lang = $this->getLanguage();
596 $rdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
602 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
604 $tagIds = wfGetDB( DB_REPLICA
)->selectFieldValues(
607 [ 'ct_rev_id' => $rev->getId() ],
611 $changeTagDefStore = MediaWikiServices
::getInstance()->getChangeTagDefStore();
612 foreach ( $tagIds as $tagId ) {
614 $tags[] = $changeTagDefStore->getName( (int)$tagId );
615 } catch ( NameTableAccessException
$exception ) {
619 $tags = implode( ',', $tags );
620 $tagSummary = ChangeTags
::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() );
622 // FIXME This is reimplementing DifferenceEngine#getRevisionHeader
623 // and partially #showDiffPage, but worse
624 return '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
625 $this->getLinkRenderer()->makeLink(
629 $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
630 $lang->userDate( $rev->getTimestamp(), $user ),
631 $lang->userTime( $rev->getTimestamp(), $user )
637 '<div id="mw-diff-' . $prefix . 'title2">' .
638 Linker
::revUserTools( $rev ) . '<br />' .
640 '<div id="mw-diff-' . $prefix . 'title3">' .
641 $minor . Linker
::revComment( $rev ) . $rdel . '<br />' .
643 '<div id="mw-diff-' . $prefix . 'title5">' .
644 $tagSummary[0] . '<br />' .
649 * Show a form confirming whether a tokenless user really wants to see a file
652 private function showFileConfirmationForm( $key ) {
653 $out = $this->getOutput();
654 $lang = $this->getLanguage();
655 $user = $this->getUser();
656 $file = new ArchivedFile( $this->mTargetObj
, 0, $this->mFilename
);
657 $out->addWikiMsg( 'undelete-show-file-confirm',
658 $this->mTargetObj
->getText(),
659 $lang->userDate( $file->getTimestamp(), $user ),
660 $lang->userTime( $file->getTimestamp(), $user ) );
662 Xml
::openElement( 'form', [
664 'action' => $this->getPageTitle()->getLocalURL( [
665 'target' => $this->mTarget
,
667 'token' => $user->getEditToken( $key ),
671 Xml
::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
677 * Show a deleted file version requested by the visitor.
680 private function showFile( $key ) {
681 $this->getOutput()->disable();
683 # We mustn't allow the output to be CDN cached, otherwise
684 # if an admin previews a deleted image, and it's cached, then
685 # a user without appropriate permissions can toddle off and
686 # nab the image, and CDN will serve it
687 $response = $this->getRequest()->response();
688 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
689 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
690 $response->header( 'Pragma: no-cache' );
692 $repo = RepoGroup
::singleton()->getLocalRepo();
693 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
694 $repo->streamFileWithStatus( $path );
697 protected function showHistory() {
698 $this->checkReadOnly();
700 $out = $this->getOutput();
701 if ( $this->mAllowed
) {
702 $out->addModules( 'mediawiki.special.undelete' );
705 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
706 [ 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj
->getPrefixedText() ) ]
709 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
710 Hooks
::run( 'UndeleteForm::showHistory', [ &$archive, $this->mTargetObj
] );
712 $out->addHTML( '<div class="mw-undelete-history">' );
713 if ( $this->mAllowed
) {
714 $out->addWikiMsg( 'undeletehistory' );
715 $out->addWikiMsg( 'undeleterevdel' );
717 $out->addWikiMsg( 'undeletehistorynoadmin' );
719 $out->addHTML( '</div>' );
721 # List all stored revisions
722 $revisions = $archive->listRevisions();
723 $files = $archive->listFiles();
725 $haveRevisions = $revisions && $revisions->numRows() > 0;
726 $haveFiles = $files && $files->numRows() > 0;
728 # Batch existence check on user and talk pages
729 if ( $haveRevisions ) {
730 $batch = new LinkBatch();
731 foreach ( $revisions as $row ) {
732 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
733 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
736 $revisions->seek( 0 );
739 $batch = new LinkBatch();
740 foreach ( $files as $row ) {
741 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
742 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
748 if ( $this->mAllowed
) {
751 $action = $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] );
752 # Start the form here
753 $form = new OOUI\
FormLayout( [
760 # Show relevant lines from the deletion log:
761 $deleteLogPage = new LogPage( 'delete' );
762 $out->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) . "\n" );
763 LogEventsList
::showLogExtract( $out, 'delete', $this->mTargetObj
);
764 # Show relevant lines from the suppression log:
765 $suppressLogPage = new LogPage( 'suppress' );
766 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
767 $out->addHTML( Xml
::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
768 LogEventsList
::showLogExtract( $out, 'suppress', $this->mTargetObj
);
771 if ( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
773 $fields[] = new OOUI\
Layout( [
774 'content' => new OOUI\
HtmlSnippet( $this->msg( 'undeleteextrahelp' )->parseAsBlock() )
777 $fields[] = new OOUI\
FieldLayout(
778 new OOUI\
TextInputWidget( [
779 'name' => 'wpComment',
780 'inputId' => 'wpComment',
782 'value' => $this->mComment
,
784 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
785 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
786 // Unicode codepoints.
787 'maxLength' => CommentStore
::COMMENT_CHARACTER_LIMIT
,
790 'label' => $this->msg( 'undeletecomment' )->text(),
795 $fields[] = new OOUI\
FieldLayout(
797 'content' => new OOUI\
HorizontalLayout( [
799 new OOUI\
ButtonInputWidget( [
801 'inputId' => 'mw-undelete-submit',
803 'label' => $this->msg( 'undeletebtn' )->text(),
804 'flags' => [ 'primary', 'progressive' ],
807 new OOUI\
ButtonInputWidget( [
809 'inputId' => 'mw-undelete-invert',
811 'label' => $this->msg( 'undeleteinvert' )->text()
818 if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
819 $fields[] = new OOUI\
FieldLayout(
820 new OOUI\
CheckboxInputWidget( [
821 'name' => 'wpUnsuppress',
822 'inputId' => 'mw-undelete-unsuppress',
826 'label' => $this->msg( 'revdelete-unsuppress' )->text(),
832 $fieldset = new OOUI\
FieldsetLayout( [
833 'label' => $this->msg( 'undelete-fieldset-title' )->text(),
834 'id' => 'mw-undelete-table',
838 $form->appendContent(
839 new OOUI\
PanelLayout( [
843 'content' => $fieldset,
845 new OOUI\
HtmlSnippet(
846 Html
::hidden( 'target', $this->mTarget
) .
847 Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() )
853 $history .= Xml
::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n";
855 if ( $haveRevisions ) {
856 # Show the page's stored (deleted) history
858 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
859 $history .= Html
::element(
864 'class' => 'deleterevision-log-submit mw-log-deleterevision-button'
866 $this->msg( 'showhideselectedversions' )->text()
870 $history .= '<ul class="mw-undelete-revlist">';
871 $remaining = $revisions->numRows();
872 $earliestLiveTime = $this->mTargetObj
->getEarliestRevTime();
874 foreach ( $revisions as $row ) {
876 $history .= $this->formatRevisionRow( $row, $earliestLiveTime, $remaining );
881 $out->addWikiMsg( 'nohistory' );
885 $history .= Xml
::element( 'h2', null, $this->msg( 'filehist' )->text() ) . "\n";
886 $history .= '<ul class="mw-undelete-revlist">';
887 foreach ( $files as $row ) {
888 $history .= $this->formatFileRow( $row );
894 if ( $this->mAllowed
) {
895 # Slip in the hidden controls here
896 $misc = Html
::hidden( 'target', $this->mTarget
);
897 $misc .= Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
900 $form->appendContent( new OOUI\
HtmlSnippet( $history ) );
901 $out->addHTML( $form );
903 $out->addHTML( $history );
909 protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
910 $rev = Revision
::newFromArchiveRow( $row,
912 'title' => $this->mTargetObj
916 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
917 // Build checkboxen...
918 if ( $this->mAllowed
) {
919 if ( $this->mInvert
) {
920 if ( in_array( $ts, $this->mTargetTimestamp
) ) {
921 $checkBox = Xml
::check( "ts$ts" );
923 $checkBox = Xml
::check( "ts$ts", true );
926 $checkBox = Xml
::check( "ts$ts" );
932 // Build page & diff links...
933 $user = $this->getUser();
934 if ( $this->mCanView
) {
935 $titleObj = $this->getPageTitle();
937 if ( !$rev->userCan( RevisionRecord
::DELETED_TEXT
, $this->getUser() ) ) {
938 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
939 $last = $this->msg( 'diff' )->escaped();
940 } elseif ( $remaining > 0 ||
( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
941 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
942 $last = $this->getLinkRenderer()->makeKnownLink(
944 $this->msg( 'diff' )->text(),
947 'target' => $this->mTargetObj
->getPrefixedText(),
953 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
954 $last = $this->msg( 'diff' )->escaped();
957 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
958 $last = $this->msg( 'diff' )->escaped();
962 $userLink = Linker
::revUserTools( $rev );
965 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
967 // Revision text size
968 $size = $row->ar_len
;
969 if ( !is_null( $size ) ) {
970 $revTextSize = Linker
::formatRevisionSize( $size );
974 $comment = Linker
::revComment( $rev );
978 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
984 $attribs['class'] = implode( ' ', $classes );
987 $revisionRow = $this->msg( 'undelete-revision-row2' )
1000 return Xml
::tags( 'li', $attribs, $revisionRow ) . "\n";
1003 private function formatFileRow( $row ) {
1004 $file = ArchivedFile
::newFromRow( $row );
1005 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
1006 $user = $this->getUser();
1009 if ( $this->mCanView
&& $row->fa_storage_key
) {
1010 if ( $this->mAllowed
) {
1011 $checkBox = Xml
::check( 'fileid' . $row->fa_id
);
1013 $key = urlencode( $row->fa_storage_key
);
1014 $pageLink = $this->getFileLink( $file, $this->getPageTitle(), $ts, $key );
1016 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
1018 $userLink = $this->getFileUser( $file );
1019 $data = $this->msg( 'widthheight' )->numParams( $row->fa_width
, $row->fa_height
)->text();
1020 $bytes = $this->msg( 'parentheses' )
1021 ->plaintextParams( $this->msg( 'nbytes' )->numParams( $row->fa_size
)->text() )
1023 $data = htmlspecialchars( $data . ' ' . $bytes );
1024 $comment = $this->getFileComment( $file );
1026 // Add show/hide deletion links if available
1027 $canHide = $this->isAllowed( 'deleterevision' );
1028 if ( $canHide ||
( $file->getVisibility() && $this->isAllowed( 'deletedhistory' ) ) ) {
1029 if ( !$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
1030 // Revision was hidden from sysops
1031 $revdlink = Linker
::revDeleteLinkDisabled( $canHide );
1034 'type' => 'filearchive',
1035 'target' => $this->mTargetObj
->getPrefixedDBkey(),
1036 'ids' => $row->fa_id
1038 $revdlink = Linker
::revDeleteLink( $query,
1039 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1045 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1049 * Fetch revision text link if it's available to all users
1051 * @param Revision $rev
1052 * @param Title $titleObj
1053 * @param string $ts Timestamp
1056 function getPageLink( $rev, $titleObj, $ts ) {
1057 $user = $this->getUser();
1058 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1060 if ( !$rev->userCan( RevisionRecord
::DELETED_TEXT
, $user ) ) {
1061 return '<span class="history-deleted">' . $time . '</span>';
1064 $link = $this->getLinkRenderer()->makeKnownLink(
1069 'target' => $this->mTargetObj
->getPrefixedText(),
1074 if ( $rev->isDeleted( RevisionRecord
::DELETED_TEXT
) ) {
1075 $link = '<span class="history-deleted">' . $link . '</span>';
1082 * Fetch image view link if it's available to all users
1084 * @param File|ArchivedFile $file
1085 * @param Title $titleObj
1086 * @param string $ts A timestamp
1087 * @param string $key A storage key
1089 * @return string HTML fragment
1091 function getFileLink( $file, $titleObj, $ts, $key ) {
1092 $user = $this->getUser();
1093 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1095 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
1096 return '<span class="history-deleted">' . htmlspecialchars( $time ) . '</span>';
1099 $link = $this->getLinkRenderer()->makeKnownLink(
1104 'target' => $this->mTargetObj
->getPrefixedText(),
1106 'token' => $user->getEditToken( $key )
1110 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
1111 $link = '<span class="history-deleted">' . $link . '</span>';
1118 * Fetch file's user id if it's available to this user
1120 * @param File|ArchivedFile $file
1121 * @return string HTML fragment
1123 function getFileUser( $file ) {
1124 if ( !$file->userCan( File
::DELETED_USER
, $this->getUser() ) ) {
1125 return '<span class="history-deleted">' .
1126 $this->msg( 'rev-deleted-user' )->escaped() .
1130 $link = Linker
::userLink( $file->getRawUser(), $file->getRawUserText() ) .
1131 Linker
::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1133 if ( $file->isDeleted( File
::DELETED_USER
) ) {
1134 $link = '<span class="history-deleted">' . $link . '</span>';
1141 * Fetch file upload comment if it's available to this user
1143 * @param File|ArchivedFile $file
1144 * @return string HTML fragment
1146 function getFileComment( $file ) {
1147 if ( !$file->userCan( File
::DELETED_COMMENT
, $this->getUser() ) ) {
1148 return '<span class="history-deleted"><span class="comment">' .
1149 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></span>';
1152 $link = Linker
::commentBlock( $file->getRawDescription() );
1154 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
1155 $link = '<span class="history-deleted">' . $link . '</span>';
1161 function undelete() {
1162 if ( $this->getConfig()->get( 'UploadMaintenance' )
1163 && $this->mTargetObj
->getNamespace() == NS_FILE
1165 throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
1168 $this->checkReadOnly();
1170 $out = $this->getOutput();
1171 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1172 Hooks
::run( 'UndeleteForm::undelete', [ &$archive, $this->mTargetObj
] );
1173 $ok = $archive->undelete(
1174 $this->mTargetTimestamp
,
1176 $this->mFileVersions
,
1181 if ( is_array( $ok ) ) {
1182 if ( $ok[1] ) { // Undeleted file count
1183 Hooks
::run( 'FileUndeleteComplete', [
1184 $this->mTargetObj
, $this->mFileVersions
,
1185 $this->getUser(), $this->mComment
] );
1188 $link = $this->getLinkRenderer()->makeKnownLink( $this->mTargetObj
);
1189 $out->addWikiMsg( 'undeletedpage', Message
::rawParam( $link ) );
1191 $out->setPageTitle( $this->msg( 'undelete-error' ) );
1194 // Show revision undeletion warnings and errors
1195 $status = $archive->getRevisionStatus();
1196 if ( $status && !$status->isGood() ) {
1197 $out->wrapWikiTextAsInterface(
1199 '<div id="mw-error-cannotundelete">' .
1200 $status->getWikiText(
1207 // Show file undeletion warnings and errors
1208 $status = $archive->getFileStatus();
1209 if ( $status && !$status->isGood() ) {
1210 $out->wrapWikiTextAsInterface(
1212 $status->getWikiText(
1213 'undelete-error-short',
1214 'undelete-error-long'
1221 * Return an array of subpages beginning with $search that this special page will accept.
1223 * @param string $search Prefix to search for
1224 * @param int $limit Maximum number of results to return (usually 10)
1225 * @param int $offset Number of results to skip (usually 0)
1226 * @return string[] Matching subpages
1228 public function prefixSearchSubpages( $search, $limit, $offset ) {
1229 return $this->prefixSearchString( $search, $limit, $offset );
1232 protected function getGroupName() {