Extension:MagnetLinks

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
MagnetLinks

Release status: beta

Implementation Tag
Description Allows creation of links to magnet URI
Author(s) Jmkim dot com
Latest version 0.1 (2012-02-05)
MediaWiki 1.16 or above
License GNU General Public License
Download http://jmnote.com/mw/MagnetLinks.tgz
Example http://jmnote.com/wiki/MagnetLinks

Translate the MagnetLinks extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

Description[edit | edit source]

This extension renders links to magnet URI.

Examples[edit | edit source]

The following examples should show how you can use this extension.

<magnet>magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C</magnet>
<magnet>magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C Magnet Link</magnet>

Source code[edit | edit source]

Add the following to your LocalSettings.php:

require_once("$IP/extensions/MagnetLinks/MagnetLinks.php");

Add the following source code to the extensions/MagnetLinks/MagnetLinks.php directory

<?php
/**
 * This file contains the main include file for the MagnetLinks extension of 
 * MediaWiki. This code is released under the GNU General Public License.
 *
 * @author Jmkim dot com <banking@nate.com>
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @package MediaWikiExtensions
 * @version 0.1
 */
 
$wgExtensionFunctions[] = 'MagnetLinksExtension';
 
function MagnetLinksExtension() {
	global $wgParser;
	$wgParser->setHook('magnet', 'render_MagnetLink');
}
 
function render_MagnetLink($input, $argv) {
	$pos = strpos($input, ' ');
	if($pos === false) {
		$uri = htmlentities(trim($input));
		$linktext = $uri;
	} else {
		$uri = htmlentities(trim(substr($input, 0, $pos)));
		$linktext = htmlentities(trim(substr($input, $pos)), ENT_COMPAT, 'UTF-8');
	}
	$icon_img = 'http://upload.wikimedia.org/wikipedia/commons/c/c2/Magnet-icon.gif';
	$link_color = '#0088a4';
	return "<img src=\"$icon_img\"/> <a style=\"color:$link_color\" href=\"$uri\">$linktext</a>";
}
 
$wgExtensionCredits['parserhook'][] = array(
	'name' => 'MagnetLinks',
	'author' => 'Jmkim dot com',
	'description' => 'render links to magnet URI between &lt;magnet&gt; and &lt;/magnet&gt;',
	'url' => 'http://www.mediawiki.org/wiki/Extension:MagnetLinks',
	'version' => '0.1.0');
?>

Known Issues[edit | edit source]

This extension may interfere with the work of expansion MathJax used to display mathematical formulas using JavaScript

See also[edit | edit source]


Language: English  • русский