(www-batch-view): Accept "?char=&ENTITY-REFERENCE;".
[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/edit.cgi")
6 (defvar chise-wiki-add-url "edit/add.cgi")
7
8 (defun www-display-char-desc (uri-char &optional lang level)
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       (when (setq parents (www-char-feature char '<-denotational))
31         (princ (format "<p>%s %s</p>\n<hr>\n"
32                        (www-format-value-as-char-list parents)
33                        (www-format-feature-name '->denotational lang))))
34       (when (setq parents (www-char-feature char '<-subsumptive))
35         (princ (format "<p>%s %s</p>\n<hr>\n"
36                        (www-format-value-as-char-list parents)
37                        (www-format-feature-name '->subsumptive lang))))
38       (setq GlyphWiki-id (char-GlyphWiki-id char))
39       (princ (format "<h%d>%s%s</h%d>\n"
40                      level
41                      (www-format-encode-string (char-to-string char))
42                      (if GlyphWiki-id
43                          (format
44                           " <a href=\"http://glyphwiki.org/wiki/%s\"><img alt=\"%s\" src=\"http://glyphwiki.org/glyph/%s.50px.png\" /></a>"
45                           GlyphWiki-id
46                           GlyphWiki-id GlyphWiki-id)
47                        "")
48                      level))
49       (if (> level 1)
50           (princ "<ul>"))
51       (dolist (cell (sort (char-attribute-alist char)
52                           (lambda (a b)
53                             (char-attribute-name<
54                              (char-feature-name-sans-versions (car a))
55                              (char-feature-name-sans-versions (car b))))))
56         (setq logical-feature (char-feature-name-sans-versions (car cell)))
57         (unless (memq logical-feature displayed-features)
58           (push logical-feature displayed-features)
59           (princ
60            (if (= level 1)
61                "<p>\n"
62              "<li>\n"))
63           (princ
64            (www-format-eval-list
65             (or (char-feature-property logical-feature ; (car cell)
66                                        'format)
67                 '((name) " : " (value)))
68             char
69             logical-feature ; (car cell)
70             lang uri-char))
71           (princ
72            (format " <a href=\"%s?char=%s&feature=%s&format=wiki-text\"
73 ><input type=\"submit\" value=\"note\" /></a>"
74                    chise-wiki-edit-url
75                    (www-format-encode-string uri-char)
76                    (www-format-encode-string
77                     (www-uri-encode-feature-name
78                      (intern (format "%s*note"
79                                      logical-feature ; (car cell)
80                                      ))))))
81           (princ
82            (if (= level 1)
83                "</p>\n"
84              "<li>\n"))
85           ))
86       (princ
87        (if (= level 1)
88            "<p>\n"
89          "<li>\n"))
90       (princ
91        (format "<a href=\"%s?char=%s\"
92 ><input type=\"submit\" value=\"add feature\" /></a>
93 "
94                chise-wiki-add-url
95                (www-format-encode-string uri-char)))
96       (princ
97        (if (= level 1)
98            "<p>\n"
99          "<li>\n"))
100       (princ
101        "<form action=\"http://chise.zinbun.kyoto-u.ac.jp/ids-find\">\n")
102       (princ
103        (www-format-encode-string
104         (format "%c" char)))
105       (princ
106        (format
107         " <input type=\"text\" name=\"components\"
108 size=\"30\" maxlength=\"30\" value=\"%s\" />"
109         (encode-coding-string (char-to-string char) 'utf-8-jp-er)))
110       ;; (princ (www-format-encode-string "と"))
111       ;; (princ "<input type=\"text\" name=\"additional-components\"
112 size=\;; "30\" maxlength=\"30\" value=\"\" />")
113       (princ
114        (www-format-encode-string
115         "を\u542Bむ\u6F22\u5B57を\u63A2す"))
116       (princ " <input type=\"submit\" value=\"search\" />\n")
117       (princ "</form>\n")
118       (princ
119        (if (= level 1)
120            "</p>\n"
121          "<li>\n"))
122       )))
123
124 (defun www-display-feature-desc (uri-feature-name uri-char &optional lang)
125   (let ((feature-name (www-uri-decode-feature-name uri-feature-name))
126         (name@lang (intern (format "name@%s" lang))))
127     (princ
128      (encode-coding-string
129       (format "<head>
130 <title>CHISE-wiki feature: %s</title>
131 </head>\n"
132               feature-name)
133       'utf-8-mcs-er))
134     (princ "<body>\n")
135     (princ
136      (format "<h1>%s</h1>\n"
137              (www-format-encode-string
138               (symbol-name feature-name))))
139     (princ (format "<p>name : %s "
140                    (or (www-format-feature-name feature-name) "")))
141     (princ
142      (format " <a href=\"%s?feature=%s&property=name&format=string&char=%s\"
143 ><input type=\"submit\" value=\"edit\" /></a>"
144              chise-wiki-edit-url
145              uri-feature-name
146              uri-char))
147     ;; (www-html-display-text
148     ;;  (format "[[[edit|%s?feature=%s&property=name&char=%s]]]"
149     ;;          ;; (char-feature-property feature-name 'name)
150     ;;          chise-wiki-edit-url
151     ;;          uri-feature-name ; (www-uri-encode-feature-name feature-name)
152     ;;          uri-char))
153     (princ "</p>")
154     (when lang
155       (princ "<p>")
156       (princ
157        (www-format-encode-string
158         (format "%s : %s"
159                 name@lang
160                 (or (char-feature-property feature-name name@lang) ""))))
161       (princ
162        (format " <a href=\"%s?feature=%s&property=%s&format=string&char=%s\"
163 ><input type=\"submit\" value=\"edit\" /></a>"
164                chise-wiki-edit-url
165                uri-feature-name
166                name@lang
167                uri-char))
168       ;; (www-html-display-text
169       ;;  (format " [[[edit|%s?feature=%s&property=%s&char=%s]]]"
170       ;;          chise-wiki-edit-url
171       ;;          uri-feature-name
172       ;;          name@lang
173       ;;          uri-char))
174       (princ "</p>"))
175     (www-html-display-paragraph
176      (format "type : %s"
177              (or (www-feature-type feature-name)
178                  ;; (char-feature-property feature-name 'type)
179                  'generic)))
180     (princ (format "<p>value-format : %s "
181                    (www-format-value
182                     nil 'value-format 
183                     (or (www-feature-value-format feature-name)
184                         'default)
185                     'default
186                     'without-tags)))
187     ;; (www-html-display-paragraph
188     ;;  (format "value-format : %s"
189     ;;          (www-xml-format-list
190     ;;           (or (www-feature-value-format feature-name)
191     ;;               'default))))
192     (princ
193      (format
194       " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&char=%s\"
195 ><input type=\"submit\" value=\"edit\" /></a></p>"
196       chise-wiki-edit-url
197       uri-feature-name
198       uri-char))
199
200     (www-html-display-paragraph
201      (format "format : %s"
202              (www-xml-format-list
203               (or (char-feature-property feature-name 'format)
204                   '((name) " : " (value))))))
205     (www-html-display-paragraph
206      (format "description : %s"
207              (or (char-feature-property feature-name 'description)
208                  "")))
209     (when lang
210       (www-html-display-paragraph
211        (format "description@%s : %s"
212                lang
213                (or (char-feature-property
214                     feature-name
215                     (intern (format "description@%s" lang)))
216                    ""))))
217     ))
218   
219 (defun www-batch-view ()
220   (setq terminal-coding-system 'binary)
221   (condition-case err
222       (let* ((target (pop command-line-args-left))
223              (user (pop command-line-args-left))
224              (accept-language (pop command-line-args-left))
225              (lang
226               (intern
227                (car (split-string
228                      (car (split-string
229                            (car (split-string accept-language ","))
230                            ";"))
231                      "-"))))
232              ret)
233         (princ "Content-Type: text/html; charset=UTF-8
234
235 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
236             \"http://www.w3.org/TR/html4/loose.dtd\">
237 <html lang=\"ja\">
238 ")
239         (cond
240          ((stringp target)
241           (when (string-match "^char=\\(&[^&;]+;\\)" target)
242             (setq ret (match-end 0))
243             (setq target
244                   (concat "char="
245                           (www-uri-encode-char
246                            (www-uri-decode-char (match-string 1 target)))
247                           (substring target ret))))
248           (setq target
249                 (mapcar (lambda (cell)
250                           (if (string-match "=" cell)
251                               (cons
252                                (intern
253                                 (decode-uri-string
254                                  (substring cell 0 (match-beginning 0))
255                                  'utf-8-mcs-er))
256                                (substring cell (match-end 0)))
257                             (list (decode-uri-string cell 'utf-8-mcs-er))))
258                         (split-string target "&")))
259           (setq ret (car target))
260           (cond ((eq (car ret) 'char)
261                  (www-display-char-desc
262                   (cdr ret) ; (decode-uri-string (cdr ret) 'utf-8-mcs-er)
263                   lang)
264                  )
265                 ((eq (car ret) 'feature)
266                  (www-display-feature-desc
267                   (decode-uri-string (cdr ret) 'utf-8-mcs-er)
268                   (cdr (assq 'char target))
269                   ;; (decode-uri-string (cdr (assq 'char target)))
270                   lang)
271                  ))
272           ))
273         (princ "\n<hr>\n")
274         (princ (format "user=%s\n" user))
275         (princ (format "local user=%s\n" (user-login-name)))
276         (princ (format "lang=%S\n" lang))
277         (princ emacs-version)
278         (princ " CHISE ")
279         (princ xemacs-chise-version)
280         (princ "
281 </body>
282 </html>")
283         )
284     (error nil
285            (princ (format "%S" err)))
286     ))
287
288 (provide 'cwiki-view)