wiki.pl: Port some fixes from upstream
[Orgmuse.git] / wikiimg
blobe1037aa4afc1492c92f3a949b01d228b80de030f
1 #!/bin/bash
2 # wikiimg --- Get and put SVG and PNG files to Oddmuse wikis
3 #
4 # Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 # 02111-1307, USA.
21 if [ -z "$2" ]; then
22 echo Usage:
23 echo
24 echo image get PageName -- gets PageName from the wiki and saves
25 echo it as PageName.svg in the current directory.
26 echo
27 echo image put PageName -- saves PageName.svg as PageNameSource
28 echo and PageName.png as PageNameImage. You are responsible for
29 echo exporting the SVG file as PNG when you are done.
30 exit
33 WIKI=http://www.communitywiki.org/en
34 USER=`id -un`
35 WIKIUSER=${WIKIUSER:-USER}
37 case $1 in
38 get)
39 F=`basename "$2" Image`.svg
40 # make sure both are accepted
41 IMG=`basename "$2" Image`Image
42 wget -O $F $WIKI/$IMG
44 put)
45 # make sure all are accepted
46 PAGE=$2
47 PAGE=`basename $PAGE .svg`
48 PAGE=`basename $PAGE .png`
49 for f in "$PAGE.svg" "$PAGE.png"; do
50 if [ ! -f "$f" ]; then
51 echo There is no file called $f
52 exit
54 done
55 wikiupload -u "$WIKIUSER" "$PAGE.png" "$WIKI/${PAGE}Image"
56 wikiupload -t "image/svg+xml" -u "$WIKIUSER" \
57 "$PAGE.svg" "$WIKI/${PAGE}Source"
60 echo You must use either get or put as first parameter.
61 exit
62 esac