(www-display-object-desc): Don't display CHISE IDS-Find for
[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-object 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       (when (eq genre 'character)
130         (princ
131          "<form action=\"http://www.chise.org/ids-find\">\n")
132         (princ
133          (www-format-encode-string
134           (est-format-object object)
135           ;; (if (eq genre 'character)
136           ;;     (format "%c" object)
137           ;;   (format "%s" (concord-object-id object)))
138           ))
139         (princ
140          (format
141           " <input type=\"text\" name=\"components\"
142 size=\"30\" maxlength=\"30\" value=\"%s\" />"
143           (encode-coding-string
144            (est-format-object object)
145            ;; (if (eq genre 'character)
146            ;;     (char-to-string object)
147            ;;   (format "%s" (concord-object-id object)))
148            'utf-8-jp-er)))
149         (princ
150          (www-format-encode-string
151           "を\u542Bむ\u6F22\u5B57を\u63A2す"))
152         (princ " <input type=\"submit\" value=\"search\" />\n")
153         (princ "</form>\n"))
154       (princ
155        (if (= level 1)
156            "</p>\n"
157          "<li>\n"))
158       )))
159
160 (defun www-display-feature-desc (uri-feature-name uri-object
161                                                   &optional lang simple)
162   (let ((feature-name (www-uri-decode-feature-name uri-feature-name))
163         (name@lang (intern (format "name@%s" lang))))
164     (princ
165      (encode-coding-string
166       (format "<head>
167 <title>EsT feature: %s</title>
168 </head>\n"
169               feature-name)
170       'utf-8-mcs-er))
171     (princ "<body>\n")
172     (princ
173      (format
174       (if simple
175           "<div style=\"text-align:right;\">
176 <a href=\"edit/view.cgi?feature=%s&char=%s\">
177 <input type=\"submit\" value=\"Edit\" />
178 </a>
179 <input type=\"submit\" value=\"New Account\" />
180 </div>
181 <hr />\n"
182           "<div style=\"text-align:right;\">
183 <a href=\"../view.cgi?feature=%s&char=%s\">
184 <input type=\"submit\" value=\"Simple\" />
185 </a>
186 </div>
187 <hr />\n")
188       uri-feature-name uri-object))
189     (princ
190      (format "<h1>%s</h1>\n"
191              (www-format-encode-string
192               (symbol-name feature-name))))
193     (princ (format "<p>name : %s "
194                    (or (www-format-feature-name feature-name) "")))
195     (unless simple
196       (princ
197        (format
198         " <a href=\"%s?feature=%s&property=name&format=string&char=%s\">"
199         chise-wiki-edit-url
200         uri-feature-name
201         uri-object))
202       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
203     (princ "</p>\n")
204     (when lang
205       (princ "<p>")
206       (princ
207        (www-format-encode-string
208         (format "%s : %s"
209                 name@lang
210                 (or (char-feature-property feature-name name@lang) ""))))
211       (unless simple
212         (princ
213          (format
214           " <a href=\"%s?feature=%s&property=%s&format=string&char=%s\">"
215           chise-wiki-edit-url
216           uri-feature-name
217           name@lang
218           uri-object))
219         (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
220       (princ "</p>\n"))
221     (www-html-display-paragraph
222      (format "type : %s"
223              (or (www-feature-type feature-name)
224                  ;; (char-feature-property feature-name 'type)
225                  'generic)))
226     (princ (format "<p>value-format : %s "
227                    (www-format-value
228                     nil 'value-format 
229                     (or (www-feature-value-format feature-name)
230                         'default)
231                     'default
232                     'without-tags)))
233     (unless simple
234       (princ
235        (format
236         " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&char=%s\"
237 >"
238         chise-wiki-edit-url
239         uri-feature-name
240         uri-object))
241       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
242     (princ "</p>\n")
243
244     (princ "<p>format : ")
245     (www-html-display-text
246      (decode-coding-string
247       (www-xml-format-list
248        (www-feature-format feature-name))
249       'utf-8-mcs-er))
250     (unless simple
251       (princ
252        (format
253         " <a href=\"%s?feature=%s&property=format&format=wiki-text&char=%s\"
254 >"
255         chise-wiki-edit-url
256         uri-feature-name
257         uri-object))
258       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
259     (princ "</p>\n")
260     
261     (www-html-display-paragraph
262      (format "description : %s"
263              (or (char-feature-property feature-name 'description)
264                  "")))
265     (when lang
266       (www-html-display-paragraph
267        (format "description@%s : %s"
268                lang
269                (or (char-feature-property
270                     feature-name
271                     (intern (format "description@%s" lang)))
272                    ""))))
273     ))
274   
275 (defun www-batch-view ()
276   (setq terminal-coding-system 'binary)
277   (condition-case err
278       (let* ((target (pop command-line-args-left))
279              (user (pop command-line-args-left))
280              (accept-language (pop command-line-args-left))
281              (mode (intern (pop command-line-args-left)))
282              (lang
283               (intern
284                (car (split-string
285                      (car (split-string
286                            (car (split-string accept-language ","))
287                            ";"))
288                      "-"))))
289              ret)
290         (princ "Content-Type: text/html; charset=UTF-8
291
292 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
293             \"http://www.w3.org/TR/html4/loose.dtd\">
294 <html lang=\"ja\">
295 ")
296         (cond
297          ((stringp target)
298           (when (string-match "^char=\\(&[^&;]+;\\)" target)
299             (setq ret (match-end 0))
300             (setq target
301                   (concat "char="
302                           (www-uri-encode-object
303                            (www-uri-decode-object
304                             'character (match-string 1 target)))
305                           (substring target ret))))
306           (setq target
307                 (mapcar (lambda (cell)
308                           (if (string-match "=" cell)
309                               (cons
310                                (intern
311                                 (decode-uri-string
312                                  (substring cell 0 (match-beginning 0))
313                                  'utf-8-mcs-er))
314                                (substring cell (match-end 0)))
315                             (list (decode-uri-string cell 'utf-8-mcs-er))))
316                         (split-string target "&")))
317           (setq ret (car target))
318           (cond ((eq (car ret) 'char)
319                  (www-display-object-desc
320                   'character
321                   (cdr ret)
322                   lang nil
323                   (eq mode 'simple))
324                  )
325                 ((eq (car ret) 'feature)
326                  (www-display-feature-desc
327                   (decode-uri-string (cdr ret) 'utf-8-mcs-er)
328                   (cdr (assq 'char target))
329                   lang
330                   (eq mode 'simple))
331                  )
332                 (t
333                  (www-display-object-desc
334                   (car ret)
335                   (cdr ret)
336                   lang nil
337                   (eq mode 'simple))
338                  ))
339           ))
340         (princ "\n<hr>\n")
341         (princ (format "mode=%S\n" mode))
342         (princ (format "user=%s\n" user))
343         ;; (princ (format "local user=%s\n" (user-login-name)))
344         (princ (format "lang=%S\n" lang))
345         (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
346         ;; (princ " CHISE ")
347         ;; (princ xemacs-chise-version)
348         (princ "
349 </body>
350 </html>")
351         )
352     (error nil
353            (princ (format "%S" err)))
354     ))
355
356 (provide 'cwiki-view)