Extension:SQL2Wiki/old

What can this extension do?
This extension can add some dynamic content to your wiki as a table. The content is taken from a MySQL-Database. Just put your SQL-Statement into the -tags and the output will be rendered as a table. This can be quite useful in some cases.

Usage

 * Show the latest 10 Tickets from your Ticket-System

SELECT * from Tickets WHERE Tickets.Owner='Someone' DESC limit 10;


 * Show all traps from your SNMP alarm-database

SELECT * from traps;

Installation
Easy: Copy SQL2Wiki.php to your extension folder.

Caching could be a problem - be sure to disable caching for this extension.

$wgEnableParserCache = false; in LocalSettings.php

Parameters
For example, you have a MySQL-Database named "rt3" which is used as a backend for your ticketsystem ("Request Tracker" in our case). Parameters define, which database should be used. Handlers will be definend in SQL2Wiki.php like this:

$aDB_handles = array( "rt3"  => "localhost;rt3_user;rt3_password",                       "trap"  => "nagios;nagios_user;nagios_pass");
 * 1) Hostname;Username;Password

'''Consider security ! These users must only have select permissions on the tables !'''

GRANT ALL ON yourDB.* to 'wikisqlext'@'wikihost' GRANT SELECT ON yourDB.* to 'wikisqlext'@'wikihost'
 * Don't do
 * Instead do

Changes to LocalSettings.php
include("extensions/SQL2Wiki.php" ); $wgEnableParserCache = false;

Code
This code is far away from perfection - it works for me. Feel free to send updates or patches to "patrick dot mueller at itc dot fh-wiesbaden dot de".

";

# Tidying mysql_free_result($result); mysql_close($link);

return $output; } ?>

Appearance of the display
To achieve a table display of your flavour change the creation of table header to   # Create Table Header $output .= "

Interwiki Links
If your table contains code like this:

extensions

it will be interpreted as a link, e.g. extensions

Change: while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { $output .= " "; foreach ($line as $col_value){ $output .= " $col_value "; }  $output .= " "; }
 * 1) Create Table Data Rows

to: while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { $output .= " "; foreach ($line as $col_value){ # Keep interwiki links, e.g. your_article if (preg_match("/(.*)\[\[(.*)\]\](.*)/i", $col_value, $article)) { $col_value = $article[1]. '' . $article[2]. ''. $article[3]; }    $output .= " $col_value "; }  $output .= " "; }
 * 1) Create Table Data Rows

Edit  to fit your needs !

Changelog
0.1 - Initial release - 05.03.07 0.2 - Added support for stylesheets (thanks to "unknown user") 0.3 - Support for Interwiki links - 05.07.07