r41727 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r41726 | r41727 (on ViewVC) | r41728 >
Date:05:55, 6 October 2008
Author:tstarling
Status:resolved (Comments)
Tags:
Comment:* 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.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
===================================================================
--- trunk/phase3/includes/parser/Parser.php	(revision 41726)
+++ trunk/phase3/includes/parser/Parser.php	(revision 41727)
@@ -4224,7 +4224,7 @@
 				'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 @@
 							/// 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: trunk/phase3/includes/Linker.php
===================================================================
--- trunk/phase3/includes/Linker.php	(revision 41726)
+++ trunk/phase3/includes/Linker.php	(revision 41727)
@@ -699,6 +699,9 @@
 	 *                          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 @@
 		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: trunk/phase3/includes/MediaTransformOutput.php
===================================================================
--- trunk/phase3/includes/MediaTransformOutput.php	(revision 41726)
+++ trunk/phase3/includes/MediaTransformOutput.php	(revision 41727)
@@ -50,6 +50,8 @@
 	 *     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 @@
 	 *     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 @@
 
 		$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: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 41726)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 41727)
@@ -288,6 +288,7 @@
 	'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:'                    ),
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 41726)
+++ trunk/phase3/RELEASE-NOTES	(revision 41727)
@@ -148,12 +148,15 @@
   $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 ===
 
 * (bug 14907) DatabasePostgres::fieldType now defined.

Follow-up revisions

RevisionCommit summaryAuthorDate
r41789Update to r41727 (bug 539) "click" parameter on images.brion00:31, 7 October 2008

Comments

#Comment by VasilievVV (Talk | contribs)   19:14, 6 October 2008

This should allow to add an information icon to the image, or we will get several copyright problems.

#Comment by Brion VIBBER (Talk | contribs)   00:32, 7 October 2008

Per discussion on the bug, that's not a new issue introduced here, so not a blocker.

#Comment by Brion VIBBER (Talk | contribs)   00:31, 7 October 2008

Renamed "click" to "link" and added parser test cases in r41789.

Views
Toolbox