2022-09-17 10:36:04 +00:00
|
|
|
#lang racket/base
|
|
|
|
(require racket/dict
|
|
|
|
; web server libs
|
|
|
|
net/url
|
|
|
|
web-server/http
|
|
|
|
"application-globals.rkt"
|
2022-11-10 10:20:09 +00:00
|
|
|
"data.rkt"
|
2023-02-05 04:56:15 +00:00
|
|
|
"../lib/url-utils.rkt"
|
|
|
|
"../lib/xexpr-utils.rkt")
|
2022-09-17 10:36:04 +00:00
|
|
|
|
|
|
|
(provide
|
|
|
|
page-global-search)
|
|
|
|
|
|
|
|
(define (page-global-search req)
|
|
|
|
(define wikiname (dict-ref (url-query (request-uri req)) 'wikiname #f))
|
|
|
|
(define q (dict-ref (url-query (request-uri req)) 'q #f))
|
|
|
|
(response-handler
|
2022-11-10 10:20:09 +00:00
|
|
|
(cond
|
|
|
|
[(not wikiname)
|
|
|
|
(response/output
|
|
|
|
#:code 400
|
|
|
|
#:mime-type "text/plain"
|
|
|
|
(λ (out)
|
|
|
|
(displayln "Requires wikiname and q parameters." out)))]
|
|
|
|
[(or (not q) (equal? q ""))
|
|
|
|
(define siteinfo (siteinfo-fetch wikiname))
|
|
|
|
(define dest (format "/~a/wiki/~a" wikiname (or (siteinfo^-basepage siteinfo) "Main_Page")))
|
|
|
|
(generate-redirect dest)]
|
|
|
|
[#t
|
|
|
|
(generate-redirect (format "/~a/search?~a"
|
|
|
|
wikiname
|
|
|
|
(params->query `(("q" . ,q)))))])))
|