(bug 23226) Add |class= parameter to image links in order to add class(es) to HTML img tag.

Change-Id: If58802ad2c513c1db7bc3488daf4e078b8694b02
This commit is contained in:
tpt 2012-08-20 12:12:47 +02:00 committed by Catrope
parent 02e2b0a250
commit 2b9c22deb3
5 changed files with 25 additions and 4 deletions

View file

@ -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.

View file

@ -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'] ) ) {

View file

@ -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.

View file

@ -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:' ),

View file

@ -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
<p><a href="/wiki/File:Foobar.jpg" class="image" title="a"><img alt="a" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" class="b" /></a>
</p>
!! end
!! article
File:Barfoo.jpg
!! text