2 // $Id: XmlRpcServer.php,v 1.24 2007-01-22 23:42:13 rurban Exp $
3 /* Copyright (C) 2002, Lawrence Akka <lakka@users.sourceforge.net>
4 * Copyright (C) 2004,2005,2006,2007 $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 * Change to unit tests: XmlRpcTest v1, v2 and private
49 * Return list of external links in listLinks
50 * Support RSS2 cloud subscription: wiki.rssPleaseNotify, pingback.ping
52 * API v2 http://www.jspwiki.org/wiki/WikiRPCInterface2 :
54 * array listAttachments( utf8 page ) - Lists attachments on a given page.
55 The array consists of utf8 attachment names that can be fed to getAttachment (or putAttachment).
56 * base64 getAttachment( utf8 attachmentName ) - returns the content of an attachment.
57 * putAttachment( utf8 attachmentName, base64 content ) - (over)writes an attachment.
58 * array system.listMethods()
59 * string system.methodHelp (string methodName)
60 * array system.methodSignature (string methodName)
63 Test hwiki.jar xmlrpc interface (java visualization plugin)
64 Make use of the xmlrpc extension if found. http://xmlrpc-epi.sourceforge.net/
65 Resolved namespace conflicts
66 Added various phpwiki specific methods (mailPasswordToUser, getUploadedFileInfo,
67 putPage, titleSearch, listPlugins, getPluginSynopsis, listRelations)
68 Use client methods in inter-phpwiki calls: SyncWiki, tests/xmlrpc/
71 // Intercept GET requests from confused users. Only POST is allowed here!
72 if (empty($GLOBALS['HTTP_SERVER_VARS']))
73 $GLOBALS['HTTP_SERVER_VARS'] =& $_SERVER;
74 if ($GLOBALS['HTTP_SERVER_VARS']['REQUEST_METHOD'] != "POST")
76 die('This is the address of the XML-RPC interface.' .
77 ' You must use XML-RPC calls to access information here.');
80 require_once("lib/XmlRpcClient.php");
81 if (loadPhpExtension('xmlrpc')) { // fast c lib
82 require_once("lib/XMLRPC/xmlrpcs_emu.inc");
83 } else { // slow php lib
84 global $_xmlrpcs_dmap;
85 require_once("lib/XMLRPC/xmlrpcs.inc");
90 * Helper function: Looks up a page revision (most recent by default) in the wiki database
92 * @param xmlrpcmsg $params : string pagename [int version]
93 * @return WikiDB _PageRevision object, or false if no such page
96 function _getPageRevision ($params)
99 $ParamPageName = $params->getParam(0);
100 $ParamVersion = $params->getParam(1);
101 $pagename = short_string_decode($ParamPageName->scalarval());
102 $version = ($ParamVersion) ? ($ParamVersion->scalarval()):(0);
103 // FIXME: test for version <=0 ??
104 $dbh = $request->getDbh();
105 if ($dbh->isWikiPage($pagename)) {
106 $page = $dbh->getPage($pagename);
108 $revision = $page->getCurrentRevision();
110 $revision = $page->getRevision($version);
118 * Get an xmlrpc "No such page" error message
120 function NoSuchPage ($pagename='')
122 global $xmlrpcerruser;
123 return new xmlrpcresp(0, $xmlrpcerruser + 1, "No such page ".$pagename);
127 // ****************************************************************************
128 // Main API functions follow
129 // ****************************************************************************
133 * int getRPCVersionSupported(): Returns 1 for this version of the API
135 $wiki_dmap['getRPCVersionSupported']
136 = array('signature' => array(array($xmlrpcInt)),
137 'documentation' => 'Get the version of the wiki API',
138 'function' => 'getRPCVersionSupported');
140 // The function must be a function in the global scope which services the XML-RPC
142 function getRPCVersionSupported($params)
144 return new xmlrpcresp(new xmlrpcval((integer)WIKI_XMLRPC_VERSION, "int"));
148 * array getRecentChanges(Date timestamp) : Get list of changed pages since
149 * timestamp, which should be in UTC. The result is an array, where each element
151 * name (string) : Name of the page. The name is UTF-8 with URL encoding to make it ASCII.
152 * lastModified (date) : Date of last modification, in UTC.
153 * author (string) : Name of the author (if available). Again, name is UTF-8 with URL encoding.
154 * version (int) : Current version.
155 * summary (string) : UTF-8 with URL encoding.
156 * A page MAY be specified multiple times. A page MAY NOT be specified multiple
157 * times with the same modification date.
158 * Additionally to API version 1 and 2 we added the summary field.
160 $wiki_dmap['getRecentChanges']
161 = array('signature' => array(array($xmlrpcArray, $xmlrpcDateTime)),
162 'documentation' => 'Get a list of changed pages since [timestamp]',
163 'function' => 'getRecentChanges');
165 function getRecentChanges($params)
168 // Get the first parameter as an ISO 8601 date. Assume UTC
169 $encoded_date = $params->getParam(0);
170 $datetime = iso8601_decode($encoded_date->scalarval(), 1);
171 $dbh = $request->getDbh();
173 $iterator = $dbh->mostRecent(array('since' => $datetime));
174 while ($page = $iterator->next()) {
175 // $page contains a WikiDB_PageRevision object
176 // no need to url encode $name, because it is already stored in that format ???
177 $name = short_string($page->getPageName());
178 $lastmodified = new xmlrpcval(iso8601_encode($page->get('mtime')), "dateTime.iso8601");
179 $author = short_string($page->get('author'));
180 $version = new xmlrpcval($page->getVersion(), 'int');
182 // Build an array of xmlrpc structs
183 $pages[] = new xmlrpcval(array('name' => $name,
184 'lastModified' => $lastmodified,
186 'summary' => short_string($page->get('summary')),
187 'version' => $version),
190 return new xmlrpcresp(new xmlrpcval($pages, "array"));
195 * base64 getPage( String pagename ): Get the raw Wiki text of page, latest version.
196 * Page name must be UTF-8, with URL encoding. Returned value is a binary object,
197 * with UTF-8 encoded page data.
199 $wiki_dmap['getPage']
200 = array('signature' => array(array($xmlrpcBase64, $xmlrpcString)),
201 'documentation' => 'Get the raw Wiki text of the current version of a page',
202 'function' => 'getPage');
204 function getPage($params)
206 $revision = _getPageRevision($params);
209 $ParamPageName = $params->getParam(0);
210 $pagename = short_string_decode($ParamPageName->scalarval());
211 return NoSuchPage($pagename);
214 return new xmlrpcresp(long_string($revision->getPackedContent()));
219 * base64 getPageVersion( String pagename, int version ): Get the raw Wiki text of page.
220 * Returns UTF-8, expects UTF-8 with URL encoding.
222 $wiki_dmap['getPageVersion']
223 = array('signature' => array(array($xmlrpcBase64, $xmlrpcString, $xmlrpcInt)),
224 'documentation' => 'Get the raw Wiki text of a page version',
225 'function' => 'getPageVersion');
227 function getPageVersion($params)
229 // error checking is done in getPage
230 return getPage($params);
234 * base64 getPageHTML( String pagename ): Return page in rendered HTML.
235 * Returns UTF-8, expects UTF-8 with URL encoding.
238 $wiki_dmap['getPageHTML']
239 = array('signature' => array(array($xmlrpcBase64, $xmlrpcString)),
240 'documentation' => 'Get the current version of a page rendered in HTML',
241 'function' => 'getPageHTML');
243 function getPageHTML($params)
245 $revision = _getPageRevision($params);
249 $content = $revision->getTransformedContent();
250 $html = $content->asXML();
251 // HACK: Get rid of outer <div class="wikitext">
252 if (preg_match('/^\s*<div class="wikitext">/', $html, $m1)
253 && preg_match('@</div>\s*$@', $html, $m2)) {
254 $html = substr($html, strlen($m1[0]), -strlen($m2[0]));
257 return new xmlrpcresp(long_string($html));
261 * base64 getPageHTMLVersion( String pagename, int version ): Return page in rendered HTML, UTF-8.
263 $wiki_dmap['getPageHTMLVersion']
264 = array('signature' => array(array($xmlrpcBase64, $xmlrpcString, $xmlrpcInt)),
265 'documentation' => 'Get a version of a page rendered in HTML',
266 'function' => 'getPageHTMLVersion');
268 function getPageHTMLVersion($params)
270 return getPageHTML($params);
274 * getAllPages(): Returns a list of all pages. The result is an array of strings.
276 $wiki_dmap['getAllPages']
277 = array('signature' => array(array($xmlrpcArray)),
278 'documentation' => 'Returns a list of all pages as an array of strings',
279 'function' => 'getAllPages');
281 function getAllPages($params)
284 $dbh = $request->getDbh();
285 $iterator = $dbh->getAllPages();
287 while ($page = $iterator->next()) {
288 $pages[] = short_string($page->getName());
290 return new xmlrpcresp(new xmlrpcval($pages, "array"));
294 * struct getPageInfo( string pagename ) : returns a struct with elements:
295 * name (string): the canonical page name
296 * lastModified (date): Last modification date
297 * version (int): current version
298 * author (string): author name
300 $wiki_dmap['getPageInfo']
301 = array('signature' => array(array($xmlrpcStruct, $xmlrpcString)),
302 'documentation' => 'Gets info about the current version of a page',
303 'function' => 'getPageInfo');
305 function getPageInfo($params)
307 $revision = _getPageRevision($params);
311 $name = short_string($revision->getPageName());
312 $version = new xmlrpcval ($revision->getVersion(), "int");
313 $lastmodified = new xmlrpcval(iso8601_encode($revision->get('mtime'), 0),
315 $author = short_string($revision->get('author'));
317 return new xmlrpcresp(new xmlrpcval(array('name' => $name,
318 'lastModified' => $lastmodified,
319 'version' => $version,
320 'author' => $author),
325 * struct getPageInfoVersion( string pagename, int version ) : returns
326 * a struct just like plain getPageInfo(), but this time for a
329 $wiki_dmap['getPageInfoVersion']
330 = array('signature' => array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcInt)),
331 'documentation' => 'Gets info about a page version',
332 'function' => 'getPageInfoVersion');
334 function getPageInfoVersion($params)
336 return getPageInfo($params);
340 /* array listLinks( string pagename ): Lists all links for a given page. The
341 * returned array contains structs, with the following elements:
342 * name (string) : The page name or URL the link is to.
343 * type (int) : The link type. Zero (0) for internal Wiki link,
344 * one (1) for external link (URL - image link, whatever).
346 $wiki_dmap['listLinks']
347 = array('signature' => array(array($xmlrpcArray, $xmlrpcString)),
348 'documentation' => 'Lists all links for a given page',
349 'function' => 'listLinks');
351 function listLinks($params)
355 $ParamPageName = $params->getParam(0);
356 $pagename = short_string_decode($ParamPageName->scalarval());
357 $dbh = $request->getDbh();
358 if (! $dbh->isWikiPage($pagename))
359 return NoSuchPage($pagename);
361 $page = $dbh->getPage($pagename);
363 // The fast WikiDB method. below is the slow method which goes through the formatter
364 // NB no clean way to extract a list of external links yet, so
365 // only internal links returned. i.e. all type 'local'.
366 $linkiterator = $page->getPageLinks();
367 $linkstruct = array();
368 while ($currentpage = $linkiterator->next()) {
369 $currentname = $currentpage->getName();
370 // Compute URL to page
372 // How to check external links?
373 if (!$currentpage->exists()) $args['action'] = 'edit';
375 // FIXME: Autodetected value of VIRTUAL_PATH wrong,
376 // this make absolute URLs constructed by WikiURL wrong.
377 // Also, if USE_PATH_INFO is false, WikiURL is wrong
378 // due to its use of SCRIPT_NAME.
379 //$use_abspath = USE_PATH_INFO && ! preg_match('/RPC2.php$/', VIRTUAL_PATH);
381 // USE_PATH_INFO must be defined in index.php or config.ini but not before,
382 // otherwise it is ignored and xmlrpc urls are wrong.
383 // SCRIPT_NAME here is always .../RPC2.php
384 if (USE_PATH_INFO and !$args) {
385 $url = preg_replace('/%2f/i', '/', rawurlencode($currentname));
386 } elseif (!USE_PATH_INFO) {
387 $url = str_replace("/RPC2.php","/index.php", WikiURL($currentname, $args, true));
389 $url = WikiURL($currentname, $args);
391 $linkstruct[] = new xmlrpcval(array('page'=> short_string($currentname),
392 'type'=> new xmlrpcval('local', 'string'),
393 'href' => short_string($url)),
398 $current = $page->getCurrentRevision();
399 $content = $current->getTransformedContent();
400 $links = $content->getLinkInfo();
401 foreach ($links as $link) {
402 // We used to give an href for unknown pages that
403 // included action=edit. I think that's probably the
404 // wrong thing to do.
405 $linkstruct[] = new xmlrpcval(array('page'=> short_string($link->page),
406 'type'=> new xmlrpcval($link->type, 'string'),
407 'href' => short_string($link->href),
408 //'pageref' => short_string($link->pageref),
413 return new xmlrpcresp(new xmlrpcval ($linkstruct, "array"));
416 /* End of WikiXMLRpc API v1 */
417 /* ======================================================================== */
418 /* Start of partial WikiXMLRpc API v2 support */
421 * struct putPage(String pagename, String content, [String author[, String password]})
422 * returns a struct with elements:
423 * code (int): 200 on success, 400 or 401 on failure
424 * message (string): success or failure message
425 * version (int): version of new page
427 * @author: Arnaud Fontaine, Reini Urban
429 * API notes: Contrary to the API v2 specs we dropped attributes and added author + password
431 $wiki_dmap['putPage']
432 = array('signature' => array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString)),
433 'documentation' => 'put the raw Wiki text into a page as new version',
434 'function' => 'putPage');
436 function _getUser($userid='') {
440 if (!isset($_SERVER))
441 $_SERVER =& $GLOBALS['HTTP_SERVER_VARS'];
443 $_ENV =& $GLOBALS['HTTP_ENV_VARS'];
444 if (isset($_SERVER['REMOTE_USER']))
445 $userid = $_SERVER['REMOTE_USER'];
446 elseif (isset($_ENV['REMOTE_USER']))
447 $userid = $_ENV['REMOTE_USER'];
448 elseif (isset($_SERVER['REMOTE_ADDR']))
449 $userid = $_SERVER['REMOTE_ADDR'];
450 elseif (isset($_ENV['REMOTE_ADDR']))
451 $userid = $_ENV['REMOTE_ADDR'];
452 elseif (isset($GLOBALS['REMOTE_ADDR']))
453 $userid = $GLOBALS['REMOTE_ADDR'];
456 if (ENABLE_USER_NEW) {
457 return WikiUser($userid);
459 return new WikiUser($request, $userid);
463 function putPage($params) {
466 $ParamPageName = $params->getParam(0);
467 $ParamContent = $params->getParam(1);
468 $pagename = short_string_decode($ParamPageName->scalarval());
469 $content = short_string_decode($ParamContent->scalarval());
471 if (count($params->params) > 2) {
472 $ParamAuthor = $params->getParam(2);
473 $userid = short_string_decode($ParamAuthor->scalarval());
474 if (count($params->params) > 3) {
475 $ParamPassword = $params->getParam(3);
476 $passwd = short_string_decode($ParamPassword->scalarval());
479 $userid = $request->_user->_userid;
481 $request->_user = _getUser($userid);
482 $request->_user->_group = $request->getGroup();
483 $request->_user->AuthCheck($userid, $passwd);
485 if (! mayAccessPage ('edit', $pagename)) {
486 return new xmlrpcresp(
488 array('code' => new xmlrpcval(401, "int"),
489 'version' => new xmlrpcval(0, "int"),
491 short_string("no permission for "
492 .$request->_user->UserName())),
497 $dbh = $request->getDbh();
498 $page = $dbh->getPage($pagename);
499 $current = $page->getCurrentRevision();
500 $content = trim($content);
501 $version = $current->getVersion();
502 // $version = -1 will force create a new version
503 if ($current->getPackedContent() != $content) {
504 $init_meta = array('ctime' => $now,
505 'creator' => $userid,
506 'creator_id' => $userid,
508 $version_meta = array('author' => $userid,
509 'author_id' => $userid,
511 'summary' => isset($summary) ? $summary : _("xml-rpc change"),
513 'pagetype' => 'wikitext',
514 'wikitext' => $init_meta,
517 $res = $page->save($content, $version, $version_meta);
519 $message = "Page $pagename version $version created";
521 $message = "Problem creating version $version of page $pagename";
524 $message = $message = "Page $pagename unchanged";
526 return new xmlrpcresp(new xmlrpcval(array('code' => new xmlrpcval($res ? 200 : 400, "int"),
527 'version' => new xmlrpcval($version, "int"),
528 'message' => short_string($message)),
532 /* End of WikiXMLRpc API v2 */
533 /* ======================================================================== */
534 /* Start of private extensions */
537 * struct getUploadedFileInfo( string localpath ) : returns a struct with elements:
538 * lastModified (date): Last modification date
539 * size (int): current version
540 * This is to sync uploaded files up to a remote master wiki. (SyncWiki)
541 * Not existing files return both 0.
543 * API notes: API v2 specs have array listAttachments( utf8 page ),
544 * base64 getAttachment( utf8 attachmentName ), putAttachment( utf8 attachmentName, base64 content )
546 $wiki_dmap['getUploadedFileInfo']
547 = array('signature' => array(array($xmlrpcStruct, $xmlrpcString)),
548 'documentation' => 'Gets date and size about an uploaded local file',
549 'function' => 'getUploadedFileInfo');
551 function getUploadedFileInfo($params)
553 // localpath is the relative part after "Upload:"
554 $ParamPath = $params->getParam(0);
555 $localpath = short_string_decode($ParamPath->scalarval());
556 preg_replace("/^[\\ \/ \.]/", "", $localpath); // strip hacks
557 $file = getUploadFilePath() . $localpath;
558 if (file_exists($file)) {
559 $size = filesize($file);
560 $lastmodified = filemtime($file);
565 return new xmlrpcresp(new xmlrpcval
566 (array('lastModified' => new xmlrpcval(iso8601_encode($lastmodified, 1),
568 'size' => new xmlrpcval($size, "int")),
573 * Publish-Subscribe (not yet implemented)
574 * Client subscribes to a RecentChanges-like channel, getting a short
575 * callback notification on every change. Like PageChangeNotification, just shorter
576 * and more complicated
577 * RSS2 support (not yet), since radio userland's rss-0.92. now called RSS2.
578 * BTW: Radio Userland deprecated this interface.
580 * boolean wiki.rssPleaseNotify ( notifyProcedure, port, path, protocol, urlList )
581 * returns: true or false
583 * Check of the channel behind the rssurl has a cloud element,
584 * if the client has a direct IP connection (no NAT),
585 * register the client on the WikiDB notification handler
587 * http://backend.userland.com/publishSubscribeWalkthrough
588 * http://www.soapware.org/xmlStorageSystem#rssPleaseNotify
589 * http://www.thetwowayweb.com/soapmeetsrss#rsscloudInterface
591 $wiki_dmap['rssPleaseNotify']
592 = array('signature' => array(array($xmlrpcBoolean, $xmlrpcStruct)),
593 'documentation' => 'RSS2 change notification subscriber channel',
594 'function' => 'rssPleaseNotify');
596 function rssPleaseNotify($params)
598 // register the clients IP
599 return new xmlrpcresp(new xmlrpcval (0, "boolean"));
603 * boolean wiki.mailPasswordToUser ( username )
604 * returns: true or false
607 $wiki_dmap['mailPasswordToUser']
608 = array('signature' => array(array($xmlrpcBoolean, $xmlrpcString)),
609 'documentation' => 'RSS2 user management helper',
610 'function' => 'mailPasswordToUser');
612 function mailPasswordToUser($params)
615 $ParamUserid = $params->getParam(0);
616 $userid = short_string_decode($ParamUserid->scalarval());
617 $request->_user = _getUser($userid);
618 //$request->_prefs =& $request->_user->_prefs;
619 $email = $request->getPref('email');
622 $body = WikiURL('') . "\nPassword: " . $request->getPref('passwd');
623 $success = mail($email, "[".WIKI_NAME."} Password Request",
626 return new xmlrpcresp(new xmlrpcval ($success, "boolean"));
630 * array wiki.titleSearch(String substring [, String option = "0"])
631 * returns an array of matching pagenames.
632 * TODO: standardize options
634 * @author: Reini Urban
636 $wiki_dmap['titleSearch']
637 = array('signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString)),
638 'documentation' => "Return matching pagenames.
639 Option 1: caseexact, 2: regex, 4: starts_with, 8: exact",
640 'function' => 'titleSearch');
642 function titleSearch($params)
645 $ParamPageName = $params->getParam(0);
646 $searchstring = short_string_decode($ParamPageName->scalarval());
647 if (count($params->params) > 1) {
648 $ParamOption = $params->getParam(1);
649 $option = (int) $ParamOption->scalarval();
652 // default option: substring, case-inexact
654 $case_exact = $option & 1;
655 $regex = $option & 2;
657 if ($option & 4) { // STARTS_WITH
659 $searchstring = "^".$searchstring;
661 if ($option & 8) { // EXACT
663 $searchstring = "^".$searchstring."$";
666 if ($option & 4 or $option & 8) {
667 global $xmlrpcerruser;
668 return new xmlrpcresp(0, $xmlrpcerruser + 1, "Invalid option");
671 include_once("lib/TextSearchQuery.php");
672 $query = new TextSearchQuery($searchstring, $case_exact, $regex ? 'auto' : 'none');
673 $dbh = $request->getDbh();
674 $iterator = $dbh->titleSearch($query);
676 while ($page = $iterator->next()) {
677 $pages[] = short_string($page->getName());
679 return new xmlrpcresp(new xmlrpcval($pages, "array"));
683 * array wiki.listPlugins()
685 * Returns an array of all available plugins.
686 * For EditToolbar pluginPulldown via AJAX
688 * @author: Reini Urban
690 $wiki_dmap['listPlugins']
691 = array('signature' => array(array($xmlrpcArray)),
692 'documentation' => "Return names of all plugins",
693 'function' => 'listPlugins');
695 function listPlugins($params)
697 $plugin_dir = 'lib/plugin';
698 if (defined('PHPWIKI_DIR'))
699 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
700 $pd = new fileSet($plugin_dir, '*.php');
701 $plugins = $pd->getFiles();
705 if (!empty($plugins)) {
706 require_once("lib/WikiPlugin.php");
707 $w = new WikiPluginLoader;
708 foreach ($plugins as $plugin) {
709 $pluginName = str_replace(".php", "", $plugin);
710 $p = $w->getPlugin($pluginName, false); // second arg?
711 // trap php files which aren't WikiPlugin~s: wikiplugin + wikiplugin_cached only
712 if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
713 $RetArray[] = short_string($pluginName);
718 return new xmlrpcresp(new xmlrpcval($RetArray, "array"));
722 * String wiki.getPluginSynopsis(String plugin)
724 * For EditToolbar pluginPulldown via AJAX
726 * @author: Reini Urban
728 $wiki_dmap['getPluginSynopsis']
729 = array('signature' => array(array($xmlrpcArray, $xmlrpcString)),
730 'documentation' => "Return plugin synopsis",
731 'function' => 'getPluginSynopsis');
733 function getPluginSynopsis($params)
735 $ParamPlugin = $params->getParam(0);
736 $pluginName = short_string_decode($ParamPlugin->scalarval());
738 require_once("lib/WikiPlugin.php");
739 $w = new WikiPluginLoader;
741 $p = $w->getPlugin($pluginName, false); // second arg?
742 // trap php files which aren't WikiPlugin~s: wikiplugin + wikiplugin_cached only
743 if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
745 $desc = $p->getArgumentsDescription();
746 $src = array("\n",'"',"'",'|','[',']','\\');
747 $replace = array('%0A','%22','%27','%7C','%5B','%5D','%5C');
748 $desc = str_replace("<br />",' ',$desc->asXML());
750 $plugin_args = '\n'.str_replace($src, $replace, $desc);
751 $synopsis = "<?plugin ".$pluginName.$plugin_args."?>"; // args?
754 return new xmlrpcresp(short_string($synopsis));
758 * array wiki.callPlugin(String name, String args)
760 * Returns an array of pages as returned by the plugins PageList call.
761 * Only valid for plugins returning pagelists, e.g. BackLinks, AllPages, ...
762 * For various AJAX or WikiFormRich calls.
764 * @author: Reini Urban
766 $wiki_dmap['callPlugin']
767 = array('signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString)),
768 'documentation' => "Returns an array of pages as returned by the plugins PageList call",
769 'function' => 'callPlugin');
771 function callPlugin($params)
774 $dbi = $request->getDbh();
775 $ParamPlugin = $params->getParam(0);
776 $pluginName = short_string_decode($ParamPlugin->scalarval());
777 $ParamArgs = $params->getParam(1);
778 $plugin_args = short_string_decode($ParamArgs->scalarval());
780 $basepage = ''; //$pluginName;
781 require_once("lib/WikiPlugin.php");
782 $w = new WikiPluginLoader;
783 $p = $w->getPlugin($pluginName, false); // second arg?
784 $pagelist = $p->run($dbi, $plugin_args, $request, $basepage);
786 if (is_object($pagelist) and isa($pagelist, 'PageList')) {
787 foreach ($pagelist->_pages as $page) {
788 $list[] = $page->getName();
791 return new xmlrpcresp(new xmlrpcval($list, "array"));
796 * array wiki.listRelations([ Integer option = 1 ])
798 * Returns an array of all available relation names.
799 * option: 1 relations only ( with 0 also )
800 * option: 2 attributes only
801 * option: 3 both, all names of relations and attributes
802 * option: 4 unsorted, this might be added as bitvalue: 7 = 4+3. default: sorted
803 * For some semanticweb autofill methods.
805 * @author: Reini Urban
807 $wiki_dmap['listRelations']
808 = array('signature' => array(array($xmlrpcArray, $xmlrpcInt)),
809 'documentation' => "Return names of all relations",
810 'function' => 'listRelations');
812 function listRelations($params)
815 $dbh = $request->getDbh();
816 if (count($params->params) > 0) {
817 $ParamOption = $params->getParam(0);
818 $option = (int) $ParamOption->scalarval();
821 $also_attributes = $option & 2;
822 $only_attributes = $option & 2 and !($option & 1);
823 $sorted = !($option & 4);
824 return new xmlrpcresp(new xmlrpcval($dbh->listRelations($also_attributes,
831 * String pingback.ping(String sourceURI, String targetURI)
833 Spec: http://www.hixie.ch/specs/pingback/pingback
836 sourceURI of type string
837 The absolute URI of the post on the source page containing the
838 link to the target site.
839 targetURI of type string
840 The absolute URI of the target of the link, as given on the source page.
842 A string, as described below.
844 If an error condition occurs, then the appropriate fault code from
845 the following list should be used. Clients can quickly determine
846 the kind of error from bits 5-8. 0×001x fault codes are used for
847 problems with the source URI, 0×002x codes are for problems with
848 the target URI, and 0×003x codes are used when the URIs are fine
849 but the pingback cannot be acknowledged for some other reaon.
852 A generic fault code. Servers MAY use this error code instead
853 of any of the others if they do not have a way of determining
854 the correct fault code.
856 The source URI does not exist.
858 The source URI does not contain a link to the target URI, and
859 so cannot be used as a source.
861 The specified target URI does not exist. This MUST only be
862 used when the target definitely does not exist, rather than
863 when the target may exist but is not recognised. See the next
866 The specified target URI cannot be used as a target. It either
867 doesn't exist, or it is not a pingback-enabled resource. For
868 example, on a blog, typically only permalinks are
869 pingback-enabled, and trying to pingback the home page, or a
870 set of posts, will fail with this error.
872 The pingback has already been registered.
876 The server could not communicate with an upstream server, or
877 received an error from an upstream server, and therefore could
878 not complete the request. This is similar to HTTP's 402 Bad
879 Gateway error. This error SHOULD be used by pingback proxies
880 when propagating errors.
882 In addition, [FaultCodes] defines some standard fault codes that
883 servers MAY use to report higher level errors.
885 Servers MUST respond to this function call either with a single string
886 or with a fault code.
888 If the pingback request is successful, then the return value MUST be a
889 single string, containing as much information as the server deems
890 useful. This string is only expected to be used for debugging
893 If the result is unsuccessful, then the server MUST respond with an
894 RPC fault value. The fault code should be either one of the codes
895 listed above, or the generic fault code zero if the server cannot
896 determine the correct fault code.
898 Clients MAY ignore the return value, whether the request was
899 successful or not. It is RECOMMENDED that clients do not show the
900 result of successful requests to the user.
902 Upon receiving a request, servers MAY do what they like. However, the
903 following steps are RECOMMENDED:
905 1. The server MAY attempt to fetch the source URI to verify that
906 the source does indeed link to the target.
907 2. The server MAY check its own data to ensure that the target
908 exists and is a valid entry.
909 3. The server MAY check that the pingback has not already been registered.
910 4. The server MAY record the pingback.
911 5. The server MAY regenerate the site's pages (if the pages are static).
913 * @author: Reini Urban
915 $wiki_dmap['pingback.ping']
916 = array('signature' => array(array($xmlrpcString, $xmlrpcString, $xmlrpcString)),
917 'documentation' => "",
918 'function' => 'pingBack');
919 function pingBack($params)
922 $Param0 = $params->getParam(0);
923 $sourceURI = short_string_decode($Param0->scalarval());
924 $Param1 = $params->getParam(1);
925 $targetURI = short_string_decode($Param1->scalarval());
929 /* End of private WikiXMLRpc API extensions */
930 /* ======================================================================== */
933 * Construct the server instance, and set up the dispatch map,
934 * which maps the XML-RPC methods on to the wiki functions.
935 * Provide the "wiki." prefix to each function. Besides
936 * the blog - pingback, ... - functions with a seperate namespace.
938 class XmlRpcServer extends xmlrpc_server
940 function XmlRpcServer ($request = false) {
942 foreach ($wiki_dmap as $name => $val) {
943 if ($name == 'pingback.ping') // non-wiki methods
946 $dmap['wiki.' . $name] = $val;
949 $this->xmlrpc_server($dmap, 0 /* delay service*/);
952 function service () {
953 global $ErrorManager;
955 $ErrorManager->pushErrorHandler(new WikiMethodCb($this, '_errorHandler'));
956 xmlrpc_server::service();
957 $ErrorManager->popErrorHandler();
960 function _errorHandler ($e) {
961 $msg = htmlspecialchars($e->asString());
962 // '--' not allowed within xml comment
963 $msg = str_replace('--', '--', $msg);
964 if (function_exists('xmlrpc_debugmsg'))
965 xmlrpc_debugmsg($msg);
971 $Log: not supported by cvs2svn $
972 Revision 1.23 2007/01/10 20:47:45 rurban
973 change int to string because of acdropdown
975 Revision 1.22 2007/01/07 18:44:11 rurban
976 Add summary to getRecentChanges result
978 Revision 1.21 2007/01/04 16:42:13 rurban
979 Use require, not include!
981 Revision 1.20 2007/01/03 21:25:52 rurban
982 add option argument to listRelations.
984 Revision 1.19 2007/01/02 13:21:21 rurban
985 split client from server. added getUploadedFileInfo (for SyncWiki), callPlugin (for WikiFormRich)
987 Revision 1.18 2006/05/18 06:10:45 rurban
988 add xmlrpc listRelations signature
990 Revision 1.17 2005/10/31 16:49:31 rurban
993 Revision 1.16 2005/10/29 14:17:51 rurban
996 Revision 1.15 2005/10/29 08:57:12 rurban
997 fix for !register_long_arrays
998 new: array wiki.listPlugins()
999 String wiki.getPluginSynopsis(String plugin)
1000 String pingback.ping(String sourceURI, String targetURI) (preliminary)
1005 // (c-file-style: "gnu")
1009 // c-basic-offset: 4
1010 // c-hanging-comment-ender-p: nil
1011 // indent-tabs-mode: nil