(bug 23226) Add |class= parameter to image links in order to add class(es) to HTML...
authortpt <thomaspt@hotmail.fr>
Mon, 20 Aug 2012 10:12:47 +0000 (12:12 +0200)
committerCatrope <roan.kattouw@gmail.com>
Wed, 22 Aug 2012 00:25:42 +0000 (17:25 -0700)
Change-Id: If58802ad2c513c1db7bc3488daf4e078b8694b02

RELEASE-NOTES-1.20
includes/Linker.php
includes/parser/Parser.php
languages/messages/MessagesEn.php
tests/parser/parserTests.txt

index 6b9de40..0a5360e 100644 (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.
index fe2650b..632cf43 100644 (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'] ) ) {
index f3c978c..2d5f966 100644 (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.
index e290a4c..c343af8 100644 (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:' ),
index 23067c1..5036268 100644 (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