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 along
21 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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") {
75 die('This is the address of the XML-RPC interface.' .
76 ' You must use XML-RPC calls to access information here.');
79 require_once 'lib/XmlRpcClient.php';
80 if (loadPhpExtension('xmlrpc')) { // fast c lib
81 require_once 'lib/XMLRPC/xmlrpcs_emu.inc';
82 } else { // slow php lib
83 global $_xmlrpcs_dmap;
84 require_once 'lib/XMLRPC/xmlrpcs.inc';
88 * Helper function: Looks up a page revision (most recent by default) in the wiki database
90 * @param xmlrpcmsg $params : string pagename [int version]
91 * @return WikiDB _PageRevision object, or false if no such page
94 function _getPageRevision($params)
97 $ParamPageName = $params->getParam(0);
98 $ParamVersion = $params->getParam(1);
99 $pagename = short_string_decode($ParamPageName->scalarval());
100 $version = ($ParamVersion) ? ($ParamVersion->scalarval()) : (0);
101 // FIXME: test for version <=0 ??
102 $dbh = $request->getDbh();
103 if ($dbh->isWikiPage($pagename)) {
104 $page = $dbh->getPage($pagename);
106 $revision = $page->getCurrentRevision();
108 $revision = $page->getRevision($version);
116 * Get an xmlrpc "No such page" error message
118 function NoSuchPage($pagename = '')
120 global $xmlrpcerruser;
121 return new xmlrpcresp(0, $xmlrpcerruser + 1, "No such page " . $pagename);
124 // ****************************************************************************
125 // Main API functions follow
126 // ****************************************************************************
130 * int getRPCVersionSupported(): Returns 1 for this version of the API
132 $wiki_dmap['getRPCVersionSupported']
133 = array('signature' => array(array($xmlrpcInt)),
134 'documentation' => 'Get the version of the wiki API',
135 'function' => 'getRPCVersionSupported');
137 // The function must be a function in the global scope which services the XML-RPC
139 function getRPCVersionSupported($params)
141 return new xmlrpcresp(new xmlrpcval((integer)WIKI_XMLRPC_VERSION, "int"));
145 * array getRecentChanges(Date timestamp) : Get list of changed pages since
146 * timestamp, which should be in UTC. The result is an array, where each element
148 * name (string) : Name of the page. The name is UTF-8 with URL encoding to make it ASCII.
149 * lastModified (date) : Date of last modification, in UTC.
150 * author (string) : Name of the author (if available). Again, name is UTF-8 with URL encoding.
151 * version (int) : Current version.
152 * summary (string) : UTF-8 with URL encoding.
153 * A page MAY be specified multiple times. A page MAY NOT be specified multiple
154 * times with the same modification date.
155 * Additionally to API version 1 and 2 we added the summary field.
157 $wiki_dmap['getRecentChanges']
158 = array('signature' => array(array($xmlrpcArray, $xmlrpcDateTime)),
159 'documentation' => 'Get a list of changed pages since [timestamp]',
160 'function' => 'getRecentChanges');
162 function getRecentChanges($params)
165 // Get the first parameter as an ISO 8601 date. Assume UTC
166 $encoded_date = $params->getParam(0);
167 $datetime = iso8601_decode($encoded_date->scalarval(), 1);
168 $dbh = $request->getDbh();
170 $iterator = $dbh->mostRecent(array('since' => $datetime));
171 while ($page = $iterator->next()) {
172 // $page contains a WikiDB_PageRevision object
173 // no need to url encode $name, because it is already stored in that format ???
174 $name = short_string($page->getPageName());
175 $lastmodified = new xmlrpcval(iso8601_encode($page->get('mtime')), "dateTime.iso8601");
176 $author = short_string($page->get('author'));
177 $version = new xmlrpcval($page->getVersion(), 'int');
179 // Build an array of xmlrpc structs
180 $pages[] = new xmlrpcval(array('name' => $name,
181 'lastModified' => $lastmodified,
183 'summary' => short_string($page->get('summary')),
184 'version' => $version),
187 return new xmlrpcresp(new xmlrpcval($pages, "array"));
191 * base64 getPage( String pagename ): Get the raw Wiki text of page, latest version.
192 * Page name must be UTF-8, with URL encoding. Returned value is a binary object,
193 * with UTF-8 encoded page data.
195 $wiki_dmap['getPage']
196 = array('signature' => array(array($xmlrpcBase64, $xmlrpcString)),
197 'documentation' => 'Get the raw Wiki text of the current version of a page',
198 'function' => 'getPage');
200 function getPage($params)
202 $revision = _getPageRevision($params);
205 $ParamPageName = $params->getParam(0);
206 $pagename = short_string_decode($ParamPageName->scalarval());
207 return NoSuchPage($pagename);
210 return new xmlrpcresp(long_string($revision->getPackedContent()));
214 * base64 getPageVersion( String pagename, int version ): Get the raw Wiki text of page.
215 * Returns UTF-8, expects UTF-8 with URL encoding.
217 $wiki_dmap['getPageVersion']
218 = array('signature' => array(array($xmlrpcBase64, $xmlrpcString, $xmlrpcInt)),
219 'documentation' => 'Get the raw Wiki text of a page version',
220 'function' => 'getPageVersion');
222 function getPageVersion($params)
224 // error checking is done in getPage
225 return getPage($params);
229 * base64 getPageHTML( String pagename ): Return page in rendered HTML.
230 * Returns UTF-8, expects UTF-8 with URL encoding.
233 $wiki_dmap['getPageHTML']
234 = array('signature' => array(array($xmlrpcBase64, $xmlrpcString)),
235 'documentation' => 'Get the current version of a page rendered in HTML',
236 'function' => 'getPageHTML');
238 function getPageHTML($params)
240 $revision = _getPageRevision($params);
244 $content = $revision->getTransformedContent();
245 $html = $content->asXML();
246 // HACK: Get rid of outer <div class="wikitext">
247 if (preg_match('/^\s*<div class="wikitext">/', $html, $m1)
248 && preg_match('@</div>\s*$@', $html, $m2)
250 $html = substr($html, strlen($m1[0]), -strlen($m2[0]));
253 return new xmlrpcresp(long_string($html));
257 * base64 getPageHTMLVersion( String pagename, int version ): Return page in rendered HTML, UTF-8.
259 $wiki_dmap['getPageHTMLVersion']
260 = array('signature' => array(array($xmlrpcBase64, $xmlrpcString, $xmlrpcInt)),
261 'documentation' => 'Get a version of a page rendered in HTML',
262 'function' => 'getPageHTMLVersion');
264 function getPageHTMLVersion($params)
266 return getPageHTML($params);
270 * getAllPages(): Returns a list of all pages. The result is an array of strings.
272 $wiki_dmap['getAllPages']
273 = array('signature' => array(array($xmlrpcArray)),
274 'documentation' => 'Returns a list of all pages as an array of strings',
275 'function' => 'getAllPages');
277 function getAllPages($params)
280 $dbh = $request->getDbh();
281 $iterator = $dbh->getAllPages();
283 while ($page = $iterator->next()) {
284 $pages[] = short_string($page->getName());
286 return new xmlrpcresp(new xmlrpcval($pages, "array"));
290 * struct getPageInfo( string pagename ) : returns a struct with elements:
291 * name (string): the canonical page name
292 * lastModified (date): Last modification date
293 * version (int): current version
294 * author (string): author name
296 $wiki_dmap['getPageInfo']
297 = array('signature' => array(array($xmlrpcStruct, $xmlrpcString)),
298 'documentation' => 'Gets info about the current version of a page',
299 'function' => 'getPageInfo');
301 function getPageInfo($params)
303 $revision = _getPageRevision($params);
307 $name = short_string($revision->getPageName());
308 $version = new xmlrpcval ($revision->getVersion(), "int");
309 $lastmodified = new xmlrpcval(iso8601_encode($revision->get('mtime'), 0),
311 $author = short_string($revision->get('author'));
313 return new xmlrpcresp(new xmlrpcval(array('name' => $name,
314 'lastModified' => $lastmodified,
315 'version' => $version,
316 'author' => $author),
321 * struct getPageInfoVersion( string pagename, int version ) : returns
322 * a struct just like plain getPageInfo(), but this time for a
325 $wiki_dmap['getPageInfoVersion']
326 = array('signature' => array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcInt)),
327 'documentation' => 'Gets info about a page version',
328 'function' => 'getPageInfoVersion');
330 function getPageInfoVersion($params)
332 return getPageInfo($params);
335 /* array listLinks( string pagename ): Lists all links for a given page. The
336 * returned array contains structs, with the following elements:
337 * name (string) : The page name or URL the link is to.
338 * type (int) : The link type. Zero (0) for internal Wiki link,
339 * one (1) for external link (URL - image link, whatever).
341 $wiki_dmap['listLinks']
342 = array('signature' => array(array($xmlrpcArray, $xmlrpcString)),
343 'documentation' => 'Lists all links for a given page',
344 'function' => 'listLinks');
346 function listLinks($params)
350 $ParamPageName = $params->getParam(0);
351 $pagename = short_string_decode($ParamPageName->scalarval());
352 $dbh = $request->getDbh();
353 if (!$dbh->isWikiPage($pagename))
354 return NoSuchPage($pagename);
356 $page = $dbh->getPage($pagename);
358 // The fast WikiDB method. below is the slow method which goes through the formatter
359 // NB no clean way to extract a list of external links yet, so
360 // only internal links returned. i.e. all type 'local'.
361 $linkiterator = $page->getPageLinks();
362 $linkstruct = array();
363 while ($currentpage = $linkiterator->next()) {
364 $currentname = $currentpage->getName();
365 // Compute URL to page
367 // How to check external links?
368 if (!$currentpage->exists()) $args['action'] = 'edit';
370 // FIXME: Autodetected value of VIRTUAL_PATH wrong,
371 // this make absolute URLs constructed by WikiURL wrong.
372 // Also, if USE_PATH_INFO is false, WikiURL is wrong
373 // due to its use of SCRIPT_NAME.
374 //$use_abspath = USE_PATH_INFO && ! preg_match('/RPC2.php$/', VIRTUAL_PATH);
376 // USE_PATH_INFO must be defined in index.php or config.ini but not before,
377 // otherwise it is ignored and xmlrpc urls are wrong.
378 // SCRIPT_NAME here is always .../RPC2.php
379 if (USE_PATH_INFO and !$args) {
380 $url = preg_replace('/%2f/i', '/', rawurlencode($currentname));
381 } elseif (!USE_PATH_INFO) {
382 $url = str_replace("/RPC2.php", "/index.php", WikiURL($currentname, $args, true));
384 $url = WikiURL($currentname, $args);
386 $linkstruct[] = new xmlrpcval(array('page' => short_string($currentname),
387 'type' => new xmlrpcval('local', 'string'),
388 'href' => short_string($url)),
393 $current = $page->getCurrentRevision();
394 $content = $current->getTransformedContent();
395 $links = $content->getLinkInfo();
396 foreach ($links as $link) {
397 // We used to give an href for unknown pages that
398 // included action=edit. I think that's probably the
399 // wrong thing to do.
400 $linkstruct[] = new xmlrpcval(array('page'=> short_string($link->page),
401 'type'=> new xmlrpcval($link->type, 'string'),
402 'href' => short_string($link->href),
403 //'pageref' => short_string($link->pageref),
408 return new xmlrpcresp(new xmlrpcval ($linkstruct, "array"));
411 /* End of WikiXMLRpc API v1 */
412 /* ======================================================================== */
413 /* Start of partial WikiXMLRpc API v2 support */
416 * struct putPage(String pagename, String content, [String author[, String password]})
417 * returns a struct with elements:
418 * code (int): 200 on success, 400 or 401 on failure
419 * message (string): success or failure message
420 * version (int): version of new page
422 * @author: Arnaud Fontaine, Reini Urban
424 * API notes: Contrary to the API v2 specs we dropped attributes and added author + password
426 $wiki_dmap['putPage']
427 = array('signature' => array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString)),
428 'documentation' => 'put the raw Wiki text into a page as new version',
429 'function' => 'putPage');
431 function _getUser($userid = '')
436 if (!isset($_SERVER))
437 $_SERVER =& $GLOBALS['HTTP_SERVER_VARS'];
439 $_ENV =& $GLOBALS['HTTP_ENV_VARS'];
440 if (isset($_SERVER['REMOTE_USER']))
441 $userid = $_SERVER['REMOTE_USER'];
442 elseif (isset($_ENV['REMOTE_USER']))
443 $userid = $_ENV['REMOTE_USER']; elseif (isset($_SERVER['REMOTE_ADDR']))
444 $userid = $_SERVER['REMOTE_ADDR']; elseif (isset($_ENV['REMOTE_ADDR']))
445 $userid = $_ENV['REMOTE_ADDR']; elseif (isset($GLOBALS['REMOTE_ADDR']))
446 $userid = $GLOBALS['REMOTE_ADDR'];
449 if (ENABLE_USER_NEW) {
450 return WikiUser($userid);
452 return new WikiUser($request, $userid);
456 function putPage($params)
460 $ParamPageName = $params->getParam(0);
461 $ParamContent = $params->getParam(1);
462 $pagename = short_string_decode($ParamPageName->scalarval());
463 $content = short_string_decode($ParamContent->scalarval());
465 if (count($params->params) > 2) {
466 $ParamAuthor = $params->getParam(2);
467 $userid = short_string_decode($ParamAuthor->scalarval());
468 if (count($params->params) > 3) {
469 $ParamPassword = $params->getParam(3);
470 $passwd = short_string_decode($ParamPassword->scalarval());
473 $userid = $request->_user->_userid;
475 $request->_user = _getUser($userid);
476 $request->_user->_group = $request->getGroup();
477 $request->_user->AuthCheck($userid, $passwd);
479 if (!mayAccessPage('edit', $pagename)) {
480 return new xmlrpcresp(
482 array('code' => new xmlrpcval(401, "int"),
483 'version' => new xmlrpcval(0, "int"),
485 short_string("no permission for "
486 . $request->_user->UserName())),
491 $dbh = $request->getDbh();
492 $page = $dbh->getPage($pagename);
493 $current = $page->getCurrentRevision();
494 $content = trim($content);
495 $version = $current->getVersion();
496 // $version = -1 will force create a new version
497 if ($current->getPackedContent() != $content) {
498 $init_meta = array('ctime' => $now,
499 'creator' => $userid,
500 'creator_id' => $userid,
502 $version_meta = array('author' => $userid,
503 'author_id' => $userid,
505 'summary' => isset($summary) ? $summary : _("xml-rpc change"),
507 'pagetype' => 'wikitext',
508 'wikitext' => $init_meta,
511 $res = $page->save($content, $version, $version_meta);
513 $message = "Page $pagename version $version created";
515 $message = "Problem creating version $version of page $pagename";
518 $message = $message = "Page $pagename unchanged";
520 return new xmlrpcresp(new xmlrpcval(array('code' => new xmlrpcval($res ? 200 : 400, "int"),
521 'version' => new xmlrpcval($version, "int"),
522 'message' => short_string($message)),
526 /* End of WikiXMLRpc API v2 */
527 /* ======================================================================== */
528 /* Start of private extensions */
531 * struct getUploadedFileInfo( string localpath ) : returns a struct with elements:
532 * lastModified (date): Last modification date
533 * size (int): current version
534 * This is to sync uploaded files up to a remote master wiki. (SyncWiki)
535 * Not existing files return both 0.
537 * API notes: API v2 specs have array listAttachments( utf8 page ),
538 * base64 getAttachment( utf8 attachmentName ), putAttachment( utf8 attachmentName, base64 content )
540 $wiki_dmap['getUploadedFileInfo']
541 = array('signature' => array(array($xmlrpcStruct, $xmlrpcString)),
542 'documentation' => 'Gets date and size about an uploaded local file',
543 'function' => 'getUploadedFileInfo');
545 function getUploadedFileInfo($params)
547 // localpath is the relative part after "Upload:"
548 $ParamPath = $params->getParam(0);
549 $localpath = short_string_decode($ParamPath->scalarval());
550 preg_replace("/^[\\ \/ \.]/", "", $localpath); // strip hacks
551 $file = getUploadFilePath() . $localpath;
552 if (file_exists($file)) {
553 $size = filesize($file);
554 $lastmodified = filemtime($file);
559 return new xmlrpcresp(new xmlrpcval
560 (array('lastModified' => new xmlrpcval(iso8601_encode($lastmodified, 1),
562 'size' => new xmlrpcval($size, "int")),
567 * Publish-Subscribe (not yet implemented)
568 * Client subscribes to a RecentChanges-like channel, getting a short
569 * callback notification on every change. Like PageChangeNotification, just shorter
570 * and more complicated
571 * RSS2 support (not yet), since radio userland's rss-0.92. now called RSS2.
572 * BTW: Radio Userland deprecated this interface.
574 * boolean wiki.rssPleaseNotify ( notifyProcedure, port, path, protocol, urlList )
575 * returns: true or false
577 * Check of the channel behind the rssurl has a cloud element,
578 * if the client has a direct IP connection (no NAT),
579 * register the client on the WikiDB notification handler
581 * http://backend.userland.com/publishSubscribeWalkthrough
582 * http://www.soapware.org/xmlStorageSystem#rssPleaseNotify
583 * http://www.thetwowayweb.com/soapmeetsrss#rsscloudInterface
585 $wiki_dmap['rssPleaseNotify']
586 = array('signature' => array(array($xmlrpcBoolean, $xmlrpcStruct)),
587 'documentation' => 'RSS2 change notification subscriber channel',
588 'function' => 'rssPleaseNotify');
590 function rssPleaseNotify($params)
592 // register the clients IP
593 return new xmlrpcresp(new xmlrpcval (0, "boolean"));
597 * boolean wiki.mailPasswordToUser ( username )
598 * returns: true or false
601 $wiki_dmap['mailPasswordToUser']
602 = array('signature' => array(array($xmlrpcBoolean, $xmlrpcString)),
603 'documentation' => 'RSS2 user management helper',
604 'function' => 'mailPasswordToUser');
606 function mailPasswordToUser($params)
609 $ParamUserid = $params->getParam(0);
610 $userid = short_string_decode($ParamUserid->scalarval());
611 $request->_user = _getUser($userid);
612 //$request->_prefs =& $request->_user->_prefs;
613 $email = $request->getPref('email');
616 $body = WikiURL('') . "\nPassword: " . $request->getPref('passwd');
617 $success = mail($email, "[" . WIKI_NAME . "} Password Request",
620 return new xmlrpcresp(new xmlrpcval ($success, "boolean"));
624 * array wiki.titleSearch(String substring [, String option = "0"])
625 * returns an array of matching pagenames.
626 * TODO: standardize options
628 * @author: Reini Urban
630 $wiki_dmap['titleSearch']
631 = array('signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString)),
632 'documentation' => "Return matching pagenames.
633 Option 1: caseexact, 2: regex, 4: starts_with, 8: exact, 16: fallback",
634 'function' => 'titleSearch');
636 function titleSearch($params)
639 $ParamPageName = $params->getParam(0);
640 $searchstring = short_string_decode($ParamPageName->scalarval());
641 if (count($params->params) > 1) {
642 $ParamOption = $params->getParam(1);
643 $option = (int)$ParamOption->scalarval();
646 // default option: substring, case-inexact
648 $case_exact = $option & 1;
649 $regex = $option & 2;
650 $fallback = $option & 16;
652 if ($option & 4) { // STARTS_WITH
654 $searchstring = "^" . $searchstring;
656 if ($option & 8) { // EXACT
658 $searchstring = "^" . $searchstring . "$";
661 if ($option & 4 or $option & 8) {
662 global $xmlrpcerruser;
663 return new xmlrpcresp(0, $xmlrpcerruser + 1, "Invalid option");
666 include_once 'lib/TextSearchQuery.php';
667 $query = new TextSearchQuery($searchstring, $case_exact, $regex ? 'auto' : 'none');
668 $dbh = $request->getDbh();
669 $iterator = $dbh->titleSearch($query);
671 while ($page = $iterator->next()) {
672 $pages[] = short_string($page->getName());
674 // On failure try again broader (substring + case inexact)
675 if ($fallback and empty($pages)) {
676 $query = new TextSearchQuery(short_string_decode($ParamPageName->scalarval()), false,
677 $regex ? 'auto' : 'none');
678 $dbh = $request->getDbh();
679 $iterator = $dbh->titleSearch($query);
680 while ($page = $iterator->next()) {
681 $pages[] = short_string($page->getName());
684 return new xmlrpcresp(new xmlrpcval($pages, "array"));
688 * array wiki.listPlugins()
690 * Returns an array of all available plugins.
691 * For EditToolbar pluginPulldown via AJAX
693 * @author: Reini Urban
695 $wiki_dmap['listPlugins']
696 = array('signature' => array(array($xmlrpcArray)),
697 'documentation' => "Return names of all plugins",
698 'function' => 'listPlugins');
700 function listPlugins($params)
702 $plugin_dir = 'lib/plugin';
703 if (defined('PHPWIKI_DIR'))
704 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
705 $pd = new fileSet($plugin_dir, '*.php');
706 $plugins = $pd->getFiles();
710 if (!empty($plugins)) {
711 require_once 'lib/WikiPlugin.php';
712 $w = new WikiPluginLoader();
713 foreach ($plugins as $plugin) {
714 $pluginName = str_replace(".php", "", $plugin);
715 $p = $w->getPlugin($pluginName, false); // second arg?
716 // trap php files which aren't WikiPlugin~s: wikiplugin + wikiplugin_cached only
717 if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
718 $RetArray[] = short_string($pluginName);
723 return new xmlrpcresp(new xmlrpcval($RetArray, "array"));
727 * String wiki.getPluginSynopsis(String plugin)
729 * For EditToolbar pluginPulldown via AJAX
731 * @author: Reini Urban
733 $wiki_dmap['getPluginSynopsis']
734 = array('signature' => array(array($xmlrpcArray, $xmlrpcString)),
735 'documentation' => "Return plugin synopsis",
736 'function' => 'getPluginSynopsis');
738 function getPluginSynopsis($params)
740 $ParamPlugin = $params->getParam(0);
741 $pluginName = short_string_decode($ParamPlugin->scalarval());
743 require_once 'lib/WikiPlugin.php';
744 $w = new WikiPluginLoader();
746 $p = $w->getPlugin($pluginName, false); // second arg?
747 // trap php files which aren't WikiPlugin~s: wikiplugin + wikiplugin_cached only
748 if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
750 $desc = $p->getArgumentsDescription();
751 $src = array("\n", '"', "'", '|', '[', ']', '\\');
752 $replace = array('%0A', '%22', '%27', '%7C', '%5B', '%5D', '%5C');
753 $desc = str_replace("<br />", ' ', $desc->asXML());
755 $plugin_args = '\n' . str_replace($src, $replace, $desc);
756 $synopsis = "<?plugin " . $pluginName . $plugin_args . "?>"; // args?
759 return new xmlrpcresp(short_string($synopsis));
763 * array wiki.callPlugin(String name, String args)
765 * Returns an array of pages as returned by the plugins PageList call.
766 * Only valid for plugins returning pagelists, e.g. BackLinks, AllPages, ...
767 * For various AJAX or WikiFormRich calls.
769 * @author: Reini Urban
771 $wiki_dmap['callPlugin']
772 = array('signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString)),
773 'documentation' => "Returns an array of pages as returned by the plugins PageList call",
774 'function' => 'callPlugin');
776 function callPlugin($params)
779 $dbi = $request->getDbh();
780 $ParamPlugin = $params->getParam(0);
781 $pluginName = short_string_decode($ParamPlugin->scalarval());
782 $ParamArgs = $params->getParam(1);
783 $plugin_args = short_string_decode($ParamArgs->scalarval());
785 $basepage = ''; //$pluginName;
786 require_once 'lib/WikiPlugin.php';
787 $w = new WikiPluginLoader();
788 $p = $w->getPlugin($pluginName, false); // second arg?
789 $pagelist = $p->run($dbi, $plugin_args, $request, $basepage);
791 if (is_object($pagelist) and isa($pagelist, 'PageList')) {
792 foreach ($pagelist->_pages as $page) {
793 $list[] = $page->getName();
796 return new xmlrpcresp(new xmlrpcval($list, "array"));
800 * array wiki.listRelations([ Integer option = 1 ])
802 * Returns an array of all available relation names.
803 * option: 1 relations only ( with 0 also )
804 * option: 2 attributes only
805 * option: 3 both, all names of relations and attributes
806 * option: 4 unsorted, this might be added as bitvalue: 7 = 4+3. default: sorted
807 * For some semanticweb autofill methods.
809 * @author: Reini Urban
811 $wiki_dmap['listRelations']
812 = array('signature' => array(array($xmlrpcArray, $xmlrpcInt)),
813 'documentation' => "Return names of all relations",
814 'function' => 'listRelations');
816 function listRelations($params)
819 $dbh = $request->getDbh();
820 if (count($params->params) > 0) {
821 $ParamOption = $params->getParam(0);
822 $option = (int)$ParamOption->scalarval();
825 $also_attributes = $option & 2;
826 $only_attributes = $option & 2 and !($option & 1);
827 $sorted = !($option & 4);
828 return new xmlrpcresp(new xmlrpcval($dbh->listRelations($also_attributes,
835 * String pingback.ping(String sourceURI, String targetURI)
837 Spec: http://www.hixie.ch/specs/pingback/pingback
840 sourceURI of type string
841 The absolute URI of the post on the source page containing the
842 link to the target site.
843 targetURI of type string
844 The absolute URI of the target of the link, as given on the source page.
846 A string, as described below.
848 If an error condition occurs, then the appropriate fault code from
849 the following list should be used. Clients can quickly determine
850 the kind of error from bits 5-8. 0x001x fault codes are used for
851 problems with the source URI, 0x002x codes are for problems with
852 the target URI, and 0x003x codes are used when the URIs are fine
853 but the pingback cannot be acknowledged for some other reaon.
856 A generic fault code. Servers MAY use this error code instead
857 of any of the others if they do not have a way of determining
858 the correct fault code.
860 The source URI does not exist.
862 The source URI does not contain a link to the target URI, and
863 so cannot be used as a source.
865 The specified target URI does not exist. This MUST only be
866 used when the target definitely does not exist, rather than
867 when the target may exist but is not recognised. See the next
870 The specified target URI cannot be used as a target. It either
871 doesn't exist, or it is not a pingback-enabled resource. For
872 example, on a blog, typically only permalinks are
873 pingback-enabled, and trying to pingback the home page, or a
874 set of posts, will fail with this error.
876 The pingback has already been registered.
880 The server could not communicate with an upstream server, or
881 received an error from an upstream server, and therefore could
882 not complete the request. This is similar to HTTP's 402 Bad
883 Gateway error. This error SHOULD be used by pingback proxies
884 when propagating errors.
886 In addition, [FaultCodes] defines some standard fault codes that
887 servers MAY use to report higher level errors.
889 Servers MUST respond to this function call either with a single string
890 or with a fault code.
892 If the pingback request is successful, then the return value MUST be a
893 single string, containing as much information as the server deems
894 useful. This string is only expected to be used for debugging
897 If the result is unsuccessful, then the server MUST respond with an
898 RPC fault value. The fault code should be either one of the codes
899 listed above, or the generic fault code zero if the server cannot
900 determine the correct fault code.
902 Clients MAY ignore the return value, whether the request was
903 successful or not. It is RECOMMENDED that clients do not show the
904 result of successful requests to the user.
906 Upon receiving a request, servers MAY do what they like. However, the
907 following steps are RECOMMENDED:
909 1. The server MAY attempt to fetch the source URI to verify that
910 the source does indeed link to the target.
911 2. The server MAY check its own data to ensure that the target
912 exists and is a valid entry.
913 3. The server MAY check that the pingback has not already been registered.
914 4. The server MAY record the pingback.
915 5. The server MAY regenerate the site's pages (if the pages are static).
916 * @author: Reini Urban
918 $wiki_dmap['pingback.ping']
919 = array('signature' => array(array($xmlrpcString, $xmlrpcString, $xmlrpcString)),
920 'documentation' => "",
921 'function' => 'pingBack');
922 function pingBack($params)
925 $Param0 = $params->getParam(0);
926 $sourceURI = short_string_decode($Param0->scalarval());
927 $Param1 = $params->getParam(1);
928 $targetURI = short_string_decode($Param1->scalarval());
932 /* End of private WikiXMLRpc API extensions */
933 /* ======================================================================== */
936 * Construct the server instance, and set up the dispatch map,
937 * which maps the XML-RPC methods on to the wiki functions.
938 * Provide the "wiki." prefix to each function. Besides
939 * the blog - pingback, ... - functions with a separate namespace.
941 class XmlRpcServer extends xmlrpc_server
943 function XmlRpcServer($request = false)
946 foreach ($wiki_dmap as $name => $val) {
947 if ($name == 'pingback.ping') // non-wiki methods
950 $dmap['wiki.' . $name] = $val;
953 $this->xmlrpc_server($dmap, 0 /* delay service*/);
958 global $ErrorManager;
960 $ErrorManager->pushErrorHandler(new WikiMethodCb($this, '_errorHandler'));
961 xmlrpc_server::service();
962 $ErrorManager->popErrorHandler();
965 function _errorHandler($e)
967 $msg = htmlspecialchars($e->asString());
968 // '--' not allowed within xml comment
969 $msg = str_replace('--', '--', $msg);
970 if (function_exists('xmlrpc_debugmsg'))
971 xmlrpc_debugmsg($msg);
980 // c-hanging-comment-ender-p: nil
981 // indent-tabs-mode: nil