Update formatting and docs
authorSiebrand Mazeland <s.mazeland@xs4all.nl>
Mon, 1 Apr 2013 21:28:27 +0000 (23:28 +0200)
committerSiebrand Mazeland <s.mazeland@xs4all.nl>
Sun, 7 Apr 2013 15:08:08 +0000 (17:08 +0200)
Also remove some unneeded else{} statements and reverse if/else if that
reduces indentation.

Change-Id: I1f7bd26119850fc944fbe84ae78bdd95cafc7bbb

includes/specials/SpecialUndelete.php

index ed550a0..0e8cf58 100644 (file)
@@ -27,7 +27,6 @@
  * @ingroup SpecialPage
  */
 class PageArchive {
-
        /**
         * @var Title
         */
@@ -44,7 +43,7 @@ class PageArchive {
        protected $revisionStatus;
 
        function __construct( $title ) {
-               if( is_null( $title ) ) {
+               if ( is_null( $title ) ) {
                        throw new MWException( __METHOD__ . ' given a null title.' );
                }
                $this->title = $title;
@@ -67,14 +66,14 @@ class PageArchive {
         * given title prefix.
         * Returns result wrapper with (ar_namespace, ar_title, count) fields.
         *
-        * @param string $prefix title prefix
+        * @param string $prefix Title prefix
         * @return ResultWrapper
         */
        public static function listPagesByPrefix( $prefix ) {
                $dbr = wfGetDB( DB_SLAVE );
 
                $title = Title::newFromText( $prefix );
-               if( $title ) {
+               if ( $title ) {
                        $ns = $title->getNamespace();
                        $prefix = $title->getDBkey();
                } else {
@@ -82,36 +81,36 @@ class PageArchive {
                        // @todo handle bare namespace names cleanly?
                        $ns = 0;
                }
+
                $conds = array(
                        'ar_namespace' => $ns,
                        'ar_title' . $dbr->buildLike( $prefix, $dbr->anyString() ),
                );
+
                return self::listPages( $dbr, $conds );
        }
 
        /**
-        * @param $dbr DatabaseBase
-        * @param $condition
+        * @param DatabaseBase $dbr
+        * @param string|array $condition
         * @return bool|ResultWrapper
         */
        protected static function listPages( $dbr, $condition ) {
-               return $dbr->resultObject(
-                       $dbr->select(
-                               array( 'archive' ),
-                               array(
-                                       'ar_namespace',
-                                       'ar_title',
-                                       'count' => 'COUNT(*)'
-                               ),
-                               $condition,
-                               __METHOD__,
-                               array(
-                                       'GROUP BY' => array( 'ar_namespace', 'ar_title' ),
-                                       'ORDER BY' => array( 'ar_namespace', 'ar_title' ),
-                                       'LIMIT' => 100,
-                               )
+               return $dbr->resultObject( $dbr->select(
+                       array( 'archive' ),
+                       array(
+                               'ar_namespace',
+                               'ar_title',
+                               'count' => 'COUNT(*)'
+                       ),
+                       $condition,
+                       __METHOD__,
+                       array(
+                               'GROUP BY' => array( 'ar_namespace', 'ar_title' ),
+                               'ORDER BY' => array( 'ar_namespace', 'ar_title' ),
+                               'LIMIT' => 100,
                        )
-               );
+               ) );
        }
 
        /**
@@ -141,8 +140,8 @@ class PageArchive {
                                'ar_title' => $this->title->getDBkey() ),
                        __METHOD__,
                        array( 'ORDER BY' => 'ar_timestamp DESC' ) );
-               $ret = $dbr->resultObject( $res );
-               return $ret;
+
+               return $dbr->resultObject( $res );
        }
 
        /**
@@ -154,26 +153,28 @@ class PageArchive {
         * @todo Does this belong in Image for fuller encapsulation?
         */
        function listFiles() {
-               if( $this->title->getNamespace() == NS_FILE ) {
-                       $dbr = wfGetDB( DB_SLAVE );
-                       $res = $dbr->select(
-                               'filearchive',
-                               ArchivedFile::selectFields(),
-                               array( 'fa_name' => $this->title->getDBkey() ),
-                               __METHOD__,
-                               array( 'ORDER BY' => 'fa_timestamp DESC' ) );
-                       $ret = $dbr->resultObject( $res );
-                       return $ret;
+               if ( $this->title->getNamespace() != NS_FILE ) {
+                       return null;
                }
-               return null;
+
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select(
+                       'filearchive',
+                       ArchivedFile::selectFields(),
+                       array( 'fa_name' => $this->title->getDBkey() ),
+                       __METHOD__,
+                       array( 'ORDER BY' => 'fa_timestamp DESC' )
+               );
+
+               return $dbr->resultObject( $res );
        }
 
        /**
         * Return a Revision object containing data for the deleted revision.
         * Note that the result *may* or *may not* have a null page ID.
         *
-        * @param $timestamp String
-        * @return Revision
+        * @param string $timestamp
+        * @return Revision|null
         */
        function getRevision( $timestamp ) {
                global $wgContentHandlerUseDB;
@@ -203,14 +204,15 @@ class PageArchive {
                $row = $dbr->selectRow( 'archive',
                        $fields,
                        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 ) {
+
+               if ( $row ) {
                        return Revision::newFromArchiveRow( $row, array( 'title' => $this->title ) );
-               } else {
-                       return null;
                }
+
+               return null;
        }
 
        /**
@@ -220,8 +222,8 @@ class PageArchive {
         * May produce unexpected results in case of history merges or other
         * unusual time issues.
         *
-        * @param $timestamp String
-        * @return Revision or null
+        * @param string $timestamp
+        * @return Revision|null Null when there is no previous revision
         */
        function getPreviousRevision( $timestamp ) {
                $dbr = wfGetDB( DB_SLAVE );
@@ -246,7 +248,7 @@ class PageArchive {
                                'page_title' => $this->title->getDBkey(),
                                'page_id = rev_page',
                                'rev_timestamp < ' .
-                                               $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
+                                       $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
                        __METHOD__,
                        array(
                                'ORDER BY' => 'rev_timestamp DESC',
@@ -254,38 +256,39 @@ class PageArchive {
                $prevLive = $row ? wfTimestamp( TS_MW, $row->rev_timestamp ) : false;
                $prevLiveId = $row ? intval( $row->rev_id ) : null;
 
-               if( $prevLive && $prevLive > $prevDeleted ) {
+               if ( $prevLive && $prevLive > $prevDeleted ) {
                        // Most prior revision was live
                        return Revision::newFromId( $prevLiveId );
-               } elseif( $prevDeleted ) {
+               } elseif ( $prevDeleted ) {
                        // Most prior revision was deleted
                        return $this->getRevision( $prevDeleted );
-               } else {
-                       // No prior revision on this page.
-                       return null;
                }
+
+               // No prior revision on this page.
+               return null;
        }
 
        /**
         * Get the text from an archive row containing ar_text, ar_flags and ar_text_id
         *
-        * @param $row Object: database row
-        * @return Revision
+        * @param Object $row Database row
+        * @return string
         */
        function getTextFromRow( $row ) {
-               if( is_null( $row->ar_text_id ) ) {
+               if ( is_null( $row->ar_text_id ) ) {
                        // An old row from MediaWiki 1.4 or previous.
                        // Text is embedded in this row in classic compression format.
                        return Revision::getRevisionText( $row, 'ar_' );
-               } else {
-                       // New-style: keyed to the text storage backend.
-                       $dbr = wfGetDB( DB_SLAVE );
-                       $text = $dbr->selectRow( 'text',
-                               array( 'old_text', 'old_flags' ),
-                               array( 'old_id' => $row->ar_text_id ),
-                               __METHOD__ );
-                       return Revision::getRevisionText( $text );
                }
+
+               // New-style: keyed to the text storage backend.
+               $dbr = wfGetDB( DB_SLAVE );
+               $text = $dbr->selectRow( 'text',
+                       array( 'old_text', 'old_flags' ),
+                       array( 'old_id' => $row->ar_text_id ),
+                       __METHOD__ );
+
+               return Revision::getRevisionText( $text );
        }
 
        /**
@@ -294,7 +297,7 @@ class PageArchive {
         *
         * If there are no archived revisions for the page, returns NULL.
         *
-        * @return String
+        * @return string|null
         */
        function getLastRevisionText() {
                $dbr = wfGetDB( DB_SLAVE );
@@ -304,17 +307,18 @@ class PageArchive {
                                'ar_title' => $this->title->getDBkey() ),
                        __METHOD__,
                        array( 'ORDER BY' => 'ar_timestamp DESC' ) );
-               if( $row ) {
+
+               if ( $row ) {
                        return $this->getTextFromRow( $row );
-               } else {
-                       return null;
                }
+
+               return null;
        }
 
        /**
         * Quick check if any archived revisions are present for the page.
         *
-        * @return Boolean
+        * @return boolean
         */
        function isDeleted() {
                $dbr = wfGetDB( DB_SLAVE );
@@ -323,6 +327,7 @@ class PageArchive {
                                'ar_title' => $this->title->getDBkey() ),
                        __METHOD__
                );
+
                return ( $n > 0 );
        }
 
@@ -331,11 +336,11 @@ class PageArchive {
         * Once restored, the items will be removed from the archive tables.
         * The deletion log will be updated with an undeletion notice.
         *
-        * @param array $timestamps pass an empty array to restore all revisions, otherwise list the ones to undelete.
-        * @param $comment String
-        * @param $fileVersions Array
-        * @param $unsuppress Boolean
-        * @param $user User doing the action, or null to use $wgUser
+        * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
+        * @param string $comment
+        * @param array $fileVersions
+        * @param bool $unsuppress
+        * @param User $user User performing the action, or null to use $wgUser
         *
         * @return array(number of file revisions restored, number of image revisions restored, log message)
         * on success, false on failure
@@ -348,7 +353,7 @@ class PageArchive {
                $restoreText = $restoreAll || !empty( $timestamps );
                $restoreFiles = $restoreAll || !empty( $fileVersions );
 
-               if( $restoreFiles && $this->title->getNamespace() == NS_FILE ) {
+               if ( $restoreFiles && $this->title->getNamespace() == NS_FILE ) {
                        $img = wfLocalFile( $this->title );
                        $this->fileStatus = $img->restore( $fileVersions, $unsuppress );
                        if ( !$this->fileStatus->isOK() ) {
@@ -359,9 +364,9 @@ class PageArchive {
                        $filesRestored = 0;
                }
 
-               if( $restoreText ) {
+               if ( $restoreText ) {
                        $this->revisionStatus = $this->undeleteRevisions( $timestamps, $unsuppress, $comment );
-                       if( !$this->revisionStatus->isOK() ) {
+                       if ( !$this->revisionStatus->isOK() ) {
                                return false;
                        }
 
@@ -372,13 +377,13 @@ class PageArchive {
 
                // Touch the log!
 
-               if( $textRestored && $filesRestored ) {
+               if ( $textRestored && $filesRestored ) {
                        $reason = wfMessage( 'undeletedrevisions-files' )
                                ->numParams( $textRestored, $filesRestored )->inContentLanguage()->text();
-               } elseif( $textRestored ) {
+               } elseif ( $textRestored ) {
                        $reason = wfMessage( 'undeletedrevisions' )->numParams( $textRestored )
                                ->inContentLanguage()->text();
-               } elseif( $filesRestored ) {
+               } elseif ( $filesRestored ) {
                        $reason = wfMessage( 'undeletedfiles' )->numParams( $filesRestored )
                                ->inContentLanguage()->text();
                } else {
@@ -386,7 +391,7 @@ class PageArchive {
                        return false;
                }
 
-               if( trim( $comment ) != '' ) {
+               if ( trim( $comment ) != '' ) {
                        $reason .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $comment;
                }
 
@@ -413,12 +418,11 @@ class PageArchive {
         * to the cur/old tables. If the page currently exists, all revisions will
         * be stuffed into old, otherwise the most recent will go into cur.
         *
-        * @param array $timestamps pass an empty array to restore all revisions, otherwise list the ones to undelete.
-        * @param $unsuppress Boolean: remove all ar_deleted/fa_deleted restrictions of seletected revs
-        *
-        * @param $comment String
+        * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
+        * @param bool $unsuppress Remove all ar_deleted/fa_deleted restrictions of seletected revs
+        * @param string $comment
         * @throws ReadOnlyError
-        * @return Status, containing the number of revisions restored on success
+        * @return Status Object containing the number of revisions restored on success
         */
        private function undeleteRevisions( $timestamps, $unsuppress = false, $comment = '' ) {
                global $wgContentHandlerUseDB;
@@ -426,8 +430,8 @@ class PageArchive {
                if ( wfReadOnly() ) {
                        throw new ReadOnlyError();
                }
-               $restoreAll = empty( $timestamps );
 
+               $restoreAll = empty( $timestamps );
                $dbw = wfGetDB( DB_MASTER );
 
                # Does this page already exist? We'll have to update it...
@@ -443,7 +447,8 @@ class PageArchive {
                        __METHOD__,
                        array( 'FOR UPDATE' ) // lock page
                );
-               if( $page ) {
+
+               if ( $page ) {
                        $makepage = false;
                        # Page already exists. Import the history, and if necessary
                        # we'll update the latest revision field in the record.
@@ -455,7 +460,7 @@ class PageArchive {
                                array( 'rev_id' => $previousRevId ),
                                __METHOD__ );
 
-                       if( $previousTimestamp === false ) {
+                       if ( $previousTimestamp === false ) {
                                wfDebug( __METHOD__ . ": existing page refers to a page_latest that does not exist\n" );
 
                                $status = Status::newGood( 0 );
@@ -470,7 +475,7 @@ class PageArchive {
                        $previousTimestamp = 0;
                }
 
-               if( $restoreAll ) {
+               if ( $restoreAll ) {
                        $oldones = '1 = 1'; # All revisions...
                } else {
                        $oldts = implode( ',',
@@ -509,14 +514,15 @@ class PageArchive {
                        $fields,
                        /* WHERE */ array(
                                'ar_namespace' => $this->title->getNamespace(),
-                               'ar_title'     => $this->title->getDBkey(),
+                               'ar_title' => $this->title->getDBkey(),
                                $oldones ),
                        __METHOD__,
                        /* options */ array( 'ORDER BY' => 'ar_timestamp' )
                );
                $ret = $dbw->resultObject( $result );
                $rev_count = $dbw->numRows( $result );
-               if( !$rev_count ) {
+
+               if ( !$rev_count ) {
                        wfDebug( __METHOD__ . ": no revisions to restore\n" );
 
                        $status = Status::newGood( 0 );
@@ -544,9 +550,9 @@ class PageArchive {
                        return $status;
                }
 
-               if( $makepage ) {
+               if ( $makepage ) {
                        // Check the state of the newest to-be version...
-                       if( !$unsuppress && ( $row->ar_deleted & Revision::DELETED_TEXT ) ) {
+                       if ( !$unsuppress && ( $row->ar_deleted & Revision::DELETED_TEXT ) ) {
                                return Status::newFatal( "undeleterevdel" );
                        }
                        // Safe to insert now...
@@ -554,9 +560,9 @@ class PageArchive {
                        $pageId = $newid;
                } else {
                        // Check if a deleted revision will become the current revision...
-                       if( $row->ar_timestamp > $previousTimestamp ) {
+                       if ( $row->ar_timestamp > $previousTimestamp ) {
                                // Check the state of the newest to-be version...
-                               if( !$unsuppress && ( $row->ar_deleted & Revision::DELETED_TEXT ) ) {
+                               if ( !$unsuppress && ( $row->ar_deleted & Revision::DELETED_TEXT ) ) {
                                        return Status::newFatal( "undeleterevdel" );
                                }
                        }
@@ -570,10 +576,10 @@ class PageArchive {
 
                foreach ( $ret as $row ) {
                        // Check for key dupes due to shitty archive integrity.
-                       if( $row->ar_rev_id ) {
+                       if ( $row->ar_rev_id ) {
                                $exists = $dbw->selectField( 'revision', '1',
                                        array( 'rev_id' => $row->ar_rev_id ), __METHOD__ );
-                               if( $exists ) {
+                               if ( $exists ) {
                                        continue; // don't throw DB errors
                                }
                        }
@@ -616,7 +622,7 @@ class PageArchive {
 
                wfRunHooks( 'ArticleUndelete', array( &$this->title, $created, $comment ) );
 
-               if( $this->title->getNamespace() == NS_FILE ) {
+               if ( $this->title->getNamespace() == NS_FILE ) {
                        $update = new HTMLCacheUpdate( $this->title, 'imagelinks' );
                        $update->doUpdate();
                }
@@ -627,12 +633,16 @@ class PageArchive {
        /**
         * @return Status
         */
-       function getFileStatus() { return $this->fileStatus; }
+       function getFileStatus() {
+               return $this->fileStatus;
+       }
 
        /**
         * @return Status
         */
-       function getRevisionStatus() { return $this->revisionStatus; }
+       function getRevisionStatus() {
+               return $this->revisionStatus;
+       }
 }
 
 /**
@@ -664,10 +674,13 @@ class SpecialUndelete extends SpecialPage {
                } 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 ) : '';
@@ -698,16 +711,16 @@ class SpecialUndelete extends SpecialPage {
                        $this->mRestore = false;
                }
 
-               if( $this->mRestore || $this->mInvert ) {
+               if ( $this->mRestore || $this->mInvert ) {
                        $timestamps = array();
                        $this->mFileVersions = array();
-                       foreach( $request->getValues() as $key => $val ) {
+                       foreach ( $request->getValues() as $key => $val ) {
                                $matches = array();
-                               if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
+                               if ( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
                                        array_push( $timestamps, $matches[1] );
                                }
 
-                               if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
+                               if ( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
                                        $this->mFileVersions[] = intval( $matches[1] );
                                }
                        }
@@ -753,7 +766,7 @@ class SpecialUndelete extends SpecialPage {
                        if ( !$file->exists() ) {
                                $out->addWikiMsg( 'filedelete-nofile', $this->mFilename );
                        } elseif ( !$file->userCan( File::DELETED_FILE, $user ) ) {
-                               if( $file->isDeleted( File::DELETED_RESTRICTED ) ) {
+                               if ( $file->isDeleted( File::DELETED_RESTRICTED ) ) {
                                        throw new PermissionsError( 'suppressrevision' );
                                } else {
                                        throw new PermissionsError( 'deletedtext' );
@@ -776,22 +789,23 @@ class SpecialUndelete extends SpecialPage {
                $out = $this->getOutput();
                $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
                $out->addHTML(
-                       Xml::openElement( 'form', array(
-                               'method' => 'get',
-                               'action' => $wgScript ) ) .
-                       Xml::fieldset( $this->msg( 'undelete-search-box' )->text() ) .
-                       Html::hidden( 'title',
-                               $this->getTitle()->getPrefixedDBkey() ) .
-                       Xml::inputLabel( $this->msg( 'undelete-search-prefix' )->text(),
-                               'prefix', 'prefix', 20,
-                               $this->mSearchPrefix ) . ' ' .
-                       Xml::submitButton( $this->msg( 'undelete-search-submit' )->text() ) .
-                       Xml::closeElement( 'fieldset' ) .
-                       Xml::closeElement( 'form' )
+                       Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
+                               Xml::fieldset( $this->msg( 'undelete-search-box' )->text() ) .
+                               Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
+                               Xml::inputLabel(
+                                       $this->msg( 'undelete-search-prefix' )->text(),
+                                       'prefix',
+                                       'prefix',
+                                       20,
+                                       $this->mSearchPrefix
+                               ) . ' ' .
+                               Xml::submitButton( $this->msg( 'undelete-search-submit' )->text() ) .
+                               Xml::closeElement( 'fieldset' ) .
+                               Xml::closeElement( 'form' )
                );
 
                # List undeletable articles
-               if( $this->mSearchPrefix ) {
+               if ( $this->mSearchPrefix ) {
                        $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix );
                        $this->showList( $result );
                }
@@ -800,13 +814,13 @@ class SpecialUndelete extends SpecialPage {
        /**
         * Generic list of deleted pages
         *
-        * @param $result ResultWrapper
+        * @param ResultWrapper $result
         * @return bool
         */
        private function showList( $result ) {
                $out = $this->getOutput();
 
-               if( $result->numRows() == 0 ) {
+               if ( $result->numRows() == 0 ) {
                        $out->addWikiMsg( 'undelete-no-results' );
                        return false;
                }
@@ -826,8 +840,15 @@ class SpecialUndelete extends SpecialPage {
                                );
                        } else {
                                // The title is no longer valid, show as text
-                               $item = Html::element( 'span', array( 'class' => 'mw-invalidtitle' ),
-                                       Linker::getInvalidTitleDescription( $this->getContext(), $row->ar_namespace, $row->ar_title ) );
+                               $item = Html::element(
+                                       'span',
+                                       array( 'class' => 'mw-invalidtitle' ),
+                                       Linker::getInvalidTitleDescription(
+                                               $this->getContext(),
+                                               $row->ar_namespace,
+                                               $row->ar_title
+                                       )
+                               );
                        }
                        $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count )->parse();
                        $out->addHTML( "<li>{$item} ({$revs})</li>\n" );
@@ -839,7 +860,7 @@ class SpecialUndelete extends SpecialPage {
        }
 
        private function showRevision( $timestamp ) {
-               if( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
+               if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
                        return;
                }
 
@@ -852,31 +873,37 @@ class SpecialUndelete extends SpecialPage {
                $out = $this->getOutput();
                $user = $this->getUser();
 
-               if( !$rev ) {
+               if ( !$rev ) {
                        $out->addWikiMsg( 'undeleterevision-missing' );
                        return;
                }
 
-               if( $rev->isDeleted( 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' );
+               if ( $rev->isDeleted( 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 {
-                               $out->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-view' );
-                               $out->addHTML( '<br />' );
-                               // and we are allowed to see...
                        }
+
+                       $out->wrapWikiMsg(
+                               "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
+                               'rev-deleted-text-view'
+                       );
+                       $out->addHTML( '<br />' );
+                       // and we are allowed to see...
                }
 
-               if( $this->mDiff ) {
+               if ( $this->mDiff ) {
                        $previousRev = $archive->getPreviousRevision( $timestamp );
-                       if( $previousRev ) {
+                       if ( $previousRev ) {
                                $this->showDiff( $previousRev, $rev );
-                               if( $this->mDiffOnly ) {
+                               if ( $this->mDiffOnly ) {
                                        return;
-                               } else {
-                                       $out->addHTML( '<hr />' );
                                }
+
+                               $out->addHTML( '<hr />' );
                        } else {
                                $out->addWikiMsg( 'undelete-nodiff' );
                        }
@@ -900,7 +927,7 @@ class SpecialUndelete extends SpecialPage {
 
                $isText = ( $content instanceof TextContent );
 
-               if( $this->mPreview || $isText ) {
+               if ( $this->mPreview || $isText ) {
                        $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
                } else {
                        $openDiv = '<div id="mw-undelete-revision">';
@@ -922,7 +949,7 @@ class SpecialUndelete extends SpecialPage {
                        return;
                }
 
-               if( $this->mPreview || !$isText ) {
+               if ( $this->mPreview || !$isText ) {
                        // NOTE: non-text content has no source view, so always use rendered preview
 
                        // Hide [edit]s
@@ -935,16 +962,21 @@ class SpecialUndelete extends SpecialPage {
 
                if ( $isText ) {
                        // source view for textual content
-                       $sourceView = Xml::element( 'textarea', array(
-                               'readonly' => 'readonly',
-                               'cols' => $user->getIntOption( 'cols' ),
-                               'rows' => $user->getIntOption( 'rows' ) ),
-                               $content->getNativeData() . "\n" );
+                       $sourceView = Xml::element(
+                               'textarea',
+                               array(
+                                       'readonly' => 'readonly',
+                                       'cols' => $user->getIntOption( 'cols' ),
+                                       'rows' => $user->getIntOption( 'rows' )
+                               ),
+                               $content->getNativeData() . "\n"
+                       );
 
                        $previewButton = Xml::element( 'input', array(
                                'type' => 'submit',
                                'name' => 'preview',
-                               'value' => $this->msg( 'showpreview' )->text() ) );
+                               'value' => $this->msg( 'showpreview' )->text()
+                       ) );
                } else {
                        $sourceView = '';
                        $previewButton = '';
@@ -957,36 +989,37 @@ class SpecialUndelete extends SpecialPage {
 
                $out->addHTML(
                        $sourceView .
-                       Xml::openElement( 'div', array(
-                               'style' => 'clear: both' ) ) .
-                       Xml::openElement( 'form', array(
-                               'method' => 'post',
-                               'action' => $this->getTitle()->getLocalURL( array( 'action' => 'submit' ) ) ) ) .
-                       Xml::element( 'input', array(
-                               'type' => 'hidden',
-                               'name' => 'target',
-                               'value' => $this->mTargetObj->getPrefixedDBkey() ) ) .
-                       Xml::element( 'input', array(
-                               'type' => 'hidden',
-                               'name' => 'timestamp',
-                               'value' => $timestamp ) ) .
-                       Xml::element( 'input', array(
-                               'type' => 'hidden',
-                               'name' => 'wpEditToken',
-                               'value' => $user->getEditToken() ) ) .
-                       $previewButton .
-                       $diffButton .
-                       Xml::closeElement( 'form' ) .
-                       Xml::closeElement( 'div' ) );
+                               Xml::openElement( 'div', array(
+                                       'style' => 'clear: both' ) ) .
+                               Xml::openElement( 'form', array(
+                                       'method' => 'post',
+                                       'action' => $this->getTitle()->getLocalURL( array( 'action' => 'submit' ) ) ) ) .
+                               Xml::element( 'input', array(
+                                       'type' => 'hidden',
+                                       'name' => 'target',
+                                       'value' => $this->mTargetObj->getPrefixedDBkey() ) ) .
+                               Xml::element( 'input', array(
+                                       'type' => 'hidden',
+                                       'name' => 'timestamp',
+                                       'value' => $timestamp ) ) .
+                               Xml::element( 'input', array(
+                                       'type' => 'hidden',
+                                       'name' => 'wpEditToken',
+                                       'value' => $user->getEditToken() ) ) .
+                               $previewButton .
+                               $diffButton .
+                               Xml::closeElement( 'form' ) .
+                               Xml::closeElement( 'div' )
+               );
        }
 
        /**
         * Build a diff display between this and the previous either deleted
         * or non-deleted edit.
         *
-        * @param $previousRev Revision
-        * @param $currentRev Revision
-        * @return String: HTML
+        * @param Revision $previousRev
+        * @param Revision $currentRev
+        * @return string HTML
         */
        function showDiff( $previousRev, $currentRev ) {
                $diffContext = clone $this->getContext();
@@ -995,20 +1028,19 @@ class SpecialUndelete extends SpecialPage {
 
                $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
                $diffEngine->showDiffStyle();
-               $this->getOutput()->addHTML(
-                       "<div>" .
+               $this->getOutput()->addHTML( "<div>" .
                        "<table style='width: 98%;' cellpadding='0' cellspacing='4' class='diff'>" .
                        "<col class='diff-marker' />" .
                        "<col class='diff-content' />" .
                        "<col class='diff-marker' />" .
                        "<col class='diff-content' />" .
                        "<tr>" .
-                               "<td colspan='2' style='width: 50%; text-align: center' class='diff-otitle'>" .
-                               $this->diffHeader( $previousRev, 'o' ) .
-                               "</td>\n" .
-                               "<td colspan='2' style='width: 50%;  text-align: center' class='diff-ntitle'>" .
-                               $this->diffHeader( $currentRev, 'n' ) .
-                               "</td>\n" .
+                       "<td colspan='2' style='width: 50%; text-align: center' class='diff-otitle'>" .
+                       $this->diffHeader( $previousRev, 'o' ) .
+                       "</td>\n" .
+                       "<td colspan='2' style='width: 50%;  text-align: center' class='diff-ntitle'>" .
+                       $this->diffHeader( $currentRev, 'n' ) .
+                       "</td>\n" .
                        "</tr>" .
                        $diffEngine->generateContentDiffBody(
                                $previousRev->getContent( Revision::FOR_THIS_USER, $this->getUser() ),
@@ -1019,13 +1051,13 @@ class SpecialUndelete extends SpecialPage {
        }
 
        /**
-        * @param $rev Revision
-        * @param $prefix
+        * @param Revision $rev
+        * @param string $prefix
         * @return string
         */
        private function diffHeader( $rev, $prefix ) {
                $isDeleted = !( $rev->getId() && $rev->getTitle() );
-               if( $isDeleted ) {
+               if ( $isDeleted ) {
                        /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
                        $targetPage = $this->getTitle();
                        $targetQuery = array(
@@ -1037,31 +1069,34 @@ class SpecialUndelete extends SpecialPage {
                        $targetPage = $rev->getTitle();
                        $targetQuery = array( 'oldid' => $rev->getId() );
                }
+
                // Add show/hide deletion links if available
                $user = $this->getUser();
                $lang = $this->getLanguage();
                $rdel = Linker::getRevDeleteLink( $user, $rev, $this->mTargetObj );
+
                if ( $rdel ) {
                        $rdel = " $rdel";
                }
+
                return '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
-                               Linker::link(
-                                       $targetPage,
-                                       $this->msg(
-                                               'revisionasof',
-                                               $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
-                                               $lang->userDate( $rev->getTimestamp(), $user ),
-                                               $lang->userTime( $rev->getTimestamp(), $user )
-                                       )->escaped(),
-                                       array(),
-                                       $targetQuery
-                               ) .
+                       Linker::link(
+                               $targetPage,
+                               $this->msg(
+                                       'revisionasof',
+                                       $lang->userTimeAndDate( $rev->getTimestamp(), $user ),
+                                       $lang->userDate( $rev->getTimestamp(), $user ),
+                                       $lang->userTime( $rev->getTimestamp(), $user )
+                               )->escaped(),
+                               array(),
+                               $targetQuery
+                       ) .
                        '</strong></div>' .
                        '<div id="mw-diff-' . $prefix . 'title2">' .
-                               Linker::revUserTools( $rev ) . '<br />' .
+                       Linker::revUserTools( $rev ) . '<br />' .
                        '</div>' .
                        '<div id="mw-diff-' . $prefix . 'title3">' .
-                               Linker::revComment( $rev ) . $rdel . '<br />' .
+                       Linker::revComment( $rev ) . $rdel . '<br />' .
                        '</div>';
        }
 
@@ -1079,15 +1114,15 @@ class SpecialUndelete extends SpecialPage {
                        $lang->userTime( $file->getTimestamp(), $user ) );
                $out->addHTML(
                        Xml::openElement( 'form', array(
-                               'method' => 'POST',
-                               'action' => $this->getTitle()->getLocalURL(
-                                       'target=' . urlencode( $this->mTarget ) .
-                                       '&file=' . urlencode( $key ) .
-                                       '&token=' . urlencode( $user->getEditToken( $key ) ) )
+                                       'method' => 'POST',
+                                       'action' => $this->getTitle()->getLocalURL(
+                                               'target=' . urlencode( $this->mTarget ) .
+                                                       '&file=' . urlencode( $key ) .
+                                                       '&token=' . urlencode( $user->getEditToken( $key ) ) )
                                )
                        ) .
-                       Xml::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
-                       '</form>'
+                               Xml::submitButton( $this->msg( 'undelete-show-file-submit' )->text() ) .
+                               '</form>'
                );
        }
 
@@ -1113,7 +1148,7 @@ class SpecialUndelete extends SpecialPage {
 
        private function showHistory() {
                $out = $this->getOutput();
-               if( $this->mAllowed ) {
+               if ( $this->mAllowed ) {
                        $out->addModules( 'mediawiki.special.undelete' );
                }
                $out->wrapWikiMsg(
@@ -1147,7 +1182,7 @@ class SpecialUndelete extends SpecialPage {
                $haveFiles = $files && $files->numRows() > 0;
 
                # Batch existence check on user and talk pages
-               if( $haveRevisions ) {
+               if ( $haveRevisions ) {
                        $batch = new LinkBatch();
                        foreach ( $revisions as $row ) {
                                $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
@@ -1156,7 +1191,7 @@ class SpecialUndelete extends SpecialPage {
                        $batch->execute();
                        $revisions->seek( 0 );
                }
-               if( $haveFiles ) {
+               if ( $haveFiles ) {
                        $batch = new LinkBatch();
                        foreach ( $files as $row ) {
                                $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
@@ -1169,7 +1204,10 @@ class SpecialUndelete extends SpecialPage {
                if ( $this->mAllowed ) {
                        $action = $this->getTitle()->getLocalURL( array( 'action' => 'submit' ) );
                        # Start the form here
-                       $top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
+                       $top = Xml::openElement(
+                               'form',
+                               array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' )
+                       );
                        $out->addHTML( $top );
                }
 
@@ -1179,59 +1217,60 @@ class SpecialUndelete extends SpecialPage {
                LogEventsList::showLogExtract( $out, 'delete', $this->mTargetObj );
                # Show relevant lines from the suppression log:
                $suppressLogPage = new LogPage( 'suppress' );
-               if( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
+               if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
                        $out->addHTML( Xml::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
                        LogEventsList::showLogExtract( $out, 'suppress', $this->mTargetObj );
                }
 
-               if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
+               if ( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
                        # Format the user-visible controls (comment field, submission button)
                        # in a nice little table
-                       if( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
+                       if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
                                $unsuppressBox =
                                        "<tr>
                                                <td>&#160;</td>
                                                <td class='mw-input'>" .
-                                                       Xml::checkLabel( $this->msg( 'revdelete-unsuppress' )->text(),
-                                                               'wpUnsuppress', 'mw-undelete-unsuppress', $this->mUnsuppress ).
+                                               Xml::checkLabel( $this->msg( 'revdelete-unsuppress' )->text(),
+                                                       'wpUnsuppress', 'mw-undelete-unsuppress', $this->mUnsuppress ) .
                                                "</td>
                                        </tr>";
                        } else {
                                $unsuppressBox = '';
                        }
+
                        $table =
                                Xml::fieldset( $this->msg( 'undelete-fieldset-title' )->text() ) .
-                               Xml::openElement( 'table', array( 'id' => 'mw-undelete-table' ) ) .
+                                       Xml::openElement( 'table', array( 'id' => 'mw-undelete-table' ) ) .
                                        "<tr>
                                                <td colspan='2' class='mw-undelete-extrahelp'>" .
-                                                       $this->msg( 'undeleteextrahelp' )->parseAsBlock() .
-                                               "</td>
-                                       </tr>
-                                       <tr>
-                                               <td class='mw-label'>" .
-                                                       Xml::label( $this->msg( 'undeletecomment' )->text(), 'wpComment' ) .
-                                               "</td>
-                                               <td class='mw-input'>" .
-                                                       Xml::input( 'wpComment', 50, $this->mComment, array( 'id' => 'wpComment' ) ) .
-                                               "</td>
-                                       </tr>
-                                       <tr>
-                                               <td>&#160;</td>
-                                               <td class='mw-submit'>" .
-                                                       Xml::submitButton( $this->msg( 'undeletebtn' )->text(), array( 'name' => 'restore', 'id' => 'mw-undelete-submit' ) ) . ' ' .
-                                                       Xml::submitButton( $this->msg( 'undeleteinvert' )->text(), array( 'name' => 'invert', 'id' => 'mw-undelete-invert' ) ) .
-                                               "</td>
-                                       </tr>" .
+                                       $this->msg( 'undeleteextrahelp' )->parseAsBlock() .
+                                       "</td>
+                               </tr>
+                               <tr>
+                                       <td class='mw-label'>" .
+                                       Xml::label( $this->msg( 'undeletecomment' )->text(), 'wpComment' ) .
+                                       "</td>
+                                       <td class='mw-input'>" .
+                                       Xml::input( 'wpComment', 50, $this->mComment, array( 'id' => 'wpComment' ) ) .
+                                       "</td>
+                               </tr>
+                               <tr>
+                                       <td>&#160;</td>
+                                       <td class='mw-submit'>" .
+                                       Xml::submitButton( $this->msg( 'undeletebtn' )->text(), array( 'name' => 'restore', 'id' => 'mw-undelete-submit' ) ) . ' ' .
+                                       Xml::submitButton( $this->msg( 'undeleteinvert' )->text(), array( 'name' => 'invert', 'id' => 'mw-undelete-invert' ) ) .
+                                       "</td>
+                               </tr>" .
                                        $unsuppressBox .
-                               Xml::closeElement( 'table' ) .
-                               Xml::closeElement( 'fieldset' );
+                                       Xml::closeElement( 'table' ) .
+                                       Xml::closeElement( 'fieldset' );
 
                        $out->addHTML( $table );
                }
 
                $out->addHTML( Xml::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n" );
 
-               if( $haveRevisions ) {
+               if ( $haveRevisions ) {
                        # The page's stored (deleted) history:
                        $out->addHTML( '<ul>' );
                        $remaining = $revisions->numRows();
@@ -1247,7 +1286,7 @@ class SpecialUndelete extends SpecialPage {
                        $out->addWikiMsg( 'nohistory' );
                }
 
-               if( $haveFiles ) {
+               if ( $haveFiles ) {
                        $out->addHTML( Xml::element( 'h2', null, $this->msg( 'filehist' )->text() ) . "\n" );
                        $out->addHTML( '<ul>' );
                        foreach ( $files as $row ) {
@@ -1277,9 +1316,9 @@ class SpecialUndelete extends SpecialPage {
                $revTextSize = '';
                $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
                // Build checkboxen...
-               if( $this->mAllowed ) {
-                       if( $this->mInvert ) {
-                               if( in_array( $ts, $this->mTargetTimestamp ) ) {
+               if ( $this->mAllowed ) {
+                       if ( $this->mInvert ) {
+                               if ( in_array( $ts, $this->mTargetTimestamp ) ) {
                                        $checkBox = Xml::check( "ts$ts" );
                                } else {
                                        $checkBox = Xml::check( "ts$ts", true );
@@ -1290,15 +1329,16 @@ class SpecialUndelete extends SpecialPage {
                } else {
                        $checkBox = '';
                }
-               $user = $this->getUser();
+
                // Build page & diff links...
-               if( $this->mCanView ) {
+               $user = $this->getUser();
+               if ( $this->mCanView ) {
                        $titleObj = $this->getTitle();
                        # Last link
-                       if( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
+                       if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
                                $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
                                $last = $this->msg( 'diff' )->escaped();
-                       } elseif( $remaining > 0 || ( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
+                       } elseif ( $remaining > 0 || ( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
                                $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
                                $last = Linker::linkKnown(
                                        $titleObj,
@@ -1318,28 +1358,35 @@ class SpecialUndelete extends SpecialPage {
                        $pageLink = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) );
                        $last = $this->msg( 'diff' )->escaped();
                }
+
                // User links
                $userLink = Linker::revUserTools( $rev );
+
                // Revision text size
                $size = $row->ar_len;
-               if( !is_null( $size ) ) {
+               if ( !is_null( $size ) ) {
                        $revTextSize = Linker::formatRevisionSize( $size );
                }
+
                // Edit summary
                $comment = Linker::revComment( $rev );
+
                // Revision delete links
                $revdlink = Linker::getRevDeleteLink( $user, $rev, $this->mTargetObj );
 
-               $revisionRow = $this->msg( 'undelete-revisionrow' )->rawParams( $checkBox, $revdlink, $last, $pageLink, $userLink, $revTextSize, $comment )->escaped();
+               $revisionRow = $this->msg( 'undelete-revisionrow' )
+                       ->rawParams( $checkBox, $revdlink, $last, $pageLink, $userLink, $revTextSize, $comment )
+                       ->escaped();
+
                return "<li>$revisionRow</li>";
        }
 
        private function formatFileRow( $row ) {
                $file = ArchivedFile::newFromRow( $row );
-
                $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
                $user = $this->getUser();
-               if( $this->mAllowed && $row->fa_storage_key ) {
+
+               if ( $this->mAllowed && $row->fa_storage_key ) {
                        $checkBox = Xml::check( 'fileid' . $row->fa_id );
                        $key = urlencode( $row->fa_storage_key );
                        $pageLink = $this->getFileLink( $file, $this->getTitle(), $ts, $key );
@@ -1349,15 +1396,18 @@ class SpecialUndelete extends SpecialPage {
                }
                $userLink = $this->getFileUser( $file );
                $data = $this->msg( 'widthheight' )->numParams( $row->fa_width, $row->fa_height )->text();
-               $bytes = $this->msg( 'parentheses' )->rawParams( $this->msg( 'nbytes' )->numParams( $row->fa_size )->text() )->plain();
+               $bytes = $this->msg( 'parentheses' )
+                       ->rawParams( $this->msg( 'nbytes' )->numParams( $row->fa_size )->text() )
+                       ->plain();
                $data = htmlspecialchars( $data . ' ' . $bytes );
                $comment = $this->getFileComment( $file );
 
                // Add show/hide deletion links if available
                $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
+               if ( $canHide || ( $file->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
+                       if ( !$file->userCan( File::DELETED_RESTRICTED, $user ) ) {
+                               // Revision was hidden from sysops
+                               $revdlink = Linker::revDeleteLinkDisabled( $canHide );
                        } else {
                                $query = array(
                                        'type' => 'filearchive',
@@ -1377,8 +1427,8 @@ class SpecialUndelete extends SpecialPage {
        /**
         * Fetch revision text link if it's available to all users
         *
-        * @param $rev Revision
-        * @param $titleObj Title
+        * @param Revision $rev
+        * @param Title $titleObj
         * @param string $ts Timestamp
         * @return string
         */
@@ -1386,95 +1436,105 @@ class SpecialUndelete extends SpecialPage {
                $user = $this->getUser();
                $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
 
-               if( !$rev->userCan( Revision::DELETED_TEXT, $user ) ) {
+               if ( !$rev->userCan( Revision::DELETED_TEXT, $user ) ) {
                        return '<span class="history-deleted">' . $time . '</span>';
-               } else {
-                       $link = Linker::linkKnown(
-                               $titleObj,
-                               htmlspecialchars( $time ),
-                               array(),
-                               array(
-                                       'target' => $this->mTargetObj->getPrefixedText(),
-                                       'timestamp' => $ts
-                               )
-                       );
-                       if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
-                               $link = '<span class="history-deleted">' . $link . '</span>';
-                       }
-                       return $link;
                }
+
+               $link = Linker::linkKnown(
+                       $titleObj,
+                       htmlspecialchars( $time ),
+                       array(),
+                       array(
+                               'target' => $this->mTargetObj->getPrefixedText(),
+                               'timestamp' => $ts
+                       )
+               );
+
+               if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
+                       $link = '<span class="history-deleted">' . $link . '</span>';
+               }
+
+               return $link;
        }
 
        /**
         * Fetch image view link if it's available to all users
         *
-        * @param $file File
-        * @param $titleObj Title
+        * @param File|ArchivedFile $file
+        * @param Title $titleObj
         * @param string $ts A timestamp
         * @param string $key a storage key
         *
-        * @return String: HTML fragment
+        * @return string HTML fragment
         */
        function getFileLink( $file, $titleObj, $ts, $key ) {
                $user = $this->getUser();
                $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
 
-               if( !$file->userCan( File::DELETED_FILE, $user ) ) {
+               if ( !$file->userCan( File::DELETED_FILE, $user ) ) {
                        return '<span class="history-deleted">' . $time . '</span>';
-               } else {
-                       $link = Linker::linkKnown(
-                               $titleObj,
-                               htmlspecialchars( $time ),
-                               array(),
-                               array(
-                                       'target' => $this->mTargetObj->getPrefixedText(),
-                                       'file' => $key,
-                                       'token' => $user->getEditToken( $key )
-                               )
-                       );
-                       if( $file->isDeleted( File::DELETED_FILE ) ) {
-                               $link = '<span class="history-deleted">' . $link . '</span>';
-                       }
-                       return $link;
                }
+
+               $link = Linker::linkKnown(
+                       $titleObj,
+                       htmlspecialchars( $time ),
+                       array(),
+                       array(
+                               'target' => $this->mTargetObj->getPrefixedText(),
+                               'file' => $key,
+                               'token' => $user->getEditToken( $key )
+                       )
+               );
+
+               if ( $file->isDeleted( File::DELETED_FILE ) ) {
+                       $link = '<span class="history-deleted">' . $link . '</span>';
+               }
+
+               return $link;
        }
 
        /**
         * Fetch file's user id if it's available to this user
         *
-        * @param $file File
-        * @return String: HTML fragment
+        * @param File|ArchivedFile $file
+        * @return string HTML fragment
         */
        function getFileUser( $file ) {
-               if( !$file->userCan( File::DELETED_USER, $this->getUser() ) ) {
-                       return '<span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
-               } else {
-                       $link = Linker::userLink( $file->getRawUser(), $file->getRawUserText() ) .
-                               Linker::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
-                       if( $file->isDeleted( File::DELETED_USER ) ) {
-                               $link = '<span class="history-deleted">' . $link . '</span>';
-                       }
-                       return $link;
+               if ( !$file->userCan( File::DELETED_USER, $this->getUser() ) ) {
+                       return '<span class="history-deleted">' .
+                               $this->msg( 'rev-deleted-user' )->escaped() .
+                               '</span>';
                }
+
+               $link = Linker::userLink( $file->getRawUser(), $file->getRawUserText() ) .
+                       Linker::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
+
+               if ( $file->isDeleted( File::DELETED_USER ) ) {
+                       $link = '<span class="history-deleted">' . $link . '</span>';
+               }
+
+               return $link;
        }
 
        /**
         * Fetch file upload comment if it's available to this user
         *
-        * @param $file File
-        * @return String: HTML fragment
+        * @param File|ArchivedFile $file
+        * @return string HTML fragment
         */
        function getFileComment( $file ) {
-               if( !$file->userCan( File::DELETED_COMMENT, $this->getUser() ) ) {
+               if ( !$file->userCan( File::DELETED_COMMENT, $this->getUser() ) ) {
                        return '<span class="history-deleted"><span class="comment">' .
                                $this->msg( 'rev-deleted-comment' )->escaped() . '</span></span>';
-               } else {
-                       $link = Linker::commentBlock( $file->getRawDescription() );
-                       if( $file->isDeleted( File::DELETED_COMMENT ) ) {
-                               $link = '<span class="history-deleted">' . $link . '</span>';
-                       }
-                       return $link;
                }
+
+               $link = Linker::commentBlock( $file->getRawDescription() );
+
+               if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
+                       $link = '<span class="history-deleted">' . $link . '</span>';
+               }
+
+               return $link;
        }
 
        function undelete() {
@@ -1499,7 +1559,7 @@ class SpecialUndelete extends SpecialPage {
                        $this->getUser()
                );
 
-               if( is_array( $ok ) ) {
+               if ( is_array( $ok ) ) {
                        if ( $ok[1] ) { // Undeleted file count
                                wfRunHooks( 'FileUndeleteComplete', array(
                                        $this->mTargetObj, $this->mFileVersions,
@@ -1514,13 +1574,13 @@ class SpecialUndelete extends SpecialPage {
 
                // Show revision undeletion warnings and errors
                $status = $archive->getRevisionStatus();
-               if( $status && !$status->isGood() ) {
+               if ( $status && !$status->isGood() ) {
                        $out->addWikiText( '<div class="error">' . $status->getWikiText( 'cannotundelete', 'cannotundelete' ) . '</div>' );
                }
 
                // Show file undeletion warnings and errors
                $status = $archive->getFileStatus();
-               if( $status && !$status->isGood() ) {
+               if ( $status && !$status->isGood() ) {
                        $out->addWikiText( '<div class="error">' . $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) . '</div>' );
                }
        }