Extension:FileProtocolLinks

Description
This extension renders links to local shares on a (corporate) intranet. It can also be used to render links to any resource in your filesystem if you are running a personal wiki on your localhost. You can also use an alternative way to enable file protocol links, but the FileProtocolLinks extension brings some little benefits:
 * It allows link adresses with blanks as sometimes usual on windows systems (e.g. c:\folder with blanks\file with blanks.txt
 * It renders the links in an other colour ;) (a nice green in this version g, but you can change the settings in the sourcecode)

Examples
The following examples should show how you can use this extension.

Example 1: A link to a file on a fileserver in your LAN
This example shows how to add a direct link to a File on a Fileserver on your LAN. Note that some wiki users may have no access to this file (e.g. due to insuficient privileges, or they have access to the wiki from outside your LAN).

Windows
//Fileserver/Directory1/Directory2/MyFile.zip

Example 2: A link to a file on your local computer
This example shows how to add a direct link to a File on your local machine (localhost). Do not use such links to local resources, except for personal wikis which are only running at your localhost!

Windows
C:/Directory1/Directory2/MyFile.zip

Limitations
http://kb.mozillazine.org/Firefox_:_Issues_:_Links_to_Local_Pages_Don't_Work
 * This extension does not work with some Browsers due to security reasons. Detailed Infos can be gathered here:
 * It does not (yet) handle special characters like '#' in the link addresses.

Version 0.2
Avoid XSS vulnerability (many thanks to Kate)

Sourcecode
Add the following to your LocalSettings.php

require_once("extensions/FileProtocolLinks.php");

Add the following source code to the extensions/FileProtocolLinks.php directory  * @copyright Copyright 2005, Edmund Mielach * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @package MediaWikiExtensions * @version 0.2 */ /** * Register the FileProtocolLinks extension with MediaWiki */ $wgExtensionFunctions[] = 'registerFileProtocolLinks';

/** * Sets the tag that this extension looks for and the function by which it * operates */ function registerFileProtocolLinks {   global $wgParser; $wgParser->setHook('file', 'renderFileProtocolLink'); }

/** * Renders a file protocol link based on the information provided by $input. * * @param string * The string should be in the following format: *     URI[;link text] * One example for a Windows environment would be: *     c:/something.txt|some nice text * @return string * Returns an anchor tag for the given input. For the example above * the return string would be *      some nice text * The links are rendered in green text color to make it easier to recognize  * them as local shares. */ function renderFileProtocolLink($input) {    $exploded = explode('|', $input);    $uri = htmlentities($exploded[0]);    if (!isset($exploded[1]) || empty($exploded[1])) {        // no linktext has been spezified ==> use the URI as linktext        $linktext = $uri;    }    else {        $linktext = htmlentities($exploded[1]);    }    return sprintf('%s',         $uri, $linktext); } ?>