From 2c2ce5dc6429628d5cb65528f8e1022ddff55376 Mon Sep 17 00:00:00 2001 From: MORIOKA Tomohiko Date: Fri, 20 Jun 2014 08:45:52 +0900 Subject: [PATCH] (est-hide-cgi-mode): New variable. (est-view-url-prefix): New variable. (est-uri-decode-feature-name-body): New function. (est-uri-encode-feature-name-body): New function. (www-uri-decode-feature-name): Use `est-uri-decode-feature-name-body'. (www-uri-encode-feature-name): Use `est-uri-encode-feature-name-body'. (www-uri-make-feature-name-url): Add implementation for `est-hide-cgi-mode'. (www-uri-decode-object): Support `est-hide-cgi-mode'; use `est-uri-decode-feature-name-body'. (www-uri-encode-object): Support `est-hide-cgi-mode'; use `est-uri-encode-feature-name-body'. (www-uri-make-object-url): Add implementation for `est-hide-cgi-mode'. --- cwiki-common.el | 166 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 132 insertions(+), 34 deletions(-) diff --git a/cwiki-common.el b/cwiki-common.el index c7d8335..f8f840c 100644 --- a/cwiki-common.el +++ b/cwiki-common.el @@ -33,6 +33,8 @@ (mount-char-attribute-table '*instance@morpheme-entry/zh-classical) +(defvar est-hide-cgi-mode nil) +(defvar est-view-url-prefix "..") (defvar chise-wiki-view-url "view.cgi") (defvar chise-wiki-edit-url "edit.cgi") @@ -301,49 +303,105 @@ ;;; @ URI representation ;;; +(defun est-uri-decode-feature-name-body (uri-feature) + (let ((len (length uri-feature)) + (i 0) + ch dest) + (while (< i len) + (setq dest + (concat + dest + (if (eq (aref uri-feature i) ?\.) + (if (and (< (+ i 2) len) + (eq (aref uri-feature (+ i 2)) ?\.)) + (prog1 + (cond + ((eq (setq ch (aref uri-feature (1+ i))) ?\.) + "/") + ((eq ch ?-) + "*") + (t + (substring uri-feature i (+ i 3)) + )) + (setq i (+ i 3))) + (setq i (1+ i)) + ".") + (prog1 + (char-to-string (aref uri-feature i)) + (setq i (1+ i))))))) + dest)) + +(defun est-uri-encode-feature-name-body (feature) + (mapconcat (lambda (c) + (cond ((eq c ?*) + ".-.") + ((eq c ?/) + "...") + (t (char-to-string c)))) + feature "")) + (defun www-uri-decode-feature-name (uri-feature) (let (feature) (setq uri-feature (decode-uri-string uri-feature 'utf-8-mcs-er)) (cond ((string-match "^from\\." uri-feature) - (intern (format "<-%s" (substring uri-feature (match-end 0)))) + (intern (format "<-%s" + (est-uri-decode-feature-name-body + (substring uri-feature (match-end 0))))) ) ((string-match "^to\\." uri-feature) - (intern (format "->%s" (substring uri-feature (match-end 0)))) + (intern (format "->%s" + (est-uri-decode-feature-name-body + (substring uri-feature (match-end 0))))) ) ((string-match "^rep\\." uri-feature) - (intern (format "=%s" (substring uri-feature (match-end 0)))) + (intern (format "=%s" + (est-uri-decode-feature-name-body + (substring uri-feature (match-end 0))))) ) ((string-match "^rep2\\." uri-feature) - (intern (format "==%s" (substring uri-feature (match-end 0)))) + (intern (format "==%s" + (est-uri-decode-feature-name-body + (substring uri-feature (match-end 0))))) ) ((string-match "^g\\." uri-feature) - (intern (format "=>>%s" (substring uri-feature (match-end 0)))) + (intern (format "=>>%s" + (est-uri-decode-feature-name-body + (substring uri-feature (match-end 0))))) ) ((string-match "^gi\\." uri-feature) - (intern (format "=>>>%s" (substring uri-feature (match-end 0)))) + (intern (format "=>>>%s" + (est-uri-decode-feature-name-body + (substring uri-feature (match-end 0))))) ) ((string-match "^gi\\([0-9]+\\)\\." uri-feature) (intern (format "=>>%s%s" (make-string (string-to-int (match-string 1 uri-feature)) ?>) - (substring uri-feature (match-end 0)))) + (est-uri-decode-feature-name-body + (substring uri-feature (match-end 0))))) ) ((string-match "^o\\." uri-feature) - (intern (format "=+>%s" (substring uri-feature (match-end 0)))) + (intern (format "=+>%s" + (est-uri-decode-feature-name-body + (substring uri-feature (match-end 0))))) ) ((string-match "^a\\." uri-feature) - (intern (format "=>%s" (substring uri-feature (match-end 0)))) + (intern (format "=>%s" + (est-uri-decode-feature-name-body + (substring uri-feature (match-end 0))))) ) ((string-match "^a\\([0-9]+\\)\\." uri-feature) (intern (format "%s>%s" (make-string (string-to-int (match-string 1 uri-feature)) ?=) - (substring uri-feature (match-end 0)))) + (est-uri-decode-feature-name-body + (substring uri-feature (match-end 0))))) ) - ((and (setq feature (intern (format "=>%s" uri-feature))) + ((and (setq uri-feature (est-uri-decode-feature-name-body uri-feature)) + (setq feature (intern (format "=>%s" uri-feature))) (find-charset feature)) feature) ((and (setq feature (intern (format "=>>%s" uri-feature))) @@ -361,52 +419,76 @@ (setq feature-name (symbol-name feature-name)) (cond ((string-match "^=\\+>\\([^=>]+\\)" feature-name) - (concat "o." (substring feature-name (match-beginning 1))) + (concat "o." + (est-uri-encode-feature-name-body + (substring feature-name (match-beginning 1)))) ) ((string-match "^=\\([^=>]+\\)" feature-name) - (concat "rep." (substring feature-name (match-beginning 1))) + (concat "rep." + (est-uri-encode-feature-name-body + (substring feature-name (match-beginning 1)))) ) ((string-match "^==\\([^=>]+\\)" feature-name) - (concat "rep2." (substring feature-name (match-beginning 1))) + (concat "rep2." + (est-uri-encode-feature-name-body + (substring feature-name (match-beginning 1)))) ) ((string-match "^=>>\\([^=>]+\\)" feature-name) - (concat "g." (substring feature-name (match-beginning 1))) + (concat "g." + (est-uri-encode-feature-name-body + (substring feature-name (match-beginning 1)))) ) ((string-match "^=>>>\\([^=>]+\\)" feature-name) - (concat "gi." (substring feature-name (match-beginning 1))) + (concat "gi." + (est-uri-encode-feature-name-body + (substring feature-name (match-beginning 1)))) ) ((string-match "^=>>\\(>+\\)" feature-name) (format "gi%d.%s" (length (match-string 1 feature-name)) - (substring feature-name (match-end 1))) + (est-uri-encode-feature-name-body + (substring feature-name (match-end 1)))) ) ((string-match "^=>\\([^=>]+\\)" feature-name) - (concat "a." (substring feature-name (match-beginning 1))) + (concat "a." + (est-uri-encode-feature-name-body + (substring feature-name (match-beginning 1)))) ) ((string-match "^\\(=+\\)>" feature-name) (format "a%d.%s" (length (match-string 1 feature-name)) - (substring feature-name (match-end 0))) + (est-uri-encode-feature-name-body + (substring feature-name (match-end 0)))) ) ((string-match "^->" feature-name) - (concat "to." (substring feature-name (match-end 0))) + (concat "to." + (est-uri-encode-feature-name-body + (substring feature-name (match-end 0)))) ) ((string-match "^<-" feature-name) - (concat "from." (substring feature-name (match-end 0))) + (concat "from." + (est-uri-encode-feature-name-body + (substring feature-name (match-end 0)))) ) - (t feature-name))) + (t (est-uri-encode-feature-name-body feature-name)))) (defun www-uri-make-feature-name-url (uri-genre uri-feature-name uri-object) - (format "%s?feature=%s&%s=%s" - chise-wiki-view-url uri-feature-name uri-genre uri-object)) + (if est-hide-cgi-mode + (format "../feature/%s&%s/%s" + uri-feature-name uri-genre uri-object) + (format "%s?feature=%s&%s=%s" + chise-wiki-view-url uri-feature-name uri-genre uri-object))) (defun www-uri-decode-object (genre char-rep) (let (ccs cpos) (cond - ((string-match "\\(%3A\\|:\\)" char-rep) + ((string-match (if est-hide-cgi-mode + "\\(%3D\\|=\\|%3A\\|:\\)" + "\\(%3A\\|:\\)") char-rep) (setq ccs (substring char-rep 0 (match-beginning 0)) cpos (substring char-rep (match-end 0))) (setq ccs (www-uri-decode-feature-name ccs)) + (setq cpos (est-uri-decode-feature-name-body cpos)) (cond ((string-match "^0x" cpos) (setq cpos @@ -483,19 +565,29 @@ (setq ccs (pop ccs-list)) (not (setq ret (encode-char object ccs 'defined-only))))) (cond (ret - (format "%s:0x%X" + (format (if est-hide-cgi-mode + "%s=0x%X" + "%s:0x%X") (www-uri-encode-feature-name ccs) ret)) ((and (setq ccs (car (split-char object))) (setq ret (encode-char object ccs))) - (format "%s:0x%X" + (format (if est-hide-cgi-mode + "%s=0x%X" + "%s:0x%X") (www-uri-encode-feature-name ccs) ret)) (t - (format "system-char-id:0x%X" + (format (if est-hide-cgi-mode + "system-char-id=0x%X" + "system-char-id:0x%X") (encode-char object 'system-char-id)) )))) - (format "rep.id:%s" (concord-object-id object)))) + (format (if est-hide-cgi-mode + "rep.id=%s" + "rep.id:%s") + (est-uri-encode-feature-name-body + (format "%s" (concord-object-id object)))))) (defun est-format-object (object &optional readable) (if (characterp object) @@ -508,11 +600,17 @@ (format "%s" ret)))) (defun www-uri-make-object-url (object &optional uri-object) - (format "%s?%s=%s" - chise-wiki-view-url - (est-object-genre object) - (or uri-object - (www-uri-encode-object object)))) + (if est-hide-cgi-mode + (format "%s/%s/%s" + est-view-url-prefix + (est-object-genre object) + (or uri-object + (www-uri-encode-object object))) + (format "%s?%s=%s" + chise-wiki-view-url + (est-object-genre object) + (or uri-object + (www-uri-encode-object object))))) ;;; @ Feature name presentation -- 1.7.10.4