From 507a82a87af4453a46b895f63174a24b496e9137 Mon Sep 17 00:00:00 2001 From: rurban Date: Thu, 21 Jul 2005 19:27:04 +0000 Subject: [PATCH] add wiki.titleSearch, bump to XMLRPC protocol version 2 git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@4729 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/XmlRpcServer.php | 57 ++++++++++++++++++++++++++++++++-- tests/xmlrpc/xmlrpc-client.php | 11 ++++--- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/lib/XmlRpcServer.php b/lib/XmlRpcServer.php index 626fae63f..ca897b90e 100644 --- a/lib/XmlRpcServer.php +++ b/lib/XmlRpcServer.php @@ -1,5 +1,5 @@ * Copyright (C) 2004, 2005 $ThePhpWikiProgrammingTeam * @@ -531,7 +531,7 @@ function putPage($params) { } $request->_user = _getUser($userid); $request->_user->_group = $request->getGroup(); - $$user = $request->_user->AuthCheck($userid, $passwd); + $request->_user->AuthCheck($userid, $passwd); if (! mayAccessPage ('edit', $pagename)) { return new xmlrpcresp( @@ -636,6 +636,59 @@ function mailPasswordToUser($params) } return new xmlrpcresp(new xmlrpcval ($success, "boolean")); } + +/** + * struct titleSearch(String substring [, Integer option = 0]) + * returns an array of matching pagenames. + * TODO: standardize options + * + * @author: Reini Urban + */ +$wiki_dmap['titleSearch'] += array('signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcInt)), + 'documentation' => "Return matching pagenames. +Option 1: caseexact, 2: regex, 4: starts_with, 8: exact", + 'function' => 'titleSearch'); + +function titleSearch($params) +{ + global $request; + $ParamPageName = $params->getParam(0); + $searchstring = short_string_decode($ParamPageName->scalarval()); + if (count($params->params) > 1) { + $ParamOption = $params->getParam(1); + $option = $ParamOption->scalarval(); + } else $option = 0; + // default option: substring, case-inexact + + $case_exact = $option & 1; + $regex = $option & 2; + if (!$regex) { + if ($option & 4) { // STARTS_WITH + $regex = true; + $searchstring = "^".$searchstring; + } + if ($option & 8) { // EXACT + $regex = true; + $searchstring = "^".$searchstring."$"; + } + } else { + if ($option & 4 or $option & 8) { + global $xmlrpcerruser; + return new xmlrpcresp(0, $xmlrpcerruser + 1, "Invalid option"); + } + } + include_once("lib/TextSearchQuery.php"); + $query = new TextSearchQuery($searchstring, $case_exact, $regex ? 'auto' : 'none'); + $dbh = $request->getDbh(); + $iterator = $dbh->titleSearch($query); + $pages = array(); + while ($page = $iterator->next()) { + $pages[] = short_string($page->getName()); + } + return new xmlrpcresp(new xmlrpcval($pages, "array")); +} + /** * Construct the server instance, and set up the dispatch map, diff --git a/tests/xmlrpc/xmlrpc-client.php b/tests/xmlrpc/xmlrpc-client.php index a829fae16..77db13bb6 100644 --- a/tests/xmlrpc/xmlrpc-client.php +++ b/tests/xmlrpc/xmlrpc-client.php @@ -171,11 +171,11 @@ function run_easy_tests($server, $debug=0, $output = null) { //global $wiki_dmap; - run_test($server, $debug, $output, "wiki.getRPCVersionSupported", '', 1); + run_test($server, $debug, $output, "wiki.getRPCVersionSupported", '', 2); // getRecentChanges of the last day: - // Note: may crash with dba - run_test($server, $debug, $output, "wiki.getRecentChanges", iso8601_encode(time()-86400)); + // Note: crashes with dba on index.php, not on RPC2.php + //run_test($server, $debug, $output, "wiki.getRecentChanges", iso8601_encode(time()-86400)); run_test($server, $debug, $output, "wiki.getPage", "HomePage", "* What is a WikiWikiWeb? A description of this application. * Learn HowToUseWiki and learn about AddingPages. * Use the SandBox page to experiment with Wiki pages. * Please sign your name in RecentVisitors. * See RecentChanges for the latest page additions and changes. * Find out which pages are MostPopular. * Read the ReleaseNotes and RecentReleases. * Administer this wiki via PhpWikiAdministration. * See more PhpWikiDocumentation."); run_test($server, $debug, $output, "wiki.getPageVersion", array("HomePage", 1)); @@ -198,7 +198,8 @@ function run_easy_tests($server, $debug=0, $output = null) { run_test($server, $debug, $output, "wiki.rssPleaseNotify", "HomePage", 0); run_test($server, $debug, $output, "wiki.mailPasswordToUser", ADMIN_USER); - + + run_test($server, $debug, $output, "wiki.titleSearch", "Hom"); } function run_stress_tests($server, $debug=0, $output=null) { @@ -229,7 +230,7 @@ if ($server) { $output['version'] = $GLOBALS['HTTP_GET_VARS']['version']; if ($server) { $title = $server['title']; - echo "

Results for $title

"; + echo "

Results for $title

"; if($GLOBALS['HTTP_GET_VARS']['stress'] == 1) { run_stress_tests($server, $debug, $output); -- 2.45.0