Difference between revisions of "MediaWiki"
(Working on Jmol extension) |
|||
Line 1: | Line 1: | ||
+ | __TOC__ | ||
+ | == Description == | ||
+ | |||
[http://www.mediawiki.org/ MediaWiki] is an open source wiki engine licensed under the [http://www.gnu.org/copyleft/gpl.html GNU General Public License]. It is used by [[metawikipedia:Sites_using_MediaWiki|many websites]], including this one. | [http://www.mediawiki.org/ MediaWiki] is an open source wiki engine licensed under the [http://www.gnu.org/copyleft/gpl.html GNU General Public License]. It is used by [[metawikipedia:Sites_using_MediaWiki|many websites]], including this one. | ||
+ | The Jmol Mediawiki Extension enables the use of the Jmol applet inside of Mediawiki pages. | ||
+ | |||
+ | == Installation == | ||
+ | |||
+ | [http://www.jmol.org/files/ Download Jmol] and extract all the files in a temporary directory. | ||
+ | |||
+ | Create the directory <tt>Jmol</tt> in <tt>$mediawiki/extensions</tt>, and copy the following files in it: | ||
+ | * <tt>COPYRIGHT.txt</tt> | ||
+ | * <tt>Jmol.js</tt> | ||
+ | * <tt>JmolApplet_i18n.jar</tt> | ||
+ | * <tt>JmolApplet0.jar</tt> | ||
+ | * <tt>JmolApplet1.jar</tt> | ||
+ | * <tt>JmolApplet2.jar</tt> | ||
+ | * <tt>JmolApplet3.jar</tt> | ||
+ | * <tt>JmolApplet4.jar</tt> | ||
+ | * <tt>JmolApplet5.jar</tt> | ||
+ | * <tt>JmolApplet6.jar</tt> | ||
+ | * <tt>LICENSE.txt</tt> | ||
+ | * <tt>README.txt</tt> | ||
+ | |||
+ | Add the following line to the end of <tt>LocalSettings.php</tt>: | ||
+ | require_once('extensions/Jmol/JmolExtension.php'); | ||
+ | |||
+ | Copy the following code and paste it into <tt>extensions/Jmol/JmolExtension.php</tt>: | ||
+ | |||
+ | <pre><?php | ||
+ | $wgExtensionFunctions[] = "wfJmolExtension"; | ||
+ | $currentTag = ""; | ||
+ | $appletContents = ""; | ||
+ | $appletScript = ""; | ||
+ | $appletName = ""; | ||
+ | $appletSize = ""; | ||
+ | $appletColor = ""; | ||
+ | $appletText = ""; | ||
+ | |||
+ | function wfJmolExtension() { | ||
+ | global $wgParser; | ||
+ | $wgParser->setHook( "jmol", "renderJmol" ); | ||
+ | $wgParser->setHook( "jmolButton", "renderJmolButton" ); | ||
+ | } | ||
+ | |||
+ | function startElement( $parser, $name, $attrs ) { | ||
+ | global $currentTag; | ||
+ | |||
+ | $currentTag = $name; | ||
+ | } | ||
+ | |||
+ | function endElement( $parser, $name ) { | ||
+ | global $currentTag; | ||
+ | |||
+ | $currentTag = ""; | ||
+ | } | ||
+ | |||
+ | function characterData( $parser, $data ) { | ||
+ | global $currentTag; | ||
+ | global $appletContents; | ||
+ | global $appletScript; | ||
+ | global $appletName; | ||
+ | global $appletSize; | ||
+ | global $appletColor; | ||
+ | global $appletText; | ||
+ | |||
+ | switch ($currentTag) { | ||
+ | case "CONTENTS": | ||
+ | $data = trim($data); | ||
+ | if ($data != "") { | ||
+ | $appletContents = $appletContents . "\n" . $data; | ||
+ | } | ||
+ | break; | ||
+ | case "SCRIPT": | ||
+ | $appletScript = $data; | ||
+ | break; | ||
+ | case "NAME": | ||
+ | $appletName = $data; | ||
+ | break; | ||
+ | case "SIZE": | ||
+ | $appletSize = $data; | ||
+ | break; | ||
+ | case "COLOR": | ||
+ | $appletColor = $data; | ||
+ | break; | ||
+ | case "TEXT": | ||
+ | $appletText = $data; | ||
+ | break; | ||
+ | default: | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | function renderJmol( $input ) { | ||
+ | global $appletContents; | ||
+ | global $appletScript; | ||
+ | global $appletName; | ||
+ | global $appletSize; | ||
+ | global $appletColor; | ||
+ | |||
+ | resetValues(); | ||
+ | $xmlParser = xml_parser_create(); | ||
+ | xml_set_element_handler($xmlParser, "startElement", "endElement"); | ||
+ | xml_set_character_data_handler($xmlParser, "characterData"); | ||
+ | $input = "<jmolApplet>$input<jmolApplet>"; | ||
+ | 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($xml_parser); | ||
+ | $appletContents = trim($appletContents); | ||
+ | $appletContents = preg_replace("/\t/", " ", $appletContents); | ||
+ | $appletContents = preg_replace("/\n/", "\\n'+\n'", $appletContents); | ||
+ | $output = $output . | ||
+ | "<script src='./extensions/jmol/Jmol.js'></script>\n". | ||
+ | "<script>\n" . | ||
+ | "jmolInitialize('./extensions/jmol');\n". | ||
+ | "jmolCheckBrowser('popup', './extensions/jmol/browsercheck', 'onClick');\n". | ||
+ | "jmolSetAppletColor('$appletColor');\n". | ||
+ | "jmolAppletInline($appletSize, \n'$appletContents', \n'$appletScript', \n'$appletName');\n" . | ||
+ | "jmolBr();\n" . | ||
+ | "</script>\n" | ||
+ | ; | ||
+ | return $output; | ||
+ | } | ||
+ | |||
+ | function renderJmolButton( $input ) { | ||
+ | global $appletScript; | ||
+ | global $appletName; | ||
+ | global $appletText; | ||
+ | |||
+ | resetValues(); | ||
+ | $xmlParser = xml_parser_create(); | ||
+ | xml_set_element_handler($xmlParser, "startElement", "endElement"); | ||
+ | xml_set_character_data_handler($xmlParser, "characterData"); | ||
+ | $input = "<jmolApplet>$input<jmolApplet>"; | ||
+ | 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($xml_parser); | ||
+ | $output = $output . | ||
+ | "<script>\n" . | ||
+ | "jmolSetTarget('$appletName');\n" . | ||
+ | "jmolButton('$appletScript', '$appletText');\n" . | ||
+ | "</script>\n" | ||
+ | ; | ||
+ | return $output; | ||
+ | } | ||
+ | |||
+ | function resetValues() { | ||
+ | global $currentTag; | ||
+ | global $appletContents; | ||
+ | global $appletScript; | ||
+ | global $appletName; | ||
+ | global $appletSize; | ||
+ | global $appletColor; | ||
+ | |||
+ | $currentTag = ""; | ||
+ | $appletContents = ""; | ||
+ | $appletScript = "set spin Y 10; spin on"; | ||
+ | $appletName = "FahWiki"; | ||
+ | $appletSize = "400"; | ||
+ | $appletColor = "black"; | ||
+ | $appletText = ""; | ||
+ | } | ||
+ | |||
+ | ?></pre> | ||
+ | |||
+ | |||
+ | |||
+ | ----- | ||
The description of Jmol Mediawiki Extension can be found [[metawikipedia:User:NicoV/Jmol_Extension|here]]. | The description of Jmol Mediawiki Extension can be found [[metawikipedia:User:NicoV/Jmol_Extension|here]]. | ||
Revision as of 20:01, 3 April 2006
Contents
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.
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:
- COPYRIGHT.txt
- Jmol.js
- JmolApplet_i18n.jar
- JmolApplet0.jar
- JmolApplet1.jar
- JmolApplet2.jar
- JmolApplet3.jar
- JmolApplet4.jar
- JmolApplet5.jar
- JmolApplet6.jar
- LICENSE.txt
- README.txt
Add the following line to the end of LocalSettings.php:
require_once('extensions/Jmol/JmolExtension.php');
Copy the following code and paste it into extensions/Jmol/JmolExtension.php:
<?php $wgExtensionFunctions[] = "wfJmolExtension"; $currentTag = ""; $appletContents = ""; $appletScript = ""; $appletName = ""; $appletSize = ""; $appletColor = ""; $appletText = ""; function wfJmolExtension() { global $wgParser; $wgParser->setHook( "jmol", "renderJmol" ); $wgParser->setHook( "jmolButton", "renderJmolButton" ); } function startElement( $parser, $name, $attrs ) { global $currentTag; $currentTag = $name; } function endElement( $parser, $name ) { global $currentTag; $currentTag = ""; } function characterData( $parser, $data ) { global $currentTag; global $appletContents; global $appletScript; global $appletName; global $appletSize; global $appletColor; global $appletText; switch ($currentTag) { case "CONTENTS": $data = trim($data); if ($data != "") { $appletContents = $appletContents . "\n" . $data; } break; case "SCRIPT": $appletScript = $data; break; case "NAME": $appletName = $data; break; case "SIZE": $appletSize = $data; break; case "COLOR": $appletColor = $data; break; case "TEXT": $appletText = $data; break; default: break; } } function renderJmol( $input ) { global $appletContents; global $appletScript; global $appletName; global $appletSize; global $appletColor; resetValues(); $xmlParser = xml_parser_create(); xml_set_element_handler($xmlParser, "startElement", "endElement"); xml_set_character_data_handler($xmlParser, "characterData"); $input = "<jmolApplet>$input<jmolApplet>"; 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($xml_parser); $appletContents = trim($appletContents); $appletContents = preg_replace("/\t/", " ", $appletContents); $appletContents = preg_replace("/\n/", "\\n'+\n'", $appletContents); $output = $output . "<script src='./extensions/jmol/Jmol.js'></script>\n". "<script>\n" . "jmolInitialize('./extensions/jmol');\n". "jmolCheckBrowser('popup', './extensions/jmol/browsercheck', 'onClick');\n". "jmolSetAppletColor('$appletColor');\n". "jmolAppletInline($appletSize, \n'$appletContents', \n'$appletScript', \n'$appletName');\n" . "jmolBr();\n" . "</script>\n" ; return $output; } function renderJmolButton( $input ) { global $appletScript; global $appletName; global $appletText; resetValues(); $xmlParser = xml_parser_create(); xml_set_element_handler($xmlParser, "startElement", "endElement"); xml_set_character_data_handler($xmlParser, "characterData"); $input = "<jmolApplet>$input<jmolApplet>"; 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($xml_parser); $output = $output . "<script>\n" . "jmolSetTarget('$appletName');\n" . "jmolButton('$appletScript', '$appletText');\n" . "</script>\n" ; return $output; } function resetValues() { global $currentTag; global $appletContents; global $appletScript; global $appletName; global $appletSize; global $appletColor; $currentTag = ""; $appletContents = ""; $appletScript = "set spin Y 10; spin on"; $appletName = "FahWiki"; $appletSize = "400"; $appletColor = "black"; $appletText = ""; } ?>
The description of Jmol Mediawiki Extension can be found here.
The source code of the current version of the extension (development version) is :
<?php $wgExtensionFunctions[] = "wfJmolExtensionDevelop"; $currentTag = ""; $appletContents = ""; $appletScript = ""; $appletName = ""; $appletSize = ""; $appletColor = ""; $appletText = ""; function wfJmolExtensionDevelop() { global $wgParser; $wgParser->setHook( "jmolDevelop", "renderJmolDevelop" ); $wgParser->setHook( "jmolButton", "renderJmolButton" ); } function startElement( $parser, $name, $attrs ) { global $currentTag; $currentTag = $name; } function endElement( $parser, $name ) { global $currentTag; $currentTag = ""; } function characterData( $parser, $data ) { global $currentTag; global $appletContents; global $appletScript; global $appletName; global $appletSize; global $appletColor; global $appletText; switch ($currentTag) { case "CONTENTS": $data = trim($data); if ($data != "") { $appletContents = $appletContents . "\n" . $data; } break; case "SCRIPT": $appletScript = $data; break; case "NAME": $appletName = $data; break; case "SIZE": $appletSize = $data; break; case "COLOR": $appletColor = $data; break; case "TEXT": $appletText = $data; break; default: break; } } function renderJmolDevelop( $input ) { global $appletContents; global $appletScript; global $appletName; global $appletSize; global $appletColor; resetValues(); $xmlParser = xml_parser_create(); xml_set_element_handler($xmlParser, "startElement", "endElement"); xml_set_character_data_handler($xmlParser, "characterData"); $input = "<jmolApplet>$input<jmolApplet>"; 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($xml_parser); $appletContents = trim($appletContents); $appletContents = preg_replace("/\t/", " ", $appletContents); $appletContents = preg_replace("/\n/", "\\n'+\n'", $appletContents); $output = $output . "<script src='./extensions/jmol/Jmol.js'></script>\n". "<script>\n" . "jmolInitialize('./extensions/jmol');\n". "jmolCheckBrowser('popup', './extensions/jmol/browsercheck', 'onClick');\n". "jmolSetAppletColor('$appletColor');\n". "jmolAppletInline($appletSize, \n'$appletContents', \n'$appletScript', \n'$appletName');\n" . "jmolBr();\n" . "</script>\n" ; return $output; } function renderJmolButton( $input ) { global $appletScript; global $appletName; global $appletText; resetValues(); $xmlParser = xml_parser_create(); xml_set_element_handler($xmlParser, "startElement", "endElement"); xml_set_character_data_handler($xmlParser, "characterData"); $input = "<jmolApplet>$input<jmolApplet>"; 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($xml_parser); $output = $output . "<script>\n" . "jmolSetTarget('$appletName');\n" . "jmolButton('$appletScript', '$appletText');\n" . "</script>\n" ; return $output; } function resetValues() { global $currentTag; global $appletContents; global $appletScript; global $appletName; global $appletSize; global $appletColor; $currentTag = ""; $appletContents = ""; $appletScript = "set spin Y 10; spin on"; $appletName = "FahWiki"; $appletSize = "400"; $appletColor = "black"; $appletText = ""; } ?>
Contributors
AngelHerraez, NicolasVervelle, Rzepa, Mevans86, Ngreeves, Pimpim, SklogWiki, Jacksmind, EricMartz