* Added "click" parameter to image links, to allow images to link to an arbitrary...
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 6 Oct 2008 05:55:27 +0000 (05:55 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 6 Oct 2008 05:55:27 +0000 (05:55 +0000)
RELEASE-NOTES
includes/Linker.php
includes/MediaTransformOutput.php
includes/parser/Parser.php
languages/messages/MessagesEn.php

index a78271e..bbe2f14 100644 (file)
@@ -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 ===
 
index 7de2e37..bc9d12c 100644 (file)
@@ -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 = "<div class=\"float{$fp['align']}\">{$s}</div>";
index 9e94f06..8840067 100644 (file)
@@ -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 <img> 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 <img> 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() );
index 2761401..7fa3eca 100644 (file)
@@ -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 ) ) );
index b2e8380..be33dc3 100644 (file)
@@ -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:'                    ),