Always set a title on images when provided
authorJackmcbarn <jackmcbarn@gmail.com>
Sun, 10 Aug 2014 22:35:37 +0000 (18:35 -0400)
committerCscott <cananian@wikimedia.org>
Fri, 12 Dec 2014 19:17:23 +0000 (19:17 +0000)
If an image has a title but isn't linked, set the title on the image
itself rather than not setting it at all.

Bug: T23454
Change-Id: I6302246cf28c84ade805a6a7d4a5e131b6f42e86

includes/media/MediaTransformOutput.php
tests/parser/parserTests.txt

index d9327fb..304cc03 100644 (file)
@@ -352,6 +352,11 @@ class ThumbnailImage extends MediaTransformOutput {
 
                $query = isset( $options['desc-query'] ) ? $options['desc-query'] : '';
 
+               $attribs = array(
+                       'alt' => $alt,
+                       'src' => $this->url,
+               );
+
                if ( !empty( $options['custom-url-link'] ) ) {
                        $linkAttribs = array( 'href' => $options['custom-url-link'] );
                        if ( !empty( $options['title'] ) ) {
@@ -381,13 +386,11 @@ class ThumbnailImage extends MediaTransformOutput {
                        $linkAttribs = array( 'href' => $this->file->getURL() );
                } else {
                        $linkAttribs = false;
+                       if ( !empty( $options['title'] ) ) {
+                               $attribs['title'] = $options['title'];
+                       }
                }
 
-               $attribs = array(
-                       'alt' => $alt,
-                       'src' => $this->url,
-               );
-
                if ( empty( $options['no-dimensions'] ) ) {
                        $attribs['width'] = $this->width;
                        $attribs['height'] = $this->height;
index 39129cb..06ac802 100644 (file)
@@ -11095,6 +11095,15 @@ thumbsize=220
 </figcaption></figure>
 !! end
 
+!! test
+Titles in unlinked images (T23454)
+!! wikitext
+[[File:Foobar.jpg|link=|stuff]]
+!! html/php
+<p><img alt="stuff" src="http://example.com/images/3/3a/Foobar.jpg" title="stuff" width="1941" height="220" />
+</p>
+!! end
+
 !! test
 Link with empty target
 !! wikitext