(bug 38351) Image alignment should follow the page content language
authorrobin <robinp.1273@gmail.com>
Wed, 1 Aug 2012 03:34:32 +0000 (05:34 +0200)
committerrobin <robinp.1273@gmail.com>
Thu, 2 Aug 2012 22:48:06 +0000 (00:48 +0200)
The alignment of image thumbs should follow the page content language instead of the wiki content language.
For this it needs the parser context, and because it makes sense to have it as first parameter, I renamed makeImageLink2() to makeImageLink(), the 2 seemed to be redundant anyway.
The old function name keeps the old behaviour, but can be removed quite soon since almost no extension is using it.

Change-Id: I0c35b06a85528dcc43fdd0578dc9b327c495cf4a

docs/hooks.txt
includes/Linker.php
includes/parser/Parser.php

index e844e89..eefb46c 100644 (file)
@@ -1051,9 +1051,9 @@ $result: User permissions error to add. If none, return true.
 &$title: Title object of the image
 &$file: File object, or false if it doesn't exist
 &$frameParams: Various parameters with special meanings; see documentation in
-       includes/Linker.php for Linker::makeImageLink2
+       includes/Linker.php for Linker::makeImageLink
 &$handlerParams: Various parameters with special meanings; see documentation in
-       includes/Linker.php for Linker::makeImageLink2
+       includes/Linker.php for Linker::makeImageLink
 &$time: Timestamp of file in 'YYYYMMDDHHIISS' string form, or false for current
 &$res: Final HTML output, used if you return false
 
index 26e99cd..db144f7 100644 (file)
@@ -513,7 +513,8 @@ class Linker {
         * Given parameters derived from [[Image:Foo|options...]], generate the
         * HTML that that syntax inserts in the page.
         *
-        * @param $title Title object
+        * @param $parser Parser object
+        * @param $title Title object of the file (not the currently viewed page)
         * @param $file File object, or false if it doesn't exist
         * @param $frameParams Array: associative array of parameters external to the media handler.
         *     Boolean parameters are indicated by presence or absence, the value is arbitrary and
@@ -540,9 +541,10 @@ class Linker {
         * @param $time String: timestamp of the file, set as false for current
         * @param $query String: query params for desc url
         * @param $widthOption: Used by the parser to remember the user preference thumbnailsize
+        * @since 1.20
         * @return String: HTML for an image, with links, wrappers, etc.
         */
-       public static function makeImageLink2( Title $title, $file, $frameParams = array(),
+       public static function makeImageLink( /*Parser*/ $parser, Title $title, $file, $frameParams = array(),
                $handlerParams = array(), $time = false, $query = "", $widthOption = null )
        {
                $res = null;
@@ -615,16 +617,20 @@ class Linker {
                }
 
                if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) {
-                       global $wgContLang;
-                       # Create a thumbnail. Alignment depends on language
-                       # writing direction, # right aligned for left-to-right-
-                       # languages ("Western languages"), left-aligned
-                       # for right-to-left-languages ("Semitic languages")
+                       # Create a thumbnail. Alignment depends on the writing direction of
+                       # the page content language (right-aligned for LTR languages,
+                       # left-aligned for RTL languages)
                        #
-                       # If  thumbnail width has not been provided, it is set
+                       # If a thumbnail width has not been provided, it is set
                        # to the default user option as specified in Language*.php
                        if ( $fp['align'] == '' ) {
-                               $fp['align'] = $wgContLang->alignEnd();
+                               if( $parser instanceof Parser ) {
+                                       $fp['align'] = $parser->getTargetLanguage()->alignEnd();
+                               } else {
+                                       # backwards compatibility, remove with makeImageLink2()
+                                       global $wgContLang;
+                                       $fp['align'] = $wgContLang->alignEnd();
+                               }
                        }
                        return $prefix . self::makeThumbLink2( $title, $file, $fp, $hp, $time, $query ) . $postfix;
                }
@@ -663,6 +669,17 @@ class Linker {
                return str_replace( "\n", ' ', $prefix . $s . $postfix );
        }
 
+       /**
+        * See makeImageLink()
+        * When this function is removed, remove if( $parser instanceof Parser ) check there too
+        * @deprecated since 1.20
+        */
+       public static function makeImageLink2( Title $title, $file, $frameParams = array(),
+               $handlerParams = array(), $time = false, $query = "", $widthOption = null ) {
+               return self::makeImageLink( null, $title, $file, $frameParams,
+                       $handlerParams, $time, $query, $widthOption );
+       }
+
        /**
         * Get the link parameters for MediaTransformOutput::toHtml() from given
         * frame parameters supplied by the Parser.
index 291db7a..16f9cb2 100644 (file)
@@ -5174,7 +5174,7 @@ class Parser {
 
                # Linker does the rest
                $time = isset( $options['time'] ) ? $options['time'] : false;
-               $ret = Linker::makeImageLink2( $title, $file, $params['frame'], $params['handler'],
+               $ret = Linker::makeImageLink( $this, $title, $file, $params['frame'], $params['handler'],
                        $time, $descQuery, $this->mOptions->getThumbSize() );
 
                # Give the handler a chance to modify the parser object