#!/bin/bash

rm -f names.txt
touch names.txt
for namespace in $(seq 0 15); do
    from=""
    while true; do
	url="http://wiki.openmoko.org/index.php?title=Special%3AAllpages&from=$from&namespace=$namespace"
	echo "# namespace $namespace from $from url $url ##" | cat -A
	wget -q -O a "$url"
	lynx -dump -force-html a | grep localhost/wiki/|cut -d'/' -f5- >> names.txt
	if ! grep "Next page" a > /dev/null; then
	    break
	fi
	from="$(tr ' ' '\n' < a | fgrep 'href="/index.php?title=Special:Allpages&amp;from' | sed -n 2p|cut -d= -f4-| cut -d'"' -f1|cut -d '&' -f1)"
	if [ "$from" = "" ]; then
	    break
	fi
    done
done
