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