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\Storage\RevisionRecord
;
26 use Wikimedia\Rdbms\IResultWrapper
;
29 * Special page allowing users with the appropriate permissions to view
30 * and restore deleted content.
32 * @ingroup SpecialPage
34 class SpecialUndelete
extends SpecialPage
{
42 private $mTargetTimestamp;
51 * @var string Search prefix
53 private $mSearchPrefix;
55 function __construct() {
56 parent
::__construct( 'Undelete', 'deletedhistory' );
59 public function doesWrites() {
63 function loadRequest( $par ) {
64 $request = $this->getRequest();
65 $user = $this->getUser();
67 $this->mAction
= $request->getVal( 'action' );
68 if ( $par !== null && $par !== '' ) {
69 $this->mTarget
= $par;
71 $this->mTarget
= $request->getVal( 'target' );
74 $this->mTargetObj
= null;
76 if ( $this->mTarget
!== null && $this->mTarget
!== '' ) {
77 $this->mTargetObj
= Title
::newFromText( $this->mTarget
);
80 $this->mSearchPrefix
= $request->getText( 'prefix' );
81 $time = $request->getVal( 'timestamp' );
82 $this->mTimestamp
= $time ?
wfTimestamp( TS_MW
, $time ) : '';
83 $this->mFilename
= $request->getVal( 'file' );
85 $posted = $request->wasPosted() &&
86 $user->matchEditToken( $request->getVal( 'wpEditToken' ) );
87 $this->mRestore
= $request->getCheck( 'restore' ) && $posted;
88 $this->mRevdel
= $request->getCheck( 'revdel' ) && $posted;
89 $this->mInvert
= $request->getCheck( 'invert' ) && $posted;
90 $this->mPreview
= $request->getCheck( 'preview' ) && $posted;
91 $this->mDiff
= $request->getCheck( 'diff' );
92 $this->mDiffOnly
= $request->getBool( 'diffonly', $this->getUser()->getOption( 'diffonly' ) );
93 $this->mComment
= $request->getText( 'wpComment' );
94 $this->mUnsuppress
= $request->getVal( 'wpUnsuppress' ) && $user->isAllowed( 'suppressrevision' );
95 $this->mToken
= $request->getVal( 'token' );
97 if ( $this->isAllowed( 'undelete' ) && !$user->isBlocked() ) {
98 $this->mAllowed
= true; // user can restore
99 $this->mCanView
= true; // user can view content
100 } elseif ( $this->isAllowed( 'deletedtext' ) ) {
101 $this->mAllowed
= false; // user cannot restore
102 $this->mCanView
= true; // user can view content
103 $this->mRestore
= false;
104 } else { // user can only view the list of revisions
105 $this->mAllowed
= false;
106 $this->mCanView
= false;
107 $this->mTimestamp
= '';
108 $this->mRestore
= false;
111 if ( $this->mRestore ||
$this->mInvert
) {
113 $this->mFileVersions
= [];
114 foreach ( $request->getValues() as $key => $val ) {
116 if ( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
117 array_push( $timestamps, $matches[1] );
120 if ( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
121 $this->mFileVersions
[] = intval( $matches[1] );
124 rsort( $timestamps );
125 $this->mTargetTimestamp
= $timestamps;
130 * Checks whether a user is allowed the permission for the
131 * specific title if one is set.
133 * @param string $permission
134 * @param User|null $user
137 protected function isAllowed( $permission, User
$user = null ) {
138 $user = $user ?
: $this->getUser();
139 if ( $this->mTargetObj
!== null ) {
140 return $this->mTargetObj
->userCan( $permission, $user );
142 return $user->isAllowed( $permission );
146 function userCanExecute( User
$user ) {
147 return $this->isAllowed( $this->mRestriction
, $user );
150 function execute( $par ) {
151 $this->useTransactionalTimeLimit();
153 $user = $this->getUser();
156 $this->outputHeader();
158 $this->loadRequest( $par );
159 $this->checkPermissions(); // Needs to be after mTargetObj is set
161 $out = $this->getOutput();
163 if ( is_null( $this->mTargetObj
) ) {
164 $out->addWikiMsg( 'undelete-header' );
166 # Not all users can just browse every deleted page from the list
167 if ( $user->isAllowed( 'browsearchive' ) ) {
168 $this->showSearchForm();
174 $this->addHelpLink( 'Help:Undelete' );
175 if ( $this->mAllowed
) {
176 $out->setPageTitle( $this->msg( 'undeletepage' ) );
178 $out->setPageTitle( $this->msg( 'viewdeletedpage' ) );
181 $this->getSkin()->setRelevantTitle( $this->mTargetObj
);
183 if ( $this->mTimestamp
!== '' ) {
184 $this->showRevision( $this->mTimestamp
);
185 } elseif ( $this->mFilename
!== null && $this->mTargetObj
->inNamespace( NS_FILE
) ) {
186 $file = new ArchivedFile( $this->mTargetObj
, '', $this->mFilename
);
187 // Check if user is allowed to see this file
188 if ( !$file->exists() ) {
189 $out->addWikiMsg( 'filedelete-nofile', $this->mFilename
);
190 } elseif ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
191 if ( $file->isDeleted( File
::DELETED_RESTRICTED
) ) {
192 throw new PermissionsError( 'suppressrevision' );
194 throw new PermissionsError( 'deletedtext' );
196 } elseif ( !$user->matchEditToken( $this->mToken
, $this->mFilename
) ) {
197 $this->showFileConfirmationForm( $this->mFilename
);
199 $this->showFile( $this->mFilename
);
201 } elseif ( $this->mAction
=== "submit" ) {
202 if ( $this->mRestore
) {
204 } elseif ( $this->mRevdel
) {
205 $this->redirectToRevDel();
209 $this->showHistory();
214 * Convert submitted form data to format expected by RevisionDelete and
215 * redirect the request
217 private function redirectToRevDel() {
218 $archive = new PageArchive( $this->mTargetObj
);
222 foreach ( $this->getRequest()->getValues() as $key => $val ) {
224 if ( preg_match( "/^ts(\d{14})$/", $key, $matches ) ) {
225 $revisions[ $archive->getRevision( $matches[1] )->getId() ] = 1;
229 "type" => "revision",
231 "target" => $this->mTargetObj
->getPrefixedText()
233 $url = SpecialPage
::getTitleFor( 'Revisiondelete' )->getFullURL( $query );
234 $this->getOutput()->redirect( $url );
237 function showSearchForm() {
238 $out = $this->getOutput();
239 $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
240 $fuzzySearch = $this->getRequest()->getVal( 'fuzzy', true );
244 $fields[] = new OOUI\
ActionFieldLayout(
245 new OOUI\
TextInputWidget( [
247 'inputId' => 'prefix',
249 'value' => $this->mSearchPrefix
,
252 new OOUI\
ButtonInputWidget( [
253 'label' => $this->msg( 'undelete-search-submit' )->text(),
254 'flags' => [ 'primary', 'progressive' ],
255 'inputId' => 'searchUndelete',
259 'label' => new OOUI\
HtmlSnippet(
261 $fuzzySearch ?
'undelete-search-full' : 'undelete-search-prefix'
268 $fieldset = new OOUI\
FieldsetLayout( [
269 'label' => $this->msg( 'undelete-search-box' )->text(),
273 $form = new OOUI\
FormLayout( [
275 'action' => wfScript(),
278 $form->appendContent(
280 new OOUI\
HtmlSnippet(
281 Html
::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
282 Html
::hidden( 'fuzzy', $fuzzySearch )
287 new OOUI\
PanelLayout( [
295 # List undeletable articles
296 if ( $this->mSearchPrefix
) {
297 // For now, we enable search engine match only when specifically asked to
298 // by using fuzzy=1 parameter.
299 if ( $fuzzySearch ) {
300 $result = PageArchive
::listPagesBySearch( $this->mSearchPrefix
);
302 $result = PageArchive
::listPagesByPrefix( $this->mSearchPrefix
);
304 $this->showList( $result );
309 * Generic list of deleted pages
311 * @param IResultWrapper $result
314 private function showList( $result ) {
315 $out = $this->getOutput();
317 if ( $result->numRows() == 0 ) {
318 $out->addWikiMsg( 'undelete-no-results' );
323 $out->addWikiMsg( 'undeletepagetext', $this->getLanguage()->formatNum( $result->numRows() ) );
325 $linkRenderer = $this->getLinkRenderer();
326 $undelete = $this->getPageTitle();
327 $out->addHTML( "<ul id='undeleteResultsList'>\n" );
328 foreach ( $result as $row ) {
329 $title = Title
::makeTitleSafe( $row->ar_namespace
, $row->ar_title
);
330 if ( $title !== null ) {
331 $item = $linkRenderer->makeKnownLink(
333 $title->getPrefixedText(),
335 [ 'target' => $title->getPrefixedText() ]
338 // The title is no longer valid, show as text
339 $item = Html
::element(
341 [ 'class' => 'mw-invalidtitle' ],
342 Linker
::getInvalidTitleDescription(
349 $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count
)->parse();
350 $out->addHTML( "<li class='undeleteResult'>{$item} ({$revs})</li>\n" );
353 $out->addHTML( "</ul>\n" );
358 private function showRevision( $timestamp ) {
359 if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
363 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
364 if ( !Hooks
::run( 'UndeleteForm::showRevision', [ &$archive, $this->mTargetObj
] ) ) {
367 $rev = $archive->getRevision( $timestamp );
369 $out = $this->getOutput();
370 $user = $this->getUser();
373 $out->addWikiMsg( 'undeleterevision-missing' );
378 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
379 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
381 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
382 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
383 'rev-suppressed-text-permission' : 'rev-deleted-text-permission'
390 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
391 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
392 'rev-suppressed-text-view' : 'rev-deleted-text-view'
394 $out->addHTML( '<br />' );
395 // and we are allowed to see...
398 if ( $this->mDiff
) {
399 $previousRev = $archive->getPreviousRevision( $timestamp );
400 if ( $previousRev ) {
401 $this->showDiff( $previousRev, $rev );
402 if ( $this->mDiffOnly
) {
406 $out->addHTML( '<hr />' );
408 $out->addWikiMsg( 'undelete-nodiff' );
412 $link = $this->getLinkRenderer()->makeKnownLink(
413 $this->getPageTitle( $this->mTargetObj
->getPrefixedDBkey() ),
414 $this->mTargetObj
->getPrefixedText()
417 $lang = $this->getLanguage();
419 // date and time are separate parameters to facilitate localisation.
420 // $time is kept for backward compat reasons.
421 $time = $lang->userTimeAndDate( $timestamp, $user );
422 $d = $lang->userDate( $timestamp, $user );
423 $t = $lang->userTime( $timestamp, $user );
424 $userLink = Linker
::revUserTools( $rev );
426 $content = $rev->getContent( RevisionRecord
::FOR_THIS_USER
, $user );
428 // TODO: MCR: this will have to become something like $hasTextSlots and $hasNonTextSlots
429 $isText = ( $content instanceof TextContent
);
431 if ( $this->mPreview ||
$isText ) {
432 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
434 $openDiv = '<div id="mw-undelete-revision">';
436 $out->addHTML( $openDiv );
438 // Revision delete links
439 if ( !$this->mDiff
) {
440 $revdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
442 $out->addHTML( "$revdel " );
446 $out->addHTML( $this->msg( 'undelete-revision' )->rawParams( $link )->params(
447 $time )->rawParams( $userLink )->params( $d, $t )->parse() . '</div>' );
449 if ( !Hooks
::run( 'UndeleteShowRevision', [ $this->mTargetObj
, $rev ] ) ) {
453 if ( $this->mPreview ||
!$isText ) {
454 // NOTE: non-text content has no source view, so always use rendered preview
456 $popts = $out->parserOptions();
457 $renderer = MediaWikiServices
::getInstance()->getRevisionRenderer();
459 $rendered = $renderer->getRenderedRevision(
460 $rev->getRevisionRecord(),
463 [ 'audience' => RevisionRecord
::FOR_THIS_USER
]
466 // Fail hard if the audience check fails, since we already checked
467 // at the beginning of this method.
468 $pout = $rendered->getRevisionParserOutput();
470 $out->addParserOutput( $pout, [
471 'enableSectionEditLinks' => false,
479 // TODO: MCR: make this work for multiple slots
480 // source view for textual content
481 $sourceView = Xml
::element( 'textarea', [
482 'readonly' => 'readonly',
485 ], $content->getNativeData() . "\n" );
487 $buttonFields[] = new OOUI\
ButtonInputWidget( [
490 'label' => $this->msg( 'showpreview' )->text()
497 $buttonFields[] = new OOUI\
ButtonInputWidget( [
500 'label' => $this->msg( 'showdiff' )->text()
505 Xml
::openElement( 'div', [
506 'style' => 'clear: both' ] ) .
507 Xml
::openElement( 'form', [
509 'action' => $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] ) ] ) .
510 Xml
::element( 'input', [
513 'value' => $this->mTargetObj
->getPrefixedDBkey() ] ) .
514 Xml
::element( 'input', [
516 'name' => 'timestamp',
517 'value' => $timestamp ] ) .
518 Xml
::element( 'input', [
520 'name' => 'wpEditToken',
521 'value' => $user->getEditToken() ] ) .
522 new OOUI\
FieldLayout(
524 'content' => new OOUI\
HorizontalLayout( [
525 'items' => $buttonFields
529 Xml
::closeElement( 'form' ) .
530 Xml
::closeElement( 'div' )
535 * Build a diff display between this and the previous either deleted
536 * or non-deleted edit.
538 * @param Revision $previousRev
539 * @param Revision $currentRev
540 * @return string HTML
542 function showDiff( $previousRev, $currentRev ) {
543 $diffContext = clone $this->getContext();
544 $diffContext->setTitle( $currentRev->getTitle() );
545 $diffContext->setWikiPage( WikiPage
::factory( $currentRev->getTitle() ) );
547 $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
548 $diffEngine->showDiffStyle();
550 $formattedDiff = $diffEngine->generateContentDiffBody(
551 $previousRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() ),
552 $currentRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() )
555 $formattedDiff = $diffEngine->addHeader(
557 $this->diffHeader( $previousRev, 'o' ),
558 $this->diffHeader( $currentRev, 'n' )
561 $this->getOutput()->addHTML( "<div>$formattedDiff</div>\n" );
565 * @param Revision $rev
566 * @param string $prefix
569 private function diffHeader( $rev, $prefix ) {
570 $isDeleted = !( $rev->getId() && $rev->getTitle() );
572 /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
573 $targetPage = $this->getPageTitle();
575 'target' => $this->mTargetObj
->getPrefixedText(),
576 'timestamp' => wfTimestamp( TS_MW
, $rev->getTimestamp() )
579 /// @todo FIXME: getId() may return non-zero for deleted revs...
580 $targetPage = $rev->getTitle();
581 $targetQuery = [ 'oldid' => $rev->getId() ];
584 // Add show/hide deletion links if available
585 $user = $this->getUser();
586 $lang = $this->getLanguage();
587 $rdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
593 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
595 $tags = wfGetDB( DB_REPLICA
)->selectField(
598 [ 'ts_rev_id' => $rev->getId() ],
601 $tagSummary = ChangeTags
::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() );
603 // FIXME This is reimplementing DifferenceEngine#getRevisionHeader
604 // and partially #showDiffPage, but worse
605 return '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
606 $this->getLinkRenderer()->makeLink(
610 $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
611 $lang->userDate( $rev->getTimestamp(), $user ),
612 $lang->userTime( $rev->getTimestamp(), $user )
618 '<div id="mw-diff-' . $prefix . 'title2">' .
619 Linker
::revUserTools( $rev ) . '<br />' .
621 '<div id="mw-diff-' . $prefix . 'title3">' .
622 $minor . Linker
::revComment( $rev ) . $rdel . '<br />' .
624 '<div id="mw-diff-' . $prefix . 'title5">' .
625 $tagSummary[0] . '<br />' .
630 * Show a form confirming whether a tokenless user really wants to see a file
633 private function showFileConfirmationForm( $key ) {
634 $out = $this->getOutput();
635 $lang = $this->getLanguage();
636 $user = $this->getUser();
637 $file = new ArchivedFile( $this->mTargetObj
, '', $this->mFilename
);
638 $out->addWikiMsg( 'undelete-show-file-confirm',
639 $this->mTargetObj
->getText(),
640 $lang->userDate( $file->getTimestamp(), $user ),
641 $lang->userTime( $file->getTimestamp(), $user ) );
643 Xml
::openElement( 'form', [
645 'action' => $this->getPageTitle()->getLocalURL( [
646 'target' => $this->mTarget
,
648 'token' => $user->getEditToken( $key ),
652 Xml
::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
658 * Show a deleted file version requested by the visitor.
661 private function showFile( $key ) {
662 $this->getOutput()->disable();
664 # We mustn't allow the output to be CDN cached, otherwise
665 # if an admin previews a deleted image, and it's cached, then
666 # a user without appropriate permissions can toddle off and
667 # nab the image, and CDN will serve it
668 $response = $this->getRequest()->response();
669 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
670 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
671 $response->header( 'Pragma: no-cache' );
673 $repo = RepoGroup
::singleton()->getLocalRepo();
674 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
675 $repo->streamFile( $path );
678 protected function showHistory() {
679 $this->checkReadOnly();
681 $out = $this->getOutput();
682 if ( $this->mAllowed
) {
683 $out->addModules( 'mediawiki.special.undelete' );
686 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
687 [ 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj
->getPrefixedText() ) ]
690 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
691 Hooks
::run( 'UndeleteForm::showHistory', [ &$archive, $this->mTargetObj
] );
693 $out->addHTML( '<div class="mw-undelete-history">' );
694 if ( $this->mAllowed
) {
695 $out->addWikiMsg( 'undeletehistory' );
696 $out->addWikiMsg( 'undeleterevdel' );
698 $out->addWikiMsg( 'undeletehistorynoadmin' );
700 $out->addHTML( '</div>' );
702 # List all stored revisions
703 $revisions = $archive->listRevisions();
704 $files = $archive->listFiles();
706 $haveRevisions = $revisions && $revisions->numRows() > 0;
707 $haveFiles = $files && $files->numRows() > 0;
709 # Batch existence check on user and talk pages
710 if ( $haveRevisions ) {
711 $batch = new LinkBatch();
712 foreach ( $revisions as $row ) {
713 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
714 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
717 $revisions->seek( 0 );
720 $batch = new LinkBatch();
721 foreach ( $files as $row ) {
722 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
723 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
729 if ( $this->mAllowed
) {
732 $action = $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] );
733 # Start the form here
734 $form = new OOUI\
FormLayout( [
741 # Show relevant lines from the deletion log:
742 $deleteLogPage = new LogPage( 'delete' );
743 $out->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) . "\n" );
744 LogEventsList
::showLogExtract( $out, 'delete', $this->mTargetObj
);
745 # Show relevant lines from the suppression log:
746 $suppressLogPage = new LogPage( 'suppress' );
747 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
748 $out->addHTML( Xml
::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
749 LogEventsList
::showLogExtract( $out, 'suppress', $this->mTargetObj
);
752 if ( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
753 $fields[] = new OOUI\
Layout( [
754 'content' => new OOUI\
HtmlSnippet( $this->msg( 'undeleteextrahelp' )->parseAsBlock() )
757 $conf = $this->getConfig();
758 $oldCommentSchema = $conf->get( 'CommentTableSchemaMigrationStage' ) === MIGRATION_OLD
;
760 $fields[] = new OOUI\
FieldLayout(
761 new OOUI\
TextInputWidget( [
762 'name' => 'wpComment',
763 'inputId' => 'wpComment',
765 'value' => $this->mComment
,
767 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
768 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
769 // Unicode codepoints (or 255 UTF-8 bytes for old schema).
770 'maxLength' => $oldCommentSchema ?
255 : CommentStore
::COMMENT_CHARACTER_LIMIT
,
773 'label' => $this->msg( 'undeletecomment' )->text(),
778 $fields[] = new OOUI\
FieldLayout(
780 'content' => new OOUI\
HorizontalLayout( [
782 new OOUI\
ButtonInputWidget( [
784 'inputId' => 'mw-undelete-submit',
786 'label' => $this->msg( 'undeletebtn' )->text(),
787 'flags' => [ 'primary', 'progressive' ],
790 new OOUI\
ButtonInputWidget( [
792 'inputId' => 'mw-undelete-invert',
794 'label' => $this->msg( 'undeleteinvert' )->text()
801 if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
802 $fields[] = new OOUI\
FieldLayout(
803 new OOUI\
CheckboxInputWidget( [
804 'name' => 'wpUnsuppress',
805 'inputId' => 'mw-undelete-unsuppress',
809 'label' => $this->msg( 'revdelete-unsuppress' )->text(),
815 $fieldset = new OOUI\
FieldsetLayout( [
816 'label' => $this->msg( 'undelete-fieldset-title' )->text(),
817 'id' => 'mw-undelete-table',
821 $form->appendContent(
822 new OOUI\
PanelLayout( [
826 'content' => $fieldset,
828 new OOUI\
HtmlSnippet(
829 Html
::hidden( 'target', $this->mTarget
) .
830 Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() )
836 $history .= Xml
::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n";
838 if ( $haveRevisions ) {
839 # Show the page's stored (deleted) history
841 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
842 $history .= Html
::element(
847 'class' => 'deleterevision-log-submit mw-log-deleterevision-button'
849 $this->msg( 'showhideselectedversions' )->text()
853 $history .= '<ul class="mw-undelete-revlist">';
854 $remaining = $revisions->numRows();
855 $earliestLiveTime = $this->mTargetObj
->getEarliestRevTime();
857 foreach ( $revisions as $row ) {
859 $history .= $this->formatRevisionRow( $row, $earliestLiveTime, $remaining );
864 $out->addWikiMsg( 'nohistory' );
868 $history .= Xml
::element( 'h2', null, $this->msg( 'filehist' )->text() ) . "\n";
869 $history .= '<ul class="mw-undelete-revlist">';
870 foreach ( $files as $row ) {
871 $history .= $this->formatFileRow( $row );
877 if ( $this->mAllowed
) {
878 # Slip in the hidden controls here
879 $misc = Html
::hidden( 'target', $this->mTarget
);
880 $misc .= Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
883 $form->appendContent( new OOUI\
HtmlSnippet( $history ) );
884 $out->addHTML( $form );
886 $out->addHTML( $history );
892 protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
893 $rev = Revision
::newFromArchiveRow( $row,
895 'title' => $this->mTargetObj
899 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
900 // Build checkboxen...
901 if ( $this->mAllowed
) {
902 if ( $this->mInvert
) {
903 if ( in_array( $ts, $this->mTargetTimestamp
) ) {
904 $checkBox = Xml
::check( "ts$ts" );
906 $checkBox = Xml
::check( "ts$ts", true );
909 $checkBox = Xml
::check( "ts$ts" );
915 // Build page & diff links...
916 $user = $this->getUser();
917 if ( $this->mCanView
) {
918 $titleObj = $this->getPageTitle();
920 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
921 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
922 $last = $this->msg( 'diff' )->escaped();
923 } elseif ( $remaining > 0 ||
( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
924 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
925 $last = $this->getLinkRenderer()->makeKnownLink(
927 $this->msg( 'diff' )->text(),
930 'target' => $this->mTargetObj
->getPrefixedText(),
936 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
937 $last = $this->msg( 'diff' )->escaped();
940 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
941 $last = $this->msg( 'diff' )->escaped();
945 $userLink = Linker
::revUserTools( $rev );
948 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
950 // Revision text size
951 $size = $row->ar_len
;
952 if ( !is_null( $size ) ) {
953 $revTextSize = Linker
::formatRevisionSize( $size );
957 $comment = Linker
::revComment( $rev );
961 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
967 $attribs['class'] = implode( ' ', $classes );
970 $revisionRow = $this->msg( 'undelete-revision-row2' )
983 return Xml
::tags( 'li', $attribs, $revisionRow ) . "\n";
986 private function formatFileRow( $row ) {
987 $file = ArchivedFile
::newFromRow( $row );
988 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
989 $user = $this->getUser();
992 if ( $this->mCanView
&& $row->fa_storage_key
) {
993 if ( $this->mAllowed
) {
994 $checkBox = Xml
::check( 'fileid' . $row->fa_id
);
996 $key = urlencode( $row->fa_storage_key
);
997 $pageLink = $this->getFileLink( $file, $this->getPageTitle(), $ts, $key );
999 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
1001 $userLink = $this->getFileUser( $file );
1002 $data = $this->msg( 'widthheight' )->numParams( $row->fa_width
, $row->fa_height
)->text();
1003 $bytes = $this->msg( 'parentheses' )
1004 ->plaintextParams( $this->msg( 'nbytes' )->numParams( $row->fa_size
)->text() )
1006 $data = htmlspecialchars( $data . ' ' . $bytes );
1007 $comment = $this->getFileComment( $file );
1009 // Add show/hide deletion links if available
1010 $canHide = $this->isAllowed( 'deleterevision' );
1011 if ( $canHide ||
( $file->getVisibility() && $this->isAllowed( 'deletedhistory' ) ) ) {
1012 if ( !$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
1013 // Revision was hidden from sysops
1014 $revdlink = Linker
::revDeleteLinkDisabled( $canHide );
1017 'type' => 'filearchive',
1018 'target' => $this->mTargetObj
->getPrefixedDBkey(),
1019 'ids' => $row->fa_id
1021 $revdlink = Linker
::revDeleteLink( $query,
1022 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1028 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1032 * Fetch revision text link if it's available to all users
1034 * @param Revision $rev
1035 * @param Title $titleObj
1036 * @param string $ts Timestamp
1039 function getPageLink( $rev, $titleObj, $ts ) {
1040 $user = $this->getUser();
1041 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1043 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1044 return '<span class="history-deleted">' . $time . '</span>';
1047 $link = $this->getLinkRenderer()->makeKnownLink(
1052 'target' => $this->mTargetObj
->getPrefixedText(),
1057 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1058 $link = '<span class="history-deleted">' . $link . '</span>';
1065 * Fetch image view link if it's available to all users
1067 * @param File|ArchivedFile $file
1068 * @param Title $titleObj
1069 * @param string $ts A timestamp
1070 * @param string $key A storage key
1072 * @return string HTML fragment
1074 function getFileLink( $file, $titleObj, $ts, $key ) {
1075 $user = $this->getUser();
1076 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1078 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
1079 return '<span class="history-deleted">' . htmlspecialchars( $time ) . '</span>';
1082 $link = $this->getLinkRenderer()->makeKnownLink(
1087 'target' => $this->mTargetObj
->getPrefixedText(),
1089 'token' => $user->getEditToken( $key )
1093 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
1094 $link = '<span class="history-deleted">' . $link . '</span>';
1101 * Fetch file's user id if it's available to this user
1103 * @param File|ArchivedFile $file
1104 * @return string HTML fragment
1106 function getFileUser( $file ) {
1107 if ( !$file->userCan( File
::DELETED_USER
, $this->getUser() ) ) {
1108 return '<span class="history-deleted">' .
1109 $this->msg( 'rev-deleted-user' )->escaped() .
1113 $link = Linker
::userLink( $file->getRawUser(), $file->getRawUserText() ) .
1114 Linker
::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1116 if ( $file->isDeleted( File
::DELETED_USER
) ) {
1117 $link = '<span class="history-deleted">' . $link . '</span>';
1124 * Fetch file upload comment if it's available to this user
1126 * @param File|ArchivedFile $file
1127 * @return string HTML fragment
1129 function getFileComment( $file ) {
1130 if ( !$file->userCan( File
::DELETED_COMMENT
, $this->getUser() ) ) {
1131 return '<span class="history-deleted"><span class="comment">' .
1132 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></span>';
1135 $link = Linker
::commentBlock( $file->getRawDescription() );
1137 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
1138 $link = '<span class="history-deleted">' . $link . '</span>';
1144 function undelete() {
1145 if ( $this->getConfig()->get( 'UploadMaintenance' )
1146 && $this->mTargetObj
->getNamespace() == NS_FILE
1148 throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
1151 $this->checkReadOnly();
1153 $out = $this->getOutput();
1154 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1155 Hooks
::run( 'UndeleteForm::undelete', [ &$archive, $this->mTargetObj
] );
1156 $ok = $archive->undelete(
1157 $this->mTargetTimestamp
,
1159 $this->mFileVersions
,
1164 if ( is_array( $ok ) ) {
1165 if ( $ok[1] ) { // Undeleted file count
1166 Hooks
::run( 'FileUndeleteComplete', [
1167 $this->mTargetObj
, $this->mFileVersions
,
1168 $this->getUser(), $this->mComment
] );
1171 $link = $this->getLinkRenderer()->makeKnownLink( $this->mTargetObj
);
1172 $out->addHTML( $this->msg( 'undeletedpage' )->rawParams( $link )->parse() );
1174 $out->setPageTitle( $this->msg( 'undelete-error' ) );
1177 // Show revision undeletion warnings and errors
1178 $status = $archive->getRevisionStatus();
1179 if ( $status && !$status->isGood() ) {
1180 $out->addWikiText( '<div class="error" id="mw-error-cannotundelete">' .
1181 $status->getWikiText(
1188 // Show file undeletion warnings and errors
1189 $status = $archive->getFileStatus();
1190 if ( $status && !$status->isGood() ) {
1191 $out->addWikiText( '<div class="error">' .
1192 $status->getWikiText(
1193 'undelete-error-short',
1194 'undelete-error-long'
1201 * Return an array of subpages beginning with $search that this special page will accept.
1203 * @param string $search Prefix to search for
1204 * @param int $limit Maximum number of results to return (usually 10)
1205 * @param int $offset Number of results to skip (usually 0)
1206 * @return string[] Matching subpages
1208 public function prefixSearchSubpages( $search, $limit, $offset ) {
1209 return $this->prefixSearchString( $search, $limit, $offset );
1212 protected function getGroupName() {