Extension:GeoGebra: Difference between revisions

From mediawiki.org
Content deleted Content added
Bigvir (talk | contribs)
No edit summary
Bigvir (talk | contribs)
mNo edit summary
Line 12: Line 12:
|version = 1.0k
|version = 1.0k
|update =
|update =
|mediawiki = tested with 1.13
|mediawiki = tested with 1.12.0 (may run with older versions)
|download =
|download =
|readme =
|readme =

Revision as of 20:39, 4 June 2008

MediaWiki extensions manual
GeoGebra
Release status: beta
Implementation Tag
Description Add GeoGebra applet to MediaWiki pages
Author(s) R. Großmann (Bigvirtalk)
Latest version 1.0k
MediaWiki tested with 1.12.0 (may run with older versions)
License GNU General Public License 2.0 or later
Download No link
Quarterly downloads 3 (Ranked 135th)

What can this extension do?

Add a GeoGebra applet to your MediaWiki page.

Usage

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

$wgFileExtensions[] = 'ggb';

Learn more about uploads.

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

<ggb_applet height="300" width="600" filename="myFile.ggb" />

You can also pass other GeoGebra applet parameters. Example:

<ggb_applet height="200" width="400" showMenuBar="true" showResetIcon="true" filename="myFile.ggb" />

Download instructions

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

Installation

To install this extension, add the following to LocalSettings.php:

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


Code

<?php

// GeoGebra Applet extension by Rudolf Grossmann, 2008-06-03
$ggb_version = "1.0k";

// This MediaWiki extension is based on the Java Applet extension by Phil Trasatti
// see: http://www.mediawiki.org/wiki/Extension:Java_Applet

$wgExtensionFunctions[] = 'ggbAppletSetup';

$wgExtensionCredits['parserhook'][] = array(
  'name'         => 'GeoGebra Applet extension',
  'author'       => 'Rudolf Grossmann',
  'url'          => 'http://not.yet.published',  //'http://www.mediawiki.org/wiki/User:Bigvir'
  'description'  => 'Add GeoGebra Applets (http://www.GeoGebra.at) to MediaWiki pages.',
  'version'      => $ggb_version
);

function ggbAppletSetup()
{
    global $wgParser;
    $wgParser->setHook( 'ggb_applet', 'get_ggbAppletOutput' );
}

function get_ggbAppletOutput( $input, $args, $parser )
{
        global $wgServer; // URL of the WIKI's server
        global $ggb_version; // see line 4 of this file
        $error_message = "no error"; //overwritten, if error occurs
        $appletBinary = 'geogebra.jar'; // Set the appletBinary to the JAR file
        $CRLF = "\r\n";

        $parameter_array = array("type", "framePossible", "bgcolor", "borderColor", "enableRightClick", "enableShiftDragZoom", "showMenuBar");
        $parameter_array = array_merge($parameter_array, array('showToolBar', 'showToolBarHelp', 'customToolBar','showAlgebraInput'));
        $parameter_array = array_merge($parameter_array, array('showResetIcon', 'language', 'country'));

        $noJavaText = 'Please <a href="http://java.sun.com/getjava">install Java 1.4</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 *.ggb file
        $ggbBinary = htmlspecialchars(strip_tags($args['filename']));
        $ggbFile = Image::newFromName($ggbBinary);
        if (!($ggbFile->exists()))
        {
          $error_message = "File " . $ggbBinary . " not found.";
        }
        else
        {
          $ggbURL = $wgServer . $ggbFile->getURL();
        }

        // Output the opening applet tag
        $output = "<!-- GeoGebra Applet MediaWiki extension " . $ggb_version . " by R. Grossmann -->" . $CRLF;

        // Add code value to tag
        $output = $output . '<applet code="geogebra.GeoGebraApplet"';

        // Add codebase value to tag
        $output = $output . ' codebase="http://www.geogebra.at/webstart/"';

        // Add width value to tag
        // use strip_tags() to avoid cross-side scripting
        $output = $output . ' width="' . htmlspecialchars(strip_tags($args['width'])) . '"';

        // Add height value to tag
        $output = $output . ' height="' . htmlspecialchars(strip_tags($args['height'])) . '"';

        // Add Archive value to tag
        $output = $output . ' archive="geogebra.jar">' . $CRLF;

        // Add URL of *.ggb file to tag
        $output = $output . '<param name="filename" value="' . $ggbURL . '">' . $CRLF;

        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;
        }

        // Message if Java is not installed
        $output = $output . $noJavaText . $CRLF;
        // Closing applet tag
        $output = $output . "</applet>" . $CRLF;

        // if error occured, discard applet and output error message
        if ($error_message != "no error")
        {
          $output = "<p>Error in MediaWiki extension (GeoGebraApplet.php): <em>" . $error_message. "</em></p>" . $CRLF;
        }

        // Send the output to the browser
        return $output;
}

See also

This Extension is based on the Java Applet extension by Phil Trasatti.