Extension:Java Applet

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Java Applet

Release status: stable

Implementation Tag
Description Add java applets to a wiki
Author(s) Phil Trasatti
Last version 1.0b (2007-09-07)
MediaWiki Tested on 1.10.0
License No license specified
Download see below

Check usage (experimental)

This Mediawiki extension adds Java applets using the "java_applet" tag. The Java binary must be uploaded to the wiki (either class file or jar file). You may need to add 'jar' and 'class' to the $wgFileExtensions variable in LocalSettings.php.

Contents

[edit] Arguments

  • code, java class file (required)
  • width, applet width (required)
  • height, applet height (required)
  • archive, jar file name (required)


[edit] Example

<java_applet code="PegGame.class"  height="150" width="150" archive="PegGame.jar" />

[edit] Installation

To install, copy the code below to "JavaApplet.php" and put it in your Mediawiki extensions directory and add...

include("extensions/JavaApplet.php");

...to your LocalSettings.php file.

This is my first try at coding php so I don't promise it to be secure, easy to use or even work. Use this program at your own risk.

<?php
$wgExtensionFunctions[] = 'efAppletSetup';
 
function efAppletSetup() 
{
    global $wgParser;
 
    $wgParser->setHook( 'java_applet', 'getAppletOutput' );
}
 
function getAppletOutput( $input, $args, $parser ) 
{
        // URL of the WIKI's server
        global $wgServer;
 
        // Look for required elements
        if( !isset( $args['code'] )    || // Eventualy remove the "archive" parameter and
            !isset( $args['archive'] ) || // make the extention detect if the code is a jar
            !isset( $args['width'] )   || // and read it's manifest to determin the main class.
            !isset( $args['height'] ) )
                return "\n<!-- JavaApplet.php: Required Element Missing -->";
 
        // Set the appletBinary to the JAR file
        $appletBinary = $args['archive'];
 
        // Get the Image object from the file name
        $file = Image::newFromName( $appletBinary ) ; // Need to check this better
 
        // Get the mediawiki path of the file
        $fileURL = $file->getURL();  // Need to check this better too
 
        // Strip the filename from the path
        $fileURL = str_replace( $appletBinary, "", $fileURL ); 
 
        // Attach wiki site path 
        $codeBase = $wgServer . $fileURL;     
 
        // Output the opening applet tag
        $output = "\n<!-- JavaApplet Mediawiki extension 1.0b -->\n<APPLET";
 
        // Add code value to tag
        $output = $output . ' code="' . $args['code'] . '"';
 
        // Add codebase value to tag
        //$output = $output . ' codebase="' . $args['codebase'] . '"';
        $output = $output . ' codebase="' . $codeBase . '"';
 
        // Add width value to tag
        $output = $output . ' width="' . $args['width'] . '"';
 
        // Add height value to tag
        $output = $output . ' height="' . $args['height'] . '"';
 
        // Add Archive value to tag if it exists
        if( isset( $args['archive'] ) )
                $output = $output . ' archive="' . $args['archive'] . '"';
 
        // The closing applet tag
        $output = $output . ">\n</APPLET>";
 
        // Send the output to the browser
        return $output;
}
?>

[edit] To Do

Automatically detect the 'code' value from jar files with properly setup manifests.

Question: I installed the files in my directory and added the LocalSettings.php extension. The Java Applet extension seems to work. However I do not have "PegGame.class" . Where do I get a test file and where do I upload it to?

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox