Extension:UnityEmbed
![]() | This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net . |
![]() | This extension is currently not actively maintained! Although it may still work, any bug reports or feature requests will more than likely be ignored. |
![]() Release status: unmaintained |
|
---|---|
Implementation | Parser extension |
Description | Allows the display of unity games on a wiki page |
Author(s) | Jon Hunter (Jhunter13talk) |
Latest version | 1.0 (2013-01-15) |
MediaWiki | |
Database changes | No |
License | GNU public License |
Download | see here |
<unity> |
|
The UnityEmbed extension allows users to embed Unity 3D games on their wiki. You will need to upload the webplayer unity3d file to the wiki in order for the game to embed correctly on the page.
Usage[edit]
Once installed you can use the <unity>
tag on any wiki page in this format:
<unity>file=myLocalFile.unity3d|width=550|height=400</unity>
Installation[edit]
To install this extension, add the following to LocalSettings.php:
require_once ("$IP/extensions/unity.php");
Code[edit]
Paste the following code into a file called unity.php in your extensions folder:
<?php
/*
* Embed a Unity 3D Game file.
*
* To activate this extension, add the following into your LocalSettings.php file:
* require_once('$IP/extensions/unity.php');
*
*/
$wgExtensionCredits['parserhook'][] = array(
'name' => 'Unity Embed',
'author' => 'Jon Hunter',
'version'=>'1.0',
'description' => 'Allows the display of unity games on a wiki page using the <code><unity></code> tag',
'url' => 'https://www.mediawiki.org/wiki/Extension:UnityEmbed',
);
$wgExtensionFunctions[] = "wfUnityExtension";
class Unity{
/* Constructor */
function Unity( $input ) {
Unity::parseInput( $input ); // Parse the input
Unity::genCode(); // Generate the final code
}
function parseInput( $input ) {
for($pos=0; $pos<strlen($input); $pos++) { // go through all arguments
if($input{$pos}=='=') { // separator between command
$this->instr = $this->tmp;
$this->tmp = '';
}
else if($input{$pos}=='|') {// separator between arguments
Unity::setValue();
$this->tmp='';
}
else{
$this->tmp .= $input{$pos};
}
}
if($this->tmp!='') Unity::setValue(); // Deal with the rest of the input string
}
function setValue() {
if($this->instr=='file'|| // Whitelist of flash commands. Anything else but flash commands is ignored.
$this->instr=='width'||
$this->instr=='height') {
$this->{$this->instr} = $this->tmp;
}
}
function genCode(){
$title = wfLocalFile(Title::newFromText(trim($this->file), NS_FILE));
if($title){
$url = $title->getFullURL();
$this->code = '<object id="UnityObject" classid="clsid:444785F1-DE89-4295-863A-D46C3A781394" width="'.$this->width.'" height="'.$this->height.'" codebase="http://webplayer.unity3d.com/download_webplayer/UnityWebPlayer.cab#version=2,0,0,0"><param name="'.$url.'" value="WebPlayer.unity3d" /><embed id="UnityEmbed" src="'.$url.'" width="'.$this->width.'" height="'.$this->height.'" type="application/vnd.unity" pluginspage="http://www.unity3d.com/unity-web-player-2.x" /></object><br>';
return $this->code;
}
}
}
function wfUnityExtension() {
global $wgParser;
$wgParser->setHook( "unity", "renderUnity" );
}
function renderUnity( $input ) {
$game = new Unity( $input );//creates a unity object
return $game->code; // send the final code to the wiki
}
Check if the extension was installed correctly by going to Special:Version, if you see "Unity Embed" under the Parser Hooks section of the page you've installed it correctly.