1 #!/usr/bin/env python 2 3 """ 4 Handle Confluence wiki requests performing searches. 5 """ 6 7 from urllib import urlencode 8 import cgi, os, sys 9 10 # An empty string means that the wiki is anchored at the site root. 11 12 URL_PREFIX = "" 13 14 def redirect(args): 15 location = "%s/?%s" % (URL_PREFIX, urlencode(args)) 16 17 print """\ 18 Status: 302 Redirect to page 19 Location: %s 20 Content-Type: text/html 21 22 <html> 23 <head><title>Redirecting to Page</title></head> 24 <body> 25 <h1>Redirecting to Page</h1> 26 <p>If you see this message, try following <a href="%s">this link</a>.</p> 27 </body> 28 </html> 29 """ % (location, cgi.escape(location, True)) 30 sys.exit(0) 31 32 def main(): 33 args = cgi.parse_qs(os.environ.get("QUERY_STRING", "")) 34 path = os.environ.get("PATH_INFO", "").strip("/") 35 space = (args.get("searchQuery.spaceKey") or args.get("where") or [None])[0] 36 query = (args.get("searchQuery.queryString") or args.get("queryString") or [None])[0] 37 38 search = [] 39 if space: 40 search.append("title:%s/" % space) 41 if query: 42 search.append(query) 43 search = " ".join(search) 44 45 redirect({ 46 "action" : "fullsearch", # Moin action performing searches 47 "context" : "180", # Textual context in characters 48 "value" : search, 49 "fullsearch" : "Text" # Indicates a page text (not title) search 50 }) 51 52 if __name__ == "__main__": 53 main() 54 55 # vim: tabstop=4 expandtab shiftwidth=4