X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=lib%2Fhtml.php;h=3ba8c3fc4c1486aa2d277eb27399464dc1be5557;hb=83a95d80e0fc3d8bdccf79fb1106a04903685090;hp=912747e2f260c79e7e70fdf67c6582be7390f605;hpb=a231078d196a86291a8c2ec879100cb93241834d;p=pukiwiki%2Fpukiwiki.git diff --git a/lib/html.php b/lib/html.php index 912747e..3ba8c3f 100644 --- a/lib/html.php +++ b/lib/html.php @@ -2,7 +2,7 @@ // PukiWiki - Yet another WikiWikiWeb clone. // html.php // Copyright -// 2002-2016 PukiWiki Development Team +// 2002-2018 PukiWiki Development Team // 2001-2002 Originally written by yu-ji // License: GPL v2 or (at your option) any later version // @@ -11,12 +11,13 @@ // Show page-content function catbody($title, $page, $body) { - global $script, $vars, $arg, $defaultpage, $whatsnew, $help_page, $hr; + global $vars, $arg, $defaultpage, $whatsnew, $help_page, $hr; global $attach_link, $related_link, $cantedit, $function_freeze; global $search_word_color, $_msg_word, $foot_explain, $note_hr, $head_tags; global $javascript, $nofollow; global $_LANG, $_LINK, $_IMAGE; global $auth_type, $auth_user; + global $html_meta_referrer_policy; global $pkwk_dtd; // XHTML 1.1, XHTML1.0, HTML 4.01 Transitional... global $page_title; // Title of this site @@ -24,9 +25,11 @@ function catbody($title, $page, $body) global $modifier; // Site administrator's web page global $modifierlink; // Site administrator's name + $script = get_base_uri(); $enable_login = false; $enable_logout = false; - if (AUTH_TYPE_FORM === $auth_type || AUTH_TYPE_EXTERNAL === $auth_type) { + if (AUTH_TYPE_FORM === $auth_type || AUTH_TYPE_EXTERNAL === $auth_type || + AUTH_TYPE_SAML === $auth_type) { if ($auth_user) { $enable_logout = true; } else { @@ -44,12 +47,9 @@ function catbody($title, $page, $body) $_page = isset($vars['page']) ? $vars['page'] : ''; $r_page = pagename_urlencode($_page); - + $is_edit_preview = isset($vars['preview']); // Canonical URL - $canonical_url = $script; - if ($_page !== $defaultpage) { - $canonical_url = $script . '?' . $r_page; - } + $canonical_url = get_page_uri($_page, PKWK_URI_ABSOLUTE); // Set $_LINK for skin $_LINK['add'] = "$script?cmd=add&page=$r_page"; @@ -59,27 +59,30 @@ function catbody($title, $page, $body) $_LINK['edit'] = "$script?cmd=edit&page=$r_page"; $_LINK['filelist'] = "$script?cmd=filelist"; $_LINK['freeze'] = "$script?cmd=freeze&page=$r_page"; - $_LINK['help'] = "$script?" . pagename_urlencode($help_page); + $_LINK['help'] = get_page_uri($help_page); $_LINK['list'] = "$script?cmd=list"; $_LINK['new'] = "$script?plugin=newpage&refer=$r_page"; $_LINK['rdf'] = "$script?cmd=rss&ver=1.0"; - $_LINK['recent'] = "$script?" . pagename_urlencode($whatsnew); - $_LINK['reload'] = $canonical_url; + $_LINK['recent'] = get_page_uri($whatsnew); + $_LINK['reload'] = get_page_uri($_page); $_LINK['rename'] = "$script?plugin=rename&refer=$r_page"; $_LINK['rss'] = "$script?cmd=rss"; $_LINK['rss10'] = "$script?cmd=rss&ver=1.0"; // Same as 'rdf' $_LINK['rss20'] = "$script?cmd=rss&ver=2.0"; $_LINK['search'] = "$script?cmd=search"; - $_LINK['top'] = "$script?" . pagename_urlencode($defaultpage); + $_LINK['top'] = get_page_uri($defaultpage); $_LINK['unfreeze'] = "$script?cmd=unfreeze&page=$r_page"; $_LINK['upload'] = "$script?plugin=attach&pcmd=upload&page=$r_page"; + $_LINK['canonical_url'] = $canonical_url; $login_link = "#LOGIN_ERROR"; // dummy link that is not used switch ($auth_type) { case AUTH_TYPE_FORM: $login_link = "$script?plugin=loginform&pcmd=login&page=$r_page"; break; case AUTH_TYPE_EXTERNAL: - $login_link = get_auth_external_login_url($_page, $_LINK['reload']); + case AUTH_TYPE_SAML: + $login_link = get_auth_external_login_url($_page, + get_page_uri($_page, PKWK_URI_ROOT)); break; } $_LINK['login'] = htmlsc($login_link); @@ -116,10 +119,11 @@ function catbody($title, $page, $body) // Last modification date (string) of the page $lastmodified = $is_read ? format_date(get_filetime($_page)) . - ' ' . get_pg_passage($_page, FALSE) : ''; + get_passage_html_span($_page) : ''; // List of attached files to the page - $attaches = ($attach_link && $is_read && exist_plugin_action('attach')) ? + $show_attaches = $is_read || arg_check('edit'); + $attaches = ($attach_link && $show_attaches && exist_plugin_action('attach')) ? attach_filelist() : ''; // List of related pages @@ -164,27 +168,26 @@ function catbody($title, $page, $body) arsort($keys, SORT_NUMERIC); $keys = get_search_words(array_keys($keys), TRUE); $id = 0; + $patterns = ''; foreach ($keys as $key=>$pattern) { - $s_key = htmlsc($key); - $pattern = '/' . + if (strlen($patterns) > 0) { + $patterns .= '|'; + } + $patterns .= '(' . $pattern . ')'; + } + if ($pattern) { + $whole_pattern = '/' . ']*>.*?<\/textarea>' . // Ignore textareas '|' . '<[^>]*>' . // Ignore tags '|' . '&[^;]+;' . // Ignore entities - '|' . '(' . $pattern . ')' . // $matches[1]: Regex for a search word + '|' . '(' . $patterns . ')' . // $matches[1]: Regex for a search word '/sS'; - $decorate_Nth_word = create_function( - '$matches', - 'return (isset($matches[1])) ? ' . - '\'\' . $matches[1] . \'\' : ' . - '$matches[0];' - ); - $body = preg_replace_callback($pattern, $decorate_Nth_word, $body); - $notes = preg_replace_callback($pattern, $decorate_Nth_word, $notes); - ++$id; + $body = preg_replace_callback($whole_pattern, '_decorate_Nth_word', $body); + $notes = preg_replace_callback($whole_pattern, '_decorate_Nth_word', $notes); } } + // Embed Scripting data + $html_scripting_data = get_html_scripting_data($_page, $is_edit_preview); // Compat: 'HTML convert time' without time about MenuBar and skin $taketime = elapsedtime(); @@ -192,20 +195,152 @@ function catbody($title, $page, $body) require(SKIN_FILE); } +function _decorate_Nth_word($matches) +{ + // $matches[0]: including both words to skip and to decorate + // $matches[1]: word to decorate + // $matches[2+]: indicates which keyword to decorate + $index = -1; + for ($i = 2; $i < count($matches); $i++) { + if (isset($matches[$i]) && $matches[$i]) { + $index = $i - 2; + break; + } + } + if (isset($matches[1])) { + // wordN highlight class: N=0...n + return '' . + $matches[0] . ''; + } + return $matches[0]; +} + +/** + * Get data used by JavaScript modules + * + * @param $page page name + * @param $in_editing true if preview in editing + */ +function get_html_scripting_data($page, $in_editing) +{ + global $ticket_link_sites, $plugin; + global $external_link_cushion_page, $external_link_cushion; + global $topicpath_title; + global $ticket_jira_default_site; + if (!isset($ticket_link_sites) || !is_array($ticket_link_sites)) { + return ''; + } + $is_utf8 = (bool)defined('PKWK_UTF8_ENABLE'); + // Require: PHP 5.4+ + $json_enabled = defined('JSON_UNESCAPED_UNICODE'); + if (!$json_enabled) { + $empty_data = <<