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(page=None, args=None): 15 location = "%s/%s%s" % (URL_PREFIX, page or "", args and "?" + urlencode(args) or "") 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 reset = args.get("reset") 38 39 if reset: 40 redirect(page="FindPage") 41 return 42 43 search = [] 44 if space: 45 search.append("title:%s/" % space) 46 if query: 47 search.append(query) 48 search = " ".join(search) 49 50 redirect(args={ 51 "action" : "fullsearch", # Moin action performing searches 52 "context" : "180", # Textual context in characters 53 "value" : search, 54 "fullsearch" : "Text" # Indicates a page text (not title) search 55 }) 56 57 if __name__ == "__main__": 58 main() 59 60 # vim: tabstop=4 expandtab shiftwidth=4