Extension:AmazonPlus

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

Release status: beta

Implementation Tag
Description A highly customizable extension to display Amazon information
Author(s) Ryan Schmidt (Skizzerztalk)
Latest version 0.5.2
MediaWiki 1.12+
License GNU General Public License
Download
Example WhatLeadership
Parameters

$wgAmazonPlusAWS
$wgAmazonPlusSecretKey
$wgAmazonPlusAssociates
$wgAmazonPlusDefaultSearch
$wgAmazonPlusDecimal

Hooks used
BeforePageDisplay

ParserFirstCallInit

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

Check usage and version matrix; code metrics

The AmazonPlus extension allows one to display data from the Amazon XML feed onto their pages. While it is a tag extension, it fully supports template parameters (e.g. {{{1}}}) and other wiki markup, the former being parsed before the query is executed and the latter after custom parameter substitution is completed.

Custom parameters (in the %parameter% format) are substituted with appropriate data from the XML feed. The currently available list of these parameters is relatively small and is geared mainly towards getting information for books. In future versions, more media will be supported.

Caveats[edit | edit source]

  • The definition of $wgAllowExternalImages is temporarily overridden and set to true so that the hotlinked images from Amazon display. It is set back to its original value after the tag finishes parsing
  • If the SpamBlacklist extension is installed, you must add the following to your MediaWiki:Spam-whitelist page so that the amazon urls work:
amazon\.(com|co\.uk|ca|jp|fr|de)

Usage[edit | edit source]

This extension is invoked using the <amazon> tag, like so:

<amazon (passed parameters)>
(wiki markup with custom parameters)
</amazon>

Passed parameters[edit | edit source]

These parameters are passed into the tag itself, such as <amazon name="value">.

Parameter name Parameter Value Default What it does
locale us, gb, fr, de, ca, or jp us Sets the locale for the query. You must have an Associates ID for the locale in question (via $wgAmazonPlusAssociates).
id the ASIN for the item (derived from keywords) Tells Amazon what item to get information for
keywords Name of the item (the page's name) If "id" is not set, this will be used to query Amazon to figure out the ASIN.
search Type of search $wgAmazonPlusDefaultSearch If "id" is not set, this will be used to tell Amazon what types of objects to retrieve from its search

Custom parameters[edit | edit source]

These parameters may be placed anywhere between the opening and closing amazon tags. They will be replaced with the appropriate data from the query according to the chart below. Please note that all images are hotlinked from Amazon.

Parameter name Parameter value
Images
%largeimage% A large image of the item
%mediumimage% A medium-sized image of the item
%smallimage% A small image of the item
%tinyimage% A very small image of the item
%swatchimage% A swatch image of the item
%thumbnail% A thumbnail of the item
Reviews and Ratings
%editorialreview% The editorial review of the item. Please note that due to a recent Amazon policy change, some editorial reviews are excluded from the Amazon result set due to copyrights.
%shortreview% A shortened version of %editorialreview% with a [more] link to display the rest of it (uses javascript)
%reviewlink% The URL to the listing of customer reviews
%source% The source of the editorial review
%rating% The rating of the item in numerical form
%stars% The rating of the item using a stars image
%totalreviews% The total amount of reviews
Prices
%price% The price in the current locale of the first available type (amazon, new, or used)
%price-amazon% Amazon's price in the current locale
%price-new% The lowest new price in the current locale
%price-used% The lowest used price in the current locale
%price-us% The price in the us locale of the first available type
%price-gb% The price in the gb locale of the first available type
%price-ca% The price in the ca locale of the first available type
%price-de% The price in the de locale of the first available type
%price-jp% The price in the jp locale of the first available type
%price-fr% The price in the fr locale of the first available type
%price-us-amazon% Amazon's price in the us locale
%price-gb-amazon% Amazon's price in the gb locale
%price-ca-amazon% Amazon's price in the ca locale
%price-de-amazon% Amazon's price in the de locale
%price-jp-amazon% Amazon's price in the jp locale
%price-fr-amazon% Amazon's price in the fr locale
%price-us-new% The lowest new price in the us locale
%price-gb-new% The lowest new price in the gb locale
%price-ca-new% The lowest new price in the ca locale
%price-de-new% The lowest new price in the de locale
%price-jp-new% The lowest new price in the jp locale
%price-fr-new% The lowest new price in the fr locale
%price-us-used% The lowest used price in the us locale
%price-gb-used% The lowest used price in the gb locale
%price-ca-used% The lowest used price in the ca locale
%price-de-used% The lowest used price in the de locale
%price-jp-used% The lowest used price in the jp locale
%price-fr-used% The lowest used price in the fr locale
%compare% A dropdown using AJAX to compare the prices in a single currency (currently does not work)
%offers% A link to all offers for the item
Details
%url% Detail page URL
%author% Author
%actor% Actor
%title% Title
%binding% Binding
%pages% Number of pages
%edition% Edition
%releaseyear% Year of release
%releasemonth% Month of release
%releaseday% Day of release
%publishedyear% Year of publication
%publishedmonth% Month of publication
%publishedday% Day of publication
%publisher% Publisher
%detailslink% Link to the item's technical details
Identification
%isbn% ISBN of the book
%asin% Amazon ID of the item
%ean% EAN of the item
Purchasing URLs
%buy% Alias for %url% for the current locale
%buy-us% Alias for %url% for the us locale
%buy-gb% Alias for %url% for the gb locale
%buy-ca% Alias for %url% for the ca locale
%buy-de% Alias for %url% for the de locale
%buy-jp% Alias for %url% for the jp locale
%buy-fr% Alias for %url% for the fr locale

Download instructions[edit | edit source]

Download the latest snapshot of this extension via the MediaWiki Extension Distributor. Then, extract the files to your MediaWiki's extensions directory (a new directory at extensions/AmazonPlus will be formed).

Warning: Before you download read Requirements or you might install the wrong version.

Installation[edit | edit source]

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/AmazonPlus/AmazonPlus.php");
$wgAmazonPlusAWS = 'INSERT AMAZON AWS ID HERE';
$wgAmazonPlusSecretKey = 'INSERT AMAZON SECRET KEY HERE (YOU GET THIS ALONG WITH YOUR AWS ID)';
$wgAmazonPlusAssociates = array(
  'us' => 'INSERT AMAZON ASSOCIATES ID FOR US HERE',
);

Requirements[edit | edit source]

  1. MediaWiki version 1.12 or above is required to use this extension. Remember that the current trunk version will always maintain backwards-compatibility, so never download a branched version of this extension.
  2. You will need to get an AWS Id from here
  3. You will need at the very least to get an Amazon Associates ID for the US locale from here. Edit the URL to sign up for other locales (such as changing it from .com to .ca or .co.uk to sign up for the ca and gb locales).
  4. Either the allow_url_fopen directive must be enabled in your php.ini file, or you must have the cURL extension loaded.
  5. The SimpleXML extension must be enabled in your php.ini file. It is enabled by default, so as long as php was not configured with the --disable-simplexml option, you should be fine
  6. MediaWiki should be allowed to use the set_time_limit() function. While this isn't necessary, PHP may time out if you are performing many queries.

Configuration parameters[edit | edit source]

These are the default values, along with a description:

$wgAmazonPlusAWS = ''; #Amazon AWS Id. Required
$wgAmazonPlusSecretKey = ''; #Amazon AWS Secret Key. Required
$wgAmazonPlusAssociates = array(); #Amazon Associates IDs, per locale.Example: array( 'us' => 'myamazonid', 'fr' => 'myfrenchid' ); Required
$wgAmazonPlusDefaultSearch = 'Books'; #Default search type, can be Books, DVDs, etc.
$wgAmazonPlusDecimal = '.'; #What to seperate the decimals with in currency. e.g. 15.43 or 12,72

System messages[edit | edit source]

The following system messages are defined by this extension:

Message Default value Description
amazonplus-desc A highly customizable extension to display Amazon information The description that appears in Special:Version
amazonplus-nores Error: No results found! Displayed when no results were found for the query
amazonplus-noidres Error: Could not find a product ID! Displayed when the id parameter is not passed and the extension was unable to find an ASIN via the keywords search
amazonplus-fgcerr Error: Could not retrieve data from Amazon! Displayed whenever the request fails on the Amazon query URL, perhaps because Amazon is temporarily offline
amazonplus-slserr Error: Could not parse data from Amazon! Displayed whenever simplexml_load_string() fails on the XML retrieved from Amazon, this probably will never happen
amazonplus-used used Denotes that the price is the lowest price for a used product from all offers
amazonplus-german German Denotes that the product being sold is in the German language
amazonplus-french French Denotes that the product being sold is in the French language
amazonplus-japanese Japanese Denotes that the product being sold is in the Japanese language
amazonplus-english Denotes that the product being sold is in the English language[1]
amazonplus-amazon amazon price Denotes that the price is what Amazon is offering the product for
amazonplus-new new Denotes that the price is the lowest price for a new product from all offers
amazonplus-status ($1) Displays the status messages, such as (new, french), etc. $1 is the string of status messages, separated with MediaWiki:Comma-separator.
amazonplus-none No copies of this item are up for sale. Used to alert the user that the locale in question has no copies of this item left for sale in any condition
amazonplus-currency $3$1 $2$4 Used to format the price. $1 is the price itself (e.g. 24.12 or 13,54, depending on what $wgAmazonPlusDecimal is), $2 is the currency code (e.g. USD), $3 is the currency symbol (e.g. $), and $4 is the status (see amazonplus-status)
amazonplus-cp-none None Used in the %compare% parameter
amazonplus-cp-usd USD Used in the %compare% parameter
amazonplus-cp-cad CAD Used in the %compare% parameter
amazonplus-cp-gbp GBP Used in the %compare% parameter
amazonplus-cp-eur EUR Used in the %compare% parameter
amazonplus-cp-jpy JPY Used in the %compare% parameter
amazonplus-more more Used in the %shortreview% parameter
amazonplus-less less Used in the %shortreview% parameter
  1. If left blank, nothing will be shown to denote that the product is in this state/language. This is useful if you don't want to show the default state/language

See Also[edit | edit source]