Mediawiki/Erweiterung/FaviconLink: Unterschied zwischen den Versionen
< Mediawiki | Erweiterung
Michi (Diskussion | Beiträge) (Die Seite wurde neu angelegt: Fügt den zusätzlichen Tag <link> hinzu, der das Favicon der betreffenden Website vor jeden externen Link setzt. == Installation ==) |
Michi (Diskussion | Beiträge) (→Installation) |
||
(6 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 2: | Zeile 2: | ||
== Installation == | == Installation == | ||
+ | |||
+ | 1. Anlegen der Datei "extensions/FaviconLink.php" und Einfügen des folgenden PHP-Codes: FaviconLink 0.1 (). | ||
+ | |||
+ | # <b>vi extensions/FaviconLink.php</b> | ||
+ | |||
+ | {| class=wiki width=100% | ||
+ | | | ||
+ | <source lang=php enclose=div> | ||
+ | <?php | ||
+ | # FaviconLink MediaWiki extension | ||
+ | # | ||
+ | # To activate the extension, include it from your LocalSettings.php | ||
+ | # with: require_once ("extensions/FaviconLink.php"); | ||
+ | |||
+ | $wgExtensionCredits['specialpage'][] = array( | ||
+ | 'name' => 'FaviconLink', | ||
+ | 'author' => 'FlappySocks', | ||
+ | 'url' => 'http://www.mediawiki.org/wiki/Extension:FaviconLink', | ||
+ | 'description' => 'Grabs the favicon from the site you are linking to, and puts it in front of the link.' | ||
+ | ); | ||
+ | |||
+ | $wgExtensionFunctions[] = "wfFaviconLink"; | ||
+ | |||
+ | function wfFaviconLink() { | ||
+ | global $wgParser; | ||
+ | $wgParser->setHook( "ilink", "FaviconLink" ); | ||
+ | } | ||
+ | |||
+ | # The callback function for converting the input text to HTML output | ||
+ | function FavIconLink( $input) { | ||
+ | |||
+ | //Look for the start of the URL | ||
+ | $pt1 = strpos($input, "://"); | ||
+ | if ($pt1===false) $input="http://".$input; | ||
+ | |||
+ | //Look for the end of the domain | ||
+ | $pt1 = strpos($input, "/",9); | ||
+ | if ($pt1===false) $pt1 = strpos($input, " ",9); | ||
+ | if ($pt1===false) $pt1 = strlen($input); | ||
+ | $favicon = substr($input, 0, $pt1)."/favicon.ico"; | ||
+ | |||
+ | |||
+ | //Look for the name/description | ||
+ | $pt2 = strpos($input, " ",$pt1); | ||
+ | if ($pt2===false) | ||
+ | { | ||
+ | $link=substr($input, 0, strlen($input)); | ||
+ | $linkname = $link; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | $link=substr($input, 0, $pt2); | ||
+ | $linkname = substr($input, $pt2+1, strlen($input)-$pt2-1); | ||
+ | } | ||
+ | |||
+ | $favicon = htmlspecialchars($favicon); | ||
+ | $linkname = htmlspecialchars($linkname); | ||
+ | $link = htmlspecialchars($link); | ||
+ | |||
+ | return '<a href="'.$link.'"><img src="'.$favicon.'"> '.$linkname.'</a>'; | ||
+ | } | ||
+ | ?> | ||
+ | </source> | ||
+ | |} | ||
+ | |||
+ | 2. Anpassung der Rechte. | ||
+ | |||
+ | # <b>chown wiki:wiki extensions/FaviconLink.php</b> | ||
+ | |||
+ | 3. Einfügen der folgenden Zeile in die Datei "LocalSettings.php". | ||
+ | |||
+ | ## Extension: FaviconLink | ||
+ | include ("extensions/FaviconLink.php"); | ||
+ | |||
+ | == Verwendung == | ||
+ | |||
+ | Der folgende Code erzeugt einen Link, vor dem das Favicon der betreffenden Website angezeigt wird. | ||
+ | |||
+ | <pre class=wiki> | ||
+ | <ilink>http://www.allocine.fr/ Allocine</ilink> | ||
+ | </pre> | ||
+ | |||
+ | Das sieht dann so aus: | ||
+ | |||
+ | * <ilink>http://www.allocine.fr/ Allocine</ilink> | ||
+ | |||
+ | == Weblinks == | ||
+ | |||
+ | * <ilink>http://www.mediawiki.org/wiki/Extension:FaviconLink Extension:FaviconLink</ilink> (Mediawiki.org) | ||
+ | |||
+ | |||
+ | {{cat|Favicon}} | ||
+ | {{cat|Mediawiki}} |
Aktuelle Version vom 1. März 2009, 16:13 Uhr
Fügt den zusätzlichen Tag <link> hinzu, der das Favicon der betreffenden Website vor jeden externen Link setzt.
Inhaltsverzeichnis
Installation
1. Anlegen der Datei "extensions/FaviconLink.php" und Einfügen des folgenden PHP-Codes: FaviconLink 0.1 ().
# vi extensions/FaviconLink.php
<?php
# FaviconLink MediaWiki extension
#
# To activate the extension, include it from your LocalSettings.php
# with: require_once ("extensions/FaviconLink.php");
$wgExtensionCredits['specialpage'][] = array(
'name' => 'FaviconLink',
'author' => 'FlappySocks',
'url' => 'http://www.mediawiki.org/wiki/Extension:FaviconLink',
'description' => 'Grabs the favicon from the site you are linking to, and puts it in front of the link.'
);
$wgExtensionFunctions[] = "wfFaviconLink";
function wfFaviconLink() {
global $wgParser;
$wgParser->setHook( "ilink", "FaviconLink" );
}
# The callback function for converting the input text to HTML output
function FavIconLink( $input) {
//Look for the start of the URL
$pt1 = strpos($input, "://");
if ($pt1===false) $input="http://".$input;
//Look for the end of the domain
$pt1 = strpos($input, "/",9);
if ($pt1===false) $pt1 = strpos($input, " ",9);
if ($pt1===false) $pt1 = strlen($input);
$favicon = substr($input, 0, $pt1)."/favicon.ico";
//Look for the name/description
$pt2 = strpos($input, " ",$pt1);
if ($pt2===false)
{
$link=substr($input, 0, strlen($input));
$linkname = $link;
}
else
{
$link=substr($input, 0, $pt2);
$linkname = substr($input, $pt2+1, strlen($input)-$pt2-1);
}
$favicon = htmlspecialchars($favicon);
$linkname = htmlspecialchars($linkname);
$link = htmlspecialchars($link);
return '<a href="'.$link.'"><img src="'.$favicon.'"> '.$linkname.'</a>';
}
?>
|
2. Anpassung der Rechte.
# chown wiki:wiki extensions/FaviconLink.php
3. Einfügen der folgenden Zeile in die Datei "LocalSettings.php".
## Extension: FaviconLink include ("extensions/FaviconLink.php");
Verwendung
Der folgende Code erzeugt einen Link, vor dem das Favicon der betreffenden Website angezeigt wird.
<ilink>http://www.allocine.fr/ Allocine</ilink>
Das sieht dann so aus:
- <ilink>http://www.allocine.fr/ Allocine</ilink>
Weblinks
- <ilink>http://www.mediawiki.org/wiki/Extension:FaviconLink Extension:FaviconLink</ilink> (Mediawiki.org)