#!/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

# disable filename globbing
set -f

# The following paths were automatically inserted by wiki2statcz.pl
###### automatic path insert here #####

export wikiurlpath="/wiki/${lang}"

echo Content-type: text/html\; charset=${wikicharset}
echo

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">'
echo '<html' xml:lang="$lang" lang="$lang" dir="ltr"'><head><meta http-equiv="Content-Type" content="text/html;' "charset=${wikicharset}\"/>"
echo '<link rel="shortcut icon"' "href=\"${wikiurlpath}/favicon.ico\"><link rel=\"stylesheet\" href=\"${wikiurlpath}/wikistatic.css\">"
echo '<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "/wiki/'${lang}'/main.css"; /*]]>*/</style>'

#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};
  pathp3=${pathp1}${pathp1}${pathp1};
else
  pathp2=` echo $arg | cut -b-2 `
  if expr $len \< 3 >/dev/null; then
    pathp3=${pathp2}`echo $arg | cut -b2`
  else
    pathp3=` echo $arg | cut -b-3 `
  fi
fi
pathcomp=${wikifilepath}/${pathp1}/${pathp2}/${pathp3}.tgz
#echo tar xfzO $pathcomp ${pathp2}/${arg}
tar xzOf $pathcomp ${pathp3}/${arg}
#cat ${wikifilepath}/${pathp1}/${pathp2}/${pathp3}/${arg}

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>"


