Mediawiki/Erweiterung/FileProtocolLinks

Aus Mikiwiki
Wechseln zu: Navigation, Suche

Die Mediawiki-Erweiterung FileProtocolLinks ermöglicht die Verlinkung zu Dateien auf dem lokalen rechner.

Inhaltsverzeichnis

Installation

1. Herunterladen der aktuellen Software unter http://www.mediawiki.org/wiki/Special:ExtensionDistributor/Description

Anlegen des Verzeichnisses "extensions/Description".

# mkdir extensions/Description
# chown wiki:wiki extensions/Description

2. Anlegen der Datei "extensions/FileProtocolLinks.php" und Einfügen des folgenden PHP-Codes: FileProtocolLinks 0.2 (für Mediawiki 1.14).

# vi extensions/FileProtocolLinks.php
<?php
 
/**
 * 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.
 
 * @author Edmund Mielach <edmund.mielach@s.roteskreuz.at>
 * @copyright Copyright 2005, Edmund Mielach
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @package MediaWikiExtensions
 * @version 0.2
 */
 
/**
 * Register the FileProtocolLinks extension with MediaWiki
 */ 
$wgExtensionFunctions[] = 'registerFileProtocolLinks';
 
/**
 * Sets the tag that this extension looks for and the function by which it
 * operates
 */
function registerFileProtocolLinks()
{
  global $wgParser;
  $wgParser->setHook('file', 'renderFileProtocolLink');
}
 
 
/**
 * 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)
{
  $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");
  }
 
  return sprintf('<a style="color:green" href="file:///%s">%s</a>', 
    $uri, $linktext);
}
 
#credits for [[Special:Version]]
$wgExtensionCredits['parserhook'][] = array(
  'name'        => 'FileProtocolLinks',
  'author'      => 'Edmund Mielach',
  'description' => 'highlights links to local filesystem',
  'url'         => 'http://www.mediawiki.org/wiki/Extension:FileProtocolLinks');	
?>

3. Anpassung der Rechte.

# chown wiki:wiki extensions/FileProtocolLinks.php

4. Einfügen der folgenden Zeile in die Datei "LocalSettings.php".

## Extension: FileProtocolLinks
require_once("extensions/FileProtocolLinks.php");

Weblinks