Extension:AmazonPartnerLink

From MediaWiki.org

Jump to: navigation, search

         

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
AmazonPartnerLink

Release status: beta

Implementation  Tag
Description This extension will allow you to put Amazon Book Links in your MediaWiki.
Author(s)  Roman Lehnert
Last Version  0.1
MediaWiki  1.6+
License No license specified
Download no link

check usage (experimental)


Contents

[edit] What can this extension do for you?

It provides mediawiki with the possibility to create Amazon-Partnernet-Links for you.


[edit] Usage

  • <amazon>978-3817118076</amazon> or <amazon>3817118074</amazon>

Both of them will give a direct link to the book at amazon. Like ISBN: 3817118074. No Matter if the ISBN-Number is given as ISBN-10, ISBN-13 or contains "-".


  • <amazon>3817118074 Regelungstechnik</amazon>

Will also create a direct link to the book at amazon. But here not only the ISBN, but also a description of the book is used as Linktext: Regelungstechnik


  • <amazon>Halliday Physik</amazon>

In case that you don't know the isbn of the book and are to lazy to look for it, you can simply put the name as Parameter. The amazon-link will point to the search-result for your given Name. In our example: Halliday Physik


[edit] Installation

  • Just put the following: file into your extension-directory:

[edit] AmazonPartnerLink.php

<?php
 
$wgExtensionFunctions[] = "AmazonBookLink";
 
function AmazonBookLink() {
    global $wgParser;
    $wgParser->setHook( "amazon", "renderAmazonLink" );
}
 
function renderAmazonLink( $input ) {
    #
    #  INSERT YOUR PARTNER-ID HERE:
    #
    $partner = "";
 
    # Split at the 1st Word
    $src = explode(' ', $input, 2);
 
    # strip "-" from the maybe-isbn
	$tmpisbn = ereg_replace("-","",$src[0]);
 
    #check if its an isbn
	if(is_numeric(substr($tmpisbn,0,7))) {
 
        # Transform ISBN-13 to ISBN-10 by stripping down to 9 digits + chksum
		if(strlen($tmpisbn) == 13) {
			$chksm =				($tmpisbn[3] * 1
								+ $tmpisbn[4] * 2
								+ $tmpisbn[5] * 3
								+ $tmpisbn[6] * 4
								+ $tmpisbn[7] * 5
								+ $tmpisbn[8] * 6
								+ $tmpisbn[9] * 7
								+ $tmpisbn[10] * 8
								+ $tmpisbn[11] * 9
								)%11;
			if($chksm == 10){
				$chksm = "X";
			}
			$tmpisbn = substr($tmpisbn,3,9) . $chksm;
 
 
		}
 
        # If the 1st Word was an ISBN and there was no title set
		if($src[1] != "") {
			$output = "<a href='http://www.amazon.de/gp/product/$tmpisbn?ie=UTF8&tag=$partner&linkCode=as2&camp=1638&creative=6742&creativeASIN=$tmpisbn'>$src[1]</a>";
		} 
        # If the 1st Word was an ISBN and there was a title set
        else {
			$output = "<a href='http://www.amazon.de/gp/product/$tmpisbn?ie=UTF8&tag=$partner&linkCode=as2&camp=1638&creative=6742&creativeASIN=$tmpisbn'>ISBN: $src[0]</a>";
		}
	} 
 
    # If the 1st Word was not an ISBN, we use a Searchlink
    else {
		$output = "<a href='http://www.amazon.de/gp/search?ie=UTF8&keywords=$input&tag=$partner&index=blended&linkCode=ur2&camp=1638&creative=6742'>$input</a>";
	}
 
    return "$output";
}
?>
  • Then insert your Amazon-PartnerID where its marked in the Code.
  • The code is for the German Amazon site. However, by changing the links in the output parameter this extension may be modified for US or other Amazon sites.
  • Finally edit your LocalSettings.php and add this line at the Bottom:
 require_once("extensions/AmazonPartnerLink.php");

That's it.

[edit] Example

On this Page of tubs-wiki.de you can see the different Links in the Last Chapter.