* Fixed a typo that caused warnings
[lhc/web/wiklou.git] / includes / Linker.php
index fbecbd9..3f35d9c 100644 (file)
@@ -20,7 +20,7 @@ class Linker {
        function Linker() {}
 
        /**
-        * OBSOLETE
+        * @deprecated
         */
        function postParseLinkColour( $s = NULL ) {
                return NULL;
@@ -130,7 +130,7 @@ class Linker {
        /**
         * Pass a title object, not a title string
         */
-       function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
+       function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
                global $wgOut, $wgUser;
                $fname = 'Linker::makeLinkObj';
                wfProfileIn( $fname );
@@ -368,7 +368,7 @@ class Linker {
        }
 
        /** @todo document */
-       function makeImageLinkObj( &$nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false, 
+       function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false, 
          $thumb = false, $manual_thumb = '' ) 
        {
                global $wgContLang, $wgUser, $wgThumbLimits;
@@ -377,6 +377,8 @@ class Linker {
                $url   = $img->getViewURL();
                $prefix = $postfix = '';
                
+               wfDebug( "makeImageLinkObj: '$width'x'$height'\n" );
+               
                if ( 'center' == $align )
                {
                        $prefix  = '<div class="center">';
@@ -418,13 +420,27 @@ class Linker {
                        if ( $height !== false && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
                                $width = $img->getWidth() * $height / $img->getHeight();
                        }
-                       if ( '' == $manual_thumb ) {
+                       if ( $manual_thumb == '') {
                                $thumb = $img->getThumbnail( $width );
-                               $height = $thumb->height;
-                               $url = $thumb->getUrl( );
+                               if ( $thumb ) {
+                                       if( $width > $thumb->width ) {
+                                               // Requested a display size larger than the actual image;
+                                               // fake it up!
+                                               $height = floor($thumb->height * $width / $thumb->width);
+                                               wfDebug( "makeImageLinkObj: client-size height set to '$height'\n" );
+                                       } else {
+                                               $height = $thumb->height;
+                                               wfDebug( "makeImageLinkObj: thumb height set to '$height'\n" );
+                                       }
+                                       $url = $thumb->getUrl();
+                               }
                        }
+               } else {
+                       $width = $img->width;
+                       $height = $img->height;
                }
 
+               wfDebug( "makeImageLinkObj2: '$width'x'$height'\n" );
                $u = $nt->escapeLocalURL();
                if ( $url == '' ) {
                        $s = $this->makeBrokenImageLinkObj( $img->getTitle() );
@@ -432,7 +448,9 @@ class Linker {
                } else {
                        $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
                                 '<img src="'.$url.'" alt="'.$alt.'" ' .
-                                'width="'.$width.'" height="'.$height.'" ' .
+                                ( $width
+                                       ? ( 'width="'.$width.'" height="'.$height.'" ' )
+                                       : '' ) .
                                 'longdesc="'.$u.'" /></a>';
                }
                if ( '' != $align ) {
@@ -471,7 +489,7 @@ class Linker {
                        $boxheight = $height;
                        $thumbUrl  = $url;
                } else {
-                       $h  = intval( $height/($width/$boxwidth) );
+                       $h  = round( $height/($width/$boxwidth) );
                        $oboxwidth = $boxwidth + 2;
                        if ( ( ! $boxheight === false ) &&  ( $h > $boxheight ) )
                        {
@@ -505,7 +523,7 @@ class Linker {
 
                $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
                if ( $thumbUrl == '' ) {
-                       $s .= $this->makeBrokenImageLinkObj( $img->getTitle );
+                       $s .= $this->makeBrokenImageLinkObj( $img->getTitle() );
                        $zoomicon = '';
                } else {
                        $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
@@ -528,7 +546,7 @@ class Linker {
        /**
         * Pass a title object, not a title string
         */
-       function makeBrokenImageLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
+       function makeBrokenImageLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
                # Fail gracefully
                if ( ! isset($nt) ) {
                        # wfDebugDieBacktrace();
@@ -786,16 +804,8 @@ class Linker {
 
        /** @todo document */
        function editSectionLink( $nt, $section ) {
-               global $wgRequest;
                global $wgContLang;
 
-               if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
-                       # Section edit links would be out of sync on an old page.
-                       # But, if we're diffing to the current page, they'll be
-                       # correct.
-                       return '';
-               }
-
                $editurl = '&section='.$section;
                $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);