コミットメタ情報

リビジョンfa378b39be6c9d540e6b3377c35b824208b07695 (tree)
日時2017-03-20 18:57:01
作者umorigu <umorigu@gmai...>
コミッターumorigu

ログメッセージ

BugTrack/2420 Use JSON for transforming AutoTicketLink site data

変更サマリ

差分

--- a/lib/html.php
+++ b/lib/html.php
@@ -195,21 +195,24 @@ function catbody($title, $page, $body)
195195 require(SKIN_FILE);
196196 }
197197
198+/**
199+ * Get data used by JavaScript modules
200+ */
198201 function get_html_scripting_data()
199202 {
200203 global $ticket_link_sites;
201204 if (!isset($ticket_link_sites) || !is_array($ticket_link_sites)) {
202205 return '';
203206 }
207+ // Require: PHP 5.4+
208+ if (!defined('JSON_UNESCAPED_UNICODE')) {
209+ return '';
210+ };
204211 $text = '';
205212 foreach ($ticket_link_sites as $s) {
206- $key = htmlsc($s['key']);
207- $type = htmlsc($s['type']);
208- $name = htmlsc($s['name']);
209- $detail = htmlsc($s['detail']);
210- $base_url = htmlsc($s['base_url']);
213+ $site_info_json = htmlsc(json_encode($s, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
211214 $text .= <<<EOS
212- <span class="pukiwiki-ticketlink-site" data-site="key=$key,type=$type,detail=$detail,name=$name,baseUrl=$base_url"></span>
215+ <span class="pukiwiki-ticketlink-site" data-site="$site_info_json"></span>
213216 EOS;
214217 $text .= "\n";
215218 }
--- a/skin/ticketlink.js
+++ b/skin/ticketlink.js
@@ -13,7 +13,7 @@ if (window.addEventListener) {
1313 var site = siteList[i];
1414 var m = keyText.match(site.re);
1515 if (m) {
16- return site.baseUrl + m[3];
16+ return site.base_url + m[3];
1717 }
1818 }
1919 return '';
@@ -56,22 +56,8 @@ if (window.addEventListener) {
5656 }
5757 function textToSiteInfo(siteDef) {
5858 if (!siteDef) return null;
59- var sp = siteDef.split(',');
60- var info = {};
61- sp.forEach(function(s) {
62- if (startsWith(s, 'key=')) {
63- info.key = s.substr('key='.length);
64- } else if (startsWith(s, 'type=')) {
65- info.type = s.substr('type='.length);
66- } else if (startsWith(s, 'name=')) {
67- info.name = s.substr('name='.length);
68- } else if (startsWith(s, 'detail=')) {
69- info.detail = s.substr('detail='.length);
70- } else if (startsWith(s, 'baseUrl=')) {
71- info.baseUrl = s.substr('baseUrl='.length);
72- }
73- });
74- if (info.key && info.type && info.name && info.baseUrl) {
59+ var info = JSON.parse(siteDef);
60+ if (info && info.key && info.type && info.name && info.base_url) {
7561 return info;
7662 }
7763 return null;
旧リポジトリブラウザで表示