Extension:EmailAddressImage

What can this extension do?
This extension turns text between and tags into an image of the text, so you can embed email addresses in your wiki without having them harvested by spammers. The address will not be clickable or copy/pastable; users will have to copy it by hand into a mail.

Usage
The email address must be specified in this tag format: user@domain.com. The code verifies that the text between the tags looks like an email address to prevent HTML/XSS injection.

Installation
Copy code below into wiki/extensions/EmailAddressImage.php and wiki/extensions/EmailAddressImage-generator.php, then add the include to your LocalSettings.php.

Note that the code assumes you're placing the code files into wiki/extensions/. If you place them elsewhere (e.g. in /wiki/extensions/EmailAddressImage/), you must modify the URL generated in the code to match.

Changes to LocalSettings.php
require_once("/extensions/EmailAddressImage.php");

EmailAddressImage.php
<?php


 * 1) allows the use of tag foo@domain.com which will result
 * 2) in inline insertion of an image with the text foo@domain.com
 * 3) CREDITS:
 * 4) email address regexp pattern borrowed from:
 * 5)   http://www.regular-expressions.info/email.html
 * 1)   http://www.regular-expressions.info/email.html

$wgExtensionFunctions[] = 'emailAddressImage';

$wgHooks['ParserAfterStrip'][] = 'emailAddressImage';
 * 1) Sets the hook to be executed once the parser has stripped HTML tags.

function emailAddressImage { global $wgParser;

$wgParser->setHook( 'email', 'doAddressImage' ); }

function doAddressImage( $input, $argv ) { $email_pattern = '/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b/';

$found = preg_match($email_pattern, $input, $matches);

$addr = ( empty( $found ) ? '[INVALID EMAIL ADDR]' : $matches[0] );

global $wgScriptPath; // wiki's root path, defined in LocalSettings

return ""; } ?>

EmailAddressImage-generator.php
 blah blah.

Header ("Content-type: image/gif");

if (isset($_REQUEST['str'])) { $string = $_REQUEST['str']; } else { $string = "[Invalid email address]"; }

$font = 4; $width = ImageFontWidth($font)* strlen($string); $height = ImageFontHeight($font); // + 5; $im = ImageCreate($width,$height);

$x=imagesx($im)-$width ; $y=imagesy($im)-$height; // + 2;

$background_color = imagecolorallocate ($im, 242, 242, 242); //white background $text_color = imagecolorallocate ($im, 0, 0,0);//black text $trans_color = $background_color;//transparent colour

imagecolortransparent($im, $trans_color); imagestring ($im, $font, $x, $y, $string, $text_color);

imagegif($im); ImageDestroy($im); ?>