From 77d634b92216becfff9a02ce39421be7f94a34a6 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 6 Oct 2008 05:55:27 +0000 Subject: [PATCH] * Added "click" parameter to image links, to allow images to link to an arbitrary title or URL. This should replace inaccessible and incomplete solutions such as CSS-based overlays and ImageMap. --- RELEASE-NOTES | 11 +++++++---- includes/Linker.php | 21 +++++++++++++++++---- includes/MediaTransformOutput.php | 11 ++++++++++- includes/parser/Parser.php | 25 ++++++++++++++++++++++++- languages/messages/MessagesEn.php | 1 + 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a78271e3ea..bbe2f14f1d 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -148,11 +148,14 @@ The following extensions are migrated into MediaWiki 1.14: $wgExternalLinkTarget * api.php now sends "Retry-After" and "X-Database-Lag" HTTP headers if the maxlag check fails, just like index.php does -* Configurable per-namespace and per-page header, - respectively MediaWiki:Pageheader-# where # is the namespace number, and +* Configurable per-namespace and per-page header, respectively + MediaWiki:Pageheader-# where # is the namespace number, and MediaWiki:Pagenumber-#-PAGENAME where # is the page's namespace number and - PAGENAME is the page name minus the namespace prefix. Can be disabled with the new magic word __NOHEADER__ - + PAGENAME is the page name minus the namespace prefix. Can be disabled with + the new magic word __NOHEADER__ +* Added "click" parameter to image links, to allow images to link to an + arbitrary title or URL. This should replace inaccessible and incomplete + solutions such as CSS-based overlays and ImageMap. === Bug fixes in 1.14 === diff --git a/includes/Linker.php b/includes/Linker.php index 7de2e3771f..bc9d12cbc9 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -699,6 +699,9 @@ class Linker { * bottom, text-bottom) * alt Alternate text for image (i.e. alt attribute). Plain text. * caption HTML for image caption. + * click-url URL to link to + * click-title Title object to link to + * no-link Boolean, suppress description link * * @param array $handlerParams Associative array of media handler parameters, to be passed * to transform(). Typical keys are "width" and "page". @@ -795,12 +798,22 @@ class Linker { if ( !$thumb ) { $s = $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true ); } else { - $s = $thumb->toHtml( array( - 'desc-link' => true, - 'desc-query' => $query, + $params = array( 'alt' => $fp['alt'], 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false , - 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false ) ); + 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false ); + if ( !empty( $fp['click-url'] ) ) { + $params['custom-url-link'] = $fp['click-url']; + } elseif ( !empty( $fp['click-title'] ) ) { + $params['custom-title-link'] = $fp['click-title']; + } elseif ( !empty( $fp['no-link'] ) ) { + // No link + } else { + $params['desc-link'] = true; + $params['desc-query'] = $query; + } + + $s = $thumb->toHtml( $params ); } if ( '' != $fp['align'] ) { $s = "
{$s}
"; diff --git a/includes/MediaTransformOutput.php b/includes/MediaTransformOutput.php index 9e94f06b93..8840067b0c 100644 --- a/includes/MediaTransformOutput.php +++ b/includes/MediaTransformOutput.php @@ -50,6 +50,8 @@ abstract class MediaTransformOutput { * alt Alternate text or caption * desc-link Boolean, show a description link * file-link Boolean, show a file download link + * custom-url-link Custom URL to link to + * custom-title-link Custom Title object to link to * valign vertical-align property, if the output is an inline element * img-class Class applied to the tag, if there is such a tag * @@ -133,6 +135,8 @@ class ThumbnailImage extends MediaTransformOutput { * valign vertical-align property, if the output is an inline element * img-class Class applied to the tag, if there is such a tag * desc-query String, description link query params + * custom-url-link Custom URL to link to + * custom-title-link Custom Title object to link to * * For images, desc-link and file-link are implemented as a click-through. For * sounds and videos, they may be displayed in other ways. @@ -147,7 +151,12 @@ class ThumbnailImage extends MediaTransformOutput { $alt = empty( $options['alt'] ) ? '' : $options['alt']; $query = empty($options['desc-query']) ? '' : $options['desc-query']; - if ( !empty( $options['desc-link'] ) ) { + if ( !empty( $options['custom-url-link'] ) ) { + $linkAttribs = array( 'href' => $options['custom-url-link'] ); + } elseif ( !empty( $options['custom-title-link'] ) ) { + $title = $options['custom-title-link']; + $linkAttribs = array( 'href' => $title->getLinkUrl(), 'title' => $title->getFullText() ); + } elseif ( !empty( $options['desc-link'] ) ) { $linkAttribs = $this->getDescLinkAttribs( $alt, $query ); } elseif ( !empty( $options['file-link'] ) ) { $linkAttribs = array( 'href' => $this->file->getURL() ); diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 276140176b..7fa3eca780 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4224,7 +4224,7 @@ class Parser 'vertAlign' => array( 'baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom' ), 'frame' => array( 'thumbnail', 'manualthumb', 'framed', 'frameless', - 'upright', 'border' ), + 'upright', 'border', 'click' ), ); static $internalParamMap; if ( !$internalParamMap ) { @@ -4343,6 +4343,29 @@ class Parser /// downstream behavior seems odd with missing manual thumbs. $validated = true; break; + case 'click': + $chars = self::EXT_LINK_URL_CLASS; + $prots = $this->mUrlProtocols; + if ( $value === '' ) { + $paramName = 'no-link'; + $value = true; + $validated = true; + } elseif ( preg_match( "/^$prots/", $value ) ) { + if ( preg_match( "/^($prots)$chars+$/", $value, $m ) ) { + $paramName = 'click-url'; + $this->mOutput->addExternalLink( $value ); + $validated = true; + } + } else { + $clickTitle = Title::newFromText( $value ); + if ( $clickTitle ) { + $paramName = 'click-title'; + $value = $clickTitle; + $this->mOutput->addLink( $clickTitle ); + $validated = true; + } + } + break; default: // Most other things appear to be empty or numeric... $validated = ( $value === false || is_numeric( trim( $value ) ) ); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index b2e83801a0..be33dc3bbb 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -288,6 +288,7 @@ $magicWords = array( 'img_middle' => array( 1, 'middle' ), 'img_bottom' => array( 1, 'bottom' ), 'img_text_bottom' => array( 1, 'text-bottom' ), + 'img_click' => array( 1, 'click=$1' ), 'int' => array( 0, 'INT:' ), 'sitename' => array( 1, 'SITENAME' ), 'ns' => array( 0, 'NS:' ), -- 2.20.1