Mediawiki/Erweiterung/IconLink: Unterschied zwischen den Versionen
< Mediawiki | Erweiterung
Michi (Diskussion | Beiträge) |
Michi (Diskussion | Beiträge) |
||
Zeile 141: | Zeile 141: | ||
* <ilink>http://www.allocine.fr/ Allocine</ilink> | * <ilink>http://www.allocine.fr/ Allocine</ilink> | ||
* {{#iconlink: http://www.allocine.fr/ | Allocine | icon | width | height}} | |||
== Weblinks == | == Weblinks == |
Version vom 1. März 2009, 14:27 Uhr
Fügt den zusätzlichen Tag <link> hinzu, der das Favicon der betreffenden Website vor jeden externen Link setzt.
Installation
1. Anlegen des Verzeichnisses "extensions/IconLink".
# mkdir extensions/IconLink # chown wiki:wiki extensions/IconLink
2. Anlegen der Datei "extensions/FaviconLink.php" und Einfügen des folgenden PHP-Codes: IconLink 0.1 (2008-03-11).
# vi extensions/IconLink/IconLink.php
<?php
#
# IconLink extension for MediaWiki
#
# Installation:
# create a new directory extensions/IconLink and copy all files there
# add the following to LocalSettings.php:
# require_once( "extensions/IconLink/IconLink.php" );
#
# Usage:
# {{#iconlink: url | description | icon | width | height}}
# where
# - url is the URL you want to create a link to
# - description is the text to show instead of the URL (optional)
# - icon is the URL of the image to show before the link (optional)
# if omitted, the favicon of the site you're linking is shown
# - width and height define the dimensions of the icon (both optional)
# if omitted, the icon will have a size of 16x16 pixels
#
if(! defined('MEDIAWIKI')) {
die("This is a MediaWiki extension and can not be used standalone.\n");
}
$wgExtensionCredits['parserhook'][] = array(
'name' => 'IconLink',
'description' => 'Prepends an icon to a link.',
'version' => '0.1',
'author' => 'Robert Hänel'
);
require_once('IconLink.code.php');
$wgExtensionFunctions[] = "wfIconLinkSetup";
$wgHooks['LanguageGetMagic'][] = 'wfIconLinkMagic';
function wfIconLinkSetup() {
global $wgParser;
$wgParser->setFunctionHook('iconlink', 'wfIconLinkRender');
}
function wfIconLinkMagic( &$magicWords, $langCode ) {
$magicWords['iconlink'] = array(0, 'iconlink');
return true;
}
?>
|
3. Anlegen der Datei "extensions/FaviconLink.php" und Einfügen des folgenden PHP-Codes: IconLink 0.1 (2008-03-11).
# vi extensions/IconLink/IconLink.code.php
<?php
function wfIconLinkRender(&$parser, $url = '', $description = '', $icon = '', $width = 16, $height = 16) {
if (empty($url)) {
return '';
}
$url = htmlspecialchars($url);
if (empty($description)) {
$description = $url;
}
$description = htmlspecialchars($description);
if (empty($icon)) {
# extract the first part of the URL (up until the host name) and append
# the name of the favicon file
$regex = '|^(http(s)?://[^/]+)|i';
preg_match($regex, $url, $result);
$icon = $result[0] . '/favicon.ico';
}
$icon = htmlspecialchars($icon);
if (! ctype_digit($width)) {
$width = 16;
}
if (! ctype_digit($height)) {
$height = 16;
}
# check the http return code after trying to access the icon file
# if it is 200 the file exists
$headers = @get_headers($icon);
$iconExists = (preg_match("|200|", $headers[0]) != 0);
$html = "<a href='$url'>";
if ($iconExists) {
$html .= "<img class='iconlink' src='$icon' width='$width' height='$height' />";
}
$html .= "$description</a>";
return $parser->insertStripItem($html, $parser->mStripState);
}
?>
|
4. Anpassung der Rechte.
# chown wiki:wiki extensions/IconLink/IconLink.php # chown wiki:wiki extensions/IconLink/IconLink.code.php
5. Einfügen der folgenden Zeile in die Datei "LocalSettings.php".
## Extension: IconLink require_once("$IP/extensions/IconLink/IconLink.php");
Verwendung
Der folgende Code erzeugt einen Link, vor dem das Favicon der betreffenden Website angezeigt wird.
{{#iconlink: url | description | icon | width | height}}
where
- url is the URL you want to create a link to
- description is the text to show instead of the URL (optional)
- icon is the URL of the image to show before the link (optional); if omitted, the favicon of the site you're linking is shown
- width and height define the dimensions of the icon (both optional); if omitted, the icon will have a size of 16x16 pixels
Das sieht dann so aus:
- <ilink>http://www.allocine.fr/ Allocine</ilink>
- {{#iconlink: http://www.allocine.fr/ | Allocine | icon | width | height}}
Weblinks
- <ilink>http://www.mediawiki.org/wiki/Extension:IconLink Extension:IconLink</ilink> (Mediawiki.org)