Fixed some doxygen warnings
[lhc/web/wiklou.git] / includes / ImagePage.php
index ccfd01d..dd2c2ab 100644 (file)
@@ -84,6 +84,8 @@ class ImagePage extends Article {
 
                if( $this->mTitle->getNamespace() != NS_FILE || ( isset( $diff ) && $diffOnly ) )
                        return Article::view();
+                       
+               $this->showRedirectedFromHeader();
 
                if( $wgShowEXIF && $this->displayImg->exists() ) {
                        // FIXME: bad interface, see note on MediaHandler::formatMetadata().
@@ -130,6 +132,12 @@ class ImagePage extends Article {
                # Yet we return metadata about the target. Definitely an issue in the FileRepo
                $this->imageRedirects();
                $this->imageLinks();
+               
+               # Allow extensions to add something after the image links
+               $html = '';
+               wfRunHooks( 'ImagePageAfterImageLinks', array( $this, &$html ) );
+               if ( $html)
+                       $wgOut->addHTML( $html );
 
                if( $showmeta ) {
                        global $wgStylePath, $wgStyleVersion;
@@ -222,14 +230,18 @@ class ImagePage extends Article {
         * @return string
         */
        protected function showTOC( $metadata ) {
-               global $wgLang;
-               $r = '<ul id="filetoc">
-                       <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>\n" .
-                       ($metadata ? '                  <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . "
-                       </ul>\n";
-               return $r;
+               $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>', 
+               );
+               if ( $metadata ) {
+                       $r[] = '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>';
+               }
+       
+               wfRunHooks( 'ImagePageShowTOC', array( $this, &$r ) );
+               
+               return '<ul id="filetoc">' . implode( "\n", $r ) . '</ul>';
        }
 
        /**
@@ -317,7 +329,7 @@ class ImagePage extends Article {
                        $linkAttribs = array( 'href' => $full_url );
                        $longDesc = $this->displayImg->getLongDesc();
 
-                       wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) )       ;
+                       wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this, &$wgOut ) );
 
                        if( $this->displayImg->allowInlineDisplay() ) {
                                # image
@@ -362,7 +374,8 @@ class ImagePage extends Article {
                                                '<br />' . Xml::tags( 'a', $linkAttribs,  $msgbig ) . "$dirmark " . $longDesc;
                                }
 
-                               if( $this->displayImg->isMultipage() ) {
+                               $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
+                               if( $isMulti ) {
                                        $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
                                }
 
@@ -376,7 +389,7 @@ class ImagePage extends Article {
                                                $anchorclose . "</div>\n" );
                                }
 
-                               if( $this->displayImg->isMultipage() ) {
+                               if( $isMulti ) {
                                        $count = $this->displayImg->pageCount();
 
                                        if( $page > 1 ) {
@@ -441,7 +454,7 @@ class ImagePage extends Article {
                                        $icon= $this->displayImg->iconThumb();
 
                                        $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
-                                       $icon->toHtml( array( 'desc-link' => true ) ) .
+                                       $icon->toHtml( array( 'file-link' => true ) ) .
                                        "</div>\n" );
                                }
 
@@ -538,7 +551,7 @@ EOT
         * external editing (and instructions link) etc.
         */
        protected function uploadLinksBox() {
-               global $wgUser, $wgOut, $wgEnableUploads;
+               global $wgUser, $wgOut, $wgEnableUploads, $wgUseExternalEditor;
 
                if( !$wgEnableUploads ) { return; }
 
@@ -551,24 +564,26 @@ EOT
                $wgOut->addHTML( "<br /><ul>\n" );
 
                # "Upload a new version of this file" link
-               if( UploadForm::userCanReUpload($wgUser,$this->img->name) ) {
+               if( UploadBase::userCanReUpload($wgUser,$this->img->name) ) {
                        $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
                        $wgOut->addHTML( "<li id=\"mw-imagepage-reupload-link\"><div class=\"plainlinks\">{$ulink}</div></li>\n" );
                }
 
                # External editing link
-               $elink = $sk->link(
-                       $this->mTitle,
-                       wfMsgHtml( 'edit-externally' ),
-                       array(),
-                       array(
-                               'action' => 'edit',
-                               'externaledit' => 'true',
-                               'mode' => 'file'
-                       ),
-                       array( 'known', 'noclasses' )
-               );
-               $wgOut->addHTML( '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . "</small></li>\n" );
+               if ( $wgUseExternalEditor ) {
+                       $elink = $sk->link(
+                               $this->mTitle,
+                               wfMsgHtml( 'edit-externally' ),
+                               array(),
+                               array(
+                                       'action' => 'edit',
+                                       'externaledit' => 'true',
+                                       'mode' => 'file'
+                               ),
+                               array( 'known', 'noclasses' )
+                       );
+                       $wgOut->addHTML( '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . "</small></li>\n" );
+               }
 
                $wgOut->addHTML( "</ul>\n" );
        }
@@ -580,7 +595,7 @@ EOT
         * we follow it with an upload history of the image and its usage.
         */
        protected function imageHistory() {
-               global $wgOut, $wgUseExternalEditor;
+               global $wgOut;
 
                $this->loadFile();
                $pager = new ImageHistoryPseudoPager( $this );
@@ -590,7 +605,7 @@ EOT
 
                # Exist check because we don't want to show this on pages where an image
                # doesn't exist along with the noimage message, that would suck. -ævar
-               if( $wgUseExternalEditor && $this->img->exists() ) {
+               if( $this->img->exists() ) {
                        $this->uploadLinksBox();
                }
        }
@@ -720,6 +735,13 @@ EOT
         * Delete the file, or an earlier version of it
         */
        public function delete() {
+               global $wgUploadMaintenance;
+               if( $wgUploadMaintenance && $this->mTitle && $this->mTitle->getNamespace() == NS_FILE ) {
+                       global $wgOut;
+                       $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>\n", array( 'filedelete-maintenance' ) );
+                       return;
+               }
+
                $this->loadFile();
                if( !$this->img->exists() || !$this->img->isLocal() || $this->img->getRedirected() ) {
                        // Standard article deletion
@@ -789,7 +811,7 @@ class ImageHistoryList {
                $this->img = $imagePage->getDisplayedFile();
                $this->title = $imagePage->getTitle();
                $this->imagePage = $imagePage;
-               $this->showThumb = $wgShowArchiveThumbnails;
+               $this->showThumb = $wgShowArchiveThumbnails && $this->img->canRender();
        }
 
        public function getImagePage() {
@@ -812,7 +834,7 @@ class ImageHistoryList {
                        . $navLinks . "\n"
                        . Xml::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n"
                        . '<tr><td></td>'
-                       . ( $this->current->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '<td></td>' : '' )
+                       . ( $this->current->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deletedhistory') ) ? '<td></td>' : '' )
                        . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
                        . ( $this->showThumb ? '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>' : '' )
                        . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
@@ -838,7 +860,7 @@ class ImageHistoryList {
                $row = $css = $selected = '';
 
                // Deletion link
-               if( $local && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ) {
+               if( $local && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deletedhistory') ) ) {
                        $row .= '<td>';
                        # Link to remove from history
                        if( $wgUser->isAllowed( 'delete' ) ) {
@@ -851,32 +873,26 @@ class ImageHistoryList {
                                        array(), $q, array( 'known' )
                                );
                        }
-                       # Link to hide content
-                       if( $wgUser->isAllowed( 'deleterevision' ) ) {
+                       # Link to hide content. Don't show useless link to people who cannot hide revisions.
+                       $canHide = $wgUser->isAllowed( 'deleterevision' );
+                       if( $canHide || ($wgUser->isAllowed('deletedhistory') && $file->getVisibility()) ) {
                                if( $wgUser->isAllowed('delete') ) {
-                                       $row .= '<br/>';
+                                       $row .= '<br />';
                                }
-                               $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
                                // If file is top revision or locked from this user, don't link
                                if( $iscur || !$file->userCan(File::DELETED_RESTRICTED) ) {
-                                       $del = wfMsgHtml( 'rev-delundel' );
+                                       $del = $this->skin->revDeleteLinkDisabled( $canHide );
                                } else {
-                                       // If the file was hidden, link to sha-1
                                        list( $ts, $name ) = explode( '!', $img, 2 );
-                                       $del = $this->skin->link( $revdel, wfMsgHtml( 'rev-delundel' ),
-                                               array(),
-                                               array( 
-                                                       'type' => 'oldimage',
-                                                       'target' => $wgTitle->getPrefixedText(), 
-                                                       'ids' => $ts,
-                                               ),
-                                               array( 'known' )
+                                       $query = array(
+                                               'type'   => 'oldimage',
+                                               'target' => $wgTitle->getPrefixedText(), 
+                                               'ids'    => $ts,
                                        );
-                                       // Bolden oversighted content
-                                       if( $file->isDeleted(File::DELETED_RESTRICTED) )
-                                               $del = "<strong>$del</strong>";
+                                       $del = $this->skin->revDeleteLink( $query,
+                                               $file->isDeleted(File::DELETED_RESTRICTED), $canHide );
                                }
-                               $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
+                               $row .= $del;
                        }
                        $row .= '</td>';
                }
@@ -1007,7 +1023,7 @@ class ImageHistoryPseudoPager extends ReverseChronologicalPager {
                $this->mImagePage = $imagePage;
                $this->mTitle = clone( $imagePage->getTitle() );
                $this->mTitle->setFragment( '#filehistory' );
-               $this->mImg = NULL;
+               $this->mImg = null;
                $this->mHist = array();
                $this->mRange = array( 0, 0 ); // display range
        }