Revision | 5944633aac73ffcf6a0226bfc2311f32ef404098 (tree) |
---|---|
Time | 2006-08-09 03:11:00 |
Author | teanan <teanan> |
Commiter | teanan |
BugTrack2/2: merged with autoalias branches (r1_4_7_autoalias).
@@ -0,0 +1,3 @@ | ||
1 | +pukiwiki\.(?:dev|official) | |
2 | +(?!) | |
3 | + |
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone. |
3 | -// $Id: file.php,v 1.72 2006/06/11 14:42:09 henoheno Exp $ | |
3 | +// $Id: file.php,v 1.73 2006/08/08 18:10:59 teanan Exp $ | |
4 | 4 | // Copyright (C) |
5 | 5 | // 2002-2006 PukiWiki Developers Team |
6 | 6 | // 2001-2002 Originally written by yu-ji |
@@ -63,6 +63,7 @@ function get_filename($page) | ||
63 | 63 | function page_write($page, $postdata, $notimestamp = FALSE) |
64 | 64 | { |
65 | 65 | global $trackback; |
66 | + global $autoalias, $aliaspage; | |
66 | 67 | |
67 | 68 | if (PKWK_READONLY) return; // Do nothing |
68 | 69 |
@@ -88,6 +89,18 @@ function page_write($page, $postdata, $notimestamp = FALSE) | ||
88 | 89 | } |
89 | 90 | |
90 | 91 | links_update($page); |
92 | + | |
93 | + // for AutoAlias | |
94 | + if ($autoalias>0 && $page==$aliaspage) { | |
95 | + // AutoAliasName is updated | |
96 | + $pages = array_keys(get_autoaliases()); | |
97 | + if(count($pages)>0) { | |
98 | + autolink_pattern_write(CACHE_DIR . 'autoalias.dat', | |
99 | + get_autolink_pattern($pages, $autoalias)); | |
100 | + } else { | |
101 | + @unlink(CACHE_DIR . 'autoalias.dat'); | |
102 | + } | |
103 | + } | |
91 | 104 | } |
92 | 105 | |
93 | 106 | // Modify original text with user-defined / system-defined rules |
@@ -457,26 +470,29 @@ function put_lastmodified() | ||
457 | 470 | fclose($fp); |
458 | 471 | |
459 | 472 | // For AutoLink |
460 | - if ($autolink) { | |
461 | - list($pattern, $pattern_a, $forceignorelist) = | |
462 | - get_autolink_pattern($pages); | |
463 | - | |
464 | - $file = CACHE_DIR . PKWK_AUTOLINK_REGEX_CACHE; | |
465 | - pkwk_touch_file($file); | |
466 | - $fp = fopen($file, 'r+') or | |
467 | - die_message('Cannot open ' . 'CACHE_DIR/' . PKWK_AUTOLINK_REGEX_CACHE); | |
468 | - set_file_buffer($fp, 0); | |
469 | - flock($fp, LOCK_EX); | |
470 | - ftruncate($fp, 0); | |
471 | - rewind($fp); | |
472 | - fputs($fp, $pattern . "\n"); | |
473 | - fputs($fp, $pattern_a . "\n"); | |
474 | - fputs($fp, join("\t", $forceignorelist) . "\n"); | |
475 | - flock($fp, LOCK_UN); | |
476 | - fclose($fp); | |
473 | + if ($autolink){ | |
474 | + autolink_pattern_write(CACHE_DIR . PKWK_AUTOLINK_REGEX_CACHE, | |
475 | + get_autolink_pattern($pages, $autolink)); | |
477 | 476 | } |
478 | 477 | } |
479 | 478 | |
479 | +// update autolink data | |
480 | +function autolink_pattern_write($filename, $autolink_pattern) | |
481 | +{ | |
482 | + list($pattern, $pattern_a, $forceignorelist) = $autolink_pattern; | |
483 | + | |
484 | + $fp = fopen($filename, 'w') or | |
485 | + die_message('Cannot open ' . $filename); | |
486 | + set_file_buffer($fp, 0); | |
487 | + flock($fp, LOCK_EX); | |
488 | + rewind($fp); | |
489 | + fputs($fp, $pattern . "\n"); | |
490 | + fputs($fp, $pattern_a . "\n"); | |
491 | + fputs($fp, join("\t", $forceignorelist) . "\n"); | |
492 | + flock($fp, LOCK_UN); | |
493 | + fclose($fp); | |
494 | +} | |
495 | + | |
480 | 496 | // Get elapsed date of the page |
481 | 497 | function get_pg_passage($page, $sw = TRUE) |
482 | 498 | { |
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone. |
3 | -// $Id: func.php,v 1.73 2006/05/15 16:41:39 teanan Exp $ | |
3 | +// $Id: func.php,v 1.74 2006/08/08 18:10:59 teanan Exp $ | |
4 | 4 | // Copyright (C) |
5 | 5 | // 2002-2006 PukiWiki Developers Team |
6 | 6 | // 2001-2002 Originally written by yu-ji |
@@ -524,7 +524,7 @@ function drop_submit($str) | ||
524 | 524 | } |
525 | 525 | |
526 | 526 | // Generate AutoLink patterns (thx to hirofummy) |
527 | -function get_autolink_pattern(& $pages) | |
527 | +function get_autolink_pattern(& $pages, $min_len = -1) | |
528 | 528 | { |
529 | 529 | global $WikiName, $autolink, $nowikiname; |
530 | 530 |
@@ -535,9 +535,13 @@ function get_autolink_pattern(& $pages) | ||
535 | 535 | unset($config); |
536 | 536 | $auto_pages = array_merge($ignorepages, $forceignorepages); |
537 | 537 | |
538 | + if ($min_len == -1) { | |
539 | + $min_len = $autolink; // set $autolink, when omitted. | |
540 | + } | |
541 | + | |
538 | 542 | foreach ($pages as $page) |
539 | 543 | if (preg_match('/^' . $WikiName . '$/', $page) ? |
540 | - $nowikiname : strlen($page) >= $autolink) | |
544 | + $nowikiname : strlen($page) >= $min_len) | |
541 | 545 | $auto_pages[] = $page; |
542 | 546 | |
543 | 547 | if (empty($auto_pages)) { |
@@ -584,6 +588,32 @@ function get_autolink_pattern_sub(& $pages, $start, $end, $pos) | ||
584 | 588 | return $result; |
585 | 589 | } |
586 | 590 | |
591 | +// get pagelist for AutoAlias | |
592 | +function get_autoaliases() | |
593 | +{ | |
594 | + global $aliaspage, $autoalias_max_words; | |
595 | + | |
596 | + $pages = array(); | |
597 | + $pattern = <<<EOD | |
598 | +\[\[ # open bracket | |
599 | +((?:(?!\]\]).)+)> # (1) alias name | |
600 | +((?:(?!\]\]).)+) # (2) alias link | |
601 | +\]\] # close bracket | |
602 | +EOD; | |
603 | + | |
604 | + $postdata = join('', get_source($aliaspage)); | |
605 | + $matches = array(); | |
606 | + if(preg_match_all("/$pattern/x", $postdata, $matches, PREG_SET_ORDER)) { | |
607 | + foreach($matches as $match) { | |
608 | + $pages[$match[1]] = trim($match[2]); | |
609 | + } | |
610 | + } | |
611 | + // fail safe | |
612 | + $pages = array_slice($pages, 0, $autoalias_max_words); | |
613 | + | |
614 | + return $pages; | |
615 | +} | |
616 | + | |
587 | 617 | // Get absolute-URI of this script |
588 | 618 | function get_script_uri($init_uri = '') |
589 | 619 | { |
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: link.php,v 1.11 2006/04/06 03:00:00 teanan Exp $ | |
3 | +// $Id: link.php,v 1.12 2006/08/08 18:10:59 teanan Exp $ | |
4 | 4 | // Copyright (C) 2003-2006 PukiWiki Developers Team |
5 | 5 | // License: GPL v2 or (at your option) any later version |
6 | 6 | // |
@@ -72,6 +72,11 @@ function links_update($page) | ||
72 | 72 | |
73 | 73 | if (is_a($_obj, 'Link_autolink')) { // 行儀が悪い |
74 | 74 | $rel_auto[] = $_obj->name; |
75 | + } else if (is_a($_obj, 'Link_autoalias')) { | |
76 | + $_alias = $_obj->get_alias($_obj->name); | |
77 | + if (is_pagename($_alias)) { | |
78 | + $rel_auto[] = $_alias; | |
79 | + } | |
75 | 80 | } else { |
76 | 81 | $rel_new[] = $_obj->name; |
77 | 82 | } |
@@ -153,11 +158,18 @@ function links_init() | ||
153 | 158 | $_obj->name == $page || $_obj->name == '') |
154 | 159 | continue; |
155 | 160 | |
156 | - $rel[] = $_obj->name; | |
157 | - if (! isset($ref[$_obj->name][$page])) | |
158 | - $ref[$_obj->name][$page] = 1; | |
161 | + $_name = $_obj->name; | |
162 | + if (is_a($_obj, 'Link_autoalias')) { | |
163 | + $_alias = $_obj->get_alias($_obj->name); | |
164 | + if (! is_pagename($_alias)) | |
165 | + continue; // not PageName | |
166 | + $_name = $_alias; | |
167 | + } | |
168 | + $rel[] = $_name; | |
169 | + if (! isset($ref[$_name][$page])) | |
170 | + $ref[$_name][$page] = 1; | |
159 | 171 | if (! is_a($_obj, 'Link_autolink')) |
160 | - $ref[$_obj->name][$page] = 0; | |
172 | + $ref[$_name][$page] = 0; | |
161 | 173 | } |
162 | 174 | $rel = array_unique($rel); |
163 | 175 | if (! empty($rel)) { |
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone. |
3 | -// $Id: make_link.php,v 1.30 2005/12/10 07:57:30 henoheno Exp $ | |
3 | +// $Id: make_link.php,v 1.31 2006/08/08 18:10:59 teanan Exp $ | |
4 | 4 | // Copyright (C) |
5 | 5 | // 2003-2005 PukiWiki Developers Team |
6 | 6 | // 2001-2002 Originally written by yu-ji |
@@ -60,9 +60,11 @@ class InlineConverter | ||
60 | 60 | 'url_interwiki', // URLs (interwiki definition) |
61 | 61 | 'mailto', // mailto: URL schemes |
62 | 62 | 'interwikiname', // InterWikiNames |
63 | + 'autoalias', // AutoAlias | |
63 | 64 | 'autolink', // AutoLinks |
64 | 65 | 'bracketname', // BracketNames |
65 | 66 | 'wikiname', // WikiNames |
67 | + 'autoalias_a', // AutoAlias(alphabet) | |
66 | 68 | 'autolink_a', // AutoLinks(alphabet) |
67 | 69 | ); |
68 | 70 | } |
@@ -703,6 +705,85 @@ class Link_autolink_a extends Link_autolink | ||
703 | 705 | } |
704 | 706 | } |
705 | 707 | |
708 | +// AutoAlias | |
709 | +class Link_autoalias extends Link | |
710 | +{ | |
711 | + var $forceignorepages = array(); | |
712 | + var $auto; | |
713 | + var $auto_a; // alphabet only | |
714 | + var $alias; | |
715 | + | |
716 | + function Link_autoalias($start) | |
717 | + { | |
718 | + global $autoalias, $aliaspage; | |
719 | + | |
720 | + parent::Link($start); | |
721 | + | |
722 | + if (!$autoalias || !file_exists(CACHE_DIR.'autoalias.dat') || $this->page==$aliaspage) | |
723 | + { | |
724 | + return; | |
725 | + } | |
726 | + @list($auto,$auto_a,$forceignorepages) = file(CACHE_DIR.'autoalias.dat'); | |
727 | + $this->auto = $auto; | |
728 | + $this->auto_a = $auto_a; | |
729 | + $this->forceignorepages = explode("\t", trim($forceignorepages)); | |
730 | + $this->alias = ''; | |
731 | + } | |
732 | + function get_pattern() | |
733 | + { | |
734 | + return isset($this->auto) ? '(' . $this->auto . ')' : FALSE; | |
735 | + } | |
736 | + function get_count() | |
737 | + { | |
738 | + return 1; | |
739 | + } | |
740 | + function set($arr,$page) | |
741 | + { | |
742 | + list($name) = $this->splice($arr); | |
743 | + // Ignore pages listed | |
744 | + if (in_array($name, $this->forceignorepages)) { | |
745 | + return FALSE; | |
746 | + } | |
747 | + return parent::setParam($page,$name,'','pagename',$name); | |
748 | + } | |
749 | + | |
750 | + function toString() | |
751 | + { | |
752 | + $this->alias = $this->get_alias($this->name); | |
753 | + if ($this->alias != '') { | |
754 | + $link = '[[' . $this->name . '>' . $this->alias . ']]'; | |
755 | + return make_link($link); | |
756 | + } | |
757 | + return ''; | |
758 | + } | |
759 | + | |
760 | + function get_alias($name) | |
761 | + { | |
762 | + static $aliases; | |
763 | + | |
764 | + if (!isset($aliases)) { | |
765 | + $aliases = get_autoaliases(); | |
766 | + } | |
767 | + $result = ''; | |
768 | + if (array_key_exists($name, $aliases)) { | |
769 | + $result = $aliases[$this->name]; | |
770 | + } | |
771 | + return $result; | |
772 | + } | |
773 | +} | |
774 | + | |
775 | +class Link_autoalias_a extends Link_autoalias | |
776 | +{ | |
777 | + function Link_autoalias_a($start) | |
778 | + { | |
779 | + parent::Link_autoalias($start); | |
780 | + } | |
781 | + function get_pattern() | |
782 | + { | |
783 | + return isset($this->auto_a) ? '(' . $this->auto_a . ')' : FALSE; | |
784 | + } | |
785 | +} | |
786 | + | |
706 | 787 | // Make hyperlink for the page |
707 | 788 | function make_pagelink($page, $alias = '', $anchor = '', $refer = '', $isautolink = FALSE) |
708 | 789 | { |
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: pukiwiki.ini.php,v 1.140 2006/06/11 14:35:39 henoheno Exp $ | |
3 | +// $Id: pukiwiki.ini.php,v 1.141 2006/08/08 18:10:59 teanan Exp $ | |
4 | 4 | // Copyright (C) |
5 | 5 | // 2002-2006 PukiWiki Developers Team |
6 | 6 | // 2001-2002 Originally written by yu-ji |
@@ -130,6 +130,7 @@ $defaultpage = 'FrontPage'; // Top / Default page | ||
130 | 130 | $whatsnew = 'RecentChanges'; // Modified page list |
131 | 131 | $whatsdeleted = 'RecentDeleted'; // Removeed page list |
132 | 132 | $interwiki = 'InterWikiName'; // Set InterWiki definition here |
133 | +$aliaspage = 'AutoAliasName'; // Set AutoAlias definition here | |
133 | 134 | $menubar = 'MenuBar'; // Menu |
134 | 135 | |
135 | 136 | ///////////////////////////////////////////////// |
@@ -178,6 +179,15 @@ $nowikiname = 0; | ||
178 | 179 | $autolink = 0; // Bytes, 0 = OFF (try 8) |
179 | 180 | |
180 | 181 | ///////////////////////////////////////////////// |
182 | +// AutoAlias feature | |
183 | + | |
184 | +// AutoAlias minimum bytes (0 = Disable) | |
185 | +$autoalias = 0; | |
186 | + | |
187 | +// Maximum number of words which AutoAlias replace | |
188 | +$autoalias_max_words = 50; | |
189 | + | |
190 | +///////////////////////////////////////////////// | |
181 | 191 | // Enable Freeze / Unfreeze feature |
182 | 192 | $function_freeze = 1; |
183 | 193 |
@@ -0,0 +1,6 @@ | ||
1 | +*AutoAliasName [#qf9311bb] | |
2 | +AutoAlias用の定義リストです。 | |
3 | + | |
4 | +* PukiWiki [#ee87d39e] | |
5 | +-[[pukiwiki.official>http://pukiwiki.sourceforge.jp/]] | |
6 | +-[[pukiwiki.dev>http://pukiwiki.sourceforge.jp/dev/]] |