Extension:Email Link

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
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

Check usage (experimental)

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.


[edit] Installation

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:

 require_once('extensions/maillink.php');

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

[edit] Source code

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:

<?php
// tested with MW 1.11
function addMailLinks(&$parser, &$text, &$strip_state) {
    $mc = "[A-Za-z0-9._+-]";
    $mcs = "[A-Za-z0-9]";
    $text = preg_replace(
        "{(?<![\\[:/])(?<!$mcs)($mcs$mc*@$mcs$mc*\.$mcs{2,})(?!$mc)(?![\\]:/])}",
        '[mailto:$1 $1]',
        $text
    );
    return true; //added for Mediawiki 1.11
} 
$wgHooks['ParserAfterStrip'][] = 'addMailLinks';
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox