×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles

    BlinkenApplet/Mediawiki Extension: Difference between revisions

    Content added Content deleted
    imported>mutante
    mNo edit summary
    imported>Took
    m (some categories added)
     
    (13 intermediate revisions by 5 users not shown)
    Line 1: Line 1:
    === [[Mediawiki]] Extension to display [[BlinkenApplet]]s ===
    === [[Mediawiki]] Extension to display [[BlinkenApplet]]s ===

    == How to Install ==

    1. Download the latest version of [http://sourceforge.net/projects/blinkenapplet/ BlinkenApplet] and put it into the "extensions" directory below your wiki install path

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

    (*) 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 <code>$dbuser="wikiuser";</code> and <code>$dbpass="yourpassword";</code> 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 <code>BlinkenExtension.php</code> 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 <code>LocalSettings.php</code> in your wiki install dir and near the bottom add the line:
    <code>include("extensions/BlinkenExtension.php");</code>.

    6. (Optional) To use the bonus features make sure you/PHP can execute the shell commands: <code>date</code>,<code>ddate</code>,<code>dict</code>,<code>top</code>,<code>grep</code>,<code>cat</code> and use PHP' crypt() function.

    == BlinkenExtension.php ==


    <pre>
    <pre>
    Line 47: Line 66:


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


    # Is input a string and not too long?
    # If not too long, set Input Text
    if (!is_string($input) || strlen($input)>255) {
    if (!is_string($input) || strlen($input)>255) {
    $input="no input text or input input text > 255 chars";
    $input="error - no text input or text over 255 chars)";
    }
    }


    Line 57: Line 76:
    case "\$fnord":
    case "\$fnord":
    # fetch a random fnord from mysql (fnord database doesnt ship with Mediawiki)
    # fetch a random fnord from mysql (fnord database doesnt ship with Mediawiki)
    # Use <blinken$fnord</blinken>

    $hd = mysql_connect("$dbhost", "$dbuser", "$dbpass") or die ("Unable to connect");
    $hd = mysql_connect("$dbhost", "$dbuser", "$dbpass") or die ("Unable to connect");
    mysql_select_db ("$dbname", $hd) or die ("Unable to select database");
    mysql_select_db ("$dbname", $hd) or die ("Unable to select database");
    Line 67: Line 88:
    $input = $fnord;
    $input = $fnord;
    break;
    break;

    case "\$quote":
    # fetch a random discordian quote from mysql (quote 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 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;

    # This gets the current site statistics from the wiki and displays it.
    # Use <blinken>$wikistats</blinken>


    case "\$wikistats":
    case "\$wikistats":
    Line 86: Line 122:
    case "\$date":
    case "\$date":
    # show date
    # show date
    # Use <blinken>$date</blinken>

    $input = `date -u`;
    $input = `date -u`;
    break;
    break;
    Line 91: Line 129:
    case "\$ddate":
    case "\$ddate":
    # show discordian date
    # show discordian date
    # Use <blinken>$ddate</blinken>
    $input = `ddate`;
    $input = `ddate`;
    break;
    break;
    Line 96: Line 135:
    case "\$ddate +%.":
    case "\$ddate +%.":
    # ddate easteregg
    # ddate easteregg
    # Use <blinken>ddate +%.</blinken>
    $input = `ddate +%.`;
    $input = `ddate +%.`;
    break;
    break;


    case "\$loadavg":
    case "\$loadavg":
    # show load average
    # show system load average
    # Use <blinken>$loadavg</blinken>
    $input = `top -b -n1 -s | grep load | cut -d, -f4,5,6`;
    $input = `top -b -n1 -s | grep load | cut -d, -f4,5,6`;
    break;
    break;


    case "\$myIP":
    case "\$myIP":
    # show User IP
    # show User IP (not server IP, each user sees hiw own IP)
    # Use <blinken>$myIP</blinken>

    if (getenv(HTTP_X_FORWARDED_FOR)) {
    if (getenv(HTTP_X_FORWARDED_FOR)) {
    $ip = getenv(HTTP_X_FORWARDED_FOR);
    $ip = getenv(HTTP_X_FORWARDED_FOR);
    Line 122: Line 165:
    # encrypt input text
    # encrypt input text
    # http://www.php.net/crypt
    # http://www.php.net/crypt
    # Use <blinken>crypt:sometext</blinken>
    if (substr($input, 0, 6) == "crypt:") {
    if (substr($input, 0, 6) == "crypt:") {
    $input=explode(":",$input);
    $input=explode(":",$input);
    Line 132: Line 176:
    # fetch a dictionary definition
    # fetch a dictionary definition
    # man dict
    # man dict
    # Use <blinken>dict:fnord</blinken>


    if (substr($input, 0, 5) == "dict:") {
    if (substr($input, 0, 5) == "dict:") {
    Line 268: Line 313:
    ?>
    ?>
    </pre>
    </pre>


    [[Category:Blinkenlights]]
    [[Category:Computer]]
    [[Category:Networking]]
    [[Category:HowTo]]
    [[Category:Wiki]]

    Latest revision as of 11:34, 10 February 2008

    Mediawiki Extension to display BlinkenApplets[edit]

    How to Install[edit]

    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 $appletpath to the path you saved the applet to.(*); If the Applet says "notinited" you have to arrange $appletpath.

    (*) 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 $dbuser="wikiuser"; and $dbpass="yourpassword"; 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 BlinkenExtension.php 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 LocalSettings.php in your wiki install dir and near the bottom add the line: include("extensions/BlinkenExtension.php");.

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

    BlinkenExtension.php[edit]

    <?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_real_escape_string($input);
    
    # Is input a string and not too long?
    if (!is_string($input) || strlen($input)>255) {
    $input="error - no text input or text over 255 chars)";
    }
    
    # Input SPECIALS
    case "\$fnord":
    # fetch a random fnord from mysql (fnord database doesnt ship with Mediawiki)
    # Use <blinken$fnord</blinken>
    
    $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":
    # fetch a random discordian quote from mysql (quote 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 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;
    
    # This gets the current site statistics from the wiki and displays it.
    # Use <blinken>$wikistats</blinken>
    
    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
    # Use <blinken>$date</blinken>
    
    $input = `date -u`;
    break;
    
    case "\$ddate":
    # show discordian date
    # Use <blinken>$ddate</blinken>
    $input = `ddate`;
    break;
    
    case "\$ddate +%.":
    # ddate easteregg
    # Use <blinken>ddate +%.</blinken>
    $input = `ddate +%.`;
    break;
    
    case "\$loadavg":
    # show system load average 
    # Use <blinken>$loadavg</blinken>
    $input = `top -b -n1 -s | grep load | cut -d, -f4,5,6`;
    break;
    
    case "\$myIP":
    # show User IP (not server IP, each user sees hiw own IP)
    # Use <blinken>$myIP</blinken>
    
    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
    # Use <blinken>crypt:sometext</blinken>
    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
    # Use <blinken>dict:fnord</blinken>
    
    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;
            }
    ?>
    
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.