WiLikiでコメント欄

なんかネタを書きとめとくのに一々編集するのも面倒になってきたんで、コメント欄を付けてみることにする。
さしあたりZuさんのところにあったので使ってみる。あ、WiLiKi 0.6_pre2やと構造変わっててそのまんまでは使えんわ。超適当に書き直して動くようにしてみる。しかし外部ファイルからWiLiKiを拡張する方法がよくわからんのでWiLiKiのソースを直書換えで。

wiliki.scmに

(define-wiliki-action comment :write (pagename
                                      (id :default "" :convert cv-in)
                                      (comment :default "" :convert cv-in)
                                      (user :convert cv-in)
                                      (mtime :convert x->integer :default 0)
                                      (above :convert x->integer :default 0)
                                      (nodate :convert x->integer :default 0))
  (if (or (string=? id "")
          (string=? comment ""))
      (cmd-view pagename)
      (cmd-commit-edit
        pagename
        (let* ((page (ref (wiliki-db-get pagename #f) 'content))
               (form (format "- \\[\\[\\$\\$comment ~a[^\\]]*\\]\\]" id))
               (line (string-append
                      (format "- ~a" comment)
                      (if (and (equal? user "")(> nodate 0))"" " --")
                      (if (equal? user "") "" (format " \\[\\[~a\\]\\]" user))
                      (if (> nodate 0)
                          ""
                          (regexp-quote (string-append " "(wiliki:format-time (sys-time))))))))
          (regexp-replace (string->regexp form)
                          page
                          (if (> above 0)
                              (string-append "\\0\r\n" line)
                              (string-append line "\r\n\\0"))))
        mtime
        ""
	#f)))

wiliki/macro.scmに

(define-writer-macro (comment . opt)
  (let ((opts (string-join (map x->string opt))))
  `(,(format "- [[$$comment ~s-~d ~a]]" (gensym) (sys-time) opts))))


(define-reader-macro (comment . arg)
  (let ((id (car arg))
        (opts (cdr arg)))
    `((form
       (@ (method POST) (action ,(script-name-of (wiliki))))
       (input (@ (type hidden) (name c) (value comment)))
       (input (@ (type hidden) (name id) (value ,id)))
       (input (@ (type hidden) (name p) (value ,(ref (wiliki-current-page) 'key))))
       (input (@ (type hidden) (name l) (value ,(wiliki:lang))))
       (input (@ (type hidden) (name mtime) (value ,(ref (wiliki-current-page) 'mtime))))
       (input (@ (type hidden) (name above) (value ,(if (member "above" opts) 1 0))))
       (input (@ (type hidden) (name nodate) (value ,(if (member "nodate" opts) 1 0))))
       (input (@ (type ,(if (member "nouser" opts) 'hidden 'text))
                 (name user) (size 10)))
       (input (@ (type text) (name comment)(size 100)))
       (br)
       (input (@ (type submit) (name submit) (value submit)))
     ))))

とか追記。あとは本家と同様

[[$comment]]

と書くとコメント欄ができるとか、

[[$comment above nouser]]

とかpukiwikiっぽいオプションが書けたりする感じ。オプションはabove, nouser, nodate。belowは要らんでしょ。しかし汚いソースやわ…。string-append連発とか、なんとかならんのか。nouserとnodateを併用するとコメント末尾に無意味な -- が付くとか手抜きすぎかも。超適当に修正。
SPAM対策は今回要らんので保留。そのうち欲しくなったら書くかも。