Extension:Silverlight
From MediaWiki.org
|
silverlight Release status: beta |
|
|---|---|
| Implementation | Tag |
| Description | This extension allows the display of silverlight content within a wiki. |
| License | GPL |
| Download | No link |
|
Check usage (experimental) |
|
Contents |
[edit] Usage
<silverlight[attributes]>filename.xap</silverlight>
[edit] Attribute Reference
- width=px (Modify the width of the object)
- height=px (Modify the height of the object)
[edit] Examples
Using Hyperlink:
<silverlight width="800" height="400">http://www.eclipse4sl.org/demo/Test.xap</silverlight>
Using local uploaded file:
<silverlight width="800" height="400">Test.xap</silverlight>
[edit] Download instructions
Please cut and paste the code found below and place it in $IP/extensions/ExtensionName/ExtensionName.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.
[edit] Installation
- Copy the code into a file (e.g. Silverlight.php)
- Save the file in the extensions directory of your mediawiki folder
- Add the line
require_once("$IP/extensions/Silverlight.php");to your LocalSettings.php file (The name of your file is case sensitive!) - If you don't already have it, add the lines
$wgFileExtensions[] = 'xap'; $wgEnableUploads = true;
to your LocalSettings.php file.
Now you can use the extension with <silverlight>...</silverlight> in the wiki
[edit] Code
<?php // MediaWiki Silverlight Extension Ver 0.1 // Set up MediaWiki to react to the "<silverlight>" tag $wgExtensionCredits['parserhook'][] = array( 'name' => 'Silverlight Extension', 'author' => 'soyatec', 'description' => 'Allows (simple) embedding of silverlight in MediaWiki pages by using <nowiki><silverlight></silverlight></nowiki>-tags', 'url' => 'http://www.mediawiki.org/wiki/Extension:Silverlight_Extension', ); $wgExtensionFunctions[] = "hookSilverlight"; function hookSilverlight() { global $wgParser; $wgParser->setHook( "silverlight", "RenderSilverlight" ); } function getXapPath($file) { $title = Title::makeTitleSafe("Image",$file); $img = new Image($title); $path = $img->getViewURL(false); return $path; } function RenderSilverlight( $input, $argv ) { global $wgScriptPath; $output = ""; // external URL if ( strpos($input , "http") === 0 && strpos($input, ".xap") == strlen($input)-4 ) { $url = $input; } // internal Media: else { $url = getXapPath(trim($input)); } $width = isset($argv['width']) ? $argv['width'] : '100%'; $height = isset($argv['height'])? $argv['height'] : '100%'; $id = basename($input, ".xap"); $output .=<<<EndOfText <style type="text/css"> #silverlightControlHost { height: 100%; overflow: auto; } </style> <script type="text/javascript"> function onSilverlightError(sender, args) { var appSource = ""; if (sender != null && sender != 0) { appSource = sender.getHost().Source; } var errorType = args.ErrorType; var iErrorCode = args.ErrorCode; var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\n" ; errMsg += "Code: "+ iErrorCode + " \n"; errMsg += "Category: " + errorType + " \n"; errMsg += "Message: " + args.ErrorMessage + " \n"; if (errorType == "ParserError") { errMsg += "File: " + args.xamlFile + " \n"; errMsg += "Line: " + args.lineNumber + " \n"; errMsg += "Position: " + args.charPosition + " \n"; } else if (errorType == "RuntimeError") { if (args.lineNumber != 0) { errMsg += "Line: " + args.lineNumber + " \n"; errMsg += "Position: " + args.charPosition + " \n"; } errMsg += "MethodName: " + args.methodName + " \n"; } throw new Error(errMsg); } </script> <div id="silverlightControlHost"> <object data="data:application/x-silverlight," type="application/x-silverlight-2" width="$width" height="$height"> <param name="source" value="$url"/> <param name="onerror" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="2.0" /> <param name="autoUpgrade" value="true" /> <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/> </a> </object> <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe> </div> EndOfText; $output = str_replace("\n", "", $output); return $output; }
