MediaWiki

From Jmol
Revision as of 05:56, 7 June 2006 by Rzepa (talk | contribs) (Test Pages)
Jump to navigation Jump to search

Description

MediaWiki is an open source wiki engine licensed under the GNU General Public License. It is used by many websites, including this one.

The Jmol Mediawiki Extension enables the use of the Jmol applet inside of Mediawiki pages. This simple page demonstrates how to use the extension.

Current status: the Jmol Mediawiki Extension is fully functional and stabilized. It currently needs production testing.


Wikis using the Jmol Extension

If you know a Wiki using the Jmol MediaWiki Extension, please add it in the following list:

How to use the Jmol Extension

Once the Jmol Extension is installed in the Wiki, you can start adding Jmol applets and controls.

Simple usage

Jmol applet in a MediaWiki page

To add a Jmol applet to a MediaWiki page, just add the following:

<jmol>
  <jmolApplet>
    <uploadedFileContents>file uploaded in the wiki containing the molecular data</uploadedFileContents>
  </jmolApplet>
</jmol>

or

<jmol>
  <jmolApplet>
    <wikiPageContents>page of the wiki containing the molecular data</wikiPageContents>
  </jmolApplet>
</jmol>

or

<jmol>
  <jmolApplet>
    <inlineContents>contents of the molecular file</inlineContents>
  </jmolApplet>
</jmol>

or

<jmol>
  <jmolApplet>
    <urlContents>URL of the molecular file</urlContents>
  </jmolApplet>
</jmol>

Controls for the Jmol applet

To add buttons to send scripts to the applet, just add the following:

<jmol>
  <jmolButton>
    <script>script to execute</script>
    <text>text of the button</text>
  </jmolButton>
</jmol>

To add links to send scripts to the applet, just add the following:

<jmol>
  <jmolLink>
    <script>script to execute</script>
    <text>text of the link</text>
  </jmolLink>
</jmol>

To add checkboxes to send scripts to the applet, just add the following:

<jmol>
  <jmolCheckbox>
    <scriptWhenChecked>script to execute when the checkbox is checked</scriptWhenChecked>
    <scriptWhenUnchecked>script to execute when the checkbox is unchecked</scriptWhenUnchecked>
    <text>text of the checkbox</text>
  </jmolCheckbox>
</jmol>

To add radio groups to send scripts to the applet, just add the following:

<jmol>
  <jmolRadioGroup>
    <item>
      <script>script to execute when the radio button is selected</script>
      <text>text of the radio button</text>
    </item>
    <item>
      <script>script to execute when the radio button is selected</script>
      <text>text of the radio button</text>
    </item>
  </jmolRadioGroup>
</jmol>

To add menus to send scripts to the applet, just add the following:

<jmol>
  <jmolMenu>
    <item>
      <script>script to execute when the menu item is selected</script>
      <text>text of the menu item</text>
    </item>
    <item>
      <script>script to execute when the menu item is selected</script>
      <text>text of the menu item</text>
    </item>
  </jmolMenu>
</jmol>

Applets and other controls can be combined in a single <jmol> tag.

Jmol applet in a popup window

To add a button that opens a new window with a Jmol applet, use the <JmolAppletButton> tag instead of the <JmolApplet> tag and also add the <text> tag in it. For example:

<jmol>
  <jmolAppletButton>
    <uploadedFileContents>file uploaded in the wiki containing the molecular data</uploadedFileContents>
    <text>text displayed in the button<text>
  </jmolAppletButton>
</jmol>

To add a link that opens a new window with a Jmol applet, use the <JmolAppletLink> tag instead of the <JmolApplet> tag and also add the <text> tag in it. For example:

<jmol>
  <jmolAppletLink>
    <uploadedFileContents>file uploaded in the wiki containing the molecular data</uploadedFileContents>
    <text>text displayed in the link<text>
  </jmolAppletLink>
</jmol>

Reference

The <jmol> tag can contain the following:

  • <jmolApplet> : Jmol Applet.
    • <signed> (true, false) : On the first Jmol applet to use the signed or unsigned version of the applet. This attribute can be disabled by the Wiki administrator with the $wgJmolAuthorizeChoosingSignedApplet setting in File icon.gifLocalSettings.php.
    • <color> : To change the background color of the Jmol applet.
    • <uploadedFileContents> : Name of an uploaded file in this wiki containing the molecular data to load in the Jmol applet. The Wiki needs to be configured to authorize the upload of molecular data files (using $wgFileExtensions in File icon.gifLocalSettings.php).
    • <wikiPageContents> : Name of a page of this wiki containing the molecular data to load in the Jmol applet.
    • <urlContents> : URL of the molecular file to load. This attribute can be disabled by the Wiki administrator with the $wgJmolAuthorizeUrl setting in File icon.gifLocalSettings.php.
    • <inlineContents> : Molecular data to load in the Jmol applet.
    • <size> : Size of the applet.
    • <script> : Script to execute at startup.
    • <name> : Name of the Jmol applet (useful if you want to use several Jmol applets in the same page).
  • <jmolButton> : Button.
    • <script> : Jmol script to execute when the button is clicked.
    • <text> : Text of the button.
    • <name> : Name of the button.
    • <target> : Name of the Jmol applet linked with the button (useful only if you want to use several Jmol applets in the same page).
  • <jmolLink> : Link. Same tags as <jmolButton>.
  • <jmolCheckbox> : Checkbox.
    • <scriptWhenChecked> : Jmol script to execute when the checkbox is checked.
    • <scriptWhenUnchecked> : Jmol script to execute when the checkbox is unchecked.
    • <checked> (true, false) : Indicates if the checkbox is checked by default.
    • <text> : Text of the button.
    • <name> : Name of the button.
    • <target> : Name of the Jmol applet linked with the button (useful only if you want to use several Jmol applets in the same page).
  • <jmolMenu> : Menu.
    • <item> : Menu item.
      • <script> : Jmol script to execute when the menu item is selected.
      • <text> : Text of the menu item.
      • <checked> (true, false) : Indicates if the menu item is checked.
    • <name> : Name of the menu.
    • <target> : Name of the Jmol applet linked with the menu (useful only if you want to use several Jmol applets in the same page).
    • <menuHeight> : Number of visible menu items (1: combo-box, 2 or greater: list with the specified number of lines, -1: calculated).
  • <jmolRadioGroup> : Radio group.
    • <item> : Radio button.
      • <script> : Jmol script to execute when the radio button is selected.
      • <text> : Text of the radio button.
      • <checked> (true, false) : Indicates if the radio button is checked.
    • <name> : Name of the radio group.
    • <target> : Name of the Jmol applet linked with the radio group (useful only if you want to use several Jmol applets in the same page).
    • <vertical> (true, false) : Indicates if the radio buttons are stacked vertically or horizontally.
  • <jmolAppletButton> : A button for opening a new window with a Jmol Applet. It can contains the same tags as the <jmolApplet> tag, and also the following tags :
    • <text> : Text of the button.
    • <title> : Title of the new window (doesn't work for the moment).
    • <x> and <y> : Position of the new window.
  • <jmolAppletLink> : A link for opening a new window with a Jmol Applet. Same tags as <jmolAppletButton>.

Test Pages

  1. Uploaded XYZ File
  2. Uploaded MDL Molfile
  3. Uploaded CML File

Installation

Download Jmol and extract all the files in a temporary directory.

Create the directory Jmol in $mediawiki/extensions, and copy the following files in it:

  • File icon.gifCOPYRIGHT.txt
  • File icon.gifJmol.js
  • File icon.gifJmolApplet_i18n.jar and File icon.gifJmolApplet0.jar to File icon.gifJmolApplet6.jar
  • File icon.gifJmolAppletSigned_i18n.jar and File icon.gifJmolAppletSigned0.jar to File icon.gifJmolAppletSigned6.jar, if you want to be able to use the signed applet.
  • File icon.gifLICENSE.txt
  • File icon.gifREADME.txt


Add the following line to the end of File icon.gifLocalSettings.php:

require_once('extensions/Jmol/JmolExtension.php');


You can configure the Jmol extension with several settings added after the above line (default value in bold):

  • $wgJmolAuthorizeUrl (true, false) : Authorize the use of <urlContents>.
  • $wgJmolAuthorizeChoosingSignedApplet (true, false) : Authorize users to choose between the unsigned and the signed Jmol applet.
  • $wgJmolDefaultAppletSize (400) : Size in pixels of the Jmol applet.
  • $wgJmolDefaultScript : Default script.
  • $wgJmolExtensionPath : Path to the directory where the Jmol extension is installed.
  • $wgJmolForceNameSpace : Force the NameSpace where the applet will go looking for wiki pages containing molecular data (using <wikiPageContents>).
  • $wgJmolUsingSignedAppletByDefault (true, false) : Choose if the signed Jmol applet will be used by default. Note: the signed Jmol applet is signed with a default certificat. If you want to use the signed Jmol applet in your wiki, I suggest resigning the Jmol applet with your own certificate.


Note: If you want to authorize users to upload files containing molecular data (for using the <uploadedFileContents> tag), you need to do the following:

  • By default, MediaWiki authorizes the uploading of files whose name ends with a limited number of extensions. For example, if you want to authorize uploading File icon.gif*.cml files, add $wgFileExtensions[] = 'cml'; in File icon.gifLocalSettings.php.
  • You can add an icon in the skins/common/images/icons/ directory for each extension (for example, File icon.giffileicon-cml.png). In this wiki, we are using this image, which leads to the following result.


Copy the following code and paste it into File icon.gifextensions/Jmol/JmolMediaWiki.js:

/*
 * Copyright (C) 2006 Nicolas Vervelle,  The Jmol Development Team
 *
 * Contact: nico@jmol.org, jmol-developers@lists.sf.net
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */

function jmolWikiPopupWindow(extensionPath, windowTitle, windowSize, windowLeft, windowTop, windowCode) {
  var windowWidth = parseInt(windowSize) + 15;
  var windowHeight = parseInt(windowSize) + 15;
  var opt = "width=" + windowWidth + "," +
            "height=" + windowHeight + "," +
            "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1," +
            "left=" + windowLeft + ",top=" + windowTop ;
  var s =
    "<html><head>\n" +
    "<script language='Javascript' type='text/javascript' src='" + extensionPath + "/Jmol.js'></script>\n" +
    "<title>" + windowTitle + "</title>\n" +
    "</head><body>" +
    "<script language='Javascript' type='text/javascript'>\n" + windowCode + "\n</script>\n" +
    "</body></html>";

  var w = open("", windowTitle, opt);
  w.document.open();
  w.document.write(s);
  w.document.close();
  w.focus();
}


Copy the following code and paste it into File icon.gifextensions/Jmol/JmolExtension.php:

<?php

/*
 * Copyright (C) 2006 Nicolas Vervelle,  The Jmol Development Team
 *
 * Contact: nico@jmol.org, jmol-developers@lists.sf.net
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
if (defined('MEDIAWIKI')) {

require_once("$IP/includes/Title.php");

global $wgJmolAuthorizeUrl;
global $wgJmolAuthorizeChoosingSignedApplet;
global $wgJmolDefaultAppletSize;
global $wgJmolDefaultScript;
global $wgJmolExtensionPath;
global $wgJmolForceNameSpace;
global $wgJmolUsingSignedAppletByDefault;

/* Global configuration parameters */
$wgJmolAuthorizeUrl = false;
$wgJmolAuthorizeChoosingSignedApplet = false;
$wgJmolDefaultAppletSize = "400";
$wgJmolDefaultScript = "";
$wgJmolExtensionPath = $wgScriptPath."/extensions/Jmol";
$wgJmolForceNameSpace = "";
$wgJmolUsingSignedAppletByDefault = false;

/* Class containing all the code for the Jmol Extension */
$wfJmolReleaseVersion = true;
class JmolExtension {
  var $mOutput, $mDepth;
  var $mCurrentObject, $mCurrentTag, $mCurrentSubTag;

  var $mValChecked;
  var $mValColor;
  var $mValInlineContents;
  var $mValItems;
  var $mValMenuHeight;
  var $mValName;
  var $mValPositionX;
  var $mValPositionY;
  var $mValScript;
  var $mValScriptWhenChecked;
  var $mValScriptWhenUnchecked;
  var $mValSigned;
  var $mValSize;
  var $mValTarget;
  var $mValText;
  var $mValTitle;
  var $mValUploadedFileContents;
  var $mValUrlContents;
  var $mValVertical;
  var $mValWikiPageContents;

  function JmolExtension() {
    $this->mOutput = "";
    $this->mDepth = 0;
    $this->resetValues();
  }

  function renderJmol($input) {
    $this->mOutput = "";
    $this->mDepth = 0;
    $xmlParser = xml_parser_create();
    xml_set_object($xmlParser, $this);
    xml_set_element_handler($xmlParser, "startElement", "endElement");
    xml_set_character_data_handler($xmlParser, "characterData");
    $input = "<jmol>$input<jmol>";
    if (!xml_parse($xmlParser, $input)) {
      die(sprintf(
        "XML error: %s at line %d",
        xml_error_string(xml_get_error_code($xmlParser)),
        xml_get_current_line_number($xmlParser)));
    }
    xml_parser_free($xmlParser);
    return $this->mOutput;
  }

  // Renders a Jmol applet directly in the Wiki page
  function renderJmolApplet() {
    global $wgJmolExtensionPath;

    $this->mValInlineContents = trim($this->mValInlineContents);
    $this->mValInlineContents = preg_replace("/\t/", " ", $this->mValInlineContents);
    $this->mValInlineContents = preg_replace("/\n/", "\\n'+\n'", $this->mValInlineContents);
    $this->mOutput .= "<script language='Javascript' type='text/javascript' src='".$wgJmolExtensionPath."/Jmol.js'></script>\n";
    $this->mOutput .= "<script language='Javascript' type='text/javascript'>\n".
                      $this->renderInternalJmolApplet("'")."\n".
                      "</script>\n";
  }

  // Renders a button in the Wiki page that will open a new window containing a Jmol applet
  function renderJmolAppletButton() {
    global $wgJmolExtensionPath;

    $this->mOutput .= "<script language='Javascript' type='text/javascript' src='".$wgJmolExtensionPath."/JmolMediaWiki.js'></script>\n";
    $this->mOutput .= "<input type='button'";
    if ($this->mValName != "") {
      $this->mOutput .= " name='".$this->mValName."' id='".$this->mValName."'";
    }
    if ($this->mValText == "") {
      $this->mValText = $this->mValTitle;
    }
    if ($this->mValText != "") {
      $this->mOutput .= " value='".$this->mValText."'";
    }
    $this->mOutput .=
      " onclick=\"jmolWikiPopupWindow('".$wgJmolExtensionPath."',".
                                     "'".$this->mValTitle."',".
                                     "'".$this->mValSize."',".
                                     "'".$this->mValPositionX."',".
                                     "'".$this->mValPositionY."',".
                                     "'".$this->renderInternalJmolApplet("\\'")."');return true\"";
    $this->mOutput .= "/>";
  }

  // Renders a button in the Wiki page that will open a new window containing a Jmol applet
  function renderJmolAppletLink() {
    global $wgJmolExtensionPath;

    $this->mOutput .= "<script language='Javascript' type='text/javascript' src='".$wgJmolExtensionPath."/JmolMediaWiki.js'></script>\n";
    $this->mOutput .= "<a";
    if ($this->mValName != "") {
      $this->mOutput .= " name='".$this->mValName."' id='".$this->mValName."'";
    }
    $this->mOutput .=
      " href=\"javascript:jmolWikiPopupWindow('".$wgJmolExtensionPath."',".
                                             "'".$this->mValTitle."',".
                                             "'".$this->mValSize."',".
                                             "'".$this->mValPositionX."',".
                                             "'".$this->mValPositionY."',".
                                             "'".$this->renderInternalJmolApplet("\\'")."');\"";
    $this->mOutput .= ">";
    if ($this->mValText == "") {
      $this->mValText = $this->mValTitle;
    }
    if ($this->mValText != "") {
      $this->mOutput .= $this->mValText;
    }
    $this->mOutput .= "</a>";
  }

  // Renders a button to control a Jmol applet
  function renderJmolButton() {
    $this->mOutput .= "<script language='Javascript' type='text/javascript'>\n";
    if ($this->mValTarget != "") {
      $this->mOutput .= "jmolSetTarget('".$this->mValTarget."');\n";
    }
    $this->mOutput .=
      "jmolButton('".$this->mValScript."','".$this->mValText."'";
    if ($this->mValName != "") {
      $this->mOutput .= ",'".$this->mValName."'";
    }
    $this->mOutput .= ");\n".
      "</script>\n";
  }

  // Renders a checkbox to control a Jmol applet
  function renderJmolCheckbox() {
    $this->mOutput .= "<script language='Javascript' type='text/javascript'>\n";
    if ($this->mValTarget != "") {
      $this->mOutput .= "jmolSetTarget('".$this->mValTarget."');\n";
    }
    $this->mOutput .=
      "jmolCheckbox('".$this->mValScriptWhenChecked."',".
                   "'".$this->mValScriptWhenUnchecked."',".
                   "'".$this->mValText."'";
    if ($this->mValChecked) {
      $this->mOutput .= ",true";
    } else {
      $this->mOutput .= ",false";
    }
    if ($this->mValName != "") {
      $this->mOutput .= ",'".$this->mValName."'";
    }
    $this->mOutput .= ");\n".
      "</script>\n";
  }

  // Renders a link to control a Jmol applet
  function renderJmolLink() {
    $this->mOutput .= "<script language='Javascript' type='text/javascript'>\n";
    if ($this->mValTarget != "") {
      $this->mOutput .= "jmolSetTarget('".$this->mValTarget."');\n";
    }
    $this->mOutput .=
      "jmolLink('".$this->mValScript."','".$this->mValText."'";
    if ($this->mValName != "") {
      $this->mOutput .= ",'".$this->mValName."'";
    }
    $this->mOutput .= ");\n".
      "</script>\n";
  }

  // Renders a menu to control a Jmol applet
  function renderJmolMenu() {
    $this->mOutput .= "<script language='Javascript' type='text/javascript'>\n";
    if ($this->mValTarget != "") {
      $this->mOutput .= "jmolSetTarget('".$this->mValTarget."');\n";
    }
    $this->mOutput .=
      "jmolMenu([".$this->mValItems."],".$this->mValMenuHeight;
    if ($this->mValName != "") {
      $this->mOutput .= ",'".$this->mValName."'";
    }
    $this->mOutput .= ");\n".
      "</script>\n";
  }

  // Renders a radio group to control a Jmol applet
  function renderJmolRadioGroup() {
    $this->mOutput .= "<script language='Javascript' type='text/javascript'>\n";
    if ($this->mValTarget != "") {
      $this->mOutput .= "jmolSetTarget('".$this->mValTarget."');\n";
    }
    $this->mOutput .=
      "jmolRadioGroup([".$this->mValItems."]";
    if ($this->mValVertical) {
      $this->mOutput .= ",jmolBr()";
    } else {
      $this->mOutput .= ",' '";
    }
    if ($this->mValName != "") {
      $this->mOutput .= ",'".$this->mValName."'";
    }
    $this->mOutput .= ");\n".
      "</script>\n";
  }

  // Internal function to make a Jmol applet
  function renderInternalJmolApplet($sep) {
    global $wgJmolAuthorizeUrl, $wgJmolForceNameSpace;
    global $wgJmolExtensionPath;
    $output = "";

    if ($this->mValSigned) {
      $output .= "jmolInitialize(".$sep.$wgJmolExtensionPath.$sep.", true);";
    } else {
      $output .= "jmolInitialize(".$sep.$wgJmolExtensionPath.$sep.", false);";
    }
    $output .=
      "jmolCheckBrowser(".$sep."popup".$sep.", ".$sep.$wgJmolExtensionPath."/browsercheck".$sep.", ".$sep."onClick".$sep.");".
      "jmolSetAppletColor(".$sep.$this->mValColor.$sep.");";
    if ($this->mValUploadedFileContents != "") {
      $title = Title::makeTitleSafe(NS_IMAGE, $this->mValUploadedFileContents);
      $article = new Article($title);
      if (!is_null($title) && $article->exists()) {
        $file = new Image($title);
        $this->mValUrlContents = $file->getURL();
      }
    }
    if ($this->mValWikiPageContents != "") {
      $this->mValUrlContents = "/index.php?title=";
      if ($wgJmolForceNameSpace != "") {
        $this->mValUrlContents .= $wgJmolForceNameSpace.":";
      }
      $this->mValUrlContents .= $this->mValWikiPageContents."&action=raw";
    }
    if (($this->mValUrlContents != "") && ($wgJmolAuthorizeUrl == true)) {
      $output .=
        "jmolApplet(".$this->mValSize.", ".
                    $sep."load ".$this->mValUrlContents."; ".$this->mValScript.$sep;
    } else {
      $output .=
        "jmolAppletInline(".$this->mValSize.", ".
                          $sep.$this->mValInlineContents.$sep.", ".
                          $sep.$this->mValScript.$sep;
    }
    if ($this->mValName != "") {
      $output .= ",".$sep.$this->mValName.$sep;
    }
    $output .=
      ");".
      "jmolBr();";

    return $output;
  }

  // Function called when an opening XML tag is found
  function startElement($parser, $name, $attrs) {
    $this->mDepth += 1;
    switch ($this->mDepth) {
    case 1:
      // JMOL tag itself
      $this->resetValues();
      break;
    case 2:
      // The interesting tags
      $this->resetValues();
      $this->mCurrentObject = $name;
      break;
    case 3:
      // Details of the interesting tags
      $this->mCurrentTag = $name;
      break;
    case 4:
      // Details of sub tags
      $this->mCurrentSubTag = $name;
      break;
    }
  }

  // Function called when a closing XML tag is found
  function endElement($parser, $name) {
    switch ($this->mDepth) {
    case 1:
      // JMOL tag itself
      $this->resetValues();
      break;
    case 2:
      // The interesting tags
      switch ($this->mCurrentObject) {
      case "JMOLAPPLET":
        $this->renderJmolApplet();
        break;
      case "JMOLAPPLETBUTTON":
        $this->renderJmolAppletButton();
        break;
      case "JMOLAPPLETLINK":
        $this->renderJmolAppletLink();
        break;
      case "JMOLBUTTON":
        $this->renderJmolButton();
        break;
      case "JMOLCHECKBOX":
        $this->renderJmolCheckbox();
        break;
      case "JMOLLINK":
        $this->renderJmolLink();
        break;
      case "JMOLMENU":
        $this->renderJmolMenu();
        break;
      case "JMOLRADIOGROUP":
        $this->renderJmolRadioGroup();
        break;
      }
      $this->resetValues();
      break;
    case 3:
      // Details of the interesting tags
      switch ($this->mCurrentTag) {
      case "ITEM":
        if ($this->mValItems != "") {
          $this->mValItems .= ",";
        }
        $this->mValItems .= "['".$this->mValScript."'";
        $this->mValItems .= ",'".$this->mValText."'";
        if ($this->mValChecked) {
          $this->mValItems .= ",true]";
        } else {
          $this->mValItems .= ",false]";
        }
        break;
      }
      $this->mCurrentTag = "";
      break;
    case 4:
      // Details of sub tags
      $this->mCurrentSubTag = "";
      break;
    }
    $this->mDepth -= 1;
  }

  // Function called for the content of a XML tag
  function characterData($parser, $data) {
    global $wgJmolAuthorizeChoosingSignedApplet;
    
    switch ($this->mDepth) {
    case 3:
      // Details of the interesting tags
      switch ($this->mCurrentTag) {
      case "CHECKED":
        $this->mValChecked = $data;
        break;
      case "COLOR":
        $this->mValColor = $data;
        break;
      case "INLINECONTENTS":
      case "ONLINECONTENTS":
        $data = trim($data);
        if ($data != "") {
          $this->mValInlineContents .= "\n" . $data;
        }
        break;
      case "MENUHEIGHT":
        $this->mValMenuHeight = $data;
        break;
      case "NAME":
        $this->mValName = $data;
        break;
      case "SCRIPT":
        $this->mValScript = $data;
        break;
      case "SCRIPTWHENCHECKED":
        $this->mValScriptWhenChecked = $data;
        break;
      case "SCRIPTWHENUNCHECKED":
        $this->mValScriptWhenUnchecked = $data;
        break;
      case "SIGNED":
        if ($wgJmolAuthorizeChoosingSignedApplet) {
          $this->mValSigned = $data;
        }
        break;
      case "SIZE":
        $this->mValSize = $data;
        break;
      case "TARGET":
        $this->mValTarget = $data;
        break;
      case "TEXT":
        $this->mValText = $data;
        break;
      case "TITLE":
        $this->mValTitle = $data;
        break;
      case "UPLOADEDFILECONTENTS":
        $this->mValUploadedFileContents = $data;
        break;
      case "URLCONTENTS":
        $this->mValUrlContents = $data;
        break;
      case "VERTICAL":
        $this->mValVertical = $data;
        break;
      case "WIKIPAGECONTENTS":
        $this->mValWikiPageContents = $data;
        break;
      case "X":
        $this->mValPositionX = $data;
        break;
      case "Y":
        $this->mValPositionY = $data;
        break;
      }
      break;
    case 4:
      // Details of sub tags
      if ($this->mCurrentTag == "ITEM") {
        switch ($this->mCurrentSubTag) {
        case "CHECKED":
          $this->mValChecked = $data;
          break;
        case "SCRIPT":
          $this->mValScript = $data;
          break;
        case "TEXT":
          $this->mValText = $data;
          break;
        }
      }
      break;
    }
  }

  // Resets internal variables to their default values
  function resetValues() {
    global $wgJmolDefaultAppletSize;
    global $wgJmolDefaultScript;
    global $wgJmolUsingSignedAppletByDefault;
    
    $this->mCurrentObject = "";
    $this->mCurrentTag = "";
    $this->mCurrentSubTag = "";

    $this->mValChecked = false;
    $this->mValColor = "black";
    $this->mValInlineContents = "";
    $this->mValItems = "";
    $this->mValMenuHeight = "1";
    $this->mValName = "";
    $this->mValPositionX = "100";
    $this->mValPositionY = "100";
    $this->mValScript = $wgJmolDefaultScript;
    $this->mValScriptWhenChecked = "";
    $this->mValScriptWhenUnchecked = "";
    $this->mValSigned = $wgJmolUsingSignedAppletByDefault;
    $this->mValSize = $wgJmolDefaultAppletSize;
    $this->mValTarget = "";
    $this->mValText = "";
    $this->mValTitle = "Jmol";
    $this->mValUploadedFileContents = "";
    $this->mValUrlContents = "";
    $this->mValVertical = false;
    $this->mValWikiPageContents = "";
  }
};

// Enables to have a Release and Development versions running simultaneously
if ($wfJmolReleaseVersion) {
  $wgExtensionFunctions[] = "wfJmolExtension";

  $wgJmolExtension = new JmolExtension;

  $wgExtensionCredits['other'][] = array(
    'name'        => 'Jmol Extension for MediaWiki',
    'description' => 'adds the possibility to include Jmol applets in MediaWiki.',
    'author'      => 'Nicolas Vervelle, Jmol Development Team',
    'url'         => 'http://wiki.jmol.org/index.php/MediaWiki'
  );

  function wfJmolExtension() {
    global $wgParser;
    $wgParser->setHook( "jmol", "wfRenderJmol" );
  }

  function wfRenderJmol($input) {
    global $wgJmolExtension;
    return $wgJmolExtension->renderJmol($input);
  }
} else {
  $wgExtensionFunctions[] = "wfJmolDevExtension";

  $wgJmolDevExtension = new JmolDevExtension;

  $wgExtensionCredits['other'][] = array(
    'name'        => 'Jmol Development Extension for MediaWiki',
    'description' => 'adds the possibility to include Jmol applets in MediaWiki.',
    'author'      => 'Nicolas Vervelle, Jmol Development Team',
    'url'         => 'http://wiki.jmol.org/index.php/MediaWiki'
  );

  function wfJmolDevExtension() {
    global $wgParser;
    $wgParser->setHook( "jmolDev", "wfRenderJmolDev" );
  }

  function wfRenderJmolDev($input) {
    global $wgJmolDevExtension;
    return $wgJmolDevExtension->renderJmol($input);
  }
}

}
?>


External links