2 // $Id: XmlRpcServer.php,v 1.21 2007-01-04 16:42:13 rurban Exp $
3 /* Copyright (C) 2002, Lawrence Akka <lakka@users.sourceforge.net>
4 * Copyright (C) 2004, 2005 $ThePhpWikiProgrammingTeam
8 * This file is part of PhpWiki.
10 * PhpWiki is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * PhpWiki is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with PhpWiki; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * LIBRARY USED - POSSIBLE PROBLEMS
25 * ================================
27 * This file provides an XML-RPC interface for PhpWiki.
28 * It checks for the existence of the xmlrpc-epi c library by Dan Libby
29 * (see http://uk2.php.net/manual/en/ref.xmlrpc.php), and falls back to
30 * the slower PHP counterpart XML-RPC library by Edd Dumbill.
31 * See http://xmlrpc.usefulinc.com/php.html for details.
33 * INTERFACE SPECIFICTION
34 * ======================
36 * The interface specification is that discussed at
37 * http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=WikiRPCInterface
39 * See also http://www.usemod.com/cgi-bin/mb.pl?XmlRpc
40 * or http://www.devshed.com/c/a/PHP/Using-XMLRPC-with-PHP/
42 * Note: All XMLRPC methods are automatically prefixed with "wiki."
43 * eg. "wiki.getAllPages"
48 Remove all warnings from xmlrpc.inc
49 Return list of external links in listLinks
50 Support RSS2 cloud subscription: wiki.rssPleaseNotify, pingback.ping
52 Test hwiki.jar xmlrpc interface (java visualization plugin)
53 Make use of the xmlrpc extension if found. http://xmlrpc-epi.sourceforge.net/
54 Resolved namespace conflicts
55 Added various phpwiki specific methods (mailPasswordToUser, getUploadedFileInfo,
56 putPage, titleSearch, listPlugins, getPluginSynopsis, listRelations)
57 Use client methods in inter-phpwiki calls: SyncWiki, tests/xmlrpc/
60 // Intercept GET requests from confused users. Only POST is allowed here!
61 if (empty($GLOBALS['HTTP_SERVER_VARS']))
62 $GLOBALS['HTTP_SERVER_VARS'] =& $_SERVER;
63 if ($GLOBALS['HTTP_SERVER_VARS']['REQUEST_METHOD'] != "POST")
65 die('This is the address of the XML-RPC interface.' .
66 ' You must use XML-RPC calls to access information here.');
69 require_once("lib/XmlRpcClient.php");
70 if (loadPhpExtension('xmlrpc')) { // fast c lib
71 require_once("lib/XMLRPC/xmlrpcs_emu.inc");
72 } else { // slow php lib
73 global $_xmlrpcs_dmap;
74 require_once("lib/XMLRPC/xmlrpcs.inc");
79 * Helper function: Looks up a page revision (most recent by default) in the wiki database
81 * @param xmlrpcmsg $params : string pagename [int version]
82 * @return WikiDB _PageRevision object, or false if no such page
85 function _getPageRevision ($params)
88 $ParamPageName = $params->getParam(0);
89 $ParamVersion = $params->getParam(1);
90 $pagename = short_string_decode($ParamPageName->scalarval());
91 $version = ($ParamVersion) ? ($ParamVersion->scalarval()):(0);
92 // FIXME: test for version <=0 ??
93 $dbh = $request->getDbh();
94 if ($dbh->isWikiPage($pagename)) {
95 $page = $dbh->getPage($pagename);
97 $revision = $page->getCurrentRevision();
99 $revision = $page->getRevision($version);
107 * Get an xmlrpc "No such page" error message
109 function NoSuchPage ($pagename='')
111 global $xmlrpcerruser;
112 return new xmlrpcresp(0, $xmlrpcerruser + 1, "No such page ".$pagename);
116 // ****************************************************************************
117 // Main API functions follow
118 // ****************************************************************************
122 * int getRPCVersionSupported(): Returns 1 for this version of the API
124 $wiki_dmap['getRPCVersionSupported']
125 = array('signature' => array(array($xmlrpcInt)),
126 'documentation' => 'Get the version of the wiki API',
127 'function' => 'getRPCVersionSupported');
129 // The function must be a function in the global scope which services the XML-RPC
131 function getRPCVersionSupported($params)
133 return new xmlrpcresp(new xmlrpcval((integer)WIKI_XMLRPC_VERSION, "int"));
137 * array getRecentChanges(Date timestamp) : Get list of changed pages since
138 * timestamp, which should be in UTC. The result is an array, where each element
140 * name (string) : Name of the page. The name is UTF-8 with URL encoding to make it ASCII.
141 * lastModified (date) : Date of last modification, in UTC.
142 * author (string) : Name of the author (if available). Again, name is UTF-8 with URL encoding.
143 * version (int) : Current version.
144 * A page MAY be specified multiple times. A page MAY NOT be specified multiple
145 * times with the same modification date.
147 $wiki_dmap['getRecentChanges']
148 = array('signature' => array(array($xmlrpcArray, $xmlrpcDateTime)),
149 'documentation' => 'Get a list of changed pages since [timestamp]',
150 'function' => 'getRecentChanges');
152 function getRecentChanges($params)
155 // Get the first parameter as an ISO 8601 date. Assume UTC
156 $encoded_date = $params->getParam(0);
157 $datetime = iso8601_decode($encoded_date->scalarval(), 1);
158 $dbh = $request->getDbh();
160 $iterator = $dbh->mostRecent(array('since' => $datetime));
161 while ($page = $iterator->next()) {
162 // $page contains a WikiDB_PageRevision object
163 // no need to url encode $name, because it is already stored in that format ???
164 $name = short_string($page->getPageName());
165 $lastmodified = new xmlrpcval(iso8601_encode($page->get('mtime')), "dateTime.iso8601");
166 $author = short_string($page->get('author'));
167 $version = new xmlrpcval($page->getVersion(), 'int');
169 // Build an array of xmlrpc structs
170 $pages[] = new xmlrpcval(array('name' => $name,
171 'lastModified' => $lastmodified,
173 'version' => $version),
176 return new xmlrpcresp(new xmlrpcval($pages, "array"));
181 * base64 getPage( String pagename ): Get the raw Wiki text of page, latest version.
182 * Page name must be UTF-8, with URL encoding. Returned value is a binary object,
183 * with UTF-8 encoded page data.
185 $wiki_dmap['getPage']
186 = array('signature' => array(array($xmlrpcBase64, $xmlrpcString)),
187 'documentation' => 'Get the raw Wiki text of the current version of a page',
188 'function' => 'getPage');
190 function getPage($params)
192 $revision = _getPageRevision($params);
195 $ParamPageName = $params->getParam(0);
196 $pagename = short_string_decode($ParamPageName->scalarval());
197 return NoSuchPage($pagename);
200 return new xmlrpcresp(long_string($revision->getPackedContent()));
205 * base64 getPageVersion( String pagename, int version ): Get the raw Wiki text of page.
206 * Returns UTF-8, expects UTF-8 with URL encoding.
208 $wiki_dmap['getPageVersion']
209 = array('signature' => array(array($xmlrpcBase64, $xmlrpcString, $xmlrpcInt)),
210 'documentation' => 'Get the raw Wiki text of a page version',
211 'function' => 'getPageVersion');
213 function getPageVersion($params)
215 // error checking is done in getPage
216 return getPage($params);
220 * base64 getPageHTML( String pagename ): Return page in rendered HTML.
221 * Returns UTF-8, expects UTF-8 with URL encoding.
224 $wiki_dmap['getPageHTML']
225 = array('signature' => array(array($xmlrpcBase64, $xmlrpcString)),
226 'documentation' => 'Get the current version of a page rendered in HTML',
227 'function' => 'getPageHTML');
229 function getPageHTML($params)
231 $revision = _getPageRevision($params);
235 $content = $revision->getTransformedContent();
236 $html = $content->asXML();
237 // HACK: Get rid of outer <div class="wikitext">
238 if (preg_match('/^\s*<div class="wikitext">/', $html, $m1)
239 && preg_match('@</div>\s*$@', $html, $m2)) {
240 $html = substr($html, strlen($m1[0]), -strlen($m2[0]));
243 return new xmlrpcresp(long_string($html));
247 * base64 getPageHTMLVersion( String pagename, int version ): Return page in rendered HTML, UTF-8.
249 $wiki_dmap['getPageHTMLVersion']
250 = array('signature' => array(array($xmlrpcBase64, $xmlrpcString, $xmlrpcInt)),
251 'documentation' => 'Get a version of a page rendered in HTML',
252 'function' => 'getPageHTMLVersion');
254 function getPageHTMLVersion($params)
256 return getPageHTML($params);
260 * getAllPages(): Returns a list of all pages. The result is an array of strings.
262 $wiki_dmap['getAllPages']
263 = array('signature' => array(array($xmlrpcArray)),
264 'documentation' => 'Returns a list of all pages as an array of strings',
265 'function' => 'getAllPages');
267 function getAllPages($params)
270 $dbh = $request->getDbh();
271 $iterator = $dbh->getAllPages();
273 while ($page = $iterator->next()) {
274 $pages[] = short_string($page->getName());
276 return new xmlrpcresp(new xmlrpcval($pages, "array"));
280 * struct getPageInfo( string pagename ) : returns a struct with elements:
281 * name (string): the canonical page name
282 * lastModified (date): Last modification date
283 * version (int): current version
284 * author (string): author name
286 $wiki_dmap['getPageInfo']
287 = array('signature' => array(array($xmlrpcStruct, $xmlrpcString)),
288 'documentation' => 'Gets info about the current version of a page',
289 'function' => 'getPageInfo');
291 function getPageInfo($params)
293 $revision = _getPageRevision($params);
297 $name = short_string($revision->getPageName());
298 $version = new xmlrpcval ($revision->getVersion(), "int");
299 $lastmodified = new xmlrpcval(iso8601_encode($revision->get('mtime'), 0),
301 $author = short_string($revision->get('author'));
303 return new xmlrpcresp(new xmlrpcval(array('name' => $name,
304 'lastModified' => $lastmodified,
305 'version' => $version,
306 'author' => $author),
311 * struct getPageInfoVersion( string pagename, int version ) : returns
312 * a struct just like plain getPageInfo(), but this time for a
315 $wiki_dmap['getPageInfoVersion']
316 = array('signature' => array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcInt)),
317 'documentation' => 'Gets info about a page version',
318 'function' => 'getPageInfoVersion');
320 function getPageInfoVersion($params)
322 return getPageInfo($params);
326 /* array listLinks( string pagename ): Lists all links for a given page. The
327 * returned array contains structs, with the following elements:
328 * name (string) : The page name or URL the link is to.
329 * type (int) : The link type. Zero (0) for internal Wiki link,
330 * one (1) for external link (URL - image link, whatever).
332 $wiki_dmap['listLinks']
333 = array('signature' => array(array($xmlrpcArray, $xmlrpcString)),
334 'documentation' => 'Lists all links for a given page',
335 'function' => 'listLinks');
337 function listLinks($params)
341 $ParamPageName = $params->getParam(0);
342 $pagename = short_string_decode($ParamPageName->scalarval());
343 $dbh = $request->getDbh();
344 if (! $dbh->isWikiPage($pagename))
345 return NoSuchPage($pagename);
347 $page = $dbh->getPage($pagename);
349 // The fast WikiDB method. below is the slow method which goes through the formatter
350 // NB no clean way to extract a list of external links yet, so
351 // only internal links returned. i.e. all type 'local'.
352 $linkiterator = $page->getPageLinks();
353 $linkstruct = array();
354 while ($currentpage = $linkiterator->next()) {
355 $currentname = $currentpage->getName();
356 // Compute URL to page
358 // How to check external links?
359 if (!$currentpage->exists()) $args['action'] = 'edit';
361 // FIXME: Autodetected value of VIRTUAL_PATH wrong,
362 // this make absolute URLs constructed by WikiURL wrong.
363 // Also, if USE_PATH_INFO is false, WikiURL is wrong
364 // due to its use of SCRIPT_NAME.
365 //$use_abspath = USE_PATH_INFO && ! preg_match('/RPC2.php$/', VIRTUAL_PATH);
367 // USE_PATH_INFO must be defined in index.php or config.ini but not before,
368 // otherwise it is ignored and xmlrpc urls are wrong.
369 // SCRIPT_NAME here is always .../RPC2.php
370 if (USE_PATH_INFO and !$args) {
371 $url = preg_replace('/%2f/i', '/', rawurlencode($currentname));
372 } elseif (!USE_PATH_INFO) {
373 $url = str_replace("/RPC2.php","/index.php", WikiURL($currentname, $args, true));
375 $url = WikiURL($currentname, $args);
377 $linkstruct[] = new xmlrpcval(array('page'=> short_string($currentname),
378 'type'=> new xmlrpcval('local', 'string'),
379 'href' => short_string($url)),
384 $current = $page->getCurrentRevision();
385 $content = $current->getTransformedContent();
386 $links = $content->getLinkInfo();
387 foreach ($links as $link) {
388 // We used to give an href for unknown pages that
389 // included action=edit. I think that's probably the
390 // wrong thing to do.
391 $linkstruct[] = new xmlrpcval(array('page'=> short_string($link->page),
392 'type'=> new xmlrpcval($link->type, 'string'),
393 'href' => short_string($link->href),
394 //'pageref' => short_string($link->pageref),
399 return new xmlrpcresp(new xmlrpcval ($linkstruct, "array"));
403 * struct putPage(String pagename, String content, [String author[, String password]})
404 * returns a struct with elements:
405 * code (int): 200 on success, 400 or 401 on failure
406 * message (string): success or failure message
407 * version (int): version of new page
409 * @author: Arnaud Fontaine, Reini Urban
411 $wiki_dmap['putPage']
412 = array('signature' => array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString)),
413 'documentation' => 'put the raw Wiki text into a page as new version',
414 'function' => 'putPage');
416 function _getUser($userid='') {
420 if (!isset($_SERVER))
421 $_SERVER =& $GLOBALS['HTTP_SERVER_VARS'];
423 $_ENV =& $GLOBALS['HTTP_ENV_VARS'];
424 if (isset($_SERVER['REMOTE_USER']))
425 $userid = $_SERVER['REMOTE_USER'];
426 elseif (isset($_ENV['REMOTE_USER']))
427 $userid = $_ENV['REMOTE_USER'];
428 elseif (isset($_SERVER['REMOTE_ADDR']))
429 $userid = $_SERVER['REMOTE_ADDR'];
430 elseif (isset($_ENV['REMOTE_ADDR']))
431 $userid = $_ENV['REMOTE_ADDR'];
432 elseif (isset($GLOBALS['REMOTE_ADDR']))
433 $userid = $GLOBALS['REMOTE_ADDR'];
436 if (ENABLE_USER_NEW) {
437 return WikiUser($userid);
439 return new WikiUser($request, $userid);
443 function putPage($params) {
446 $ParamPageName = $params->getParam(0);
447 $ParamContent = $params->getParam(1);
448 $pagename = short_string_decode($ParamPageName->scalarval());
449 $content = short_string_decode($ParamContent->scalarval());
451 if (count($params->params) > 2) {
452 $ParamAuthor = $params->getParam(2);
453 $userid = short_string_decode($ParamAuthor->scalarval());
454 if (count($params->params) > 3) {
455 $ParamPassword = $params->getParam(3);
456 $passwd = short_string_decode($ParamPassword->scalarval());
459 $userid = $request->_user->_userid;
461 $request->_user = _getUser($userid);
462 $request->_user->_group = $request->getGroup();
463 $request->_user->AuthCheck($userid, $passwd);
465 if (! mayAccessPage ('edit', $pagename)) {
466 return new xmlrpcresp(
468 array('code' => new xmlrpcval(401, "int"),
469 'version' => new xmlrpcval(0, "int"),
471 short_string("no permission for "
472 .$request->_user->UserName())),
477 $dbh = $request->getDbh();
478 $page = $dbh->getPage($pagename);
479 $current = $page->getCurrentRevision();
480 $content = trim($content);
481 $version = $current->getVersion();
482 // $version = -1 will force create a new version
483 if ($current->getPackedContent() != $content) {
484 $init_meta = array('ctime' => $now,
485 'creator' => $userid,
486 'creator_id' => $userid,
488 $version_meta = array('author' => $userid,
489 'author_id' => $userid,
491 'summary' => isset($summary) ? $summary : _("xml-rpc change"),
493 'pagetype' => 'wikitext',
494 'wikitext' => $init_meta,
497 $res = $page->save($content, $version, $version_meta);
499 $message = "Page $pagename version $version created";
501 $message = "Problem creating version $version of page $pagename";
504 $message = $message = "Page $pagename unchanged";
506 return new xmlrpcresp(new xmlrpcval(array('code' => new xmlrpcval($res ? 200 : 400, "int"),
507 'version' => new xmlrpcval($version, "int"),
508 'message' => short_string($message)),
513 * struct getUploadedFileInfo( string localpath ) : returns a struct with elements:
514 * lastModified (date): Last modification date
515 * size (int): current version
516 * This is to sync uploaded files up to a remote master wiki. (SyncWiki)
517 * Not existing files return both 0.
519 $wiki_dmap['getUploadedFileInfo']
520 = array('signature' => array(array($xmlrpcStruct, $xmlrpcString)),
521 'documentation' => 'Gets date and size about an uploaded local file',
522 'function' => 'getUploadedFileInfo');
524 function getUploadedFileInfo($params)
526 // localpath is the relative part after "Upload:"
527 $ParamPath = $params->getParam(0);
528 $localpath = short_string_decode($ParamPath->scalarval());
529 preg_replace("/^[\\ \/ \.]/", "", $localpath); // strip hacks
530 $file = getUploadFilePath() . $localpath;
531 if (file_exists($file)) {
532 $size = filesize($file);
533 $lastmodified = filemtime($file);
538 return new xmlrpcresp(new xmlrpcval
539 (array('lastModified' => new xmlrpcval(iso8601_encode($lastmodified, 1),
541 'size' => new xmlrpcval($size, "int")),
547 * Client subscribes to a RecentChanges-like channel, getting a short
548 * callback notification on every change. Like PageChangeNotification, just shorter
549 * and more complicated
550 * RSS2 support (not yet), since radio userland's rss-0.92. now called RSS2.
551 * BTW: Radio Userland deprecated this interface.
553 * boolean wiki.rssPleaseNotify ( notifyProcedure, port, path, protocol, urlList )
554 * returns: true or false
556 * Check of the channel behind the rssurl has a cloud element,
557 * if the client has a direct IP connection (no NAT),
558 * register the client on the WikiDB notification handler
560 * http://backend.userland.com/publishSubscribeWalkthrough
561 * http://www.soapware.org/xmlStorageSystem#rssPleaseNotify
562 * http://www.thetwowayweb.com/soapmeetsrss#rsscloudInterface
564 $wiki_dmap['rssPleaseNotify']
565 = array('signature' => array(array($xmlrpcBoolean, $xmlrpcStruct)),
566 'documentation' => 'RSS2 change notification subscriber channel',
567 'function' => 'rssPleaseNotify');
569 function rssPleaseNotify($params)
571 // register the clients IP
572 return new xmlrpcresp(new xmlrpcval (0, "boolean"));
576 * boolean wiki.mailPasswordToUser ( username )
577 * returns: true or false
580 $wiki_dmap['mailPasswordToUser']
581 = array('signature' => array(array($xmlrpcBoolean, $xmlrpcString)),
582 'documentation' => 'RSS2 user management helper',
583 'function' => 'mailPasswordToUser');
585 function mailPasswordToUser($params)
588 $ParamUserid = $params->getParam(0);
589 $userid = short_string_decode($ParamUserid->scalarval());
590 $request->_user = _getUser($userid);
591 //$request->_prefs =& $request->_user->_prefs;
592 $email = $request->getPref('email');
595 $body = WikiURL('') . "\nPassword: " . $request->getPref('passwd');
596 $success = mail($email, "[".WIKI_NAME."} Password Request",
599 return new xmlrpcresp(new xmlrpcval ($success, "boolean"));
603 * array wiki.titleSearch(String substring [, Integer option = 0])
604 * returns an array of matching pagenames.
605 * TODO: standardize options
607 * @author: Reini Urban
609 $wiki_dmap['titleSearch']
610 = array('signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcInt)),
611 'documentation' => "Return matching pagenames.
612 Option 1: caseexact, 2: regex, 4: starts_with, 8: exact",
613 'function' => 'titleSearch');
615 function titleSearch($params)
618 $ParamPageName = $params->getParam(0);
619 $searchstring = short_string_decode($ParamPageName->scalarval());
620 if (count($params->params) > 1) {
621 $ParamOption = $params->getParam(1);
622 $option = (int) $ParamOption->scalarval();
624 // default option: substring, case-inexact
626 $case_exact = $option & 1;
627 $regex = $option & 2;
629 if ($option & 4) { // STARTS_WITH
631 $searchstring = "^".$searchstring;
633 if ($option & 8) { // EXACT
635 $searchstring = "^".$searchstring."$";
638 if ($option & 4 or $option & 8) {
639 global $xmlrpcerruser;
640 return new xmlrpcresp(0, $xmlrpcerruser + 1, "Invalid option");
643 include_once("lib/TextSearchQuery.php");
644 $query = new TextSearchQuery($searchstring, $case_exact, $regex ? 'auto' : 'none');
645 $dbh = $request->getDbh();
646 $iterator = $dbh->titleSearch($query);
648 while ($page = $iterator->next()) {
649 $pages[] = short_string($page->getName());
651 return new xmlrpcresp(new xmlrpcval($pages, "array"));
655 * array wiki.listPlugins()
657 * Returns an array of all available plugins.
658 * For EditToolbar pluginPulldown via AJAX
660 * @author: Reini Urban
662 $wiki_dmap['listPlugins']
663 = array('signature' => array(array($xmlrpcArray)),
664 'documentation' => "Return names of all plugins",
665 'function' => 'listPlugins');
667 function listPlugins($params)
669 $plugin_dir = 'lib/plugin';
670 if (defined('PHPWIKI_DIR'))
671 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
672 $pd = new fileSet($plugin_dir, '*.php');
673 $plugins = $pd->getFiles();
677 if (!empty($plugins)) {
678 require_once("lib/WikiPlugin.php");
679 $w = new WikiPluginLoader;
680 foreach ($plugins as $plugin) {
681 $pluginName = str_replace(".php", "", $plugin);
682 $p = $w->getPlugin($pluginName, false); // second arg?
683 // trap php files which aren't WikiPlugin~s: wikiplugin + wikiplugin_cached only
684 if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
685 $RetArray[] = short_string($pluginName);
690 return new xmlrpcresp(new xmlrpcval($RetArray, "array"));
694 * String wiki.getPluginSynopsis(String plugin)
696 * For EditToolbar pluginPulldown via AJAX
698 * @author: Reini Urban
700 $wiki_dmap['getPluginSynopsis']
701 = array('signature' => array(array($xmlrpcArray, $xmlrpcString)),
702 'documentation' => "Return plugin synopsis",
703 'function' => 'getPluginSynopsis');
705 function getPluginSynopsis($params)
707 $ParamPlugin = $params->getParam(0);
708 $pluginName = short_string_decode($ParamPlugin->scalarval());
710 require_once("lib/WikiPlugin.php");
711 $w = new WikiPluginLoader;
713 $p = $w->getPlugin($pluginName, false); // second arg?
714 // trap php files which aren't WikiPlugin~s: wikiplugin + wikiplugin_cached only
715 if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
717 $desc = $p->getArgumentsDescription();
718 $src = array("\n",'"',"'",'|','[',']','\\');
719 $replace = array('%0A','%22','%27','%7C','%5B','%5D','%5C');
720 $desc = str_replace("<br />",' ',$desc->asXML());
722 $plugin_args = '\n'.str_replace($src, $replace, $desc);
723 $synopsis = "<?plugin ".$pluginName.$plugin_args."?>"; // args?
726 return new xmlrpcresp(short_string($synopsis));
730 * array wiki.callPlugin(String name, String args)
732 * Returns an array of pages as returned by the plugins PageList call.
733 * Only valid for plugins returning pagelists, e.g. BackLinks, AllPages, ...
734 * For various AJAX or WikiFormRich calls.
736 * @author: Reini Urban
738 $wiki_dmap['callPlugin']
739 = array('signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString)),
740 'documentation' => "Returns an array of pages as returned by the plugins PageList call",
741 'function' => 'callPlugin');
743 function callPlugin($params)
746 $dbi = $request->getDbh();
747 $ParamPlugin = $params->getParam(0);
748 $pluginName = short_string_decode($ParamPlugin->scalarval());
749 $ParamArgs = $params->getParam(1);
750 $plugin_args = short_string_decode($ParamArgs->scalarval());
751 $basepage = ''; //$pluginName;
753 require_once("lib/WikiPlugin.php");
754 $w = new WikiPluginLoader;
755 $p = $w->getPlugin($pluginName, false); // second arg?
756 $pagelist = $p->run($dbi, $plugin_args, $request, $basepage);
758 if (is_object($pagelist) and isa($pagelist, 'PageList')) {
759 foreach ($pagelist->_pages as $page) {
760 $list[] = $page->getName();
763 return new xmlrpcresp(new xmlrpcval($list, "array"));
768 * array wiki.listRelations([ Integer option = 1 ])
770 * Returns an array of all available relation names.
771 * option: 1 relations only ( with 0 also )
772 * option: 2 attributes only
773 * option: 3 both, all names of relations and attributes
774 * option: 4 unsorted, this might be added as bitvalue: 7 = 4+3. default: sorted
775 * For some semanticweb autofill methods.
777 * @author: Reini Urban
779 $wiki_dmap['listRelations']
780 = array('signature' => array(array($xmlrpcArray, $xmlrpcInt)),
781 'documentation' => "Return names of all relations",
782 'function' => 'listRelations');
784 function listRelations($params)
787 $dbh = $request->getDbh();
788 if (count($params->params) > 0) {
789 $ParamOption = $params->getParam(0);
790 $option = (int) $ParamOption->scalarval();
793 $also_attributes = $option & 2;
794 $only_attributes = $option & 2 and !($option & 1);
795 $sorted = !($option & 4);
796 return new xmlrpcresp(new xmlrpcval($dbh->listRelations($also_attributes,
803 * String pingback.ping(String sourceURI, String targetURI)
805 Spec: http://www.hixie.ch/specs/pingback/pingback
808 sourceURI of type string
809 The absolute URI of the post on the source page containing the
810 link to the target site.
811 targetURI of type string
812 The absolute URI of the target of the link, as given on the source page.
814 A string, as described below.
816 If an error condition occurs, then the appropriate fault code from
817 the following list should be used. Clients can quickly determine
818 the kind of error from bits 5-8. 0×001x fault codes are used for
819 problems with the source URI, 0×002x codes are for problems with
820 the target URI, and 0×003x codes are used when the URIs are fine
821 but the pingback cannot be acknowledged for some other reaon.
824 A generic fault code. Servers MAY use this error code instead
825 of any of the others if they do not have a way of determining
826 the correct fault code.
828 The source URI does not exist.
830 The source URI does not contain a link to the target URI, and
831 so cannot be used as a source.
833 The specified target URI does not exist. This MUST only be
834 used when the target definitely does not exist, rather than
835 when the target may exist but is not recognised. See the next
838 The specified target URI cannot be used as a target. It either
839 doesn't exist, or it is not a pingback-enabled resource. For
840 example, on a blog, typically only permalinks are
841 pingback-enabled, and trying to pingback the home page, or a
842 set of posts, will fail with this error.
844 The pingback has already been registered.
848 The server could not communicate with an upstream server, or
849 received an error from an upstream server, and therefore could
850 not complete the request. This is similar to HTTP's 402 Bad
851 Gateway error. This error SHOULD be used by pingback proxies
852 when propagating errors.
854 In addition, [FaultCodes] defines some standard fault codes that
855 servers MAY use to report higher level errors.
857 Servers MUST respond to this function call either with a single string
858 or with a fault code.
860 If the pingback request is successful, then the return value MUST be a
861 single string, containing as much information as the server deems
862 useful. This string is only expected to be used for debugging
865 If the result is unsuccessful, then the server MUST respond with an
866 RPC fault value. The fault code should be either one of the codes
867 listed above, or the generic fault code zero if the server cannot
868 determine the correct fault code.
870 Clients MAY ignore the return value, whether the request was
871 successful or not. It is RECOMMENDED that clients do not show the
872 result of successful requests to the user.
874 Upon receiving a request, servers MAY do what they like. However, the
875 following steps are RECOMMENDED:
877 1. The server MAY attempt to fetch the source URI to verify that
878 the source does indeed link to the target.
879 2. The server MAY check its own data to ensure that the target
880 exists and is a valid entry.
881 3. The server MAY check that the pingback has not already been registered.
882 4. The server MAY record the pingback.
883 5. The server MAY regenerate the site's pages (if the pages are static).
885 * @author: Reini Urban
887 $wiki_dmap['pingback.ping']
888 = array('signature' => array(array($xmlrpcString, $xmlrpcString, $xmlrpcString)),
889 'documentation' => "",
890 'function' => 'pingBack');
891 function pingBack($params)
894 $Param0 = $params->getParam(0);
895 $sourceURI = short_string_decode($Param0->scalarval());
896 $Param1 = $params->getParam(1);
897 $targetURI = short_string_decode($Param1->scalarval());
902 * Construct the server instance, and set up the dispatch map,
903 * which maps the XML-RPC methods on to the wiki functions.
904 * Provide the "wiki." prefix to each function. Besides
905 * the blog - pingback, ... - functions with a seperate namespace.
907 class XmlRpcServer extends xmlrpc_server
909 function XmlRpcServer ($request = false) {
911 foreach ($wiki_dmap as $name => $val) {
912 if ($name == 'pingback.ping') // non-wiki methods
915 $dmap['wiki.' . $name] = $val;
918 $this->xmlrpc_server($dmap, 0 /* delay service*/);
921 function service () {
922 global $ErrorManager;
924 $ErrorManager->pushErrorHandler(new WikiMethodCb($this, '_errorHandler'));
925 xmlrpc_server::service();
926 $ErrorManager->popErrorHandler();
929 function _errorHandler ($e) {
930 $msg = htmlspecialchars($e->asString());
931 // '--' not allowed within xml comment
932 $msg = str_replace('--', '--', $msg);
933 if (function_exists('xmlrpc_debugmsg'))
934 xmlrpc_debugmsg($msg);
940 $Log: not supported by cvs2svn $
941 Revision 1.20 2007/01/03 21:25:52 rurban
942 add option argument to listRelations.
944 Revision 1.19 2007/01/02 13:21:21 rurban
945 split client from server. added getUploadedFileInfo (for SyncWiki), callPlugin (for WikiFormRich)
947 Revision 1.18 2006/05/18 06:10:45 rurban
948 add xmlrpc listRelations signature
950 Revision 1.17 2005/10/31 16:49:31 rurban
953 Revision 1.16 2005/10/29 14:17:51 rurban
956 Revision 1.15 2005/10/29 08:57:12 rurban
957 fix for !register_long_arrays
958 new: array wiki.listPlugins()
959 String wiki.getPluginSynopsis(String plugin)
960 String pingback.ping(String sourceURI, String targetURI) (preliminary)
965 // (c-file-style: "gnu")
970 // c-hanging-comment-ender-p: nil
971 // indent-tabs-mode: nil