Extension:SemanticSVGPrinter

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
Crystal Clear action run.svg
SemanticSVGPrinter
Release status: unmaintained
SemanticSVGPrinter screenshot.png
Implementation Parser extension
Description Extra output format for Semantic MediaWiki, creating a svg image from a template.
Author(s) Säsongsmat.nu (Rotseetalk)
Latest version 0.1
MediaWiki 1.18
License Free BSD
Download tar.gz zip
Example http://xn--ssongsmat-v2a.nu/ssm/Plommon
Translate the SemanticSVGPrinter extension if it is available at translatewiki.net
Check usage and version matrix.

What can this extension do?[edit]

This extension adds an extra result format to Semantic MediaWiki, to create a SVG image representing the results. I wrote it to create maps as the one to the right (showing worldwide export of pears), but there are probably other uses for it.

This extension was made for http://säsongsmat.nu, and work pretty well there. It might or might not work for you.

I'm not a programmer, so this code could probably be improved a lot. Feel free to modify it, but please share the result of your work with the rest of us!

Usage[edit]

SemanticSVGPrinter needs a template SVG to work from (in the example image a blank world map). The areas are colored using lower case class names, so each area should have a class name that can be shown in a query.

The first column (or a value derived from it using |keyquery={propertyname} will be matched against id:s of areas in the SVG. For each column the value, if numerical, will be used to fill the corresponding area. Colors are taken from the column labels, or from a default list. If more than one column on the same row contains a value, only the last column will be drawn. If more than one row has the same name, values will be added together.

In this example (assuming a blank world map as SVG template) Afghanistan and Belgium will be light blue, and Benin will be dark blue, Sweden will be red:

Query
{{#ask:
|?Has value  =Green
|?Is special =b90000
|?svgtemplate=BlankWorldMap.svg
|?svgname    =List_of_country_values.svg
}}
Result
            |  Green   | b90000 |
Afghanistan |       14 |        |
Belgium     |       11 |        |
Benin       |      380 |        |
Sweden      |          |      1 |

Installation[edit]

Download the extension (see info box) and unpack it to your extensions directory. To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/SemanticSVGPrinter/SemanticSVGPrinter.php");
$ssmTemporaryDirectory = path-to-empty-temp-directory;

Where $ssmTemporaryDirectory is a otherwise empty directory (NB: files here will be deleted!). Your web server (e.g. www or www-data) must have read-write permissions to this dir.

Query parameters[edit]

  • svgtemplate: A template SVG, with class names for the fields you want to fill
  • svgname: Output file name. NB: Will be overwritten if it exists!!! This is probably what you want, as you want the maps to be up to date, but please be careful!
  • svgimagedescription: Text for the file description page (not fully working, see to do list below)
  • svgkeyquery: Extra query to make from the first column, to get the class name. Probably only useful when working with Semantic Internal Objects.
  • svgmode: Make color from percent of total ('total'), percent of highest number ('max') or as a percent value between 0 and 1 ('fraction') or 0 and 100 ('percent')
  • amplify: Amplify all value, so that light colors are more visible. Useful for large datasets, such as a world map (the export map in the upper right corner has an amplify-value of 5.

The color can be controlled via the column labels, either via a hex code (such as 006622), or by a common color name from the following list: WHITE, BLACK, RED, GREEN, BLUE, YELLOW, SNOW, LINEN, PAPAYA, BISQUE, PEACH, IVORY, AZURE, LAVENDER, GRAY, LIGHTGRAY, NAVY, TURQUOISE, CYAN, KHAKI, OLIVE, GOLD, BEIGE, BROWN, ORANGE, PINK, VIOLET, PLUM or PURPLE. If no color code or name is found, it will loop through a predefined set of colors. There is currently no support for multiple colors on the same field (with stripes or similar). The last color of the last column will always be used.

Values that are not numbers will be ignored. If one field (one "table cell") contains multiple values (e.g. an array), or if the same key occurs twice, values will be added.

Preconditions[edit]

You need
  1. Semantic MediaWiki installed
  2. Local files uploads enabled
  3. SVG files enabled ( $wgFileExtensions[] = 'svg'; i LocalSettings), and
  4. some SVG file converter installed if you want to use the SVG images in articles
  5. A SVG template to work with. The shapes you wish to fill with colors should have lower case class names that correspond to the labels of the columns in a SMW query result
  6. A temporary directory that can store the images prior to uploading them (uploading is done through the Job Queue). Your web server must have permissions to read and write here.
You might want
  1. ...to use some other SVG converter than Batik (e.g. ImageMagick), as Batik does not handle SVG images with a lot of style information in them very well. If you notice that some areas do not get filled, this might be the problem.

Bugs and to do's[edit]

  • Files in temp directory will all get uploaded and deleted. Upload only those with an "filenamn.uploadme" text file.
  • All images get the same page description if more than one is uploaded at the same time. Put file descriptions in individual files to prevent this (same as above).
  • Variables passed will contain UNIQ / QINU messages. How do we get around this? Currently very ugly solution with preg_replace
  • use MW temp dir
  • Support multiple columns on the same row, using e.g. striped fields?
  • Error handling in various places
  • Server locale need to be correctly set for non ascii characters to show in file description. Maybe this would not be the case if putting descriptions in file?
  • Templates in file page description will be substituted. This is probably not the wanted behaviour
  • Create robot user in runJobs.php, and use --user=
  • Something is wrong with how we use the parameters, for the last parameter not to be null all parameters above has to be set. That does not make sense.
  • i18n

Changelog[edit]

  • 0.1 - First version

See also[edit]