Extension:GeoGebra/de

From MediaWiki.org

Jump to: navigation, search

         

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

Release status: beta

Implementation  Tag
Description Einbetten eines GeoGebra-Applets in eine MediaWiki-Seite
Author(s)  R. Großmann (BigvirTalk)
Last Version  2.0p
MediaWiki  getested mit 1.12.0
(funktioniert wahrscheinlich auch mit älteren Versionen)
License No license specified
Download siehe unten

Contents

[edit] Wozu dient diese Erweiterung?

Einbettung eines GeoGebra-Applets zu einer MediaWiki-Seite.

Ein GeoGebra-Applet ist ein dynamisches Geometrie-System, das mit der Möglichkeit versehen wurde, direkt Gleichungen und Koordinaten eingeben zu können. Dies ist sehr nützlich für den Mathematikunterricht und mathematische Untersuchungen.

[edit] Usage

[edit] Uploads von ggb-Dateien zulassen

Sinnvollerweise sollte man Uploads von GeoGebra-Dateien (*.ggb) zulassen. Dies erreicht man, indem man die folgenden zwei Zeilen zur Datei LocalSettings.php hinzufügt:

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

Bitte teilen Sie mir mit, falls Sie wissen, wie man das "MimeType checking" nur für bestimmte Dateinamen-Erweiterungen ausschaltet.

Hier finden Sie mehr über den upload von Media-Dateien.

[edit] Einfügen eines GeoGebra-Applets in Ihre MediaWiki-Seite

Die folgende Zeile fügt ein GeoGebra-Applet in Ihre MediaWiki-Seite ein:

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

Man kann auch andere GeoGebra-Applet-Parameter übergeben. Beispiel:

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

[edit] Benutzug von useLocalJar = true/false

Als Voreinstellung (default) gilt useLocalJar = "false". Das heißt, die Datei geogebra.jar wird von www.geogebra.at geladen.

Falls geogebra.jar nicht bei www.geogebra.at gefunden wird, oder falls der Parameter useLocalJar = "false" explizit gesetzt ist, wird geogebra.jar im gleichen Verzeichnis wie GeoGebra.php gesucht.

[edit] Anleitung zum Download

Bitte kopieren Sie den unten angegebenen Code und speichern Sie ihn in der Datei $IP/extensions/GeoGebra/GeoGebra.php.

Anmerkung: $IP steht für das "root directory" der MediaWiki-Installation, dasselbe Verzeichnis, in dem auch die Datei LocalSettings.php gespeicher ist.

Laden Sie die folgenden Dateien Ihrer GeoGebra-Installation (wahrscheinlich in \programme\GeoGebra zu finden) hoch nach $IP/extensions/GeoGebra.

  • geogebra.jar
  • geogebra_cas.jar
  • geogebra_export.jar
  • geogebra_gui.jar
  • geogebra_main.jar
  • geogebra_properties.jar
  • lax.jar
  • license.txt
  • gpl-2.0.txt
  • cc-by-nc-nd-3.0.txt

[edit] Installation

Um diese Extension zu aktivieren, fügen Sie bitte folgende Zeile zu LocalSettings.php hinzu:

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

[edit] Code

<?php
/**
 * GeoGebra extension
 *
 * @author Rudolf Grossmann
 * @version 2.0p
 */
 
$ggb_version = "2.0p";
 
// 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.at GeoGebra] applets to MediaWiki pages.',
        'version'      => $ggb_version
);
 
//check if an external file exists, code from http://www.webdigity.com/index.php/topic,7148
if (! function_exists('url_exists')){
   function url_exists($url) {
        $url = str_replace(" ", "%20", $url);
        $a_url = parse_url($url);
        if (!isset($a_url['port'])) $a_url['port'] = 80;
        $errno = 0;
        $errstr = ''; 
        $timeout = 15;
        if(isset($a_url['host']) && $a_url['host']!=gethostbyname($a_url['host'])){
                $fid = fsockopen($a_url['host'], $a_url['port'], $errno, $errstr, $timeout);
                if (!$fid) return false;
                $page = isset($a_url['path'])  ?$a_url['path']:'';
                $page .= isset($a_url['query'])?'?'.$a_url['query']:'';
                fputs($fid, 'HEAD '.$page.' HTTP/1.0'."\r\n".'Host: '.$a_url['host']."\r\n\r\n");
                $head = fread($fid, 4096); 
                fclose($fid);
                return preg_match('#^HTTP/.*\s+[200|302]+\s#i', $head);
        } else {
                return false;
        }
   }
}
 
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
        $CRLF = "\r\n";
        $quot='"';
 
        $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).";
 
        $appletBinary = "geogebra.jar" ;
        $codeBase = "http://www.geogebra.at/webstart/"; // default
        $filenotfound = false;
        if (url_exists($codeBase . $appletBinary) == 'false'){
          $filenotfound = true;
        }
 
        if ($filenotfound == true || $args['uselocaljar'] == 'true' ){
          # 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 . "/";
          }
          $filenotfound = false;  
          if (url_exists($codeBase . $appletBinary) == 'false'){
            $filenotfound = true;
          }
        }
        if ($filenotfound){
          $error_message = "File " . $codeBase . $appletBinary . " not found.";
        }
 
        $output = "<!-- GeoGebra Applet MediaWiki extension " . $ggb_version . " by R. Grossmann -->" . $CRLF;
        $output = $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 = $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 *.ggb file
        $ggbBinary = htmlspecialchars(strip_tags($args['filename']));
        $ggbFile = Image::newFromName($ggbBinary);
        if (!($ggbFile->exists()))
        {
          $error_message = "File " . $ggbBinary . " not found.";
        }
        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
        $output = $output . '<param name="filename" value="' . $ggbURL . '">' . $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 (GeoGebra.php): <em>" . $error_message. "</em></p>" . $CRLF;
        }
 
        // Send the output to the browser
        return $output;
} // missing php end tag to avoid troubles.

[edit] Bekannte Probleme

  • Mit Opera trat folgender Fehler auf: Opera zeigte Applet crashed anstelle des GeoGebra-Applets. Dieser Fehler trat nur auf, falls useLocalJar="true" gesetzt war und falls nur geogebra.jar ohne den Rest der geogebra*.jar-Dateien installiert war. Bitte teilen Sie mir mit, falls Sie Opera benutzen und dieser oder ein ähnlicher Fehler auftaucht.
  • Es gibt manchmal Probleme, die URL einer ins Mediawiki-Datei-Repositorium hochgeladenen GGB-Datei zu ermitteln. Dies betrifft nur eine einzelne Installation der GeoGebra-Extension; die anderen arbeiten ohne Fehler. Vielleicht liegt eine Beeinflussung durch eine andere Extension vor.

[edit] Changes from 1.0u to 2.0p

If geogebra.jar is not found at www.geogebra.at, or if using useLocalJar="true", GeoGebra extension looks for geogebra.jar at another place:

Version 1.0u looked for geogebra.jar in the file repository of the wiki. This caused problems, when geogebra.jar changed to be only a starter for other geogebra*.jar files, e.g. geogebra_main.jar, geogebra_gui.jar etc.

Version 2.0p now looks for geogebra.jar in the /extension/GeoGebra subdirectory of the wiki. So you have to upload all geogebra*.jar files using FTP.

A minor change was necessary, because $_SERVER['DOCUMENT_ROOT'] did not work correctly.

[edit] See also