<?php
-/////////////////////////////////////////////////
// PukiWiki - Yet another WikiWikiWeb clone.
+// html.php
+// Copyright
+// 2002-2017 PukiWiki Development Team
+// 2001-2002 Originally written by yu-ji
+// License: GPL v2 or (at your option) any later version
//
-// $Id: html.php,v 1.3 2004/10/03 07:05:34 henoheno Exp $
-//
+// HTML-publishing related functions
-// ËÜʸ¤ò½ÐÎÏ
-function catbody($title,$page,$body)
+// Show page-content
+function catbody($title, $page, $body)
{
- global $script, $vars, $arg, $defaultpage, $whatsnew, $help_page, $hr;
- global $related_link, $cantedit, $function_freeze, $search_word_color, $_msg_word;
- global $foot_explain, $note_hr, $head_tags, $trackback, $referer;
+ 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 $pkwk_dtd; // XHTML 1.1, XHTML1.0, HTML 4.01 Transitional...
+ global $page_title; // Title of this site
+ global $do_backup; // Do backup or not
+ 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 ||
+ AUTH_TYPE_SAML === $auth_type) {
+ if ($auth_user) {
+ $enable_logout = true;
+ } else {
+ $enable_login = true;
+ }
+ } else if (AUTH_TYPE_BASIC === $auth_type) {
+ if ($auth_user) {
+ $enable_logout = true;
+ }
+ }
+ if (! file_exists(SKIN_FILE) || ! is_readable(SKIN_FILE))
+ die_message('SKIN_FILE is not found');
- global $html_transitional; // FALSE:XHTML1.1 TRUE:XHTML1.0 Transitional
- global $page_title; // ¥Û¡¼¥à¥Ú¡¼¥¸¤Î¥¿¥¤¥È¥ë
- global $do_backup; // ¥Ð¥Ã¥¯¥¢¥Ã¥×¤ò¹Ô¤¦¤«¤É¤¦¤«
- global $modifier; // ÊÔ½¸¼Ô¤Î¥Û¡¼¥à¥Ú¡¼¥¸
- global $modifierlink; // ÊÔ½¸¼Ô¤Î̾Á°
-
- $_LANG = $_LINK = $_IMAGE = array();
+ $_LINK = $_IMAGE = array();
$_page = isset($vars['page']) ? $vars['page'] : '';
- $r_page = rawurlencode($_page);
+ $r_page = pagename_urlencode($_page);
+
+ // Canonical URL
+ $canonical_url = get_page_uri($_page, PKWK_URI_ABSOLUTE);
// Set $_LINK for skin
$_LINK['add'] = "$script?cmd=add&page=$r_page";
$_LINK['edit'] = "$script?cmd=edit&page=$r_page";
$_LINK['filelist'] = "$script?cmd=filelist";
$_LINK['freeze'] = "$script?cmd=freeze&page=$r_page";
- $_LINK['help'] = "$script?" . rawurlencode($help_page);
+ $_LINK['help'] = get_page_uri($help_page);
$_LINK['list'] = "$script?cmd=list";
$_LINK['new'] = "$script?plugin=newpage&refer=$r_page";
- $_LINK['recent'] = "$script?" . rawurlencode($whatsnew);
- $_LINK['refer'] = "$script?plugin=referer&page=$r_page";
- $_LINK['reload'] = "$script?$r_page";
+ $_LINK['rdf'] = "$script?cmd=rss&ver=1.0";
+ $_LINK['recent'] = get_page_uri($whatsnew);
+ $_LINK['reload'] = get_page_uri($_page);
$_LINK['rename'] = "$script?plugin=rename&refer=$r_page";
- $_LINK['rss'] = "$script?cmd=rss10";
+ $_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?" . rawurlencode($defaultpage);
- if ($trackback) {
- $tb_id = tb_get_id($_page);
- $_LINK['trackback'] = "$script?plugin=tb&__mode=view&tb_id=$tb_id";
- }
+ $_LINK['top'] = get_page_uri($defaultpage);
$_LINK['unfreeze'] = "$script?cmd=unfreeze&page=$r_page";
$_LINK['upload'] = "$script?plugin=attach&pcmd=upload&page=$r_page";
-
- // ¥Ú¡¼¥¸¤Îɽ¼¨»þTRUE(¥Ð¥Ã¥¯¥¢¥Ã¥×¤Îɽ¼¨¡¢RecentChanges¤Îɽ¼¨¤ò½ü¤¯)
- $is_page = (is_pagename($_page) and !arg_check('backup') and $_page != $whatsnew);
-
- // ¥Ú¡¼¥¸¤ÎÆɤ߽Ф·»þTRUE
- $is_read = (arg_check('read') and is_page($_page));
-
- // ¥Ú¡¼¥¸¤¬Åà·ë¤µ¤ì¤Æ¤¤¤ë¤È¤TRUE
+ $_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:
+ case AUTH_TYPE_SAML:
+ $login_link = get_auth_external_login_url($_page, $_LINK['reload']);
+ break;
+ }
+ $_LINK['login'] = htmlsc($login_link);
+ $_LINK['logout'] = "$script?plugin=loginform&pcmd=logout&page=$r_page";
+
+ // Compat: Skins for 1.4.4 and before
+ $link_add = & $_LINK['add'];
+ $link_new = & $_LINK['new']; // New!
+ $link_edit = & $_LINK['edit'];
+ $link_diff = & $_LINK['diff'];
+ $link_top = & $_LINK['top'];
+ $link_list = & $_LINK['list'];
+ $link_filelist = & $_LINK['filelist'];
+ $link_search = & $_LINK['search'];
+ $link_whatsnew = & $_LINK['recent'];
+ $link_backup = & $_LINK['backup'];
+ $link_help = & $_LINK['help'];
+ $link_trackback = ''; // Removed (compat)
+ $link_rdf = & $_LINK['rdf']; // New!
+ $link_rss = & $_LINK['rss'];
+ $link_rss10 = & $_LINK['rss10']; // New!
+ $link_rss20 = & $_LINK['rss20']; // New!
+ $link_freeze = & $_LINK['freeze'];
+ $link_unfreeze = & $_LINK['unfreeze'];
+ $link_upload = & $_LINK['upload'];
+ $link_template = & $_LINK['copy'];
+ $link_refer = ''; // Removed (compat)
+ $link_rename = & $_LINK['rename'];
+
+ // Init flags
+ $is_page = (is_pagename($_page) && ! arg_check('backup') && $_page != $whatsnew);
+ $is_read = (arg_check('read') && is_page($_page));
$is_freeze = is_freeze($_page);
- // ¥Ú¡¼¥¸¤ÎºÇ½ª¹¹¿·»þ¹ï(ʸ»úÎó)
- $lastmodified = $is_read ?
- get_date('D, d M Y H:i:s T',get_filetime($_page)).' '.get_pg_passage($_page,FALSE) : '';
+ // Last modification date (string) of the page
+ $lastmodified = $is_read ? format_date(get_filetime($_page)) .
+ get_passage_html_span($_page) : '';
- // ´ØÏ¢¤¹¤ë¥Ú¡¼¥¸¤Î¥ê¥¹¥È
- $related = ($is_read and $related_link) ? make_related($_page) : '';
+ // List of attached files to the page
+ $show_attaches = $is_read || arg_check('edit');
+ $attaches = ($attach_link && $show_attaches && exist_plugin_action('attach')) ?
+ attach_filelist() : '';
- // źÉÕ¥Õ¥¡¥¤¥ë¤Î¥ê¥¹¥È
- $attaches = ($is_read and exist_plugin_action('attach')) ? attach_filelist() : '';
+ // List of related pages
+ $related = ($related_link && $is_read) ? make_related($_page) : '';
- // Ãí¼á¤Î¥ê¥¹¥È
- ksort($foot_explain,SORT_NUMERIC);
- $notes = count($foot_explain) ? $note_hr.join("\n",$foot_explain) : '';
+ // List of footnotes
+ ksort($foot_explain, SORT_NUMERIC);
+ $notes = ! empty($foot_explain) ? $note_hr . join("\n", $foot_explain) : '';
- // <head>Æâ¤ËÄɲ乤륿¥°
- $head_tag = count($head_tags) ? join("\n",$head_tags)."\n" : '';
+ // Tags will be inserted into <head></head>
+ $head_tag = ! empty($head_tags) ? join("\n", $head_tags) ."\n" : '';
// 1.3.x compat
- // ¥Ú¡¼¥¸¤ÎºÇ½ª¹¹¿·»þ¹ï(UNIX timestamp)
+ // Last modification date (UNIX timestamp) of the page
$fmt = $is_read ? get_filetime($_page) + LOCALZONE : 0;
- //ñ¸ì¸¡º÷
- if ($search_word_color and array_key_exists('word',$vars))
- {
- $body = '<div class="small">'.$_msg_word.htmlspecialchars($vars['word'])."</div>$hr\n$body";
- $words = array_flip(array_splice(preg_split('/\s+/',$vars['word'],-1,PREG_SPLIT_NO_EMPTY),0,10));
- $keys = array();
- foreach ($words as $word=>$id)
- {
- $keys[$word] = strlen($word);
+ // Output nofollow / noindex regardless os skin file
+ if (!$is_read || $nofollow) {
+ if (!headers_sent()) {
+ header("X-Robots-Tag: noindex,nofollow");
}
- arsort($keys,SORT_NUMERIC);
- $keys = get_search_words(array_keys($keys),TRUE);
+ }
+
+ // Send Canonical URL for Search Engine Optimization
+ if ($is_read && !headers_sent()) {
+ header("Link: <$canonical_url>; rel=\"canonical\"");
+ }
+
+ // Search words
+ if ($search_word_color && isset($vars['word'])) {
+ $body = '<div class="small">' . $_msg_word . htmlsc($vars['word']) .
+ '</div>' . $hr . "\n" . $body;
+
+ // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
+ // with array_splice(), array_flip()
+ $words = preg_split('/\s+/', $vars['word'], -1, PREG_SPLIT_NO_EMPTY);
+ $words = array_splice($words, 0, 10); // Max: 10 words
+ $words = array_flip($words);
+
+ $keys = array();
+ foreach ($words as $word=>$id) $keys[$word] = strlen($word);
+ arsort($keys, SORT_NUMERIC);
+ $keys = get_search_words(array_keys($keys), TRUE);
$id = 0;
- foreach ($keys as $key=>$pattern)
- {
- $s_key = htmlspecialchars($key);
- $pattern = "/<[^>]*>|($pattern)|&[^;]+;/";
- $callback = create_function(
- '$arr',
- 'return (count($arr) > 1) ? "<strong class=\"word'.$id++.'\">{$arr[1]}</strong>" : $arr[0];'
- );
- $body = preg_replace_callback($pattern,$callback,$body);
- $notes = preg_replace_callback($pattern,$callback,$notes);
+ $patterns = '';
+ foreach ($keys as $key=>$pattern) {
+ if (strlen($patterns) > 0) {
+ $patterns .= '|';
+ }
+ $patterns .= '(' . $pattern . ')';
+ }
+ if ($pattern) {
+ $whole_pattern = '/' .
+ '<textarea[^>]*>.*?<\/textarea>' . // Ignore textareas
+ '|' . '<[^>]*>' . // Ignore tags
+ '|' . '&[^;]+;' . // Ignore entities
+ '|' . '(' . $patterns . ')' . // $matches[1]: Regex for a search word
+ '/sS';
+ $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();
- $longtaketime = getmicrotime() - MUTIME;
- $taketime = sprintf('%01.03f',$longtaketime);
+ // Compat: 'HTML convert time' without time about MenuBar and skin
+ $taketime = elapsedtime();
- if (!file_exists(SKIN_FILE)||!is_readable(SKIN_FILE))
- {
- die_message(SKIN_FILE.'(skin file) is not found.');
- }
require(SKIN_FILE);
}
-// ¥¤¥ó¥é¥¤¥óÍ×ÁǤΥѡ¼¥¹ (obsolete)
-function inline($line,$remove=FALSE)
+function _decorate_Nth_word($matches)
{
- global $NotePattern;
-
- $line = htmlspecialchars($line);
- if ($remove)
- {
- $line = preg_replace($NotePattern,'',$line);
+ // $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 '<strong class="word' . $index . '">' .
+ $matches[0] . '</strong>';
}
- return $line;
+ return $matches[0];
}
-// ¥¤¥ó¥é¥¤¥óÍ×ÁǤΥѡ¼¥¹ (¥ê¥ó¥¯¡¢¸«½Ð¤·°ìÍ÷) (obsolete)
-function inline2($str)
+/**
+ * Get data used by JavaScript modules
+ */
+function get_html_scripting_data()
{
- return make_link($str);
+ global $ticket_link_sites, $plugin;
+ 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 = <<<EOS
+<div id="pukiwiki-site-properties" style="display:none;">
+</div>
+EOS;
+ return $empty_data;
+ }
+ // Site basic Properties
+ $props = array(
+ 'is_utf8' => $is_utf8,
+ 'json_enabled' => $json_enabled,
+ 'base_uri_pathname' => get_base_uri(PKWK_URI_ROOT),
+ 'base_uri_absolute' => get_base_uri(PKWK_URI_ABSOLUTE)
+ );
+ $props_json = htmlsc(json_encode($props, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
+ $site_props = <<<EOS
+<div data-key="site-props" data-value="$props_json"></div>
+EOS;
+ $h_plugin = htmlsc($plugin);
+ $plugin_prop = <<<EOS
+<input type="hidden" class="plugin-name" value="$h_plugin" />
+EOS;
+
+ // AutoTicketLink
+ $filtered_ticket_link_sites = array();
+ foreach ($ticket_link_sites as $s) {
+ if (!preg_match('/^([a-zA-Z0-9]+)([\.\-][a-zA-Z0-9]+)*$/', $s['key'])) {
+ continue;
+ }
+ array_push($filtered_ticket_link_sites, $s);
+ }
+ $h_ticket_link_sites = htmlsc(json_encode($filtered_ticket_link_sites,
+ JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
+ $ticketlink_data = <<<EOS
+<input type="hidden" class="ticketlink-def" value="$h_ticket_link_sites" />
+EOS;
+ $data = <<<EOS
+<div id="pukiwiki-site-properties" style="display:none;">
+$site_props
+$plugin_prop
+$ticketlink_data
+</div>
+EOS;
+ return $data;
}
-// ÊÔ½¸¥Õ¥©¡¼¥à¤Îɽ¼¨
-function edit_form($page,$postdata,$digest = 0,$b_template = TRUE)
+// Show 'edit' form
+function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE)
{
- global $script,$vars,$rows,$cols,$hr,$function_freeze;
- global $_btn_addtop,$_btn_preview,$_btn_repreview,$_btn_update,$_btn_freeze,$_msg_help,$_btn_notchangetimestamp;
- global $whatsnew,$_btn_template,$_btn_load,$non_list,$load_template_func;
-
- $refer = $template = $addtag = $add_top = '';
-
- if ($digest == 0) {
- $digest = md5(join('',get_source($page)));
- }
-
- $checked_top = array_key_exists('add_top',$vars) ? ' checked="checked"' : '';
- $checked_time = array_key_exists('notimestamp',$vars) ? ' checked="checked"' : '';
-
- if(array_key_exists('add',$vars)) {
- $addtag = '<input type="hidden" name="add" value="true" />';
- $add_top = "<input type=\"checkbox\" name=\"add_top\" value=\"true\"$checked_top /><span class=\"small\">$_btn_addtop</span>";
+ global $vars, $rows, $cols, $hr, $function_freeze;
+ global $_btn_preview, $_btn_repreview, $_btn_update, $_btn_cancel, $_msg_help;
+ global $whatsnew, $_btn_template, $_btn_load, $load_template_func;
+ global $notimeupdate;
+ global $_title_list, $_label_template_pages;
+ global $_msg_edit_cancel_confirm, $_msg_edit_unloadbefore_message;
+ global $rule_page;
+
+ $script = get_base_uri();
+ // Newly generate $digest or not
+ if ($digest === FALSE) $digest = md5(join('', get_source($page)));
+
+ $refer = $template = '';
+
+ // Add plugin
+ $addtag = $add_top = '';
+ if(isset($vars['add'])) {
+ global $_btn_addtop;
+ $addtag = '<input type="hidden" name="add" value="true" />';
+ $add_top = isset($vars['add_top']) ? ' checked="checked"' : '';
+ $add_top = '<input type="checkbox" name="add_top" ' .
+ 'id="_edit_form_add_top" value="true"' . $add_top . ' />' . "\n" .
+ ' <label for="_edit_form_add_top">' .
+ '<span class="small">' . $_btn_addtop . '</span>' .
+ '</label>';
}
- if($load_template_func and $b_template) {
- $_pages = get_existpages();
- $pages = array();
- foreach($_pages as $_page) {
- if ($_page == $whatsnew or preg_match("/$non_list/",$_page)) {
+ if($load_template_func && $b_template) {
+ $tpage_names = array(); // Pages marked as template
+ $template_page = ':config/Templates';
+ $page_max = 100;
+ foreach(get_source($template_page) as $_templates) {
+ $m = array();
+ if (! preg_match('#\-\s*\[\[([^\[\]]+)\]\]#', $_templates, $m)) continue;
+ $tpage = preg_replace('#^./#', "$template_page/", $m[1]);
+ if (! is_page($tpage)) continue;
+ $tpage_names[] = $tpage;
+ }
+ $page_names = array();
+ foreach(get_existpages() as $_page) {
+ if ($_page == $whatsnew || check_non_list($_page) ||
+ !is_page_readable($_page))
continue;
+ if (preg_match('/template/i', $_page)) {
+ $tpage_names[] = $_page;
+ } else {
+ if (count($page_names) >= $page_max) continue;
+ $page_names[] = $_page;
}
- $s_page = htmlspecialchars($_page);
- $pages[$_page] = " <option value=\"$s_page\">$s_page</option>";
}
- ksort($pages);
- $s_pages = join("\n",$pages);
+ $tpage_names2 = array_values(array_unique($tpage_names));
+ natcasesort($tpage_names2);
+ natcasesort($page_names);
+ $tpages = array(); // Template pages
+ $npages = array(); // Normal pages
+ foreach($tpage_names2 as $p) {
+ $ps = htmlsc($p);
+ $tpages[] = ' <option value="' . $ps . '">' . $ps . '</option>';
+ }
+ foreach($page_names as $p) {
+ $ps = htmlsc($p);
+ $npages[] = ' <option value="' . $ps . '">' . $ps . '</option>';
+ }
+ if (count($page_names) === $page_max) {
+ $npages[] = ' <option value="">...</option>';
+ }
+ $s_tpages = join("\n", $tpages);
+ $s_npages = join("\n", $npages);
$template = <<<EOD
<select name="template_page">
<option value="">-- $_btn_template --</option>
-$s_pages
+ <optgroup label="$_label_template_pages">
+$s_tpages
+ </optgroup>
+ <optgroup label="$_title_list">
+$s_npages
+ </optgroup>
</select>
<input type="submit" name="template" value="$_btn_load" accesskey="r" />
<br />
EOD;
- if (array_key_exists('refer',$vars) and $vars['refer'] != '') {
- $refer = '[['.strip_bracket($vars['refer'])."]]\n\n";
- }
+ if (isset($vars['refer']) && $vars['refer'] != '')
+ $refer = '[[' . strip_bracket($vars['refer']) . ']]' . "\n\n";
}
- $r_page = rawurlencode($page);
- $s_page = htmlspecialchars($page);
- $s_digest = htmlspecialchars($digest);
- $s_postdata = htmlspecialchars($refer.$postdata);
- $s_original = array_key_exists('original',$vars) ? htmlspecialchars($vars['original']) : $s_postdata;
- $b_preview = array_key_exists('preview',$vars); // ¥×¥ì¥Ó¥å¡¼ÃæTRUE
+ $r_page = rawurlencode($page);
+ $s_page = htmlsc($page);
+ $s_digest = htmlsc($digest);
+ $s_postdata = htmlsc($refer . $postdata);
+ $s_original = isset($vars['original']) ? htmlsc($vars['original']) : $s_postdata;
+ $b_preview = isset($vars['preview']); // TRUE when preview
$btn_preview = $b_preview ? $_btn_repreview : $_btn_preview;
+ // Checkbox 'do not change timestamp'
+ $add_notimestamp = '';
+ if ($notimeupdate != 0) {
+ global $_btn_notchangetimestamp;
+ $checked_time = isset($vars['notimestamp']) ? ' checked="checked"' : '';
+ // Only for administrator
+ if ($notimeupdate == 2) {
+ $add_notimestamp = ' ' .
+ '<input type="password" name="pass" size="12" />' . "\n";
+ }
+ $add_notimestamp = '<input type="checkbox" name="notimestamp" ' .
+ 'id="_edit_form_notimestamp" value="true"' . $checked_time . ' />' . "\n" .
+ ' ' . '<label for="_edit_form_notimestamp"><span class="small">' .
+ $_btn_notchangetimestamp . '</span></label>' . "\n" .
+ $add_notimestamp .
+ ' ';
+ }
+
+ // 'margin-bottom', 'float:left', and 'margin-top'
+ // are for layout of 'cancel button'
+ $h_msg_edit_cancel_confirm = htmlsc($_msg_edit_cancel_confirm);
+ $h_msg_edit_unloadbefore_message = htmlsc($_msg_edit_unloadbefore_message);
$body = <<<EOD
-<form action="$script" method="post">
- <div class="edit_form">
+<div class="edit_form">
+ <form action="$script" method="post" class="_plugin_edit_edit_form" style="margin-bottom:0px;">
$template
$addtag
- <input type="hidden" name="cmd" value="edit" />
- <input type="hidden" name="page" value="$s_page" />
+ <input type="hidden" name="cmd" value="edit" />
+ <input type="hidden" name="page" value="$s_page" />
<input type="hidden" name="digest" value="$s_digest" />
+ <input type="hidden" id="_msg_edit_cancel_confirm" value="$h_msg_edit_cancel_confirm" />
+ <input type="hidden" id="_msg_edit_unloadbefore_message" value="$h_msg_edit_unloadbefore_message" />
<textarea name="msg" rows="$rows" cols="$cols">$s_postdata</textarea>
<br />
- <input type="submit" name="preview" value="$btn_preview" accesskey="p" />
- <input type="submit" name="write" value="$_btn_update" accesskey="s" />
- $add_top
- <input type="checkbox" name="notimestamp" value="true"$checked_time />
- <span style="small">$_btn_notchangetimestamp</span>
+ <div style="float:left;">
+ <input type="submit" name="preview" value="$btn_preview" accesskey="p" />
+ <input type="submit" name="write" value="$_btn_update" accesskey="s" />
+ $add_top
+ $add_notimestamp
+ </div>
<textarea name="original" rows="1" cols="1" style="display:none">$s_original</textarea>
- </div>
-</form>
+ </form>
+ <form action="$script" method="post" class="_plugin_edit_cancel" style="margin-top:0px;">
+ <input type="hidden" name="cmd" value="edit" />
+ <input type="hidden" name="page" value="$s_page" />
+ <input type="submit" name="cancel" value="$_btn_cancel" accesskey="c" />
+ </form>
+</div>
EOD;
- if (array_key_exists('help', $vars)) {
- $body .= $hr . catrule();
- } else {
- $body .=
- "<ul><li><a href=\"$script?cmd=edit&help=true&page=$r_page\">$_msg_help</a></li></ul>";
- }
+ $body .= '<ul><li><a href="' .
+ get_page_uri($rule_page) .
+ '" target="_blank">' . $_msg_help . '</a></li></ul>';
return $body;
}
-// ´ØÏ¢¤¹¤ë¥Ú¡¼¥¸
-function make_related($page,$tag='')
+// Related pages
+function make_related($page, $tag = '')
{
- global $script,$vars,$related,$rule_related_str,$related_str,$non_list;
- global $_ul_left_margin, $_ul_margin, $_list_pad_str;
+ global $vars, $rule_related_str, $related_str;
+ $script = get_base_uri();
+ prepare_links_related($page);
$links = links_get_related($page);
if ($tag) {
- ksort($links);
- }
- else {
- arsort($links);
+ ksort($links, SORT_STRING); // Page name, alphabetical order
+ } else {
+ arsort($links, SORT_NUMERIC); // Last modified date, newer
}
+
$_links = array();
- foreach ($links as $page=>$lastmod)
- {
- if (preg_match("/$non_list/",$page))
- {
- continue;
+ foreach ($links as $page=>$lastmod) {
+ if (check_non_list($page)) continue;
+ $page_uri = get_page_uri($page);
+ $s_page = htmlsc($page);
+ if ($tag) {
+ $attrs = get_page_link_a_attrs($page);
+ $_links[] = '<a href="' . $page_uri . '" class="' .
+ $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] .
+ '">' . $s_page . '</a>';
+ } else {
+ $mtime_span = get_passage_mtime_html_span($lastmod + LOCALZONE);
+ $_links[] = '<a href="' . $page_uri . '">' .
+ $s_page . '</a>' . $mtime_span;
}
- $r_page = rawurlencode($page);
- $s_page = htmlspecialchars($page);
- $passage = get_passage($lastmod);
- $_links[] = $tag ?
- "<a href=\"$script?$r_page\" title=\"$s_page $passage\">$s_page</a>" :
- "<a href=\"$script?$r_page\">$s_page</a>$passage";
}
-
- if (count($_links) == 0)
- {
- return '';
+ if (empty($_links)) return ''; // Nothing
+
+ if ($tag == 'p') { // From the line-head
+ $style = sprintf(pkwk_list_attrs_template(), 1, 1);
+ $retval = "\n" . '<ul' . $style . '>' . "\n" .
+ '<li>' . join($rule_related_str, $_links) . '</li>' . "\n" .
+ '</ul>' . "\n";
+ } else if ($tag) {
+ $retval = join($rule_related_str, $_links);
+ } else {
+ $retval = join($related_str, $_links);
}
- if ($tag == 'p') // ¹ÔƬ¤«¤é
- {
- $margin = $_ul_left_margin + $_ul_margin;
- $style = sprintf($_list_pad_str,1,$margin,$margin);
- $retval = "\n<ul$style>\n<li>".join($rule_related_str,$_links)."</li>\n</ul>\n";
- }
- else if ($tag)
- {
- $retval = join($rule_related_str,$_links);
- }
- else
- {
- $retval = join($related_str,$_links);
- }
return $retval;
}
-// ¥æ¡¼¥¶ÄêµÁ¥ë¡¼¥ë(¥½¡¼¥¹¤ÏÃÖ´¹¤»¤º¥³¥ó¥Ð¡¼¥È)
+function _convert_line_rule_to_regex($a)
+{
+ return '/' . $a . '/';
+}
+
+// User-defined rules (convert without replacing source)
function make_line_rules($str)
{
global $line_rules;
- static $pattern,$replace;
+ static $pattern, $replace;
- if (!isset($pattern))
- {
- $pattern = array_map(create_function('$a','return "/$a/";'),array_keys($line_rules));
+ if (! isset($pattern)) {
+ $pattern = array_map('_convert_line_rule_to_regex', array_keys($line_rules));
$replace = array_values($line_rules);
unset($line_rules);
}
- return preg_replace($pattern,$replace,$str);
+
+ return preg_replace($pattern, $replace, $str);
}
-// HTML¥¿¥°¤ò¼è¤ê½ü¤¯
-function strip_htmltag($str)
+// Remove all HTML tags(or just anchor tags), and WikiName-speific decorations
+function strip_htmltag($str, $all = TRUE)
{
global $_symbol_noexists;
+ static $noexists_pattern;
- $noexists_pattern = '#<span class="noexists">([^<]*)<a[^>]+>'.
- preg_quote($_symbol_noexists,'#').
- '</a></span>#';
+ if (! isset($noexists_pattern))
+ $noexists_pattern = '#<span class="noexists">([^<]*)<a[^>]+>' .
+ preg_quote($_symbol_noexists, '#') . '</a></span>#';
+
+ // Strip Dagnling-Link decoration (Tags and "$_symbol_noexists")
+ $str = preg_replace($noexists_pattern, '$1', $str);
+
+ if ($all) {
+ // All other HTML tags
+ return preg_replace('#<[^>]+>#', '', $str);
+ } else {
+ // All other anchor-tags only
+ return preg_replace('#<a[^>]+>|</a>#i', '', $str);
+ }
+}
- $str = preg_replace($noexists_pattern,'$1',$str);
- //$str = preg_replace('/<a[^>]+>\?<\/a>/','',$str);
- return preg_replace('/<[^>]+>/','',$str);
+// Remove AutoLink marker with AutLink itself
+function strip_autolink($str)
+{
+ return preg_replace('#<!--autolink--><a [^>]+>|</a><!--/autolink-->#', '', $str);
}
-// ¥Ú¡¼¥¸Ì¾¤«¤é¥Ú¡¼¥¸Ì¾¤ò¸¡º÷¤¹¤ë¥ê¥ó¥¯¤òºîÀ®
+// Make a backlink. searching-link of the page name, by the page name, for the page name
function make_search($page)
{
- global $script,$WikiName;
-
- $s_page = htmlspecialchars($page);
+ $s_page = htmlsc($page);
$r_page = rawurlencode($page);
-
- //WikiWikiWeb like...
- //if(preg_match("/^$WikiName$/",$page))
- // $name = preg_replace("/([A-Z][a-z]+)/","$1 ",$name);
-
- return "<a href=\"$script?cmd=search&word=$r_page\">$s_page</a> ";
+ return '<a href="' . get_base_uri() . '?plugin=related&page=' . $r_page .
+ '">' . $s_page . '</a> ';
}
-// ¸«½Ð¤·¤òÀ¸À® (Ãí¼á¤äHTML¥¿¥°¤ò½üµî)
-function make_heading(&$str,$strip=TRUE)
+// Make heading string (remove heading-related decorations from Wiki text)
+function make_heading(& $str, $strip = TRUE)
{
global $NotePattern;
- // ¸«½Ð¤·¤Î¸ÇÍIDÉô¤òºï½ü
+ // Cut fixed-heading anchors
$id = '';
- if (preg_match('/^(\*{0,3})(.*?)\[#([A-Za-z][\w-]+)\](.*?)$/m',$str,$matches))
- {
- $str = $matches[2].$matches[4];
- $id = $matches[3];
+ $matches = array();
+ if (preg_match('/^(\*{0,3})(.*?)\[#([A-Za-z][\w-]+)\](.*?)$/m', $str, $matches)) {
+ $str = $matches[2] . $matches[4];
+ $id = & $matches[3];
+ } else {
+ $str = preg_replace('/^\*{0,3}/', '', $str);
+ }
+
+ // Cut footnotes and tags
+ if ($strip === TRUE)
+ $str = strip_htmltag(make_link(preg_replace($NotePattern, '', $str)));
+
+ return $id;
+}
+
+// Separate a page-name(or URL or null string) and an anchor
+// (last one standing) without sharp
+function anchor_explode($page, $strict_editable = FALSE)
+{
+ $pos = strrpos($page, '#');
+ if ($pos === FALSE) return array($page, '', FALSE);
+
+ // Ignore the last sharp letter
+ if ($pos + 1 == strlen($page)) {
+ $pos = strpos(substr($page, $pos + 1), '#');
+ if ($pos === FALSE) return array($page, '', FALSE);
}
- else
- {
- $str = preg_replace('/^\*{0,3}/','',$str);
+
+ $s_page = substr($page, 0, $pos);
+ $anchor = substr($page, $pos + 1);
+
+ if($strict_editable === TRUE && preg_match('/^[a-z][a-f0-9]{7}$/', $anchor)) {
+ return array ($s_page, $anchor, TRUE); // Seems fixed-anchor
+ } else {
+ return array ($s_page, $anchor, FALSE);
}
- if ($strip)
- {
- $str = strip_htmltag(make_link(preg_replace($NotePattern,'',$str)));
+}
+
+// Check HTTP header()s were sent already, or
+// there're blank lines or something out of php blocks
+function pkwk_headers_sent()
+{
+ if (PKWK_OPTIMISE) return;
+
+ $file = $line = '';
+ if (version_compare(PHP_VERSION, '4.3.0', '>=')) {
+ if (headers_sent($file, $line))
+ die('Headers already sent at ' .
+ htmlsc($file) .
+ ' line ' . $line . '.');
+ } else {
+ if (headers_sent())
+ die('Headers already sent.');
}
+}
- return $id;
+// Output common HTTP headers
+function pkwk_common_headers()
+{
+ if (! PKWK_OPTIMISE) pkwk_headers_sent();
+
+ if(defined('PKWK_ZLIB_LOADABLE_MODULE')) {
+ $matches = array();
+ if(ini_get('zlib.output_compression') &&
+ preg_match('/\b(gzip|deflate)\b/i', $_SERVER['HTTP_ACCEPT_ENCODING'], $matches)) {
+ // Bug #29350 output_compression compresses everything _without header_ as loadable module
+ // http://bugs.php.net/bug.php?id=29350
+ header('Content-Encoding: ' . $matches[1]);
+ header('Vary: Accept-Encoding');
+ }
+ }
+}
+
+// DTD definitions
+define('PKWK_DTD_XHTML_1_1', 17); // Strict only
+define('PKWK_DTD_XHTML_1_0', 16); // Strict
+define('PKWK_DTD_XHTML_1_0_STRICT', 16);
+define('PKWK_DTD_XHTML_1_0_TRANSITIONAL', 15);
+define('PKWK_DTD_XHTML_1_0_FRAMESET', 14);
+define('PKWK_DTD_HTML_4_01', 3); // Strict
+define('PKWK_DTD_HTML_4_01_STRICT', 3);
+define('PKWK_DTD_HTML_4_01_TRANSITIONAL', 2);
+define('PKWK_DTD_HTML_4_01_FRAMESET', 1);
+
+define('PKWK_DTD_TYPE_XHTML', 1);
+define('PKWK_DTD_TYPE_HTML', 0);
+
+// Output HTML DTD, <html> start tag. Return content-type.
+function pkwk_output_dtd($pkwk_dtd = PKWK_DTD_XHTML_1_1, $charset = CONTENT_CHARSET)
+{
+ static $called;
+ if (isset($called)) die('pkwk_output_dtd() already called. Why?');
+ $called = TRUE;
+
+ $type = PKWK_DTD_TYPE_XHTML;
+ $option = '';
+ switch($pkwk_dtd){
+ case PKWK_DTD_XHTML_1_1 :
+ $version = '1.1' ;
+ $dtd = 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd';
+ break;
+ case PKWK_DTD_XHTML_1_0_STRICT :
+ $version = '1.0' ;
+ $option = 'Strict';
+ $dtd = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd';
+ break;
+ case PKWK_DTD_XHTML_1_0_TRANSITIONAL:
+ $version = '1.0' ;
+ $option = 'Transitional';
+ $dtd = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd';
+ break;
+
+ case PKWK_DTD_HTML_4_01_STRICT :
+ $type = PKWK_DTD_TYPE_HTML;
+ $version = '4.01';
+ $dtd = 'http://www.w3.org/TR/html4/strict.dtd';
+ break;
+ case PKWK_DTD_HTML_4_01_TRANSITIONAL:
+ $type = PKWK_DTD_TYPE_HTML;
+ $version = '4.01';
+ $option = 'Transitional';
+ $dtd = 'http://www.w3.org/TR/html4/loose.dtd';
+ break;
+
+ default: die('DTD not specified or invalid DTD');
+ break;
+ }
+
+ $charset = htmlsc($charset);
+
+ // Output XML or not
+ if ($type == PKWK_DTD_TYPE_XHTML) echo '<?xml version="1.0" encoding="' . $charset . '" ?>' . "\n";
+
+ // Output doctype
+ echo '<!DOCTYPE html PUBLIC "-//W3C//DTD ' .
+ ($type == PKWK_DTD_TYPE_XHTML ? 'XHTML' : 'HTML') . ' ' .
+ $version .
+ ($option != '' ? ' ' . $option : '') .
+ '//EN" "' .
+ $dtd .
+ '">' . "\n";
+
+ // Output <html> start tag
+ echo '<html';
+ if ($type == PKWK_DTD_TYPE_XHTML) {
+ echo ' xmlns="http://www.w3.org/1999/xhtml"'; // dir="ltr" /* LeftToRight */
+ echo ' xml:lang="' . LANG . '"';
+ if ($version == '1.0') echo ' lang="' . LANG . '"'; // Only XHTML 1.0
+ } else {
+ echo ' lang="' . LANG . '"'; // HTML
+ }
+ echo '>' . "\n"; // <html>
+
+ // Return content-type (with MIME type)
+ if ($type == PKWK_DTD_TYPE_XHTML) {
+ // NOTE: XHTML 1.1 browser will ignore http-equiv
+ return '<meta http-equiv="content-type" content="application/xhtml+xml; charset=' . $charset . '" />' . "\n";
+ } else {
+ return '<meta http-equiv="content-type" content="text/html; charset=' . $charset . '" />' . "\n";
+ }
+}
+
+/**
+ * Get template of List (ul, ol, dl) attributes
+ */
+function pkwk_list_attrs_template() {
+ return ' class="list%d list-indent%d"';
}
-?>