From: teanan Date: Tue, 8 Aug 2006 18:11:00 +0000 (+0900) Subject: BugTrack2/2: merged with autoalias branches (r1_4_7_autoalias). X-Git-Tag: r1_4_7_autoalias_merge_end X-Git-Url: http://git.osdn.net/view?p=pukiwiki%2Fpukiwiki.git;a=commitdiff_plain;h=5944633aac73ffcf6a0226bfc2311f32ef404098 BugTrack2/2: merged with autoalias branches (r1_4_7_autoalias). --- diff --git a/cache/autoalias.dat b/cache/autoalias.dat new file mode 100644 index 0000000..8d6c163 --- /dev/null +++ b/cache/autoalias.dat @@ -0,0 +1,3 @@ +pukiwiki\.(?:dev|official) +(?!) + diff --git a/lib/file.php b/lib/file.php index dec5781..817378f 100644 --- a/lib/file.php +++ b/lib/file.php @@ -1,6 +1,6 @@ 0 && $page==$aliaspage) { + // AutoAliasName is updated + $pages = array_keys(get_autoaliases()); + if(count($pages)>0) { + autolink_pattern_write(CACHE_DIR . 'autoalias.dat', + get_autolink_pattern($pages, $autoalias)); + } else { + @unlink(CACHE_DIR . 'autoalias.dat'); + } + } } // Modify original text with user-defined / system-defined rules @@ -457,26 +470,29 @@ function put_lastmodified() fclose($fp); // For AutoLink - if ($autolink) { - list($pattern, $pattern_a, $forceignorelist) = - get_autolink_pattern($pages); - - $file = CACHE_DIR . PKWK_AUTOLINK_REGEX_CACHE; - pkwk_touch_file($file); - $fp = fopen($file, 'r+') or - die_message('Cannot open ' . 'CACHE_DIR/' . PKWK_AUTOLINK_REGEX_CACHE); - set_file_buffer($fp, 0); - flock($fp, LOCK_EX); - ftruncate($fp, 0); - rewind($fp); - fputs($fp, $pattern . "\n"); - fputs($fp, $pattern_a . "\n"); - fputs($fp, join("\t", $forceignorelist) . "\n"); - flock($fp, LOCK_UN); - fclose($fp); + if ($autolink){ + autolink_pattern_write(CACHE_DIR . PKWK_AUTOLINK_REGEX_CACHE, + get_autolink_pattern($pages, $autolink)); } } +// update autolink data +function autolink_pattern_write($filename, $autolink_pattern) +{ + list($pattern, $pattern_a, $forceignorelist) = $autolink_pattern; + + $fp = fopen($filename, 'w') or + die_message('Cannot open ' . $filename); + set_file_buffer($fp, 0); + flock($fp, LOCK_EX); + rewind($fp); + fputs($fp, $pattern . "\n"); + fputs($fp, $pattern_a . "\n"); + fputs($fp, join("\t", $forceignorelist) . "\n"); + flock($fp, LOCK_UN); + fclose($fp); +} + // Get elapsed date of the page function get_pg_passage($page, $sw = TRUE) { diff --git a/lib/func.php b/lib/func.php index 92e1fd6..11d9e40 100644 --- a/lib/func.php +++ b/lib/func.php @@ -1,6 +1,6 @@ = $autolink) + $nowikiname : strlen($page) >= $min_len) $auto_pages[] = $page; if (empty($auto_pages)) { @@ -584,6 +588,32 @@ function get_autolink_pattern_sub(& $pages, $start, $end, $pos) return $result; } +// get pagelist for AutoAlias +function get_autoaliases() +{ + global $aliaspage, $autoalias_max_words; + + $pages = array(); + $pattern = << # (1) alias name +((?:(?!\]\]).)+) # (2) alias link +\]\] # close bracket +EOD; + + $postdata = join('', get_source($aliaspage)); + $matches = array(); + if(preg_match_all("/$pattern/x", $postdata, $matches, PREG_SET_ORDER)) { + foreach($matches as $match) { + $pages[$match[1]] = trim($match[2]); + } + } + // fail safe + $pages = array_slice($pages, 0, $autoalias_max_words); + + return $pages; +} + // Get absolute-URI of this script function get_script_uri($init_uri = '') { diff --git a/lib/link.php b/lib/link.php index cdcf345..145eb0f 100644 --- a/lib/link.php +++ b/lib/link.php @@ -1,6 +1,6 @@ name; + } else if (is_a($_obj, 'Link_autoalias')) { + $_alias = $_obj->get_alias($_obj->name); + if (is_pagename($_alias)) { + $rel_auto[] = $_alias; + } } else { $rel_new[] = $_obj->name; } @@ -153,11 +158,18 @@ function links_init() $_obj->name == $page || $_obj->name == '') continue; - $rel[] = $_obj->name; - if (! isset($ref[$_obj->name][$page])) - $ref[$_obj->name][$page] = 1; + $_name = $_obj->name; + if (is_a($_obj, 'Link_autoalias')) { + $_alias = $_obj->get_alias($_obj->name); + if (! is_pagename($_alias)) + continue; // not PageName + $_name = $_alias; + } + $rel[] = $_name; + if (! isset($ref[$_name][$page])) + $ref[$_name][$page] = 1; if (! is_a($_obj, 'Link_autolink')) - $ref[$_obj->name][$page] = 0; + $ref[$_name][$page] = 0; } $rel = array_unique($rel); if (! empty($rel)) { diff --git a/lib/make_link.php b/lib/make_link.php index b18b9a6..b0e8d5c 100644 --- a/lib/make_link.php +++ b/lib/make_link.php @@ -1,6 +1,6 @@ page==$aliaspage) + { + return; + } + @list($auto,$auto_a,$forceignorepages) = file(CACHE_DIR.'autoalias.dat'); + $this->auto = $auto; + $this->auto_a = $auto_a; + $this->forceignorepages = explode("\t", trim($forceignorepages)); + $this->alias = ''; + } + function get_pattern() + { + return isset($this->auto) ? '(' . $this->auto . ')' : FALSE; + } + function get_count() + { + return 1; + } + function set($arr,$page) + { + list($name) = $this->splice($arr); + // Ignore pages listed + if (in_array($name, $this->forceignorepages)) { + return FALSE; + } + return parent::setParam($page,$name,'','pagename',$name); + } + + function toString() + { + $this->alias = $this->get_alias($this->name); + if ($this->alias != '') { + $link = '[[' . $this->name . '>' . $this->alias . ']]'; + return make_link($link); + } + return ''; + } + + function get_alias($name) + { + static $aliases; + + if (!isset($aliases)) { + $aliases = get_autoaliases(); + } + $result = ''; + if (array_key_exists($name, $aliases)) { + $result = $aliases[$this->name]; + } + return $result; + } +} + +class Link_autoalias_a extends Link_autoalias +{ + function Link_autoalias_a($start) + { + parent::Link_autoalias($start); + } + function get_pattern() + { + return isset($this->auto_a) ? '(' . $this->auto_a . ')' : FALSE; + } +} + // Make hyperlink for the page function make_pagelink($page, $alias = '', $anchor = '', $refer = '', $isautolink = FALSE) { diff --git a/pukiwiki.ini.php b/pukiwiki.ini.php index 5e68172..63e3b4a 100644 --- a/pukiwiki.ini.php +++ b/pukiwiki.ini.php @@ -1,6 +1,6 @@ http://pukiwiki.sourceforge.jp/]] +-[[pukiwiki.dev>http://pukiwiki.sourceforge.jp/dev/]]