PHPDocumentor [http://en.wikipedia.org/wiki/PhpDocumentor] documentation tweaking...
[lhc/web/wiklou.git] / includes / ImagePage.php
index 102ae49..d7639d9 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 /**
- * @package MediaWiki
  */
 
 /**
@@ -11,7 +10,6 @@ if( !defined( 'MEDIAWIKI' ) )
 
 /**
  * Special handling for image description pages
- * @package MediaWiki
  */
 class ImagePage extends Article {
 
@@ -29,59 +27,62 @@ class ImagePage extends Article {
        }
 
        function view() {
-               global $wgOut, $wgShowEXIF;
+               global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
 
                $this->img = new Image( $this->mTitle );
 
-               if( $this->mTitle->getNamespace() == NS_IMAGE  ) {
-                       if ($wgShowEXIF && $this->img->exists()) {
-                               $exif = $this->img->getExifData();
-                               $showmeta = count($exif) ? true : false;
-                       } else {
-                               $exif = false;
-                               $showmeta = false;
-                       }
+               $diff = $wgRequest->getVal( 'diff' );
+               $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
 
-                       if ($this->img->exists())
-                               $wgOut->addHTML($this->showTOC($showmeta));
+               if ( $this->mTitle->getNamespace() != NS_IMAGE || ( isset( $diff ) && $diffOnly ) )
+                       return Article::view();
 
-                       $this->openShowImage();
+               if ($wgShowEXIF && $this->img->exists()) {
+                       $exif = $this->img->getExifData();
+                       $showmeta = count($exif) ? true : false;
+               } else {
+                       $exif = false;
+                       $showmeta = false;
+               }
 
-                       # No need to display noarticletext, we use our own message, output in openShowImage()
-                       if( $this->getID() ) {
-                               Article::view();
-                       } else {
-                               # Just need to set the right headers
-                               $wgOut->setArticleFlag( true );
-                               $wgOut->setRobotpolicy( 'index,follow' );
-                               $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
-                               $this->viewUpdates();
-                       }
+               if ($this->img->exists())
+                       $wgOut->addHTML($this->showTOC($showmeta));
 
-                       # Show shared description, if needed
-                       if( $this->mExtraDescription ) {
-                               $fol = wfMsg( 'shareddescriptionfollows' );
-                               if( $fol != '-' ) {
-                                       $wgOut->addWikiText( $fol );
-                               }
-                               $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
-                       }
+               $this->openShowImage();
 
-                       $this->closeShowImage();
-                       $this->imageHistory();
-                       $this->imageLinks();
-                       if( $exif ) {
-                               global $wgStylePath, $wgStyleVersion;
-                               $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
-                               $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
-                               $wgOut->addHTML( "<h2 id=\"metadata\">" . wfMsgHtml( 'metadata' ) . "</h2>\n" );
-                               $wgOut->addWikiText( $this->makeMetadataTable( $exif ) );
-                               $wgOut->addHTML(
-                                       "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js?wgStyleVersion\"></script>\n" .
-                                       "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
-                       }
-               } else {
+               # No need to display noarticletext, we use our own message, output in openShowImage()
+               if ( $this->getID() ) {
                        Article::view();
+               } else {
+                       # Just need to set the right headers
+                       $wgOut->setArticleFlag( true );
+                       $wgOut->setRobotpolicy( 'index,follow' );
+                       $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
+                       $this->viewUpdates();
+               }
+
+               # Show shared description, if needed
+               if ( $this->mExtraDescription ) {
+                       $fol = wfMsg( 'shareddescriptionfollows' );
+                       if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
+                               $wgOut->addWikiText( $fol );
+                       }
+                       $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
+               }
+
+               $this->closeShowImage();
+               $this->imageHistory();
+               $this->imageLinks();
+
+               if ( $exif ) {
+                       global $wgStylePath, $wgStyleVersion;
+                       $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
+                       $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
+                       $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
+                       $wgOut->addWikiText( $this->makeMetadataTable( $exif ) );
+                       $wgOut->addHTML(
+                               "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js?$wgStyleVersion\"></script>\n" .
+                               "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
                }
        }
 
@@ -142,6 +143,7 @@ class ImagePage extends Article {
                $fields = array();
                $lines = explode( "\n", wfMsgForContent( 'metadata-fields' ) );
                foreach( $lines as $line ) {
+                       $matches = array();
                        if( preg_match( '/^\\*\s*(.*?)\s*$/', $line, $matches ) ) {
                                $fields[] = $matches[1];
                        }
@@ -169,14 +171,16 @@ class ImagePage extends Article {
                $full_url  = $this->img->getURL();
                $anchoropen = '';
                $anchorclose = '';
-
-               if( $wgUser->getOption( 'imagesize' ) == '' ) {
-                       $sizeSel = User::getDefaultOption( 'imagesize' );
-               } else {
-                       $sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
-               }
+               $sizeSel = intval( $wgUser->getOption( 'imagesize') );
                if( !isset( $wgImageLimits[$sizeSel] ) ) {
                        $sizeSel = User::getDefaultOption( 'imagesize' );
+
+                       // The user offset might still be incorrect, specially if
+                       // $wgImageLimits got changed (see bug #8858).
+                       if( !isset( $wgImageLimits[$sizeSel] ) ) {
+                               // Default to the first offset in $wgImageLimits
+                               $sizeSel = 0;
+                       }
                }
                $max = $wgImageLimits[$sizeSel];
                $maxWidth = $max[0];
@@ -191,16 +195,19 @@ class ImagePage extends Article {
                        } else {
                                $page = 1;
                        }
-                       $width = $this->img->getWidth();
-                       $height = $this->img->getHeight();
+                       $width_orig = $this->img->getWidth();
+                       $width = $width_orig;
+                       $height_orig = $this->img->getHeight();
+                       $height = $height_orig;
+                       $mime = $this->img->getMimeType();
                        $showLink = false;
 
                        if ( $this->img->allowInlineDisplay() and $width and $height) {
                                # image
 
                                # "Download high res version" link below the image
-                               $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
-
+                               $msgbig  = wfMsgHtml('show-big-image');
+                               $msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
                                # We'll show a thumbnail of this image
                                if ( $width > $maxWidth || $height > $maxHeight ) {
                                        # Calculate the thumbnail size.
@@ -234,7 +241,8 @@ class ImagePage extends Article {
                                        if( $this->img->mustRender() ) {
                                                $showLink = true;
                                        } else {
-                                               $anchorclose .= "\n$anchoropen{$msg}</a>";
+                                               $anchorclose .= wfMsg('show-big-image-thumb', $width, $height ) .
+                                                       '<br />' . "\n$anchoropen{$msgbig}</a> " . $msgsize;
                                        }
                                } else {
                                        $url = $this->img->getViewURL();
@@ -247,7 +255,7 @@ class ImagePage extends Article {
 
                                $wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .
                                     "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
-                                    htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>' );
+                                    htmlspecialchars( $this->img->getTitle()->getPrefixedText() ).'" />' . $anchorclose . '</div>' );
 
                                if ( $this->img->isMultipage() ) {
                                        $count = $this->img->pageCount();
@@ -270,7 +278,11 @@ class ImagePage extends Article {
                                                $thumb2 = '';
                                        }
 
-                                       $select = '<form name="pageselector" action="' . $this->img->getEscapeLocalUrl( '' ) . '" method="GET" onchange="document.pageselector.submit();">' ;
+                                       global $wgScript;
+                                       $select = '<form name="pageselector" action="' . 
+                                               htmlspecialchars( $wgScript ) .
+                                               '" method="get" onchange="document.pageselector.submit();">' .
+                                               Xml::hidden( 'title', $this->getTitle()->getPrefixedDbKey() );
                                        $select .= $wgOut->parse( wfMsg( 'imgmultigotopre' ), false ) .
                                                ' <select id="pageselector" name="page">';
                                        for ( $i=1; $i <= $count; $i++ ) {
@@ -299,25 +311,35 @@ class ImagePage extends Article {
 
 
                        if ($showLink) {
-                               $filename = wfEscapeWikiText( $this->img->getName() );
                                // Hacky workaround: for some reason we use the incorrect MIME type
                                // image/svg for SVG.  This should be fixed internally, but at least
                                // make the displayed type right.
-                               $mime = $this->img->getMimeType();
                                if ($mime == 'image/svg') $mime = 'image/svg+xml';
 
-                               $info = wfMsg( 'fileinfo',
-                                       ceil($this->img->getSize()/1024.0),
-                                       $mime );
+                               $filename = wfEscapeWikiText( $this->img->getName() );
+                               $info = wfMsg( 'file-info', $sk->formatSize( $this->img->getSize() ), $mime );
+                               $infores = '';
+
+                               // Check for MIME type. Other types may have more information in the future.
+                               if (substr($mime,0,9) == 'image/svg' ) {
+                                       $infores = wfMsg('file-svg', $width_orig, $height_orig ) . '<br />';
+                               } elseif ( substr($mime,0,5) == 'image' ) { 
+                                       $infores = wfMsg('file-nohires') . '<br />';
+                                       $info = wfMsg( 
+                                               'file-info-size',
+                                               $width_orig, $height_orig,
+                                               $sk->formatSize( $this->img->getSize() ),
+                                               $mime );
+                               }
 
                                global $wgContLang;
                                $dirmark = $wgContLang->getDirMark();
                                if (!$this->img->isSafeFile()) {
                                        $warning = wfMsg( 'mediawarning' );
                                        $wgOut->addWikiText( <<<END
-<div class="fullMedia">
+<div class="fullMedia">$infores
 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
-<span class="fileInfo"> ($info)</span>
+<span class="fileInfo"> $info</span>
 </div>
 
 <div class="mediaWarning">$warning</div>
@@ -325,8 +347,8 @@ END
                                                );
                                } else {
                                        $wgOut->addWikiText( <<<END
-<div class="fullMedia">
-[[Media:$filename|$filename]]$dirmark <span class="fileInfo"> ($info)</span>
+<div class="fullMedia">$infores
+[[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $info</span>
 </div>
 END
                                                );
@@ -363,7 +385,9 @@ END
                $wgOut->addHTML($sharedtext);
 
                if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
-                       $text = Http::get($url . '?action=render');
+                       $renderUrl = wfAppendQuery( $url, 'action=render' );
+                       wfDebug( "Fetching shared description from $renderUrl\n" );
+                       $text = Http::get( $renderUrl );
                        if ($text)
                                $this->mExtraDescription = $text;
                }
@@ -392,11 +416,11 @@ END
                # "Upload a new version of this file" link
                if( $wgUser->isAllowed( 'reupload' ) ) {
                        $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
-                       $wgOut->addHtml( "<li><div>{$ulink}</div></li>" );
+                       $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
                }
                
                # External editing link
-               $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
+               $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
                $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
                
                $wgOut->addHtml( '</ul>' );
@@ -452,9 +476,9 @@ END
        {
                global $wgUser, $wgOut;
 
-               $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
+               $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'filelinks' ), wfMsg( 'imagelinks' ) ) . "\n" );
 
-               $dbr =& wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
                $page = $dbr->tableName( 'page' );
                $imagelinks = $dbr->tableName( 'imagelinks' );
 
@@ -536,15 +560,10 @@ END
         * @param $reason User provided reason for deletion.
         */
        function doDelete( $reason ) {
-               global $wgOut, $wgRequest, $wgUseSquid;
-               global $wgPostCommitUpdateList;
-
-               $fname = 'ImagePage::doDelete';
+               global $wgOut, $wgRequest;
 
                $oldimage = $wgRequest->getVal( 'oldimage' );
 
-               $dbw =& wfGetDB( DB_MASTER );
-
                if ( !is_null( $oldimage ) ) {
                        if ( strlen( $oldimage ) < 16 ) {
                                $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
@@ -627,7 +646,7 @@ END
                        $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
                        return;
                }
-               if ( ! $this->mTitle->userCanEdit() ) {
+               if ( ! $this->mTitle->userCan( 'edit' ) ) {
                        $wgOut->readOnlyPage( $this->getContent(), true );
                        return;
                }
@@ -653,9 +672,6 @@ END
                }
                $oldver = wfTimestampNow() . "!{$name}";
 
-               $dbr =& wfGetDB( DB_SLAVE );
-               $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage )  );
-
                if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
                        $wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" );
                        return;
@@ -702,7 +718,6 @@ END
 
 /**
  * @todo document
- * @package MediaWiki
  */
 class ImageHistoryList {
        function ImageHistoryList( &$skin ) {
@@ -710,8 +725,9 @@ class ImageHistoryList {
        }
 
        function beginImageHistoryList() {
-               $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
-                 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
+               $s = "\n" .
+                       Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'imghistory' ) ) .
+                       "\n<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
                return $s;
        }
 
@@ -724,9 +740,9 @@ class ImageHistoryList {
                global $wgUser, $wgLang, $wgTitle, $wgContLang;
 
                $datetime = $wgLang->timeanddate( $timestamp, true );
-               $del = wfMsg( 'deleteimg' );
-               $delall = wfMsg( 'deleteimgcompletely' );
-               $cur = wfMsg( 'cur' );
+               $del = wfMsgHtml( 'deleteimg' );
+               $delall = wfMsgHtml( 'deleteimgcompletely' );
+               $cur = wfMsgHtml( 'cur' );
 
                if ( $iscur ) {
                        $url = Image::imageUrl( $img );
@@ -742,10 +758,10 @@ class ImageHistoryList {
                        }
                } else {
                        $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
-                       if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
+                       if( $wgUser->getID() != 0 && $wgTitle->userCan( 'edit' ) ) {
                                $token = urlencode( $wgUser->editToken( $img ) );
                                $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
-                                          wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
+                                          wfMsgHtml( 'revertimg' ), 'action=revert&oldimage=' .
                                           urlencode( $img ) . "&wpEditToken=$token" );
                                $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
                                           $del, 'action=delete&oldimage=' . urlencode( $img ) .
@@ -754,7 +770,7 @@ class ImageHistoryList {
                                # Having live active links for non-logged in users
                                # means that bots and spiders crawling our site can
                                # inadvertently change content. Baaaad idea.
-                               $rlink = wfMsg( 'revertimg' );
+                               $rlink = wfMsgHtml( 'revertimg' );
                                $dlink = $del;
                        }
                }
@@ -762,7 +778,7 @@ class ImageHistoryList {
                $userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
                $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
                        $wgLang->formatNum( $size ) );
-               $widthheight = wfMsg( 'widthheight', $width, $height );
+               $widthheight = wfMsgHtml( 'widthheight', $width, $height );
                $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
 
                $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";