begin cleanup on magnus' url upload thingy
[lhc/web/wiklou.git] / includes / Linker.php
index 12cd4bc..d34971f 100644 (file)
@@ -30,7 +30,7 @@ class Linker {
        function getExternalLinkAttributes( $link, $text, $class='' ) {
                $link = htmlspecialchars( $link );
 
-               $r = ($class != '') ? " class='$class'" : " class='external'";
+               $r = ($class != '') ? " class=\"$class\"" : " class=\"external\"";
 
                $r .= " title=\"{$link}\"";
                return $r;
@@ -45,7 +45,7 @@ class Linker {
                $link = preg_replace( '/[\\x00-\\x1f]/', ' ', $link );
                $link = htmlspecialchars( $link );
 
-               $r = ($class != '') ? " class='$class'" : " class='external'";
+               $r = ($class != '') ? " class=\"$class\"" : " class=\"external\"";
 
                $r .= " title=\"{$link}\"";
                return $r;
@@ -194,7 +194,7 @@ class Linker {
 
                # Fail gracefully
                if ( ! is_object($nt) ) {
-                       # wfDebugDieBacktrace();
+                       # throw new MWException();
                        wfProfileOut( $fname );
                        return "<!-- ERROR -->{$prefix}{$text}{$trail}";
                }
@@ -343,7 +343,7 @@ class Linker {
        function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
                # Fail gracefully
                if ( ! isset($nt) ) {
-                       # wfDebugDieBacktrace();
+                       # throw new MWException();
                        return "<!-- ERROR -->{$prefix}{$text}{$trail}";
                }
 
@@ -456,11 +456,16 @@ class Linker {
 
        /** @todo document */
        function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false,
-         $thumb = false, $manual_thumb = '' )
+         $thumb = false, $manual_thumb = '', $page = null )
        {
-               global $wgContLang, $wgUser, $wgThumbLimits;
+               global $wgContLang, $wgUser, $wgThumbLimits, $wgGenerateThumbnailOnParse;
 
                $img   = new Image( $nt );
+
+               if ( ! is_null( $page ) ) {
+                       $img->selectPage( $page );
+               }
+
                if ( !$img->allowInlineDisplay() && $img->exists() ) {
                        return $this->makeKnownLinkObj( $nt );
                }
@@ -468,7 +473,7 @@ class Linker {
                $url   = $img->getViewURL();
                $error = $prefix = $postfix = '';
 
-               wfDebug( "makeImageLinkObj: '$width'x'$height'\n" );
+               wfDebug( "makeImageLinkObj: '$width'x'$height', \"$label\"\n" );
 
                if ( 'center' == $align )
                {
@@ -512,7 +517,7 @@ class Linker {
                        if ( $height == false )
                                $height = -1;
                        if ( $manual_thumb == '') {
-                               $thumb = $img->getThumbnail( $width, $height );
+                               $thumb = $img->getThumbnail( $width, $height, $wgGenerateThumbnailOnParse );
                                if ( $thumb ) {
                                        // In most cases, $width = $thumb->width or $height = $thumb->height.
                                        // If not, we're scaling the image larger than it can be scaled,
@@ -563,8 +568,7 @@ class Linker {
         * $img is an Image object
         */
        function makeThumbLinkObj( $img, $label = '', $alt, $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
-               global $wgStylePath, $wgContLang;
-               $url  = $img->getViewURL();
+               global $wgStylePath, $wgContLang, $wgGenerateThumbnailOnParse;
                $thumbUrl = '';
                $error = '';
 
@@ -583,12 +587,12 @@ class Linker {
                        // Use image dimensions, don't scale
                        $boxwidth  = $width;
                        $boxheight = $height;
-                       $thumbUrl  = $url;
+                       $thumbUrl  = $img->getViewURL();
                } else {
                        if ( $boxheight === false )
                                $boxheight = -1;
                        if ( '' == $manual_thumb ) {
-                               $thumb = $img->getThumbnail( $boxwidth, $boxheight );
+                               $thumb = $img->getThumbnail( $boxwidth, $boxheight, $wgGenerateThumbnailOnParse );
                                if ( $thumb ) {
                                        $thumbUrl = $thumb->getUrl();
                                        $boxwidth = $thumb->width;
@@ -626,7 +630,7 @@ class Linker {
                $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
                if( $thumbUrl == '' ) {
                        // Couldn't generate thumbnail? Scale the image client-side.
-                       $thumbUrl = $url;
+                       $thumbUrl = $img->getViewURL();
                }
                if ( $error ) {
                        $s .= htmlspecialchars( $error );
@@ -648,7 +652,7 @@ class Linker {
                                        'width="15" height="11" alt="'.$more.'" /></a></div>';
                        }
                }
-               $s .= '  <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
+               $s .= '  <div class="thumbcaption"'.$textalign.'>'.$zoomicon.$label."</div></div></div>";
                return str_replace("\n", ' ', $s);
        }
 
@@ -658,7 +662,7 @@ class Linker {
        function makeBrokenImageLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
                # Fail gracefully
                if ( ! isset($nt) ) {
-                       # wfDebugDieBacktrace();
+                       # throw new MWException();
                        return "<!-- ERROR -->{$prefix}{$text}{$trail}";
                }
 
@@ -721,7 +725,7 @@ class Linker {
                                $text = $alt;
                        }
                        $u = htmlspecialchars( $url );
-                       return "<a href=\"{$u}\" class='$class' title=\"{$alt}\">{$text}</a>";
+                       return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
                }
        }
 
@@ -833,12 +837,12 @@ class Linker {
         * @return string HTML
         */
        function revUserLink( $rev ) {
-               if( $rev->userCan( Revision::MW_REV_DELETED_USER ) ) {
+               if( $rev->userCan( Revision::DELETED_USER ) ) {
                        $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() );
                } else {
                        $link = wfMsgHtml( 'rev-deleted-user' );
                }
-               if( $rev->isDeleted( Revision::MW_REV_DELETED_USER ) ) {
+               if( $rev->isDeleted( Revision::DELETED_USER ) ) {
                        return '<span class="history-deleted">' . $link . '</span>';
                }
                return $link;
@@ -850,14 +854,14 @@ class Linker {
         * @return string HTML
         */
        function revUserTools( $rev ) {
-               if( $rev->userCan( Revision::MW_REV_DELETED_USER ) ) {
+               if( $rev->userCan( Revision::DELETED_USER ) ) {
                        $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() ) .
                                ' ' .
                                $this->userToolLinks( $rev->getRawUser(), $rev->getRawUserText() );
                } else {
                        $link = wfMsgHtml( 'rev-deleted-user' );
                }
-               if( $rev->isDeleted( Revision::MW_REV_DELETED_USER ) ) {
+               if( $rev->isDeleted( Revision::DELETED_USER ) ) {
                        return '<span class="history-deleted">' . $link . '</span>';
                }
                return $link;
@@ -966,7 +970,7 @@ class Linker {
                        return '';
                } else {
                        $formatted = $this->formatComment( $comment, $title );
-                       return " <span class='comment'>($formatted)</span>";
+                       return " <span class=\"comment\">($formatted)</span>";
                }
        }
        
@@ -977,14 +981,14 @@ class Linker {
         * @return string HTML
         */
        function revComment( $rev ) {
-               if( $rev->userCan( Revision::MW_REV_DELETED_COMMENT ) ) {
+               if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
                        $block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle() );
                } else {
-                       $block = " <span class='comment'>" .
+                       $block = " <span class=\"comment\">" .
                                wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
                }
-               if( $rev->isDeleted( Revision::MW_REV_DELETED_COMMENT ) ) {
-                       return " <span class='history-deleted'>$block</span>";
+               if( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
+                       return " <span class=\"history-deleted\">$block</span>";
                }
                return $block;
        }
@@ -1003,7 +1007,7 @@ class Linker {
         * parameter level defines if we are on an indentation level
         */
        function tocLine( $anchor, $tocline, $tocnumber, $level ) {
-               return "\n<li class='toclevel-$level'><a href=\"#" .
+               return "\n<li class=\"toclevel-$level\"><a href=\"#" .
                        $anchor . '"><span class="tocnumber">' .
                        $tocnumber . '</span> <span class="toctext">' .
                        $tocline . '</span></a>';
@@ -1081,7 +1085,7 @@ class Linker {
         *
         * @static
         */
-       function splitTrail( $trail ) {
+       static function splitTrail( $trail ) {
                static $regex = false;
                if ( $regex === false ) {
                        global $wgContLang;