Extension:FileProtocolLinks
|
FileProtocolLinks Release status: stable |
|
|---|---|
| Implementation | Tag |
| Description | Allows creation of links to local filesystem or network files |
| Author(s) | EdmundMielach,Silver Quettier |
| Last version | 0.3 (2011-12-14) |
| MediaWiki | 1.16 or above |
| License | GPL |
| Download | No link |
|
Check usage (experimental) |
|
Contents |
[edit] 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 another colour (green)
[edit] Examples
The following examples should show how you can use this extension.
[edit] Link to a file on a fileserver on 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 insufficient privileges, or they have access to the wiki from outside your LAN).
<file>\\Fileserver\Directory1\Directory2\MyFile.zip</file>
[edit] 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!
[edit] Windows
<file>C:/Directory1/Directory2/MyFile.zip</file>
or
<file>C:/Directory1/Directory2/MyFile.zip|ZIP-Archive of MyFile</file>
[edit] Templating
You can use this in a template (without subst: as of version 0.3) for various reasons, such as factoring a common long path for multiple resources:
Code:
{{getOnIntranet|file=work/myFile.zip|txt=Some important file}}
Template:
<file>//some/very/long/path/with/a/lot/of/subdirectories/{{{file}}}|{{{txt}}}</file>
[edit] Limitations
- This extension does not work with some browsers due to security reasons. Detailed info can be found here. Maybe installing this extension helps Firefox users.
- It does not (yet) handle special characters like '#' [1] in the link addresses.
[edit] Changelog
[edit] Version 0.3
Added support for wikitext parsing - requires mediawiki 1.16a or above.
[edit] Version 0.2
Avoid XSS vulnerability (many thanks to Kate)
[edit] Sourcecode
Add the following to your LocalSettings.php:
require_once("$IP/extensions/FileProtocolLinks.php");
Add the following source code to the extensions/FileProtocolLinks.php directory
<?php /** * This file contains the main include file for the FileProtocolLinks extension of * MediaWiki. This code is released under the GNU General Public License. * * As I am new to php the code for this plugin was taken from the XFNLinks Plugin. * Thanks to Travis Swicegood for his work. * * 2011 Edit by Silver Quettier : added wikitext parsing * @author Edmund Mielach <edmund.mielach@s.roteskreuz.at> * @copyright Copyright 2005, Edmund Mielach * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @package MediaWikiExtensions * @version 0.3 */ /** * 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 * <a style="color:green" href="file:///c:/something.txt“>some nice text</a> * The links are rendered in green text color to make it easier to recognize * them as local shares. */ function renderFileProtocolLink($input, array $args, Parser $parser, PPFrame $frame) { $exploded = explode('|', $input); $uri = htmlentities($exploded[0], ENT_COMPAT, "UTF-8"); if (!isset($exploded[1]) || empty($exploded[1])) { // no linktext has been specified ==> use the URI as linktext $linktext = $uri; } else { $linktext = htmlentities($exploded[1], ENT_COMPAT, "UTF-8"); } $linktext = $parser->recursiveTagParse($linktext, $frame); $uri = $parser->recursiveTagParse($uri, $frame); return sprintf('<a style="color:green" href="file:///%s">%s</a>', $uri, $linktext); } #credits for [[Special:Version]] $wgExtensionCredits['parserhook'][] = array( 'name' => 'FileProtocolLinks', 'author' => 'Edmund Mielach, Silver Quettier', 'description' => 'highlights links to local filesystem', 'url' => 'http://www.mediawiki.org/wiki/Extension:FileProtocolLinks'); ?>
[edit] See also
- Extension:FileLink
- Extension:FileProtocolLinks
- Extension:FileLink ParserFunction
