(www-display-char-desc): Try to display glyph of GlyphWiki and link
[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< (car a)(car b)))))
54         (setq logical-feature (char-feature-name-sans-versions (car cell)))
55         (unless (memq logical-feature displayed-features)
56           (push logical-feature displayed-features)
57           (princ
58            (if (= level 1)
59                "<p>\n"
60              "<li>\n"))
61           (princ
62            (www-format-eval-list
63             (or (char-feature-property logical-feature ; (car cell)
64                                        'format)
65                 '((name) " : " (value)))
66             char
67             logical-feature ; (car cell)
68             lang uri-char))
69           (princ
70            (format " <a href=\"%s?char=%s&feature=%s&format=wiki-text\"
71 ><input type=\"submit\" value=\"note\" /></a>"
72                    chise-wiki-edit-url
73                    (www-format-encode-string uri-char)
74                    (www-format-encode-string
75                     (www-uri-encode-feature-name
76                      (intern (format "%s*note"
77                                      logical-feature ; (car cell)
78                                      ))))))
79           (princ
80            (if (= level 1)
81                "</p>\n"
82              "<li>\n"))
83           ))
84       (princ
85        (if (= level 1)
86            "<p>\n"
87          "<li>\n"))
88       (princ
89        (format "<a href=\"%s?char=%s\"
90 ><input type=\"submit\" value=\"add feature\" /></a>
91 "
92                chise-wiki-add-url
93                (www-format-encode-string uri-char)))
94       (princ
95        (if (= level 1)
96            "</p>\n"
97          "<li>\n"))
98       )))
99
100 (defun www-display-feature-desc (uri-feature-name uri-char &optional lang)
101   (let ((feature-name (www-uri-decode-feature-name uri-feature-name))
102         (name@lang (intern (format "name@%s" lang))))
103     (princ
104      (encode-coding-string
105       (format "<head>
106 <title>CHISE-wiki feature: %s</title>
107 </head>\n"
108               feature-name)
109       'utf-8-mcs-er))
110     (princ "<body>\n")
111     (princ
112      (format "<h1>%s</h1>\n"
113              (www-format-encode-string
114               (symbol-name feature-name))))
115     (princ (format "<p>name : %s "
116                    (or (www-format-feature-name feature-name) "")))
117     (princ
118      (format " <a href=\"%s?feature=%s&property=name&format=string&char=%s\"
119 ><input type=\"submit\" value=\"edit\" /></a>"
120              chise-wiki-edit-url
121              uri-feature-name
122              uri-char))
123     ;; (www-html-display-text
124     ;;  (format "[[[edit|%s?feature=%s&property=name&char=%s]]]"
125     ;;          ;; (char-feature-property feature-name 'name)
126     ;;          chise-wiki-edit-url
127     ;;          uri-feature-name ; (www-uri-encode-feature-name feature-name)
128     ;;          uri-char))
129     (princ "</p>")
130     (when lang
131       (princ "<p>")
132       (princ
133        (www-format-encode-string
134         (format "%s : %s"
135                 name@lang
136                 (or (char-feature-property feature-name name@lang) ""))))
137       (princ
138        (format " <a href=\"%s?feature=%s&property=%s&format=string&char=%s\"
139 ><input type=\"submit\" value=\"edit\" /></a>"
140                chise-wiki-edit-url
141                uri-feature-name
142                name@lang
143                uri-char))
144       ;; (www-html-display-text
145       ;;  (format " [[[edit|%s?feature=%s&property=%s&char=%s]]]"
146       ;;          chise-wiki-edit-url
147       ;;          uri-feature-name
148       ;;          name@lang
149       ;;          uri-char))
150       (princ "</p>"))
151     (www-html-display-paragraph
152      (format "type : %s"
153              (or (www-feature-type feature-name)
154                  ;; (char-feature-property feature-name 'type)
155                  'generic)))
156     (princ (format "<p>value-format : %s "
157                    (www-format-value
158                     nil 'value-format 
159                     (or (www-feature-value-format feature-name)
160                         'default)
161                     'default
162                     'without-tags)))
163     ;; (www-html-display-paragraph
164     ;;  (format "value-format : %s"
165     ;;          (www-xml-format-list
166     ;;           (or (www-feature-value-format feature-name)
167     ;;               'default))))
168     (princ
169      (format
170       " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&char=%s\"
171 ><input type=\"submit\" value=\"edit\" /></a></p>"
172       chise-wiki-edit-url
173       uri-feature-name
174       uri-char))
175
176     (www-html-display-paragraph
177      (format "format : %s"
178              (www-xml-format-list
179               (or (char-feature-property feature-name 'format)
180                   '((name) " : " (value))))))
181     (www-html-display-paragraph
182      (format "description : %s"
183              (or (char-feature-property feature-name 'description)
184                  "")))
185     (when lang
186       (www-html-display-paragraph
187        (format "description@%s : %s"
188                lang
189                (or (char-feature-property
190                     feature-name
191                     (intern (format "description@%s" lang)))
192                    ""))))
193     ))
194   
195 (defun www-batch-view ()
196   (setq terminal-coding-system 'binary)
197   (condition-case err
198       (let* ((target (pop command-line-args-left))
199              (user (pop command-line-args-left))
200              (accept-language (pop command-line-args-left))
201              (lang
202               (intern
203                (car (split-string
204                      (car (split-string
205                            (car (split-string accept-language ","))
206                            ";"))
207                      "-"))))
208              ret)
209         (princ "Content-Type: text/html; charset=UTF-8
210
211 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
212             \"http://www.w3.org/TR/html4/loose.dtd\">
213 <html lang=\"ja\">
214 ")
215         (cond
216          ((stringp target)
217           (setq target
218                 (mapcar (lambda (cell)
219                           (if (string-match "=" cell)
220                               (cons
221                                (intern
222                                 (decode-uri-string
223                                  (substring cell 0 (match-beginning 0))
224                                  'utf-8-mcs-er))
225                                (substring cell (match-end 0)))
226                             (list (decode-uri-string cell 'utf-8-mcs-er))))
227                         (split-string target "&")))
228           (setq ret (car target))
229           (cond ((eq (car ret) 'char)
230                  (www-display-char-desc
231                   (cdr ret) ; (decode-uri-string (cdr ret) 'utf-8-mcs-er)
232                   lang)
233                  )
234                 ((eq (car ret) 'feature)
235                  (www-display-feature-desc
236                   (decode-uri-string (cdr ret) 'utf-8-mcs-er)
237                   (cdr (assq 'char target))
238                   ;; (decode-uri-string (cdr (assq 'char target)))
239                   lang)
240                  ))
241           ))
242         (princ "\n<hr>\n")
243         (princ (format "user=%s\n" user))
244         (princ (format "local user=%s\n" (user-login-name)))
245         (princ (format "lang=%S\n" lang))
246         (princ emacs-version)
247         (princ " CHISE ")
248         (princ xemacs-chise-version)
249         (princ "
250 </body>
251 </html>")
252         )
253     (error nil
254            (princ (format "%S" err)))
255     ))
256
257 (provide 'cwiki-view)