wiki helper cgi script
Will Ware
wware at alum.mit.edu
Wed Apr 24 23:06:24 EDT 2002
I have a few wikis on my site, all using UseMod. The following Python script
can be shared by all my wikis, and it lets me put a link on the wiki that
generates an alphabetized list of all the wiki's pages with links to them.
It doesn't care what directory or subdirectory the wiki in is. I just put the
following in the wiki:
[http://willware.net:8080/cgi-bin/pagelist.py List] of all pages
I'm running this on a Linux box with Apache. YMMV otherwise.
Bon appetit, Will Ware
#######################################
#!/usr/bin/python
import os, sys, string
def ouch(arg):
print "Content-type: text/html\n"
print "<HTML><TITLE>Ouch</TITLE>"
print "<BODY BGCOLOR=\"WHITE\">"
print "<H1>Ouch: %s</H1>" % repr(arg)
print "Don't try to call this CGI script directly."
print "</BODY></HTML>"
sys.exit(0)
if os.environ.has_key('HTTP_REFERER'):
referer = os.environ['HTTP_REFERER']
else:
ouch(1)
referer = referer[7:] # strip off "http://"
referer = string.split(referer, "/")
if referer[0] != 'willware.net:8080':
ouch(2)
if referer[1] != 'cgi-bin':
ouch(3)
referer = string.join(referer[2:-1], "/")
inf = os.popen("find %s/data/page -type f" % referer)
L = inf.readlines()
inf.close()
L.sort()
print """Content-type: text/html
<html>
<title>List of all pages for WifiWiki</title>
<body bgcolor=white>
<h1>List of all pages for WifiWiki</h1>
<ul>
"""
for x in L:
x = x[13+len(referer):]
x = x[:-4]
url = "http://willware.net:8080/cgi-bin/%s/wiki.cgi?%s" % (referer, x)
item = "<li><a href=\"%s\">%s</a>" % (url, x)
print item
print """</ul>
</body>
</html>
"""
#######################################
More information about the Python-list
mailing list