(Created page with "Images on a MediaWiki wiki will by default, link to the description page, so that licensing information, upload history, contributors, and full resolution version...") |
No edit summary |
||
Line 6: | Line 6: | ||
Direct internal or external links from images are possible using the syntax documented at [[Help:Images]] | Direct internal or external links from images are possible using the syntax documented at [[Help:Images]] | ||
{{note|link '''does not work with''' thumb '''or''' frame in versions before 1.17.}} | {{note|link '''does not work with''' thumb '''or''' frame in versions before 1.17.}} | ||
In your wikicode: | In your wikicode: | ||
<pre>[[Image:Wiki.png|50px|link= | <pre>[[Image:Wiki.png|50px|link=Main_Page]]</pre> | ||
This will make a 50px width picture with a link to the page [[ | This will make a 50px width picture with a link to the page [[Main_Page]]: | ||
[[Image:Wiki.png|50px|link= | [[Image:Wiki.png|50px|link=Main_Page]] | ||
==Old CSS workarounds for vanilla installs pre 1.14 == | ==Old CSS workarounds for vanilla installs pre 1.14 == | ||
MediaWiki was for a long time designed to prevent manual manipulation of images in wikicode which may circumvent the link to description page operation: The '''<tt><img></tt>''' tag is specifically not whitelisted in the | MediaWiki was for a long time designed to prevent manual manipulation of images in wikicode which may circumvent the link to description page operation: The '''<tt><img></tt>''' tag is specifically not whitelisted in the Sanitizer, nor is the '''<tt>background-image</tt>''' CSS attribute. | ||
On these older versions, there were the following workarounds. | On these older versions, there were the following workarounds. | ||
Line 56: | Line 54: | ||
===Inline CSS=== | ===Inline CSS=== | ||
You can also attempt to superimpose an invisible link over an image via CSS | You can also attempt to superimpose an invisible link over an image via CSS. An example of a typical click template is: | ||
<pre><div style="position: relative; width: {{{width}}}; height: {{{height}}}; overflow: hidden;"> | <pre><div style="position: relative; width: {{{width}}}; height: {{{height}}}; overflow: hidden;"> | ||
<div style="position: absolute; top: 0px; left: 0px; font-size: 100px; overflow: hidden; line-height: 100px; z-index: 3;">[[{{{link}}}|&nbsp;&nbsp;&nbsp;]]</div> | <div style="position: absolute; top: 0px; left: 0px; font-size: 100px; overflow: hidden; line-height: 100px; z-index: 3;">[[{{{link}}}|&nbsp;&nbsp;&nbsp;]]</div> | ||
Line 67: | Line 65: | ||
If you have server access, but do not want to install any extensions, these solutions may work for you. | If you have server access, but do not want to install any extensions, these solutions may work for you. | ||
===External image syntax=== | ===External image syntax=== | ||
If you enable | If you enable $wgAllowExternalImages (which allows external images from any domain) or $wgAllowExternalImagesFrom (which restricts the list of domains), anyone can then easily create an "external" link to an "external" image. External simply means: using the full URL rather than a local link, so you can link locally, but you need to use the full URL. The plainlinks class is used to remove the "external link" icon: | ||
After enabling | After enabling $wgAllowExternalImages, you can also embed an image by simply typing the URL of the image. | ||
For example <pre>http://domain.com/images/image_file.png</pre>, will display the image on screen. | For example <pre>http://domain.com/images/image_file.png</pre>, will display the image on screen. | ||
<span class="plainlinks"><span style="color:red;"><nowiki>[http://linktopage http://linktoimage]</nowiki></span></span> | <span class="plainlinks"><span style="color:red;"><nowiki>[http://linktopage http://linktoimage]</nowiki></span></span> | ||
So for example, were external images allowed here, you could link to the | So for example, were external images allowed here, you could link to the main page with http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png using wikicode like: | ||
<span class="plainlinks"><nowiki>[{{fullurl:MediaWiki}} http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png]</nowiki></span> | <span class="plainlinks"><nowiki>[{{fullurl:MediaWiki}} http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png]</nowiki></span> | ||
This has the disadvantage of not registering the link, or the image use, as well as not being easily portable to forks and mirrors. | This has the disadvantage of not registering the link, or the image use, as well as not being easily portable to forks and mirrors. | ||
==Other options== | ==Other options== | ||
Line 102: | Line 86: | ||
*[[Help:Images]] | *[[Help:Images]] | ||
[[Category:Help]] | |||
[[Category: |
Latest revision as of 15:49, 29 May 2013
Images on a MediaWiki wiki will by default, link to the description page, so that licensing information, upload history, contributors, and full resolution versions are immediately available to the user when he or she clicks an image.
However, there are several workarounds for those that require them.
link= Syntax available since version 1.14
Direct internal or external links from images are possible using the syntax documented at Help:Images
In your wikicode:
[[Image:Wiki.png|50px|link=Main_Page]]
This will make a 50px width picture with a link to the page Main_Page:
Old CSS workarounds for vanilla installs pre 1.14
MediaWiki was for a long time designed to prevent manual manipulation of images in wikicode which may circumvent the link to description page operation: The <img> tag is specifically not whitelisted in the Sanitizer, nor is the background-image CSS attribute.
On these older versions, there were the following workarounds.
Site CSS
The simplest method, if your requirements for external images are specialized (that is, restricted to one page or one image), is to add a CSS rule to your MediaWiki:Common.css (or other CSS files, such as MediaWiki:Skinname.css or /skins/skinname/main.css, etc) giving child links of a certain class of object a background image. This method also has some security, as it requires editing the site-wide CSS files, meaning only sysops have access to modify the image shown.
For example (red sections are parts to configure for each image):
In MediaWiki:Common.css:
.imagelink_somename a { width:100px; height:100px; display:block; text-decoration:none; background-image: url("http://fullurltoimage") }
In your wikicode:
<div class="imagelink_somename">[[Some link| ]]</div>
This would give the link the background image specified, as well as the width and height of the image (which you have to set manually). To find the location of an uploaded file, go to the image description page and click the image itself, and copy the image location in the address bar.
For example on Image:Wiki.png, the image location is http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png (location format will differ depending on local settings), and the width and height would be set to 135px and 135px. So to make a link to the main page here using that logo, one would add to MediaWiki:Common.css:
.imagelink_wikilogo a { width:135px; height:135px; display:block; text-decoration:none; background-image: url("http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png") }
And then use the wikicode:
<div class="imagelink_wikilogo">[[MediaWiki| ]]</div>
Which would give you:
You can also use a thumbnail of an image, but make sure the thumbnail is being used elsewhere, as most installations are not configured to generate thumbnails on demand.
Inline CSS
You can also attempt to superimpose an invisible link over an image via CSS. An example of a typical click template is:
<div style="position: relative; width: {{{width}}}; height: {{{height}}}; overflow: hidden;"> <div style="position: absolute; top: 0px; left: 0px; font-size: 100px; overflow: hidden; line-height: 100px; z-index: 3;">[[{{{link}}}| ]]</div> <div style="position: absolute; top: 0px; left: 0px; z-index: 2;">[[Image:{{{image}}}|{{{width}}}|{{{link}}}]]</div> </div>
Known problems: It doesn't work in text-only browsers, and in screen readers for the disabled, and possibly other situations. The technique of using CSS to change page content also completely breaks an article's web accessibility by contravening a WAI priority-one checkpoint.[1]
Native with configuration change
If you have server access, but do not want to install any extensions, these solutions may work for you.
External image syntax
If you enable $wgAllowExternalImages (which allows external images from any domain) or $wgAllowExternalImagesFrom (which restricts the list of domains), anyone can then easily create an "external" link to an "external" image. External simply means: using the full URL rather than a local link, so you can link locally, but you need to use the full URL. The plainlinks class is used to remove the "external link" icon:
After enabling $wgAllowExternalImages, you can also embed an image by simply typing the URL of the image.
For example
http://domain.com/images/image_file.png
, will display the image on screen.
<span class="plainlinks">[http://linktopage http://linktoimage]</span>
So for example, were external images allowed here, you could link to the main page with http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png using wikicode like:
<span class="plainlinks">[{{fullurl:MediaWiki}} http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png]</span>
This has the disadvantage of not registering the link, or the image use, as well as not being easily portable to forks and mirrors.
Other options
If you want, you can do some more drastic things, such as modify /includes/Sanitizer.php (where the HTML tag whitelist is), and add <img /> to the list of allowed tags.