diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-03-14 21:54:55 +0100 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-03-14 21:54:55 +0100 |
commit | 8a1ee16835571d4a590cd66f6ce21926ff02a875 (patch) | |
tree | c5e154f2958ad9551b0f3364cf1bb99572088e95 | |
parent | 07d79cf8bc26d3debec26508f26d6b170f7b8e5d (diff) |
Support the creation of articles and the addition of aliases to existing articles.
-rw-r--r-- | mulkcms.lisp | 44 | ||||
-rw-r--r-- | templates/article_summary_page.html | 18 |
2 files changed, 56 insertions, 6 deletions
diff --git a/mulkcms.lisp b/mulkcms.lisp index b2c88d3..e3f5c35 100644 --- a/mulkcms.lisp +++ b/mulkcms.lisp @@ -13,11 +13,28 @@ *template-formatters*))) +(defun make-uuid () + ;; Taken from Mulkblog. + "Generate a version 4 UUID according to RFC 4122, section 4.4." + (format nil "~(~8,'0x-~4,'0x-~4,'0x-~2,'0x~2,'0x-~12,'0x~)" + (random #x100000000) ;time_low + (random #x10000) ;time_mid + (logior #b0100000000000000 + (logand #b0000111111111111 + (random #x10000))) ;time_hi_and_version + (logior #b10000000 + (logand #b00111111 + (random #x100))) ;clock_seq_hi_and_reserved + (random #x100) ;clock_seq_low + (random #x1000000000000))) + + (defun find-canonical-article-alias (article) (query "SELECT alias FROM article_aliases WHERE article = $1 LIMIT 1" article :single)) + (defun link-to (action &key comment-id article-id revision-id (absolute nil)) ;; Taken from Mulkblog. (with-output-to-string (out) @@ -465,12 +482,10 @@ (parse-row-or-array string)) (defun find-article-summary-handler (path params &optional action characteristics) - (declare (ignore characteristics params action)) - (print path) + (declare (ignore characteristics action)) (when (string= path "admin/articles") (lambda () (with-authorization (user-id :require :admin) - (declare (ignore user-id)) (with-db (labels ((paramify-revision-row (row article-id) (destructuring-bind (id title date characteristics) @@ -491,6 +506,22 @@ :aliases aliases :revisions revision-data :revision-num (length revision-data)))))) + + (when (assoc "add-alias" params :test #'equal) + (with-transaction () + (query "INSERT INTO article_aliases(article, alias) VALUES ($1, $2)" + (parse-integer (cdr (assoc "article" params :test #'equal))) + (cdr (assoc "alias" params :test #'equal)) + :none))) + (when (assoc "create-article" params :test #'equal) + (with-transaction () + (let ((article-id (query "INSERT INTO articles(type) VALUES (1) RETURNING id" + :single!))) + (query "INSERT INTO article_revisions(article, title, content, author, format, status, global_id) + VALUES ($1, '', '', $2, 'html', 'draft', $3)" + article-id + user-id + (format nil "urn:uuid:~A" (make-uuid)))))) (let* ((articles (query "SELECT a.id, array_agg(DISTINCT ROW(r.id, @@ -517,7 +548,10 @@ GROUP BY r.id, r.title, r.date) AS r ON bt.revision = r.id - GROUP BY a.id" + LEFT OUTER JOIN article_publishing_dates pd + ON pd.article = a.id + GROUP BY a.id, pd.publishing_date + ORDER BY pd.publishing_date DESC" :rows)) (article-data (mapcar #'paramify-article-row articles))) (expand-page (template "article_summary_page") @@ -528,6 +562,8 @@ :branch-title-label "Title" :characteristics-label "Characteristics" :date-label "Date" + :create-button-label "Add article" + :add-alias-label "+" :articles article-data))))))))) (defun find-article-request-handler (path params &optional action characteristics) diff --git a/templates/article_summary_page.html b/templates/article_summary_page.html index f2b222a..09b3cf5 100644 --- a/templates/article_summary_page.html +++ b/templates/article_summary_page.html @@ -3,6 +3,13 @@ {.end} {.section body} +<p> + <form method="POST"> + <input name="create-article" type="hidden" /> + <input type="submit" value="{create-button-label|html-attr-value}" /> + </form> +</p> + <table> <thead> <th>{id-label}</th> @@ -22,12 +29,19 @@ rowspan="{revision-num|html-attr-value}"> {.repeated section aliases} {@|html} - {.alternates with} <br /> {.end} + <form method="POST" style="white-space: nowrap"> + <input name="add-alias" type="hidden" /> + <input name="article" type="hidden" value="{id|html-attr-value}" /> + <input name="alias" type="text" size="10" /> + <input type="submit" value="{add-alias-label|html-attr-value}" /> + </form> </td> {.repeated section revisions} - <td class="revision-id">{id|html}</a></td> + <td class="revision-id"> + <a href="{link|html-attr-value}">{id|html}</a> + </td> <td class="revision-title"> <a href="{link|html-attr-value}">{title|html}</a> </td> |