From 497649c9045838551236530aa92aa4dce864ba65 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 31 Aug 2007 02:51:23 +0000 Subject: [PATCH] In OggHandler: * Changed display style: added a "more" link which expands a box for player selection. * Allow return to the still image only display. * Fixed Java detection in IE (I hope) Elsewhere: * Changed MediaTransformOutput::toHtml() parameters, now accepts a single associative array with well-defined elements. Allows OggHandler to distinguish between file download links and image description links. * Made image links consistently have an anchor tag with class=image, instead of a mixture of image and internalParse. * Made most images have a border=0 attribute, instead of just images on the image description page. Does not appear to adversely affect display at all, it was just convenient. * Use the image name as the title attribute for the tag, when an a caption was not given by the user * Block centering by the auto margins method in ImageGallery * Fixed complete breakage of the thumbnail on upload conflict feature * TODO: test DjVu --- includes/ImageGallery.php | 14 +++-- includes/ImagePage.php | 17 +++--- includes/Linker.php | 42 +++----------- includes/MediaTransformOutput.php | 91 +++++++++++++++++++++++++------ includes/SpecialUpload.php | 12 ++-- includes/filerepo/File.php | 2 +- includes/media/Bitmap.php | 8 +-- includes/media/DjVu.php | 4 +- includes/media/Generic.php | 3 +- includes/media/SVG.php | 4 +- maintenance/parserTests.txt | 54 +++++++++--------- 11 files changed, 140 insertions(+), 111 deletions(-) diff --git a/includes/ImageGallery.php b/includes/ImageGallery.php index 54aa83b8e9..64f266f653 100644 --- a/includes/ImageGallery.php +++ b/includes/ImageGallery.php @@ -261,13 +261,14 @@ class ImageGallery . htmlspecialchars( $img->getLastError() ) . ''; } else { $vpad = floor( ( 1.25*$this->mHeights - $thumb->height ) /2 ) - 2; - $linkAttribs = array( - 'href' => $nt->getLocalURL(), - 'title' => $nt->getPrefixedText(), - ); - $thumbhtml = "\n\t\t\t".'
' - . $thumb->toHtml( array(), $linkAttribs ) . '
'; + $thumbhtml = "\n\t\t\t". + '
' + # Auto-margin centering for block-level elements. Needed now that we have video + # handlers since they may emit block-level elements as opposed to simple tags. + # ref http://css-discuss.incutio.com/?page=CenteringBlockElement + . '
' + . $thumb->toHtml( array( 'desc-link' => true ) ) . '
'; // Call parser transform hook if ( $this->mParser && $img->getHandler() ) { @@ -350,3 +351,4 @@ class ImageGallery } //class + diff --git a/includes/ImagePage.php b/includes/ImagePage.php index cd516d698f..3cf6d0ac16 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -242,14 +242,13 @@ class ImagePage extends Article { $wgOut->addHTML( '
' ); } - $imgAttribs = array( - 'border' => 0, - 'alt' => $this->img->getTitle()->getPrefixedText() - ); - if ( $thumbnail ) { + $options = array( + 'alt' => $this->img->getTitle()->getPrefixedText(), + 'file-link' => true, + ); $wgOut->addHTML( '' ); } @@ -297,9 +296,9 @@ class ImagePage extends Article { if ($this->img->isSafeFile()) { $icon= $this->img->iconThumb(); - $wgOut->addHTML( '' ); + $wgOut->addHTML( '' ); } $showLink = true; diff --git a/includes/Linker.php b/includes/Linker.php index 35951d5166..4bc64d4c5e 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -566,33 +566,13 @@ class Linker { $thumb = false; } - if ( $page ) { - $query = 'page=' . urlencode( $page ); - } else { - $query = ''; - } - $url = $title->getLocalURL( $query ); - $imgAttribs = array( - 'alt' => $fp['alt'], - 'longdesc' => $url - ); - - if ( isset( $fp['valign'] ) ) { - $imgAttribs['style'] = "vertical-align: {$fp['valign']}"; - } - if ( isset( $fp['border'] ) ) { - $imgAttribs['class'] = "thumbborder"; - } - $linkAttribs = array( - 'href' => $url, - 'class' => 'image', - 'title' => $fp['alt'] - ); - if ( !$thumb ) { $s = $this->makeBrokenImageLinkObj( $title ); } else { - $s = $thumb->toHtml( $imgAttribs, $linkAttribs ); + $s = $thumb->toHtml( array( + 'desc-link' => true, + 'alt' => $fp['alt'], + 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ) ); } if ( '' != $fp['align'] ) { $s = "
{$s}
"; @@ -684,18 +664,10 @@ class Linker { $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) ); $zoomicon = ''; } else { - $imgAttribs = array( + $s .= $thumb->toHtml( array( 'alt' => $fp['alt'], - 'longdesc' => $url, - 'class' => 'thumbimage' - ); - $linkAttribs = array( - 'href' => $url, - 'class' => 'internal', - 'title' => $fp['alt'] - ); - - $s .= $thumb->toHtml( $imgAttribs, $linkAttribs ); + 'img-class' => 'thumbimage', + 'desc-link' => true ) ); if ( isset( $fp['framed'] ) ) { $zoomicon=""; } else { diff --git a/includes/MediaTransformOutput.php b/includes/MediaTransformOutput.php index 8745bb5853..c6cf9ac2f0 100644 --- a/includes/MediaTransformOutput.php +++ b/includes/MediaTransformOutput.php @@ -6,6 +6,8 @@ * @addtogroup Media */ abstract class MediaTransformOutput { + var $file, $width, $height, $url, $page, $path; + /** * Get the width of the output box */ @@ -36,12 +38,23 @@ abstract class MediaTransformOutput { /** * Fetch HTML for this transform output - * @param array $attribs Advisory associative array of HTML attributes supplied - * by the linker. These can be incorporated into the output in any way. - * @param array $linkAttribs Attributes of a suggested enclosing tag. - * May be ignored. + * + * @param array $options Associative array of options. Boolean options + * should be indicated with a value of true for true, and false or + * absent for false. + * + * alt Alternate text or caption + * desc-link Boolean, show a description link + * file-link Boolean, show a file download link + * valign vertical-align property, if the output is an inline element + * img-class Class applied to the tag, if there is such a tag + * + * For images, desc-link and file-link are implemented as a click-through. For + * sounds and videos, they may be displayed in other ways. + * + * @return string */ - abstract function toHtml( $attribs = array() , $linkAttribs = false ); + abstract function toHtml( $options = array() ); /** * This will be overridden to return true in error classes @@ -60,6 +73,19 @@ abstract class MediaTransformOutput { return $contents; } } + + function getDescLinkAttribs( $alt = false ) { + $query = $this->page ? ( 'page=' . urlencode( $this->page ) ) : ''; + $title = $this->file->getTitle(); + if ( strval( $alt ) === '' ) { + $alt = $title->getText(); + } + return array( + 'href' => $this->file->getTitle()->getLocalURL( $query ), + 'class' => 'image', + 'title' => $alt + ); + } } @@ -74,7 +100,8 @@ class ThumbnailImage extends MediaTransformOutput { * @param string $url URL path to the thumb * @private */ - function ThumbnailImage( $url, $width, $height, $path = false ) { + function ThumbnailImage( $file, $url, $width, $height, $path = false, $page = false ) { + $this->file = $file; $this->url = $url; # These should be integers when they get here. # If not, there's a bug somewhere. But let's at @@ -82,28 +109,56 @@ class ThumbnailImage extends MediaTransformOutput { $this->width = round( $width ); $this->height = round( $height ); $this->path = $path; + $this->page = $page; } /** * Return HTML tag for the thumbnail, will include * width and height attributes and a blank alt text (as required). + * + * @param array $options Associative array of options. Boolean options + * should be indicated with a value of true for true, and false or + * absent for false. * - * You can set or override additional attributes by passing an - * associative array of name => data pairs. The data will be escaped - * for HTML output, so should be in plaintext. + * alt Alternate text or caption + * desc-link Boolean, show a description link + * file-link Boolean, show a file download link + * valign vertical-align property, if the output is an inline element + * img-class Class applied to the tag, if there is such a tag * - * If $linkAttribs is given, the image will be enclosed in an tag. + * For images, desc-link and file-link are implemented as a click-through. For + * sounds and videos, they may be displayed in other ways. * - * @param array $attribs - * @param array $linkAttribs * @return string * @public */ - function toHtml( $attribs = array(), $linkAttribs = false ) { - $attribs['src'] = $this->url; - $attribs['width'] = $this->width; - $attribs['height'] = $this->height; - if( !isset( $attribs['alt'] ) ) $attribs['alt'] = ''; + function toHtml( $options = array() ) { + if ( count( func_get_args() ) == 2 ) { + throw new MWException( __METHOD__ .' called in the old style' ); + } + + $alt = empty( $options['alt'] ) ? '' : $options['alt']; + if ( !empty( $options['desc-link'] ) ) { + $linkAttribs = $this->getDescLinkAttribs( $alt ); + } elseif ( !empty( $options['file-link'] ) ) { + $linkAttribs = array( 'href' => $this->file->getURL() ); + } else { + $linkAttribs = false; + } + + $attribs = array( + 'alt' => $alt, + 'src' => $this->url, + 'width' => $this->width, + 'height' => $this->height, + 'border' => 0, + ); + if ( !empty( $options['valign'] ) ) { + $attribs['style'] = "vertical-align: {$options['valign']}"; + } + if ( !empty( $options['img-class'] ) ) { + $attribs['class'] = $options['img-class']; + } return $this->linkWrap( $linkAttribs, Xml::element( 'img', $attribs ) ); } @@ -130,7 +185,7 @@ class MediaTransformError extends MediaTransformOutput { $this->path = false; } - function toHtml( $attribs = array(), $linkAttribs = false ) { + function toHtml( $options = array() ) { return "width}px; height: {$this->height}px;\">
" . $this->htmlMsg . diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index ee55e25a84..a254a1df1e 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -481,8 +481,8 @@ class UploadForm { $file->getName(), 'right', array(), false, true ); } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) { $icon = $file->iconThumb(); - $dlink2 = ''; + $dlink2 = '
' . + $icon->toHtml( array( 'desc-link' => true ) ) . '
' . $dlink . '
'; } else { $dlink2 = ''; } @@ -498,8 +498,8 @@ class UploadForm { $nt_lc->getText(), 'right', array(), false, true ); } elseif ( !$file_lc->allowInlineDisplay() && $file_lc->isSafeFile() ) { $icon = $file_lc->iconThumb(); - $dlink2 = ''; + $dlink2 = '
' . + $icon->toHtml( array( 'desc-link' => true ) ) . '
' . $dlink . '
'; } else { $dlink2 = ''; } @@ -522,8 +522,8 @@ class UploadForm { $nt_thb->getText(), 'right', array(), false, true ); } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) { $icon = $file_thb->iconThumb(); - $dlink2 = '
' . $icon->toHtml() . '
' . + $dlink2 = '
' . + $icon->toHtml( array( 'desc-link' => true ) ) . '
' . $dlink . '
'; } else { $dlink2 = ''; diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 84b64fbbdd..21b7a86547 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -559,7 +559,7 @@ abstract class File { $path = '/common/images/icons/' . $icon; $filepath = $wgStyleDirectory . $path; if( file_exists( $filepath ) ) { - return new ThumbnailImage( $wgStylePath . $path, 120, 120 ); + return new ThumbnailImage( $this, $wgStylePath . $path, 120, 120 ); } } return null; diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php index 245abb8ccc..ca82aab0dd 100644 --- a/includes/media/Bitmap.php +++ b/includes/media/Bitmap.php @@ -58,7 +58,7 @@ class BitmapHandler extends ImageHandler { if ( $physicalWidth == $srcWidth && $physicalHeight == $srcHeight ) { # normaliseParams (or the user) wants us to return the unscaled image wfDebug( __METHOD__.": returning unscaled image\n" ); - return new ThumbnailImage( $image->getURL(), $clientWidth, $clientHeight, $srcPath ); + return new ThumbnailImage( $image, $image->getURL(), $clientWidth, $clientHeight, $srcPath ); } if ( !$dstPath ) { @@ -77,11 +77,11 @@ class BitmapHandler extends ImageHandler { if ( $scaler == 'client' ) { # Client-side image scaling, use the source URL # Using the destination URL in a TRANSFORM_LATER request would be incorrect - return new ThumbnailImage( $image->getURL(), $clientWidth, $clientHeight, $srcPath ); + return new ThumbnailImage( $image, $image->getURL(), $clientWidth, $clientHeight, $srcPath ); } if ( $flags & self::TRANSFORM_LATER ) { - return new ThumbnailImage( $dstUrl, $clientWidth, $clientHeight, $dstPath ); + return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath ); } if ( !wfMkdirParents( dirname( $dstPath ) ) ) { @@ -201,7 +201,7 @@ class BitmapHandler extends ImageHandler { wfHostname(), $retval, trim($err), $cmd ) ); return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight, $err ); } else { - return new ThumbnailImage( $dstUrl, $clientWidth, $clientHeight, $dstPath ); + return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath ); } } diff --git a/includes/media/DjVu.php b/includes/media/DjVu.php index 45664dbe3d..20e59d18b8 100644 --- a/includes/media/DjVu.php +++ b/includes/media/DjVu.php @@ -83,7 +83,7 @@ class DjVuHandler extends ImageHandler { } if ( $flags & self::TRANSFORM_LATER ) { - return new ThumbnailImage( $dstUrl, $width, $height, $dstPath ); + return new ThumbnailImage( $image, $dstUrl, $width, $height, $dstPath, $page ); } if ( !wfMkdirParents( dirname( $dstPath ) ) ) { @@ -110,7 +110,7 @@ class DjVuHandler extends ImageHandler { wfHostname(), $retval, trim($err), $cmd ) ); return new MediaTransformError( 'thumbnail_error', $width, $height, $err ); } else { - return new ThumbnailImage( $dstUrl, $width, $height, $dstPath ); + return new ThumbnailImage( $image, $dstUrl, $width, $height, $dstPath, $page ); } } diff --git a/includes/media/Generic.php b/includes/media/Generic.php index 12c3051c12..a0707c2570 100644 --- a/includes/media/Generic.php +++ b/includes/media/Generic.php @@ -349,7 +349,8 @@ abstract class ImageHandler extends MediaHandler { return false; } $url = $script . '&' . wfArrayToCGI( $this->getScriptParams( $params ) ); - return new ThumbnailImage( $url, $params['width'], $params['height'] ); + $page = isset( $params['page'] ) ? $params['page'] : false; + return new ThumbnailImage( $image, $url, $params['width'], $params['height'], $page ); } /** diff --git a/includes/media/SVG.php b/includes/media/SVG.php index d279a1ae0d..75d0ad3d86 100644 --- a/includes/media/SVG.php +++ b/includes/media/SVG.php @@ -49,7 +49,7 @@ class SvgHandler extends ImageHandler { $srcPath = $image->getPath(); if ( $flags & self::TRANSFORM_LATER ) { - return new ThumbnailImage( $dstUrl, $clientWidth, $clientHeight, $dstPath ); + return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath ); } if ( !wfMkdirParents( dirname( $dstPath ) ) ) { @@ -80,7 +80,7 @@ class SvgHandler extends ImageHandler { wfHostname(), $retval, trim($err), $cmd ) ); return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight, $err ); } else { - return new ThumbnailImage( $dstUrl, $clientWidth, $clientHeight, $dstPath ); + return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath ); } } diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt index cd3887fd5f..27cc792c25 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -2946,7 +2946,7 @@ Simple image !! input [[Image:foobar.jpg]] !! result -

Image:foobar.jpg +

Image:foobar.jpg

!! end @@ -2955,7 +2955,7 @@ Right-aligned image !! input [[Image:foobar.jpg|right]] !! result -
+
!! end @@ -2964,7 +2964,7 @@ Image with caption !! input [[Image:foobar.jpg|right|Caption text]] !! result -
Caption text
+
Caption text
!! end @@ -2973,7 +2973,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
+
This is a test image Main Page
This is a test image Main Page
!! end @@ -2993,7 +2993,7 @@ Frameless image caption with a free URL !! input [[Image:foobar.jpg|http://example.com]] !! result -

http://example.com +

http://example.com

!! end @@ -3002,7 +3002,7 @@ Thumbnail image caption with a free URL !! input [[Image:foobar.jpg|thumb|http://example.com]] !! result - + !! end @@ -3011,7 +3011,7 @@ BUG 1887: A ISBN with a thumbnail !! input [[Image:foobar.jpg|thumb|ISBN 1235467890]] !! result - + !! end @@ -3020,7 +3020,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
+
This is RFC 12354
This is RFC 12354
!! end @@ -3029,7 +3029,7 @@ BUG 1887: A mailto link with a thumbnail !! input [[Image:foobar.jpg|thumb|Please mailto:nobody@example.com]] !! result - + !! end @@ -3039,7 +3039,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>
+
<math>2+2</math>
<math>2+2</math>
!! end @@ -3050,7 +3050,7 @@ math !! input [[Image:foobar.jpg|thumb|2+2]] !! result -
2 + 2
2 + 2
+
2 + 2
2 + 2
!! end @@ -3060,7 +3060,7 @@ BUG 648: Frameless image caption with a link !! input [[Image:foobar.jpg|text with a [[link]] in it]] !! result -

text with a link in it +

text with a link in it

!! end @@ -3069,7 +3069,7 @@ BUG 648: Frameless image caption with a link (suffix) !! input [[Image:foobar.jpg|text with a [[link]]foo in it]] !! result -

text with a linkfoo in it +

text with a linkfoo in it

!! end @@ -3078,7 +3078,7 @@ BUG 648: Frameless image caption with an interwiki link !! input [[Image:foobar.jpg|text with a [[MeatBall:Link]] in it]] !! result -

text with a MeatBall:Link in it +

text with a MeatBall:Link in it

!! end @@ -3087,7 +3087,7 @@ BUG 648: Frameless image caption with a piped interwiki link !! input [[Image:foobar.jpg|text with a [[MeatBall:Link|link]] in it]] !! result -

text with a link in it +

text with a link in it

!! end @@ -3096,7 +3096,7 @@ Escape HTML special chars in image alt text !! input [[Image:foobar.jpg|& < > "]] !! result -

& < > " +

& < > "

!! end @@ -3105,7 +3105,7 @@ BUG 499: Alt text should have Ӓ, not &1234; !! input [[Image:foobar.jpg|♀]] !! result -

♀ +

♀

!! end @@ -3123,7 +3123,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 Image:Icon.png inside it!
This is a caption with another Image:Icon.png inside it!
+
This is a caption with another Image:Icon.png inside it!
This is a caption with another Image:Icon.png inside it!
!! end @@ -3133,7 +3133,7 @@ Image caption containing a newline [[Image:Foobar.jpg|This *is some text]] !! result -

This *is some text +

This *is some text

!!end @@ -3143,7 +3143,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.
+
This caption has irc and Secure ext links in it.
This caption has irc and Secure ext links in it.
!! end @@ -3503,7 +3503,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 Image:foobar.jpg

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

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

http://example.comImage:foobar.jpg

!!end @@ -4787,7 +4787,7 @@ Fuzz testing: image with bogus manual thumbnail !!input [[Image:foobar.jpg|thumbnail= ]] !!result -
+
Error creating thumbnail:
!!end @@ -6080,7 +6080,7 @@ Centre-aligned image !! input [[Image:foobar.jpg|centre]] !! result -
+
!!end @@ -6089,7 +6089,7 @@ None-aligned image !! input [[Image:foobar.jpg|none]] !! result -
+
!!end @@ -6098,7 +6098,7 @@ Width + Height sized image (using px) (height is ignored) !! input [[Image:foobar.jpg|640x480px]] !! result -

+

!!end @@ -6136,7 +6136,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 -- 2.20.1