Extension:GeoGebra/pt

From MediaWiki.org
Jump to: navigation, search
Manual das Extensões do MediaWiki
lista
Crystal Clear action run.png
GeoGebra

Estado da versão: beta

Implementação Elemento
Descrição Adiciona um applet GeoGebra às páginas
Autor(es) R. Großmann (Bigvirtalk)
Última Versão 2.0p
MediaWiki Testado com 1.12.0
(pode funcionar em versões antigas)
Licença Nenhuma licença especificada
Download veja abaixo
Hooks usados
ParserFirstCallInit

verificar uso (experimental)

Contents

O que esta extensão faz? [edit]

Ela adiciona um applet do GeoGebra à uma página produzida com o MediaWiki.

Os applets GeoGebra usam a tecnologia Java para combinar um ambiente de geometria dinâmica com a habilidade de introduzir equações e coordenadas diretamente. Deste modo eles se tornam muito uteis em educação matemática e explorações matemáticas.

Uso [edit]

Habilite o carregamento de arquivos ggb [edit]

Você terá que habilitar o carregamento de arquivos do GeoGebra (que têm extensão ggb). Isto pode ser feito adicionando as seguintes linhas no LocalSettings.php:

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

Por favor, avise o autor se você sabe como desabilitar a checagem de MimeType apenas para certas extensões de arquivos.

Aprenda mais sobre carregamento de arquivos.

Adicione uma tag à sua página [edit]

A seguinte tag irá adicionar um applet GeoGebra à sua página MediaWiki:

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

Você também pode passar outros parâmetros para o applet. Exemplo:

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

Uso de useLocalJar = true/false [edit]

Por padrão, useLocalJar = "false". Isto significa que geogebra.jar é obtido a partir de www.geogebra.at.

Se geogebra.jar não for encontrado em www.geogebra.at ou se useLocalJar = "true" é definido explicitamente, então geogebra.jar será procurado no mesmo diretório onde se encontra o arquivo GeoGebra.php.

Exemplo:

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

Instruções para o download [edit]

Por favor, copie e cole o código exibido abaixo e coloque-o em <;code>$IP/extensions/GeoGebra.php. Nota: $IP representa o diretório raiz da sua instalação do MediaWiki, o mesmo diretório onde fica o LocalSettings.php.

Instruções para baixar [edit]

Por favor, copie e cole o código exibido abaixo e coloque-o em $IP/extensions/GeoGebra/GeoGebra.php.

Nota: $IP representa o diretório raiz da sua instalação do MediaWiki, o mesmo diretório onde fica o arquivo LocalSettings.php.

Carregue os seguintes arquivos da sua instalação do GeoGebra (talvez em "\programs\GeoGebra") para $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

Instalação [edit]

Para instalar esta extensão, adicione o seguinte ao LocalSettings.php:

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

Código [edit]

<?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, -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.

Problemas conhecidos [edit]

  • Havia um problema com o navegador Opera. O Opera exibia Applet crashed em vez do applet GeoGebra. Este problema ocorria apenas se useLocalJar="true" fosse usado e apenas geogebra.jar estivesse instalado, sem o resto dos arquivos geogebra*.jar. Por favor informe o autor desta extensão se você estiver usando o Opera e o erro ocorrer.
  • Existe um problema ao obter a URL de um arquivo GGB carregado ao repositório de arquivos do MediaWiki. Isto diz respeito apenas a uma instalação da extensão do GeoGebra. As demais funcionam bem. Talvez seja uma interferência com alguma outra extensão.

Alterações da versão 1.0u para a 2.0p [edit]

Se geogebra.jar não for encontrado em www.geogebra.at, ou se for usado useLocalJar="true", a extensão GeoGebra procura por geogebra.jar em outro lugar:

A versão 1.0u procurava por geogebra.jar no repositório de arquivos da wiki. Isto causava problemas, quando geogebra.jar mudou para ser apenas o inicializador para outros arquivos geogebra*.jar, como geogebra_main.jar, geogebra_gui.jar etc.

A versão 2.0p agora procura por geogebra.jar no subdiretório /extension/GeoGebra da wiki. Então você precisa carregar todos os arquivos geogebra*.jar usando FTP.

Uma pequena alteração foi necessária, porque $_SERVER['DOCUMENT_ROOT'] não funcionava corretamente.

Ver também [edit]

Língua: English  • Deutsch • português