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 Wikimedia\Rdbms\ResultWrapper
;
27 * Special page allowing users with the appropriate permissions to view
28 * and restore deleted content.
30 * @ingroup SpecialPage
32 class SpecialUndelete
extends SpecialPage
{
40 private $mTargetTimestamp;
49 * @var string Search prefix
51 private $mSearchPrefix;
53 function __construct() {
54 parent
::__construct( 'Undelete', 'deletedhistory' );
57 public function doesWrites() {
61 function loadRequest( $par ) {
62 $request = $this->getRequest();
63 $user = $this->getUser();
65 $this->mAction
= $request->getVal( 'action' );
66 if ( $par !== null && $par !== '' ) {
67 $this->mTarget
= $par;
69 $this->mTarget
= $request->getVal( 'target' );
72 $this->mTargetObj
= null;
74 if ( $this->mTarget
!== null && $this->mTarget
!== '' ) {
75 $this->mTargetObj
= Title
::newFromText( $this->mTarget
);
78 $this->mSearchPrefix
= $request->getText( 'prefix' );
79 $time = $request->getVal( 'timestamp' );
80 $this->mTimestamp
= $time ?
wfTimestamp( TS_MW
, $time ) : '';
81 $this->mFilename
= $request->getVal( 'file' );
83 $posted = $request->wasPosted() &&
84 $user->matchEditToken( $request->getVal( 'wpEditToken' ) );
85 $this->mRestore
= $request->getCheck( 'restore' ) && $posted;
86 $this->mRevdel
= $request->getCheck( 'revdel' ) && $posted;
87 $this->mInvert
= $request->getCheck( 'invert' ) && $posted;
88 $this->mPreview
= $request->getCheck( 'preview' ) && $posted;
89 $this->mDiff
= $request->getCheck( 'diff' );
90 $this->mDiffOnly
= $request->getBool( 'diffonly', $this->getUser()->getOption( 'diffonly' ) );
91 $this->mComment
= $request->getText( 'wpComment' );
92 $this->mUnsuppress
= $request->getVal( 'wpUnsuppress' ) && $user->isAllowed( 'suppressrevision' );
93 $this->mToken
= $request->getVal( 'token' );
95 if ( $this->isAllowed( 'undelete' ) && !$user->isBlocked() ) {
96 $this->mAllowed
= true; // user can restore
97 $this->mCanView
= true; // user can view content
98 } elseif ( $this->isAllowed( 'deletedtext' ) ) {
99 $this->mAllowed
= false; // user cannot restore
100 $this->mCanView
= true; // user can view content
101 $this->mRestore
= false;
102 } else { // user can only view the list of revisions
103 $this->mAllowed
= false;
104 $this->mCanView
= false;
105 $this->mTimestamp
= '';
106 $this->mRestore
= false;
109 if ( $this->mRestore ||
$this->mInvert
) {
111 $this->mFileVersions
= [];
112 foreach ( $request->getValues() as $key => $val ) {
114 if ( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
115 array_push( $timestamps, $matches[1] );
118 if ( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
119 $this->mFileVersions
[] = intval( $matches[1] );
122 rsort( $timestamps );
123 $this->mTargetTimestamp
= $timestamps;
128 * Checks whether a user is allowed the permission for the
129 * specific title if one is set.
131 * @param string $permission
135 protected function isAllowed( $permission, User
$user = null ) {
136 $user = $user ?
: $this->getUser();
137 if ( $this->mTargetObj
!== null ) {
138 return $this->mTargetObj
->userCan( $permission, $user );
140 return $user->isAllowed( $permission );
144 function userCanExecute( User
$user ) {
145 return $this->isAllowed( $this->mRestriction
, $user );
148 function execute( $par ) {
149 $this->useTransactionalTimeLimit();
151 $user = $this->getUser();
154 $this->outputHeader();
156 $this->loadRequest( $par );
157 $this->checkPermissions(); // Needs to be after mTargetObj is set
159 $out = $this->getOutput();
161 if ( is_null( $this->mTargetObj
) ) {
162 $out->addWikiMsg( 'undelete-header' );
164 # Not all users can just browse every deleted page from the list
165 if ( $user->isAllowed( 'browsearchive' ) ) {
166 $this->showSearchForm();
172 $this->addHelpLink( 'Help:Undelete' );
173 if ( $this->mAllowed
) {
174 $out->setPageTitle( $this->msg( 'undeletepage' ) );
176 $out->setPageTitle( $this->msg( 'viewdeletedpage' ) );
179 $this->getSkin()->setRelevantTitle( $this->mTargetObj
);
181 if ( $this->mTimestamp
!== '' ) {
182 $this->showRevision( $this->mTimestamp
);
183 } elseif ( $this->mFilename
!== null && $this->mTargetObj
->inNamespace( NS_FILE
) ) {
184 $file = new ArchivedFile( $this->mTargetObj
, '', $this->mFilename
);
185 // Check if user is allowed to see this file
186 if ( !$file->exists() ) {
187 $out->addWikiMsg( 'filedelete-nofile', $this->mFilename
);
188 } elseif ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
189 if ( $file->isDeleted( File
::DELETED_RESTRICTED
) ) {
190 throw new PermissionsError( 'suppressrevision' );
192 throw new PermissionsError( 'deletedtext' );
194 } elseif ( !$user->matchEditToken( $this->mToken
, $this->mFilename
) ) {
195 $this->showFileConfirmationForm( $this->mFilename
);
197 $this->showFile( $this->mFilename
);
199 } elseif ( $this->mAction
=== "submit" ) {
200 if ( $this->mRestore
) {
202 } elseif ( $this->mRevdel
) {
203 $this->redirectToRevDel();
207 $this->showHistory();
212 * Convert submitted form data to format expected by RevisionDelete and
213 * redirect the request
215 private function redirectToRevDel() {
216 $archive = new PageArchive( $this->mTargetObj
);
220 foreach ( $this->getRequest()->getValues() as $key => $val ) {
222 if ( preg_match( "/^ts(\d{14})$/", $key, $matches ) ) {
223 $revisions[ $archive->getRevision( $matches[1] )->getId() ] = 1;
227 "type" => "revision",
229 "target" => $this->mTargetObj
->getPrefixedText()
231 $url = SpecialPage
::getTitleFor( 'Revisiondelete' )->getFullURL( $query );
232 $this->getOutput()->redirect( $url );
235 function showSearchForm() {
236 $out = $this->getOutput();
237 $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
238 $fuzzySearch = $this->getRequest()->getVal( "fuzzy", false );
240 Xml
::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] ) .
241 Xml
::fieldset( $this->msg( 'undelete-search-box' )->text() ) .
242 Html
::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
243 Html
::hidden( 'fuzzy', $this->getRequest()->getVal( 'fuzzy' ) ) .
246 [ 'for' => 'prefix' ],
247 $this->msg( $fuzzySearch ?
'undelete-search-full' : 'undelete-search-prefix' )
253 $this->mSearchPrefix
,
254 [ 'id' => 'prefix', 'autofocus' => '' ]
258 $this->msg( 'undelete-search-submit' )->text(),
259 [ 'id' => 'searchUndelete' ]
261 Xml
::closeElement( 'fieldset' ) .
262 Xml
::closeElement( 'form' )
265 # List undeletable articles
266 if ( $this->mSearchPrefix
) {
267 // For now, we enable search engine match only when specifically asked to
268 // by using fuzzy=1 parameter.
269 if ( $fuzzySearch ) {
270 $result = PageArchive
::listPagesBySearch( $this->mSearchPrefix
);
272 $result = PageArchive
::listPagesByPrefix( $this->mSearchPrefix
);
274 $this->showList( $result );
279 * Generic list of deleted pages
281 * @param ResultWrapper $result
284 private function showList( $result ) {
285 $out = $this->getOutput();
287 if ( $result->numRows() == 0 ) {
288 $out->addWikiMsg( 'undelete-no-results' );
293 $out->addWikiMsg( 'undeletepagetext', $this->getLanguage()->formatNum( $result->numRows() ) );
295 $linkRenderer = $this->getLinkRenderer();
296 $undelete = $this->getPageTitle();
297 $out->addHTML( "<ul id='undeleteResultsList'>\n" );
298 foreach ( $result as $row ) {
299 $title = Title
::makeTitleSafe( $row->ar_namespace
, $row->ar_title
);
300 if ( $title !== null ) {
301 $item = $linkRenderer->makeKnownLink(
303 $title->getPrefixedText(),
305 [ 'target' => $title->getPrefixedText() ]
308 // The title is no longer valid, show as text
309 $item = Html
::element(
311 [ 'class' => 'mw-invalidtitle' ],
312 Linker
::getInvalidTitleDescription(
319 $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count
)->parse();
320 $out->addHTML( "<li class='undeleteResult'>{$item} ({$revs})</li>\n" );
323 $out->addHTML( "</ul>\n" );
328 private function showRevision( $timestamp ) {
329 if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
333 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
334 if ( !Hooks
::run( 'UndeleteForm::showRevision', [ &$archive, $this->mTargetObj
] ) ) {
337 $rev = $archive->getRevision( $timestamp );
339 $out = $this->getOutput();
340 $user = $this->getUser();
343 $out->addWikiMsg( 'undeleterevision-missing' );
348 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
349 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
351 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
352 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
353 'rev-suppressed-text-permission' : 'rev-deleted-text-permission'
360 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
361 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
362 'rev-suppressed-text-view' : 'rev-deleted-text-view'
364 $out->addHTML( '<br />' );
365 // and we are allowed to see...
368 if ( $this->mDiff
) {
369 $previousRev = $archive->getPreviousRevision( $timestamp );
370 if ( $previousRev ) {
371 $this->showDiff( $previousRev, $rev );
372 if ( $this->mDiffOnly
) {
376 $out->addHTML( '<hr />' );
378 $out->addWikiMsg( 'undelete-nodiff' );
382 $link = $this->getLinkRenderer()->makeKnownLink(
383 $this->getPageTitle( $this->mTargetObj
->getPrefixedDBkey() ),
384 $this->mTargetObj
->getPrefixedText()
387 $lang = $this->getLanguage();
389 // date and time are separate parameters to facilitate localisation.
390 // $time is kept for backward compat reasons.
391 $time = $lang->userTimeAndDate( $timestamp, $user );
392 $d = $lang->userDate( $timestamp, $user );
393 $t = $lang->userTime( $timestamp, $user );
394 $userLink = Linker
::revUserTools( $rev );
396 $content = $rev->getContent( Revision
::FOR_THIS_USER
, $user );
398 $isText = ( $content instanceof TextContent
);
400 if ( $this->mPreview ||
$isText ) {
401 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
403 $openDiv = '<div id="mw-undelete-revision">';
405 $out->addHTML( $openDiv );
407 // Revision delete links
408 if ( !$this->mDiff
) {
409 $revdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
411 $out->addHTML( "$revdel " );
415 $out->addHTML( $this->msg( 'undelete-revision' )->rawParams( $link )->params(
416 $time )->rawParams( $userLink )->params( $d, $t )->parse() . '</div>' );
418 if ( !Hooks
::run( 'UndeleteShowRevision', [ $this->mTargetObj
, $rev ] ) ) {
422 if ( ( $this->mPreview ||
!$isText ) && $content ) {
423 // NOTE: non-text content has no source view, so always use rendered preview
426 $popts = $out->parserOptions();
427 $popts->setEditSection( false );
429 $pout = $content->getParserOutput( $this->mTargetObj
, $rev->getId(), $popts, true );
430 $out->addParserOutput( $pout );
434 // source view for textual content
435 $sourceView = Xml
::element(
438 'readonly' => 'readonly',
442 $content->getNativeData() . "\n"
445 $previewButton = Xml
::element( 'input', [
448 'value' => $this->msg( 'showpreview' )->text()
455 $diffButton = Xml
::element( 'input', [
458 'value' => $this->msg( 'showdiff' )->text() ] );
462 Xml
::openElement( 'div', [
463 'style' => 'clear: both' ] ) .
464 Xml
::openElement( 'form', [
466 'action' => $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] ) ] ) .
467 Xml
::element( 'input', [
470 'value' => $this->mTargetObj
->getPrefixedDBkey() ] ) .
471 Xml
::element( 'input', [
473 'name' => 'timestamp',
474 'value' => $timestamp ] ) .
475 Xml
::element( 'input', [
477 'name' => 'wpEditToken',
478 'value' => $user->getEditToken() ] ) .
481 Xml
::closeElement( 'form' ) .
482 Xml
::closeElement( 'div' )
487 * Build a diff display between this and the previous either deleted
488 * or non-deleted edit.
490 * @param Revision $previousRev
491 * @param Revision $currentRev
492 * @return string HTML
494 function showDiff( $previousRev, $currentRev ) {
495 $diffContext = clone $this->getContext();
496 $diffContext->setTitle( $currentRev->getTitle() );
497 $diffContext->setWikiPage( WikiPage
::factory( $currentRev->getTitle() ) );
499 $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
500 $diffEngine->showDiffStyle();
502 $formattedDiff = $diffEngine->generateContentDiffBody(
503 $previousRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() ),
504 $currentRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() )
507 $formattedDiff = $diffEngine->addHeader(
509 $this->diffHeader( $previousRev, 'o' ),
510 $this->diffHeader( $currentRev, 'n' )
513 $this->getOutput()->addHTML( "<div>$formattedDiff</div>\n" );
517 * @param Revision $rev
518 * @param string $prefix
521 private function diffHeader( $rev, $prefix ) {
522 $isDeleted = !( $rev->getId() && $rev->getTitle() );
524 /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
525 $targetPage = $this->getPageTitle();
527 'target' => $this->mTargetObj
->getPrefixedText(),
528 'timestamp' => wfTimestamp( TS_MW
, $rev->getTimestamp() )
531 /// @todo FIXME: getId() may return non-zero for deleted revs...
532 $targetPage = $rev->getTitle();
533 $targetQuery = [ 'oldid' => $rev->getId() ];
536 // Add show/hide deletion links if available
537 $user = $this->getUser();
538 $lang = $this->getLanguage();
539 $rdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
545 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
547 $tags = wfGetDB( DB_REPLICA
)->selectField(
550 [ 'ts_rev_id' => $rev->getId() ],
553 $tagSummary = ChangeTags
::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() );
555 // FIXME This is reimplementing DifferenceEngine#getRevisionHeader
556 // and partially #showDiffPage, but worse
557 return '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
558 $this->getLinkRenderer()->makeLink(
562 $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
563 $lang->userDate( $rev->getTimestamp(), $user ),
564 $lang->userTime( $rev->getTimestamp(), $user )
570 '<div id="mw-diff-' . $prefix . 'title2">' .
571 Linker
::revUserTools( $rev ) . '<br />' .
573 '<div id="mw-diff-' . $prefix . 'title3">' .
574 $minor . Linker
::revComment( $rev ) . $rdel . '<br />' .
576 '<div id="mw-diff-' . $prefix . 'title5">' .
577 $tagSummary[0] . '<br />' .
582 * Show a form confirming whether a tokenless user really wants to see a file
585 private function showFileConfirmationForm( $key ) {
586 $out = $this->getOutput();
587 $lang = $this->getLanguage();
588 $user = $this->getUser();
589 $file = new ArchivedFile( $this->mTargetObj
, '', $this->mFilename
);
590 $out->addWikiMsg( 'undelete-show-file-confirm',
591 $this->mTargetObj
->getText(),
592 $lang->userDate( $file->getTimestamp(), $user ),
593 $lang->userTime( $file->getTimestamp(), $user ) );
595 Xml
::openElement( 'form', [
597 'action' => $this->getPageTitle()->getLocalURL( [
598 'target' => $this->mTarget
,
600 'token' => $user->getEditToken( $key ),
604 Xml
::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
610 * Show a deleted file version requested by the visitor.
613 private function showFile( $key ) {
614 $this->getOutput()->disable();
616 # We mustn't allow the output to be CDN cached, otherwise
617 # if an admin previews a deleted image, and it's cached, then
618 # a user without appropriate permissions can toddle off and
619 # nab the image, and CDN will serve it
620 $response = $this->getRequest()->response();
621 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
622 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
623 $response->header( 'Pragma: no-cache' );
625 $repo = RepoGroup
::singleton()->getLocalRepo();
626 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
627 $repo->streamFile( $path );
630 protected function showHistory() {
631 $this->checkReadOnly();
633 $out = $this->getOutput();
634 if ( $this->mAllowed
) {
635 $out->addModules( 'mediawiki.special.undelete' );
638 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
639 [ 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj
->getPrefixedText() ) ]
642 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
643 Hooks
::run( 'UndeleteForm::showHistory', [ &$archive, $this->mTargetObj
] );
645 $text = $archive->getLastRevisionText();
646 if( is_null( $text ) ) {
647 $out->addWikiMsg( 'nohistory' );
651 $out->addHTML( '<div class="mw-undelete-history">' );
652 if ( $this->mAllowed
) {
653 $out->addWikiMsg( 'undeletehistory' );
654 $out->addWikiMsg( 'undeleterevdel' );
656 $out->addWikiMsg( 'undeletehistorynoadmin' );
658 $out->addHTML( '</div>' );
660 # List all stored revisions
661 $revisions = $archive->listRevisions();
662 $files = $archive->listFiles();
664 $haveRevisions = $revisions && $revisions->numRows() > 0;
665 $haveFiles = $files && $files->numRows() > 0;
667 # Batch existence check on user and talk pages
668 if ( $haveRevisions ) {
669 $batch = new LinkBatch();
670 foreach ( $revisions as $row ) {
671 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
672 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
675 $revisions->seek( 0 );
678 $batch = new LinkBatch();
679 foreach ( $files as $row ) {
680 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
681 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
687 if ( $this->mAllowed
) {
688 $action = $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] );
689 # Start the form here
690 $top = Xml
::openElement(
692 [ 'method' => 'post', 'action' => $action, 'id' => 'undelete' ]
694 $out->addHTML( $top );
697 # Show relevant lines from the deletion log:
698 $deleteLogPage = new LogPage( 'delete' );
699 $out->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) . "\n" );
700 LogEventsList
::showLogExtract( $out, 'delete', $this->mTargetObj
);
701 # Show relevant lines from the suppression log:
702 $suppressLogPage = new LogPage( 'suppress' );
703 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
704 $out->addHTML( Xml
::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
705 LogEventsList
::showLogExtract( $out, 'suppress', $this->mTargetObj
);
708 if ( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
709 # Format the user-visible controls (comment field, submission button)
710 # in a nice little table
711 if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
715 <td class='mw-input'>" .
716 Xml
::checkLabel( $this->msg( 'revdelete-unsuppress' )->text(),
717 'wpUnsuppress', 'mw-undelete-unsuppress', $this->mUnsuppress
) .
724 $table = Xml
::fieldset( $this->msg( 'undelete-fieldset-title' )->text() ) .
725 Xml
::openElement( 'table', [ 'id' => 'mw-undelete-table' ] ) .
727 <td colspan='2' class='mw-undelete-extrahelp'>" .
728 $this->msg( 'undeleteextrahelp' )->parseAsBlock() .
732 <td class='mw-label'>" .
733 Xml
::label( $this->msg( 'undeletecomment' )->text(), 'wpComment' ) .
735 <td class='mw-input'>" .
740 [ 'id' => 'wpComment', 'autofocus' => '' ]
746 <td class='mw-submit'>" .
748 $this->msg( 'undeletebtn' )->text(),
749 [ 'name' => 'restore', 'id' => 'mw-undelete-submit' ]
752 $this->msg( 'undeleteinvert' )->text(),
753 [ 'name' => 'invert', 'id' => 'mw-undelete-invert' ]
758 Xml
::closeElement( 'table' ) .
759 Xml
::closeElement( 'fieldset' );
761 $out->addHTML( $table );
764 $out->addHTML( Xml
::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n" );
766 if ( $haveRevisions ) {
767 # Show the page's stored (deleted) history
769 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
770 $out->addHTML( Html
::element(
775 'class' => 'deleterevision-log-submit mw-log-deleterevision-button'
777 $this->msg( 'showhideselectedversions' )->text()
781 $out->addHTML( '<ul>' );
782 $remaining = $revisions->numRows();
783 $earliestLiveTime = $this->mTargetObj
->getEarliestRevTime();
785 foreach ( $revisions as $row ) {
787 $out->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining ) );
790 $out->addHTML( '</ul>' );
792 $out->addWikiMsg( 'nohistory' );
796 $out->addHTML( Xml
::element( 'h2', null, $this->msg( 'filehist' )->text() ) . "\n" );
797 $out->addHTML( '<ul>' );
798 foreach ( $files as $row ) {
799 $out->addHTML( $this->formatFileRow( $row ) );
802 $out->addHTML( '</ul>' );
805 if ( $this->mAllowed
) {
806 # Slip in the hidden controls here
807 $misc = Html
::hidden( 'target', $this->mTarget
);
808 $misc .= Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
809 $misc .= Xml
::closeElement( 'form' );
810 $out->addHTML( $misc );
816 protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
817 $rev = Revision
::newFromArchiveRow( $row,
819 'title' => $this->mTargetObj
823 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
824 // Build checkboxen...
825 if ( $this->mAllowed
) {
826 if ( $this->mInvert
) {
827 if ( in_array( $ts, $this->mTargetTimestamp
) ) {
828 $checkBox = Xml
::check( "ts$ts" );
830 $checkBox = Xml
::check( "ts$ts", true );
833 $checkBox = Xml
::check( "ts$ts" );
839 // Build page & diff links...
840 $user = $this->getUser();
841 if ( $this->mCanView
) {
842 $titleObj = $this->getPageTitle();
844 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
845 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
846 $last = $this->msg( 'diff' )->escaped();
847 } elseif ( $remaining > 0 ||
( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
848 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
849 $last = $this->getLinkRenderer()->makeKnownLink(
851 $this->msg( 'diff' )->text(),
854 'target' => $this->mTargetObj
->getPrefixedText(),
860 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
861 $last = $this->msg( 'diff' )->escaped();
864 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
865 $last = $this->msg( 'diff' )->escaped();
869 $userLink = Linker
::revUserTools( $rev );
872 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
874 // Revision text size
875 $size = $row->ar_len
;
876 if ( !is_null( $size ) ) {
877 $revTextSize = Linker
::formatRevisionSize( $size );
881 $comment = Linker
::revComment( $rev );
885 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
891 $attribs['class'] = implode( ' ', $classes );
894 $revisionRow = $this->msg( 'undelete-revision-row2' )
907 return Xml
::tags( 'li', $attribs, $revisionRow ) . "\n";
910 private function formatFileRow( $row ) {
911 $file = ArchivedFile
::newFromRow( $row );
912 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
913 $user = $this->getUser();
916 if ( $this->mCanView
&& $row->fa_storage_key
) {
917 if ( $this->mAllowed
) {
918 $checkBox = Xml
::check( 'fileid' . $row->fa_id
);
920 $key = urlencode( $row->fa_storage_key
);
921 $pageLink = $this->getFileLink( $file, $this->getPageTitle(), $ts, $key );
923 $pageLink = $this->getLanguage()->userTimeAndDate( $ts, $user );
925 $userLink = $this->getFileUser( $file );
926 $data = $this->msg( 'widthheight' )->numParams( $row->fa_width
, $row->fa_height
)->text();
927 $bytes = $this->msg( 'parentheses' )
928 ->rawParams( $this->msg( 'nbytes' )->numParams( $row->fa_size
)->text() )
930 $data = htmlspecialchars( $data . ' ' . $bytes );
931 $comment = $this->getFileComment( $file );
933 // Add show/hide deletion links if available
934 $canHide = $this->isAllowed( 'deleterevision' );
935 if ( $canHide ||
( $file->getVisibility() && $this->isAllowed( 'deletedhistory' ) ) ) {
936 if ( !$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
937 // Revision was hidden from sysops
938 $revdlink = Linker
::revDeleteLinkDisabled( $canHide );
941 'type' => 'filearchive',
942 'target' => $this->mTargetObj
->getPrefixedDBkey(),
945 $revdlink = Linker
::revDeleteLink( $query,
946 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
952 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
956 * Fetch revision text link if it's available to all users
958 * @param Revision $rev
959 * @param Title $titleObj
960 * @param string $ts Timestamp
963 function getPageLink( $rev, $titleObj, $ts ) {
964 $user = $this->getUser();
965 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
967 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
968 return '<span class="history-deleted">' . $time . '</span>';
971 $link = $this->getLinkRenderer()->makeKnownLink(
976 'target' => $this->mTargetObj
->getPrefixedText(),
981 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
982 $link = '<span class="history-deleted">' . $link . '</span>';
989 * Fetch image view link if it's available to all users
991 * @param File|ArchivedFile $file
992 * @param Title $titleObj
993 * @param string $ts A timestamp
994 * @param string $key A storage key
996 * @return string HTML fragment
998 function getFileLink( $file, $titleObj, $ts, $key ) {
999 $user = $this->getUser();
1000 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1002 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
1003 return '<span class="history-deleted">' . $time . '</span>';
1006 $link = $this->getLinkRenderer()->makeKnownLink(
1011 'target' => $this->mTargetObj
->getPrefixedText(),
1013 'token' => $user->getEditToken( $key )
1017 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
1018 $link = '<span class="history-deleted">' . $link . '</span>';
1025 * Fetch file's user id if it's available to this user
1027 * @param File|ArchivedFile $file
1028 * @return string HTML fragment
1030 function getFileUser( $file ) {
1031 if ( !$file->userCan( File
::DELETED_USER
, $this->getUser() ) ) {
1032 return '<span class="history-deleted">' .
1033 $this->msg( 'rev-deleted-user' )->escaped() .
1037 $link = Linker
::userLink( $file->getRawUser(), $file->getRawUserText() ) .
1038 Linker
::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1040 if ( $file->isDeleted( File
::DELETED_USER
) ) {
1041 $link = '<span class="history-deleted">' . $link . '</span>';
1048 * Fetch file upload comment if it's available to this user
1050 * @param File|ArchivedFile $file
1051 * @return string HTML fragment
1053 function getFileComment( $file ) {
1054 if ( !$file->userCan( File
::DELETED_COMMENT
, $this->getUser() ) ) {
1055 return '<span class="history-deleted"><span class="comment">' .
1056 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></span>';
1059 $link = Linker
::commentBlock( $file->getRawDescription() );
1061 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
1062 $link = '<span class="history-deleted">' . $link . '</span>';
1068 function undelete() {
1069 if ( $this->getConfig()->get( 'UploadMaintenance' )
1070 && $this->mTargetObj
->getNamespace() == NS_FILE
1072 throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
1075 $this->checkReadOnly();
1077 $out = $this->getOutput();
1078 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1079 Hooks
::run( 'UndeleteForm::undelete', [ &$archive, $this->mTargetObj
] );
1080 $ok = $archive->undelete(
1081 $this->mTargetTimestamp
,
1083 $this->mFileVersions
,
1088 if ( is_array( $ok ) ) {
1089 if ( $ok[1] ) { // Undeleted file count
1090 Hooks
::run( 'FileUndeleteComplete', [
1091 $this->mTargetObj
, $this->mFileVersions
,
1092 $this->getUser(), $this->mComment
] );
1095 $link = $this->getLinkRenderer()->makeKnownLink( $this->mTargetObj
);
1096 $out->addHTML( $this->msg( 'undeletedpage' )->rawParams( $link )->parse() );
1098 $out->setPageTitle( $this->msg( 'undelete-error' ) );
1101 // Show revision undeletion warnings and errors
1102 $status = $archive->getRevisionStatus();
1103 if ( $status && !$status->isGood() ) {
1104 $out->addWikiText( '<div class="error" id="mw-error-cannotundelete">' .
1105 $status->getWikiText(
1112 // Show file undeletion warnings and errors
1113 $status = $archive->getFileStatus();
1114 if ( $status && !$status->isGood() ) {
1115 $out->addWikiText( '<div class="error">' .
1116 $status->getWikiText(
1117 'undelete-error-short',
1118 'undelete-error-long'
1125 * Return an array of subpages beginning with $search that this special page will accept.
1127 * @param string $search Prefix to search for
1128 * @param int $limit Maximum number of results to return (usually 10)
1129 * @param int $offset Number of results to skip (usually 0)
1130 * @return string[] Matching subpages
1132 public function prefixSearchSubpages( $search, $limit, $offset ) {
1133 return $this->prefixSearchString( $search, $limit, $offset );
1136 protected function getGroupName() {