BlinkenApplet/Mediawiki Extension

How to Install
1. Download the latest version of BlinkenApplet and put it into the "extensions" directory below your wiki install path

2. Copy the PHP code below and set  to the path you saved the applet to.(*); If the Applet says "notinited" you have to arrange.

(*) example, cause can be tricky: if your Apache document_root is /var/www and you installed the wiki to /var/www/w (in order to make URLs appear as /wiki/ and hide the index.php); you need to set the path like an absolute path but from the wiki's point of view, so $appletpath="/w/extensions/BlinkenApplet0.71.jar"; would be correct even though you copied the file to /var/www/w/extensions on the shell.

3. Set  and   to the/a MySQL user and password that has access to the "wikidb" database. (yes this could be probably made better by including it from general Mediawiki config)

4. After editing save as  and also put it into "extensions" in your wiki install dir. Make sure the user who runs the webserver can at least read it.

5. Edit  in your wiki install dir and near the bottom add the line: .

6. (Optional) To use the bonus features make sure you/PHP can execute the shell commands:, , , , ,  and use PHP' crypt function.

BlinkenExtension.php
setHook( "blinken", "renderBlinkenapplet" ); }

function renderBlinkenapplet( $input, $argv ) { global $wgOutputEncoding;
 * 1) the actual extension function


 * 1) Config

$appletpath="/w/extensions/BlinkenApplet0.71.jar";
 * 1) set path to applet here

$dbuser="wikiuser"; $dbpass="";
 * 1) set a mysql user with (select) access to "wikidb" here

$dbhost="localhost"; $dbname="wikidb";
 * 1) Just in case your MySQL server is not on the same host
 * 1) Just in case you choose a different database name on Mediawiki install


 * 1) End Config

$debug=1; $version="BlinkenApplet0.71.jar";
 * 1) debug level of BlinkenApplet


 * 1) some default input for testing
 * 2) $input="BlinkenApplet by took running on S23 Wiki. It works.";

$input = mysql_real_escape_string($input);
 * 1) filter our mysql escape strings from user input, just to make sure

if (!is_string($input) || strlen($input)>255) { $input="error - no text input or text over 255 chars)"; }
 * 1) Is input a string and not too long?

case "\$fnord":
 * 1) Input SPECIALS
 * 1) fetch a random fnord from mysql (fnord database doesnt ship with Mediawiki)
 * 2) Use <blinken$fnord

$hd = mysql_connect("$dbhost", "$dbuser", "$dbpass") or die ("Unable to connect"); mysql_select_db ("$dbname", $hd) or die ("Unable to select database"); $res = mysql_query("SELECT * from fnord ORDER BY rand LIMIT 0,1", $hd) or die ("Unable to run query"); while ($row = mysql_fetch_assoc($res)) { $id = $row["id"]; $fnord = $row["text"]; } $input = $fnord; break;

case "\$quote": $hd = mysql_connect("$dbhost", "$dbuser", "$dbpass") or die ("Unable to connect"); mysql_select_db ("$dbname", $hd) or die ("Unable to select database"); $res = mysql_query("SELECT quote from quotes ORDER BY rand LIMIT 0,1", $hd) or die ("Unable to run query"); while ($row = mysql_fetch_assoc($res)) { $quote = $row["quote"]; } $input = $quote; break;
 * 1) fetch a random discordian quote from mysql (quote database doesnt ship with Mediawiki)


 * 1) This gets the current site statistics from the wiki and displays it.
 * 2) Use $wikistats

case "\$wikistats": $hd = mysql_connect("$dbhost", "$dbuser", "$dbpass") or die ("Unable to connect"); mysql_select_db ("$dbname", $hd) or die ("Unable to select database"); $res = mysql_query("SELECT * from site_stats", $hd) or die ("Unable to run query"); while ($row = mysql_fetch_assoc($res)) { $views = $row["ss_total_views"]; $edits = $row["ss_total_edits"]; $good = $row["ss_good_articles"]; $total = $row["ss_total_pages"]; $users = $row["ss_users"]; $images = $row["ss_images"]; } $input = "Wiki Site Stats: Views: $views Edits: $edits Good pages: $good Total pages: $total Users: $users Images: $images"; break;

case "\$date":
 * 1) show date
 * 2) Use $date

$input = `date -u`; break;

case "\$ddate": $input = `ddate`; break;
 * 1) show discordian date
 * 2) Use $ddate

case "\$ddate +%.": $input = `ddate +%.`; break;
 * 1) ddate easteregg
 * 2) Use ddate +%.

case "\$loadavg": $input = `top -b -n1 -s | grep load | cut -d, -f4,5,6`; break;
 * 1) show system load average
 * 2) Use $loadavg

case "\$myIP":
 * 1) show User IP (not server IP, each user sees hiw own IP)
 * 2) Use $myIP

if (getenv(HTTP_X_FORWARDED_FOR)) { $ip = getenv(HTTP_X_FORWARDED_FOR); } else { $ip = getenv(REMOTE_ADDR); } $input="Your IP is $ip"; break;

default: $input=$input; }
 * 1) normal text input

if (substr($input, 0, 6) == "crypt:") { $input=explode(":",$input); $input=$input[1]; $input=crypt($input); $input=substr($input,0, 254); }
 * 1) crypt:
 * 2) encrypt input text
 * 3) http://www.php.net/crypt
 * 4) Use crypt:sometext


 * 1) dict:
 * 2) fetch a dictionary definition
 * 3) man dict
 * 4) Use dict:fnord

if (substr($input, 0, 5) == "dict:") { $input=explode(":",$input); $input=$input[1]; $input="Dict feature currently disabled for security reasons."; $input=substr($input,0, 254); }
 * 1) $input=`dict $input | sed s/\'//g | sed s/\"//g | xargs`;
 * 2) $input=explode(":",$input);
 * 3) $input=$input[1].$input[2];
 * 4) $input=addslashes($input);


 * 1) Set Colors
 * 2) Background Color

$bgcolor=explode(",",$argv["bgcolor"]); $bgred=$bgcolor[0]; $bggreen=$bgcolor[1]; $bgblue=$bgcolor[2];

if (!is_numeric($bgred) || $bgred<0 || $bgred>255) { $bgred="255"; } if (!is_numeric($bggreen) || $bggreen<0 || $bggreen>255) { $bggreen="255"; } if (!is_numeric($bgblue) || $bgblue<0 || $bgblue>255) { $bgblue="255"; }

$bgcolor="$bgred,$bggreen,$bgblue";


 * 1) LampOn Color

$lamponcolor=explode(",",$argv["lamponcolor"]); $lamponred=$lamponcolor[0]; $lampongreen=$lamponcolor[1]; $lamponblue=$lamponcolor[2];

if (!is_numeric($lamponred) || $lamponred<0 || $lamponred>255) { $lamponred="0"; } if (!is_numeric($lampongreen) || $lampongreen<0 || $lampongreen>255) { $lampongreen="255"; } if (!is_numeric($lamponblue) || $lamponblue<0 || $lamponblue>255) { $lamponblue="0"; }

$lamponcolor="$lamponred,$lampongreen,$lamponblue";


 * 1) LampOff Color

$lampoffcolor=explode(",",$argv["lampoffcolor"]); $lampoffred=$lampoffcolor[0]; $lampoffgreen=$lampoffcolor[1]; $lampoffblue=$lampoffcolor[2];

if (!is_numeric($lampoffred) || $lampoffred<0 || $lampoffred>255) { $lampoffred="0"; } if (!is_numeric($lampoffgreen) || $lampoffgreen<0 || $lampoffgreen>255) { $lampoffgreen="0"; } if (!is_numeric($lampoffblue) || $lampoffblue<0 || $lampoffblue>255) { $lampoffblue="0"; }

$lampoffcolor="$lampoffred,$lampoffgreen,$lampoffblue";

switch ($argv["font"]) { case "5pxStd": $font="5pxStd"; break; case "8pxStd": $font="8pxStd"; break; case "MorseCode": $font="MorseCode"; break; default: $font="5pxStd"; }
 * 1) Set Font
 * 2) Set Font

if ($argv["loop"]=="Off" || $argv["loop"]=="off" ) { $loop="off"; } else { $loop="on"; }
 * 1) Set Loop

if (is_numeric($argv["width"]) && $argv["width"]>=0 && $argv["width"] <=800) { $width=$argv["width"]; } else { $width=200; }
 * 1) Set Width

if (is_numeric($argv["height"]) && $argv["height"]>=0 && $argv["height"] <=800) { $height=$argv["height"]; } else { $height=200; }
 * 1) Set Height

if (is_numeric($argv["delay"]) && $argv["delay"]>=0 && $argv["delay"] <=100) { $delay=$argv["delay"]; } else { $delay=1; }
 * 1) Set Delay


 * 1) Build Html Output

$output= <<           END; return $output; } ?>
 * 1) Send it