$head_tag = ! empty($head_tags) ? join("\n", $head_tags) ."\n" : ''; // 1.3.x compat // Last modification date (UNIX timestamp) of the page $fmt = $is_read ? get_filetime($_page) + LOCALZONE : 0; // Output nofollow / noindex regardless os skin file if (!$is_read || $nofollow) { if (!headers_sent()) { header("X-Robots-Tag: noindex,nofollow"); } } // 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 = '
' . $_msg_word . htmlsc($vars['word']) . '
' . $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 = htmlsc($key); $pattern = '/' . ']*>.*?<\/textarea>' . // Ignore textareas '|' . '<[^>]*>' . // Ignore tags '|' . '&[^;]+;' . // Ignore entities '|' . '(' . $pattern . ')' . // $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; } } // Compat: 'HTML convert time' without time about MenuBar and skin $taketime = elapsedtime(); require(SKIN_FILE); } // Show 'edit' form function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE) { global $script, $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; // 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 = ''; $add_top = isset($vars['add_top']) ? ' checked="checked"' : ''; $add_top = '' . "\n" . ' '; } 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)) continue; if (preg_match('/template/i', $_page)) { $tpage_names[] = $_page; } else { if (count($page_names) >= $page_max) continue; $page_names[] = $_page; } } $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[] = ' '; } foreach($page_names as $p) { $ps = htmlsc($p); $npages[] = ' '; } if (count($page_names) === $page_max) { $npages[] = ' '; } $s_tpages = join("\n", $tpages); $s_npages = join("\n", $npages); $template = << $s_tpages $s_npages
EOD; if (isset($vars['refer']) && $vars['refer'] != '') $refer = '[[' . strip_bracket($vars['refer']) . ']]' . "\n\n"; } $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 = ' ' . '' . "\n"; } $add_notimestamp = '' . "\n" . ' ' . '' . "\n" . $add_notimestamp . ' '; } // 'margin-bottom', 'float:left', and 'margin-top' // are for layout of 'cancel button' $body = <<
$template $addtag
$add_top $add_notimestamp
EOD; if (isset($vars['help'])) { $body .= $hr . catrule(); } else { $body .= ''; } return $body; } // Related pages function make_related($page, $tag = '') { global $script, $vars, $rule_related_str, $related_str; global $_ul_left_margin, $_ul_margin, $_list_pad_str; $links = links_get_related($page); if ($tag) { 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 (check_non_list($page)) continue; $r_page = pagename_urlencode($page); $s_page = htmlsc($page); $passage = get_passage($lastmod); $_links[] = $tag ? '' . $s_page . '' : '' . $s_page . '' . $passage; } if (empty($_links)) return ''; // Nothing if ($tag == 'p') { // From the line-head $margin = $_ul_left_margin + $_ul_margin; $style = sprintf($_list_pad_str, 1, $margin, $margin); $retval = "\n" . '' . "\n" . '
  • ' . join($rule_related_str, $_links) . '
  • ' . "\n" . '' . "\n"; } else if ($tag) { $retval = join($rule_related_str, $_links); } else { $retval = join($related_str, $_links); } return $retval; } // User-defined rules (convert without replacing source) function make_line_rules($str) { global $line_rules; static $pattern, $replace; if (! isset($pattern)) { $pattern = array_map(create_function('$a', 'return \'/\' . $a . \'/\';'), array_keys($line_rules)); $replace = array_values($line_rules); unset($line_rules); } return preg_replace($pattern, $replace, $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; if (! isset($noexists_pattern)) $noexists_pattern = '#([^<]*)]+>' . preg_quote($_symbol_noexists, '#') . '#'; // 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('#]+>|#i', '', $str); } } // Remove AutoLink marker with AutLink itself function strip_autolink($str) { return preg_replace('#]+>|#', '', $str); } // Make a backlink. searching-link of the page name, by the page name, for the page name function make_search($page) { global $script; $s_page = htmlsc($page); $r_page = rawurlencode($page); return '' . $s_page . ' '; } // Make heading string (remove heading-related decorations from Wiki text) function make_heading(& $str, $strip = TRUE) { global $NotePattern; // Cut fixed-heading anchors $id = ''; $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); } $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); } } // 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.'); } } // 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, 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 '' . "\n"; // Output doctype echo '' . "\n"; // Output start tag echo '' . "\n"; // // Return content-type (with MIME type) if ($type == PKWK_DTD_TYPE_XHTML) { // NOTE: XHTML 1.1 browser will ignore http-equiv return '' . "\n"; } else { return '' . "\n"; } }