From e4b4bfdf9b3191ab731a1bdea3c47a49f7f55c1a Mon Sep 17 00:00:00 2001 From: robin Date: Wed, 1 Aug 2012 05:34:32 +0200 Subject: [PATCH] (bug 38351) Image alignment should follow the page content language 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 | 4 ++-- includes/Linker.php | 35 ++++++++++++++++++++++++++--------- includes/parser/Parser.php | 2 +- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index e844e891c9..eefb46c49b 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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 diff --git a/includes/Linker.php b/includes/Linker.php index 26e99cd98d..db144f79dc 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -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. diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 291db7a81d..16f9cb2439 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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 -- 2.20.1