4 * Taken from http://www.wlug.org.nz/archive/
5 * Please see http://phpwiki.sourceforge.net/phpwiki/PhpWiki.wdsl
6 * for the wdsl discussion.
9 * checkCredentials: set the $GLOBALS['request']->_user object for
11 * enable native pecl extension (xml-rpc or soap)
13 * Installer helper which changes server url of the default PhpWiki.wdsl
14 * Or do it dynamically in the soap class? No, the client must connect to us.
16 * @author: Reini Urban
18 define ("WIKI_SOAP", true);
20 include_once './index.php';
21 include_once 'lib/main.php';
22 if (!loadExtension('soap'))
23 require_once 'lib/nusoap/nusoap.php';
26 // bypass auth and request loop for now.
27 // require_once('lib/prepend.php');
28 include_once 'index.php';
30 //require_once('lib/stdlib.php');
31 require_once 'lib/WikiDB.php';
32 require_once 'lib/config.php';
33 class WikiRequest extends Request {}
34 $request = new WikiRequest();
35 require_once 'lib/PagePerm.php';
36 require_once 'lib/WikiUserNew.php';
37 require_once 'lib/WikiGroup.php';
40 function checkCredentials(&$server, &$credentials, $access, $pagename)
42 // check the "Authorization: Basic '.base64_encode("$this->username:$this->password").'\r\n'" header
43 if (isset($server->header['Authorization'])) {
44 $line = base64_decode(str_replace("Basic ", "", trim($server->header['Authorization'])));
45 list($credentials['username'], $credentials['password']) = explode(':', $line);
48 $_SERVER =& $GLOBALS['HTTP_SERVER_VARS'];
49 // TODO: where in the header is the client IP
50 if (!isset($credentials['username'])) {
51 if (isset($_SERVER['REMOTE_ADDR']))
52 $credentials['username'] = $_SERVER['REMOTE_ADDR'];
53 elseif (isset($GLOBALS['REMOTE_ADDR']))
54 $credentials['username'] = $GLOBALS['REMOTE_ADDR']; else
55 $credentials['username'] = $server->host;
58 if (!isset($credentials['password'])) $credentials['password'] = '';
61 if (ENABLE_USER_NEW) {
62 $request->_user = WikiUser($credentials['username']);
64 $request->_user = new WikiUser($request, $credentials['username']);
66 $request->_user->AuthCheck(array('userid' => $credentials['username'],
67 'passwd' => $credentials['password']));
68 if (!mayAccessPage($access, $pagename))
69 $server->fault(401, '', "no permission");
72 $GLOBALS['SERVER_NAME'] = SERVER_URL;
73 $GLOBALS['SCRIPT_NAME'] = DATA_PATH . "/SOAP.php";
74 $url = SERVER_URL . DATA_PATH . "/SOAP.php";
76 // Local or external wdsl support is experimental.
77 // It works without also. Just the client has to
78 // know the wdsl definitions.
79 $server = new soap_server( /* 'PhpWiki.wdsl' */);
80 // Now change the server url to ours, because in the wdsl is the original PhpWiki address
81 // <soap:address location="http://phpwiki.sourceforge.net/phpwiki/SOAP.php" />
82 // <soap:operation soapAction="http://phpwiki.sourceforge.net/phpwiki/SOAP.php" />
84 $server->ports[$server->currentPort]['location'] = $url;
85 $server->bindings[$server->ports[$server->currentPort]['binding']]['endpoint'] = $url;
86 $server->soapaction = $url; // soap_transport_http
88 $actions = array('getPageContent', 'getPageRevision', 'getCurrentRevision',
89 'getPageMeta', 'doSavePage', 'getAllPagenames',
90 'getBackLinks', 'doTitleSearch', 'doFullTextSearch',
91 'getRecentChanges', 'listLinks', 'listPlugins',
92 'getPluginSynopsis', 'callPlugin', 'listRelations',
95 foreach ($actions as $action) {
96 $server->register($actions);
97 $server->operations[$actions]['soapaction'] = $url;
100 //todo: check and set credentials
101 // requiredAuthorityForPage($action);
102 // require 'edit' access
103 function doSavePage($pagename, $content, $credentials = false)
106 checkCredentials($server, $credentials, 'edit', $pagename);
107 $dbi = WikiDB::open($GLOBALS['DBParams']);
108 $page = $dbi->getPage($pagename);
109 $current = $page->getCurrentRevision();
110 $meta = $current->_data;
111 $meta['summary'] = sprintf(_("SOAP Request %s", $credentials['username'])); // from user or IP ?
112 $version = $current->getVersion();
113 return $page->save($content, $version + 1, $meta);
116 // require 'view' access
117 function getPageContent($pagename, $credentials = false)
120 checkCredentials($server, $credentials, 'view', $pagename);
121 $dbi = WikiDB::open($GLOBALS['DBParams']);
122 $page = $dbi->getPage($pagename);
123 $rev = $page->getCurrentRevision();
124 $text = $rev->getPackedContent();
128 // require 'view' access
129 function getPageRevision($pagename, $revision, $credentials = false)
132 checkCredentials($server, $credentials, 'view', $pagename);
133 $dbi = WikiDB::open($GLOBALS['DBParams']);
134 $page = $dbi->getPage($pagename);
135 $rev = $page->getCurrentRevision();
136 $text = $rev->getPackedContent();
140 // require 'view' access
141 function getCurrentRevision($pagename, $credentials = false)
144 checkCredentials($server, $credentials, 'view', $pagename);
145 if (!mayAccessPage('view', $pagename))
146 $server->fault(401, '', "no permission");
147 $dbi = WikiDB::open($GLOBALS['DBParams']);
148 $page = $dbi->getPage($pagename);
149 $rev = $page->getCurrentRevision();
150 $version = $current->getVersion();
151 return (double)$version;
154 // require 'change' or 'view' access ?
155 function getPageMeta($pagename, $credentials = false)
158 checkCredentials($server, $credentials, 'view', $pagename);
159 $dbi = WikiDB::open($GLOBALS['DBParams']);
160 $page = $dbi->getPage($pagename);
161 $rev = $page->getCurrentRevision();
163 //todo: reformat the meta hash
167 // require 'view' access to AllPages
168 function getAllPagenames($credentials = false)
171 checkCredentials($server, $credentials, 'view', _("AllPages"));
172 $dbi = WikiDB::open($GLOBALS['DBParams']);
173 $page_iter = $dbi->getAllPages();
175 while ($page = $page_iter->next()) {
176 $pages[] = array('pagename' => $page->_pagename);
181 // require 'view' access
182 function getBacklinks($pagename, $credentials = false)
185 checkCredentials($server, $credentials, 'view', $pagename);
186 $dbi = WikiDB::open($GLOBALS['DBParams']);
187 $backend = &$dbi->_backend;
188 $result = $backend->get_links($pagename);
189 $page_iter = new WikiDB_PageIterator($dbi, $result);
191 while ($page = $page_iter->next()) {
192 $pages[] = array('pagename' => $page->getName());
197 // require 'view' access to TitleSearch
198 function doTitleSearch($s, $credentials = false)
201 checkCredentials($server, $credentials, 'view', _("TitleSearch"));
202 $dbi = WikiDB::open($GLOBALS['DBParams']);
203 $query = new TextSearchQuery($s);
204 $page_iter = $dbi->titleSearch($query);
206 while ($page = $page_iter->next()) {
207 $pages[] = array('pagename' => $page->getName());
212 // require 'view' access to FullTextSearch
213 function doFullTextSearch($s, $credentials = false)
216 checkCredentials($server, $credentials, 'view', _("FullTextSearch"));
217 $dbi = WikiDB::open($GLOBALS['DBParams']);
218 $query = new TextSearchQuery($s);
219 $page_iter = $dbi->fullSearch($query);
221 while ($page = $page_iter->next()) {
222 $pages[] = array('pagename' => $page->getName());
227 // require 'view' access to RecentChanges
228 function getRecentChanges($limit = false, $since = false, $include_minor = false, $credentials = false)
231 checkCredentials($server, $credentials, 'view', _("RecentChanges"));
232 $dbi = WikiDB::open($GLOBALS['DBParams']);
233 $params = array('limit' => $limit, 'since' => $since,
234 'include_minor_revisions' => $include_minor);
235 $page_iter = $dbi->mostRecent($params);
237 while ($page = $page_iter->next()) {
238 $pages[] = array('pagename' => $page->getName(),
239 'lastModified' => $page->get('mtime'),
240 'author' => $page->get('author'),
241 'summary' => $page->get('summary'), // added with 1.3.13
242 'version' => $page->getVersion()
248 // require 'view' access
249 function listLinks($pagename, $credentials = false)
252 checkCredentials($server, $credentials, 'view', $pagename);
253 $dbi = WikiDB::open($GLOBALS['DBParams']);
254 $page = $dbi->getPage($pagename);
255 $linkiterator = $page->getPageLinks();
257 while ($currentpage = $linkiterator->next()) {
258 if ($currentpage->exists())
259 $links[] = array('pagename' => $currentpage->getName());
264 function listPlugins($credentials = false)
267 checkCredentials($server, $credentials, 'change', _("HomePage"));
268 $plugin_dir = 'lib/plugin';
269 if (defined('PHPWIKI_DIR'))
270 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
271 $pd = new fileSet($plugin_dir, '*.php');
272 $plugins = $pd->getFiles();
276 if (!empty($plugins)) {
277 require_once 'lib/WikiPlugin.php';
278 $w = new WikiPluginLoader;
279 foreach ($plugins as $plugin) {
280 $pluginName = str_replace(".php", "", $plugin);
281 $p = $w->getPlugin($pluginName, false); // second arg?
282 // trap php files which aren't WikiPlugin~s: wikiplugin + wikiplugin_cached only
283 if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
284 $RetArray[] = $pluginName;
291 function getPluginSynopsis($pluginname, $credentials = false)
294 checkCredentials($server, $credentials, 'change', "Help/" . $pluginname . "Plugin");
295 require_once 'lib/WikiPlugin.php';
296 $w = new WikiPluginLoader;
298 $p = $w->getPlugin($pluginName, false); // second arg?
299 // trap php files which aren't WikiPlugin~s: wikiplugin + wikiplugin_cached only
300 if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
302 $desc = $p->getArgumentsDescription();
303 $src = array("\n", '"', "'", '|', '[', ']', '\\');
304 $replace = array('%0A', '%22', '%27', '%7C', '%5B', '%5D', '%5C');
305 $desc = str_replace("<br />", ' ', $desc->asXML());
307 $plugin_args = '\n' . str_replace($src, $replace, $desc);
308 $synopsis = "<?plugin " . $pluginName . $plugin_args . "?>"; // args?
313 // only plugins returning pagelists will return something useful. so omit the html output
314 function callPlugin($pluginname, $pluginargs, $credentials = false)
317 checkCredentials($server, $credentials, 'change', "Help/" . $pluginname . "Plugin");
321 require_once 'lib/WikiPlugin.php';
322 $w = new WikiPluginLoader;
323 $p = $w->getPlugin($pluginName, false); // second arg?
324 $pagelist = $p->run($dbi, $pluginargs, $request, $basepage);
326 if (is_object($pagelist) and isa($pagelist, 'PageList')) {
327 foreach ($pagelist->pageNames() as $name)
328 $pages[] = array('pagename' => $name);
334 * array listRelations([ Integer option = 1 ])
336 * Returns an array of all available relation names.
337 * option: 1 relations only ( with 0 also )
338 * option: 2 attributes only
339 * option: 3 both, all names of relations and attributes
340 * option: 4 unsorted, this might be added as bitvalue: 7 = 4+3. default: sorted
341 * For some semanticweb autofill methods.
343 * @author: Reini Urban
345 function listRelations($option = 1, $credentials = false)
348 checkCredentials($server, $credentials, 'view', _("HomePage"));
349 $also_attributes = $option & 2;
350 $only_attributes = $option & 2 and !($option & 1);
351 $sorted = !($option & 4);
352 return $dbh->listRelations($also_attributes,
357 // some basic semantic search
358 function linkSearch($linktype, $search, $pages = "*", $relation = "*", $credentials = false)
361 checkCredentials($server, $credentials, 'view', _("HomePage"));
362 $dbi = WikiDB::open($GLOBALS['DBParams']);
363 require_once 'lib/TextSearchQuery.php';
364 $pagequery = new TextSearchQuery($pages);
365 $linkquery = new TextSearchQuery($search);
366 if ($linktype == 'relation') {
367 $relquery = new TextSearchQuery($relation);
368 $links = $dbi->_backend->link_search($pagequery, $linkquery, $linktype, $relquery);
369 } elseif ($linktype == 'attribute') { // only numeric search withh attributes!
370 $relquery = new TextSearchQuery($relation);
371 require_once 'lib/SemanticWeb.php';
372 // search: "population > 1 million and area < 200 km^2" relation="*" pages="*"
373 $linkquery = new SemanticAttributeSearchQuery($search, $relation);
374 $links = $dbi->_backend->link_search($pagequery, $linkquery, $linktype, $relquery);
376 // we already do have forward and backlinks as SOAP
377 $links = $dbi->_backend->link_search($pagequery, $linkquery, $linktype);
379 return $links->asArray();
382 $server->service($GLOBALS['HTTP_RAW_POST_DATA']);
388 // c-hanging-comment-ender-p: nil
389 // indent-tabs-mode: nil