Changeset 15367 in project for release/4/qwiki/trunk/qwiki.scm


Ignore:
Timestamp:
08/08/09 15:18:53 (12 years ago)
Author:
sjamaan
Message:

Add history viewing functionality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/qwiki/trunk/qwiki.scm

    r15360 r15367  
    4040
    4141(import chicken scheme)
    42 (use extras files ports posix data-structures srfi-1 srfi-13
     42(use extras regex files ports posix data-structures srfi-1 srfi-13 srfi-18
    4343     intarweb uri-common spiffy sxml-transforms svn-client
    4444     wiki-parse qwiki-sxml doctype sxml-fu sxml-shortcuts)
     
    9292  (with-output-to-file path thunk))
    9393
     94;; Get the history for a given file starting at rev, going back in
     95;; time.  If rev is #f, start at the latest revision.  If limit is not
     96;; specified or #f, the full history is returned.  Otherwise, a
     97;; maximum of that many items is returned.
     98(define (get-history file rev #!optional limit)
     99  (let ((history '()))
     100   (svn-client-log2
     101    file (if rev (make-svn-opt-revision-number rev) svn-opt-revision-head)
     102    (make-svn-opt-revision-number 0) (or limit 0) #f #f
     103    (qwiki-repos-username) (qwiki-repos-password)
     104    (lambda (files rev author date msg)
     105      ;; What about the timezone?  Is it always GMT?  POSIX strptime
     106      ;; doesn't know about this so we may need to use srfi-19...
     107      (let* ((seconds-date (string-substitute "\\.[0-9]+.*" "" date))
     108             (date (string->time date "%Y-%m-%dT%H:%M")))
     109       (set! history (cons (list rev author date msg) history)))))
     110   (reverse history)))
     111
     112(define (call-with-input-revision file rev proc)
     113  (let ((filename (svn-client-cat
     114                   file (make-svn-opt-revision-number rev)
     115                   (qwiki-repos-username) (qwiki-repos-password))))
     116    (handle-exceptions exn
     117      (begin
     118        (delete-file* filename)
     119        (raise exn))
     120     (let ((result (call-with-input-file filename proc)))
     121       (delete-file* filename)
     122       result))))
     123
     124(define (send-content content)
     125  (write-logged-response)
     126  (with-output-to-port (response-port (current-response))
     127    (lambda ()
     128      (output-xml content (qwiki-transformation-steps))))
     129  (close-output-port (response-port (current-response))))
     130
    94131;;; Actions
    95132(define (qwiki-history path req)
    96   (send-status 404 "Not found")) ;; TODO
     133  (let* ((source-file (path->source-filename path))
     134         (rev (string->number
     135               (alist-ref 'rev (uri-query (request-uri req)) eq? "")))
     136         (history (get-history source-file rev 10))
     137         (content `(page (history ,history))))
     138    (send-content content)))
    97139
    98140(define (qwiki-edit path req)
     
    128170          (with-output-to-path source-file (lambda () (display source)))
    129171          (redirect-to-qwiki-page req action: "show"))
    130         (begin
    131           (write-logged-response)
    132           (with-output-to-port (response-port (current-response))
    133             (lambda ()
    134               (output-xml content (qwiki-transformation-steps))))))))
     172        (send-content content))))
    135173
    136174(define (redirect-to-qwiki-page req
     
    152190  ;; TODO: What if someone did something else than GET or HEAD?
    153191  (let* ((html-file (path->html-filename path))
    154          (source-file (path->source-filename path)))
     192         (source-file (path->source-filename path))
     193         (rev (string->number
     194               (alist-ref 'rev (uri-query (request-uri req)) eq? ""))))
    155195    (if (file-exists? source-file)
    156         (begin
    157           (update-html-file! (make-pathname (root-path) html-file) source-file)
    158           (send-static-file html-file))
     196        (if rev
     197            (send-content ; Do not store if old rev
     198             `(wiki-page ,(call-with-input-revision
     199                           source-file rev wiki-parse)))
     200            (begin
     201             (update-html-file! (make-pathname (root-path) html-file)
     202                                source-file)
     203             (send-static-file html-file)))
    159204        (redirect-to-qwiki-page req action: "edit"))))
    160205
Note: See TracChangeset for help on using the changeset viewer.