Mediawiki/Erweiterung/IconLink: Unterschied zwischen den Versionen

Aus Mikiwiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 3: Zeile 3:
== Installation ==
== Installation ==


1. Anlegen der Datei "extensions/FaviconLink.php" und Einfügen des folgenden PHP-Codes: FaviconLink 0.1 ().
1. Anlegen des Verzeichnisses "extensions/IconLink".


  # <b>vi extensions/FaviconLink.php</b>
# <b>mkdir extensions/IconLink</b>
# <b>chown wiki:wiki extensions/IconLink</b>
 
2. Anlegen der Datei "extensions/FaviconLink.php" und Einfügen des folgenden PHP-Codes: IconLink 0.1 (2008-03-11).
 
  # <b>vi extensions/IconLink/IconLink.php</b>
 
{| class=wiki width=100%
|
<source lang=php enclose=div>
<?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&auml;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;
}
?>
</source>
|}
 
3. Anlegen der Datei "extensions/FaviconLink.php" und Einfügen des folgenden PHP-Codes: IconLink 0.1 (2008-03-11).
 
# <b>vi extensions/IconLink/IconLink.code.php</b>


{| class=wiki width=100%
{| class=wiki width=100%
|
|
<source lang=php enclose=div>
<source lang=php enclose=div>
<?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);
}


</source>
</source>
|}
|}


2. Anpassung der Rechte.
4. Anpassung der Rechte.


  # <b>chown wiki:wiki extensions/FaviconLink.php</b>
  # <b>chown wiki:wiki extensions/IconLink/IconLink.php</b>
# <b>chown wiki:wiki extensions/IconLink/IconLink.code.php</b>


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


  ## Extension: IconLink
  ## Extension: IconLink
Zeile 33: Zeile 131:
{{#iconlink: url | description | icon | width | height}}
{{#iconlink: url | description | icon | width | height}}
</pre>
</pre>
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:
Das sieht dann so aus:

Version vom 1. März 2009, 14:23 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&auml;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:

Weblinks