// PukiWiki - Yet another WikiWikiWeb clone.
// file.php
// Copyright
-// 2002-2017 PukiWiki Development Team
+// 2002-2020 PukiWiki Development Team
// 2001-2002 Originally written by yu-ji
// License: GPL v2 or (at your option) any later version
//
// AutoLink
define('PKWK_AUTOLINK_REGEX_CACHE', 'autolink.dat');
+// AutoAlias
+define('PKWK_AUTOALIAS_REGEX_CACHE', 'autoalias.dat');
+
/**
* Get source(wiki text) data of the page
*
// Put a data(wiki text) into a physical file(diff, backup, text)
function page_write($page, $postdata, $notimestamp = FALSE)
{
+ global $autoalias, $aliaspage;
+
if (PKWK_READONLY) return; // Do nothing
$postdata = make_str_rules($postdata);
file_write(DATA_DIR, $page, $postdata, $notimestamp, $is_delete);
links_update($page);
+
+ // Update autoalias.dat (AutoAliasName)
+ if ($autoalias && $page === $aliaspage) {
+ update_autoalias_cache_file();
+ }
}
// Modify original text with user-defined / system-defined rules
// 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);
+ autolink_pattern_write(CACHE_DIR . PKWK_AUTOLINK_REGEX_CACHE,
+ get_autolink_pattern($pages, $autolink));
}
}
unlink($file);
}
+// 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);
+}
+
+// Update AutoAlias regex cache
+function update_autoalias_cache_file()
+{
+ global $autoalias; // Disable (0), Enable (min-length)
+ $aliases = get_autoaliases();
+ if (empty($aliases)) {
+ // Remove
+ @unlink(CACHE_DIR . PKWK_AUTOALIAS_REGEX_CACHE);
+ } else {
+ // Create or Update
+ autolink_pattern_write(CACHE_DIR . PKWK_AUTOALIAS_REGEX_CACHE,
+ get_autolink_pattern(array_keys($aliases), $autoalias));
+ }
+}
+
// Get elapsed date of the page
function get_pg_passage($page, $sw = TRUE)
{
// PukiWiki - Yet another WikiWikiWeb clone.
// func.php
// Copyright
-// 2002-2019 PukiWiki Development Team
+// 2002-2020 PukiWiki Development Team
// 2001-2002 Originally written by yu-ji
// License: GPL v2 or (at your option) any later version
//
}
// Generate AutoLink patterns (thx to hirofummy)
-function get_autolink_pattern(& $pages)
+function get_autolink_pattern($pages, $min_length)
{
- global $WikiName, $autolink, $nowikiname;
+ global $WikiName, $nowikiname;
$config = new Config('AutoLink');
$config->read();
unset($config);
$auto_pages = array_merge($ignorepages, $forceignorepages);
- foreach ($pages as $page)
+ foreach ($pages as $page) {
if (preg_match('/^' . $WikiName . '$/', $page) ?
- $nowikiname : strlen($page) >= $autolink)
+ $nowikiname : strlen($page) >= $min_length) {
$auto_pages[] = $page;
-
+ }
+ }
if (empty($auto_pages)) {
$result = $result_a = '(?!)';
} else {
return array($result, $result_a, $forceignorepages);
}
-function get_autolink_pattern_sub(& $pages, $start, $end, $pos)
+function get_autolink_pattern_sub($pages, $start, $end, $pos)
{
if ($end == 0) return '(?!)';
return $result;
}
+// Get AutoAlias value
+function get_autoalias_right_link($alias_name)
+{
+ $pairs = get_autoaliases();
+ // A string: Seek the pair
+ if (isset($pairs[$alias_name])) {
+ return $pairs[$alias_name];
+ }
+ return '';
+}
+
+// Load setting pairs from AutoAliasName
+function get_autoaliases()
+{
+ global $aliaspage, $autoalias_max_words;
+ static $pairs;
+
+ if (! isset($pairs)) {
+ $pairs = array();
+ $pattern = <<<EOD
+\[\[ # open bracket
+((?:(?!\]\]).)+)> # (1) alias name
+((?:(?!\]\]).)+) # (2) alias link
+\]\] # close bracket
+EOD;
+ $postdata = join('', get_source($aliaspage));
+ $matches = array();
+ $count = 0;
+ $max = max($autoalias_max_words, 0);
+ if (preg_match_all('/' . $pattern . '/x', $postdata, $matches, PREG_SET_ORDER)) {
+ foreach($matches as $key => $value) {
+ if ($count == $max) break;
+ $name = trim($value[1]);
+ if (! isset($pairs[$name])) {
+ ++$count;
+ $pairs[$name] = trim($value[2]);
+ }
+ unset($matches[$key]);
+ }
+ }
+ }
+ return $pairs;
+}
+
/**
* Get propery URI of this script
*
<?php
// PukiWiki - Yet another WikiWikiWeb clone
-// $Id: link.php,v 1.20 2011/01/25 15:01:01 henoheno Exp $
-// Copyright (C) 2003-2007 PukiWiki Developers Team
+// link.php
+// Copyright 2003-2020 PukiWiki Development Team
// License: GPL v2 or (at your option) any later version
//
// Backlinks / AutoLinks related functions
if (is_a($_obj, 'Link_autolink')) { // 行儀が悪い
$rel_auto[] = $_obj->name;
+ } else if (is_a($_obj, 'Link_autoalias')) {
+ $_alias = get_autoalias_right_link($_obj->name);
+ if (is_pagename($_alias)) {
+ $rel_auto[] = $_alias;
+ }
} else {
$rel_new[] = $_obj->name;
}
$links = links_get_objects($page);
foreach ($links as $_obj) {
if (! isset($_obj->type) || $_obj->type != 'pagename' ||
- $_obj->name == $page || $_obj->name == '')
+ $_obj->name == $page || $_obj->name == '') {
continue;
-
- $rel[] = $_obj->name;
- if (! isset($ref[$_obj->name][$page]))
- $ref[$_obj->name][$page] = 1;
- if (! is_a($_obj, 'Link_autolink'))
- $ref[$_obj->name][$page] = 0;
+ }
+ $_name = $_obj->name;
+ if (is_a($_obj, 'Link_autoalias')) {
+ $_alias = get_autoalias_right_link($_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[$_name][$page] = 0;
+ }
}
$rel = array_unique($rel);
if (! empty($rel)) {
'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)
);
}
}
}
+// 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 . PKWK_AUTOALIAS_REGEX_CACHE) || $this->page == $aliaspage)
+ {
+ return;
+ }
+
+ @list($auto, $auto_a, $forceignorepages) = file(CACHE_DIR . PKWK_AUTOALIAS_REGEX_CACHE);
+ $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 = get_autoalias_right_link($this->name);
+ if ($this->alias != '') {
+ $link = '[[' . $this->name . '>' . $this->alias . ']]';
+ return make_link($link);
+ }
+ return '';
+ }
+}
+
+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)
{
EOS;
page_write($autoticketlink_def_page, $body);
}
+
+function init_autoalias_def_page()
+{
+ global $aliaspage; // 'AutoAliasName'
+ $autoticketlink_def_page = get_autoticketlink_def_page();
+ if (is_page($aliaspage)) {
+ return;
+ }
+ $body = <<<EOS
+#freeze
+*AutoAliasName [#qf9311bb]
+AutoAlias definition
+
+Reference: https://pukiwiki.osdn.jp/?AutoAlias
+
+* PukiWiki [#ee87d39e]
+-[[pukiwiki.official>https://pukiwiki.osdn.jp/]]
+-[[pukiwiki.dev>https://pukiwiki.osdn.jp/dev/]]
+EOS;
+ page_write($aliaspage, $body);
+ update_autoalias_cache_file();
+}
*/
function plugin_edit_setup_initial_pages()
{
+ global $autoalias;
+
// Related: Rename plugin
if (exist_plugin('rename') && function_exists('plugin_rename_setup_initial_pages')) {
plugin_rename_setup_initial_pages();
}
// AutoTicketLinkName page
init_autoticketlink_def_page();
+ // AutoAliasName page
+ if ($autoalias) {
+ init_autoalias_def_page();
+ }
}
// PukiWiki - Yet another WikiWikiWeb clone
// pukiwiki.ini.php
// Copyright
-// 2002-2019 PukiWiki Development Team
+// 2002-2020 PukiWiki Development Team
// 2001-2002 Originally written by yu-ji
// License: GPL v2 or (at your option) any later version
//
$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
/////////////////////////////////////////////////
/////////////////////////////////////////////////
// AutoLink feature
+// Automatic link to existing pages
// AutoLink minimum length of page name
$autolink = 0; // Bytes, 0 = OFF (try 8)
/////////////////////////////////////////////////
+// AutoAlias feature
+// Automatic link from specified word, to specifiled URI, page or InterWiki
+
+// AutoAlias minimum length of alias "from" word
+$autoalias = 0; // Bytes, 0 = OFF (try 8)
+
+// Limit loading valid alias pairs
+$autoalias_max_words = 50; // pairs
+
+/////////////////////////////////////////////////
// Enable Freeze / Unfreeze feature
$function_freeze = 1;