#!/bin/sh
#
###################################################
#
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# WARNING! This script does not check its inputs and is
# therefore completely UNSAFE!
# Do not run it on any webserver reachable via a network!
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#
# Extracts static wikipedia entries from tgz archives
# To be used on data created with wiki2staticz and wiki-tar.
# 
# Author: Markus Baumeister (markus@spampit.retsiemuab.de)
#
# Version: 0.1
#
# More info on http://www.retsiemuab.de/wiki2zaurus
#
####################################################

# disable filename globbing
set -f

#source wpg-cgi.conf
export lang="de"
export wikiurlpath="/wiki/${lang}"
export wikifilepath="/mnt/cf/www/wiki/${lang}"
#export wikifilepath="/srv/www/htdocs/wiki/${lang}"
export wikicharset="iso-8859-1"

# print completely static parts of page

echo Content-type: text/html
echo

echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
echo '<html' lang=$lang '><head><meta http-equiv="Content-type" content="text/html"' "charset=${wikircharset}>"
echo '<link rel="shortcut icon"' "href=\"${wikiurlpath}/favicon.ico\"><link rel=\"stylesheet\" href=\"${wikiurlpath}/wikistatic.css\">"

# get path to tgz file and extract page from it

#echo argc is $#. argv is "$*".
arg=$1
base=`basename $1 .ht`
len=${#base}
pathp1=`echo $arg | cut -b-1 `
if expr $len \< 2 >/dev/null; then
  pathp2=${pathp1}${pathp1}; 
else
  pathp2=` echo $arg | cut -b-2 `
fi
pathcomp=${wikifilepath}/${pathp1}/${pathp2}.tgz
#echo tar xfzO $pathcomp ${pathp2}/${arg}
tar xzOf $pathcomp ${pathp2}/${arg}

# print footer (static again)

echo "<small>All text is available under the terms of the <a href=\"/cgi-bin/wpg-${lang}?gnu_free_documentation_license.html\">GNU Free Documentation License</a>.</small></td></tr></table></div></body></html>"


