Extension:DataInvoker

DataInvoker is an extension that introduces a new parser function,, which allows retrieving data from a local database.

Installation
Please cut and paste the code found below and place it in. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

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

Configuration parameters
Note: These parameters should be put in LocalSettings.php, and must be put after the code shown in the section!

There are currently 4 configuration parameters for this extension. They are:
 * $wgDataInvokerHostName - String that indicates the host name of the database connection. Default value is.
 * $wgDataInvokerUserName - String that specifies the username of the database connection. Default value is.
 * $wgDataInvokerPassword - String that specifies the password of the database connection. Default value is.
 * $wgDataInvokerDatabase - String that specifies the name of the database being connected to. Default value is.

Reference
DataInvoker currently introduces 1 new parser function allowing data retrieving.

Usage
Other than the first parameter (table_name), all parameters are optional.
 * table_name
 * The name(s) of the table to retrieve data from. If there are multiple tables, use commas to separate them - although retrieving data from multiple tables isn't fully tested yet and might not work.


 * column_name
 * The name(s) of the columns from which the fields are wanted in the result output. If there are multiple columns, use commas to separate them. If all columns of a table is wanted, use an asterisk (*). Default value is *.


 * match_column and match_value
 * Indicates that the match_column column of the retrieved result rows must be match_value. If omitted (or empty), no matching pattern is required for the retrieved rows.


 * order_by
 * Sorts the retrieved rows by the order_by column(s). If there are multiple columns to sort by, use commas to separate them - although sorting by multiple rows isn't fully tested yet and might not work. If omitted (or empty), no sorting is done to the retrieved rows.


 * order
 * Specifies the way the rows are ordered by order_by. Possible values are ASC (in ascending order), or DESC (in descending order). Default value is ASC.


 * join_char
 * If column_name is * or multiple columns, the output will be the values of all fields in the fetched row, listed one by one, separated by join_char</tt>. Default value is |</tt> (pipe character). This might allow some convenient interactions with templates.


 * row_number
 * When multiple rows are retrieved and they all match the matching pattern defined by match_column</tt> and match_value</tt> (if any), only the row_number</tt>th row will be output. Default value is 1</tt>. Must be a positive integer.

Example
Assume there is a table named "grocery_list", with the following rows and columns: Then the following wikitext will generate the corresponding result:

Limitations
This extension is still in experimental phase so its functions are pretty incomplete. Currently, it only allows one bonus database connection for a whole MediaWiki installation, and does not support custom SQL queries for security reasons. Also, the match pattern for the WHERE substatement is one equation at most, ie. it does not support logical operators (like AND, OR), comparative operators (like <, >) and the LIKE operator. Overcoming of these limitations is being planned and if you would like to help, please state it in the talk page.

Acknowledgments
Thanks go to those guys at the #mediawiki IRC channel who helped me with this. They include MinuteElectron, Werdna, Duesentrieb, and Dantman. Thanks again!

Under Development
This extension is still under development; it might be unstable since it hasn't undergone strict testing, and it is still too simple at the current stage. It lacks more functionality and I'm aware of the situation; you are welcome to give suggestions in the talk page.

Trivia
Invoker is a hero in the game DotA Allstars, who has the game's most unique skillset and requires a lot of skills to play.