(www-display-char-desc): Use <div> instead of <p> to display feature
[chise/est.git] / cwiki-view.el
1 ;; -*- coding: utf-8-mcs-er -*-
2 (require 'cwiki-common)
3
4 (defvar chise-wiki-view-url "view.cgi")
5 (defvar chise-wiki-edit-url "edit.cgi")
6 (defvar chise-wiki-add-url "add.cgi")
7
8 (defun www-display-char-desc (uri-char &optional lang level simple)
9   (unless level
10     (setq level 1))
11   (let ((char (www-uri-decode-char uri-char))
12         logical-feature displayed-features
13         parents
14         GlyphWiki-id)
15     (when (characterp char)
16       (when (= (length uri-char) 1)
17         (setq uri-char (www-uri-encode-char char)))
18       (when (= level 1)
19         (princ
20          (encode-coding-string
21           (format "<head>
22 <title>CHISE-wiki character: %s</title>
23 </head>\n"
24                   (decode-uri-string uri-char 'utf-8-mcs-er))
25           'utf-8-mcs-er))
26         (princ "<body>\n"))
27       (dolist (feature (char-feature-property '$object 'additional-features))
28         (mount-char-attribute-table
29          (char-feature-name-at-domain feature '$rev=latest)))
30       (princ
31        (format
32         (if simple
33             "<div style=\"text-align:right;\">
34 <a href=\"edit/view.cgi?char=%s\">
35 <input type=\"submit\" value=\"Edit\" />
36 </a>
37 <input type=\"submit\" value=\"New Account\" />
38 </div>
39 <hr />\n"
40           "<div style=\"text-align:right;\">
41 <a href=\"../view.cgi?char=%s\">
42 <input type=\"submit\" value=\"Simple\" />
43 </a>
44 </div>
45 <hr />\n")
46         uri-char))
47       (when (setq parents (www-char-feature char '<-denotational))
48         (princ (format "<p>%s %s</p>\n<hr>\n"
49                        (www-format-value-as-char-list parents)
50                        (www-format-feature-name '->denotational lang))))
51       (when (setq parents (www-char-feature char '<-subsumptive))
52         (princ (format "<p>%s %s</p>\n<hr>\n"
53                        (www-format-value-as-char-list parents)
54                        (www-format-feature-name '->subsumptive lang))))
55       (setq GlyphWiki-id (char-GlyphWiki-id char))
56       (princ (format "<h%d>%s%s</h%d>\n"
57                      level
58                      (www-format-encode-string (char-to-string char))
59                      (if GlyphWiki-id
60                          (format
61                           " <a href=\"http://glyphwiki.org/wiki/%s\"><img alt=\"%s\" src=\"http://glyphwiki.org/glyph/%s.50px.png\" /></a>"
62                           GlyphWiki-id
63                           GlyphWiki-id GlyphWiki-id)
64                        "")
65                      level))
66       (if (> level 1)
67           (princ "<ul>"))
68       (dolist (cell (sort (char-attribute-alist char)
69                           (lambda (a b)
70                             (char-attribute-name<
71                              (char-feature-name-sans-versions (car a))
72                              (char-feature-name-sans-versions (car b))))))
73         (setq logical-feature (char-feature-name-sans-versions (car cell)))
74         (unless (memq logical-feature displayed-features)
75           (push logical-feature displayed-features)
76           (princ
77            (if (= level 1)
78                "<div class=\"feature\" style=\"line-height:150%\">\n"
79              "<li>\n"))
80           (princ
81            (www-format-eval-list
82             (or (char-feature-property logical-feature ; (car cell)
83                                        'format)
84                 '((name) " : " (value)))
85             char
86             logical-feature ; (car cell)
87             lang uri-char
88             nil simple))
89           (unless simple
90             (princ
91              (format " <a href=\"%s?char=%s&feature=%s&format=wiki-text\"
92 ><input type=\"submit\" value=\"note\" /></a>"
93                      chise-wiki-edit-url
94                      (www-format-encode-string uri-char)
95                      (www-format-encode-string
96                       (www-uri-encode-feature-name
97                        (intern (format "%s*note"
98                                        logical-feature ; (car cell)
99                                        )))))))
100           (princ
101            (if (= level 1)
102                "</div>\n"
103              "<li>\n"))
104           ))
105       (princ
106        (if (= level 1)
107            "<p>\n"
108          "<li>\n"))
109       (princ
110        (format "<a href=\"%s?char=%s\"
111 ><input type=\"submit\" value=\"add feature\" /></a>
112 "
113                chise-wiki-add-url
114                (www-format-encode-string uri-char)))
115       (princ
116        (if (= level 1)
117            "<p>\n"
118          "<li>\n"))
119       (princ
120        "<form action=\"http://chise.zinbun.kyoto-u.ac.jp/ids-find\">\n")
121       (princ
122        (www-format-encode-string
123         (format "%c" char)))
124       (princ
125        (format
126         " <input type=\"text\" name=\"components\"
127 size=\"30\" maxlength=\"30\" value=\"%s\" />"
128         (encode-coding-string (char-to-string char) 'utf-8-jp-er)))
129       ;; (princ (www-format-encode-string "と"))
130       ;; (princ "<input type=\"text\" name=\"additional-components\"
131 size=\;; "30\" maxlength=\"30\" value=\"\" />")
132       (princ
133        (www-format-encode-string
134         "を\u542Bむ\u6F22\u5B57を\u63A2す"))
135       (princ " <input type=\"submit\" value=\"search\" />\n")
136       (princ "</form>\n")
137       (princ
138        (if (= level 1)
139            "</p>\n"
140          "<li>\n"))
141       )))
142
143 (defun www-display-feature-desc (uri-feature-name uri-char &optional lang)
144   (let ((feature-name (www-uri-decode-feature-name uri-feature-name))
145         (name@lang (intern (format "name@%s" lang))))
146     (princ
147      (encode-coding-string
148       (format "<head>
149 <title>CHISE-wiki feature: %s</title>
150 </head>\n"
151               feature-name)
152       'utf-8-mcs-er))
153     (princ "<body>\n")
154     (princ
155      (format "<h1>%s</h1>\n"
156              (www-format-encode-string
157               (symbol-name feature-name))))
158     (princ (format "<p>name : %s "
159                    (or (www-format-feature-name feature-name) "")))
160     (princ
161      (format " <a href=\"%s?feature=%s&property=name&format=string&char=%s\"
162 ><input type=\"submit\" value=\"edit\" /></a>"
163              chise-wiki-edit-url
164              uri-feature-name
165              uri-char))
166     ;; (www-html-display-text
167     ;;  (format "[[[edit|%s?feature=%s&property=name&char=%s]]]"
168     ;;          ;; (char-feature-property feature-name 'name)
169     ;;          chise-wiki-edit-url
170     ;;          uri-feature-name ; (www-uri-encode-feature-name feature-name)
171     ;;          uri-char))
172     (princ "</p>")
173     (when lang
174       (princ "<p>")
175       (princ
176        (www-format-encode-string
177         (format "%s : %s"
178                 name@lang
179                 (or (char-feature-property feature-name name@lang) ""))))
180       (princ
181        (format " <a href=\"%s?feature=%s&property=%s&format=string&char=%s\"
182 ><input type=\"submit\" value=\"edit\" /></a>"
183                chise-wiki-edit-url
184                uri-feature-name
185                name@lang
186                uri-char))
187       ;; (www-html-display-text
188       ;;  (format " [[[edit|%s?feature=%s&property=%s&char=%s]]]"
189       ;;          chise-wiki-edit-url
190       ;;          uri-feature-name
191       ;;          name@lang
192       ;;          uri-char))
193       (princ "</p>"))
194     (www-html-display-paragraph
195      (format "type : %s"
196              (or (www-feature-type feature-name)
197                  ;; (char-feature-property feature-name 'type)
198                  'generic)))
199     (princ (format "<p>value-format : %s "
200                    (www-format-value
201                     nil 'value-format 
202                     (or (www-feature-value-format feature-name)
203                         'default)
204                     'default
205                     'without-tags)))
206     ;; (www-html-display-paragraph
207     ;;  (format "value-format : %s"
208     ;;          (www-xml-format-list
209     ;;           (or (www-feature-value-format feature-name)
210     ;;               'default))))
211     (princ
212      (format
213       " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&char=%s\"
214 ><input type=\"submit\" value=\"edit\" /></a></p>"
215       chise-wiki-edit-url
216       uri-feature-name
217       uri-char))
218
219     (www-html-display-paragraph
220      (format "format : %s"
221              (www-xml-format-list
222               (or (char-feature-property feature-name 'format)
223                   '((name) " : " (value))))))
224     (www-html-display-paragraph
225      (format "description : %s"
226              (or (char-feature-property feature-name 'description)
227                  "")))
228     (when lang
229       (www-html-display-paragraph
230        (format "description@%s : %s"
231                lang
232                (or (char-feature-property
233                     feature-name
234                     (intern (format "description@%s" lang)))
235                    ""))))
236     ))
237   
238 (defun www-batch-view ()
239   (setq terminal-coding-system 'binary)
240   (condition-case err
241       (let* ((target (pop command-line-args-left))
242              (user (pop command-line-args-left))
243              (accept-language (pop command-line-args-left))
244              (mode (intern (pop command-line-args-left)))
245              (lang
246               (intern
247                (car (split-string
248                      (car (split-string
249                            (car (split-string accept-language ","))
250                            ";"))
251                      "-"))))
252              ret)
253         (princ "Content-Type: text/html; charset=UTF-8
254
255 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
256             \"http://www.w3.org/TR/html4/loose.dtd\">
257 <html lang=\"ja\">
258 ")
259         (cond
260          ((stringp target)
261           (when (string-match "^char=\\(&[^&;]+;\\)" target)
262             (setq ret (match-end 0))
263             (setq target
264                   (concat "char="
265                           (www-uri-encode-char
266                            (www-uri-decode-char (match-string 1 target)))
267                           (substring target ret))))
268           (setq target
269                 (mapcar (lambda (cell)
270                           (if (string-match "=" cell)
271                               (cons
272                                (intern
273                                 (decode-uri-string
274                                  (substring cell 0 (match-beginning 0))
275                                  'utf-8-mcs-er))
276                                (substring cell (match-end 0)))
277                             (list (decode-uri-string cell 'utf-8-mcs-er))))
278                         (split-string target "&")))
279           (setq ret (car target))
280           (cond ((eq (car ret) 'char)
281                  (www-display-char-desc
282                   (cdr ret) ; (decode-uri-string (cdr ret) 'utf-8-mcs-er)
283                   lang nil (eq mode 'simple))
284                  )
285                 ((eq (car ret) 'feature)
286                  (www-display-feature-desc
287                   (decode-uri-string (cdr ret) 'utf-8-mcs-er)
288                   (cdr (assq 'char target))
289                   ;; (decode-uri-string (cdr (assq 'char target)))
290                   lang)
291                  ))
292           ))
293         (princ "\n<hr>\n")
294         (princ (format "mode=%S\n" mode))
295         (princ (format "user=%s\n" user))
296         ;; (princ (format "local user=%s\n" (user-login-name)))
297         (princ (format "lang=%S\n" lang))
298         (princ (emacs-version))
299         ;; (princ " CHISE ")
300         ;; (princ xemacs-chise-version)
301         (princ "
302 </body>
303 </html>")
304         )
305     (error nil
306            (princ (format "%S" err)))
307     ))
308
309 (provide 'cwiki-view)