Content added Content deleted
imported>mutante mNo edit summary |
imported>mutante mNo edit summary |
||
Line 1: | Line 1: | ||
=== [[Mediawiki]] Extension to display [[BlinkenApplet]]s === |
|||
fnord |
|||
<pre> |
|||
<?php |
|||
# BlinkenApplet Mediawiki Extension |
|||
# An extension to display Blinkenlights scrolltexts on Mediawiki pages. |
|||
# by mutante for took (author of BlinkenApplet) |
|||
# http://s23.org/wiki/BlinkenApplet |
|||
# http://blinkenapplet.sf.net/ |
|||
# S23 - 2006/06/15 |
|||
$wgExtensionFunctions[] = "wfBlinkenExtension"; |
|||
# extension hook callback function from mediawiki |
|||
function wfBlinkenExtension() { |
|||
global $wgParser; |
|||
$wgParser->setHook( "blinken", "renderBlinkenapplet" ); |
|||
} |
|||
# the actual extension function |
|||
function renderBlinkenapplet( $input, $argv ) { |
|||
global $wgOutputEncoding; |
|||
# Config |
|||
# set path to applet here |
|||
$appletpath="/w/extensions/BlinkenApplet0.71.jar"; |
|||
# set a mysql user with (select) access to "wikidb" here |
|||
$dbuser="wikiuser"; |
|||
$dbpass=""; |
|||
# Just in case your MySQL server is not on the same host |
|||
$dbhost="localhost"; |
|||
# Just in case you choose a different database name on Mediawiki install |
|||
$dbname="wikidb"; |
|||
# End Config |
|||
# debug level of BlinkenApplet |
|||
$debug=1; |
|||
$version="BlinkenApplet0.71.jar"; |
|||
# some default input for testing |
|||
# $input="BlinkenApplet by took running on S23 Wiki. It works."; |
|||
# filter our mysql escape strings from user input, just to make sure |
|||
# $input = mysql_escape_string($input); |
|||
# If not too long, set Input Text |
|||
if (!is_string($input) || strlen($input)>255) { |
|||
$input="no input text or input input text > 255 chars"; |
|||
} |
|||
# Input SPECIALS |
|||
case "\$fnord": |
|||
# fetch a random fnord from mysql (fnord database doesnt ship with Mediawiki) |
|||
$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 "\$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": |
|||
# show date |
|||
$input = `date -u`; |
|||
break; |
|||
case "\$ddate": |
|||
# show discordian date |
|||
$input = `ddate`; |
|||
break; |
|||
case "\$ddate +%.": |
|||
# ddate easteregg |
|||
$input = `ddate +%.`; |
|||
break; |
|||
case "\$loadavg": |
|||
# show load average |
|||
$input = `top -b -n1 -s | grep load | cut -d, -f4,5,6`; |
|||
break; |
|||
case "\$myIP": |
|||
# show User IP |
|||
if (getenv(HTTP_X_FORWARDED_FOR)) { |
|||
$ip = getenv(HTTP_X_FORWARDED_FOR); |
|||
} else { |
|||
$ip = getenv(REMOTE_ADDR); |
|||
} |
|||
$input="Your IP is $ip"; |
|||
break; |
|||
default: |
|||
# normal text input |
|||
$input=$input; |
|||
} |
|||
# crypt:<text> |
|||
# encrypt input text |
|||
# http://www.php.net/crypt |
|||
if (substr($input, 0, 6) == "crypt:") { |
|||
$input=explode(":",$input); |
|||
$input=$input[1]; |
|||
$input=crypt($input); |
|||
$input=substr($input,0, 254); |
|||
} |
|||
# dict:<dict> |
|||
# fetch a dictionary definition |
|||
# man dict |
|||
if (substr($input, 0, 5) == "dict:") { |
|||
$input=explode(":",$input); |
|||
$input=$input[1]; |
|||
# $input=`dict $input | sed s/\'//g | sed s/\"//g | xargs`; |
|||
# $input=explode(":",$input); |
|||
# $input=$input[1].$input[2]; |
|||
# $input=addslashes($input); |
|||
$input="Dict feature currently disabled for security reasons."; |
|||
$input=substr($input,0, 254); |
|||
} |
|||
# Set Colors |
|||
# 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"; |
|||
# 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"; |
|||
# 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"; |
|||
# Set Font |
|||
# Set Font |
|||
switch ($argv["font"]) { |
|||
case "5pxStd": |
|||
$font="5pxStd"; |
|||
break; |
|||
case "8pxStd": |
|||
$font="8pxStd"; |
|||
break; |
|||
case "MorseCode": |
|||
$font="MorseCode"; |
|||
break; |
|||
default: |
|||
$font="5pxStd"; |
|||
} |
|||
# Set Loop |
|||
if ($argv["loop"]=="Off" || $argv["loop"]=="off" ) { |
|||
$loop="off"; |
|||
} else { |
|||
$loop="on"; |
|||
} |
|||
# Set Width |
|||
if (is_numeric($argv["width"]) && $argv["width"]>=0 && $argv["width"] <=800) { |
|||
$width=$argv["width"]; |
|||
} else { |
|||
$width=200; |
|||
} |
|||
# Set Height |
|||
if (is_numeric($argv["height"]) && $argv["height"]>=0 && $argv["height"] <=800) { |
|||
$height=$argv["height"]; |
|||
} else { |
|||
$height=200; |
|||
} |
|||
# Set Delay |
|||
if (is_numeric($argv["delay"]) && $argv["delay"]>=0 && $argv["delay"] <=100) { |
|||
$delay=$argv["delay"]; |
|||
} else { |
|||
$delay=1; |
|||
} |
|||
# Build Html Output |
|||
$output= <<<END |
|||
<applet codebase = "." code=blinkenapplet.BlinkenApplet.class |
|||
archive="$appletpath" width="$width" height="$height"> |
|||
<param name="debugLevel" value="$debug"> |
|||
<param name="lauftext" value="$input"> |
|||
<param name="lauftext_loop" value="$loop"> |
|||
<param name="ShowDemo1" value="off"> |
|||
<param name="ShowDemo2" value="off"> |
|||
<param name="lauftext_schriftart" value="$font"> |
|||
<param name="delayFaktor" value="$delay"> |
|||
<param name="bgColor" value="$bgcolor"> |
|||
<param name="LampOffColor" value="$lampoffcolor"> |
|||
<param name="LampOnColor" value="$lamponcolor"> |
|||
</applet> |
|||
END; |
|||
# Send it |
|||
return $output; |
|||
} |
|||
?> |
|||
</pre> |
Revision as of 15:26, 7 September 2006
Mediawiki Extension to display BlinkenApplets
<?php # BlinkenApplet Mediawiki Extension # An extension to display Blinkenlights scrolltexts on Mediawiki pages. # by mutante for took (author of BlinkenApplet) # http://s23.org/wiki/BlinkenApplet # http://blinkenapplet.sf.net/ # S23 - 2006/06/15 $wgExtensionFunctions[] = "wfBlinkenExtension"; # extension hook callback function from mediawiki function wfBlinkenExtension() { global $wgParser; $wgParser->setHook( "blinken", "renderBlinkenapplet" ); } # the actual extension function function renderBlinkenapplet( $input, $argv ) { global $wgOutputEncoding; # Config # set path to applet here $appletpath="/w/extensions/BlinkenApplet0.71.jar"; # set a mysql user with (select) access to "wikidb" here $dbuser="wikiuser"; $dbpass=""; # Just in case your MySQL server is not on the same host $dbhost="localhost"; # Just in case you choose a different database name on Mediawiki install $dbname="wikidb"; # End Config # debug level of BlinkenApplet $debug=1; $version="BlinkenApplet0.71.jar"; # some default input for testing # $input="BlinkenApplet by took running on S23 Wiki. It works."; # filter our mysql escape strings from user input, just to make sure # $input = mysql_escape_string($input); # If not too long, set Input Text if (!is_string($input) || strlen($input)>255) { $input="no input text or input input text > 255 chars"; } # Input SPECIALS case "\$fnord": # fetch a random fnord from mysql (fnord database doesnt ship with Mediawiki) $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 "\$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": # show date $input = `date -u`; break; case "\$ddate": # show discordian date $input = `ddate`; break; case "\$ddate +%.": # ddate easteregg $input = `ddate +%.`; break; case "\$loadavg": # show load average $input = `top -b -n1 -s | grep load | cut -d, -f4,5,6`; break; case "\$myIP": # show User IP if (getenv(HTTP_X_FORWARDED_FOR)) { $ip = getenv(HTTP_X_FORWARDED_FOR); } else { $ip = getenv(REMOTE_ADDR); } $input="Your IP is $ip"; break; default: # normal text input $input=$input; } # crypt:<text> # encrypt input text # http://www.php.net/crypt if (substr($input, 0, 6) == "crypt:") { $input=explode(":",$input); $input=$input[1]; $input=crypt($input); $input=substr($input,0, 254); } # dict:<dict> # fetch a dictionary definition # man dict if (substr($input, 0, 5) == "dict:") { $input=explode(":",$input); $input=$input[1]; # $input=`dict $input | sed s/\'//g | sed s/\"//g | xargs`; # $input=explode(":",$input); # $input=$input[1].$input[2]; # $input=addslashes($input); $input="Dict feature currently disabled for security reasons."; $input=substr($input,0, 254); } # Set Colors # 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"; # 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"; # 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"; # Set Font # Set Font switch ($argv["font"]) { case "5pxStd": $font="5pxStd"; break; case "8pxStd": $font="8pxStd"; break; case "MorseCode": $font="MorseCode"; break; default: $font="5pxStd"; } # Set Loop if ($argv["loop"]=="Off" || $argv["loop"]=="off" ) { $loop="off"; } else { $loop="on"; } # Set Width if (is_numeric($argv["width"]) && $argv["width"]>=0 && $argv["width"] <=800) { $width=$argv["width"]; } else { $width=200; } # Set Height if (is_numeric($argv["height"]) && $argv["height"]>=0 && $argv["height"] <=800) { $height=$argv["height"]; } else { $height=200; } # Set Delay if (is_numeric($argv["delay"]) && $argv["delay"]>=0 && $argv["delay"] <=100) { $delay=$argv["delay"]; } else { $delay=1; } # Build Html Output $output= <<<END <applet codebase = "." code=blinkenapplet.BlinkenApplet.class archive="$appletpath" width="$width" height="$height"> <param name="debugLevel" value="$debug"> <param name="lauftext" value="$input"> <param name="lauftext_loop" value="$loop"> <param name="ShowDemo1" value="off"> <param name="ShowDemo2" value="off"> <param name="lauftext_schriftart" value="$font"> <param name="delayFaktor" value="$delay"> <param name="bgColor" value="$bgcolor"> <param name="LampOffColor" value="$lampoffcolor"> <param name="LampOnColor" value="$lamponcolor"> </applet> END; # Send it return $output; } ?>