Changeset 15367 in project


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

Add history viewing functionality

Location:
release/4/qwiki/trunk
Files:
4 edited

Legend:

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

    r15360 r15367  
    4141(import chicken scheme)
    4242
    43 (use sxpath-lolevel sxml-transforms doctype uri-generic)
     43(use posix sxpath-lolevel sxml-transforms doctype uri-generic)
    4444
    4545(define qwiki-basic-transformation-rules
     
    5353                      (page-specific-links)
    5454                      ,@(sxml:content-raw page))))))
     55    ;; Maybe this should be done in multiple steps to make it more "hookable"
     56    (history
     57     *macro* . ,(lambda (history items)
     58                  `(table
     59                    (tr (th "revision")
     60                        (th "author")
     61                        (th "date")
     62                        (th "description"))
     63                    ,@(map (lambda (item)
     64                             `(tr (td (url ,(string-append
     65                                             "?action=show&rev="
     66                                             (number->string (car item)))
     67                                           ,(car item)))
     68                                  (td ,(cadr item))
     69                                  (td ,(time->string (caddr item)))
     70                                  (td ,(cadddr item))))
     71                           items))))
    5572    (page-specific-links
    5673     *macro* . ,(lambda _
  • release/4/qwiki/trunk/qwiki.meta

    r15360 r15367  
    11((synopsis "qwiki - the quick wiki")
    22 (needs wiki-parse intarweb uri-common spiffy (doctype 1.2) sxml-transforms
    3         (sxml-fu 0.2))
     3        (sxml-fu 0.2) svn-client)
    44 (author "Peter Bex")
    55 (category www)
     
    77 (doc-from-wiki)
    88 (hidden)
    9  (files "qwiki.scm" "qwiki.setup"))
     9 (files "qwiki.scm" "qwiki-sxml" "qwiki.setup"))
  • 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
  • release/4/qwiki/trunk/qwiki.setup

    r15351 r15367  
    22(compile -s -O2 qwiki.import.scm)
    33
    4 (compile -s -O2 qwiki-sxml.scm -j qwiki)
     4(compile -s -O2 qwiki-sxml.scm -j qwiki-sxml)
    55(compile -s -O2 qwiki-sxml.import.scm)
    66
    77(install-extension
    88  'qwiki
    9   '("qwiki.so" "qwiki.import.so" "qwiki-sxml.so" "qwiki-sxml.import.so")
     9  '("qwiki.so" "qwiki.import.so"
     10    "qwiki-sxml.so" "qwiki-sxml.import.so")
    1011  `((version 0.1)
    1112    (documentation "qwiki.html")))
Note: See TracChangeset for help on using the changeset viewer.