Extension:FileProtocolLinks
![]() |
This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net. |
FileProtocolLinks Release status: stable |
|||
---|---|---|---|
Implementation | Tag | ||
Description | Allows creation of links to local filesystem or network files | ||
Author(s) | EdmundMielach, Silver Quettier | ||
Latest version | 0.3.2 (2011-12-14) | ||
MediaWiki | 1.16+ | ||
License | GPL v2+ | ||
Download | see here | ||
|
|||
Translate the FileProtocolLinks extension if possible |
|||
Check usage and version matrix; code metrics |
The FileProtocolLinks 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)
Contents
Examples[edit | edit source]
The following examples should show how you can use this extension.
Link to a file on a fileserver on your LAN[edit | edit source]
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>
Link to a file on your local computer[edit | edit source]
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[edit | edit source]
<file>C:/Directory1/Directory2/MyFile.zip</file>
or
<file>C:/Directory1/Directory2/MyFile.zip|ZIP-Archive of MyFile</file>
Templating[edit | edit source]
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>
Limitations[edit | edit source]
- 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.
Changelog[edit | edit source]
Version 0.3[edit | edit source]
Added support for wikitext parsing - requires mediawiki 1.16a or above.
Version 0.2[edit | edit source]
Avoid XSS vulnerability (many thanks to Kate)
Installation[edit | edit source]
Add the following to your LocalSettings.php:
require_once( "$IP/extensions/FileProtocolLinks/FileProtocolLinks.php" );
Sourcecode[edit | edit source]
Add the following source code to the /extensions/FileProtocolLinks/ directory
- FileProtocolLinks.php
<?php if ( !defined( 'MEDIAWIKI' ) ) { die( 'This file is a MediaWiki extension, it is not a valid entry point' ); } /** * 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 <[email protected]> * @copyright Copyright 2005, Edmund Mielach * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @package MediaWikiExtensions * @version 0.3.2 */ /** * Check if we are being called directly */ if ( !defined( 'MEDIAWIKI' ) ) { die( 'This file is an extension to MediaWiki and thus not a valid entry point.' ); } /** * Register this extenion on Special:Version */ $wgExtensionCredits['parserhook'][] = array( 'name' => 'FileProtocolLinks', 'author' => array( 'Edmund Mielach', 'Silver Quettier' ), 'version' => '0.3.2', 'description' => 'Allows creation of links to local filesystem or network files', 'url' => 'https://www.mediawiki.org/wiki/Extension:FileProtocolLinks' ); $wgHooks['ParserFirstCallInit'][] = 'wfRegisterFileProtocolLinks'; /** * Sets the tag that this extension looks for and the function by which it * operates */ function wfRegisterFileProtocolLinks( Parser $parser ) { $parser->setHook( 'file', 'renderFileProtocolLink' ); return true; } /** * 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 ); }