(www-edit-display-feature-input-box):
[chise/est.git] / cwiki-view.el
1 ;; -*- coding: utf-8-mcs-er -*-
2 (require 'cwiki-format)
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-edit-display-feature-input-box (char feature-name
9                                                 &optional format value)
10   (if (symbolp char)
11       (setq char (or (concord-decode-object '=id char 'feature)
12                      (concord-make-object 'feature char))))
13   (unless format
14     (setq format 'default))
15   (unless value
16     (setq value (www-get-feature-value char feature-name)))
17   (if (and (symbolp value)
18            (eq format 'wiki-text))
19       (setq value (list (list value))))
20   (princ
21    (format "<p><input type=\"text\" name=\"feature-name\"
22 size=\"32\" maxlength=\"256\" value=\"%s\">"
23            feature-name))
24   (princ (encode-coding-string " \u2190 " 'utf-8-mcs-er))
25   (princ
26    (format "%s<input type=\"text\" name=\"%s\"
27 size=\"64\" maxlength=\"256\" value=\"%s\">
28 <input type=\"submit\" value=\"set\" /></p>
29 "
30            (if (or (eq format 'HEX)(eq format 'hex))
31                "0x"
32              "")
33            format
34            (mapconcat (lambda (c)
35                         (cond
36                          ;; ((eq c ?<) "&amp;lt;")
37                          ;; ((eq c ?>) "&amp;gt;")
38                          ((eq c ?\u0022) "&quot;")
39                          (t
40                           (char-to-string c))))
41                       (est-format-list value format nil nil " ")
42                       "")))
43   )
44
45 (defun www-display-object-desc (genre uri-object &optional lang level simple
46                                       uri-feature-name-to-edit editing-format)
47   (unless level
48     (setq level 0))
49   (let ((object (www-uri-decode-object genre uri-object))
50         feature-name-to-edit
51         base-name-to-edit metadata-name-to-edit
52         without-header
53         logical-feature chise-wiki-displayed-features
54         parents
55         GlyphWiki-id ret object-spec)
56     (if (eq level 0)
57         (setq level 1
58               without-header nil)
59       (setq without-header t))
60     (when object
61       (when uri-feature-name-to-edit
62         (setq feature-name-to-edit
63               (www-uri-decode-feature-name uri-feature-name-to-edit))
64         (setq ret (symbol-name feature-name-to-edit))
65         (if (string-match "\\*" ret)
66             (setq base-name-to-edit (intern
67                                      (substring ret 0 (match-beginning 0)))
68                   metadata-name-to-edit (intern
69                                          (substring ret (match-end 0))))
70           (setq base-name-to-edit feature-name-to-edit))
71         (when (stringp editing-format)
72           (setq editing-format (intern editing-format))))
73       (when (and (eq genre 'character)
74                  (= (length uri-object) 1))
75         (setq uri-object (www-uri-encode-object object)))
76       (when (= level 1)
77         (princ
78          (encode-coding-string
79           (format "<head>
80 <title>EsT %s = %s</title>
81 </head>\n"
82                   genre
83                   (decode-uri-string uri-object 'utf-8-mcs-er))
84           'utf-8-mcs-er))
85         (princ "<body>\n"))
86       (when (eq genre 'character)
87         (dolist (feature (char-feature-property '$object 'additional-features))
88           (mount-char-attribute-table
89            (char-feature-name-at-domain feature '$rev=latest))))
90       (princ
91        (format
92         (if simple
93             "<div style=\"text-align:right;\">
94 <a href=\"edit/view.cgi?%s=%s\">
95 <input type=\"submit\" value=\"Edit\" />
96 </a>
97 <input type=\"submit\" value=\"New Account\" />
98 </div>
99 <hr />\n"
100           "<div style=\"text-align:right;\">
101 <a href=\"../view.cgi?%s=%s\">
102 <input type=\"submit\" value=\"Simple\" />
103 </a>
104 </div>
105 <hr />\n")
106         genre
107         uri-object))
108       (when (setq parents (www-get-feature-value object '<-denotational))
109         (princ (format "<p>%s %s</p>\n<hr>\n"
110                        (www-format-value-as-char-list parents)
111                        (www-format-feature-name '->denotational lang))))
112       (when (setq parents (www-get-feature-value object '<-subsumptive))
113         (princ (format "<p>%s %s</p>\n<hr>\n"
114                        (www-format-value-as-char-list parents)
115                        (www-format-feature-name '->subsumptive lang))))
116       (when (eq genre 'character)
117         (setq GlyphWiki-id (char-GlyphWiki-id object)))
118       (princ (format "<h%d>%s%s</h%d>\n"
119                      level
120                      (www-format-encode-string
121                       (est-format-object object)
122                       ;; (if (eq genre 'character)
123                       ;;     (char-to-string object)
124                       ;;   (format "%s" (concord-object-id object)))
125                       )
126                      (if GlyphWiki-id
127                          (format
128                           " <a href=\"http://glyphwiki.org/wiki/%s\"><img alt=\"%s\" src=\"http://glyphwiki.org/glyph/%s.50px.png\" /></a>"
129                           GlyphWiki-id
130                           GlyphWiki-id GlyphWiki-id)
131                        "")
132                      level))
133       (if (> level 1)
134           (princ "<ul>"))
135       (when feature-name-to-edit
136         (princ "<form action=\"set.cgi\" method=\"GET\">\n")
137         (princ
138          (encode-coding-string
139           (format "<p>(%s : <input type=\"text\" name=\"%s\"
140 size=\"30\" maxlength=\"30\" value=\"%s\">)</p>
141 "
142                   genre genre
143                   (decode-uri-string uri-object 'utf-8-mcs-er))
144           'utf-8-mcs-er)))
145       (setq object-spec
146             (if (eq genre 'character)
147                 (char-attribute-alist object)
148               (concord-object-spec object)))
149       (when feature-name-to-edit
150         (unless (assq base-name-to-edit object-spec)
151           (setq object-spec (cons (cons base-name-to-edit nil)
152                                   object-spec))))
153       (dolist (cell (sort object-spec
154                           (lambda (a b)
155                             (char-attribute-name<
156                              (char-feature-name-sans-versions (car a))
157                              (char-feature-name-sans-versions (car b))))))
158         (setq logical-feature (char-feature-name-sans-versions (car cell)))
159         (unless (memq logical-feature chise-wiki-displayed-features)
160           (push logical-feature chise-wiki-displayed-features)
161           (cond
162            ((and feature-name-to-edit
163                  (eq (car cell) feature-name-to-edit))
164             (www-edit-display-feature-input-box
165              object feature-name-to-edit editing-format)
166             )
167            (t
168             (princ
169              (if (= level 1)
170                  "<div class=\"feature\" style=\"line-height:150%\">\n"
171                "<li>\n"))
172             (princ
173              (www-format-eval-list
174               (www-feature-format logical-feature)
175               object
176               logical-feature ; (car cell)
177               lang uri-object
178               nil simple))
179             (unless simple
180               (princ
181                (format " <a href=\"%s?%s=%s&feature=%s&format=wiki-text\"
182 ><input type=\"submit\" value=\"note\" /></a>"
183                        chise-wiki-edit-url
184                        genre
185                        (www-format-encode-string uri-object)
186                        (www-format-encode-string
187                         (www-uri-encode-feature-name
188                          (intern (format "%s*note"
189                                          logical-feature ; (car cell)
190                                          )))))))
191             (when (and feature-name-to-edit
192                        (eq base-name-to-edit (car cell)) metadata-name-to-edit)
193               (princ "<ul>\n")
194               (princ "<li>")
195               (www-edit-display-feature-input-box
196                object feature-name-to-edit editing-format)
197               (princ "</li>")
198               (princ "</ul>"))
199             (princ
200              (if (= level 1)
201                  "</div>\n"
202                "<li>\n"))
203             ))
204           ))
205       (princ
206        (if (= level 1)
207            "<p>\n"
208          "<li>\n"))
209       (when feature-name-to-edit
210         (princ "</form>\n"))
211       (unless simple
212         (princ
213          (format "<a href=\"%s?%s=%s\"
214 ><input type=\"submit\" value=\"add feature\" /></a>
215 "
216                  chise-wiki-add-url
217                  genre
218                  (www-format-encode-string uri-object))))
219       (princ
220        (if (= level 1)
221            "<p>\n"
222          "<li>\n"))
223       (when (eq genre 'character)
224         (princ
225          "<form action=\"http://www.chise.org/ids-find\">\n")
226         (princ
227          (www-format-encode-string
228           (est-format-object object)
229           ;; (if (eq genre 'character)
230           ;;     (format "%c" object)
231           ;;   (format "%s" (concord-object-id object)))
232           ))
233         (princ
234          (format
235           " <input type=\"text\" name=\"components\"
236 size=\"30\" maxlength=\"30\" value=\"%s\" />"
237           (encode-coding-string
238            (est-format-object object)
239            ;; (if (eq genre 'character)
240            ;;     (char-to-string object)
241            ;;   (format "%s" (concord-object-id object)))
242            'utf-8-jp-er)))
243         (princ
244          (www-format-encode-string
245           "を\u542Bむ\u6F22\u5B57を\u63A2す"))
246         (princ " <input type=\"submit\" value=\"search\" />\n")
247         (princ "</form>\n"))
248       (princ
249        (if (= level 1)
250            "</p>\n"
251          "<li>\n"))
252       )))
253
254 (defun www-display-feature-desc (uri-feature-name genre uri-object
255                                                   &optional lang simple)
256   (let ((feature-name (www-uri-decode-feature-name uri-feature-name))
257         (name@lang (intern (format "name@%s" lang))))
258     (princ
259      (encode-coding-string
260       (format "<head>
261 <title>EsT feature: %s</title>
262 </head>\n"
263               feature-name)
264       'utf-8-mcs-er))
265     (princ "<body>\n")
266     (princ
267      (format
268       (if simple
269           "<div style=\"text-align:right;\">
270 <a href=\"edit/view.cgi?feature=%s&%s=%s\">
271 <input type=\"submit\" value=\"Edit\" />
272 </a>
273 <input type=\"submit\" value=\"New Account\" />
274 </div>
275 <hr />\n"
276           "<div style=\"text-align:right;\">
277 <a href=\"../view.cgi?feature=%s&%s=%s\">
278 <input type=\"submit\" value=\"Simple\" />
279 </a>
280 </div>
281 <hr />\n")
282       uri-feature-name genre uri-object))
283     (princ
284      (format "<h1>%s</h1>\n"
285              (www-format-encode-string
286               (symbol-name feature-name))))
287     (princ (format "<p>name : %s "
288                    (or (www-format-feature-name feature-name) "")))
289     (unless simple
290       (princ
291        (format
292         " <a href=\"%s?feature=%s&property=name&format=string&%s=%s\">"
293         chise-wiki-edit-url
294         uri-feature-name
295         genre
296         uri-object))
297       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
298     (princ "</p>\n")
299     (when lang
300       (princ "<p>")
301       (princ
302        (www-format-encode-string
303         (format "%s : %s"
304                 name@lang
305                 (or (char-feature-property feature-name name@lang) ""))))
306       (unless simple
307         (princ
308          (format
309           " <a href=\"%s?feature=%s&property=%s&format=string&%s=%s\">"
310           chise-wiki-edit-url
311           uri-feature-name
312           name@lang
313           genre
314           uri-object))
315         (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
316       (princ "</p>\n"))
317     (www-html-display-paragraph
318      (format "type : %s"
319              (or (www-feature-type feature-name)
320                  ;; (char-feature-property feature-name 'type)
321                  'generic)))
322     (princ (format "<p>value-format : %s "
323                    (www-format-value
324                     nil 'value-format 
325                     (or (www-feature-value-format feature-name)
326                         'default)
327                     'default
328                     'without-tags)
329                    ))
330     (unless simple
331       (princ
332        (format
333         " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&%s=%s\"
334 >"
335         chise-wiki-edit-url
336         uri-feature-name
337         genre
338         uri-object))
339       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
340     (princ "</p>\n")
341
342     (princ "<p>format : ")
343     (www-html-display-text
344      (decode-coding-string
345       (www-xml-format-list
346        (www-feature-format feature-name))
347       'utf-8-mcs-er))
348     (unless simple
349       (princ
350        (format
351         " <a href=\"%s?feature=%s&property=format&format=wiki-text&%s=%s\"
352 >"
353         chise-wiki-edit-url
354         uri-feature-name
355         genre
356         uri-object))
357       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
358     (princ "</p>\n")
359     
360     (www-html-display-paragraph
361      (format "description : %s"
362              (or (char-feature-property feature-name 'description)
363                  "")))
364     (when lang
365       (www-html-display-paragraph
366        (format "description@%s : %s"
367                lang
368                (or (char-feature-property
369                     feature-name
370                     (intern (format "description@%s" lang)))
371                    ""))))
372     ))
373   
374 (defun www-batch-view ()
375   (setq terminal-coding-system 'binary)
376   (condition-case err
377       (let* ((target (pop command-line-args-left))
378              (user (pop command-line-args-left))
379              (accept-language (pop command-line-args-left))
380              (mode (intern (pop command-line-args-left)))
381              (lang
382               (intern
383                (car (split-string
384                      (car (split-string
385                            (car (split-string accept-language ","))
386                            ";"))
387                      "-"))))
388              ret)
389         (princ "Content-Type: text/html; charset=UTF-8
390
391 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
392             \"http://www.w3.org/TR/html4/loose.dtd\">
393 <html lang=\"ja\">
394 ")
395         (cond
396          ((stringp target)
397           (when (string-match "^char=\\(&[^&;]+;\\)" target)
398             (setq ret (match-end 0))
399             (setq target
400                   (concat "char="
401                           (www-uri-encode-object
402                            (www-uri-decode-object
403                             'character (match-string 1 target)))
404                           (substring target ret))))
405           (setq target
406                 (mapcar (lambda (cell)
407                           (if (string-match "=" cell)
408                               (cons
409                                (intern
410                                 (decode-uri-string
411                                  (substring cell 0 (match-beginning 0))
412                                  'utf-8-mcs-er))
413                                (substring cell (match-end 0)))
414                             (list (decode-uri-string cell 'utf-8-mcs-er))))
415                         (split-string target "&")))
416           (setq ret (car target))
417           (cond ((eq (car ret) 'char)
418                  (www-display-object-desc
419                   'character
420                   (cdr ret)
421                   lang nil
422                   (eq mode 'simple))
423                  )
424                 ((eq (car ret) 'feature)
425                  (www-display-feature-desc
426                   (decode-uri-string (cdr ret) 'utf-8-mcs-er)
427                   (car (nth 1 target))
428                   (cdr (nth 1 target))
429                   lang
430                   (eq mode 'simple))
431                  )
432                 (t
433                  (www-display-object-desc
434                   (car ret)
435                   (cdr ret)
436                   lang nil
437                   (eq mode 'simple))
438                  ))
439           ))
440         (princ "\n<hr>\n")
441         (princ (format "mode=%S\n" mode))
442         (princ (format "user=%s\n" user))
443         ;; (princ (format "local user=%s\n" (user-login-name)))
444         (princ (format "lang=%S\n" lang))
445         (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
446         ;; (princ " CHISE ")
447         ;; (princ xemacs-chise-version)
448         (princ "
449 </body>
450 </html>")
451         )
452     (error nil
453            (princ (format "%S" err)))
454     ))
455
456 (provide 'cwiki-view)