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