From 57a3f382304b10700a1ddd89248ff7060c400f12 Mon Sep 17 00:00:00 2001 From: rurban Date: Mon, 14 Nov 2005 22:27:07 +0000 Subject: [PATCH] add linkrelation support getPageLinks returns now an array of hashes pass stoplist through iterator git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@4976 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/CachedMarkup.php | 106 ++++++++++++++++++++++++++++++++++++++----- lib/WikiDB.php | 53 ++++++++++++++++++---- 2 files changed, 138 insertions(+), 21 deletions(-) diff --git a/lib/CachedMarkup.php b/lib/CachedMarkup.php index 0f149d431..fa51aa6aa 100644 --- a/lib/CachedMarkup.php +++ b/lib/CachedMarkup.php @@ -1,5 +1,5 @@ * Copyright (C) 2004, 2005 $ThePhpWikiProgrammingTeam * @@ -78,24 +78,20 @@ class CacheableMarkup extends XmlContent { /** Get names of wikipages linked to. * * @return array - * A list of wiki page names (strings). + * A hash of linkto=>pagenames, relation=>pagenames (strings). */ function getWikiPageLinks() { - include_once('lib/WikiPlugin.php'); - $ploader = new WikiPluginLoader(); + // include_once('lib/WikiPlugin.php'); + // $ploader = new WikiPluginLoader(); $links = array(); foreach ($this->_content as $item) { if (!isa($item, 'Cached_DynamicContent')) continue; - if (!($item_links = $item->getWikiPageLinks($this->_basepage))) continue; - foreach ($item_links as $pagename) - if (is_string($pagename) and $pagename != '') - $links[] = $pagename; + $links = array_merge($links, $item_links); } - return array_unique($links); } @@ -263,10 +259,11 @@ class Cached_DynamicContent { } class XmlRpc_LinkInfo { - function XmlRpc_LinkInfo($page, $type, $href) { + function XmlRpc_LinkInfo($page, $type, $href, $relation = '') { $this->page = $page; $this->type = $type; $this->href = $href; + $this->relation = $relation; //$this->pageref = str_replace("/RPC2.php", "/index.php", $href); } } @@ -285,12 +282,16 @@ class Cached_Link extends Cached_DynamicContent { function getLinkInfo($basepage) { return new XmlRpc_LinkInfo($this->_getName($basepage), $this->_getType(), - $this->_getURL($basepage)); + $this->_getURL($basepage), + $this->_getRelation($basepage)); } function _getURL($basepage) { return $this->_url; } + function __getRelation($basepage) { + return $this->_relation; + } } class Cached_WikiLink extends Cached_Link { @@ -315,7 +316,8 @@ class Cached_WikiLink extends Cached_Link { function getWikiPageLinks($basepage) { if ($basepage == '') return false; - if ($link = $this->getPagename($basepage)) return array($link); + if ($link = $this->getPagename($basepage)) + return array(array('linkto' => $link, 'relation' => 0)); else return false; } @@ -391,6 +393,86 @@ class Cached_PhpwikiURL extends Cached_DynamicContent return $this->_url; } } + +class Cached_SemanticLink extends Cached_WikiLink { + + function Cached_SemanticLink ($url, $label) { + $this->_url = $url; + if ($label && $label != $url) + $this->_label = $label; + } + + function isInlineElement() { + return true; + } + + function getPagename($basepage) { + $page = new WikiPageName($this->_page, $basepage); + if ($page->isValid()) return $page->name; + else return false; + } + + /* add relation to the link table */ + function getWikiPageLinks($basepage) { + if ($basepage == '') return false; + if ($link = $this->getPagename($basepage)) + return array(array('linkto' => $link, 'relation' => $this->_relation)); + else return false; + } + + function _expand($url, $label = false) { + $m = array(); + if (!preg_match('/^ ([^:]*) (:[:-]) (.*) $/x', $url, $m)) { + return HTML::strong(array('class' => 'rawurl'), + HTML::u(array('class' => 'baduri'), + _("BAD semantic relation link"))); + } + $relation = $this->_relation = urldecode($m[1]); + $page = $this->_page = urldecode($m[3]); + $class = 'wikilink'; + // do not link to the attribute value, but to the attribute + $is_attribute = ($m[2] == ':-'); + if ($label) { + return HTML::span( + HTML::a(array('href' => WikiURL($is_attribute ? $relation : $page), + 'class' => $class), + $label) + ); + } elseif ($is_attribute) { + return HTML::span( + HTML::a(array('href' => WikiURL($relation), + 'class' => $class), + $url) + ); + } else { + return HTML::span( + HTML::a(array('href' => WikiURL($relation), + 'class' => $class), + $relation), + $m[2], + HTML::a(array('href' => WikiURL($page), + 'class' => $class), + $page) + ); + } + } + function expand($basepage, &$markup) { + $label = isset($this->_label) ? $this->_label : false; + return $this->_expand($this->_url, $label); + } + + function asXML() { + $label = isset($this->_label) ? $this->_label : false; + $link = $this->_expand($this->_url, $label); + return $link->asXML(); + } + + function asString() { + if (isset($this->_label)) + return $this->_label; + return $this->_url; + } +} class Cached_ExternalLink extends Cached_Link { diff --git a/lib/WikiDB.php b/lib/WikiDB.php index 082144315..b4f20b7c9 100644 --- a/lib/WikiDB.php +++ b/lib/WikiDB.php @@ -1,5 +1,5 @@ _backend->text_search($search, true, $sortby, $limit, $exclude); return new WikiDB_PageIterator($this, $result, array('exclude' => $exclude, - 'limit' => $limit)); + 'limit' => $limit, + 'stoplisted' => $result->stoplisted + )); } /** @@ -801,7 +803,7 @@ class WikiDB_Page * @param hash $metadata Metadata for new revision. * All values in the hash should be scalars (strings or integers). * - * @param array $links List of pagenames which this page links to. + * @param hash $links List of linkto=>pagename, relation=>pagename which this page links to. * * @return WikiDB_PageRevision Returns the new WikiDB_PageRevision object. If * $version was incorrect, returns false @@ -1084,7 +1086,7 @@ class WikiDB_Page * * @return WikiDB_PageRevision The current WikiDB_PageRevision object. */ - function getCurrentRevision($need_content = true) { + function getCurrentRevision ($need_content = true) { $backend = &$this->_wikidb->_backend; $cache = &$this->_wikidb->_cache; $pagename = &$this->_pagename; @@ -1115,7 +1117,7 @@ class WikiDB_Page * false if the requested revision does not exist in the {@link WikiDB}. * Note that version zero of any page always exists. */ - function getRevision($version, $need_content=true) { + function getRevision ($version, $need_content=true) { $cache = &$this->_wikidb->_cache; $pagename = &$this->_pagename; @@ -1147,7 +1149,7 @@ class WikiDB_Page * unless $version is greater than zero, a revision (perhaps version zero, * the default revision) will always be found. */ - function getRevisionBefore($version=false, $need_content=true) { + function getRevisionBefore ($version=false, $need_content=true) { $backend = &$this->_wikidb->_backend; $pagename = &$this->_pagename; if ($version === false) @@ -1191,8 +1193,8 @@ class WikiDB_Page * @return WikiDB_PageIterator A WikiDB_PageIterator containing * all matching pages. */ - function getLinks($reversed = true, $include_empty=false, $sortby=false, - $limit=false, $exclude=false) { + function getLinks ($reversed = true, $include_empty=false, $sortby=false, + $limit=false, $exclude=false) { $backend = &$this->_wikidb->_backend; $result = $backend->get_links($this->_pagename, $reversed, $include_empty, $sortby, $limit, $exclude); @@ -1215,6 +1217,22 @@ class WikiDB_Page function getPageLinks($include_empty=false, $sortby=false, $limit=false, $exclude=false) { return $this->getLinks(false, $include_empty, $sortby, $limit, $exclude); } + /** + * Relations: All links from this page to other pages with relation <> 0. + * Like isa:=page + */ + function getRelations($sortby=false, $limit=false, $exclude=false) { + $backend = &$this->_wikidb->_backend; + $result = $backend->get_links($this->_pagename, false, true, + $sortby, $limit, $exclude, + true); + // we do not care for the linked page versiondata, just the pagename and relationname + return new WikiDB_PageIterator($this->_wikidb, $result, + array('include_empty' => true, + 'sortby' => $sortby, + 'limit' => $limit, + 'exclude' => $exclude)); + } /** * possibly faster link existance check. not yet accelerated. @@ -1233,6 +1251,17 @@ class WikiDB_Page $iter->free(); return false; } + + /* Semantic relations are links with the relation pointing to another page, + the so called "RDF Triple". + [San Diego] is%20a::city + => "At the page San Diego there is a relation link of 'is a' to the page 'city'." + */ + + /* Semantic attributes for a page. + [San Diego] population:=1,305,736 + Attributes are links with the relation pointing to another page. + */ /** * Access WikiDB_Page non version-specific meta-data. @@ -1798,7 +1827,10 @@ class WikiDB_PageIterator and !$this->_options['include_empty'] and isset($next['id'])) { $this->_wikidb->_cache->_id_cache[$next['pagename']] = $next['id']; } - return new WikiDB_Page($this->_wikidb, $pagename); + $page = new WikiDB_Page($this->_wikidb, $pagename); + if (isset($next['linkrelation'])) + $page->set('linkrelation', $next['linkrelation']); + return $page; } /** @@ -2198,6 +2230,9 @@ function _sql_debuglog_shutdown_function() { } // $Log: not supported by cvs2svn $ +// Revision 1.137 2005/10/12 06:16:18 rurban +// better From header +// // Revision 1.136 2005/10/03 16:14:57 rurban // improve description // -- 2.45.0