Add returntoquery= parameter to Special:Userlogin which adds a query string to the...
[lhc/web/wiklou.git] / includes / ImagePage.php
index 612d2a6..ccfd01d 100644 (file)
@@ -224,7 +224,7 @@ class ImagePage extends Article {
        protected function showTOC( $metadata ) {
                global $wgLang;
                $r = '<ul id="filetoc">
-                       <li><a href="#file">' . $wgLang->getNsText( NS_FILE ) . '</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>\n" .
                        ($metadata ? '                  <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . "
@@ -241,8 +241,8 @@ class ImagePage extends Article {
         * @return string
         */
        protected function makeMetadataTable( $metadata ) {
-               $r = "<div class=\"mw-imagepage-section-metadata\">\n";
-               $r .= wfMsg( 'metadata-help' );
+               $r = "<div class=\"mw-imagepage-section-metadata\">";
+               $r .= wfMsgNoTrans( 'metadata-help' );
                $r .= "<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
                foreach ( $metadata as $type => $stuff ) {
                        foreach ( $stuff as $v ) {
@@ -275,7 +275,8 @@ class ImagePage extends Article {
        }
 
        protected function openShowImage() {
-               global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
+               global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
+                       $wgLang, $wgContLang, $wgEnableUploads;
 
                $this->loadFile();
 
@@ -380,7 +381,13 @@ class ImagePage extends Article {
 
                                        if( $page > 1 ) {
                                                $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
-                                               $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page-1) );
+                                               $link = $sk->link(
+                                                       $this->mTitle,
+                                                       $label,
+                                                       array(),
+                                                       array( 'page' => $page - 1 ),
+                                                       array( 'known', 'noclasses' )
+                                               );
                                                $thumb1 = $sk->makeThumbLinkObj( $this->mTitle, $this->displayImg, $link, $label, 'none',
                                                        array( 'page' => $page - 1 ) );
                                        } else {
@@ -389,7 +396,13 @@ class ImagePage extends Article {
 
                                        if( $page < $count ) {
                                                $label = wfMsg( 'imgmultipagenext' );
-                                               $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page+1) );
+                                               $link = $sk->link(
+                                                       $this->mTitle,
+                                                       $label,
+                                                       array(),
+                                                       array( 'page' => $page + 1 ),
+                                                       array( 'known', 'noclasses' )
+                                               );
                                                $thumb2 = $sk->makeThumbLinkObj( $this->mTitle, $this->displayImg, $link, $label, 'none',
                                                        array( 'page' => $page + 1 ) );
                                        } else {
@@ -438,9 +451,7 @@ class ImagePage extends Article {
 
                        if($showLink) {
                                $filename = wfEscapeWikiText( $this->displayImg->getName() );
-                               $medialink = $this->displayImg->isMissing() ?
-                                       "'''$filename'''" :
-                                       "[[Media:$filename|$filename]]";
+                               $medialink = "[[Media:$filename|$filename]]";
 
                                if( !$this->displayImg->isSafeFile() ) {
                                        $warning = wfMsgNoTrans( 'mediawarning' );
@@ -459,7 +470,7 @@ EOT
 <span class="fileInfo">$longDesc</span>
 </div>
 EOT
-                                               );
+                                       );
                                }
                        }
 
@@ -468,12 +479,20 @@ EOT
                        }
                } else {
                        # Image does not exist
-
-                       $title = SpecialPage::getTitleFor( 'Upload' );
-                       $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
-                               'wpDestFile=' . urlencode( $this->displayImg->getName() ) );
+                       if ( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
+                               // Only show an upload link if the user can upload
+                               $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
+                               $nofile = array(
+                                       'filepage-nofile-link',
+                                       $uploadTitle->getFullUrl( array( 'wpDestFile' => $this->img->getName() ) )
+                               );
+                       }
+                       else
+                       {
+                               $nofile = 'filepage-nofile';
+                       }
                        $wgOut->setRobotPolicy( 'noindex,nofollow' );
-                       $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
+                       $wgOut->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
                }
        }
 
@@ -508,7 +527,10 @@ EOT
        public function getUploadUrl() {
                $this->loadFile();
                $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
-               return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) . '&wpForReUpload=1' );
+               return $uploadTitle->getFullUrl( array(
+                       'wpDestFile' => $this->img->getName(),
+                       'wpForReUpload' => 1
+                ) );
        }
 
        /**
@@ -516,7 +538,9 @@ EOT
         * external editing (and instructions link) etc.
         */
        protected function uploadLinksBox() {
-               global $wgUser, $wgOut;
+               global $wgUser, $wgOut, $wgEnableUploads;
+
+               if( !$wgEnableUploads ) { return; }
 
                $this->loadFile();
                if( !$this->img->isLocal() )
@@ -533,7 +557,17 @@ EOT
                }
 
                # External editing link
-               $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
+               $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" );
@@ -601,8 +635,13 @@ EOT
                        $count++;
                        if( $count <= $limit ) {
                                // We have not yet reached the extra one that tells us there is more to fetch
-                               $name = Title::makeTitle( $s->page_namespace, $s->page_title );
-                               $link = $sk->makeKnownLinkObj( $name, "" );
+                               $link = $sk->link(
+                                       Title::makeTitle( $s->page_namespace, $s->page_title ),
+                                       null,
+                                       array(),
+                                       array(),
+                                       array( 'known', 'noclasses' )
+                               );
                                $wgOut->addHTML( "<li>{$link}</li>\n" );
                        }
                }
@@ -629,7 +668,13 @@ EOT
 
                $sk = $wgUser->getSkin();
                foreach ( $redirects as $title ) {
-                       $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" );
+                       $link = $sk->link(
+                               $title,
+                               null,
+                               array(),
+                               array( 'redirect' => 'no' ),
+                               array( 'known', 'noclasses' )
+                       );
                        $wgOut->addHTML( "<li>{$link}</li>\n" );
                }
                $wgOut->addHTML( "</ul></div>\n" );
@@ -653,9 +698,15 @@ EOT
                $sk = $wgUser->getSkin();
                foreach ( $dupes as $file ) {
                        $fromSrc = '';
-                       if( $file->isLocal() )
-                               $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
-                       else {
+                       if( $file->isLocal() ) {
+                               $link = $sk->link(
+                                       $file->getTitle(),
+                                       null,
+                                       array(),
+                                       array(),
+                                       array( 'known', 'noclasses' )
+                               );
+                       } else {
                                $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
                                        $file->getTitle()->getPrefixedText() );
                                $fromSrc = wfMsg( 'shared-repo-from', $file->getRepo()->getDisplayName() );
@@ -729,15 +780,16 @@ EOT
  */
 class ImageHistoryList {
 
-       protected $imagePage, $img, $skin, $title, $repo;
+       protected $imagePage, $img, $skin, $title, $repo, $showThumb;
 
        public function __construct( $imagePage ) {
-               global $wgUser;
+               global $wgUser, $wgShowArchiveThumbnails;
                $this->skin = $wgUser->getSkin();
                $this->current = $imagePage->getFile();
                $this->img = $imagePage->getDisplayedFile();
                $this->title = $imagePage->getTitle();
                $this->imagePage = $imagePage;
+               $this->showThumb = $wgShowArchiveThumbnails;
        }
 
        public function getImagePage() {
@@ -758,11 +810,11 @@ class ImageHistoryList {
                        . "<div id=\"mw-imagepage-section-filehistory\">\n"
                        . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
                        . $navLinks . "\n"
-                       . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
+                       . Xml::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n"
                        . '<tr><td></td>'
                        . ( $this->current->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '<td></td>' : '' )
                        . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
-                       . '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>'
+                       . ( $this->showThumb ? '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>' : '' )
                        . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
                        . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
                        . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
@@ -781,7 +833,6 @@ class ImageHistoryList {
                $user = $file->getUser('id');
                $usertext = $file->getUser('text');
                $description = $file->getDescription();
-               $sha1 = $file->getSha1();
 
                $local = $this->current->isLocal();
                $row = $css = $selected = '';
@@ -814,7 +865,11 @@ class ImageHistoryList {
                                        list( $ts, $name ) = explode( '!', $img, 2 );
                                        $del = $this->skin->link( $revdel, wfMsgHtml( 'rev-delundel' ),
                                                array(),
-                                               array( 'target' => $wgTitle->getPrefixedText(), 'oldimage' => $ts ),
+                                               array( 
+                                                       'type' => 'oldimage',
+                                                       'target' => $wgTitle->getPrefixedText(), 
+                                                       'ids' => $ts,
+                                               ),
                                                array( 'known' )
                                        );
                                        // Bolden oversighted content
@@ -834,13 +889,17 @@ class ImageHistoryList {
                        if( $file->isDeleted(File::DELETED_FILE) ) {
                                $row .= wfMsgHtml('filehist-revert');
                        } else {
-                               $q = array();
-                               $q[] = 'action=revert';
-                               $q[] = 'oldimage=' . urlencode( $img );
-                               $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
-                               $row .= $this->skin->makeKnownLinkObj( $this->title,
+                               $row .= $this->skin->link(
+                                       $this->title,
                                        wfMsgHtml( 'filehist-revert' ),
-                                       implode( '&', $q ) );
+                                       array(),
+                                       array(
+                                               'action' => 'revert',
+                                               'oldimage' => $img,
+                                               'wpEditToken' => $wgUser->editToken( $img )
+                                       ),
+                                       array( 'known', 'noclasses' )
+                               );
                        }
                }
                $row .= '</td>';
@@ -856,12 +915,18 @@ class ImageHistoryList {
                } elseif( $file->isDeleted(File::DELETED_FILE) ) {
                        $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
                        # Make a link to review the image
-                       $url = $this->skin->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
-                               "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current->getExtension() );
+                       $url = $this->skin->link(
+                               $revdel,
+                               $wgLang->timeAndDate( $timestamp, true ),
+                               array(),
+                               array(
+                                       'target' => $wgTitle->getPrefixedText(),
+                                       'file' => $img,
+                                       'token' => $wgUser->editToken( $img )
+                               ),
+                               array( 'known', 'noclasses' )
+                       );
                        $row .= '<span class="history-deleted">'.$url.'</span>';
-               } elseif( $file->isMissing() ) {
-                       # Don't link to missing files
-                       $row .= $wgLang->timeAndDate( $timestamp, true );
                } else {
                        $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
                        $row .= Xml::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
@@ -869,7 +934,9 @@ class ImageHistoryList {
                $row .= "</td>";
 
                // Thumbnail
-               $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
+               if ( $this->showThumb ) {
+                       $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
+               }
 
                // Image dimensions + size
                $row .= '<td>';
@@ -909,9 +976,7 @@ class ImageHistoryList {
        protected function getThumbForLine( $file ) {
                global $wgLang;
 
-               if( $file->isMissing() ) {
-                       return '<strong class="error">' . wfMsgHtml( 'filehist-missing' ) . '</strong>';
-               } elseif( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE ) && !$file->isDeleted( File::DELETED_FILE ) ) {
+               if( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE ) && !$file->isDeleted( File::DELETED_FILE ) ) {
                        $params = array(
                                'width' => '120',
                                'height' => '120',
@@ -920,7 +985,10 @@ class ImageHistoryList {
 
                        $thumbnail = $file->transform( $params );
                        $options = array(
-                               'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ),
+                               'alt' => wfMsg( 'filehist-thumbtext',
+                                       $wgLang->timeAndDate( $timestamp, true ),
+                                       $wgLang->date( $timestamp, true ),
+                                       $wgLang->time( $timestamp, true ) ),
                                'file-link' => true,
                        );