From b7f4c5612ec6cd221fd33a1ee8e6bb4b05eb00bd Mon Sep 17 00:00:00 2001 From: Remember the dot Date: Sat, 11 Jul 2009 04:47:12 +0000 Subject: [PATCH] Updated parser tests for r52726. Also fixed some corner cases and updated the parser test for PMID links. --- includes/Linker.php | 8 +++-- includes/MediaTransformOutput.php | 28 ++++++++------- maintenance/parserTests.txt | 58 +++++++++++++++---------------- 3 files changed, 49 insertions(+), 45 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 02e4790aeb..4577c5cf54 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -89,7 +89,7 @@ class Linker { */ private function getLinkAttributesInternal( $title, $class, $classDefault = false ) { $title = htmlspecialchars( $title ); - if( $class === '' and $classDefault !== false ) { + if ( $class === '' and $classDefault !== false ) { # FIXME: Parameter defaults the hard way! We should just have # $class = 'external' or whatever as the default in the externally- # exposed functions, not $class = ''. @@ -97,10 +97,12 @@ class Linker { } $class = htmlspecialchars( $class ); $r = ''; - if( $class !== '' ) { + if ( $class != '' ) { $r .= " class=\"$class\""; } - $r .= " title=\"$title\""; + if ( $title != '') { + $r .= " title=\"$title\""; + } return $r; } diff --git a/includes/MediaTransformOutput.php b/includes/MediaTransformOutput.php index e19a0c69ac..a3fcc96eeb 100644 --- a/includes/MediaTransformOutput.php +++ b/includes/MediaTransformOutput.php @@ -80,17 +80,19 @@ abstract class MediaTransformOutput { } } - function getDescLinkAttribs( $alt = false, $params = '' ) { + function getDescLinkAttribs( $title = null, $params = '' ) { $query = $this->page ? ( 'page=' . urlencode( $this->page ) ) : ''; if( $params ) { $query .= $query ? '&'.$params : $params; } - $title = $this->file->getTitle(); - return array( + $attribs = array( 'href' => $this->file->getTitle()->getLocalURL( $query ), 'class' => 'image', - 'title' => $alt ); + if ( $title ) { + $attribs['title'] = $title; + } + return $attribs; } } @@ -148,22 +150,22 @@ class ThumbnailImage extends MediaTransformOutput { } $alt = empty( $options['alt'] ) ? '' : $options['alt']; - # Note: if title is empty and alt is not, make the title empty, don't - # use alt; only use alt if title is not set - $title = !isset( $options['title'] ) ? $alt : $options['title']; - $query = empty($options['desc-query']) ? '' : $options['desc-query']; + + $query = empty( $options['desc-query'] ) ? '' : $options['desc-query']; if ( !empty( $options['custom-url-link'] ) ) { $linkAttribs = array( 'href' => $options['custom-url-link'] ); - if ( $alt ) { - $linkAttribs['title'] = $alt; + if ( !empty( $options['title'] ) ) { + $linkAttribs['title'] = $options['title']; } } elseif ( !empty( $options['custom-title-link'] ) ) { $title = $options['custom-title-link']; - $linkAttribs = array( 'href' => $title->getLinkUrl(), - 'title' => $alt ); + $linkAttribs = array( + 'href' => $title->getLinkUrl(), + 'title' => empty( $options['title'] ) ? $title->getFullText() : $options['title'] + ); } elseif ( !empty( $options['desc-link'] ) ) { - $linkAttribs = $this->getDescLinkAttribs( $title, $query ); + $linkAttribs = $this->getDescLinkAttribs( empty( $options['title'] ) ? null : $options['title'], $query ); } elseif ( !empty( $options['file-link'] ) ) { $linkAttribs = array( 'href' => $this->file->getURL() ); } else { diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt index e7ebd96e38..1ce66bf033 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -2198,7 +2198,7 @@ Magic links: PMID incorrectly converts space to underscore !! input PMID 1234 !! result -

PMID 1234 +

PMID 1234

!! end @@ -3130,7 +3130,7 @@ Simple image !! input [[Image:foobar.jpg]] !! result -

Image:foobar.jpg +

Foobar.jpg

!! end @@ -3139,7 +3139,7 @@ Right-aligned image !! input [[Image:foobar.jpg|right]] !! result -
+
Foobar.jpg
!! end @@ -3148,7 +3148,7 @@ Simple image (using File: namespace, now canonical) !! input [[File:foobar.jpg]] !! result -

File:foobar.jpg +

Foobar.jpg

!! end @@ -3166,7 +3166,7 @@ Image with link parameter, wiki target !! input [[Image:foobar.jpg|link=Target page]] !! result -

+

Foobar.jpg

!! end @@ -3175,7 +3175,7 @@ Image with link parameter, URL target !! input [[Image:foobar.jpg|link=http://example.com/]] !! result -

+

Foobar.jpg

!! end @@ -3184,7 +3184,7 @@ Image with empty link parameter !! input [[Image:foobar.jpg|link=]] !! result -

+

Foobar.jpg

!! end @@ -3213,7 +3213,7 @@ Image with frame and link !! input [[Image:Foobar.jpg|frame|left|This is a test image [[Main Page]]]] !! result -
This is a test image Main Page
+
This is a test image Main Page
!! end @@ -3222,7 +3222,7 @@ Image with frame and link and explicit alt !! input [[Image:Foobar.jpg|frame|left|This is a test image [[Main Page]]|alt=Altitude]] !! result -
Altitude
This is a test image Main Page
+
Altitude
This is a test image Main Page
!! end @@ -3240,7 +3240,7 @@ Image with wiki markup in explicit alt !! input [[Image:Foobar.jpg|alt=testing '''bold''' in alt]] !! result -

testing bold in alt +

testing bold in alt

!! end @@ -3269,7 +3269,7 @@ Thumbnail image caption with a free URL !! input [[Image:foobar.jpg|thumb|http://example.com]] !! result -
+
!! end @@ -3278,7 +3278,7 @@ Thumbnail image caption with a free URL and explicit alt !! input [[Image:foobar.jpg|thumb|http://example.com|alt=Alteration]] !! result -
+
!! end @@ -3287,7 +3287,7 @@ BUG 1887: A ISBN with a thumbnail !! input [[Image:foobar.jpg|thumb|ISBN 1235467890]] !! result -
+
!! end @@ -3296,7 +3296,7 @@ BUG 1887: A RFC with a thumbnail !! input [[Image:foobar.jpg|thumb|This is RFC 12354]] !! result -
This is RFC 12354
+
This is RFC 12354
!! end @@ -3305,7 +3305,7 @@ BUG 1887: A mailto link with a thumbnail !! input [[Image:foobar.jpg|thumb|Please mailto:nobody@example.com]] !! result -
+
!! end @@ -3315,7 +3315,7 @@ so math is not stripped and turns up as escaped <math> tags. !! input [[Image:foobar.jpg|thumb|2+2]] !! result -
<math>2+2</math>
+
<math>2+2</math>
!! end @@ -3326,7 +3326,7 @@ math !! input [[Image:foobar.jpg|thumb|2+2]] !! result -
2 + 2
+
2 + 2
!! end @@ -3399,7 +3399,7 @@ Image caption containing another image !! input [[Image:Foobar.jpg|thumb|This is a caption with another [[Image:icon.png|image]] inside it!]] !! result -
This is a caption with another File:Icon.png inside it!
+
This is a caption with another File:Icon.png inside it!
!! end @@ -3419,7 +3419,7 @@ Bug 3090: External links other than http: in image captions !! input [[Image:Foobar.jpg|thumb|200px|This caption has [irc://example.net irc] and [https://example.com Secure] ext links in it.]] !! result -
This caption has irc and Secure ext links in it.
+
This caption has irc and Secure ext links in it.
!! end @@ -3822,7 +3822,7 @@ BUG 1219 URL next to image (good) !! input http://example.com [[Image:foobar.jpg]] !! result -

http://example.com Image:foobar.jpg +

http://example.com Foobar.jpg

!!end @@ -3831,7 +3831,7 @@ BUG 1219 URL next to image (broken) !! input http://example.com[[Image:foobar.jpg]] !! result -

http://example.comImage:foobar.jpg +

http://example.comFoobar.jpg

!!end @@ -6339,7 +6339,7 @@ Centre-aligned image !! input [[Image:foobar.jpg|centre]] !! result -
+
Foobar.jpg
!!end @@ -6348,7 +6348,7 @@ None-aligned image !! input [[Image:foobar.jpg|none]] !! result -
+
Foobar.jpg
!!end @@ -6357,7 +6357,7 @@ Width + Height sized image (using px) (height is ignored) !! input [[Image:foobar.jpg|640x480px]] !! result -

+

Foobar.jpg

!!end @@ -6366,7 +6366,7 @@ Width-sized image (using px, no following whitespace) !! input [[Image:foobar.jpg|640px]] !! result -

+

Foobar.jpg

!!end @@ -6375,7 +6375,7 @@ Width-sized image (using px, with following whitespace - test regression from r3 !! input [[Image:foobar.jpg|640px ]] !! result -

+

Foobar.jpg

!!end @@ -6384,7 +6384,7 @@ Width-sized image (using px, with preceding whitespace - test regression from r3 !! input [[Image:foobar.jpg| 640px]] !! result -

+

Foobar.jpg

!!end @@ -6422,7 +6422,7 @@ Images with the "|" character in the comment !! input [[image:Foobar.jpg|thumb|An [http://test/?param1=|left|¶m2=|x external] URL]] !! result -
An external URL
An external URL
+
An external URL
An external URL
!!end @@ -7227,7 +7227,7 @@ Free external link invading image caption !! input [[Image:Foobar.jpg|thumb|http://x|hello]] !! result -
hello
+
hello
!! end -- 2.20.1