X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=5d4274d3ef3da14b197cf2979626966ca28531cc;hb=0db8ece2b11070d5cd923743af27ed4ba8429042;hp=4d090d522207a0f49f522f008447ecf525a9973d;hpb=af2177edfd9b108eca8598f9ace57672f0521942;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 4d090d5222..5d4274d3ef 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -27,7 +27,7 @@ class ImagePage extends Article { } function view() { - global $wgUseExternalEditor, $wgOut, $wgShowEXIF; + global $wgOut, $wgShowEXIF; $this->img = new Image( $this->mTitle ); @@ -44,8 +44,6 @@ class ImagePage extends Article { $wgOut->addHTML($this->showTOC($showmeta)); $this->openShowImage(); - if ($exif) - $wgOut->addWikiText($this->makeMetadataTable($exif)); # No need to display noarticletext, we use our own message, output in openShowImage() if( $this->getID() ) { @@ -69,6 +67,16 @@ class ImagePage extends Article { $this->closeShowImage(); $this->imageHistory(); $this->imageLinks(); + if( $exif ) { + global $wgStylePath; + $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) ); + $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) ); + $wgOut->addHTML( "

" . wfMsgHtml( 'metadata' ) . "

\n" ); + $wgOut->addWikiText( $this->makeMetadataTable( $exif ) ); + $wgOut->addHTML( + "\n" . + "\n" ); + } } else { Article::view(); } @@ -85,10 +93,10 @@ class ImagePage extends Article { function showTOC( $metadata ) { global $wgLang; $r = ''; return $r; } @@ -102,15 +110,40 @@ class ImagePage extends Article { * @return string */ function makeMetadataTable( $exif ) { - $r = "{| class=metadata align=right width=250px\n"; - $r .= '|+ id=metadata | '. htmlspecialchars( wfMsgHtml( 'metadata' ) ) . "\n"; + $r = wfMsg( 'metadata-help' ) . "\n\n"; + $r .= "{| id=mw_metadata class=mw_metadata\n"; + $visibleFields = $this->visibleMetadataFields(); foreach( $exif as $k => $v ) { $tag = strtolower( $k ); - $r .= "! class=$tag |" . wfMsg( "exif-$tag" ) . "\n"; - $r .= "| class=$tag |" . htmlspecialchars( $v ) . "\n"; - $r .= "|-\n"; + $msg = wfMsg( "exif-$tag" ); + $class = "exif-$tag"; + if( !in_array( $tag, $visibleFields ) ) { + $class .= ' collapsable'; + } + $r .= "|- class=\"$class\"\n"; + $r .= "!| $msg\n"; + $r .= "|| $v\n"; } - return substr($r, 0, -3) . '|}'; + $r .= '|}'; + return $r; + } + + /** + * Get a list of EXIF metadata items which should be displayed when + * the metadata table is collapsed. + * + * @return array of strings + * @access private + */ + function visibleMetadataFields() { + $fields = array(); + $lines = explode( "\n", wfMsgForContent( 'metadata-fields' ) ); + foreach( $lines as $line ) { + if( preg_match( '/^\\*\s*(.*?)\s*$/', $line, $matches ) ) { + $fields[] = $matches[1]; + } + } + return $fields; } /** @@ -127,12 +160,10 @@ class ImagePage extends Article { return Article::getContent( $noredir ); } - function openShowImage() - { - global $wgOut, $wgUser, $wgImageLimits, $wgRequest, - $wgUseImageResize, $wgRepositoryBaseUrl, - $wgUseExternalEditor, $wgServer, $wgFetchCommonsDescriptions; - $full_url = $this->img->getViewURL(); + function openShowImage() { + global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize; + + $full_url = $this->img->getURL(); $anchoropen = ''; $anchorclose = ''; @@ -160,33 +191,45 @@ class ImagePage extends Article { # "Download high res version" link below the image $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) ); - if ( $width > $maxWidth ) { - $height = floor( $height * $maxWidth / $width ); - $width = $maxWidth; - } - if ( $height > $maxHeight ) { - $width = floor( $width * $maxHeight / $height ); - $height = $maxHeight; - } - if ( !$this->img->mustRender() - && ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) ) { + + # We'll show a thumbnail of this image + if ( $width > $maxWidth || $height > $maxHeight ) { + # Calculate the thumbnail size. + # First case, the limiting factor is the width, not the height. + if ( $width / $height >= $maxWidth / $maxHeight ) { + $height = round( $height * $maxWidth / $width); + $width = $maxWidth; + # Note that $height <= $maxHeight now. + } else { + $newwidth = floor( $width * $maxHeight / $height); + $height = round( $height * $newwidth / $width ); + $width = $newwidth; + # Note that $height <= $maxHeight now, but might not be identical + # because of rounding. + } + if( $wgUseImageResize ) { $thumbnail = $this->img->getThumbnail( $width ); if ( $thumbnail == null ) { - $url = $full_url; + $url = $this->img->getViewURL(); } else { - $url = $thumbnail->getUrl(); + $url = $thumbnail->getURL(); } } else { # No resize ability? Show the full image, but scale # it down in the browser so it fits on the page. - $url = $full_url; + $url = $this->img->getViewURL(); } $anchoropen = ""; - $anchorclose = "
\n$anchoropen{$msg}"; + $anchorclose = "
"; + if( $this->img->mustRender() ) { + $showLink = true; + } else { + $anchorclose .= "\n$anchoropen{$msg}"; + } } else { - $url = $full_url; - $showLink = $this->img->mustRender(); + $url = $this->img->getViewURL(); + $showLink = true; } $wgOut->addHTML( '' ); } - + $showLink = true; } @@ -210,7 +253,7 @@ class ImagePage extends Article { $info = wfMsg( 'fileinfo', ceil($this->img->getSize()/1024.0), $this->img->getMimeType() ); - + if (!$this->img->isSafeFile()) { $warning = wfMsg( 'mediawarning' ); $wgOut->addWikiText( <<mTitle->getDBkey()); - $sharedtext = "
" . wfMsg("sharedupload"); + $sharedtext = "
" . wfMsgWikiHtml("sharedupload"); if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) { $sk = $wgUser->getSkin(); $title = Title::makeTitle( NS_SPECIAL, 'Upload' ); $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'), array( 'wpDestFile' => urlencode( $this->img->getName() ))); - $sharedtext .= " " . wfMsgHtml('shareduploadwiki', $link); + $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link); } $sharedtext .= "
"; $wgOut->addHTML($sharedtext); @@ -286,9 +329,11 @@ END return; $sk = $wgUser->getSkin(); - $wgOut->addHTML( '