Extension:UncPath

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
Crystal Clear action run.svg
uncPath
Release status: unmaintained
Implementation Tag
Description Add's Intranet Link Capability for Files Stored in your wiki and for \\servername\filename paths
Author(s) David Sheffield (Dksheffieldtalk)
License No license specified
Download .rar File
Tags
<unc />
Hooks used
ParserFirstCallInit
Translate the UncPath extension if it is available at translatewiki.net
Check usage and version matrix.

The UncPath Add's Intranet Link Capability for Files Stored in your wiki and for \\servername\filename paths. It 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.

Example[edit]

  • 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

Usage[edit]

  • 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>

Download instructions[edit]

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.

Installation[edit]

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";

Code[edit]

  • Save this code as uncPath.php and place in your /extensions/uncPath/ directory
<?php
// 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.' );
}

// Credits
$wgExtensionCredits['uncPaths'][]= array(
  'name'         => 'UNC Path File Extension', 
  'version'      => '1.0.1', 
  'author'       => 'David Sheffield', 
  'url'          => 'https://www.mediawiki.org/wiki/Extension:UncPath', 
  'description'  => 'Allows for easier file sharing in an intranet environment'
);
  
//Declare 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 ) {

//Declare 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 Characters 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;

}