Open main menu

Extension:Itemstats

MediaWiki extensions manual
OOjs UI icon advanced.svg
Itemstats
Release status: stable
Implementation Tag
Description This extension adds the possibility to use World of Warcraft ItemStats [1] "item" and "itemico" tags in articles.
Author(s) Patrick Atoon
Latest version 1.0
MediaWiki 1.7
License No license specified
Download See below
Translate the Itemstats extension if it is available at translatewiki.net
Check usage and version matrix.

Contents

What can this extension do?Edit

Itemstats is a library that adds World of Warcraft item linking capabilities to a website. Itemstats is freely available from http://itemstats.free.fr and comes with standard integration options for several forum applications. Be sure to also check http://www.wowtooltips.com/ when Itemstats fails to work out of the box.

This extension allows Itemstats to integrate with MediaWiki. It adds two tags to the parser: "item" and "itemico".

UsageEdit

Below is some example usage of the tags:

<item>Light-Collar of the Incarnate</item>

This will display a colored link that will display a detail info popup on mouseover. The detail information will be retrieved from a central database by Itemstats.

<itemico>Light-Collar of the Incarnate</itemico>

This will display the icon for the indicated item that will display a detail info popup on mouseover. The detail information will be retrieved from a central database by Itemstats.


Download instructionsEdit

Please copy and paste the code found below and place it in $IP/extension/itemstats/mediawiki_itemstats.php. Unpack the Itemstats package in the same directory. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

InstallationEdit

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

#add configuration parameters here
#setup user rights here
require_once("$IP/extensions/itemstats/mediawiki_itemstats.php");

CodeEdit

<?php
/**
 * mediawiki_itemstats.php
 *
 * Extension for MediaWiki to understand the <item> and <itemico> tags
 * for embedding links to World of Warcraft items.
 * The latest version of this MediaWiki extension can be retrieved from
 * http://www.mediawiki.org/wiki/Extension:Itemstats
 *
 * Based on the code for Itemstats: http://itemstats.free.fr/
 *
 * @author Patrick Atoon <patricka@two4u.com>
 * @addtogroup Extensions
 * @copyright (c) 2007 Patrick Atoon
 * @licence GNU General Public Licence 2.0 or later
 *
 *
 * INSTALLING
 *
 *  - Download the itemstats 1.5.5.1 version from http://itemstats.free.fr/
 *  - Unpack the file to the MediaWiki "extensions/itemstats/" directory.
 *  - Move this file ("mediawiki_itemstats.php") to the "extensions/itemstats" directory.
 *  - Download an iconpack from http://wow.allakhazam.com/db/guides.html?guide=502
 *  - Unpack the iconpack to the directory "extensions/itemstats/images/".
 *  - Edit "config.php" and modify the ICON_STORE_LOCATION to:
 *
 *       define('ICON_STORE_LOCATION', $wgScriptPath . '/extensions/itemstats/images/');
 *
 *  - Make sure you have a MySQL database set up for item caching; Itemstats
 *    will need a username and a password that allows it to create a table.
 *    This can also be done manually with:
 *
 *       CREATE TABLE IF NOT EXISTS `item_cache`
 *       (`item_name` varchar(100) NOT NULL DEFAULT '',
 *       `item_id` varchar(100) DEFAULT '0',
 *       `item_lang` varchar(2) DEFAULT '',
 *       `item_link` varchar(100) DEFAULT NULL,
 *       `item_color` varchar(20) NOT NULL DEFAULT '',
 *       `item_icon` varchar(50) NOT NULL DEFAULT '',
 *       `item_html` text NOT NULL,
 *       UNIQUE KEY `item_name` (`item_name`),
 *       FULLTEXT KEY `item_html` (`item_html`))
 *
 *  - Add the following line to MediaWiki's "LocalSettings.php" file:
 *
 *       require_once("$IP/extensions/itemstats/mediawiki_itemstats.php");
 *
 * And now you should be set to go!
 *
 * KNOWN BUGS:
 *  - On mouseover, a patch of white appears under the popup icon.
 *  - Itemstats can use an icon_lsize parameter passed to the getItemForDisplay
 *    function. Right now the parameter is ignored and the default value for
 *    the icon size will always be used.
 */

// Get out if not part of MediaWiki
if(!defined('MEDIAWIKI')) {
        echo("This file is part of an extension to the MediaWiki software and cannot be used standalone.\n");
        die(true);
}

include_once(dirname(__FILE__) . '/itemstats.php');

// Make this extension visible in Special:Version
$wgExtensionCredits['parserhook'][] = array(
    'name' => 'Itemstats',
    'author' => 'Patrick Atoon',
    'url' => 'http://www.mediawiki.org/wiki/Extension:Itemstats',
    'description' => 'This extension adds the possibility to use World of Warcraft ItemStats (http://itemstats.free.fr) "item" and "itemico" tags in articles.'
    );

// Add extra HTML for javascript and style calls to make the Itemstats extension work
$wgHooks['BeforePageDisplay'][] = 'wowItemstatsExtraHtml';

function wowItemstatsExtraHtml($out) {
    global $wgScriptPath;

    $out->addStyle("../extensions/itemstats/templates/itemstats.css");
    $out->addScript("<script type=\"text/javascript\" src=\"$wgScriptPath/extensions/itemstats/overlib/overlib.js\"><!-- overLIB (c) Erik Bosrup --></script>");

    return true;
}


// Add "item" and "itemico" tags to the parser
$wgExtensionFunctions[] = 'wowItemstatsSetup';

function wowItemstatsSetup() {
    global $wgParser;

    $wgParser->setHook('item', 'wowItemstatsItemTagRender');
    $wgParser->setHook('itemico', 'wowItemstatsItemicoTagRender');
}


/**
 * Hook function called from MediaWiki. Renders a tag like e.g.:
 *
 *     <item>Light-Collar of the Incarnate</item>
 *
 * This will display a colored link that will display a detail info
 * popup on mouseover. The detail information will be retrieved from
 * a central database by Itemstats.
 *
 * @param input Text that was entered between the tags.
 * @param args Array of attributes and their value. Not used.
 * @param parser MediaWiki parser object for special function calls. Not used.
 * @return The HTML for the colored link plus info.
 */
function wowItemstatsItemTagRender( $input, $args, $parser ) {
    $item_stats = new ItemStats();

    if ( $item_stats->connected == false ) {
        return htmlspecialchars( $input );
    }

    $item_html = $item_stats->getItemForDisplay( $input, 'item', 0, true );

    if ( defined( path_itemstats ) ) {
        $item_html = str_replace( "{PATH_ITEMSTATS}", path_itemstats, $item_html );
    } else {
        $item_html = str_replace( "{PATH_ITEMSTATS}", "./itemstats", $item_html );
    }

    return $item_html;
}


/**
 * Hook function called from MediaWiki. Renders a tag like e.g.:
 *
 *     <itemico>Light-Collar of the Incarnate</itemico>
 *
 * This will display the icon for the indicated item that will display
 * a detail info popup on mouseover. The detail information will be retrieved
 * from a central database by Itemstats.
 *
 * @param input Text that was entered between the tags.
 * @param args Array of attributes and their value. Not used.
 * @param parser MediaWiki parser object for special function calls. Not used.
 * @return The HTML for the icon plus info.
 */
function wowItemstatsItemIcoTagRender( $input, $args, $parser ) {
    $item_stats = new ItemStats();

    if ( $item_stats->connected == false ) {
        return htmlspecialchars( $input );
    }

    $item_html = $item_stats->getItemForDisplay( $input, 'itemico', 0, true );

    if ( defined( path_itemstats ) ) {
        $item_html = str_replace( "{PATH_ITEMSTATS}", path_itemstats, $item_html );
    } else {
        $item_html = str_replace( "{PATH_ITEMSTATS}", "./itemstats", $item_html );
    }

    return $item_html;
}

?>

See alsoEdit