ImagePage.php: add missing braces + other code style tweaks
[lhc/web/wiklou.git] / includes / ImagePage.php
index 6286b1b..3d059ca 100644 (file)
@@ -1,8 +1,5 @@
 <?php
 
-if ( !defined( 'MEDIAWIKI' ) )
-       die( 1 );
-
 /**
  * Special handling for image description pages
  *
@@ -10,10 +7,17 @@ if ( !defined( 'MEDIAWIKI' ) )
  */
 class ImagePage extends Article {
 
-       /* private */ var $img;  // Image object
+       /**
+        * @var File
+        */
+       /* private */ var $img;
+       /**
+        * @var File
+        */
        /* private */ var $displayImg;
        /* private */ var $repo;
        /* private */ var $fileLoaded;
+
        var $mExtraDescription = false;
        var $dupes;
 
@@ -22,7 +26,11 @@ class ImagePage extends Article {
                $this->dupes = null;
                $this->repo = null;
        }
-       
+
+       /**
+        * @param $file File:
+        * @return void
+        */
        public function setFile( $file ) {
                $this->displayImg = $file;
                $this->img = $file;
@@ -66,7 +74,7 @@ class ImagePage extends Article {
                $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
 
                if ( $this->mTitle->getNamespace() != NS_FILE || ( isset( $diff ) && $diffOnly ) ) {
-                       return Article::view();
+                       return parent::view();
                }
                        
                $this->loadFile();
@@ -76,7 +84,7 @@ class ImagePage extends Article {
                                // mTitle is the same as the redirect target so ask Article
                                // to perform the redirect for us.
                                $wgRequest->setVal( 'diffonly', 'true' );
-                               return Article::view();
+                               return parent::view();
                        } else {
                                // mTitle is not the same as the redirect target so it is 
                                // probably the redirect page itself. Fake the redirect symbol
@@ -98,15 +106,17 @@ class ImagePage extends Article {
                        $showmeta = false;
                }
 
-               if ( !$diff && $this->displayImg->exists() )
+               if ( !$diff && $this->displayImg->exists() ) {
                        $wgOut->addHTML( $this->showTOC( $showmeta ) );
+               }
 
-               if ( !$diff )
+               if ( !$diff ) {
                        $this->openShowImage();
+               }
 
                # No need to display noarticletext, we use our own message, output in openShowImage()
                if ( $this->getID() ) {
-                       Article::view();
+                       parent::view();
                } else {
                        # Just need to set the right headers
                        $wgOut->setArticleFlag( true );
@@ -116,9 +126,9 @@ class ImagePage extends Article {
 
                # Show shared description, if needed
                if ( $this->mExtraDescription ) {
-                       $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
-                       if ( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
-                               $wgOut->addWikiText( $fol );
+                       $fol = wfMessage( 'shareddescriptionfollows' );
+                       if ( !$fol->isDisabled() ) {
+                               $wgOut->addWikiText( $fol->plain() );
                        }
                        $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . "</div>\n" );
                }
@@ -139,18 +149,14 @@ class ImagePage extends Article {
                # Allow extensions to add something after the image links
                $html = '';
                wfRunHooks( 'ImagePageAfterImageLinks', array( $this, &$html ) );
-               if ( $html )
+               if ( $html ) {
                        $wgOut->addHTML( $html );
+               }
 
                if ( $showmeta ) {
-                       global $wgStylePath, $wgStyleVersion;
-                       $expand = htmlspecialchars( Xml::escapeJsString( wfMsg( 'metadata-expand' ) ) );
-                       $collapse = htmlspecialchars( Xml::escapeJsString( wfMsg( 'metadata-collapse' ) ) );
                        $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ) . "\n" );
                        $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
-                       $wgOut->addScriptFile( 'metadata.js' );
-                       $wgOut->addHTML(
-                               "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
+                       $wgOut->addModules( array( 'mediawiki.legacy.metadata' ) );
                }
                
                $css = $this->repo->getDescriptionStylesheetUrl();
@@ -172,6 +178,7 @@ class ImagePage extends Article {
                }
                return $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to );
        }
+
        public function followRedirect() {
                $this->loadFile();
                if ( $this->img->isLocal() ) {
@@ -184,10 +191,12 @@ class ImagePage extends Article {
                }
                return Title::makeTitle( NS_FILE, $to );
        }
+
        public function isRedirect( $text = false ) {
                $this->loadFile();
-               if ( $this->img->isLocal() )
+               if ( $this->img->isLocal() ) {
                        return parent::isRedirect( $text );
+               }
                        
                return (bool)$this->img->getRedirected();
        }
@@ -212,7 +221,8 @@ class ImagePage extends Article {
                if ( !is_null( $this->dupes ) ) {
                        return $this->dupes;
                }
-               if ( !( $hash = $this->img->getSha1() ) ) {
+               $hash = $this->img->getSha1();
+               if ( !( $hash ) ) {
                        return $this->dupes = array();
                }
                $dupes = RepoGroup::singleton()->findBySha1( $hash );
@@ -221,15 +231,15 @@ class ImagePage extends Article {
                $size = $this->img->getSize();
                foreach ( $dupes as $index => $file ) {
                        $key = $file->getRepoName() . ':' . $file->getName();
-                       if ( $key == $self )
+                       if ( $key == $self ) {
                                unset( $dupes[$index] );
-                       if ( $file->getSize() != $size )
+                       }
+                       if ( $file->getSize() != $size ) {
                                unset( $dupes[$index] );
+                       }
                }
                return $this->dupes = $dupes;
-               
        }
-       
 
        /**
         * Create the TOC
@@ -239,9 +249,9 @@ class ImagePage extends Article {
         */
        protected function showTOC( $metadata ) {
                $r = array(
-                               '<li><a href="#file">' . wfMsgHtml( 'file-anchor-link' ) . '</a></li>',
-                               '<li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>',
-                               '<li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>',
+                       '<li><a href="#file">' . wfMsgHtml( 'file-anchor-link' ) . '</a></li>',
+                       '<li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>',
+                       '<li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>',
                );
                if ( $metadata ) {
                        $r[] = '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>';
@@ -291,7 +301,7 @@ class ImagePage extends Article {
                if ( $this->img && !$this->img->isLocal() && 0 == $this->getID() ) {
                        return '';
                }
-               return Article::getContent();
+               return parent::getContent();
        }
 
        protected function openShowImage() {
@@ -300,8 +310,6 @@ class ImagePage extends Article {
 
                $this->loadFile();
 
-               $full_url  = $this->displayImg->getURL();
-               $linkAttribs = false;
                $sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
                if ( !isset( $wgImageLimits[$sizeSel] ) ) {
                        $sizeSel = User::getDefaultOption( 'imagesize' );
@@ -328,14 +336,12 @@ class ImagePage extends Article {
                        } else {
                                $params = array( 'page' => $page );
                        }
-                       $width_orig = $this->displayImg->getWidth();
+                       $width_orig = $this->displayImg->getWidth( $page );
                        $width = $width_orig;
-                       $height_orig = $this->displayImg->getHeight();
+                       $height_orig = $this->displayImg->getHeight( $page );
                        $height = $height_orig;
-                       $mime = $this->displayImg->getMimeType();
-                       $showLink = false;
-                       $linkAttribs = array( 'href' => $full_url );
-                       $longDesc = $this->displayImg->getLongDesc();
+
+                       $longDesc = wfMsg( 'parentheses', $this->displayImg->getLongDesc() );
 
                        wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this, &$wgOut ) );
 
@@ -343,7 +349,7 @@ class ImagePage extends Article {
                                # image
 
                                # "Download high res version" link below the image
-                               # $msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
+                               # $msgsize = wfMsgHtml( 'file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
                                # We'll show a thumbnail of this image
                                if ( $width > $maxWidth || $height > $maxHeight ) {
                                        # Calculate the thumbnail size.
@@ -360,27 +366,29 @@ class ImagePage extends Article {
                                                # because of rounding.
                                        }
                                        $msgbig  = wfMsgHtml( 'show-big-image' );
-                                       $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline',
-                                               $wgLang->formatNum( $width ),
-                                               $wgLang->formatNum( $height )
-                                       );
+                                       $otherSizes = array();
+                                       foreach ( $wgImageLimits as $size ) {
+                                               if ( $size[0] < $width_orig && $size[1] < $height_orig &&
+                                                               $size[0] != $width && $size[1] != $height ) {
+                                                       $otherSizes[] = $this->makeSizeLink( $params, $size[0], $size[1] );                                                     
+                                               }
+                                       }
+                                       $msgsmall = wfMessage( 'show-big-image-preview' )->
+                                               rawParams( $this->makeSizeLink( $params, $width, $height ) )->
+                                               parse() . ' ' . 
+                                               wfMessage( 'show-big-image-other' )->
+                                               rawParams( $wgLang->pipeList( $otherSizes ) )->parse();
                                } else {
                                        # Image is small enough to show full size on image page
-                                       $msgbig = htmlspecialchars( $this->displayImg->getName() );
                                        $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
                                }
 
                                $params['width'] = $width;
+                               $params['height'] = $height;
                                $thumbnail = $this->displayImg->transform( $params );
 
-                               $anchorclose = "<br />";
-                               if ( $this->displayImg->mustRender() ) {
-                                       $showLink = true;
-                               } else {
-                                       $anchorclose .=
-                                               $msgsmall .
-                                               '<br />' . Xml::tags( 'a', $linkAttribs,  $msgbig ) . "$dirmark " . $longDesc;
-                               }
+                               $showLink = true;
+                               $anchorclose = '<br />' . $msgsmall;
 
                                $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
                                if ( $isMulti ) {
@@ -438,7 +446,6 @@ class ImagePage extends Article {
                                                'onchange' => 'document.pageselector.submit();',
                                        );
 
-                                       $option = array();
                                        for ( $i = 1; $i <= $count; $i++ ) {
                                                $options[] = Xml::option( $wgLang->formatNum( $i ), $i, $i == $page );
                                        }
@@ -449,7 +456,7 @@ class ImagePage extends Article {
                                        $wgOut->addHTML(
                                                '</td><td><div class="multipageimagenavbox">' .
                                                Xml::openElement( 'form', $formParams ) .
-                                               Xml::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
+                                               Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
                                                wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
                                                Xml::submitButton( wfMsg( 'imgmultigo' ) ) .
                                                Xml::closeElement( 'form' ) .
@@ -462,33 +469,31 @@ class ImagePage extends Article {
                                        $icon = $this->displayImg->iconThumb();
 
                                        $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
-                                       $icon->toHtml( array( 'file-link' => true ) ) .
-                                       "</div>\n" );
+                                               $icon->toHtml( array( 'file-link' => true ) ) .
+                                               "</div>\n" );
                                }
 
                                $showLink = true;
                        }
 
-
                        if ( $showLink ) {
                                $filename = wfEscapeWikiText( $this->displayImg->getName() );
-                               $medialink = "[[Media:$filename|$filename]]";
+                               $linktext = $filename;
+                               if ( isset( $msgbig ) ) {
+                                       $linktext = wfEscapeWikiText( $msgbig );
+                               }
+                               $medialink = "[[Media:$filename|$linktext]]";
 
                                if ( !$this->displayImg->isSafeFile() ) {
                                        $warning = wfMsgNoTrans( 'mediawarning' );
                                        $wgOut->addWikiText( <<<EOT
-<div class="fullMedia">
-<span class="dangerousLink">{$medialink}</span>$dirmark
-<span class="fileInfo">$longDesc</span>
-</div>
+<div class="fullMedia"><span class="dangerousLink">{$medialink}</span>$dirmark <span class="fileInfo">$longDesc</span></div>
 <div class="mediaWarning">$warning</div>
 EOT
                                                );
                                } else {
                                        $wgOut->addWikiText( <<<EOT
-<div class="fullMedia">
-{$medialink}{$dirmark}
-<span class="fileInfo">$longDesc</span>
+<div class="fullMedia">{$medialink}{$dirmark} <span class="fileInfo">$longDesc</span>
 </div>
 EOT
                                        );
@@ -505,15 +510,45 @@ EOT
                                $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
                                $nofile = array(
                                        'filepage-nofile-link',
-                                       $uploadTitle->getFullUrl( array( 'wpDestFile' => $this->img->getName() ) )
+                                       $uploadTitle->getFullURL( array( 'wpDestFile' => $this->img->getName() ) )
                                );
-                       }
-                       else
-                       {
+                       } else {
                                $nofile = 'filepage-nofile';
                        }
+                       // Note, if there is an image description page, but
+                       // no image, then this setRobotPolicy is overriden
+                       // by Article::View().
                        $wgOut->setRobotPolicy( 'noindex,nofollow' );
                        $wgOut->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
+                       if ( !$this->getID() ) {
+                               // If there is no image, no shared image, and no description page,
+                               // output a 404, to be consistent with articles.
+                               $wgRequest->response()->header( 'HTTP/1.1 404 Not Found' );
+                       }
+               }
+       }
+       
+       /**
+        * Creates an thumbnail of specified size and returns an HTML link to it  
+        * @param array $params Scaler parameters
+        * @param int $width
+        * @param int $height
+        */
+       private function makeSizeLink( $params, $width, $height ) {
+               global $wgLang;
+               
+               $params['width'] = $width;
+               $params['height'] = $height;
+               $thumbnail = $this->displayImg->transform( $params );
+               if ( $thumbnail && !$thumbnail->isError() ) {
+                       return Html::rawElement( 'a', array(
+                               'href' => $thumbnail->getUrl(),
+                               'class' => 'mw-thumbnail-link'
+                               ), wfMessage( 'show-big-image-size' )->numParams(
+                                       $thumbnail->getWidth(), $thumbnail->getHeight() 
+                               )->parse() );
+               } else {
+                       return '';
                }
        }
 
@@ -528,10 +563,14 @@ EOT
                $descUrl = $this->img->getDescriptionUrl();
                $descText = $this->img->getDescriptionText();
 
+               /* Add canonical to head if there is no local page for this shared file */
+               if( $descUrl && $this->getID() == 0 ) {
+                       $wgOut->addLink( array( 'rel' => 'canonical', 'href' => $descUrl ) );
+               }
+
                $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
                $repo = $this->img->getRepo()->getDisplayName();
 
-               $msg = '';
                if ( $descUrl && $descText && wfMsgNoTrans( 'sharedupload-desc-here' ) !== '-'  ) {
                        $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) );
                } elseif ( $descUrl && wfMsgNoTrans( 'sharedupload-desc-there' ) !== '-' ) {
@@ -548,7 +587,7 @@ EOT
        public function getUploadUrl() {
                $this->loadFile();
                $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
-               return $uploadTitle->getFullUrl( array(
+               return $uploadTitle->getFullURL( array(
                        'wpDestFile' => $this->img->getName(),
                        'wpForReUpload' => 1
                 ) );
@@ -561,11 +600,14 @@ EOT
        protected function uploadLinksBox() {
                global $wgUser, $wgOut, $wgEnableUploads, $wgUseExternalEditor;
 
-               if ( !$wgEnableUploads ) { return; }
+               if ( !$wgEnableUploads ) {
+                       return;
+               }
 
                $this->loadFile();
-               if ( !$this->img->isLocal() )
+               if ( !$this->img->isLocal() ) {
                        return;
+               }
 
                $sk = $wgUser->getSkin();
 
@@ -590,7 +632,11 @@ EOT
                                ),
                                array( 'known', 'noclasses' )
                        );
-                       $wgOut->addHTML( '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . "</small></li>\n" );
+                       $wgOut->addHTML(
+                               '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' .
+                               wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) .
+                               "</small></li>\n"
+                       );
                }
 
                $wgOut->addHTML( "</ul>\n" );
@@ -608,6 +654,7 @@ EOT
                $this->loadFile();
                $pager = new ImageHistoryPseudoPager( $this );
                $wgOut->addHTML( $pager->getBody() );
+               $wgOut->preventClickjacking( $pager->getPreventClickjacking() );
 
                $this->img->resetHistory(); // free db resources
 
@@ -634,7 +681,11 @@ EOT
                );
                $count = $dbr->numRows( $res );
                if ( $count == 0 ) {
-                       $wgOut->wrapWikiMsg( Html::rawElement( 'div', array ( 'id' => 'mw-imagepage-nolinkstoimage' ), "\n$1\n" ), 'nolinkstoimage' );
+                       $wgOut->wrapWikiMsg(
+                               Html::rawElement( 'div',
+                                       array( 'id' => 'mw-imagepage-nolinkstoimage' ), "\n$1\n" ),
+                               'nolinkstoimage'
+                       );
                        return;
                }
                
@@ -649,11 +700,14 @@ EOT
                        );
                }
 
-               $wgOut->addHTML( Html::openElement( 'ul', array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n" );
+               $wgOut->addHTML(
+                       Html::openElement( 'ul',
+                               array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n"
+               );
                $sk = $wgUser->getSkin();
                $count = 0;
                $elements = array();
-               while ( $s = $res->fetchObject() ) {
+               foreach ( $res as $s ) {
                        $count++;
                        if ( $count <= $limit ) {
                                // We have not yet reached the extra one that tells us there is more to fetch
@@ -662,16 +716,16 @@ EOT
                }
 
                // Sort the list by namespace:title
-               usort ( $elements, array( $this, 'compare' ) );
+               usort( $elements, array( $this, 'compare' ) );
 
                // Create links for every element
                foreach( $elements as $element ) {    
                        $link = $sk->linkKnown( Title::makeTitle( $element->page_namespace, $element->page_title ) );
                        $wgOut->addHTML( Html::rawElement(
-                                               'li',
-                                               array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
-                                               $link
-                                       ) . "\n"
+                                       'li',
+                                       array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
+                                       $link
+                               ) . "\n"
                        );
 
                };
@@ -689,7 +743,9 @@ EOT
                global $wgUser, $wgOut, $wgLang;
 
                $redirects = $this->getTitle()->getRedirectsHere( NS_FILE );
-               if ( count( $redirects ) == 0 ) return;
+               if ( count( $redirects ) == 0 ) {
+                       return;
+               }
 
                $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
                $wgOut->addWikiMsg( 'redirectstofile',
@@ -709,7 +765,6 @@ EOT
                        $wgOut->addHTML( "<li>{$link}</li>\n" );
                }
                $wgOut->addHTML( "</ul></div>\n" );
-
        }
 
        protected function imageDupes() {
@@ -718,7 +773,9 @@ EOT
                $this->loadFile();
 
                $dupes = $this->getDuplicates();
-               if ( count( $dupes ) == 0 ) return;
+               if ( count( $dupes ) == 0 ) {
+                       return;
+               }
 
                $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
                $wgOut->addWikiMsg( 'duplicatesoffile',
@@ -761,7 +818,7 @@ EOT
                $this->loadFile();
                if ( !$this->img->exists() || !$this->img->isLocal() || $this->img->getRedirected() ) {
                        // Standard article deletion
-                       Article::delete();
+                       parent::delete();
                        return;
                }
                $deleter = new FileDeleteForm( $this->img );
@@ -783,13 +840,13 @@ EOT
        public function doPurge() {
                $this->loadFile();
                if ( $this->img->exists() ) {
-                       wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
+                       wfDebug( 'ImagePage::doPurge purging ' . $this->img->getName() . "\n" );
                        $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
                        $update->doUpdate();
                        $this->img->upgradeRow();
                        $this->img->purgeCache();
                } else {
-                       wfDebug( "ImagePage::doPurge no image for " . $this->img->getName() . "; limiting purge to cache only\n" );
+                       wfDebug( 'ImagePage::doPurge no image for ' . $this->img->getName() . "; limiting purge to cache only\n" );
                        // even if the file supposedly doesn't exist, force any cached information
                        // to be updated (in case the cached information is wrong)
                        $this->img->purgeCache();
@@ -802,14 +859,13 @@ EOT
         */
        function showError( $description ) {
                global $wgOut;
-               $wgOut->setPageTitle( wfMsg( "internalerror" ) );
-               $wgOut->setRobotPolicy( "noindex,nofollow" );
+               $wgOut->setPageTitle( wfMsg( 'internalerror' ) );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->setArticleRelated( false );
                $wgOut->enableClientCache( false );
                $wgOut->addWikiText( $description );
        }
 
-
        /**
         * Callback for usort() to do link sorts by (namespace, title)
         * Function copied from Title::compare()
@@ -834,8 +890,32 @@ EOT
  */
 class ImageHistoryList {
 
-       protected $imagePage, $img, $skin, $title, $repo, $showThumb;
+       /**
+        * @var Title
+        */
+       protected $title;
+
+       /**
+        * @var File
+        */
+       protected $img;
 
+       /**
+        * @var ImagePage
+        */
+       protected $imagePage;
+
+       /**
+        * @var Skin
+        */
+       protected $skin;
+
+       protected $repo, $showThumb;
+       protected $preventClickjacking = false;
+
+       /**
+        * @param ImagePage $imagePage
+        */
        public function __construct( $imagePage ) {
                global $wgUser, $wgShowArchiveThumbnails;
                $this->skin = $wgUser->getSkin();
@@ -866,7 +946,7 @@ class ImageHistoryList {
                        . $navLinks . "\n"
                        . Xml::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n"
                        . '<tr><td></td>'
-                       . ( $this->current->isLocal() && ( $wgUser->isAllowed( 'delete' ) || $wgUser->isAllowed( 'deletedhistory' ) ) ? '<td></td>' : '' )
+                       . ( $this->current->isLocal() && ( $wgUser->isAllowedAny( 'delete', 'deletedhistory' ) ) ? '<td></td>' : '' )
                        . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
                        . ( $this->showThumb ? '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>' : '' )
                        . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
@@ -879,8 +959,13 @@ class ImageHistoryList {
                return "</table>\n$navLinks\n</div>\n";
        }
 
+       /**
+        * @param $iscur
+        * @param $file File
+        * @return string
+        */
        public function imageHistoryLine( $iscur, $file ) {
-               global $wgUser, $wgLang, $wgContLang;
+               global $wgUser, $wgLang;
 
                $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
                $img = $iscur ? $file->getName() : $file->getArchiveName();
@@ -889,16 +974,17 @@ class ImageHistoryList {
                $description = $file->getDescription();
 
                $local = $this->current->isLocal();
-               $row = $css = $selected = '';
+               $row = $selected = '';
 
                // Deletion link
-               if ( $local && ( $wgUser->isAllowed( 'delete' ) || $wgUser->isAllowed( 'deletedhistory' ) ) ) {
+               if ( $local && ( $wgUser->isAllowedAny( 'delete', 'deletedhistory' ) ) ) {
                        $row .= '<td>';
                        # Link to remove from history
                        if ( $wgUser->isAllowed( 'delete' ) ) {
                                $q = array( 'action' => 'delete' );
-                               if ( !$iscur )
+                               if ( !$iscur ) {
                                        $q['oldimage'] = $img;
+                               }
                                $row .= $this->skin->link(
                                        $this->title,
                                        wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ),
@@ -961,6 +1047,7 @@ class ImageHistoryList {
                        # Don't link to unviewable files
                        $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
                } elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
+                       $this->preventClickjacking();
                        $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
                        # Make a link to review the image
                        $url = $this->skin->link(
@@ -989,7 +1076,7 @@ class ImageHistoryList {
                // Image dimensions + size
                $row .= '<td>';
                $row .= htmlspecialchars( $file->getDimensionsString() );
-               $row .= " <span style='white-space: nowrap;'>(" . $this->skin->formatSize( $file->getSize() ) . ')</span>';
+               $row .= ' <span style="white-space: nowrap;">(' . $this->skin->formatSize( $file->getSize() ) . ')</span>';
                $row .= '</td>';
 
                // Uploading user
@@ -999,8 +1086,8 @@ class ImageHistoryList {
                        if ( $file->isDeleted( File::DELETED_USER ) ) {
                                $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
                        } else {
-                               $row .= $this->skin->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
-                                       $this->skin->userToolLinks( $user, $usertext ) . "</span>";
+                               $row .= $this->skin->userLink( $user, $usertext ) . ' <span style="white-space: nowrap;">' .
+                                       $this->skin->userToolLinks( $user, $usertext ) . '</span>';
                        }
                } else {
                        $row .= htmlspecialchars( $usertext );
@@ -1015,12 +1102,17 @@ class ImageHistoryList {
                }
                $row .= '</td>';
 
+               $rowClass = null;
                wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
-               $classAttr = $rowClass ? " class='$rowClass'" : "";
+               $classAttr = $rowClass ? " class='$rowClass'" : '';
 
                return "<tr{$classAttr}>{$row}</tr>\n";
        }
 
+       /**
+        * @param $file File
+        * @return string
+        */
        protected function getThumbForLine( $file ) {
                global $wgLang;
 
@@ -1040,16 +1132,41 @@ class ImageHistoryList {
                                'file-link' => true,
                        );
                        
-                       if ( !$thumbnail ) return wfMsgHtml( 'filehist-nothumb' );
+                       if ( !$thumbnail ) {
+                               return wfMsgHtml( 'filehist-nothumb' );
+                       }
 
                        return $thumbnail->toHtml( $options );
                } else {
                        return wfMsgHtml( 'filehist-nothumb' );
                }
        }
+
+       protected function preventClickjacking( $enable = true ) {
+               $this->preventClickjacking = $enable;
+       }
+
+       public function getPreventClickjacking() {
+               return $this->preventClickjacking;
+       }
 }
 
 class ImageHistoryPseudoPager extends ReverseChronologicalPager {
+       protected $preventClickjacking = false;
+
+       /**
+        * @var File
+        */
+       protected $mImg;
+
+       /**
+        * @var Title
+        */
+       protected $mTitle;
+
+       /**
+        * @param ImagePage $imagePage
+        */
        function __construct( $imagePage ) {
                parent::__construct();
                $this->mImagePage = $imagePage;
@@ -1090,12 +1207,18 @@ class ImageHistoryPseudoPager extends ReverseChronologicalPager {
                                $s .= $list->imageHistoryLine( !$file->isOld(), $file );
                        }
                        $s .= $list->endImageHistoryList( $navLink );
+
+                       if ( $list->getPreventClickjacking() ) {
+                               $this->preventClickjacking();
+                       }
                }
                return $s;
        }
 
        function doQuery() {
-               if ( $this->mQueryDone ) return;
+               if ( $this->mQueryDone ) {
+                       return;
+               }
                $this->mImg = $this->mImagePage->getFile(); // ensure loading
                if ( !$this->mImg->exists() ) {
                        return;
@@ -1172,4 +1295,13 @@ class ImageHistoryPseudoPager extends ReverseChronologicalPager {
                }
                $this->mQueryDone = true;
        }
+       
+       protected function preventClickjacking( $enable = true ) {
+               $this->preventClickjacking = $enable;
+       }
+
+       public function getPreventClickjacking() {
+               return $this->preventClickjacking;
+       }
+
 }