MediaWiki extensions manual
OOjs UI icon advanced-invert.svg
Release status: unmaintained
Implementation Hook , Link markup
Description Act as a complement for the FileProtocolLinks extension by rewriting file:/// protocol links into smb:// ones, for non windows computer.
Author(s) Jean-Louis Biasini (Baruch99talk)
Latest version 0.1 (2015-06-19)
MediaWiki 1.25+ (probably working on earlier version too.)
PHP tested on 5.5 (probably working on earlier version too.)
License GPL
Download No link
require_once( "extensions/FileProtocolLinksLinux.php" );

Check usage and version matrix.

What can this extension do?Edit

If you use Extension:FileProtocolLinks to create links to local Windows shares, Linux and Mac users are not able to follow them.

This extension changes the links according to the client OS from "file:///\\windows_server\folder\to\file.ext" to "smb://windows_server/folder/to/file.ext" All other behaviour from Extension:FileProtocolLinks should remains unchanged.

This is an adaptation/improvement of the Extension:SmbLinks from Daniel Schürmann and of Extension:FileProtocolLinksSMB from Dan Sinclair. The same idea is implemented (detection by user-agent, rewritings of links). The only difference is that it is applied not at the link creation but just before it get displayed. That way it works also with cache activated. Extension:SmbLinks seems broken on the current version of MediaWiki (which is 1.25 as of June 2015). Extension:FileProtocolLinksSMB does not works with cache enable. So this can be considered as a rewriting/update of Daniel Schürmann and Dan Sinclair work.


The usage is the very same as for Extension:FileProtocolLinks, it just expands its possibility to have it work on Linux (and Mac). Note that it might also slow your wiki a bit due to extra time processing before displaying the page. (I did not notice it...)

MS WindowsEdit

On MS Windows machines, the behavior stay just as with the Extension:FileProtocolLinks extension



you have to register the smb: protocol handler.

  • Open "about:config" and add the following settings:

network.protocol-handler.expose.smb = false (Typ: boolean)
network.protocol-handler.external.smb = true (Typ: boolean)

  • Next time you click an smb: Link firefox ask you for an application.

select "/usr/bin/xdg-open". This does not mount the location. So ensure sat you have opened the window share with your file application first.

  • For KDE:

This is from the Extension:SmbLinks extension and was not actually tested:

we have to make a workaround with a script because Firefox does not allow do add additional parameters

kfmclient exec $1
  • You will have to confirm that you want to access on local share

Tested with:

  • Client: Firefox 38.0.1 on Debian jessie, Server: centos6.6, Apache/2.2.15, php-fpm/5.5.26, memcached


... TO DO ...


require_once("$IP/extensions/FileProtocolLinksLinux.php" );
  • Be sure to disable file caching, as it create a conflict:

$wgUseFileCache = false;

  • Then paste the following code in a new <MW folder>/extensions/FileProtocolLinksLinux.php file.


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 FileProtocolLinksLinux extension of
 * MediaWiki. This code is released under the GNU General Public License.
 * This extension was inspired by the Smblinks one, written by Daniel Schürmann and of 
 * FileProtocolLinksSMB from Dan Sinclair
 * This comes as a complement to the FileProtocolLinks extension. You NEED to
 * install FileProtocolLinks first for this to work.
 * @author Jean-Louis Biasini (Baruch99)
 * @copyright Copyright 2015, Jean-Louis Biasini
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @version 0.1

 * 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' => 'FileProtocolLinksLinux',
                                            'author' => array( 'Jean-Louis Biasini' ),
                                            'version' => '0.1',
                                            'description' => 'Act as a complement for the FileProtocolLinks extension by rewriting file:/// protocol links into smb:// ones, for non windows computer.',
                                            'url' => 'https://www.mediawiki.org/wiki/Extension:FileProtocolLinksLinux'

$wgHooks['BeforePageDisplay'][] = 'AdaptFileProtocolToUserAgent';

function AdaptFileProtocolToUserAgent( $out ) {
  // retrieve user agent
  $user_agent = $_SERVER['HTTP_USER_AGENT'];
  if (!strstr($user_agent, "Windows")) {
    // This is a non-windows user agent
    if(preg_match_all('/file:\/\/\/[^"]+/', $out->mBodytext, $matches)) {
      // There are file(s) link(s) on the page
      foreach($matches as $key=>$value) {
        // we rewrite each link to smb:// protocol
        $repl = str_replace('file:///', 'smb:', $value);
        // But wait! Those slash are not in the right direction either!
        $repl = str_replace('\\', '/', $repl);
        // We pass the corrected text back to the OutPage object
        $out->mBodytext = str_replace( $value, $repl, $out->getHTML());
    return true;