Add wiki extension files.

This commit is contained in:
kovacsv 2014-10-18 18:26:43 +02:00
parent 2118b5eae6
commit bd7ba77a0c
6 changed files with 96 additions and 3 deletions

View File

@ -1,4 +1,4 @@
function Online3DViewerLoad ()
function LoadOnline3DModels ()
{
function Error (viewerElement, message)
{
@ -76,5 +76,3 @@ function Online3DViewerLoad ()
}
}
}
window.addEventListener ('load', Online3DViewerLoad, true);

View File

@ -13,6 +13,9 @@
<script type="text/javascript" src="../jsmodeler/three.min.js"></script>
<script type="text/javascript" src="../jsmodeler/jsmodeler.js"></script>
<script type="text/javascript" src="include/online3dembedder.js"></script>
<script type="text/javascript">
window.addEventListener ('load', LoadOnline3DModels, true);
</script>
<title>Online 3D Viewer</title>

View File

@ -35,6 +35,13 @@ def BuildEmbeddable (rootFolder, resultFolder):
indexFilePath = os.path.join (targetFolder, 'index.html')
ReplaceInFile (indexFilePath, '../jsmodeler/', 'jsmodeler/')
def BuildWikiExtension (rootFolder, resultFolder):
targetFolder = os.path.join (resultFolder, 'wikiextension')
shutil.copytree (os.path.join (rootFolder, 'wikiextension'), targetFolder)
shutil.copy (os.path.join (rootFolder, 'jsmodeler', 'three.min.js'), os.path.join (targetFolder, 'three.min.js'))
shutil.copy (os.path.join (rootFolder, 'jsmodeler', 'jsmodeler.js'), os.path.join (targetFolder, 'jsmodeler.js'))
shutil.copy (os.path.join (rootFolder, 'embeddable', 'include', 'online3dembedder.js'), os.path.join (targetFolder, 'online3dembedder.js'))
def Main ():
rootFolder = os.path.abspath ('..')
resultFolder = os.path.join (rootFolder, 'build')
@ -47,6 +54,9 @@ def Main ():
PrintInfo ('Building embeddable example to folder <' + resultFolder + '>.')
BuildEmbeddable (rootFolder, resultFolder)
PrintInfo ('Building wiki extension to folder <' + resultFolder + '>.')
BuildWikiExtension (rootFolder, resultFolder)
return 0
sys.exit (Main ())

View File

@ -0,0 +1,54 @@
<?php
$viewerCounter = 0;
class Viewer3DHooks {
public static function OnParserFirstCallInit (&$parser)
{
$parser->setHook ('viewer3d', 'Viewer3DHooks::OnSampleTag');
return true;
}
public static function OnSampleTag ($data, $attribs, $parser, $frame)
{
$parser->getOutput ()->addJsConfigVars ('myConfigVar', 'anna');
$parser->getOutput ()->addModules ('ext.Viewer3D');
global $viewerCounter;
$viewerCounter++;
$width = 300;
if (in_array ('width', array_keys ($attribs))) {
$width = $attribs['width'];
}
$height = 200;
if (in_array ('height', array_keys ($attribs))) {
$height = $attribs['height'];
}
$originalFiles = '';
if (in_array ('sourcefiles', array_keys ($attribs))) {
$originalFiles = $attribs['sourcefiles'];
}
$sourceFiles = '';
$splitted = explode ('|', $originalFiles);
for ($i = 0; $i < count ($splitted); $i++) {
$fileObject = wfFindFile ($splitted[$i]);
if ($fileObject) {
$filePath = $fileObject->getFullUrl ();
$sourceFiles .= $filePath;
if ($i < count ($splitted) - 1) {
$sourceFiles .= '|';
}
}
}
$html = '';
$html .= '<canvas class="3dviewer" width="'.$width.'" height="'.$height.'" sourcefiles="'.$sourceFiles.'"></canvas>';
return $html;
}
}
?>

View File

@ -0,0 +1,3 @@
mw.loader.using ('ext.Viewer3D', function () {
LoadOnline3DModels ();
});

View File

@ -0,0 +1,25 @@
<?php
$dir = dirname (__FILE__);
$dirbasename = basename ($dir);
$wgExtensionCredits['viewer3d'][] = array(
'path' => __FILE__,
'name' => 'Viewer3D',
'author' => 'Viktor Kovacs',
'url' => 'https://www.mediawiki.org/wiki/Extension:Viewer3D',
'description' => 'With this extension you can view 3D models with WebGL.',
'version' => 0.1,
'license-name' => "MIT"
);
$wgAutoloadClasses['Viewer3DHooks'] = $dir.'/Viewer3D.hooks.php';
$wgHooks['ParserFirstCallInit'][] = 'Viewer3DHooks::OnParserFirstCallInit';
$wgResourceModules['ext.Viewer3D'] = array(
'scripts' => array ('three.min.js', 'jsmodeler.js', 'online3dembedder.js', 'Viewer3D.js'),
'localBasePath' => $dir,
'remoteExtPath' => 'Viewer3D'
);
?>