Mediawiki/Erweiterung/FileProtocolLinks: Unterschied zwischen den Versionen

Aus Mikiwiki
Zur Navigation springen Zur Suche springen
(Die Seite wurde neu angelegt: „Die Mediawiki-Erweiterung <b>FileProtocolLinks</b> ermöglicht die Verlinkung zu Dateien auf dem lokalen rechner. == Installation == 1. Herunterladen der ak...“)
 
Keine Bearbeitungszusammenfassung
Zeile 44: Zeile 44:
function registerFileProtocolLinks()
function registerFileProtocolLinks()
{
{
    global $wgParser;
  global $wgParser;
    $wgParser->setHook('file', 'renderFileProtocolLink');
  $wgParser->setHook('file', 'renderFileProtocolLink');
}
}
   
   
Zeile 66: Zeile 66:
function renderFileProtocolLink($input)
function renderFileProtocolLink($input)
{
{
    $exploded = explode('|', $input);
  $exploded = explode('|', $input);
    $uri = htmlentities($exploded[0], ENT_COMPAT, "UTF-8");
  $uri = htmlentities($exploded[0], ENT_COMPAT, "UTF-8");
   
   
    if (!isset($exploded[1]) || empty($exploded[1])) {
  if (!isset($exploded[1]) || empty($exploded[1])) {
        // no linktext has been specified ==> use the URI as linktext
    // no linktext has been specified ==> use the URI as linktext
        $linktext = $uri;
    $linktext = $uri;
    }
  }
    else {
  else {
        $linktext = htmlentities($exploded[1], ENT_COMPAT, "UTF-8");
    $linktext = htmlentities($exploded[1], ENT_COMPAT, "UTF-8");
    }
  }
   
   
    return sprintf('<a style="color:green" href="file:///%s">%s</a>',  
  return sprintf('<a style="color:green" href="file:///%s">%s</a>',  
        $uri, $linktext);
    $uri, $linktext);
}
}
   
   
#credits for [[Special:Version]]
#credits for [[Special:Version]]
$wgExtensionCredits['parserhook'][] = array(
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'FileProtocolLinks',
  'name'       => 'FileProtocolLinks',
        'author' => 'Edmund Mielach',
  'author'     => 'Edmund Mielach',
        'description' => 'highlights links to local filesystem',
  'description' => 'highlights links to local filesystem',
        'url' => 'http://www.mediawiki.org/wiki/Extension:FileProtocolLinks');
  'url'         => 'http://www.mediawiki.org/wiki/Extension:FileProtocolLinks');
?>
?>
</source>
</source>

Version vom 3. Mai 2009, 19:03 Uhr

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

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