Extension:Cindy

From MediaWiki.org

Jump to: navigation, search

           

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
Cindy

Release status: beta

Implementation  Tag
Description Add Cinderella applet to MediaWiki pages
Author(s)  R. Großmann (BigvirTalk)
Last Version  1.0d
MediaWiki  tested with 1.12.0
(may run with older versions)
License No license specified
Download see below

check usage (experimental)

Contents

[edit] What can this extension do?

Add a Cinderella applet to your MediaWiki page.

Cinderella applets use Java technology to give you an interactive geometry environment. Cinderella is a powerful mathematics simulation environment. It includes simple physics and a programming language called CindyScript, that can be used to create complex, and even interactive, mathematical constructions.

[edit] Usage

[edit] Allow uploads of cdy-files

You will have to allow uploads of Cinderella-files (*.cdy). This can be done by adding the following two lines to LocalSettings.php:

$wgFileExtensions[] = 'cdy';
$wgVerifyMimeType = false;

Please tell me ( R. Grossmann) if you know how to swich off MimeType checking only for certain file extensions.

Learn more about upload of Media files.

[edit] Add a Cinderella applet tag to your MediaWiki page

The following tag will add a Cinderella applet to your MediaWiki page:

<cdy_applet width="600"  height="300" filename="myFile.cdy" />

You can also pass other Cinderella applet parameters. Example:

<cdy_applet width=800 height=450 filename="myFile.cdy"
kernelID=1014875487410
exercise=true
viewport="de.cinderella.ports.EuclideanPort"
polar="false"
mesh="false"
axes="false"
snap="false"
scale="25.0"
/>

[edit] List of parameters

  • Obligatory parameters: width, height, filename.
  • Optional parameters: anglemodulo, axes, axes.show, backgroundimage, cinderella.antialias, console, controls, darkenDependent, deltafactor, doublebuffer, euclideanport.scale, exercise, imagealpha, imagescalemode, KernelID, mesh, mesh.density, mesh.rectangular, mesh.triangular, originx, originy, polar, precision.angle, precision.angle.int, precision.measure, precision.measure.int, pref0, pref1, pref2, printscale, printscale.int, scale, show.adjacencymatrix, snap, viewport.
  • Please inform me (R. Grossmann), if you know more Cinderella parameters. Maybe there is a list in the documentation?

[edit] Installation

[edit] Download instructions

Please cut and paste the code found below and place it in $IP/extensions/Cindy.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

[edit] Implementation

To implement the Cindy extension inside your MediaWiki, add the following line to LocalSettings.php:

require_once("$IP/extensions/Cindy.php");

The wiki page Special:Version will show you all implemented extensions with a version message.

[edit] Upload of Cindyrun.jar

You will need the file Cindyrun.jar (runtime Java archive for Cinderella applets). The Cindy extension will look for this file in the file repository of your MediaWiki.

You will have to allow uploads of JAR-files for some minutes. This can be done by adding the following line to LocalSettings.php:

$wgFileExtensions[] = 'jar';

Then upload Cindyrun.jar to your wiki. After successfull upload, you can delete this line in your LocalSettings.php

[edit] Code

<?php
/**
 * Cindy extension
 *
 * @author Rudolf Grossmann
 * @version 1.0d
 */
 
$cdy_version = "1.0d";
 
// This MediaWiki extension is based on the Java Applet extension by Phil Trasatti
// see: http://www.mediawiki.org/wiki/Extension:Java_Applet
 
//Avoid unstubbing $wgParser too early on modern (1.12+) MW versions, as per r35980
if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
        $wgHooks['ParserFirstCallInit'][] = 'cdy_AppletSetup';
} else {
        $wgExtensionFunctions[] = 'cdy_AppletSetup';
}
 
$wgExtensionCredits['parserhook'][] = array(
        'name'         => 'Cindy',
        'author'       => 'Rudolf Grossmann',
        'url'          => 'http://www.mediawiki.org/wiki/Extension:Cindy',
        'description'  => 'Add [http://cinderella.de Cinderella] applets to MediaWiki pages.',
        'version'      => $cdy_version
);
 
function cdy_AppletSetup() {
        global $wgParser;
        $wgParser->setHook( 'cdy_applet', 'get_cdyAppletOutput' );
        return true;
}
 
function get_cdyAppletOutput( $input, $args, $parser ) {
        global $wgServer; // URL of the WIKI's server
        global $cdy_version; // see line 9 of this file
 
        $error_message = "no error"; //will be overwritten, if error occurs
        $CRLF = "\r\n";
        $quot='"';
 
        $parameter_array = array('anglemodulo', 'axes', 'axes.show', 'backgroundimage', 'cinderella.antialias');
        $parameter_array = array_merge($parameter_array, array('console', 'controls', 'darkenDependent', 'deltafactor', 'doublebuffer'));
        $parameter_array = array_merge($parameter_array, array('euclideanport.scale', 'exercise', 'imagealpha', 'imagescalemode', 'KernelID'));
        $parameter_array = array_merge($parameter_array, array('mesh', 'mesh.density', 'mesh.rectangular', 'mesh.triangular', 'originx'));
        $parameter_array = array_merge($parameter_array, array('originy', 'polar', 'precision.angle', 'precision.angle.int', 'precision.measure'));
        $parameter_array = array_merge($parameter_array, array('precision.measure.int', 'pref0', 'pref1', 'pref2', 'printscale'));
        $parameter_array = array_merge($parameter_array, array('printscale.int', 'scale', 'show.adjacencymatrix', 'snap', 'viewport'));
 
        $noJavaText = 'Please <a href="http://java.sun.com/getjava">install Java 1.4.2</a> (or later) to use this page.';
 
        // Look for required parameters
        if( !isset( $args['width'] )   ||
            !isset( $args['height'] )  ||
            !isset( $args['filename'] ) )
            $error_message = "Missing parameter (width or height or filename).";
 
        // Retrieve URL of uploaded JAR file.
        $appletBinary = "cindyrun.jar" ;
        $appletBinary = ucfirst($appletBinary); // set first letter of jar-file upper case
        $file = Image::newFromName( $appletBinary ) ; // Get the Image object from the file name
        $fileURL = $file->getURL(); // Get the mediawiki path of the file
        $fileURL = str_replace( $appletBinary, "", $fileURL ); // Strip the filename from the path
        $codeBase = $wgServer . $fileURL; // Attach wiki site path
 
        $output = "<!-- Cindy MediaWiki extension " . $cdy_version . " by R. Grossmann -->" . $CRLF;
        $output = $output . '<applet code="de.cinderella.CindyApplet"'; // Add code value to tag
        if( isset( $args['name'] )){
           $output = $output . " name=" . $quot . htmlspecialchars(strip_tags($args['name'])) . $quot; // Add name value to tag
        }
        $output = $output . " codebase=" . $quot . $codeBase . $quot; // Add codebase value to tag
        $output = $output . " width=" . $quot . htmlspecialchars(strip_tags($args['width'])) . $quot; // Add width value to tag
        $output = $output . " height=" . $quot . htmlspecialchars(strip_tags($args['height'])) . $quot; // Add height value to tag
        $output = $output . " archive=" . $quot. $appletBinary . $quot. " >"; // Add archive value to tag
 
        // retrieve URL of *.cdy file
        $cdyBinary = htmlspecialchars(strip_tags($args['filename']));
        $cdyFile = Image::newFromName($cdyBinary);
        if (!($cdyFile->exists()))
        {
          $error_message = "File " . $cdyBinary . " not found.";
        }
        else
        {
          $cdyURL = $cdyFile->getURL();
          // if URL doesn't start with slash, add starting slash.
          if (substr($cdyURL, 0, 1) != '/'){
                  $cdyURL = '/' . $cdyURL;
          }
          $cdyURL = $wgServer . $cdyURL;
        }
 
        // Add URL of *.cdy file to tag
        $output = $output . '<param name="filename" value="' . $cdyURL . '">' . $CRLF;
 
        // Add code for parameters, if exist!.
        foreach($parameter_array as $parameter) {
          $value = $args[strtolower($parameter)]; //strtolower necessary for $args [   ]
          $value = htmlspecialchars(strip_tags($value));
          if(strlen($value) > 0)
             $output = $output . '<param name="' . $parameter .'" value="' . $value . '">' . $CRLF;
        }
 
        $output = $output . $noJavaText . $CRLF; // Message if Java is not installed
        $output = $output . "</applet>" . $CRLF; // The closing applet tag
 
 
        // if error occured, discard applet and output error message
        if ($error_message != "no error") {
          $output = "<p>Error in MediaWiki extension (Cindy.php): <em>" . $error_message. "</em></p>" . $CRLF;
        }
 
        // Send the output to the browser
        return $output;
} // missing php end tag to avoid troubles.

[edit] See also