create new tag
, view all tags


I want to have filenames which people type into wiki made into links to that resource.

Please see SlashFilenamePlugin

To support this I have added the following to my create-links-to-all custom plugin's startRenderingHandler. This adds the browser-side feature of being able to surf microsoft windows file sharing server files (i.e. files on WINS servers, or SAMBA servers for unix boxes). This type of sharing has the syntax \\server\shared-resource\pathname\file. This is only used for very specific file linking...

Any suggestions to the below are appreciated. Likely I have missed a large cross section of possible pathnames.

Example Usage

The following paragraph is on my wiki.

The project is made up of the following source packages:

  • \\intranet\share\projects\myproj\src\base
  • \\intranet\share\projects\myproj\src\custom

The plugin will make the pathnames into href links.


inside startRenderingHandler:

# windows networking shares
# example: "the file is \\vsb1\vol1\directory\directory\file"
# example: "the file is \\vsb1\vol1\directory\directory\file." links only the file, not period.
# example: "the file is \\vsb1\vol1\directory\directory\file.txt" links the file & extension.
# example: "the drive is \\vsb1\vol1\." 
# example: \\vsb1\vol1\directory\directory\

    $_[0] =~ s/(\\\\[a-zA-Z0-9]+\\[a-zA-Z0-9_\-\\]+)/&handleShare($1)/geo;

    $_[0] =~ s/(\\\\[a-zA-Z0-9]+\\[a-zA-Z0-9_\-\\]+\.[a-zA-Z0-9_\-\$]+)/&handleShare($1)/geo;

where the handler function is:

sub handleShare
    return "<a href=\"".

-- JonathanCline - 08 Jul 2002

Good idea. How about you combine this with your Source code detector and publish it as FilenamePlugin?

-- MartinCleaver - 09 Jul 2002

I can put implementation notes there, however I can't release code, since it was developed for our intranet, and more importantly, when it comes to microsoft networking (like above), I am pretty naive. However since these are easy regex replacements, a plugin theoretically should be very easy.

-- JonathanCline - 09 Jul 2002

See DiskPathsAsLinks for some information on how to do file:/// type links in various browsers, and some discussion of syntax. This should probably be done as a plugin.

As for releasing code - it would be worth considering the fact that TWiki is GNU GPL licensed code that has been created and modified by many other people who are also doing work for their intranets, but decided that sharing their code was beneficial to their own company and to the TWiki community. If everyone decided "I can't release code because it was done for our intranet", it is doubtful that TWiki would be as powerful as it is today... See OpenSource for some links etc.

Nothing in the GPL requires you to release your code unless you distribute your modified TWiki to other people, whether in your company or elsewhere - however, the updates that you have done are already GPLed due to the way the license works, so if you do distribute your modified TWiki, the recipient is within their rights to redistribute the code. Even if your code is not very complete, it's useful to see it so that it can be improved. Of course, you have released some code on this page, so I'm not sure why releasing all the code would be a problem.

-- RichardDonkin - 09 Jul 2002

These are the requirements as I see it for MetaLinkToMicrosoftFileSharing and DiskPathsAsLinks and FilenamePlugin. With the below examples, backslashes are equivalent to forward slashes, except for protocol prefixes (like file://).

Security Warning? These methods may have the possibility of executing a file. This means some other user can type in the name of a trojan, and other users might end up executing it.

1. user types file protocol, file://some/URL 
  wiki replaces with anchor 
  <a href="file://some/URL">file://some/URL</a>

2. user types WINS path, \\server\share\some\path
  wiki replaces with anchor
  <a href="file://server/share/some/path">//server/share/some/path</a>

3. user types full-dos-path or mapped network drive path, x:\some\path
  wiki replaces with anchor
  <a href="file://x/some/path">//localhost/x/some/path</a>

4. user types a simple path, /some/path
   this might be the name of a mount point, a windows path, or a cvs module path.
   for windows servers, a default drive would have to be filled in.
  wiki replaces with anchor
  <a href="file://some/path">/some/path</a>
  unless the cvs module 'some' exists, in which case,
  wiki replaces with anchor
  <a href="http://your-link-to-cvsweb-root/some/path">/some/path</a>

5. any mac specific stuff?  Anyone use os-x?  Do all mac cases fall under the unix cases?

Configuration options for the theoretical plugin.

  1. anchors can optionally open of new browser windows.
  2. anchors may use the text "{External Link}" after the keyword to indicate to user an external resource.
  3. default drive letter (i.e. H:) to use on windows servers.
  4. list of mount points, for unix servers ? or just link anyway, and if unavailable, the link will appear broken.
  5. It would be much more featurefull to insert a link for each path element (like cvsweb).
    • //server/some/long/path/file.txt inserts a link for each word: server, some, long, path, file.txt
  6. for security? disable linking to a file target to prevent user from executing the file.
    • easy for dos-style filenames, just don't link file.exe
    • impossible for any other pathname, since /some/path/to/directory.extension looks exactly like some/path/to/file.extension
  7. for more security, allow disabling all use of file:// (see above)
    • or only for trusted servers or mount points
  8. all or none of these link modes may be enabled.


  • if spaces are in the filenames, it's impossible. How can reliable links for "c:\program files" be created automatically (i.e. without other tokenization like brackets around the path)?

-- JonathanCline - 10 Jul 2002

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2003-06-12 - JonathanCline
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.