| Amazon Widget|
Release status: beta
|Description||Insert Amazon Associates advertising widget in wiki page|
|Download|| Project page|
|Check usage and version matrix; Widget code metrics|
What can this extension do?[edit | edit source]Amazon Widget is a MediaWiki tag extension that allows the insertion of an Amazon Associates advertising "widget" into a wiki page. Your Amazon Associate ID is specified through a global variable you must initialize in your "LocalSettings.php", and the long hexadecimal string that uniquely identifies each Amazon ad unit is supplied to the tag through an attribute. Amazon Widget supplies the rest of the boiler-plate for the Amazon ad, and wraps it in a
This extension is not suitable for creating Amazon "Omakase" widgets (see http://github.com/gleneivey/AmazonOmakaseWidget for that), and has so far been tested only with "My Favorites"-type widgets.
Amazon Widget is licensed under the GNU AGPLv3.
Usage[edit | edit source]
An ad block is included in a wiki page by placing the "<amazonwidget>" tag in your wikitext. For example:
<amazonwidget adcode="01234567-89ab-cdef-0123-456789abcdef" />
The "adcode" attribute allows you to supply the ID number for the specific ad to be requested from Amazon. You can find this in the URLs that Amazon includes when you view the HTML code that would be inserted in a normal web page to cause the ad to display. The "adcode" value is checked to make sure it is valid (composed only of hexadecimal digits and hyphens), and if it is not, Amazon Widget produces an HTML comment with an error message (search for "AmazonWidget" in the returned page source).
Amazon Widget places the HTML for the ad itself inside of a <div> tag. It places the following attributes in this tag:
- This attribute sets the class of all div's produced by Amazon Widget the same so that you can apply CSS styling to all of them as a set.
- In addition to being included in the HTML for the ad itself, Amazon Widget places the value from the "adcode" attribute in the wikitext of the page in the ad div's "id". This could be used to apply CSS styling to an individual ad.
- style="float: right"
- By default, Amazon Widget creates div's that are "floated" right, so that they're shown flush against the right edge of the content area of the page, and the rest of the page's content flows around them. To control how this attribute is created in the output HTML, include a 'float="<value>"' attribute in the <amazonwidget> tag in your wiki page's source, like:
<amazonwidget adcode="01234567-89ab-cdef-0123-456789abcdef" float="left" />
This example will generate output HTML with 'style="float: left"', causing the ad to be positioned between the "portal" column (normally at the far left edge of a wiki page) and the rest of the page's text/etc. The acceptable values for the "float" attribute are "left", "right", and "none". An unacceptable value will produce the default of "right".
Download instructions[edit | edit source]
The public repository for AmazonWidget is on GitHub at http://github.com/gleneivey/AmazonWidget
Installation[edit | edit source]To install this extension, add the following to LocalSettings.php:
$wg_AMZWID_associateId = "<your associate tracking-id>"; require_once( "$IP/extensions/AmazonWidget/AmazonWidget.php" );
The global variable for your associate ID (shown above) is required. There are additional optional configuration globals supported, see below. The associate ID must be supplied on LocalSettings.php for security reasons, preventing anyone with "just" page-editing privileges from modifying the beneficiary of advertising on the wiki.
Configuration parameters[edit | edit source]
In addition to the mandatory $wg_AMZWID_associateId, Amazon Widget supports two additional variables that can be set in LocalSettings.php. These are intended to accomodate variations in the format of the amazon.com URL. If the URLs that Amazon provides for your ads match the default URL patterns in Amazon Widget, you will have no need for most of these parameters.
- The HTML code Amazon provides for ad widgets includes the ad URL twice: once as the "src" of a <script> tag, and once as the "href" of an <a>. The URL template described above completely controls the URL used for the script-tag src. The value of this variable, which defaults to:(which matches Amazon's current value) is appended to the URL used for src in order to produce the one used as the "href" of the <noscript> tag.
- If this global variable is defined and the div containing an Amazon Widget is floated, then Amazon Widget will add a margin specification to the div's "style=" attribute. For example, within "LocalSettings.php", the Amazon Widget tag
$wg_AMZWID_margin = "2em";will produce a div tag in the generated HTML that looks like
<amazonwidget adcode="..." float="left" />Note that the margin is always added to the opposite side from the float, so that the specified blank area is left between the text of the page and the edge of the ad. The value of $wg_AMZWID_margin is copied directly into the output HTML and not error checked in any way.
<div id="..." class="AmazonWidget" style="float: left; margin-right: 2em">