Extension:UncPath

From MediaWiki.org
Jump to: navigation, search


MediaWiki extensions manual - list
Crystal Clear action run.png
uncPath

Release status: beta

Implementation Tag
Description Add's Intranet Link Capability for Files Stored in your wiki and for \\servername\filename paths
Author(s) DksheffieldTalk
License No license specified
Download .rar File
Tags
<unc />

Check usage (experimental)

Contents

[edit] What can this extension do?

This extension has two main purposes:

  • Allow "Intranet Style" linking to files that are uploaded into your wiki
  • Allow "Intranet Style" linking to files stored on your intranet "\\servername\filename.ext"

This is only beneficial to you if your wiki is housed internally and used for as an intranet for your company.

[edit] Example

  • You upload an Excel spreadsheet to your wiki
  • You want to provide a link to the file that people can click on to edit the file
  • Place the filename in the <unc /> Tags like this: <unc>Filename.xls</unc>
  • Now users can click the link and the file will open in excel
    • Standard file permissions apply when opening the file, the user must have Read / Write Access to the file to be able to open it

[edit] Usage

  • To Create a link to a file stored in your wiki:
<unc>Filename.ext</unc>
  • To create a link to a file not stored in your wiki
<unc>\\servername\filename.ext</unc>

[edit] Download instructions

Please cut and paste the code found below and place it in $IP/extensions/uncPath/uncPath.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

[edit] Installation

To install this extension, add the following to LocalSettings.php:

#add configuration parameters here
#setup user rights here
require_once("$IP/extensions/uncPath/uncPath.php");

[edit] Configuration parameters

[edit] User rights

[edit] Code

  • Save this code as uncPath.php and place in your /extensions/uncPath/ directory
 <?php
// Credits
$wgExtensionCredits['uncPaths'][]= array(
  'name'         => 'UNC Path File Extension', 
  'version'      => '1.0.1', 
  'author'       => 'David Sheffield', 
  'url'          => 'http://www.mediawiki.org/wiki/Extension:UncPath', 
  'description'  => 'This extension allows for easier file sharing in an intranet environment. It allows files and paths inside a <unc /> tag to be linked easily');
 
//Decalre and Set Path to the upload directory, use / slashes
// $path_to_upload_directory = "//david-xppro01/c$/wamp/www/it_wiki/images/";
 
 
$wgHooks['ParserFirstCallInit'][] = 'efUncParserInit';
 
function efUncParserInit( &$parser ) {
        $parser->setHook( 'unc', 'efUncRender' );
        return true;
}
 
function efUncRender( $input, $args, $parser, $frame ) {
 
//Decalre and Set Path to the upload directory, use / slashes
$path_to_upload_directory = "//servername/sharename/upload/directory/images/";
$path_to_icon_file = "/w//extensions/uncPath/icon.png";
 
//Find out if it is a file stored in mediawiki or an external unc path
                $backslash_count = substr_count($input, '\\');
        if ($backslash_count == 0) {
                //This is a wiki Upload
                $descr = "It is a wiki upload";
 
                //Replace all blanks " " with an underscore "_"
                        $input = str_replace(" ", "_", $input);
 
                //Get Has Value of filename
                        $hash_value = md5($input);
                //Get First character of hash value
                        $first_character_of_hash = substr($hash_value, 0, 1);
                //Get First two Chatacters of Has Value
                        $second_characters_of_hash = substr($hash_value, 0, 2);
 
                //Create http link
                        $http_path = "file:///" . $path_to_upload_directory . $first_character_of_hash . "/" . $second_characters_of_hash . "/" . $input;
 
                //Create UNC Path
                //Replace all / with \\
                        $unc_path = str_replace("/", "\\", $path_to_upload_directory);
                        $unc_path = $unc_path . $first_character_of_hash . "\\" . $second_characters_of_hash . "\\" . $input;
 
                //Create HTML Output
                        $html_output = "<a href='" . $http_path . "' class='external text' title='" . $unc_path . "' rel='nofollow' target='_blank'><img alt='" . $unc_path . "' src='" . $path_to_icon_file . "' width='20' height='20' border='0' />" . $input . "</a>";
 
 
        } else {
                $descr = "It is an External UNC Path";
 
                // Create HTTP Path
                        //Convert all \ to /
                        $http_path = str_replace('\\', '/', htmlspecialchars($input));
                        $http_path = "file:///" . $http_path;
 
                // Create UNC Path
                        $unc_path = $input;
 
                //Create HTML Output
                        $html_output = "<a href='" . $http_path . "' class='external text' title='" . $unc_path . "' rel='nofollow' target='_blank'><img alt='" . $unc_path . "' src='" . $path_to_icon_file . "' width='20' height='20' border='0' />" . $unc_path . "</a>";
 
 
 
        }
 
// Write the Output that displays on the wiki page
 
        // This line gives us a description of what type file it is
        //return $descr . "<br />" . $html_output;
 
        return $html_output;
 
}

[edit] See also

Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox