Commit MetaInfo

修订版5944633aac73ffcf6a0226bfc2311f32ef404098 (tree)
时间2006-08-09 03:11:00
作者teanan <teanan>
Commiterteanan

Log Message

BugTrack2/2: merged with autoalias branches (r1_4_7_autoalias).

更改概述

差异

--- /dev/null
+++ b/cache/autoalias.dat
@@ -0,0 +1,3 @@
1+pukiwiki\.(?:dev|official)
2+(?!)
3+
--- a/lib/file.php
+++ b/lib/file.php
@@ -1,6 +1,6 @@
11 <?php
22 // 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 $
44 // Copyright (C)
55 // 2002-2006 PukiWiki Developers Team
66 // 2001-2002 Originally written by yu-ji
@@ -63,6 +63,7 @@ function get_filename($page)
6363 function page_write($page, $postdata, $notimestamp = FALSE)
6464 {
6565 global $trackback;
66+ global $autoalias, $aliaspage;
6667
6768 if (PKWK_READONLY) return; // Do nothing
6869
@@ -88,6 +89,18 @@ function page_write($page, $postdata, $notimestamp = FALSE)
8889 }
8990
9091 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+ }
91104 }
92105
93106 // Modify original text with user-defined / system-defined rules
@@ -457,26 +470,29 @@ function put_lastmodified()
457470 fclose($fp);
458471
459472 // 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));
477476 }
478477 }
479478
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+
480496 // Get elapsed date of the page
481497 function get_pg_passage($page, $sw = TRUE)
482498 {
--- a/lib/func.php
+++ b/lib/func.php
@@ -1,6 +1,6 @@
11 <?php
22 // 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 $
44 // Copyright (C)
55 // 2002-2006 PukiWiki Developers Team
66 // 2001-2002 Originally written by yu-ji
@@ -524,7 +524,7 @@ function drop_submit($str)
524524 }
525525
526526 // Generate AutoLink patterns (thx to hirofummy)
527-function get_autolink_pattern(& $pages)
527+function get_autolink_pattern(& $pages, $min_len = -1)
528528 {
529529 global $WikiName, $autolink, $nowikiname;
530530
@@ -535,9 +535,13 @@ function get_autolink_pattern(& $pages)
535535 unset($config);
536536 $auto_pages = array_merge($ignorepages, $forceignorepages);
537537
538+ if ($min_len == -1) {
539+ $min_len = $autolink; // set $autolink, when omitted.
540+ }
541+
538542 foreach ($pages as $page)
539543 if (preg_match('/^' . $WikiName . '$/', $page) ?
540- $nowikiname : strlen($page) >= $autolink)
544+ $nowikiname : strlen($page) >= $min_len)
541545 $auto_pages[] = $page;
542546
543547 if (empty($auto_pages)) {
@@ -584,6 +588,32 @@ function get_autolink_pattern_sub(& $pages, $start, $end, $pos)
584588 return $result;
585589 }
586590
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+
587617 // Get absolute-URI of this script
588618 function get_script_uri($init_uri = '')
589619 {
--- a/lib/link.php
+++ b/lib/link.php
@@ -1,6 +1,6 @@
11 <?php
22 // 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 $
44 // Copyright (C) 2003-2006 PukiWiki Developers Team
55 // License: GPL v2 or (at your option) any later version
66 //
@@ -72,6 +72,11 @@ function links_update($page)
7272
7373 if (is_a($_obj, 'Link_autolink')) { // 行儀が悪い
7474 $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+ }
7580 } else {
7681 $rel_new[] = $_obj->name;
7782 }
@@ -153,11 +158,18 @@ function links_init()
153158 $_obj->name == $page || $_obj->name == '')
154159 continue;
155160
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;
159171 if (! is_a($_obj, 'Link_autolink'))
160- $ref[$_obj->name][$page] = 0;
172+ $ref[$_name][$page] = 0;
161173 }
162174 $rel = array_unique($rel);
163175 if (! empty($rel)) {
--- a/lib/make_link.php
+++ b/lib/make_link.php
@@ -1,6 +1,6 @@
11 <?php
22 // 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 $
44 // Copyright (C)
55 // 2003-2005 PukiWiki Developers Team
66 // 2001-2002 Originally written by yu-ji
@@ -60,9 +60,11 @@ class InlineConverter
6060 'url_interwiki', // URLs (interwiki definition)
6161 'mailto', // mailto: URL schemes
6262 'interwikiname', // InterWikiNames
63+ 'autoalias', // AutoAlias
6364 'autolink', // AutoLinks
6465 'bracketname', // BracketNames
6566 'wikiname', // WikiNames
67+ 'autoalias_a', // AutoAlias(alphabet)
6668 'autolink_a', // AutoLinks(alphabet)
6769 );
6870 }
@@ -703,6 +705,85 @@ class Link_autolink_a extends Link_autolink
703705 }
704706 }
705707
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+
706787 // Make hyperlink for the page
707788 function make_pagelink($page, $alias = '', $anchor = '', $refer = '', $isautolink = FALSE)
708789 {
--- a/pukiwiki.ini.php
+++ b/pukiwiki.ini.php
@@ -1,6 +1,6 @@
11 <?php
22 // 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 $
44 // Copyright (C)
55 // 2002-2006 PukiWiki Developers Team
66 // 2001-2002 Originally written by yu-ji
@@ -130,6 +130,7 @@ $defaultpage = 'FrontPage'; // Top / Default page
130130 $whatsnew = 'RecentChanges'; // Modified page list
131131 $whatsdeleted = 'RecentDeleted'; // Removeed page list
132132 $interwiki = 'InterWikiName'; // Set InterWiki definition here
133+$aliaspage = 'AutoAliasName'; // Set AutoAlias definition here
133134 $menubar = 'MenuBar'; // Menu
134135
135136 /////////////////////////////////////////////////
@@ -178,6 +179,15 @@ $nowikiname = 0;
178179 $autolink = 0; // Bytes, 0 = OFF (try 8)
179180
180181 /////////////////////////////////////////////////
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+/////////////////////////////////////////////////
181191 // Enable Freeze / Unfreeze feature
182192 $function_freeze = 1;
183193
--- /dev/null
+++ b/wiki/4175746F416C6961734E616D65.txt
@@ -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/]]
Show on old repository browser