r41727 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41726‎ | r41727 | r41728 >
Date:05:55, 6 October 2008
Author:tstarling
Status:old (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:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/MediaTransformOutput.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -288,6 +288,7 @@
289289 'img_middle' => array( 1, 'middle' ),
290290 'img_bottom' => array( 1, 'bottom' ),
291291 'img_text_bottom' => array( 1, 'text-bottom' ),
 292+ 'img_click' => array( 1, 'click=$1' ),
292293 'int' => array( 0, 'INT:' ),
293294 'sitename' => array( 1, 'SITENAME' ),
294295 'ns' => array( 0, 'NS:' ),
Index: trunk/phase3/RELEASE-NOTES
@@ -148,12 +148,15 @@
149149 $wgExternalLinkTarget
150150 * api.php now sends "Retry-After" and "X-Database-Lag" HTTP headers if the maxlag
151151 check fails, just like index.php does
152 -* Configurable per-namespace and per-page header,
153 - respectively MediaWiki:Pageheader-# where # is the namespace number, and
 152+* Configurable per-namespace and per-page header, respectively
 153+ MediaWiki:Pageheader-# where # is the namespace number, and
154154 MediaWiki:Pagenumber-#-PAGENAME where # is the page's namespace number and
155 - PAGENAME is the page name minus the namespace prefix. Can be disabled with the new magic word __NOHEADER__
 155+ PAGENAME is the page name minus the namespace prefix. Can be disabled with
 156+ the new magic word __NOHEADER__
 157+* Added "click" parameter to image links, to allow images to link to an
 158+ arbitrary title or URL. This should replace inaccessible and incomplete
 159+ solutions such as CSS-based overlays and ImageMap.
156160
157 -
158161 === Bug fixes in 1.14 ===
159162
160163 * (bug 14907) DatabasePostgres::fieldType now defined.
Index: trunk/phase3/includes/parser/Parser.php
@@ -4224,7 +4224,7 @@
42254225 'vertAlign' => array( 'baseline', 'sub', 'super', 'top', 'text-top', 'middle',
42264226 'bottom', 'text-bottom' ),
42274227 'frame' => array( 'thumbnail', 'manualthumb', 'framed', 'frameless',
4228 - 'upright', 'border' ),
 4228+ 'upright', 'border', 'click' ),
42294229 );
42304230 static $internalParamMap;
42314231 if ( !$internalParamMap ) {
@@ -4343,6 +4343,29 @@
43444344 /// downstream behavior seems odd with missing manual thumbs.
43454345 $validated = true;
43464346 break;
 4347+ case 'click':
 4348+ $chars = self::EXT_LINK_URL_CLASS;
 4349+ $prots = $this->mUrlProtocols;
 4350+ if ( $value === '' ) {
 4351+ $paramName = 'no-link';
 4352+ $value = true;
 4353+ $validated = true;
 4354+ } elseif ( preg_match( "/^$prots/", $value ) ) {
 4355+ if ( preg_match( "/^($prots)$chars+$/", $value, $m ) ) {
 4356+ $paramName = 'click-url';
 4357+ $this->mOutput->addExternalLink( $value );
 4358+ $validated = true;
 4359+ }
 4360+ } else {
 4361+ $clickTitle = Title::newFromText( $value );
 4362+ if ( $clickTitle ) {
 4363+ $paramName = 'click-title';
 4364+ $value = $clickTitle;
 4365+ $this->mOutput->addLink( $clickTitle );
 4366+ $validated = true;
 4367+ }
 4368+ }
 4369+ break;
43474370 default:
43484371 // Most other things appear to be empty or numeric...
43494372 $validated = ( $value === false || is_numeric( trim( $value ) ) );
Index: trunk/phase3/includes/Linker.php
@@ -699,6 +699,9 @@
700700 * bottom, text-bottom)
701701 * alt Alternate text for image (i.e. alt attribute). Plain text.
702702 * caption HTML for image caption.
 703+ * click-url URL to link to
 704+ * click-title Title object to link to
 705+ * no-link Boolean, suppress description link
703706 *
704707 * @param array $handlerParams Associative array of media handler parameters, to be passed
705708 * to transform(). Typical keys are "width" and "page".
@@ -795,12 +798,22 @@
796799 if ( !$thumb ) {
797800 $s = $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
798801 } else {
799 - $s = $thumb->toHtml( array(
800 - 'desc-link' => true,
801 - 'desc-query' => $query,
 802+ $params = array(
802803 'alt' => $fp['alt'],
803804 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
804 - 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false ) );
 805+ 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
 806+ if ( !empty( $fp['click-url'] ) ) {
 807+ $params['custom-url-link'] = $fp['click-url'];
 808+ } elseif ( !empty( $fp['click-title'] ) ) {
 809+ $params['custom-title-link'] = $fp['click-title'];
 810+ } elseif ( !empty( $fp['no-link'] ) ) {
 811+ // No link
 812+ } else {
 813+ $params['desc-link'] = true;
 814+ $params['desc-query'] = $query;
 815+ }
 816+
 817+ $s = $thumb->toHtml( $params );
805818 }
806819 if ( '' != $fp['align'] ) {
807820 $s = "<div class=\"float{$fp['align']}\">{$s}</div>";
Index: trunk/phase3/includes/MediaTransformOutput.php
@@ -50,6 +50,8 @@
5151 * alt Alternate text or caption
5252 * desc-link Boolean, show a description link
5353 * file-link Boolean, show a file download link
 54+ * custom-url-link Custom URL to link to
 55+ * custom-title-link Custom Title object to link to
5456 * valign vertical-align property, if the output is an inline element
5557 * img-class Class applied to the <img> tag, if there is such a tag
5658 *
@@ -133,6 +135,8 @@
134136 * valign vertical-align property, if the output is an inline element
135137 * img-class Class applied to the <img> tag, if there is such a tag
136138 * desc-query String, description link query params
 139+ * custom-url-link Custom URL to link to
 140+ * custom-title-link Custom Title object to link to
137141 *
138142 * For images, desc-link and file-link are implemented as a click-through. For
139143 * sounds and videos, they may be displayed in other ways.
@@ -147,7 +151,12 @@
148152
149153 $alt = empty( $options['alt'] ) ? '' : $options['alt'];
150154 $query = empty($options['desc-query']) ? '' : $options['desc-query'];
151 - if ( !empty( $options['desc-link'] ) ) {
 155+ if ( !empty( $options['custom-url-link'] ) ) {
 156+ $linkAttribs = array( 'href' => $options['custom-url-link'] );
 157+ } elseif ( !empty( $options['custom-title-link'] ) ) {
 158+ $title = $options['custom-title-link'];
 159+ $linkAttribs = array( 'href' => $title->getLinkUrl(), 'title' => $title->getFullText() );
 160+ } elseif ( !empty( $options['desc-link'] ) ) {
152161 $linkAttribs = $this->getDescLinkAttribs( $alt, $query );
153162 } elseif ( !empty( $options['file-link'] ) ) {
154163 $linkAttribs = array( 'href' => $this->file->getURL() );

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.

Status & tagging log