![]() Release status: unmaintained |
|
---|---|
Implementation | Media |
Description | Allows Dia diagrams to be rendered inside MediaWiki pages. |
Author(s) | EleotleCram |
MediaWiki | 1.11 |
License | GNU General Public License 2.0 or later |
Download | GitHub: Note: |
Parameters
$wgDIANominalSize, $wgDIAMaxSize, $wgDIAConverters, $wgDIAConverter, $wgDIAConverterPath |
|
What does this extension do?
The Dia extension allows Dia diagrams to be embedded/rendered inside MediaWiki pages. It can be used to have thumbnails of specified size to be automatically generated from the uploaded .dia
files. (If no size is given, then the nominal size will be used.)
In the future, when SVG gets better support in all the major browsers, this extension may also produce .svg
from the .dia
files.
Dependencies
- dia - This extension relies on an external conversion program to perform the conversion. By default, dia itself is used to perform this conversion, which means that you will need to have it installed on the server.
Installation
First copy the Dia/
directory into the extensions folder of your MediaWiki installation.
To activate the extension, add the following lines to your LocalSettings.php
file (near the end):
require_once( "$IP/extensions/Dia/Dia.php" ); # Load Dia extension
$wgFileExtensions[] = 'dia'; # Allow uploading of dia files
Also make sure that you have mediawiki configured to allow for file uploads:
$wgEnableUploads = true;
This setting is already present in LocalSettings.php
, however, it defaults to false. To enable uploads, make sure it is set to true.
Furthermore, when relatively large diagrams are used, dia consumes more memory than the default 100MB that MediaWiki grants it. You can increase the memory to 512MB by adding the following line to LocalSettings.php
:
$wgMaxShellMemory = 512000;
Mime type recognition
The following is only required by MediaWiki versions 1.12 and below.
To finish the installation, you must make sure the dia mime types are known to Mediawiki. This can be done by applying the supplied patch mimetypes.patch
. To do so, go to your mediawiki installation root (the directory containing the includes/ directory) and type the following in a commandline shell:
patch -p0 < extensions/Dia/mimetypes.patch
If that doesn't work, you'll have to modify the files manually.
First add the following line to includes/mime.types
:
application/x-dia-diagram dia
Then add the following line to includes/mime.info
:
application/x-dia-diagram [DRAWING]
MediaWiki 1.12
In MediaWiki 1.12, the mime type checking has been "improved" , which means that it now recognises files not only by file name extension but also based on its contents. Unfortunately, because MediaWiki does not recognise dia files by default, it detects a dia file as an ordinary xml file.
To fix this, you will have to patch MediaWiki. Copy/paste the following code snippet to a file called dia_xml_format.patch
.
--- includes/MimeMagic.php 2008-07-04 09:27:27.000000000 +0200
+++ includes/MimeMagic.php 2008-07-04 09:27:14.000000000 +0200
@@ -462,6 +462,7 @@
'svg' => 'image/svg+xml',
'http://www.w3.org/1999/xhtml:html' => 'text/html', // application/xhtml+xml?
'html' => 'text/html', // application/xhtml+xml?
+ 'http://www.lysator.liu.se/~alla/dia/:diagram' => 'application/x-dia-diagram',
);
if( isset( $types[$xml->rootElement] ) ) {
$mime = $types[$xml->rootElement];
And apply the patch from the MediaWiki installation root:
patch -p0 < extension/Dia/dia_xml_format.patch
If this doesn't work, manually add the line to the file includes/MimeMagic.php
.
Configuration
- $wgDIANominalSize
- The nominal width of a Dia file when rendered to png (default: 300px).
- $wgDIAMaxSize
- Don't scale a Dia file larger than this (default: 1024px).
Advanced Configuration
Dia diagrams may be uploaded as drawings. these diagrams are converted to png before they can be rendered on a page. An external program is required to perform this conversion. By default 'dia' itself is used to perform this conversion, but if you have a different tool to perform the conversion you can set it up here.
- $wgDIAConverters
- An associative array linking your conversion tool (as key) with the commandline to be used for your tool. In this commandline you can use the following variables:
- $input: The input filename
- $output: The output filename
- $width: The output width
- $wgDIAConverter
- The currently selected converter (default: 'dia').
- $wgDIAConverterPath
- If the currently selected converter is not in the default PATH environment variable, you can set the path here.
Note: Future versions of the extension may also output SVG.
Client side
This extension works great when using an external editor, which even works with HTTP authentication.
FAQ
Please also see Extension_talk:Dia for further assistence and questions regarding this extension.
"Corrupt file"
- Question
- When I upload I get: "The file is corrupt or has an incorrect extension"
- Answer
- You are probably using MediaWiki 1.12 and have not yet applied the above patch.
- Answer
- It might also be because dia compresses the dia file when you save it. Try selecting "save as" and remove the v in the kompression box in the lover left corner of the save box.
"Cannot allocate memory"
- Question
- After I have successfully uploaded a dia file, instead of a diagram, I get a gray box with the error message
Error creating thumbnail: dia: error while loading shared libraries: libXrender.so.1: failed to map segment from shared object: Cannot allocate memory
- Answer
- By default, MediaWiki only grants 100MB to a the dia program, which is not enough when relatively large diagrams are processed. To increase the allowed amount of memory to 500MB, add the following line to the end of
LocalSettings.php
:
$wgMaxShellMemory = 512000;
Which shapes does this extension support?
- Answer
- This extension uses 'dia' itself to perform the conversion, so it will supported whatever the 'dia' that is installed on the server will support.
If someone uploads a.dia
file that uses shapes (from a third-party plugin) that the installed 'dia' does not have, then these shapes will not get rendered in the thumbnail until the 'dia' on the server-side is also extended with the used plugin.
How can I display a dia file?
- Answer
- A Dia file can be displayed and edited using Dia . The file can also be exported to a variety of different formats (such as SVG, PDF, PNG). Of course, once exported, it cannot be edited anymore. This plugin performs an automatic conversion to PNG when including dia files as images inside mediawiki. However, the original dia file can be retrieved for editing and maintenance via the image page.
Editing Dia files
- Question
- The installation works fine for me and i am able to see the thumbnail on the wiki page. Now I have more than 10 to 20 users who would be using the wiki page. In order to edit the .dia file, I understand that an external editor has to be configured. My question is do all the users have to configure the external editor in their pc's to edit the .dia file and upload it back to the server?
- Answer
- Yes, you will need to set up and configure the external editor for each user/on each system. Please refer to systems administration best practices to set it up automatically for all users/each system.
"String could not be parsed as XML"
- Question
- I've set it up, following the instructions on 1.10. But I get this error:
exception 'Exception' with message 'String could not be parsed as XML' in /srv/www/vhosts/itwiki_science_unsw_edu_au/extensions/Dia/Dia.body.php:11 Stack trace: #0 /srv/www/vhosts/itwiki_science_unsw_edu_au/extensions/Dia/Dia.body.php(11): SimpleXMLElement->__construct('????????????[s?...') #1 /srv/www/vhosts/itwiki_science_unsw_edu_au/extensions/Dia/Dia.body.php(159): wfGetDIAsize('/srv/www/vhosts...') #2 /srv/www/vhosts/itwiki_science_unsw_edu_au/includes/Image.php(279): DiaHandler->getImageSize(Object(Image), '/srv/www/vhosts...') #3 /srv/www/vhosts/itwiki_science_unsw_edu_au/includes/Image.php(1061): Image->loadFromFile() #4 /srv/www/vhosts/itwiki_science_unsw_edu_au/includes/Image.php(1072): Image->purgeMetadataCache() #5 /srv/www/vhosts/itwiki_science_unsw_edu_au/includes/Image.php(1270): Image->purgeCache() #6 /srv/www/vhosts/itwiki_science_unsw_edu_au/includes/SpecialUpload.php(509): Image->recordUpload('20090421012807!...', , , , , true) #7 /srv/www/vhosts/itwiki_science_unsw_edu_au/includes/SpecialUpload.php(249): UploadForm->processUpload() #8 /srv/www/vhosts/itwiki_science_unsw_edu_au/includes/SpecialUpload.php(14): UploadForm->execute() #9 /srv/www/vhosts/itwiki_science_unsw_edu_au/includes/SpecialPage.php(627): wfSpecialUpload(NULL, Object(SpecialPage)) #10 /srv/www/vhosts/itwiki_science_unsw_edu_au/includes/SpecialPage.php(433): SpecialPage->execute(NULL) #11 /srv/www/vhosts/itwiki_science_unsw_edu_au/includes/Wiki.php(196): SpecialPage::executePath(Object(Title)) #12 /srv/www/vhosts/itwiki_science_unsw_edu_au/includes/Wiki.php(45): MediaWiki->initializeSpecialCases(Object(Title), Object(OutputPage), Object(WebRequest)) #13 /srv/www/vhosts/itwiki_science_unsw_edu_au/index.php(89): MediaWiki->initialize(Object(Title), Object(OutputPage), Object(User), Object(WebRequest)) #14 {main}
- Answer
This is caused by newer versions of dia that by default save the dia files as gzip compressed XML files. You have to re-save the dia diagram as an "uncompressed" file.
- Or make two hacks
At line 8 of extensions/Dia/Dia.body.php add:
// hack for dia zip files if($xmlstr[0] != "<") { exec("gzip -d - < \"$filename\"", $xmlstr); $xmlstr = join("\n", $xmlstr); }
And in doGuessMimeType in includes/MimeMagic.php after fclose($f) add:
// hack for dia if($head[0] != "<") { exec("gzip -d - < \"$file\"", $unzip); $unzip = join("\n", $unzip); if(strstr($unzip, 'http://www.lysator.liu.se/~alla/dia/')) return('application/x-dia-diagram'); }
"Error creating thumbnail: Missing input: mwstore://local-backend/local-public/..."
- Question
- with MediaWiki 1.19 or newer, my thumbnails no longer appear, instead giving an error message like:
Error creating thumbnail: Missing input: mwstore://local-backend/local-public/Bld_dep_mod.dia could not import gtkcons.py
- Answer
- need to update extensions/Dia/Dia.body.php and replace getPath with getLocalRefPath:
- $srcPath = $image->getPath(); + $srcPath = $image->getLocalRefPath();
History
- 20071031 Initial version.