From e81b0518b0d0bd149669049abd619f1de5b79138 Mon Sep 17 00:00:00 2001 From: dairiki Date: Sun, 15 Sep 2002 05:52:23 +0000 Subject: [PATCH] Fixed so that wiki.listLinks() returns external as well as internal links. Since the external links aren't currently stored in the link database, we need to scan the page text for the links. We might as well pull the internal links out from the same scan. (Commented out the old code which queries the link db.) Also fixed a couple bugs/features: o wiki.listLinks() was listing backlinks not outgoing links. o When urlencoding short strings we only really need to encode the ascii control characters (which aren't allowed in XML 1.0 :-/) git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@2346 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/XmlRpcServer.php | 51 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/lib/XmlRpcServer.php b/lib/XmlRpcServer.php index 3a71f8901..bfdaa24b8 100644 --- a/lib/XmlRpcServer.php +++ b/lib/XmlRpcServer.php @@ -1,5 +1,5 @@ * * LICENCE @@ -123,11 +123,24 @@ function _getPageRevision ($params) * XML-RPC base64 binary objects. */ +/** + * Urlencode ASCII control characters. + * + * (And control characters...) + * + * @param string $str + * @return string + * @see urlencode + */ +function UrlencodeControlCharacters($str) { + return preg_replace('/([\x00-\x20])/e', "urlencode('\\1')", $str); +} + /** * Convert a short string (page name, author) to xmlrpcval. */ function short_string ($str) { - return new xmlrpcval(rawurlencode(utf8_encode($str)), 'string'); + return new xmlrpcval(UrlencodeControlCharacters(utf8_encode($str)), 'string'); } /** @@ -383,9 +396,10 @@ function listLinks($params) $dbh = $request->getDbh(); if (! $dbh->isWikiPage($pagename)) return NoSuchPage(); - + $page = $dbh->getPage($pagename); - $linkiterator = $page->getLinks(); + /* + $linkiterator = $page->getLinks(false); $linkstruct = array(); while ($currentpage = $linkiterator->next()) { $currentname = $currentpage->getName(); @@ -412,6 +426,35 @@ function listLinks($params) 'href' => $href), "struct"); } + */ + + $current = $page->getCurrentRevision(); + list ($pages, $urls) = ExtractLinks($current->getContent()); + + $type = new xmlrpcval("internal"); + foreach ($pages as $wikiword) { + $name = short_string($wikiword); + $args = array(); + if (! $dbh->isWikiPage($wikiword)) + $args['action'] = 'edit'; + // FIXME: see comments in above commented sections + // about possible screwed up absolute URLS... + $href = short_string(WikiURL($wikiword, $args, 'abspath')); + $linkstruct[] = new xmlrpcval(array('name'=> $name, + 'type'=> $type, + 'href' => $href), + "struct"); + } + + $type = new xmlrpcval("external"); + foreach ($urls as $url) { + $href = short_string($url); + $linkstruct[] = new xmlrpcval(array('name'=> $href, + 'type'=> $type, + 'href' => $href), + "struct"); + } + return new xmlrpcresp(new xmlrpcval ($linkstruct, "array")); } -- 2.45.0