OSDN Git Service

BugTrack2/2: merged with autoalias branches (r1_4_7_autoalias). r1_4_7_autoalias_merge_end
authorteanan <teanan>
Tue, 8 Aug 2006 18:11:00 +0000 (03:11 +0900)
committerteanan <teanan>
Tue, 8 Aug 2006 18:11:00 +0000 (03:11 +0900)
cache/autoalias.dat [new file with mode: 0644]
lib/file.php
lib/func.php
lib/link.php
lib/make_link.php
pukiwiki.ini.php
wiki/4175746F416C6961734E616D65.txt [new file with mode: 0644]

diff --git a/cache/autoalias.dat b/cache/autoalias.dat
new file mode 100644 (file)
index 0000000..8d6c163
--- /dev/null
@@ -0,0 +1,3 @@
+pukiwiki\.(?:dev|official)
+(?!)
+
index dec5781..817378f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: file.php,v 1.72 2006/06/11 14:42:09 henoheno Exp $
+// $Id: file.php,v 1.73 2006/08/08 18:10:59 teanan Exp $
 // Copyright (C)
 //   2002-2006 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -63,6 +63,7 @@ function get_filename($page)
 function page_write($page, $postdata, $notimestamp = FALSE)
 {
        global $trackback;
+       global $autoalias, $aliaspage;
 
        if (PKWK_READONLY) return; // Do nothing
 
@@ -88,6 +89,18 @@ function page_write($page, $postdata, $notimestamp = FALSE)
        }
 
        links_update($page);
+
+       // for AutoAlias
+       if ($autoalias>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)
 {
index 92e1fd6..11d9e40 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: func.php,v 1.73 2006/05/15 16:41:39 teanan Exp $
+// $Id: func.php,v 1.74 2006/08/08 18:10:59 teanan Exp $
 // Copyright (C)
 //   2002-2006 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -524,7 +524,7 @@ function drop_submit($str)
 }
 
 // Generate AutoLink patterns (thx to hirofummy)
-function get_autolink_pattern(& $pages)
+function get_autolink_pattern(& $pages, $min_len = -1)
 {
        global $WikiName, $autolink, $nowikiname;
 
@@ -535,9 +535,13 @@ function get_autolink_pattern(& $pages)
        unset($config);
        $auto_pages = array_merge($ignorepages, $forceignorepages);
 
+       if ($min_len == -1) {
+               $min_len = $autolink;   // set $autolink, when omitted.
+       }
+
        foreach ($pages as $page)
                if (preg_match('/^' . $WikiName . '$/', $page) ?
-                   $nowikiname : strlen($page) >= $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 = <<<EOD
+\[\[                # open bracket
+((?:(?!\]\]).)+)>   # (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 = '')
 {
index cdcf345..145eb0f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone
-// $Id: link.php,v 1.11 2006/04/06 03:00:00 teanan Exp $
+// $Id: link.php,v 1.12 2006/08/08 18:10:59 teanan Exp $
 // Copyright (C) 2003-2006 PukiWiki Developers Team
 // License: GPL v2 or (at your option) any later version
 //
@@ -72,6 +72,11 @@ function links_update($page)
 
                if (is_a($_obj, 'Link_autolink')) { // ¹Ôµ·¤¬°­¤¤
                        $rel_auto[] = $_obj->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)) {
index b18b9a6..b0e8d5c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: make_link.php,v 1.30 2005/12/10 07:57:30 henoheno Exp $
+// $Id: make_link.php,v 1.31 2006/08/08 18:10:59 teanan Exp $
 // Copyright (C)
 //   2003-2005 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -60,9 +60,11 @@ class InlineConverter
                                'url_interwiki', // URLs (interwiki definition)
                                'mailto',        // mailto: URL schemes
                                'interwikiname', // InterWikiNames
+                               'autoalias',     // AutoAlias
                                'autolink',      // AutoLinks
                                'bracketname',   // BracketNames
                                'wikiname',      // WikiNames
+                               'autoalias_a',   // AutoAlias(alphabet)
                                'autolink_a',    // AutoLinks(alphabet)
                        );
                }
@@ -703,6 +705,85 @@ class Link_autolink_a extends Link_autolink
        }
 }
 
+// AutoAlias
+class Link_autoalias extends Link
+{
+       var $forceignorepages = array();
+       var $auto;
+       var $auto_a; // alphabet only
+       var $alias;
+
+       function Link_autoalias($start)
+       {
+               global $autoalias, $aliaspage;
+
+               parent::Link($start);
+
+               if (!$autoalias || !file_exists(CACHE_DIR.'autoalias.dat') || $this->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)
 {
index 5e68172..63e3b4a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone
-// $Id: pukiwiki.ini.php,v 1.140 2006/06/11 14:35:39 henoheno Exp $
+// $Id: pukiwiki.ini.php,v 1.141 2006/08/08 18:10:59 teanan Exp $
 // Copyright (C)
 //   2002-2006 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -130,6 +130,7 @@ $defaultpage  = 'FrontPage';     // Top / Default page
 $whatsnew     = 'RecentChanges'; // Modified page list
 $whatsdeleted = 'RecentDeleted'; // Removeed page list
 $interwiki    = 'InterWikiName'; // Set InterWiki definition here
+$aliaspage    = 'AutoAliasName'; // Set AutoAlias definition here
 $menubar      = 'MenuBar';       // Menu
 
 /////////////////////////////////////////////////
@@ -178,6 +179,15 @@ $nowikiname = 0;
 $autolink = 0; // Bytes, 0 = OFF (try 8)
 
 /////////////////////////////////////////////////
+// AutoAlias feature
+
+// AutoAlias minimum bytes (0 = Disable)
+$autoalias = 0;
+
+// Maximum number of words which AutoAlias replace
+$autoalias_max_words = 50;
+
+/////////////////////////////////////////////////
 // Enable Freeze / Unfreeze feature
 $function_freeze = 1;
 
diff --git a/wiki/4175746F416C6961734E616D65.txt b/wiki/4175746F416C6961734E616D65.txt
new file mode 100644 (file)
index 0000000..ef81b77
--- /dev/null
@@ -0,0 +1,6 @@
+*AutoAliasName [#qf9311bb]
+AutoAliasÍѤÎÄêµÁ¥ê¥¹¥È¤Ç¤¹¡£
+
+* PukiWiki [#ee87d39e]
+-[[pukiwiki.official>http://pukiwiki.sourceforge.jp/]]
+-[[pukiwiki.dev>http://pukiwiki.sourceforge.jp/dev/]]