From 2b9c22deb3f7031892b3cbef70197c59a3709bc6 Mon Sep 17 00:00:00 2001 From: tpt Date: Mon, 20 Aug 2012 12:12:47 +0200 Subject: [PATCH] (bug 23226) Add |class= parameter to image links in order to add class(es) to HTML img tag. Change-Id: If58802ad2c513c1db7bc3488daf4e078b8694b02 --- RELEASE-NOTES-1.20 | 1 + includes/Linker.php | 14 +++++++++++--- includes/parser/Parser.php | 4 +++- languages/messages/MessagesEn.php | 1 + tests/parser/parserTests.txt | 9 +++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index 6b9de400f6..0a5360ee85 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -128,6 +128,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki. * Add lang and hreflang attributes to language links on Login page. * (bug 22749) Create Special:MostInterwikis. * Show change tags when transclude Special:Recentchanges(linked) or Special:Newpages. +* (bug 23226) Add |class= parameter to image links in order to add class(es) to HTML img tag. === Bug fixes in 1.20 === * (bug 30245) Use the correct way to construct a log page title. diff --git a/includes/Linker.php b/includes/Linker.php index fe2650b30f..632cf432f0 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -536,6 +536,7 @@ class Linker { * valign Vertical alignment (baseline, sub, super, top, text-top, middle, * bottom, text-bottom) * alt Alternate text for image (i.e. alt attribute). Plain text. + * class HTML for image classes. Plain text. * caption HTML for image caption. * link-url URL to link to * link-title Title object to link to @@ -580,6 +581,9 @@ class Linker { if ( !isset( $fp['title'] ) ) { $fp['title'] = ''; } + if ( !isset( $fp['class'] ) ) { + $fp['class'] = ''; + } $prefix = $postfix = ''; @@ -663,8 +667,11 @@ class Linker { $params = array( 'alt' => $fp['alt'], 'title' => $fp['title'], - 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false , - 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false ); + 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false, + 'img-class' => $fp['class'] ); + if ( isset( $fp['border'] ) ) { + $params['img-class'] .= ( $params['img-class'] !== '' ) ? ' thumbborder' : 'thumbborder'; + } $params = self::getImageLinkMTOParams( $fp, $query, $parser ) + $params; $s = $thumb->toHtml( $params ); @@ -831,7 +838,8 @@ class Linker { $params = array( 'alt' => $fp['alt'], 'title' => $fp['title'], - 'img-class' => 'thumbimage' ); + 'img-class' => ( isset( $fp['class'] ) && $fp['class'] !== '' ) ? $fp['class'] . ' thumbimage' : 'thumbimage' + ); $params = self::getImageLinkMTOParams( $fp, $query ) + $params; $s .= $thumb->toHtml( $params ); if ( isset( $fp['framed'] ) ) { diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index f3c978c48d..2d5f966728 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4959,7 +4959,7 @@ class Parser { 'vertAlign' => array( 'baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom' ), 'frame' => array( 'thumbnail', 'manualthumb', 'framed', 'frameless', - 'upright', 'border', 'link', 'alt' ), + 'upright', 'border', 'link', 'alt', 'class' ), ); static $internalParamMap; if ( !$internalParamMap ) { @@ -5009,6 +5009,7 @@ class Parser { # * upright reduce width for upright images, rounded to full __0 px # * border draw a 1px border around the image # * alt Text for HTML alt attribute (defaults to empty) + # * class Set a class for img node # * link Set the target of the image link. Can be external, interwiki, or local # vertical-align values (no % or length right now): # * baseline @@ -5077,6 +5078,7 @@ class Parser { switch( $paramName ) { case 'manualthumb': case 'alt': + case 'class': # @todo FIXME: Possibly check validity here for # manualthumb? downstream behavior seems odd with # missing manual thumbs. diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index e290a4c976..c343af8894 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -282,6 +282,7 @@ $magicWords = array( 'img_text_bottom' => array( 1, 'text-bottom' ), 'img_link' => array( 1, 'link=$1' ), 'img_alt' => array( 1, 'alt=$1' ), + 'img_class' => array( 1, 'class=$1' ), 'int' => array( 0, 'INT:' ), 'sitename' => array( 1, 'SITENAME' ), 'ns' => array( 0, 'NS:' ), diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 23067c16d9..5036268e95 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -4984,6 +4984,15 @@ Bug 3090: External links other than http: in image captions !! end +!! test +Custom class +!! input +[[Image:foobar.jpg|a|class=b]] +!! result +

a +

+!! end + !! article File:Barfoo.jpg !! text -- 2.20.1