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 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();
353 [ 'class' => 'undeleteResult' ],
359 $out->addHTML( "</ul>\n" );
364 private function showRevision( $timestamp ) {
365 if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
369 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
370 if ( !Hooks
::run( 'UndeleteForm::showRevision', [ &$archive, $this->mTargetObj
] ) ) {
373 $rev = $archive->getRevision( $timestamp );
375 $out = $this->getOutput();
376 $user = $this->getUser();
379 $out->addWikiMsg( 'undeleterevision-missing' );
384 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
385 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
387 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
388 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
389 'rev-suppressed-text-permission' : 'rev-deleted-text-permission'
396 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
397 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
398 'rev-suppressed-text-view' : 'rev-deleted-text-view'
400 $out->addHTML( '<br />' );
401 // and we are allowed to see...
404 if ( $this->mDiff
) {
405 $previousRev = $archive->getPreviousRevision( $timestamp );
406 if ( $previousRev ) {
407 $this->showDiff( $previousRev, $rev );
408 if ( $this->mDiffOnly
) {
412 $out->addHTML( '<hr />' );
414 $out->addWikiMsg( 'undelete-nodiff' );
418 $link = $this->getLinkRenderer()->makeKnownLink(
419 $this->getPageTitle( $this->mTargetObj
->getPrefixedDBkey() ),
420 $this->mTargetObj
->getPrefixedText()
423 $lang = $this->getLanguage();
425 // date and time are separate parameters to facilitate localisation.
426 // $time is kept for backward compat reasons.
427 $time = $lang->userTimeAndDate( $timestamp, $user );
428 $d = $lang->userDate( $timestamp, $user );
429 $t = $lang->userTime( $timestamp, $user );
430 $userLink = Linker
::revUserTools( $rev );
432 $content = $rev->getContent( RevisionRecord
::FOR_THIS_USER
, $user );
434 // TODO: MCR: this will have to become something like $hasTextSlots and $hasNonTextSlots
435 $isText = ( $content instanceof TextContent
);
437 if ( $this->mPreview ||
$isText ) {
438 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
440 $openDiv = '<div id="mw-undelete-revision">';
442 $out->addHTML( $openDiv );
444 // Revision delete links
445 if ( !$this->mDiff
) {
446 $revdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
448 $out->addHTML( "$revdel " );
452 $out->addHTML( $this->msg( 'undelete-revision' )->rawParams( $link )->params(
453 $time )->rawParams( $userLink )->params( $d, $t )->parse() . '</div>' );
455 if ( !Hooks
::run( 'UndeleteShowRevision', [ $this->mTargetObj
, $rev ] ) ) {
459 if ( $this->mPreview ||
!$isText ) {
460 // NOTE: non-text content has no source view, so always use rendered preview
462 $popts = $out->parserOptions();
463 $renderer = MediaWikiServices
::getInstance()->getRevisionRenderer();
465 $rendered = $renderer->getRenderedRevision(
466 $rev->getRevisionRecord(),
469 [ 'audience' => RevisionRecord
::FOR_THIS_USER
]
472 // Fail hard if the audience check fails, since we already checked
473 // at the beginning of this method.
474 $pout = $rendered->getRevisionParserOutput();
476 $out->addParserOutput( $pout, [
477 'enableSectionEditLinks' => false,
485 // TODO: MCR: make this work for multiple slots
486 // source view for textual content
487 $sourceView = Xml
::element( 'textarea', [
488 'readonly' => 'readonly',
491 ], $content->getNativeData() . "\n" );
493 $buttonFields[] = new OOUI\
ButtonInputWidget( [
496 'label' => $this->msg( 'showpreview' )->text()
503 $buttonFields[] = new OOUI\
ButtonInputWidget( [
506 'label' => $this->msg( 'showdiff' )->text()
511 Xml
::openElement( 'div', [
512 'style' => 'clear: both' ] ) .
513 Xml
::openElement( 'form', [
515 'action' => $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] ) ] ) .
516 Xml
::element( 'input', [
519 'value' => $this->mTargetObj
->getPrefixedDBkey() ] ) .
520 Xml
::element( 'input', [
522 'name' => 'timestamp',
523 'value' => $timestamp ] ) .
524 Xml
::element( 'input', [
526 'name' => 'wpEditToken',
527 'value' => $user->getEditToken() ] ) .
528 new OOUI\
FieldLayout(
530 'content' => new OOUI\
HorizontalLayout( [
531 'items' => $buttonFields
535 Xml
::closeElement( 'form' ) .
536 Xml
::closeElement( 'div' )
541 * Build a diff display between this and the previous either deleted
542 * or non-deleted edit.
544 * @param Revision $previousRev
545 * @param Revision $currentRev
546 * @return string HTML
548 function showDiff( $previousRev, $currentRev ) {
549 $diffContext = clone $this->getContext();
550 $diffContext->setTitle( $currentRev->getTitle() );
551 $diffContext->setWikiPage( WikiPage
::factory( $currentRev->getTitle() ) );
553 $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
554 $diffEngine->showDiffStyle();
556 $formattedDiff = $diffEngine->generateContentDiffBody(
557 $previousRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() ),
558 $currentRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() )
561 $formattedDiff = $diffEngine->addHeader(
563 $this->diffHeader( $previousRev, 'o' ),
564 $this->diffHeader( $currentRev, 'n' )
567 $this->getOutput()->addHTML( "<div>$formattedDiff</div>\n" );
571 * @param Revision $rev
572 * @param string $prefix
575 private function diffHeader( $rev, $prefix ) {
576 $isDeleted = !( $rev->getId() && $rev->getTitle() );
578 /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
579 $targetPage = $this->getPageTitle();
581 'target' => $this->mTargetObj
->getPrefixedText(),
582 'timestamp' => wfTimestamp( TS_MW
, $rev->getTimestamp() )
585 /// @todo FIXME: getId() may return non-zero for deleted revs...
586 $targetPage = $rev->getTitle();
587 $targetQuery = [ 'oldid' => $rev->getId() ];
590 // Add show/hide deletion links if available
591 $user = $this->getUser();
592 $lang = $this->getLanguage();
593 $rdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
599 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
601 $tags = wfGetDB( DB_REPLICA
)->selectField(
604 [ 'ts_rev_id' => $rev->getId() ],
607 $tagSummary = ChangeTags
::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() );
609 // FIXME This is reimplementing DifferenceEngine#getRevisionHeader
610 // and partially #showDiffPage, but worse
611 return '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
612 $this->getLinkRenderer()->makeLink(
616 $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
617 $lang->userDate( $rev->getTimestamp(), $user ),
618 $lang->userTime( $rev->getTimestamp(), $user )
624 '<div id="mw-diff-' . $prefix . 'title2">' .
625 Linker
::revUserTools( $rev ) . '<br />' .
627 '<div id="mw-diff-' . $prefix . 'title3">' .
628 $minor . Linker
::revComment( $rev ) . $rdel . '<br />' .
630 '<div id="mw-diff-' . $prefix . 'title5">' .
631 $tagSummary[0] . '<br />' .
636 * Show a form confirming whether a tokenless user really wants to see a file
639 private function showFileConfirmationForm( $key ) {
640 $out = $this->getOutput();
641 $lang = $this->getLanguage();
642 $user = $this->getUser();
643 $file = new ArchivedFile( $this->mTargetObj
, '', $this->mFilename
);
644 $out->addWikiMsg( 'undelete-show-file-confirm',
645 $this->mTargetObj
->getText(),
646 $lang->userDate( $file->getTimestamp(), $user ),
647 $lang->userTime( $file->getTimestamp(), $user ) );
649 Xml
::openElement( 'form', [
651 'action' => $this->getPageTitle()->getLocalURL( [
652 'target' => $this->mTarget
,
654 'token' => $user->getEditToken( $key ),
658 Xml
::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
664 * Show a deleted file version requested by the visitor.
667 private function showFile( $key ) {
668 $this->getOutput()->disable();
670 # We mustn't allow the output to be CDN cached, otherwise
671 # if an admin previews a deleted image, and it's cached, then
672 # a user without appropriate permissions can toddle off and
673 # nab the image, and CDN will serve it
674 $response = $this->getRequest()->response();
675 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
676 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
677 $response->header( 'Pragma: no-cache' );
679 $repo = RepoGroup
::singleton()->getLocalRepo();
680 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
681 $repo->streamFile( $path );
684 protected function showHistory() {
685 $this->checkReadOnly();
687 $out = $this->getOutput();
688 if ( $this->mAllowed
) {
689 $out->addModules( 'mediawiki.special.undelete' );
692 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
693 [ 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj
->getPrefixedText() ) ]
696 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
697 Hooks
::run( 'UndeleteForm::showHistory', [ &$archive, $this->mTargetObj
] );
699 $out->addHTML( '<div class="mw-undelete-history">' );
700 if ( $this->mAllowed
) {
701 $out->addWikiMsg( 'undeletehistory' );
702 $out->addWikiMsg( 'undeleterevdel' );
704 $out->addWikiMsg( 'undeletehistorynoadmin' );
706 $out->addHTML( '</div>' );
708 # List all stored revisions
709 $revisions = $archive->listRevisions();
710 $files = $archive->listFiles();
712 $haveRevisions = $revisions && $revisions->numRows() > 0;
713 $haveFiles = $files && $files->numRows() > 0;
715 # Batch existence check on user and talk pages
716 if ( $haveRevisions ) {
717 $batch = new LinkBatch();
718 foreach ( $revisions as $row ) {
719 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
720 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
723 $revisions->seek( 0 );
726 $batch = new LinkBatch();
727 foreach ( $files as $row ) {
728 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
729 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
735 if ( $this->mAllowed
) {
738 $action = $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] );
739 # Start the form here
740 $form = new OOUI\
FormLayout( [
747 # Show relevant lines from the deletion log:
748 $deleteLogPage = new LogPage( 'delete' );
749 $out->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) . "\n" );
750 LogEventsList
::showLogExtract( $out, 'delete', $this->mTargetObj
);
751 # Show relevant lines from the suppression log:
752 $suppressLogPage = new LogPage( 'suppress' );
753 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
754 $out->addHTML( Xml
::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
755 LogEventsList
::showLogExtract( $out, 'suppress', $this->mTargetObj
);
758 if ( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
759 $fields[] = new OOUI\
Layout( [
760 'content' => new OOUI\
HtmlSnippet( $this->msg( 'undeleteextrahelp' )->parseAsBlock() )
763 $conf = $this->getConfig();
764 $oldCommentSchema = $conf->get( 'CommentTableSchemaMigrationStage' ) === MIGRATION_OLD
;
766 $fields[] = new OOUI\
FieldLayout(
767 new OOUI\
TextInputWidget( [
768 'name' => 'wpComment',
769 'inputId' => 'wpComment',
771 'value' => $this->mComment
,
773 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
774 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
775 // Unicode codepoints (or 255 UTF-8 bytes for old schema).
776 'maxLength' => $oldCommentSchema ?
255 : CommentStore
::COMMENT_CHARACTER_LIMIT
,
779 'label' => $this->msg( 'undeletecomment' )->text(),
784 $fields[] = new OOUI\
FieldLayout(
786 'content' => new OOUI\
HorizontalLayout( [
788 new OOUI\
ButtonInputWidget( [
790 'inputId' => 'mw-undelete-submit',
792 'label' => $this->msg( 'undeletebtn' )->text(),
793 'flags' => [ 'primary', 'progressive' ],
796 new OOUI\
ButtonInputWidget( [
798 'inputId' => 'mw-undelete-invert',
800 'label' => $this->msg( 'undeleteinvert' )->text()
807 if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
808 $fields[] = new OOUI\
FieldLayout(
809 new OOUI\
CheckboxInputWidget( [
810 'name' => 'wpUnsuppress',
811 'inputId' => 'mw-undelete-unsuppress',
815 'label' => $this->msg( 'revdelete-unsuppress' )->text(),
821 $fieldset = new OOUI\
FieldsetLayout( [
822 'label' => $this->msg( 'undelete-fieldset-title' )->text(),
823 'id' => 'mw-undelete-table',
827 $form->appendContent(
828 new OOUI\
PanelLayout( [
832 'content' => $fieldset,
834 new OOUI\
HtmlSnippet(
835 Html
::hidden( 'target', $this->mTarget
) .
836 Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() )
842 $history .= Xml
::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n";
844 if ( $haveRevisions ) {
845 # Show the page's stored (deleted) history
847 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
848 $history .= Html
::element(
853 'class' => 'deleterevision-log-submit mw-log-deleterevision-button'
855 $this->msg( 'showhideselectedversions' )->text()
859 $history .= '<ul class="mw-undelete-revlist">';
860 $remaining = $revisions->numRows();
861 $earliestLiveTime = $this->mTargetObj
->getEarliestRevTime();
863 foreach ( $revisions as $row ) {
865 $history .= $this->formatRevisionRow( $row, $earliestLiveTime, $remaining );
870 $out->addWikiMsg( 'nohistory' );
874 $history .= Xml
::element( 'h2', null, $this->msg( 'filehist' )->text() ) . "\n";
875 $history .= '<ul class="mw-undelete-revlist">';
876 foreach ( $files as $row ) {
877 $history .= $this->formatFileRow( $row );
883 if ( $this->mAllowed
) {
884 # Slip in the hidden controls here
885 $misc = Html
::hidden( 'target', $this->mTarget
);
886 $misc .= Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
889 $form->appendContent( new OOUI\
HtmlSnippet( $history ) );
890 $out->addHTML( $form );
892 $out->addHTML( $history );
898 protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
899 $rev = Revision
::newFromArchiveRow( $row,
901 'title' => $this->mTargetObj
905 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
906 // Build checkboxen...
907 if ( $this->mAllowed
) {
908 if ( $this->mInvert
) {
909 if ( in_array( $ts, $this->mTargetTimestamp
) ) {
910 $checkBox = Xml
::check( "ts$ts" );
912 $checkBox = Xml
::check( "ts$ts", true );
915 $checkBox = Xml
::check( "ts$ts" );
921 // Build page & diff links...
922 $user = $this->getUser();
923 if ( $this->mCanView
) {
924 $titleObj = $this->getPageTitle();
926 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
927 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
928 $last = $this->msg( 'diff' )->escaped();
929 } elseif ( $remaining > 0 ||
( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
930 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
931 $last = $this->getLinkRenderer()->makeKnownLink(
933 $this->msg( 'diff' )->text(),
936 'target' => $this->mTargetObj
->getPrefixedText(),
942 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
943 $last = $this->msg( 'diff' )->escaped();
946 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
947 $last = $this->msg( 'diff' )->escaped();
951 $userLink = Linker
::revUserTools( $rev );
954 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
956 // Revision text size
957 $size = $row->ar_len
;
958 if ( !is_null( $size ) ) {
959 $revTextSize = Linker
::formatRevisionSize( $size );
963 $comment = Linker
::revComment( $rev );
967 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
973 $attribs['class'] = implode( ' ', $classes );
976 $revisionRow = $this->msg( 'undelete-revision-row2' )
989 return Xml
::tags( 'li', $attribs, $revisionRow ) . "\n";
992 private function formatFileRow( $row ) {
993 $file = ArchivedFile
::newFromRow( $row );
994 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
995 $user = $this->getUser();
998 if ( $this->mCanView
&& $row->fa_storage_key
) {
999 if ( $this->mAllowed
) {
1000 $checkBox = Xml
::check( 'fileid' . $row->fa_id
);
1002 $key = urlencode( $row->fa_storage_key
);
1003 $pageLink = $this->getFileLink( $file, $this->getPageTitle(), $ts, $key );
1005 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
1007 $userLink = $this->getFileUser( $file );
1008 $data = $this->msg( 'widthheight' )->numParams( $row->fa_width
, $row->fa_height
)->text();
1009 $bytes = $this->msg( 'parentheses' )
1010 ->plaintextParams( $this->msg( 'nbytes' )->numParams( $row->fa_size
)->text() )
1012 $data = htmlspecialchars( $data . ' ' . $bytes );
1013 $comment = $this->getFileComment( $file );
1015 // Add show/hide deletion links if available
1016 $canHide = $this->isAllowed( 'deleterevision' );
1017 if ( $canHide ||
( $file->getVisibility() && $this->isAllowed( 'deletedhistory' ) ) ) {
1018 if ( !$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
1019 // Revision was hidden from sysops
1020 $revdlink = Linker
::revDeleteLinkDisabled( $canHide );
1023 'type' => 'filearchive',
1024 'target' => $this->mTargetObj
->getPrefixedDBkey(),
1025 'ids' => $row->fa_id
1027 $revdlink = Linker
::revDeleteLink( $query,
1028 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1034 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1038 * Fetch revision text link if it's available to all users
1040 * @param Revision $rev
1041 * @param Title $titleObj
1042 * @param string $ts Timestamp
1045 function getPageLink( $rev, $titleObj, $ts ) {
1046 $user = $this->getUser();
1047 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1049 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1050 return '<span class="history-deleted">' . $time . '</span>';
1053 $link = $this->getLinkRenderer()->makeKnownLink(
1058 'target' => $this->mTargetObj
->getPrefixedText(),
1063 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1064 $link = '<span class="history-deleted">' . $link . '</span>';
1071 * Fetch image view link if it's available to all users
1073 * @param File|ArchivedFile $file
1074 * @param Title $titleObj
1075 * @param string $ts A timestamp
1076 * @param string $key A storage key
1078 * @return string HTML fragment
1080 function getFileLink( $file, $titleObj, $ts, $key ) {
1081 $user = $this->getUser();
1082 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1084 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
1085 return '<span class="history-deleted">' . htmlspecialchars( $time ) . '</span>';
1088 $link = $this->getLinkRenderer()->makeKnownLink(
1093 'target' => $this->mTargetObj
->getPrefixedText(),
1095 'token' => $user->getEditToken( $key )
1099 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
1100 $link = '<span class="history-deleted">' . $link . '</span>';
1107 * Fetch file's user id if it's available to this user
1109 * @param File|ArchivedFile $file
1110 * @return string HTML fragment
1112 function getFileUser( $file ) {
1113 if ( !$file->userCan( File
::DELETED_USER
, $this->getUser() ) ) {
1114 return '<span class="history-deleted">' .
1115 $this->msg( 'rev-deleted-user' )->escaped() .
1119 $link = Linker
::userLink( $file->getRawUser(), $file->getRawUserText() ) .
1120 Linker
::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1122 if ( $file->isDeleted( File
::DELETED_USER
) ) {
1123 $link = '<span class="history-deleted">' . $link . '</span>';
1130 * Fetch file upload comment if it's available to this user
1132 * @param File|ArchivedFile $file
1133 * @return string HTML fragment
1135 function getFileComment( $file ) {
1136 if ( !$file->userCan( File
::DELETED_COMMENT
, $this->getUser() ) ) {
1137 return '<span class="history-deleted"><span class="comment">' .
1138 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></span>';
1141 $link = Linker
::commentBlock( $file->getRawDescription() );
1143 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
1144 $link = '<span class="history-deleted">' . $link . '</span>';
1150 function undelete() {
1151 if ( $this->getConfig()->get( 'UploadMaintenance' )
1152 && $this->mTargetObj
->getNamespace() == NS_FILE
1154 throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
1157 $this->checkReadOnly();
1159 $out = $this->getOutput();
1160 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1161 Hooks
::run( 'UndeleteForm::undelete', [ &$archive, $this->mTargetObj
] );
1162 $ok = $archive->undelete(
1163 $this->mTargetTimestamp
,
1165 $this->mFileVersions
,
1170 if ( is_array( $ok ) ) {
1171 if ( $ok[1] ) { // Undeleted file count
1172 Hooks
::run( 'FileUndeleteComplete', [
1173 $this->mTargetObj
, $this->mFileVersions
,
1174 $this->getUser(), $this->mComment
] );
1177 $link = $this->getLinkRenderer()->makeKnownLink( $this->mTargetObj
);
1178 $out->addHTML( $this->msg( 'undeletedpage' )->rawParams( $link )->parse() );
1180 $out->setPageTitle( $this->msg( 'undelete-error' ) );
1183 // Show revision undeletion warnings and errors
1184 $status = $archive->getRevisionStatus();
1185 if ( $status && !$status->isGood() ) {
1186 $out->wrapWikiTextAsInterface(
1188 '<div id="mw-error-cannotundelete">' .
1189 $status->getWikiText(
1196 // Show file undeletion warnings and errors
1197 $status = $archive->getFileStatus();
1198 if ( $status && !$status->isGood() ) {
1199 $out->wrapWikiTextAsInterface(
1201 $status->getWikiText(
1202 'undelete-error-short',
1203 'undelete-error-long'
1210 * Return an array of subpages beginning with $search that this special page will accept.
1212 * @param string $search Prefix to search for
1213 * @param int $limit Maximum number of results to return (usually 10)
1214 * @param int $offset Number of results to skip (usually 0)
1215 * @return string[] Matching subpages
1217 public function prefixSearchSubpages( $search, $limit, $offset ) {
1218 return $this->prefixSearchString( $search, $limit, $offset );
1221 protected function getGroupName() {