• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

コミットメタ情報

リビジョン81f97796e37ccac655be04bfed1faa11647b0556 (tree)
日時2017-09-27 04:53:51
作者umorigu <umorigu@gmai...>
コミッターumorigu

ログメッセージ

Improve encode_hint handling

変更サマリ

差分

--- a/lib/html.php
+++ b/lib/html.php
@@ -206,7 +206,7 @@ function get_html_scripting_data()
206206 if (!isset($ticket_link_sites) || !is_array($ticket_link_sites)) {
207207 return '';
208208 }
209- $is_utf8 = SOURCE_ENCODING === 'UTF-8';
209+ $is_utf8 = (bool)defined('PKWK_UTF8_ENABLE');
210210 // Require: PHP 5.4+
211211 $json_enabled = defined('JSON_UNESCAPED_UNICODE');
212212 if (!$json_enabled) {
--- a/plugin/search2.inc.php
+++ b/plugin/search2.inc.php
@@ -218,7 +218,7 @@ EOD;
218218 <noscript>
219219 <p>$_msg_unsupported_webbrowser $alt_msg</p>
220220 </noscript>
221-<p class="_plugin_search2_nosupport_message" style="display:block;">
221+<p class="_plugin_search2_nosupport_message" style="display:none;">
222222 $_msg_unsupported_webbrowser $alt_msg
223223 </p>
224224 <form action="$script" method="GET" class="_plugin_search2_form">
--- a/skin/search2.js
+++ b/skin/search2.js
@@ -304,7 +304,7 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
304304 // Remove this line from search target
305305 continue;
306306 } else if (line.match(/^#freeze(\W|$)/)) {
307- // Stil in header
307+ // Still in header
308308 } else {
309309 // Already in body
310310 isInAuthorHeader = false;
@@ -343,7 +343,6 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
343343 }
344344 }
345345 return blocks;
346- //return foundLines.join('\n');
347346 }
348347 function getSummary(bodyText, searchRegex) {
349348 return getTargetLines(bodyText, searchRegex);
@@ -392,10 +391,17 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
392391 return summary.join(' ').substring(0, 150);
393392 }
394393 function removeEncodeHint() {
395- var form = document.querySelector('form');
396- if (form && form.encode_hint && (typeof form.encode_hint.removeAttribute === 'function')) {
397- form.encode_hint.removeAttribute('name');
398- }
394+ // Remove 'encode_hint' if site charset is UTF-8
395+ var props = getSiteProps();
396+ if (!props.is_utf8) return;
397+ var forms = document.querySelectorAll('form');
398+ forEach(forms, function(form){
399+ if (form.cmd && form.cmd.value === 'search2') {
400+ if (form.encode_hint && (typeof form.encode_hint.removeAttribute === 'function')) {
401+ form.encode_hint.removeAttribute('name');
402+ }
403+ }
404+ });
399405 }
400406 function kickFirstSearch() {
401407 var form = document.querySelector('._plugin_search2_form');
@@ -436,12 +442,18 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
436442 forEach(f.querySelectorAll('input[name="base"]'), function(radio){
437443 if (radio.checked) base = radio.value;
438444 });
445+ var props = getSiteProps();
439446 var loc = document.location;
440- var url = loc.protocol + '//' + loc.host + loc.pathname +
441- '?cmd=search2' +
447+ var baseUri = loc.protocol + '//' + loc.host + loc.pathname;
448+ if (props.base_uri_pathname) {
449+ baseUri = props.base_uri_pathname;
450+ }
451+ var url = baseUri + '?' +
452+ (props.is_utf8 ? '' : 'encode_hint=\u3077' + '&') +
453+ 'cmd=search2' +
442454 '&q=' + encodeSearchText(q) +
443455 (base ? '&base=' + encodeURIComponent(base) : '');
444- e.preventDefault();
456+ e.preventDefault();
445457 setTimeout(function() {
446458 location.href = url;
447459 }, 1);
@@ -567,13 +579,18 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
567579 return false;
568580 }
569581 function isEnableServerFunctions() {
582+ var props = getSiteProps();
583+ if (props.json_enabled) return true;
584+ return false;
585+ }
586+ function getSiteProps() {
587+ var empty = {};
570588 var propsDiv = document.getElementById('pukiwiki-site-properties');
571- if (!propsDiv) return false;
589+ if (!propsDiv) return empty;
572590 var jsonE = propsDiv.querySelector('div[data-key="site-props"]');
573- if (!jsonE) return false;
591+ if (!jsonE) return emptry;
574592 var props = JSON.parse(jsonE.getAttribute('data-value'));
575- if (props.json_enabled) return true;
576- return false;
593+ return props || empty;
577594 }
578595 colorSearchTextInBody();
579596 if (! isEnabledFetchFunctions()) {