diff -Nur /home/tpj/share/Praca/Notatnik/for-patch/orig/tools/wiki/index.cgi ./index.cgi --- /home/tpj/share/Praca/Notatnik/for-patch/orig/tools/wiki/index.cgi 2010-03-05 13:57:05.000000000 +0100 +++ ./index.cgi 2010-06-26 09:41:33.000000000 +0200 @@ -47,6 +47,11 @@ (if (not SETUP:security) (set 'SETUP:security "open")) (if (not SETUP:template) (set 'SETUP:template "template.html")) (if (not SETUP:page-title) (set 'SETUP:page-title "on")) +(if (not SETUP:toc-level) (set 'SETUP:toc-level 3)) +(if (not SETUP:toc-start) (set 'SETUP:toc-start {
Table of contents:
")) +(if (not SETUP:toc-elm-start) (set 'SETUP:toc-elm-start "
  • ")) +(if (not SETUP:toc-elm-end) (set 'SETUP:toc-elm-end "
  • ")) ;; if no rss header info is supplied, make a guess (if (not SETUP:rss-title) (set 'SETUP:rss-title (or (read-file "pages/Browser_Title") ""))) @@ -292,6 +297,7 @@ { } dfle { } { edit} + { rename} { backup} { restore} { delete} @@ -349,10 +355,62 @@ (push {} files) (join files "\r\n")) +;; creates an empty TOC context +(define (init-toc) + (set 'TOC:toc (list SETUP:toc-start)) + (set 'TOC:lvl 1) + (set 'TOC:anchor 0) + (set 'TOC:found false)) + + +;; checks the given line and updates TOC data +(define (update-toc line) + + (define (append-toc content level) + (unless (> level SETUP:toc-level) + (while (> level TOC:lvl) + (push "" TOC:toc) + (-- TOC:lvl)) + (push (append SETUP:toc-elm-start {} content {} SETUP:toc-elm-end) TOC:toc))) + + (cond + ((find "======(.*)======" line 512) (append-toc $1 5)) + ((find "=====(.*)=====" line 512) (append-toc $1 4)) + ((find "====(.*)====" line 512) (append-toc $1 3)) + ((find "===(.*)===" line 512) (append-toc $1 2)) + ((find "==(.*)==" line 512) (append-toc $1 1)) + ((find {\[toc\]} line 512) (set 'TOC:found true)) )) + +;; returns an anchored content for TOC, if needed +;; this function also updates the anchor number +(define (get-anchor content level) + (if (> level SETUP:toc-level) + content + (let ( str (append {[TOC][TOC]} content {[TOC][TOC]}) ) + (++ TOC:anchor) + str))) + +;; applies all the changes needed to properly display (or not) TOC +(define (finalize-toc) + (if TOC:found + (begin + (push SETUP:toc-end TOC:toc) + (reverse TOC:toc) + (let ( str-toc (join TOC:toc "") ) + (replace {\[toc\]} page str-toc 512) + (replace {\[TOC\]\[TOC\]} page "" 512) + (replace {\[TOC\]\[TOC\]} page "" 512) + (replace {\[TOC\]" (slice str 6) "") page)) ;; supress lines, which are only comments (if (not (find "" str 512)) - (push (format-line str) page)))) + (begin + (update-toc str) + (push (format-line str) page))))) (set 'page (join (reverse page) "
    \r\n")) (replace ">
    \r\n" page ">\r\n") (replace "a> ." page "a>.") @@ -371,7 +431,8 @@ (replace "a> ;" page "a>;") (replace "a> :" page "a>:") (replace "a> !" page "a>!") - (replace "a> ?" page "a>?") + (replace "a> ?" page "a>?") + (finalize-toc) ) ;; hide second level includes and locked pages @@ -453,11 +514,11 @@ (replace "%this%" str page-name) ;; generate HTML for easy titles - (replace "======(.*)======" str (append "
    " $1 "
    ") 512) - (replace "=====(.*)=====" str (append "

    " $1 "

    ") 512) - (replace "====(.*)====" str (append "

    " $1 "

    ") 512) - (replace "===(.*)===" str (append "

    " $1 "

    ") 512) - (replace "==(.*)==" str (append "

    " $1 "

    ") 512) + (replace "======(.*)======" str (append "
    " (get-anchor $1 5) "
    ") 512) + (replace "=====(.*)=====" str (append "

    " (get-anchor $1 4) "

    ") 512) + (replace "====(.*)====" str (append "

    " (get-anchor $1 3) "

    ") 512) + (replace "===(.*)===" str (append "

    " (get-anchor $1 2) "

    ") 512) + (replace "==(.*)==" str (append "

    " (get-anchor $1 1) "

    ") 512) ;; generate HTML for indented blocks (if (starts-with str ": ") @@ -648,6 +709,20 @@ (if (find page content 0) (inc cnt))) cnt) +;; changes all references to the given page-old +;; to references to the given page-new +(define (change-refs page-old page-new) + (let ( page-old-filename (replace "_" (dup page-old 1) ".") + rexp (append {\[\[} page-old {\]\]}) + subst (append {[[} page-new {]]}) + files (slice (directory "pages/") 2) ) + (dolist (fle files) + (let ( content (get-content fle) ) + (if (find rexp content 0) + (begin + (replace rexp content subst 512) + (write-file (append "pages/" fle) content))))))) + ;; backup a spefic page, postfix the name with current time (define (backup fname , date-str) (set 'date-str (eval @@ -1386,7 +1461,7 @@ (exit))) ;; request to show list of files with edit/backup/restore/delete links -(if (CGI:get "files") +(if (CGI:get "files") (files-table)) @@ -1477,6 +1552,43 @@ (display-page "Home") (exit))) +;; request to rename a page +(if (CGI:get "rename") + (if (CGI:get "continue") + (letn ( page-old (CGI:get "rename") + page-old-filename (replace " " (dup page-old 1) "_") + page-new (CGI:get "new") + page-new-filename (replace " " (dup page-new 1) "_") ) + (if (= (length (trim page-new)) 0) + (let ( body (append {

    You haven't entered any new name for the page } page-old {.

    } + {

    Try again on rename page, go to } + {} page-old {, or } + {get back to Home.

    } ) ) + (set 'body body) + (set 'page-name "Rename") + (CGI:put-page SETUP:template) + (exit)) + (begin + (change-refs page-old page-new) + (rename-file (append "pages/" page-old-filename) (append "pages/" page-new-filename)) + (display-page "Home") + (exit)))) + (letn ( page-name (CGI:get "rename") + bdy (append {

    You can rename the page } page-name {.

    } + {} + {} + {} + {

    New page name:

    } + {

    Do you really want to rename the page ? } + {

    } + {} + {

    You can cancel this action and get back to Home.

    }) ) + (set 'body bdy) + (set 'page-name "Rename") + (CGI:put-page SETUP:template) + (exit)))) + ;; take parameter as page name and display it (set 'link (env "QUERY_STRING")) diff -Nur /home/tpj/share/Praca/Notatnik/for-patch/orig/tools/wiki/pages/Default_Style ./pages/Default_Style --- /home/tpj/share/Praca/Notatnik/for-patch/orig/tools/wiki/pages/Default_Style 2004-06-25 19:56:04.000000000 +0200 +++ ./pages/Default_Style 2010-06-24 04:07:21.000000000 +0200 @@ -215,5 +215,11 @@ width: 200px; border: 1px #999 dashed; } + /* table of contents */ +.toc { + border: 1px #117 dashed; + background-color: #eee; +} + /* eof */