Extension:ImgTag
Release status: stable |
|
|---|---|
| Implementation | Tag, Parser function |
| Description | Adds back the <img /> tag removed in MediaWiki 1.42 |
| Author(s) | PetraMagnatalk |
| Latest version | v0.2.1 |
| MediaWiki | 1.43+ |
| Database changes | No |
| License | GNU General Public License 2.0 or later |
| Download | GitHub: Note: |
|
|
The ImgTag extension adds back the <img /> tag removed in MediaWiki 1.42. It also adds a parser function {{#fileused that marks a local file as being used on the page.
Installation
[edit]- Download and place the file(s) in a directory called
ImgTagin yourextensions/folder. - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'ImgTag' );
- Configure as required.
Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Configuration
[edit]$wgImgTagSanitizeDomain- Whether the domain name of the image tag's
srcattribute should be sanitized. - Default:
true. $wgImgTagDomains- An array of permitted domains in the src attribute. Disabled if
$wgImgTagSanitizeDomainis set tofalse. - Default:
['upload.wikimedia.org']. $wgImgTagProtocols- An array of permitted protocols for loading images.
- Default:
['http', 'https'].
Usage examples
[edit]Below is a basic example.
<img src="https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg" width="100px" class="some-class" alt="Logo of Wikipedia" />
You can also use a parser function:
{{#img:
|src=https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg
|width=100px
|class=some-class
|alt=Logo of Wikipedia
}}
This example registers a file as being used on a page using the parser function {{#fileused. Note that alternatives such as using Scribunto's exists function is expensive and therefore not scalable.
<img src="{{filepath:Logo.png}}" width="50px" />
{{#fileused:Logo.png}}
Permitted attributes
[edit]Below is an example element using all permitted attributes. Note that this example should not be used in practice because some attributes render others useless. See Mozilla's documentation for more details on how to use each attribute.
<img
id="img-id"
style="border: 1px solid black"
alt="An example image"
title="Example"
width="200px"
height="auto"
class="some-class"
fetchpriority="low"
loading="lazy"
sizes="(width <= 600px) 200px, 50vw"/>
Caveats
[edit]Although <img> is valid HTML markup since it is a self-closing tag, MediaWiki cannot properly parse it, so it is not supported by this extension. All usages must end with a slash (i.e. <img ... />). Some extensions with similar functionalities can automatically add a slash at the end: see AddImgTag and MoeImgTag listed at the end of the page.
See also
[edit]| This extension is included in the following wiki farms/hosts and/or packages: This is not an authoritative list. Some wiki farms/hosts and/or packages may contain this extension even if they are not listed here. Always check with your wiki farms/hosts or bundle to confirm. |
