Extension:Email Link

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
Email Link
Release status: stable
Implementation Link markup
Description Turns email addresses into links
Author(s) Juerd
License No license specified
Download Author's website
Translate the Email Link extension if it is available at translatewiki.net
Check usage and version matrix.

This extension matches things that look like email addresses, and turns them into links. It was not written because it's a good idea to do this, but because many people did want this feature.

Note that it does NOT match ALL valid email addresses because the author believes that there would be too many false positives.

The regular expression tries to avoid linking what is already linked, but cannot entirely reliably do so, because it doesn't parse all of the wikitext.


Put the source code below in a file called maillink.php in your extensions directory, and add the following line just before the closing ?> of your LocalSettings.php:


Note: you need to make sure that there is no whitespace just before the initial <?php in maillink.php.

Source code[edit]

The function needs to have a 'return true' added to the function as hooks have changed as of Mediawiki 1.11 apparently. The code should look like the following:

// tested with MW 1.11
function addMailLinks(&$parser, &$text, &$strip_state) {
    $mc = "[A-Za-z0-9._+-]";
    $mcs = "[A-Za-z0-9]";
    $text = preg_replace(
        '[mailto:$1 $1]',
    return true; //added for Mediawiki 1.11
$wgHooks['ParserAfterStrip'][] = 'addMailLinks';