Commit MetaInfo

Revisão9fd99786b6f537176eecf10b2dae4f0e38ed04f1 (tree)
Hora2020-02-14 02:57:42
Autorteanan <teanan>
Commiterumorigu

Mensagem de Log

BugTrack/2002 AutoAlias

Merged with autoalias branches (r1_4_7_autoalias).

* Link defined keywords in AutoAliasName page

Mudança Sumário

Diff

--- /dev/null
+++ b/cache/autoalias.dat
@@ -0,0 +1,3 @@
1+pukiwiki\.(?:dev|official)
2+(?!)
3+
--- a/lib/file.php
+++ b/lib/file.php
@@ -2,7 +2,7 @@
22 // PukiWiki - Yet another WikiWikiWeb clone.
33 // file.php
44 // Copyright
5-// 2002-2017 PukiWiki Development Team
5+// 2002-2020 PukiWiki Development Team
66 // 2001-2002 Originally written by yu-ji
77 // License: GPL v2 or (at your option) any later version
88 //
@@ -15,6 +15,9 @@ define('PKWK_MAXSHOW_CACHE', 'recent.dat');
1515 // AutoLink
1616 define('PKWK_AUTOLINK_REGEX_CACHE', 'autolink.dat');
1717
18+// AutoAlias
19+define('PKWK_AUTOALIAS_REGEX_CACHE', 'autoalias.dat');
20+
1821 /**
1922 * Get source(wiki text) data of the page
2023 *
@@ -104,6 +107,8 @@ function get_filename($page)
104107 // Put a data(wiki text) into a physical file(diff, backup, text)
105108 function page_write($page, $postdata, $notimestamp = FALSE)
106109 {
110+ global $trackback, $autoalias, $aliaspage;
111+
107112 if (PKWK_READONLY) return; // Do nothing
108113
109114 $postdata = make_str_rules($postdata);
@@ -133,6 +138,19 @@ function page_write($page, $postdata, $notimestamp = FALSE)
133138 file_write(DATA_DIR, $page, $postdata, $notimestamp, $is_delete);
134139
135140 links_update($page);
141+
142+ // Update autoalias.dat (AutoAliasName)
143+ if ($autoalias && $page == $aliaspage) {
144+ $aliases = get_autoaliases();
145+ if (empty($aliases)) {
146+ // Remove
147+ @unlink(CACHE_DIR . PKWK_AUTOALIAS_REGEX_CACHE);
148+ } else {
149+ // Create or Update
150+ autolink_pattern_write(CACHE_DIR . PKWK_AUTOALIAS_REGEX_CACHE,
151+ get_autolink_pattern(array_keys($aliases), $autoalias));
152+ }
153+ }
136154 }
137155
138156 // Modify original text with user-defined / system-defined rules
@@ -602,23 +620,9 @@ function put_lastmodified()
602620 fclose($fp);
603621
604622 // For AutoLink
605- if ($autolink) {
606- list($pattern, $pattern_a, $forceignorelist) =
607- get_autolink_pattern($pages);
608-
609- $file = CACHE_DIR . PKWK_AUTOLINK_REGEX_CACHE;
610- pkwk_touch_file($file);
611- $fp = fopen($file, 'r+') or
612- die_message('Cannot open ' . 'CACHE_DIR/' . PKWK_AUTOLINK_REGEX_CACHE);
613- set_file_buffer($fp, 0);
614- flock($fp, LOCK_EX);
615- ftruncate($fp, 0);
616- rewind($fp);
617- fputs($fp, $pattern . "\n");
618- fputs($fp, $pattern_a . "\n");
619- fputs($fp, join("\t", $forceignorelist) . "\n");
620- flock($fp, LOCK_UN);
621- fclose($fp);
623+ if ($autolink){
624+ autolink_pattern_write(CACHE_DIR . PKWK_AUTOLINK_REGEX_CACHE,
625+ get_autolink_pattern($pages, $autolink));
622626 }
623627 }
624628
@@ -648,6 +652,23 @@ function delete_recent_changes_cache() {
648652 unlink($file);
649653 }
650654
655+// update autolink data
656+function autolink_pattern_write($filename, $autolink_pattern)
657+{
658+ list($pattern, $pattern_a, $forceignorelist) = $autolink_pattern;
659+
660+ $fp = fopen($filename, 'w') or
661+ die_message('Cannot open ' . $filename);
662+ set_file_buffer($fp, 0);
663+ flock($fp, LOCK_EX);
664+ rewind($fp);
665+ fputs($fp, $pattern . "\n");
666+ fputs($fp, $pattern_a . "\n");
667+ fputs($fp, join("\t", $forceignorelist) . "\n");
668+ flock($fp, LOCK_UN);
669+ fclose($fp);
670+}
671+
651672 // Get elapsed date of the page
652673 function get_pg_passage($page, $sw = TRUE)
653674 {
--- a/lib/func.php
+++ b/lib/func.php
@@ -2,7 +2,7 @@
22 // PukiWiki - Yet another WikiWikiWeb clone.
33 // func.php
44 // Copyright
5-// 2002-2019 PukiWiki Development Team
5+// 2002-2020 PukiWiki Development Team
66 // 2001-2002 Originally written by yu-ji
77 // License: GPL v2 or (at your option) any later version
88 //
@@ -723,7 +723,7 @@ function drop_submit($str)
723723 }
724724
725725 // Generate AutoLink patterns (thx to hirofummy)
726-function get_autolink_pattern(& $pages)
726+function get_autolink_pattern(& $pages, $min_len = -1)
727727 {
728728 global $WikiName, $autolink, $nowikiname;
729729
@@ -734,9 +734,13 @@ function get_autolink_pattern(& $pages)
734734 unset($config);
735735 $auto_pages = array_merge($ignorepages, $forceignorepages);
736736
737+ if ($min_len == -1) {
738+ $min_len = $autolink; // set $autolink, when omitted.
739+ }
740+
737741 foreach ($pages as $page)
738742 if (preg_match('/^' . $WikiName . '$/', $page) ?
739- $nowikiname : strlen($page) >= $autolink)
743+ $nowikiname : strlen($page) >= $min_len)
740744 $auto_pages[] = $page;
741745
742746 if (empty($auto_pages)) {
@@ -783,6 +787,50 @@ function get_autolink_pattern_sub(& $pages, $start, $end, $pos)
783787 return $result;
784788 }
785789
790+// Load/get setting pairs from AutoAliasName
791+function get_autoaliases($word = '')
792+{
793+ global $aliaspage, $autoalias_max_words;
794+ static $pairs;
795+
796+ if (! isset($pairs)) {
797+ $pairs = array();
798+ $pattern = <<<EOD
799+\[\[ # open bracket
800+((?:(?!\]\]).)+)> # (1) alias name
801+((?:(?!\]\]).)+) # (2) alias link
802+\]\] # close bracket
803+EOD;
804+ $postdata = join('', get_source($aliaspage));
805+ $matches = array();
806+ $count = 0;
807+ $max = max($autoalias_max_words, 0);
808+ if (preg_match_all('/' . $pattern . '/x', $postdata, $matches, PREG_SET_ORDER)) {
809+ foreach($matches as $key => $value) {
810+ if ($count == $max) break;
811+ $name = trim($value[1]);
812+ if (! isset($pairs[$name])) {
813+ ++$count;
814+ $pairs[$name] = trim($value[2]);
815+ }
816+ unset($matches[$key]);
817+ }
818+ }
819+ }
820+
821+ if ($word === '') {
822+ // An array(): All pairs
823+ return $pairs;
824+ } else {
825+ // A string: Seek the pair
826+ if (isset($pairs[$word])) {
827+ return $pairs[$word];
828+ } else {
829+ return '';
830+ }
831+ }
832+}
833+
786834 /**
787835 * Get propery URI of this script
788836 *
--- a/lib/link.php
+++ b/lib/link.php
@@ -1,7 +1,7 @@
11 <?php
22 // PukiWiki - Yet another WikiWikiWeb clone
3-// $Id: link.php,v 1.20 2011/01/25 15:01:01 henoheno Exp $
4-// Copyright (C) 2003-2007 PukiWiki Developers Team
3+// link.php
4+// Copyright 2003-2020 PukiWiki Development Team
55 // License: GPL v2 or (at your option) any later version
66 //
77 // Backlinks / AutoLinks related functions
@@ -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 = get_autoaliases($_obj->name);
77+ if (is_pagename($_alias)) {
78+ $rel_auto[] = $_alias;
79+ }
7580 } else {
7681 $rel_new[] = $_obj->name;
7782 }
@@ -152,11 +157,18 @@ function links_init()
152157 $_obj->name == $page || $_obj->name == '')
153158 continue;
154159
155- $rel[] = $_obj->name;
156- if (! isset($ref[$_obj->name][$page]))
157- $ref[$_obj->name][$page] = 1;
160+ $_name = $_obj->name;
161+ if (is_a($_obj, 'Link_autoalias')) {
162+ $_alias = get_autoaliases($_name);
163+ if (! is_pagename($_alias))
164+ continue; // not PageName
165+ $_name = $_alias;
166+ }
167+ $rel[] = $_name;
168+ if (! isset($ref[$_name][$page]))
169+ $ref[$_name][$page] = 1;
158170 if (! is_a($_obj, 'Link_autolink'))
159- $ref[$_obj->name][$page] = 0;
171+ $ref[$_name][$page] = 0;
160172 }
161173 $rel = array_unique($rel);
162174 if (! empty($rel)) {
--- a/lib/make_link.php
+++ b/lib/make_link.php
@@ -83,9 +83,11 @@ class InlineConverter
8383 'url_interwiki', // URLs (interwiki definition)
8484 'mailto', // mailto: URL schemes
8585 'interwikiname', // InterWikiNames
86+ 'autoalias', // AutoAlias
8687 'autolink', // AutoLinks
8788 'bracketname', // BracketNames
8889 'wikiname', // WikiNames
90+ 'autoalias_a', // AutoAlias(alphabet)
8991 'autolink_a', // AutoLinks(alphabet)
9092 );
9193 }
@@ -766,6 +768,72 @@ class Link_autolink_a extends Link_autolink
766768 }
767769 }
768770
771+// AutoAlias
772+class Link_autoalias extends Link
773+{
774+ var $forceignorepages = array();
775+ var $auto;
776+ var $auto_a; // alphabet only
777+ var $alias;
778+
779+ function Link_autoalias($start)
780+ {
781+ global $autoalias, $aliaspage;
782+
783+ parent::Link($start);
784+
785+ if (! $autoalias || ! file_exists(CACHE_DIR . PKWK_AUTOALIAS_REGEX_CACHE) || $this->page == $aliaspage)
786+ {
787+ return;
788+ }
789+
790+ @list($auto, $auto_a, $forceignorepages) = file(CACHE_DIR . PKWK_AUTOALIAS_REGEX_CACHE);
791+ $this->auto = $auto;
792+ $this->auto_a = $auto_a;
793+ $this->forceignorepages = explode("\t", trim($forceignorepages));
794+ $this->alias = '';
795+ }
796+ function get_pattern()
797+ {
798+ return isset($this->auto) ? '(' . $this->auto . ')' : FALSE;
799+ }
800+ function get_count()
801+ {
802+ return 1;
803+ }
804+ function set($arr,$page)
805+ {
806+ list($name) = $this->splice($arr);
807+ // Ignore pages listed
808+ if (in_array($name, $this->forceignorepages)) {
809+ return FALSE;
810+ }
811+ return parent::setParam($page,$name,'','pagename',$name);
812+ }
813+
814+ function toString()
815+ {
816+ $this->alias = get_autoaliases($this->name);
817+ if ($this->alias != '') {
818+ $link = '[[' . $this->name . '>' . $this->alias . ']]';
819+ return make_link($link);
820+ }
821+ return '';
822+ }
823+}
824+
825+class Link_autoalias_a extends Link_autoalias
826+{
827+ function Link_autoalias_a($start)
828+ {
829+ parent::Link_autoalias($start);
830+ }
831+ function get_pattern()
832+ {
833+ return isset($this->auto_a) ? '(' . $this->auto_a . ')' : FALSE;
834+ }
835+}
836+
769837 // Make hyperlink for the page
770838 function make_pagelink($page, $alias = '', $anchor = '', $refer = '', $isautolink = FALSE)
771839 {
--- a/pukiwiki.ini.php
+++ b/pukiwiki.ini.php
@@ -2,7 +2,7 @@
22 // PukiWiki - Yet another WikiWikiWeb clone
33 // pukiwiki.ini.php
44 // Copyright
5-// 2002-2019 PukiWiki Development Team
5+// 2002-2020 PukiWiki Development Team
66 // 2001-2002 Originally written by yu-ji
77 // License: GPL v2 or (at your option) any later version
88 //
@@ -129,6 +129,7 @@ $defaultpage = 'FrontPage'; // Top / Default page
129129 $whatsnew = 'RecentChanges'; // Modified page list
130130 $whatsdeleted = 'RecentDeleted'; // Removeed page list
131131 $interwiki = 'InterWikiName'; // Set InterWiki definition here
132+$aliaspage = 'AutoAliasName'; // Set AutoAlias definition here
132133 $menubar = 'MenuBar'; // Menu
133134
134135 /////////////////////////////////////////////////
@@ -159,11 +160,22 @@ $nowikiname = 0;
159160
160161 /////////////////////////////////////////////////
161162 // AutoLink feature
163+// Automatic link to existing pages (especially helpful for non-wikiword pages, but heavy)
162164
163-// AutoLink minimum length of page name
165+// Minimum length of page name
164166 $autolink = 0; // Bytes, 0 = OFF (try 8)
165167
166168 /////////////////////////////////////////////////
169+// AutoAlias feature
170+// Automatic link from specified word, to specifiled URI, page or InterWiki
171+
172+// Minimum length of alias "from" word
173+$autoalias = 0; // Bytes, 0 = OFF (try 8)
174+
175+// Limit loading valid alias pairs
176+$autoalias_max_words = 50; // pairs
177+
178+/////////////////////////////////////////////////
167179 // Enable Freeze / Unfreeze feature
168180 $function_freeze = 1;
169181
--- /dev/null
+++ b/wiki/4175746F416C6961734E616D65.txt
@@ -0,0 +1,6 @@
1+*AutoAliasName [#qf9311bb]
2+AutoAlias用の定義リストです。
3+
4+* PukiWiki [#ee87d39e]
5+-[[pukiwiki.official>https://pukiwiki.osdn.jp/]]
6+-[[pukiwiki.dev>https://pukiwiki.osdn.jp/dev/]]
Show on old repository browser