Use TargetLanguage of the Parser in ImageGallery
authorumherirrender <umherirrender_de.wp@web.de>
Sat, 9 Mar 2013 13:59:36 +0000 (14:59 +0100)
committerumherirrender <umherirrender_de.wp@web.de>
Sat, 9 Mar 2013 13:59:36 +0000 (14:59 +0100)
If there is a parser set on ImageGallery, the target language of the
parser should be used, because this parsed piece of html can get into
the parser cache.

Change-Id: I2e47b316e3dcc6a3db4fb5d13f5065e35fc369dd

includes/ImageGallery.php

index 037093a..2c9fece 100644 (file)
@@ -238,8 +238,6 @@ class ImageGallery {
         * @return string
         */
        function toHTML() {
-               global $wgLang;
-
                if ( $this->mPerRow > 0 ) {
                        $maxwidth = $this->mPerRow * ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING + self::GB_BORDERS );
                        $oldStyle = isset( $this->mAttribs['style'] ) ? $this->mAttribs['style'] : '';
@@ -255,6 +253,7 @@ class ImageGallery {
                        $output .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
                }
 
+               $lang = $this->getLang();
                $params = array(
                        'width' => $this->mWidths,
                        'height' => $this->mHeights
@@ -337,7 +336,7 @@ class ImageGallery {
 
                        if( $this->mShowBytes ) {
                                if( $img ) {
-                                       $fileSize = htmlspecialchars( $wgLang->formatSize( $img->getSize() ) );
+                                       $fileSize = htmlspecialchars( $lang->formatSize( $img->getSize() ) );
                                } else {
                                        $fileSize = wfMessage( 'filemissing' )->escaped();
                                }
@@ -349,7 +348,7 @@ class ImageGallery {
                        $textlink = $this->mShowFilename ?
                                Linker::link(
                                        $nt,
-                                       htmlspecialchars( $wgLang->truncate( $nt->getText(), $this->mCaptionLength ) ),
+                                       htmlspecialchars( $lang->truncate( $nt->getText(), $this->mCaptionLength ) ),
                                        array(),
                                        array(),
                                        array( 'known', 'noclasses' )
@@ -403,4 +402,15 @@ class ImageGallery {
                        : false;
        }
 
+       /**
+        * Determines the correct language to be used for this image gallery
+        * @return Language object
+        */
+       private function getLang() {
+               global $wgLang;
+               return $this->mParser
+                       ? $this->mParser->getTargetLanguage()
+                       : $wgLang;
+       }
+
 } //class