User:Mutante/Fnord

From Meta, a Wikimedia project coordination wiki
Jump to: navigation, search
Blue Glass Arrow.svg MediaWiki logo.png
This page should be moved to MediaWiki.org.
Please do not move the page by hand. It will be imported by a MediaWiki.org administrator with the full edit history. In the meantime, you may continue to edit the page as normal.

An extension for discordians. Use <fnord></fnord> to produce random fnord definitions. You need to create your personal fnord table before ,like here.

CREATE TABLE `fnord` (
  `id` int(11) NOT NULL auto_increment,
  `text` varchar(255) default NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

read the lines from this fnord file or be creative and create your own, fill the mysql table with them.(Using UltraEdit Macros i added insert into fnord.fnord (text) values (" to the start and "); to the end of every line). then import via mysql client.


<?php
#  Fnord Mediawiki extension
# display random fnord definitions in wiki pages using a <fnord> tag
# inside a {{Template:Fnord}}
# input can be used for LIMITing the mysql random select (later)
# by mutante 17.04.2005

$wgExtensionFunctions[] = "wfFnordExtension";

function wfFnordExtension() {
global $wgParser;
$wgParser->setHook( "fnord", "renderFnord" );
}

function renderFnord( $input ) {

$input = mysql_escape_string($input);

# check if input is integer else set to 1
if (is_int($input)){
$limit = $input;
} else {
$limit = 1;
}

$hd = mysql_connect("localhost", "wikiuser", "PASSWORD") or die ("Unable to connect");
mysql_select_db ("wikidb", $hd) or die ("Unable to select database");
$res = mysql_query("SELECT * from fnord ORDER BY rand() LIMIT 0,$limit", $hd) or die ("Unable to run query");
while ($row = mysql_fetch_assoc($res))
{
$id = $row["id"];
$fnord = $row["text"];
}
$output = " $fnord ((K)fnord_id #$id))";

return $output;

}

?>

put this into /var/www/wiki/extensions/ as FnordExtension.php