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