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