Jump to content

Extension:AddImgTag

From mediawiki.org
MediaWiki extensions manual
AddImgTag
Release status: stable
Implementation Parser function , Tag
Description Provides the ‎<img> tag for MediaWiki 1.43 and later versions.
Author(s) awajietalk
Maintainer(s) awajie, ZoruaFox
Latest version 1.0.0 (2025-09-29)
Compatibility policy Main branch maintains backward compatibility.
MediaWiki 1.43+
PHP 7.4+
Database changes No
  • $wgAddImgTagBlacklist
  • $wgAddImgTagBlacklistDomainsList
  • $wgAddImgTagSelfClosingTag
  • $wgAddImgTagWhitelist
  • $wgAddImgTagWhitelistDomainsList
‎<img>
Licence GNU General Public License 2.0 or later
Download
README (Simplified Chinese)

The AddImgTag extension allows you to use HTML ‎<img> tags directly in your wiki pages, effectively restoring the support for this tag that was removed in MediaWiki 1.42.

Supported attributes include src, alt, title, loading, width, height, class, style.

Installation

[edit]
  • Download and place the file(s) in a directory called AddImgTag in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'AddImgTag' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Usage

[edit]

Simply add the ‎<img> tag to your wiki pages. For example:

<img src="https://example.com/image.jpg" alt="Example image" width="300" height="200" />

The tag is also available as a parser function, supporting the same parameters. For example:

{{#img: url| width=100px| height=100px| ....}}

Configuration

[edit]

You can control which image sources are allowed or blocked using the following configuration parameters:

Parameter Description Type Default
$wgAddImgTagSelfClosingTag Whether to replace every instance of ‎<img> in a wiki page with ‎<img />.

This feature iterates through the page with a time complexity of On, hence it is disabled by default.

Boolean false
$wgAddImgTagWhitelist Whether to enable or not the whitelist feature. Boolean false
$wgAddImgTagWhitelistDomainsList List of domains that are always allowed. Array []
$wgAddImgTagBlacklist Whether to enable or not the blacklist feature. Boolean false
$wgAddImgTagBlacklistDomainsList List of domains that are always blocked. Array []

Example configuration in LocalSettings.php:

$wgAddImgTagWhitelistDomainsList = [
    'commons.wikimedia.org',
    'upload.wikimedia.org'
];

$wgAddImgTagBlacklistDomainsList = [
    'example.com',
    'untrusted-site.org'
];

See also

[edit]