Fix bug in prefixing scheme
[lhc/web/wiklou.git] / includes / Linker.php
index c7f7df9..008b9b8 100644 (file)
@@ -529,16 +529,7 @@ class Linker {
                                'title' => $fp['title'],
                                'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
                                'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
-                       if ( !empty( $fp['link-url'] ) ) {
-                               $params['custom-url-link'] = $fp['link-url'];
-                       } elseif ( !empty( $fp['link-title'] ) ) {
-                               $params['custom-title-link'] = $fp['link-title'];
-                       } elseif ( !empty( $fp['no-link'] ) ) {
-                               // No link
-                       } else {
-                               $params['desc-link'] = true;
-                               $params['desc-query'] = $query;
-                       }
+                       $params = $this->getImageLinkMTOParams( $fp, $query ) + $params;
 
                        $s = $thumb->toHtml( $params );
                }
@@ -548,6 +539,27 @@ class Linker {
                return str_replace("\n", ' ',$prefix.$s.$postfix);
        }
 
+       /**
+        * Get the link parameters for MediaTransformOutput::toHtml() from given 
+        * frame parameters supplied by the Parser.
+        * @param $frameParams The frame parameters
+        * @param $query An optional query string to add to description page links
+        */
+       function getImageLinkMTOParams( $frameParams, $query = '' ) {
+               $mtoParams = array();
+               if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
+                       $mtoParams['custom-url-link'] = $frameParams['link-url'];
+               } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
+                       $mtoParams['custom-title-link'] = $frameParams['link-title'];
+               } elseif ( !empty( $frameParams['no-link'] ) ) {
+                       // No link
+               } else {
+                       $mtoParams['desc-link'] = true;
+                       $mtoParams['desc-query'] = $query;
+               }
+               return $mtoParams;
+       }
+
        /**
         * Make HTML for a thumbnail including image, border and caption
         * @param $title Title object
@@ -571,7 +583,7 @@ class Linker {
        }
 
        function makeThumbLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
-               global $wgStylePath, $wgContLang;
+               global $wgStylePath;
                $exists = $file && $file->exists();
 
                # Shortcuts
@@ -632,32 +644,31 @@ class Linker {
                        $url = wfAppendQuery( $url, 'page=' . urlencode( $page ) );
                }
 
-               $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
-
                $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
                if( !$exists ) {
                        $s .= $this->makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time==true );
-                       $zoomicon = '';
+                       $zoomIcon = '';
                } elseif ( !$thumb ) {
                        $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
-                       $zoomicon = '';
+                       $zoomIcon = '';
                } else {
-                       $s .= $thumb->toHtml( array(
+                       $params = array(
                                'alt' => $fp['alt'],
                                'title' => $fp['title'],
-                               'img-class' => 'thumbimage',
-                               'desc-link' => true,
-                               'desc-query' => $query ) );
+                               'img-class' => 'thumbimage' );
+                       $params = $this->getImageLinkMTOParams( $fp, $query ) + $params;
+                       $s .= $thumb->toHtml( $params );
                        if ( isset( $fp['framed'] ) ) {
-                               $zoomicon="";
+                               $zoomIcon = "";
                        } else {
-                               $zoomicon =  '<div class="magnify">'.
-                                       '<a href="'.$url.'" class="internal" title="'.$more.'">'.
-                                       '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
-                                       'width="15" height="11" alt="" /></a></div>';
+                               $zoomIcon =  '<div class="magnify">'.
+                                       '<a href="' . htmlspecialchars( $url ) . '" class="internal" ' .
+                                               'title="' . htmlspecialchars( wfMsg( 'thumbnail-more' ) ) . '">'.
+                                       '<img src="' . htmlspecialchars( $wgStylePath ) . '/common/images/magnify-clip.png" ' .
+                                               'width="15" height="11" alt="" /></a></div>';
                        }
                }
-               $s .= '  <div class="thumbcaption">'.$zoomicon.$fp['caption']."</div></div></div>";
+               $s .= '  <div class="thumbcaption">' . $zoomIcon . $fp['caption'] . "</div></div></div>";
                return str_replace("\n", ' ', $s);
        }
 
@@ -693,11 +704,9 @@ class Linker {
                                list( $inside, $trail ) = self::splitTrail( $trail );
 
                                wfProfileOut( __METHOD__ );
-                               return Html::element( 'a', array(
-                                       'href' => $href,
-                                       'class' => 'new',
-                                       'title' => $title->getPrefixedText()
-                               ), $prefix . $text . $inside ) . $trail;
+                               return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' . 
+                                                               htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES ) . '">' .
+                                                               htmlspecialchars( $prefix . $text . $inside, ENT_NOQUOTES ) . '</a>' . $trail;
                        } else {
                                wfProfileOut( __METHOD__ );
                                return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
@@ -751,7 +760,7 @@ class Linker {
                                $url = $this->getUploadUrl( $title );
                                $class = 'new';
                        }
-                       $alt = htmlspecialchars( $title->getText() );
+                       $alt = htmlspecialchars( $title->getText(),  ENT_QUOTES );
                        if( $text == '' ) {
                                $text = $alt;
                        }