* (bug 32512) Include 'associated namespace' checkbox on Special:Contributions
[lhc/web/wiklou.git] / includes / specials / SpecialUndelete.php
index 246a666..68e35b7 100644 (file)
@@ -116,7 +116,7 @@ class PageArchive {
                $res = $dbr->select( 'archive',
                        array(
                                'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text',
-                               'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id'
+                               'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1'
                        ),
                        array( 'ar_namespace' => $this->title->getNamespace(),
                                   'ar_title' => $this->title->getDBkey() ),
@@ -187,10 +187,12 @@ class PageArchive {
                                'ar_flags',
                                'ar_text_id',
                                'ar_deleted',
-                               'ar_len' ),
+                               'ar_len',
+                               'ar_sha1',
+                       ),
                        array( 'ar_namespace' => $this->title->getNamespace(),
-                                  'ar_title' => $this->title->getDBkey(),
-                                  'ar_timestamp' => $dbr->timestamp( $timestamp ) ),
+                                       'ar_title' => $this->title->getDBkey(),
+                                       'ar_timestamp' => $dbr->timestamp( $timestamp ) ),
                        __METHOD__ );
                if( $row ) {
                        return Revision::newFromArchiveRow( $row, array( 'page' => $this->title->getArticleId() ) );
@@ -398,7 +400,11 @@ class PageArchive {
                $dbw = wfGetDB( DB_MASTER );
 
                # Does this page already exist? We'll have to update it...
-               $article = new Article( $this->title );
+               $article = WikiPage::factory( $this->title );
+               # Load latest data for the current page (bug 31179)
+               $article->loadPageData( 'fromdbmaster' );
+               $oldcountable = $article->isCountable();
+
                $options = 'FOR UPDATE'; // lock page
                $page = $dbw->selectRow( 'page',
                        array( 'page_id', 'page_latest' ),
@@ -456,7 +462,8 @@ class PageArchive {
                                'ar_text_id',
                                'ar_deleted',
                                'ar_page_id',
-                               'ar_len' ),
+                               'ar_len',
+                               'ar_sha1' ),
                        /* WHERE */ array(
                                'ar_namespace' => $this->title->getNamespace(),
                                'ar_title'     => $this->title->getDBkey(),
@@ -532,7 +539,6 @@ class PageArchive {
                }
 
                $created = (bool)$newid;
-               $oldcountable = $article->isCountable();
 
                // Attach the latest revision to the page...
                $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId );
@@ -577,12 +583,20 @@ class SpecialUndelete extends SpecialPage {
                parent::__construct( 'Undelete', 'deletedhistory' );
        }
 
-       function loadRequest() {
+       function loadRequest( $par ) {
                $request = $this->getRequest();
                $user = $this->getUser();
 
                $this->mAction = $request->getVal( 'action' );
-               $this->mTarget = $request->getVal( 'target' );
+               if ( $par !== null && $par !== '' ) {
+                       $this->mTarget = $par;
+               } else {
+                       $this->mTarget = $request->getVal( 'target' );
+               }
+               $this->mTargetObj = null;
+               if ( $this->mTarget !== null && $this->mTarget !== '' ) {
+                       $this->mTargetObj = Title::newFromURL( $this->mTarget );
+               }
                $this->mSearchPrefix = $request->getText( 'prefix' );
                $time = $request->getVal( 'timestamp' );
                $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
@@ -594,6 +608,7 @@ class SpecialUndelete extends SpecialPage {
                $this->mInvert = $request->getCheck( 'invert' ) && $posted;
                $this->mPreview = $request->getCheck( 'preview' ) && $posted;
                $this->mDiff = $request->getCheck( 'diff' );
+               $this->mDiffOnly = $request->getBool( 'diffonly', $this->getUser()->getOption( 'diffonly' ) );
                $this->mComment = $request->getText( 'wpComment' );
                $this->mUnsuppress = $request->getVal( 'wpUnsuppress' ) && $user->isAllowed( 'suppressrevision' );
                $this->mToken = $request->getVal( 'token' );
@@ -604,6 +619,7 @@ class SpecialUndelete extends SpecialPage {
                } elseif ( $user->isAllowed( 'deletedtext' ) ) {
                        $this->mAllowed = false; // user cannot restore
                        $this->mCanView = true; // user can view content
+                       $this->mRestore = false;
                } else { // user can only view the list of revisions
                        $this->mAllowed = false;
                        $this->mCanView = false;
@@ -630,96 +646,65 @@ class SpecialUndelete extends SpecialPage {
        }
 
        function execute( $par ) {
-               $this->setHeaders();
-               if ( !$this->userCanExecute( $this->getUser() ) ) {
-                       $this->displayRestrictionError();
-                       return;
-               }
-
-               if ( $this->getUser()->isBlocked() ) {
-                       throw new UserBlockedError( $this->getUser()->getBlock() );
-               }
+               $this->checkPermissions();
+               $user = $this->getUser();
 
+               $this->setHeaders();
                $this->outputHeader();
 
-               $this->loadRequest();
+               $this->loadRequest( $par );
 
                $out = $this->getOutput();
 
-               if ( $this->mAllowed ) {
-                       $out->setPageTitle( wfMsg( 'undeletepage' ) );
-               } else {
-                       $out->setPageTitle( wfMsg( 'viewdeletedpage' ) );
-               }
-
-               if( $par != '' ) {
-                       $this->mTarget = $par;
-               }
-               if ( $this->mTarget !== '' ) {
-                       $this->mTargetObj = Title::newFromURL( $this->mTarget );
-                       $this->getSkin()->setRelevantTitle( $this->mTargetObj );
-               } else {
-                       $this->mTargetObj = null;
-               }
+               if ( is_null( $this->mTargetObj ) ) {
+                       $out->addWikiMsg( 'undelete-header' );
 
-               if( is_null( $this->mTargetObj ) ) {
                        # Not all users can just browse every deleted page from the list
-                       if( $this->getUser()->isAllowed( 'browsearchive' ) ) {
+                       if ( $user->isAllowed( 'browsearchive' ) ) {
                                $this->showSearchForm();
-
-                               # List undeletable articles
-                               if( $this->mSearchPrefix ) {
-                                       $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix );
-                                       $this->showList( $result );
-                               }
-                       } else {
-                               $out->addWikiMsg( 'undelete-header' );
                        }
                        return;
                }
-               if( $this->mTimestamp !== '' ) {
-                       return $this->showRevision( $this->mTimestamp );
+
+               if ( $this->mAllowed ) {
+                       $out->setPageTitle( $this->msg( 'undeletepage' ) );
+               } else {
+                       $out->setPageTitle( $this->msg( 'viewdeletedpage' ) );
                }
-               if( $this->mFilename !== null ) {
+
+               $this->getSkin()->setRelevantTitle( $this->mTargetObj );
+
+               if ( $this->mTimestamp !== '' ) {
+                       $this->showRevision( $this->mTimestamp );
+               } elseif ( $this->mFilename !== null ) {
                        $file = new ArchivedFile( $this->mTargetObj, '', $this->mFilename );
                        // Check if user is allowed to see this file
                        if ( !$file->exists() ) {
                                $out->addWikiMsg( 'filedelete-nofile', $this->mFilename );
-                               return;
-                       } elseif( !$file->userCan( File::DELETED_FILE ) ) {
+                       } elseif ( !$file->userCan( File::DELETED_FILE, $user ) ) {
                                if( $file->isDeleted( File::DELETED_RESTRICTED ) ) {
-                                       $out->permissionRequired( 'suppressrevision' );
+                                       throw new PermissionsError( 'suppressrevision' );
                                } else {
-                                       $out->permissionRequired( 'deletedtext' );
+                                       throw new PermissionsError( 'deletedtext' );
                                }
-                               return false;
-                       } elseif ( !$this->getUser()->matchEditToken( $this->mToken, $this->mFilename ) ) {
+                       } elseif ( !$user->matchEditToken( $this->mToken, $this->mFilename ) ) {
                                $this->showFileConfirmationForm( $this->mFilename );
-                               return false;
                        } else {
-                               return $this->showFile( $this->mFilename );
+                               $this->showFile( $this->mFilename );
                        }
+               } elseif ( $this->mRestore && $this->mAction == 'submit' ) {
+                       $this->undelete();
+               } else {
+                       $this->showHistory();
                }
-               if( $this->mRestore && $this->mAction == 'submit' ) {
-                       global $wgUploadMaintenance;
-                       if( $wgUploadMaintenance && $this->mTargetObj && $this->mTargetObj->getNamespace() == NS_FILE ) {
-                               $out->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n", array( 'filedelete-maintenance' ) );
-                               return;
-                       }
-                       return $this->undelete();
-               }
-               if( $this->mInvert && $this->mAction == 'submit' ) {
-                       return $this->showHistory();
-               }
-               return $this->showHistory();
        }
 
        function showSearchForm() {
                global $wgScript;
 
-               $this->getOutput()->addWikiMsg( 'undelete-header' );
-
-               $this->getOutput()->addHTML(
+               $out = $this->getOutput();
+               $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
+               $out->addHTML(
                        Xml::openElement( 'form', array(
                                'method' => 'get',
                                'action' => $wgScript ) ) .
@@ -733,6 +718,12 @@ class SpecialUndelete extends SpecialPage {
                        Xml::closeElement( 'fieldset' ) .
                        Xml::closeElement( 'form' )
                );
+
+               # List undeletable articles
+               if( $this->mSearchPrefix ) {
+                       $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix );
+                       $this->showList( $result );
+               }
        }
 
        /**
@@ -749,7 +740,7 @@ class SpecialUndelete extends SpecialPage {
                        return;
                }
 
-               $out->addWikiMsg( 'undeletepagetext', $this->getLang()->formatNum( $result->numRows() ) );
+               $out->addWikiMsg( 'undeletepagetext', $this->getLanguage()->formatNum( $result->numRows() ) );
 
                $undelete = $this->getTitle();
                $out->addHTML( "<ul>\n" );
@@ -763,7 +754,7 @@ class SpecialUndelete extends SpecialPage {
                        );
                        $revs = wfMsgExt( 'undeleterevisions',
                                array( 'parseinline' ),
-                               $this->getLang()->formatNum( $row->count ) );
+                               $this->getLanguage()->formatNum( $row->count ) );
                        $out->addHTML( "<li>{$link} ({$revs})</li>\n" );
                }
                $result->free();
@@ -773,8 +764,6 @@ class SpecialUndelete extends SpecialPage {
        }
 
        private function showRevision( $timestamp ) {
-               $out = $this->getOutput();
-
                if( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
                        return 0;
                }
@@ -783,13 +772,16 @@ class SpecialUndelete extends SpecialPage {
                wfRunHooks( 'UndeleteForm::showRevision', array( &$archive, $this->mTargetObj ) );
                $rev = $archive->getRevision( $timestamp );
 
+               $out = $this->getOutput();
+               $user = $this->getUser();
+
                if( !$rev ) {
                        $out->addWikiMsg( 'undeleterevision-missing' );
                        return;
                }
 
                if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
-                       if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
+                       if( !$rev->userCan( Revision::DELETED_TEXT, $user ) ) {
                                $out->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-permission' );
                                return;
                        } else {
@@ -799,13 +791,11 @@ class SpecialUndelete extends SpecialPage {
                        }
                }
 
-               $out->setPageTitle( wfMsg( 'undeletepage' ) );
-
                if( $this->mDiff ) {
                        $previousRev = $archive->getPreviousRevision( $timestamp );
                        if( $previousRev ) {
                                $this->showDiff( $previousRev, $rev );
-                               if( $this->getUser()->getOption( 'diffonly' ) ) {
+                               if( $this->mDiffOnly ) {
                                        return;
                                } else {
                                        $out->addHTML( '<hr />' );
@@ -822,10 +812,10 @@ class SpecialUndelete extends SpecialPage {
 
                // date and time are separate parameters to facilitate localisation.
                // $time is kept for backward compat reasons.
-               $time = $this->getLang()->timeAndDate( $timestamp, true );
-               $d = $this->getLang()->date( $timestamp, true );
-               $t = $this->getLang()->time( $timestamp, true );
-               $user = Linker::revUserTools( $rev );
+               $time = $this->getLanguage()->timeAndDate( $timestamp, true );
+               $d = $this->getLanguage()->date( $timestamp, true );
+               $t = $this->getLanguage()->time( $timestamp, true );
+               $userLink = Linker::revUserTools( $rev );
 
                if( $this->mPreview ) {
                        $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
@@ -836,14 +826,14 @@ class SpecialUndelete extends SpecialPage {
 
                // Revision delete links
                if ( !$this->mDiff ) {
-                       $revdel = Linker::getRevDeleteLink( $this->getUser(), $rev, $this->mTargetObj );
+                       $revdel = Linker::getRevDeleteLink( $user, $rev, $this->mTargetObj );
                        if ( $revdel ) {
                                $out->addHTML( "$revdel " );
                        }
                }
 
                $out->addHTML( wfMessage( 'undelete-revision' )->rawParams( $link )->params(
-                       $time )->rawParams( $user )->params( $d, $t )->parse() . '</div>' );
+                       $time )->rawParams( $userLink )->params( $d, $t )->parse() . '</div>' );
                wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
 
                if( $this->mPreview ) {
@@ -851,15 +841,15 @@ class SpecialUndelete extends SpecialPage {
                        $popts = $out->parserOptions();
                        $popts->setEditSection( false );
                        $out->parserOptions( $popts );
-                       $out->addWikiTextTitleTidy( $rev->getText( Revision::FOR_THIS_USER ), $this->mTargetObj, true );
+                       $out->addWikiTextTitleTidy( $rev->getText( Revision::FOR_THIS_USER, $user ), $this->mTargetObj, true );
                }
 
                $out->addHTML(
                        Xml::element( 'textarea', array(
                                        'readonly' => 'readonly',
-                                       'cols' => intval( $this->getUser()->getOption( 'cols' ) ),
-                                       'rows' => intval( $this->getUser()->getOption( 'rows' ) ) ),
-                               $rev->getText( Revision::FOR_THIS_USER ) . "\n" ) .
+                                       'cols' => intval( $user->getOption( 'cols' ) ),
+                                       'rows' => intval( $user->getOption( 'rows' ) ) ),
+                               $rev->getText( Revision::FOR_THIS_USER, $user ) . "\n" ) .
                        Xml::openElement( 'div' ) .
                        Xml::openElement( 'form', array(
                                'method' => 'post',
@@ -875,7 +865,7 @@ class SpecialUndelete extends SpecialPage {
                        Xml::element( 'input', array(
                                'type' => 'hidden',
                                'name' => 'wpEditToken',
-                               'value' => $this->getUser()->editToken() ) ) .
+                               'value' => $user->getEditToken() ) ) .
                        Xml::element( 'input', array(
                                'type' => 'submit',
                                'name' => 'preview',
@@ -897,7 +887,7 @@ class SpecialUndelete extends SpecialPage {
         * @return String: HTML
         */
        function showDiff( $previousRev, $currentRev ) {
-               $diffEngine = new DifferenceEngine( $previousRev->getTitle() );
+               $diffEngine = new DifferenceEngine( $this->getContext() );
                $diffEngine->showDiffStyle();
                $this->getOutput()->addHTML(
                        "<div>" .
@@ -950,9 +940,9 @@ class SpecialUndelete extends SpecialPage {
                                        wfMsgExt(
                                                'revisionasof',
                                                array( 'escape' ),
-                                               $this->getLang()->timeanddate( $rev->getTimestamp(), true ),
-                                               $this->getLang()->date( $rev->getTimestamp(), true ),
-                                               $this->getLang()->time( $rev->getTimestamp(), true )
+                                               $this->getLanguage()->timeanddate( $rev->getTimestamp(), true ),
+                                               $this->getLanguage()->date( $rev->getTimestamp(), true ),
+                                               $this->getLanguage()->time( $rev->getTimestamp(), true )
                                        ),
                                        array(),
                                        $targetQuery
@@ -973,15 +963,15 @@ class SpecialUndelete extends SpecialPage {
                $file = new ArchivedFile( $this->mTargetObj, '', $this->mFilename );
                $this->getOutput()->addWikiMsg( 'undelete-show-file-confirm',
                        $this->mTargetObj->getText(),
-                       $this->getLang()->date( $file->getTimestamp() ),
-                       $this->getLang()->time( $file->getTimestamp() ) );
+                       $this->getLanguage()->date( $file->getTimestamp() ),
+                       $this->getLanguage()->time( $file->getTimestamp() ) );
                $this->getOutput()->addHTML(
                        Xml::openElement( 'form', array(
                                'method' => 'POST',
                                'action' => $this->getTitle()->getLocalURL(
                                        'target=' . urlencode( $this->mTarget ) .
                                        '&file=' . urlencode( $key ) .
-                                       '&token=' . urlencode( $this->getUser()->editToken( $key ) ) )
+                                       '&token=' . urlencode( $this->getUser()->getEditToken( $key ) ) )
                                )
                        ) .
                        Xml::submitButton( wfMsg( 'undelete-show-file-submit' ) ) .
@@ -1013,9 +1003,6 @@ class SpecialUndelete extends SpecialPage {
                $out = $this->getOutput();
                if( $this->mAllowed ) {
                        $out->addModules( 'mediawiki.special.undelete' );
-                       $out->setPageTitle( wfMsg( 'undeletepage' ) );
-               } else {
-                       $out->setPageTitle( wfMsg( 'viewdeletedpage' ) );
                }
                $out->wrapWikiMsg(
                        "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
@@ -1076,11 +1063,11 @@ class SpecialUndelete extends SpecialPage {
 
                # Show relevant lines from the deletion log:
                $out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) . "\n" );
-               LogEventsList::showLogExtract( $out, 'delete', $this->mTargetObj->getPrefixedText() );
+               LogEventsList::showLogExtract( $out, 'delete', $this->mTargetObj );
                # Show relevant lines from the suppression log:
                if( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
                        $out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'suppress' ) ) . "\n" );
-                       LogEventsList::showLogExtract( $out, 'suppress', $this->mTargetObj->getPrefixedText() );
+                       LogEventsList::showLogExtract( $out, 'suppress', $this->mTargetObj );
                }
 
                if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
@@ -1159,7 +1146,7 @@ class SpecialUndelete extends SpecialPage {
                if ( $this->mAllowed ) {
                        # Slip in the hidden controls here
                        $misc  = Html::hidden( 'target', $this->mTarget );
-                       $misc .= Html::hidden( 'wpEditToken', $this->getUser()->editToken() );
+                       $misc .= Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
                        $misc .= Xml::closeElement( 'form' );
                        $out->addHTML( $misc );
                }
@@ -1190,8 +1177,8 @@ class SpecialUndelete extends SpecialPage {
                if( $this->mCanView ) {
                        $titleObj = $this->getTitle();
                        # Last link
-                       if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
-                               $pageLink = htmlspecialchars( $this->getLang()->timeanddate( $ts, true ) );
+                       if( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
+                               $pageLink = htmlspecialchars( $this->getLanguage()->timeanddate( $ts, true ) );
                                $last = wfMsgHtml( 'diff' );
                        } elseif( $remaining > 0 || ( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
                                $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
@@ -1210,7 +1197,7 @@ class SpecialUndelete extends SpecialPage {
                                $last = wfMsgHtml( 'diff' );
                        }
                } else {
-                       $pageLink = htmlspecialchars( $this->getLang()->timeanddate( $ts, true ) );
+                       $pageLink = htmlspecialchars( $this->getLanguage()->timeanddate( $ts, true ) );
                        $last = wfMsgHtml( 'diff' );
                }
                // User links
@@ -1237,23 +1224,24 @@ class SpecialUndelete extends SpecialPage {
                        $pageLink = $this->getFileLink( $file, $this->getTitle(), $ts, $key );
                } else {
                        $checkBox = '';
-                       $pageLink = $this->getLang()->timeanddate( $ts, true );
+                       $pageLink = $this->getLanguage()->timeanddate( $ts, true );
                }
                $userLink = $this->getFileUser( $file );
                $data =
                        wfMsg( 'widthheight',
-                               $this->getLang()->formatNum( $row->fa_width ),
-                               $this->getLang()->formatNum( $row->fa_height ) ) .
+                               $this->getLanguage()->formatNum( $row->fa_width ),
+                               $this->getLanguage()->formatNum( $row->fa_height ) ) .
                        ' (' .
-                       wfMsg( 'nbytes', $this->getLang()->formatNum( $row->fa_size ) ) .
+                       wfMsg( 'nbytes', $this->getLanguage()->formatNum( $row->fa_size ) ) .
                        ')';
                $data = htmlspecialchars( $data );
                $comment = $this->getFileComment( $file );
 
                // Add show/hide deletion links if available
-               $canHide = $this->getUser()->isAllowed( 'deleterevision' );
-               if( $canHide || ( $file->getVisibility() && $this->getUser()->isAllowed( 'deletedhistory' ) ) ) {
-                       if( !$file->userCan( File::DELETED_RESTRICTED ) ) {
+               $user = $this->getUser();
+               $canHide = $user->isAllowed( 'deleterevision' );
+               if( $canHide || ( $file->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
+                       if( !$file->userCan( File::DELETED_RESTRICTED, $user ) ) {
                                $revdlink = Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
                        } else {
                                $query = array(
@@ -1278,9 +1266,9 @@ class SpecialUndelete extends SpecialPage {
         * @return string
         */
        function getPageLink( $rev, $titleObj, $ts ) {
-               $time = htmlspecialchars( $this->getLang()->timeanddate( $ts, true ) );
+               $time = htmlspecialchars( $this->getLanguage()->timeanddate( $ts, true ) );
 
-               if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
+               if( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
                        return '<span class="history-deleted">' . $time . '</span>';
                } else {
                        $link = Linker::linkKnown(
@@ -1306,17 +1294,17 @@ class SpecialUndelete extends SpecialPage {
         * @return String: HTML fragment
         */
        function getFileLink( $file, $titleObj, $ts, $key ) {
-               if( !$file->userCan( File::DELETED_FILE ) ) {
-                       return '<span class="history-deleted">' . $this->getLang()->timeanddate( $ts, true ) . '</span>';
+               if( !$file->userCan( File::DELETED_FILE, $this->getUser() ) ) {
+                       return '<span class="history-deleted">' . $this->getLanguage()->timeanddate( $ts, true ) . '</span>';
                } else {
                        $link = Linker::linkKnown(
                                $titleObj,
-                               $this->getLang()->timeanddate( $ts, true ),
+                               $this->getLanguage()->timeanddate( $ts, true ),
                                array(),
                                array(
                                        'target' => $this->mTargetObj->getPrefixedText(),
                                        'file' => $key,
-                                       'token' => $this->getUser()->editToken( $key )
+                                       'token' => $this->getUser()->getEditToken( $key )
                                )
                        );
                        if( $file->isDeleted( File::DELETED_FILE ) ) {
@@ -1333,7 +1321,7 @@ class SpecialUndelete extends SpecialPage {
         * @return String: HTML fragment
         */
        function getFileUser( $file ) {
-               if( !$file->userCan( File::DELETED_USER ) ) {
+               if( !$file->userCan( File::DELETED_USER, $this->getUser() ) ) {
                        return '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
                } else {
                        $link = Linker::userLink( $file->getRawUser(), $file->getRawUserText() ) .
@@ -1352,7 +1340,7 @@ class SpecialUndelete extends SpecialPage {
         * @return String: HTML fragment
         */
        function getFileComment( $file ) {
-               if( !$file->userCan( File::DELETED_COMMENT ) ) {
+               if( !$file->userCan( File::DELETED_COMMENT, $this->getUser() ) ) {
                        return '<span class="history-deleted"><span class="comment">' .
                                wfMsgHtml( 'rev-deleted-comment' ) . '</span></span>';
                } else {
@@ -1365,41 +1353,44 @@ class SpecialUndelete extends SpecialPage {
        }
 
        function undelete() {
+               global $wgUploadMaintenance;
+
+               if ( $wgUploadMaintenance && $this->mTargetObj->getNamespace() == NS_FILE ) {
+                       throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
+               }
+
                if ( wfReadOnly() ) {
                        throw new ReadOnlyError;
                }
 
-               if( !is_null( $this->mTargetObj ) ) {
-                       $archive = new PageArchive( $this->mTargetObj );
-                       wfRunHooks( 'UndeleteForm::undelete', array( &$archive, $this->mTargetObj ) );
-                       $ok = $archive->undelete(
-                               $this->mTargetTimestamp,
-                               $this->mComment,
-                               $this->mFileVersions,
-                               $this->mUnsuppress );
-
-                       if( is_array( $ok ) ) {
-                               if ( $ok[1] ) { // Undeleted file count
-                                       wfRunHooks( 'FileUndeleteComplete', array(
-                                               $this->mTargetObj, $this->mFileVersions,
-                                               $this->getUser(), $this->mComment ) );
-                               }
-
-                               $link = Linker::linkKnown( $this->mTargetObj );
-                               $this->getOutput()->addHTML( wfMessage( 'undeletedpage' )->rawParams( $link )->parse() );
-                       } else {
-                               $this->getOutput()->showFatalError( wfMsg( 'cannotundelete' ) );
-                               $this->getOutput()->addWikiMsg( 'undeleterevdel' );
+               $out = $this->getOutput();
+               $archive = new PageArchive( $this->mTargetObj );
+               wfRunHooks( 'UndeleteForm::undelete', array( &$archive, $this->mTargetObj ) );
+               $ok = $archive->undelete(
+                       $this->mTargetTimestamp,
+                       $this->mComment,
+                       $this->mFileVersions,
+                       $this->mUnsuppress );
+
+               if( is_array( $ok ) ) {
+                       if ( $ok[1] ) { // Undeleted file count
+                               wfRunHooks( 'FileUndeleteComplete', array(
+                                       $this->mTargetObj, $this->mFileVersions,
+                                       $this->getUser(), $this->mComment ) );
                        }
 
-                       // Show file deletion warnings and errors
-                       $status = $archive->getFileStatus();
-                       if( $status && !$status->isGood() ) {
-                               $this->getOutput()->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
-                       }
+                       $link = Linker::linkKnown( $this->mTargetObj );
+                       $out->addHTML( $this->msg( 'undeletedpage' )->rawParams( $link )->parse() );
                } else {
-                       $this->getOutput()->showFatalError( wfMsg( 'cannotundelete' ) );
+                       $out->setPageTitle( $this->msg( 'undelete-error' ) );
+                       $out->addWikiMsg( 'cannotundelete' );
+                       $out->addWikiMsg( 'undeleterevdel' );
+               }
+
+               // Show file deletion warnings and errors
+               $status = $archive->getFileStatus();
+               if( $status && !$status->isGood() ) {
+                       $out->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
                }
-               return false;
        }
 }