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' ) );
239 Xml
::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] ) .
240 Xml
::fieldset( $this->msg( 'undelete-search-box' )->text() ) .
241 Html
::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
242 Html
::hidden( 'fuzzy', $this->getRequest()->getVal( 'fuzzy' ) ) .
245 [ 'for' => 'prefix' ],
246 $this->msg( 'undelete-search-prefix' )->parse()
251 $this->mSearchPrefix
,
252 [ 'id' => 'prefix', 'autofocus' => '' ]
256 $this->msg( 'undelete-search-submit' )->text(),
257 [ 'id' => 'searchUndelete' ]
259 Xml
::closeElement( 'fieldset' ) .
260 Xml
::closeElement( 'form' )
263 # List undeletable articles
264 if ( $this->mSearchPrefix
) {
265 // For now, we enable search engine match only when specifically asked to
266 // by using fuzzy=1 parameter.
267 if ( $this->getRequest()->getVal( "fuzzy", false ) ) {
268 $result = PageArchive
::listPagesBySearch( $this->mSearchPrefix
);
270 $result = PageArchive
::listPagesByPrefix( $this->mSearchPrefix
);
272 $this->showList( $result );
277 * Generic list of deleted pages
279 * @param ResultWrapper $result
282 private function showList( $result ) {
283 $out = $this->getOutput();
285 if ( $result->numRows() == 0 ) {
286 $out->addWikiMsg( 'undelete-no-results' );
291 $out->addWikiMsg( 'undeletepagetext', $this->getLanguage()->formatNum( $result->numRows() ) );
293 $linkRenderer = $this->getLinkRenderer();
294 $undelete = $this->getPageTitle();
295 $out->addHTML( "<ul id='undeleteResultsList'>\n" );
296 foreach ( $result as $row ) {
297 $title = Title
::makeTitleSafe( $row->ar_namespace
, $row->ar_title
);
298 if ( $title !== null ) {
299 $item = $linkRenderer->makeKnownLink(
301 $title->getPrefixedText(),
303 [ 'target' => $title->getPrefixedText() ]
306 // The title is no longer valid, show as text
307 $item = Html
::element(
309 [ 'class' => 'mw-invalidtitle' ],
310 Linker
::getInvalidTitleDescription(
317 $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count
)->parse();
318 $out->addHTML( "<li class='undeleteResult'>{$item} ({$revs})</li>\n" );
321 $out->addHTML( "</ul>\n" );
326 private function showRevision( $timestamp ) {
327 if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
331 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
332 if ( !Hooks
::run( 'UndeleteForm::showRevision', [ &$archive, $this->mTargetObj
] ) ) {
335 $rev = $archive->getRevision( $timestamp );
337 $out = $this->getOutput();
338 $user = $this->getUser();
341 $out->addWikiMsg( 'undeleterevision-missing' );
346 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
347 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
349 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
350 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
351 'rev-suppressed-text-permission' : 'rev-deleted-text-permission'
358 "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
359 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ?
360 'rev-suppressed-text-view' : 'rev-deleted-text-view'
362 $out->addHTML( '<br />' );
363 // and we are allowed to see...
366 if ( $this->mDiff
) {
367 $previousRev = $archive->getPreviousRevision( $timestamp );
368 if ( $previousRev ) {
369 $this->showDiff( $previousRev, $rev );
370 if ( $this->mDiffOnly
) {
374 $out->addHTML( '<hr />' );
376 $out->addWikiMsg( 'undelete-nodiff' );
380 $link = $this->getLinkRenderer()->makeKnownLink(
381 $this->getPageTitle( $this->mTargetObj
->getPrefixedDBkey() ),
382 $this->mTargetObj
->getPrefixedText()
385 $lang = $this->getLanguage();
387 // date and time are separate parameters to facilitate localisation.
388 // $time is kept for backward compat reasons.
389 $time = $lang->userTimeAndDate( $timestamp, $user );
390 $d = $lang->userDate( $timestamp, $user );
391 $t = $lang->userTime( $timestamp, $user );
392 $userLink = Linker
::revUserTools( $rev );
394 $content = $rev->getContent( Revision
::FOR_THIS_USER
, $user );
396 $isText = ( $content instanceof TextContent
);
398 if ( $this->mPreview ||
$isText ) {
399 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
401 $openDiv = '<div id="mw-undelete-revision">';
403 $out->addHTML( $openDiv );
405 // Revision delete links
406 if ( !$this->mDiff
) {
407 $revdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
409 $out->addHTML( "$revdel " );
413 $out->addHTML( $this->msg( 'undelete-revision' )->rawParams( $link )->params(
414 $time )->rawParams( $userLink )->params( $d, $t )->parse() . '</div>' );
416 if ( !Hooks
::run( 'UndeleteShowRevision', [ $this->mTargetObj
, $rev ] ) ) {
420 if ( ( $this->mPreview ||
!$isText ) && $content ) {
421 // NOTE: non-text content has no source view, so always use rendered preview
424 $popts = $out->parserOptions();
425 $popts->setEditSection( false );
427 $pout = $content->getParserOutput( $this->mTargetObj
, $rev->getId(), $popts, true );
428 $out->addParserOutput( $pout );
432 // source view for textual content
433 $sourceView = Xml
::element(
436 'readonly' => 'readonly',
440 $content->getNativeData() . "\n"
443 $previewButton = Xml
::element( 'input', [
446 'value' => $this->msg( 'showpreview' )->text()
453 $diffButton = Xml
::element( 'input', [
456 'value' => $this->msg( 'showdiff' )->text() ] );
460 Xml
::openElement( 'div', [
461 'style' => 'clear: both' ] ) .
462 Xml
::openElement( 'form', [
464 'action' => $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] ) ] ) .
465 Xml
::element( 'input', [
468 'value' => $this->mTargetObj
->getPrefixedDBkey() ] ) .
469 Xml
::element( 'input', [
471 'name' => 'timestamp',
472 'value' => $timestamp ] ) .
473 Xml
::element( 'input', [
475 'name' => 'wpEditToken',
476 'value' => $user->getEditToken() ] ) .
479 Xml
::closeElement( 'form' ) .
480 Xml
::closeElement( 'div' )
485 * Build a diff display between this and the previous either deleted
486 * or non-deleted edit.
488 * @param Revision $previousRev
489 * @param Revision $currentRev
490 * @return string HTML
492 function showDiff( $previousRev, $currentRev ) {
493 $diffContext = clone $this->getContext();
494 $diffContext->setTitle( $currentRev->getTitle() );
495 $diffContext->setWikiPage( WikiPage
::factory( $currentRev->getTitle() ) );
497 $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
498 $diffEngine->showDiffStyle();
500 $formattedDiff = $diffEngine->generateContentDiffBody(
501 $previousRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() ),
502 $currentRev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() )
505 $formattedDiff = $diffEngine->addHeader(
507 $this->diffHeader( $previousRev, 'o' ),
508 $this->diffHeader( $currentRev, 'n' )
511 $this->getOutput()->addHTML( "<div>$formattedDiff</div>\n" );
515 * @param Revision $rev
516 * @param string $prefix
519 private function diffHeader( $rev, $prefix ) {
520 $isDeleted = !( $rev->getId() && $rev->getTitle() );
522 /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
523 $targetPage = $this->getPageTitle();
525 'target' => $this->mTargetObj
->getPrefixedText(),
526 'timestamp' => wfTimestamp( TS_MW
, $rev->getTimestamp() )
529 /// @todo FIXME: getId() may return non-zero for deleted revs...
530 $targetPage = $rev->getTitle();
531 $targetQuery = [ 'oldid' => $rev->getId() ];
534 // Add show/hide deletion links if available
535 $user = $this->getUser();
536 $lang = $this->getLanguage();
537 $rdel = Linker
::getRevDeleteLink( $user, $rev, $this->mTargetObj
);
543 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
545 $tags = wfGetDB( DB_REPLICA
)->selectField(
548 [ 'ts_rev_id' => $rev->getId() ],
551 $tagSummary = ChangeTags
::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() );
553 // FIXME This is reimplementing DifferenceEngine#getRevisionHeader
554 // and partially #showDiffPage, but worse
555 return '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
556 $this->getLinkRenderer()->makeLink(
560 $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
561 $lang->userDate( $rev->getTimestamp(), $user ),
562 $lang->userTime( $rev->getTimestamp(), $user )
568 '<div id="mw-diff-' . $prefix . 'title2">' .
569 Linker
::revUserTools( $rev ) . '<br />' .
571 '<div id="mw-diff-' . $prefix . 'title3">' .
572 $minor . Linker
::revComment( $rev ) . $rdel . '<br />' .
574 '<div id="mw-diff-' . $prefix . 'title5">' .
575 $tagSummary[0] . '<br />' .
580 * Show a form confirming whether a tokenless user really wants to see a file
583 private function showFileConfirmationForm( $key ) {
584 $out = $this->getOutput();
585 $lang = $this->getLanguage();
586 $user = $this->getUser();
587 $file = new ArchivedFile( $this->mTargetObj
, '', $this->mFilename
);
588 $out->addWikiMsg( 'undelete-show-file-confirm',
589 $this->mTargetObj
->getText(),
590 $lang->userDate( $file->getTimestamp(), $user ),
591 $lang->userTime( $file->getTimestamp(), $user ) );
593 Xml
::openElement( 'form', [
595 'action' => $this->getPageTitle()->getLocalURL( [
596 'target' => $this->mTarget
,
598 'token' => $user->getEditToken( $key ),
602 Xml
::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
608 * Show a deleted file version requested by the visitor.
611 private function showFile( $key ) {
612 $this->getOutput()->disable();
614 # We mustn't allow the output to be CDN cached, otherwise
615 # if an admin previews a deleted image, and it's cached, then
616 # a user without appropriate permissions can toddle off and
617 # nab the image, and CDN will serve it
618 $response = $this->getRequest()->response();
619 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
620 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
621 $response->header( 'Pragma: no-cache' );
623 $repo = RepoGroup
::singleton()->getLocalRepo();
624 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
625 $repo->streamFile( $path );
628 protected function showHistory() {
629 $this->checkReadOnly();
631 $out = $this->getOutput();
632 if ( $this->mAllowed
) {
633 $out->addModules( 'mediawiki.special.undelete' );
636 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
637 [ 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj
->getPrefixedText() ) ]
640 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
641 Hooks
::run( 'UndeleteForm::showHistory', [ &$archive, $this->mTargetObj
] );
643 $text = $archive->getLastRevisionText();
644 if( is_null( $text ) ) {
645 $out->addWikiMsg( 'nohistory' );
649 $out->addHTML( '<div class="mw-undelete-history">' );
650 if ( $this->mAllowed
) {
651 $out->addWikiMsg( 'undeletehistory' );
652 $out->addWikiMsg( 'undeleterevdel' );
654 $out->addWikiMsg( 'undeletehistorynoadmin' );
656 $out->addHTML( '</div>' );
658 # List all stored revisions
659 $revisions = $archive->listRevisions();
660 $files = $archive->listFiles();
662 $haveRevisions = $revisions && $revisions->numRows() > 0;
663 $haveFiles = $files && $files->numRows() > 0;
665 # Batch existence check on user and talk pages
666 if ( $haveRevisions ) {
667 $batch = new LinkBatch();
668 foreach ( $revisions as $row ) {
669 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
670 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
673 $revisions->seek( 0 );
676 $batch = new LinkBatch();
677 foreach ( $files as $row ) {
678 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
679 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
685 if ( $this->mAllowed
) {
686 $action = $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] );
687 # Start the form here
688 $top = Xml
::openElement(
690 [ 'method' => 'post', 'action' => $action, 'id' => 'undelete' ]
692 $out->addHTML( $top );
695 # Show relevant lines from the deletion log:
696 $deleteLogPage = new LogPage( 'delete' );
697 $out->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) . "\n" );
698 LogEventsList
::showLogExtract( $out, 'delete', $this->mTargetObj
);
699 # Show relevant lines from the suppression log:
700 $suppressLogPage = new LogPage( 'suppress' );
701 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
702 $out->addHTML( Xml
::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
703 LogEventsList
::showLogExtract( $out, 'suppress', $this->mTargetObj
);
706 if ( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
707 # Format the user-visible controls (comment field, submission button)
708 # in a nice little table
709 if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
713 <td class='mw-input'>" .
714 Xml
::checkLabel( $this->msg( 'revdelete-unsuppress' )->text(),
715 'wpUnsuppress', 'mw-undelete-unsuppress', $this->mUnsuppress
) .
722 $table = Xml
::fieldset( $this->msg( 'undelete-fieldset-title' )->text() ) .
723 Xml
::openElement( 'table', [ 'id' => 'mw-undelete-table' ] ) .
725 <td colspan='2' class='mw-undelete-extrahelp'>" .
726 $this->msg( 'undeleteextrahelp' )->parseAsBlock() .
730 <td class='mw-label'>" .
731 Xml
::label( $this->msg( 'undeletecomment' )->text(), 'wpComment' ) .
733 <td class='mw-input'>" .
738 [ 'id' => 'wpComment', 'autofocus' => '' ]
744 <td class='mw-submit'>" .
746 $this->msg( 'undeletebtn' )->text(),
747 [ 'name' => 'restore', 'id' => 'mw-undelete-submit' ]
750 $this->msg( 'undeleteinvert' )->text(),
751 [ 'name' => 'invert', 'id' => 'mw-undelete-invert' ]
756 Xml
::closeElement( 'table' ) .
757 Xml
::closeElement( 'fieldset' );
759 $out->addHTML( $table );
762 $out->addHTML( Xml
::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n" );
764 if ( $haveRevisions ) {
765 # Show the page's stored (deleted) history
767 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
768 $out->addHTML( Html
::element(
773 'class' => 'deleterevision-log-submit mw-log-deleterevision-button'
775 $this->msg( 'showhideselectedversions' )->text()
779 $out->addHTML( '<ul>' );
780 $remaining = $revisions->numRows();
781 $earliestLiveTime = $this->mTargetObj
->getEarliestRevTime();
783 foreach ( $revisions as $row ) {
785 $out->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining ) );
788 $out->addHTML( '</ul>' );
790 $out->addWikiMsg( 'nohistory' );
794 $out->addHTML( Xml
::element( 'h2', null, $this->msg( 'filehist' )->text() ) . "\n" );
795 $out->addHTML( '<ul>' );
796 foreach ( $files as $row ) {
797 $out->addHTML( $this->formatFileRow( $row ) );
800 $out->addHTML( '</ul>' );
803 if ( $this->mAllowed
) {
804 # Slip in the hidden controls here
805 $misc = Html
::hidden( 'target', $this->mTarget
);
806 $misc .= Html
::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
807 $misc .= Xml
::closeElement( 'form' );
808 $out->addHTML( $misc );
814 protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
815 $rev = Revision
::newFromArchiveRow( $row,
817 'title' => $this->mTargetObj
821 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
822 // Build checkboxen...
823 if ( $this->mAllowed
) {
824 if ( $this->mInvert
) {
825 if ( in_array( $ts, $this->mTargetTimestamp
) ) {
826 $checkBox = Xml
::check( "ts$ts" );
828 $checkBox = Xml
::check( "ts$ts", true );
831 $checkBox = Xml
::check( "ts$ts" );
837 // Build page & diff links...
838 $user = $this->getUser();
839 if ( $this->mCanView
) {
840 $titleObj = $this->getPageTitle();
842 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
843 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
844 $last = $this->msg( 'diff' )->escaped();
845 } elseif ( $remaining > 0 ||
( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
846 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
847 $last = $this->getLinkRenderer()->makeKnownLink(
849 $this->msg( 'diff' )->text(),
852 'target' => $this->mTargetObj
->getPrefixedText(),
858 $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
859 $last = $this->msg( 'diff' )->escaped();
862 $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
863 $last = $this->msg( 'diff' )->escaped();
867 $userLink = Linker
::revUserTools( $rev );
870 $minor = $rev->isMinor() ? ChangesList
::flag( 'minor' ) : '';
872 // Revision text size
873 $size = $row->ar_len
;
874 if ( !is_null( $size ) ) {
875 $revTextSize = Linker
::formatRevisionSize( $size );
879 $comment = Linker
::revComment( $rev );
883 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
889 $attribs['class'] = implode( ' ', $classes );
892 $revisionRow = $this->msg( 'undelete-revision-row2' )
905 return Xml
::tags( 'li', $attribs, $revisionRow ) . "\n";
908 private function formatFileRow( $row ) {
909 $file = ArchivedFile
::newFromRow( $row );
910 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
911 $user = $this->getUser();
914 if ( $this->mCanView
&& $row->fa_storage_key
) {
915 if ( $this->mAllowed
) {
916 $checkBox = Xml
::check( 'fileid' . $row->fa_id
);
918 $key = urlencode( $row->fa_storage_key
);
919 $pageLink = $this->getFileLink( $file, $this->getPageTitle(), $ts, $key );
921 $pageLink = $this->getLanguage()->userTimeAndDate( $ts, $user );
923 $userLink = $this->getFileUser( $file );
924 $data = $this->msg( 'widthheight' )->numParams( $row->fa_width
, $row->fa_height
)->text();
925 $bytes = $this->msg( 'parentheses' )
926 ->rawParams( $this->msg( 'nbytes' )->numParams( $row->fa_size
)->text() )
928 $data = htmlspecialchars( $data . ' ' . $bytes );
929 $comment = $this->getFileComment( $file );
931 // Add show/hide deletion links if available
932 $canHide = $this->isAllowed( 'deleterevision' );
933 if ( $canHide ||
( $file->getVisibility() && $this->isAllowed( 'deletedhistory' ) ) ) {
934 if ( !$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
935 // Revision was hidden from sysops
936 $revdlink = Linker
::revDeleteLinkDisabled( $canHide );
939 'type' => 'filearchive',
940 'target' => $this->mTargetObj
->getPrefixedDBkey(),
943 $revdlink = Linker
::revDeleteLink( $query,
944 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
950 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
954 * Fetch revision text link if it's available to all users
956 * @param Revision $rev
957 * @param Title $titleObj
958 * @param string $ts Timestamp
961 function getPageLink( $rev, $titleObj, $ts ) {
962 $user = $this->getUser();
963 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
965 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
966 return '<span class="history-deleted">' . $time . '</span>';
969 $link = $this->getLinkRenderer()->makeKnownLink(
974 'target' => $this->mTargetObj
->getPrefixedText(),
979 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
980 $link = '<span class="history-deleted">' . $link . '</span>';
987 * Fetch image view link if it's available to all users
989 * @param File|ArchivedFile $file
990 * @param Title $titleObj
991 * @param string $ts A timestamp
992 * @param string $key A storage key
994 * @return string HTML fragment
996 function getFileLink( $file, $titleObj, $ts, $key ) {
997 $user = $this->getUser();
998 $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
1000 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
1001 return '<span class="history-deleted">' . $time . '</span>';
1004 $link = $this->getLinkRenderer()->makeKnownLink(
1009 'target' => $this->mTargetObj
->getPrefixedText(),
1011 'token' => $user->getEditToken( $key )
1015 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
1016 $link = '<span class="history-deleted">' . $link . '</span>';
1023 * Fetch file's user id if it's available to this user
1025 * @param File|ArchivedFile $file
1026 * @return string HTML fragment
1028 function getFileUser( $file ) {
1029 if ( !$file->userCan( File
::DELETED_USER
, $this->getUser() ) ) {
1030 return '<span class="history-deleted">' .
1031 $this->msg( 'rev-deleted-user' )->escaped() .
1035 $link = Linker
::userLink( $file->getRawUser(), $file->getRawUserText() ) .
1036 Linker
::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1038 if ( $file->isDeleted( File
::DELETED_USER
) ) {
1039 $link = '<span class="history-deleted">' . $link . '</span>';
1046 * Fetch file upload comment if it's available to this user
1048 * @param File|ArchivedFile $file
1049 * @return string HTML fragment
1051 function getFileComment( $file ) {
1052 if ( !$file->userCan( File
::DELETED_COMMENT
, $this->getUser() ) ) {
1053 return '<span class="history-deleted"><span class="comment">' .
1054 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></span>';
1057 $link = Linker
::commentBlock( $file->getRawDescription() );
1059 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
1060 $link = '<span class="history-deleted">' . $link . '</span>';
1066 function undelete() {
1067 if ( $this->getConfig()->get( 'UploadMaintenance' )
1068 && $this->mTargetObj
->getNamespace() == NS_FILE
1070 throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
1073 $this->checkReadOnly();
1075 $out = $this->getOutput();
1076 $archive = new PageArchive( $this->mTargetObj
, $this->getConfig() );
1077 Hooks
::run( 'UndeleteForm::undelete', [ &$archive, $this->mTargetObj
] );
1078 $ok = $archive->undelete(
1079 $this->mTargetTimestamp
,
1081 $this->mFileVersions
,
1086 if ( is_array( $ok ) ) {
1087 if ( $ok[1] ) { // Undeleted file count
1088 Hooks
::run( 'FileUndeleteComplete', [
1089 $this->mTargetObj
, $this->mFileVersions
,
1090 $this->getUser(), $this->mComment
] );
1093 $link = $this->getLinkRenderer()->makeKnownLink( $this->mTargetObj
);
1094 $out->addHTML( $this->msg( 'undeletedpage' )->rawParams( $link )->parse() );
1096 $out->setPageTitle( $this->msg( 'undelete-error' ) );
1099 // Show revision undeletion warnings and errors
1100 $status = $archive->getRevisionStatus();
1101 if ( $status && !$status->isGood() ) {
1102 $out->addWikiText( '<div class="error" id="mw-error-cannotundelete">' .
1103 $status->getWikiText(
1110 // Show file undeletion warnings and errors
1111 $status = $archive->getFileStatus();
1112 if ( $status && !$status->isGood() ) {
1113 $out->addWikiText( '<div class="error">' .
1114 $status->getWikiText(
1115 'undelete-error-short',
1116 'undelete-error-long'
1123 * Return an array of subpages beginning with $search that this special page will accept.
1125 * @param string $search Prefix to search for
1126 * @param int $limit Maximum number of results to return (usually 10)
1127 * @param int $offset Number of results to skip (usually 0)
1128 * @return string[] Matching subpages
1130 public function prefixSearchSubpages( $search, $limit, $offset ) {
1131 return $this->prefixSearchString( $search, $limit, $offset );
1134 protected function getGroupName() {