Extension:GeoGebra

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

Release status: stable

Implementation Tag
Description Add GeoGebra applet to MediaWiki pages
Author(s) R. Großmann (BigvirTalk)
Last version 2.7f
MediaWiki tested with 1.12.0
(may run with older versions)
License No license specified
Download see below
Hooks used
ParserFirstCallInit

Check usage (experimental)

Contents

[edit] What can this extension do?

Add a GeoGebra applet to your MediaWiki page.

GeoGebra applets use Java technology to combine an interactive geometry environment with the ability to directly enter equations and coordinates making it very useful in math education and math explorations.

[edit] Usage

[edit] Add a GeoGebra Applet tag to your MediaWiki page

With GeoGebra 3.2.33.0 or later you can export a GeoGebra file to a wiki very comfortably.

Use the new Export function of GeoGebra:

Use File - Export - Dynamic Worksheet as Webpage... Then go to "Advanced" and choose "Clipboard:MediaWiki" (bottom right).

Paste the clipoard to your wiki in edit mode. Done! This will create a tag like this:

<ggb_applet height="300" width="600" ggbBase64="AbCd67Fg...KhRs" />

You do not have to upload ggb files like in version 2.0p!

You can also pass other GeoGebra applet parameters. Example:

<ggb_applet height="200" width="400" showMenuBar="true" showResetIcon="true" ggbBase64="AbCd67Fg...KhRs" />

[edit] Usage of useLocalJar = true/false

By default, useLocalJar = "false". That means, geogebra.jar is fetched from www.geogebra.at.

If geogebra.jar is not found at www.geogebra.at or if useLocalJar = "true" is set explicitly, geogebra.jar will be searched in the same directory as GeoGebra.php.

Example:

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

If there is no connection to the Internet, and the Wiki is installed on a local server (e.g. using XAMPP), UseLocalJar="true" can be used with benefit.

[edit] Usage of useSignedJar = true/false

The parameter 'useSignedJar' has precedence over parameter 'useLocalJar'. If useSignedJar='true', the signed JAR files from www.geogebra.org are used. Digital signing makes it possible for the GeoGebra applet to change to an application by doubleclicking. This application is able to write GGB files to the local hard disc.

[edit] Status changed to stable

Version 2.7 was tested with more then 6 wikis. See Examples.

There were no reports of critical errors, only minor changes (see history above).

So I decided to change status from beta to stable at 2011-03-05.

Here you find the old stable version 2.0p.

[edit] Download instructions

Please cut and paste the code found below and place it in $IP/extensions/GeoGebra/GeoGebra.php.

Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

If you want your users to be able to use parameter useLocalJar=true, then upload the following files

from http://www.geogebra.org/webstart/unsigned/unpacked/ to $IP/extensions/GeoGebra.

  • geogebra.jar
  • geogebra_cas.jar
  • geogebra_export.jar
  • geogebra_gui.jar
  • geogebra_main.jar
  • geogebra_properties.jar

If you want to use fast loading of Java applets, also upload the following packed files

from http://www.geogebra.org/webstart/unsigned/packed/

  • geogebra.jar.pack.gz
  • geogebra_cas.jar.pack.gz
  • geogebra_export.jar.pack.gz
  • geogebra_gui.jar.pack.gz
  • geogebra_main.jar.pack.gz
  • geogebra_properties.jar.pack.gz

Make sure you use unsigned JAR files.

[edit] Installation

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

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

[edit] Code

<?php
/**
 * GeoGebra extension
 *
 * @author Rudolf Grossmann
 * @version 2.7g
 */
 
$ggb_version = "2.7g";
 
// 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'][] = 'ggb_AppletSetup';
} else {
        $wgExtensionFunctions[] = 'ggb_AppletSetup';
}
 
$wgExtensionCredits['parserhook'][] = array(
        'name'         => 'GeoGebra',
        'author'       => 'Rudolf Grossmann',
        'url'          => 'http://www.mediawiki.org/wiki/Extension:GeoGebra',
        'description'  => 'Add [http://www.geogebra.org GeoGebra] applets to MediaWiki pages.',
        'version'      => $ggb_version
);
 
function ggb_AppletSetup() {
        global $wgParser;
        $wgParser->setHook( 'ggb_applet', 'get_ggbAppletOutput' );
        return true;
}
 
function get_ggbAppletOutput( $input, $args, $parser ) {
        global $wgServer; // URL of the WIKI's server
        global $ggb_version; // see line 9 of this file
 
        $error_message = "no error"; //will be overwritten, if error occurs
        $debug = 'Debug: ';
        $CRLF = "\r\n";
        $quot='"';
        $appletBinary = "geogebra.jar" ;
        $codeBaseSigned = 'http://www.geogebra.org/webstart/';
        if( isset( $args['version'] ) ) {
          $version = htmlspecialchars(strip_tags($args['version']));
          $codeBaseUnsigned = 'http://www.geogebra.org/webstart/' . $version .'/unsigned/';
        } else {
          $codeBaseUnsigned = 'http://www.geogebra.org/webstart/unsigned/';
        }
 
        // Special parameters, not for parameter (name - value) tags. Use lowercase for sake of comparison!
        $special_parameters = array('width', 'height', 'uselocaljar', 'usesignedjar', 'substimage', 'filename', 'ggbbase64', 'version', 'debug'); 
        $noJavaText = 'Please <a href="http://java.sun.com/getjava">install Java</a> to use this page.'; 
 
        // retrieve URL of image file substituting GeoGebra applet if Java ist not installed
        $imgBinary = isset($args['substimage']) ? htmlspecialchars(strip_tags($args['substimage'])) : '';
        if ($imgBinary=='') {
          $imgBinary = 'filenotfound.jpg';
        }
        $imgFile = Image::newFromName($imgBinary);
        if ($imgFile->exists())
        {
          $imgURL = $imgFile->getURL();
          // if URL doesn't start with slash, add starting slash.
          if (substr($imgURL, 0, 1) != '/'){
                  $imgURL = '/' . $imgURL;
          }
          $imgURL = $wgServer . $imgURL;
          $noJavaText = "<img src=". $quot . $imgURL . $quot;
          $noJavaText = $noJavaText . " width=" . $quot . htmlspecialchars(strip_tags($args['width'])) . $quot; // Add width value to tag
          $noJavaText = $noJavaText . " height=" . $quot . htmlspecialchars(strip_tags($args['height'])) . $quot; // Add height value to tag
          $noJavaText = $noJavaText . " alt=" . $quot . "Image replacing GeoGebra applet" . $quot. " >". $CRLF;
          $noJavaText = $noJavaText . '<p>Please <a href="http://java.sun.com/getjava">install Java</a> to see a dynamic version of this image.</p>';
        }
 
        //Look for parameter 'useSignedJar'.
        $useSignedJar = isset($args['usesignedjar']) ? $args['usesignedjar'] : '';
        //Look for parameter 'useLocalJar'. Will be overwritten with 'true', if parameter 'filename is used'
        $useLocalJar = isset($args['uselocaljar']) ? $args['uselocaljar'] : '';
        $printDebug = isset($args['debug']) ? $args['debug'] : 'false';
 
        // Look for required parameters width, height, ggbBase64 or filename
        if( !(isset( $args['width'] ) ) )
        {
          $error_message = "Missing parameter 'width'.";
        } else {
          if( !(isset( $args['height'] ) ) )
          {
            $error_message = "Missing parameter 'height'.";
          } else {
            if( isset( $args['ggbbase64'] ) )
            {
              $ggbBase64String = htmlspecialchars(strip_tags($args['ggbbase64']));
              if ($ggbBase64String != '')
              {
                $ggbSource = '<param name="ggbBase64" value="' . $ggbBase64String . '">' . $CRLF;
              }
            } else {
              // No parameter ' ggbBase64'. Parameter 'filename' necessary
              if( !(isset( $args['filename'] ) ) )
              {
                $error_message = "No parameter 'ggbBase64' or 'filename'.";
              } else {
                // retrieve URL of *.ggb file
                $ggbBinary = htmlspecialchars(strip_tags($args['filename']));
                if ($ggbBinary == '') {
                  $ggbBinary = 'filenotfound.ggb';
                }
                $ggbFile = Image::newFromName($ggbBinary);
                if (!($ggbFile->exists()))
                {
                  $error_message = "File not found: " . $ggbBinary;
                }
                else
                {
                  $ggbURL = $ggbFile->getURL();
                  // if URL doesn't start with slash, add starting slash.
                  if (substr($ggbURL, 0, 1) != '/'){
                          $ggbURL = '/' . $ggbURL;
                  }
                  $ggbURL = $wgServer . $ggbURL;
                  // Add URL of *.ggb file to tag
                  $ggbSource = '<param name="filename" value="' . $ggbURL . '">' . $CRLF;
                  $useLocalJar = 'true'; //Avoid trouble (security exception)
                }
              }
            }
          }
        }
 
        // if error occured, discard applet and output error message
        if ($error_message == 'no error') {
          $debug .= 'No error<br>' . $CRLF;
          if ($useSignedJar != 'true'){  // Default
            $debug .= 'useSigned=false<br>' . $CRLF;
            if ($useLocalJar != 'true'){
              $debug .= 'useLocal=false<br>' . $CRLF;
              $codeBase = $codeBaseUnsigned; //Default
            } 
          } else {
              $debug .= 'User explicitly wants signed applet!<br>' . $CRLF;
              // User explicitly wants signed applet
              $codeBase = $codeBaseSigned;
              $useLocalJar = 'false';
          }
 
          if ($useLocalJar == 'true'){  // Parameter set or JAR from geogebra.org not found
            $debug .= 'useLocal=true<br>' . $CRLF;
            # The following line is code from http://code.activestate.com/recipes/576595/   "A more reliable DOCUMENT_ROOT"
            $docroot = realpath((getenv('DOCUMENT_ROOT') && ereg('^'.preg_quote(realpath(getenv('DOCUMENT_ROOT'))), realpath(__FILE__))) ? getenv('DOCUMENT_ROOT') : str_replace(dirname(@$_SERVER['PHP_SELF']), '', str_replace(DIRECTORY_SEPARATOR, '/', dirname(__FILE__))));
            $delta = substr(dirname(__FILE__), strlen($docroot));
            $codeBase = $wgServer . $delta;
            # replace backslash by slash
            $codeBase=str_replace('\\','/',$codeBase); 
            # add slash at ending
            if (substr($codeBase, strlen($codeBase)-1) != '/') {
              $codeBase = $codeBase . "/";
            }
          }
        }
 
        if ($error_message == 'no error') {
            // Assemble the applet tag
            $output = "<!-- GeoGebra Applet MediaWiki extension " . $ggb_version . " by R. Grossmann -->";
            $output .= '<applet code="geogebra.GeoGebraApplet"'; // 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 .= " codebase=" . $quot . $codeBase . $quot; // Add codebase value to tag
            $output .= " width=" . $quot . htmlspecialchars(strip_tags($args['width'])) . $quot; // Add width value to tag
            $output .= " height=" . $quot . htmlspecialchars(strip_tags($args['height'])) . $quot; // Add height value to tag
            $output .= " archive=" . $quot. $appletBinary . $quot. " >"; // Add archive value to tag
            $output .= $ggbSource;
 
            // Add code for  non-special parameters
            foreach($args as $par_name => $par_value) {
              if (! in_array(strtolower($par_name), $special_parameters)){
                $parameter = htmlspecialchars(strip_tags($par_name));
                $value = htmlspecialchars(strip_tags($par_value));
                $debug .= '<p>Allgemein: ' . $par_name . ' => ' . $par_value . '</p>' . $CRLF;
                if(strlen($value) > 0) {
                   $output .= '<param name="' . $parameter .'" value="' . $value . '">' . $CRLF;
                }
              }
            }
            $output .= '<param name="java_arguments" value="-Djnlp.packEnabled=true">'. $CRLF; // Use packed JAR if available
            // Close applet tag
            $output .= $noJavaText . $CRLF; // Message if Java is not installed
            $output .= "</applet>" . $CRLF; // The closing applet tag
        } else {
            $output = "<p>Error in MediaWiki extension (GeoGebra.php): <em>" . $error_message. "</em></p>" . $CRLF;
        }
        if ($printDebug == 'true') {
           $output .= '<p>' . $debug . '</p>' . $CRLF;
        }
        // Send the output to the browser
        return $output;
} // missing php end tag to avoid troubles.

[edit] Changes from 1.0u to 2.0p

See Version 2.0p

[edit] Changes from 2.0p to 2.6m

[edit] Use of unsigned JAR files

Digitally signed JAR files were used by GeoGebra to allow an applet to "turn into an application" and write to the local hard disc. But some users were frightened by the security alerts caused by the digital signature. In addition, a digital signature uses to expire, causing the security alerts to look even more frightening. Markus Hohenwarter and his team decided to deliver new, unsigned JAR files. Now the applets cause no security alerts, but cannot save a GeoGebra (ggb) file. If you want to create and save a ggb file, you have to use GeoGebra as an application.

[edit] New parameter ggbBase64 replaces filename

Use of filename="foo.ggb" is easy, if the JAR fileand the GGB fileare in the same subdirectory. But things become more complicated, if the GGB file is for example in a file repository of a wiki. The mechanism of retrieving the path to the GGB file sometimes sucked. (Very hard to debug, if the wiki is not your own and you have no admin rights to install new versions of the extension.)

Using the new parameter ggbBase64, you cam pass the content of a GGB file as a base64-encoded String. No filename is needed. No upload is needed.

[edit] Use of packed JAR files

[edit] Change from 2.6m to 2.6n

  • Avoiding errors in apache error log, suggestion of PrimeMogul, see Bigvir

[edit] Change from 2.6n to 2.7c

  • Function url_exists() was not reliable and caused some traffic at the GeoGebra server.
  • Function url_exists() was deleted. If geogebra.jar is not found at www.geogebra.org, the browser (or the Java plugin) will generate an error message. (In version 2.6n the error message was generated by the PHP code of the extension.)

[edit] Change from 2.7c to 2.7f (Chrome error)

  • Some redundant CRLFs (Carriage return /Line feed) used by assembling the applet tag caused MediaWiki to render the tags in a wrong order:
    2.7c: <p>...<applet>...</p>...</applet>
    
  • Internet Explorer, Firefox, and Opera ignored this HTML syntax error, but not the Chrome browser.
  • 2.7f fixes this bug:
    2.7f: <p>...</p>...<applet>...</applet>
    

[edit] Change from 2.7f to 2.7g

The following code caused an error if the file with name $ggbBinary did not exist.

$ggbFile = Image::newFromName($ggbBinary);
if (!($ggbFile->exists()))
{
     $error_message = "File not found: " . $ggbFile;
}

The following code fixes this:

$ggbFile = Image::newFromName($ggbBinary);
if (!($ggbFile->exists()))
{
     $error_message = "File not found: " . $ggbBinary;
}

[edit] See also

Language: English  • Deutsch • Português
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox