Extension:Embed3DMLW
From MediaWiki.org
(Redirected from Extension:Embed3DWML)
|
Embed3DMLW Release status: beta |
|
|---|---|
| Implementation | Tag |
| Description | This extension will embed 3d objects (*.3ds, *.obj, ...) defined in 3dmlw file inside a MediaWiki page. |
| Author(s) | 3D Technologies |
| Last version | 0.1.0 |
| MediaWiki | 1.6.x, 1.9.x, 1.10.x or higher |
| License | The MIT License |
| Download | see below |
| Example | Screenshot.jpg|600|400|Player Title}} |
|
Check usage (experimental) |
|
Contents |
[edit] Purpose
The Embed3DMLW MediaWiki Extension will show 3dmlw files embedded inside a MediaWiki page.
[edit] Usage
{{#3d:3DFile.3dmlw}}
{{#3d:3DFile.3dmlw|Screenshot.jpg|600|400|Player Title}}
{{#3d:http://mydomain/3DFile.3dmlw%7CScreenshot.jpg%7C600%7C400%7CPlayer Title}}
Note: Numbers 600 and 400 are width and height of player, Screenshot.jpg is default image which user will see if there is not installed player plugin
[edit] Installation
- Copy the code into
extensions/Embeded3D.php - Add
intorequire_once("$IP/extensions/Embeded3D.php");
LocalSettings.php
[edit] Code
<?php $wgExtensionCredits['parserhook'][] = array( 'name'=>'Embeded3D', 'author'=>'3D Technologies R & D', 'url'=>'', 'description'=>'Allows ebmeding of 3dmlw objects in wiki page.', 'version'=>'0.1.0' ); /* Global Actions */ $wgEmbed3D = new Embeded3D(); $wgExtensionFunctions[] = array($wgEmbed3D, 'setup'); $wgEmbed3dmlw_MinWidth = 100; $wgEmbed3dmlw_MaxWidth = 800; if (version_compare($wgVersion, '1.7', '<')) { function wfEmbed3DLanguageGetMagic( &$magicWords ) { global $wgEmbed3D; $wgEmbed3D->parserFunctionMagic( $magicWords ); return true; } $wgHooks['LanguageGetMagic'][] = 'wfEmbed3DLanguageGetMagic'; } else { $wgHooks['LanguageGetMagic'][] = array($wgEmbed3D, 'parserFunctionMagic'); } /* Constructor */ class Embeded3D { function setup() { /* Setup hook */ global $wgParser, $wgVersion; $hook = (version_compare($wgVersion, '1.7', '<')?'#3d':'3d'); $wgParser->setFunctionHook( $hook, array($this, 'parserFunction') ); /*Create Messages*/ global $wgMessageCache; $wgMessageCache->addMessage('embed3d-missing-params', 'Missing a required parameter.'); $wgMessageCache->addMessage('embed3d-width', 'Wrong width parameter "$1".'); $wgMessageCache->addMessage('embed3d-embed-text', '<div style="position: relative;">'. '<object classid="clsid:A3F45AE8-DEDE-4B21-BBFB-0EC7724E06EC" id="3DMLW_plugin" '. 'type="text/3dmlw" codebase="http://www.3dmlw.com/download/3dmlw_installer.exe" '. 'height="$4" width="$3"><param name="source" value="$1">'. '<embed id="3DMLW_plugin2" source="$1" type="text/3dmlw" '. 'pluginspage="http://www.3dmlw.com/download/3dmlw_installer.exe" '. 'height="$4" width="$3"></embed></object>$5 $6'. '</div>' ); $wgMessageCache->addMessage('embed3d-alt-text', '<img style="position:absolute; top: 0px; left:0px; width:$1px; height:$2px" width="$1" height="$2" src="$3" />' ); } function parserFunctionMagic( &$magicWords, $langCode='en' ) { $magicWords['3d'] = array( 0, '3d' ); return true; } function parserFunction( $parser, $filename=null, $alternative=null, $width = null, $height = null, $title = null ) { global $wgEmbed3dmlw_MinWidth, $wgEmbed3dmlw_MaxWidth; if ($filename===null) return '<div class="errorbox">'.wfMsg('embed3d-missing-params').'</div>'; if (!is_numeric($wgEmbed3dmlw_MinWidth) || $wgEmbed3dmlw_MinWidth<100) $wgEmbed3dmlw_MinWidth = 100; if (!is_numeric($wgEmbed3dmlw_MaxWidth) || $wgEmbed3dmlw_MaxWidth>1024) $wgEmbed3dmlw_MaxWidth = 1024; $params = array( 'filename' => trim($filename), 'image' => trim($alternative), 'width' => ($width===null ? 600 : trim($width)), 'height' => ($height===null ? 400 : trim($height)), 'title' => trim($title) ); if(strstr($filename,'http://') == $filename){ $params['filename'] = $filename; } else { $params['filename'] = $this->getViewPath($filename); $filename = $this->getViewPath($filename); } if(strstr($alternative,'http://') == $alternative){ $params['image'] = $alternative; } else { $params['image'] = $this->getViewPath($alternative); $image = $this->getViewPath($alternative); } $ratio = 600 / 400; $width = 600; if ($params['width'] !== null) { if (!is_numeric($params['width']) || $params['width'] < $wgEmbed3dmlw_MinWidth || $params['width'] > $wgEmbed3dmlw_MaxWidth) return '<div class="errorbox">'. wfMsgForContent('embed3d-width', @htmlspecialchars($params['width'])) . '</div>'; $width = $params['width']; } if ($params['height'] == null || !is_numeric($params['height']) ) { $height = round($width / $ratio); } else { $height = $params['height']; } $alternative_text = ''; if($image) { $alternative_text = wfMsgForContent('embed3d-alt-text', $width, $height, $image); } if($title) { $title = '<p>'.$title.'</p>'; } return $parser->insertStripItem(wfMsgForContent('embed3d-embed-text', $filename, $alternative, $width, $height, $alternative_text, $title), $parser->mStripState); } /* get file url */ function getViewPath($file) { $title = Title::makeTitleSafe("Image",$file); $img = new Image($title); $path = $img->getFullUrl(true); return $path; } } ?>
