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) {
41 // check the "Authorization: Basic '.base64_encode("$this->username:$this->password").'\r\n'" header
42 if (isset($server->header['Authorization'])) {
43 $line = base64_decode(str_replace("Basic ","",trim($server->header['Authorization'])));
44 list($credentials['username'],$credentials['password']) = explode(':',$line);
47 $_SERVER =& $GLOBALS['HTTP_SERVER_VARS'];
48 // TODO: where in the header is the client IP
49 if (!isset($credentials['username'])) {
50 if (isset($_SERVER['REMOTE_ADDR']))
51 $credentials['username'] = $_SERVER['REMOTE_ADDR'];
52 elseif (isset($GLOBALS['REMOTE_ADDR']))
53 $credentials['username'] = $GLOBALS['REMOTE_ADDR'];
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) {
105 checkCredentials($server, $credentials,'edit',$pagename);
106 $dbi = WikiDB::open($GLOBALS['DBParams']);
107 $page = $dbi->getPage($pagename);
108 $current = $page->getCurrentRevision();
109 $meta = $current->_data;
110 $meta['summary'] = sprintf(_("SOAP Request %s", $credentials['username'])); // from user or IP ?
111 $version = $current->getVersion();
112 return $page->save($content, $version + 1, $meta);
115 // require 'view' access
116 function getPageContent($pagename,$credentials=false) {
118 checkCredentials($server,$credentials,'view',$pagename);
119 $dbi = WikiDB::open($GLOBALS['DBParams']);
120 $page = $dbi->getPage($pagename);
121 $rev = $page->getCurrentRevision();
122 $text = $rev->getPackedContent();
125 // require 'view' access
126 function getPageRevision($pagename,$revision,$credentials=false) {
128 checkCredentials($server,$credentials,'view',$pagename);
129 $dbi = WikiDB::open($GLOBALS['DBParams']);
130 $page = $dbi->getPage($pagename);
131 $rev = $page->getCurrentRevision();
132 $text = $rev->getPackedContent();
135 // require 'view' access
136 function getCurrentRevision($pagename,$credentials=false) {
138 checkCredentials($server,$credentials,'view',$pagename);
139 if (!mayAccessPage ('view',$pagename))
140 $server->fault(401,'',"no permission");
141 $dbi = WikiDB::open($GLOBALS['DBParams']);
142 $page = $dbi->getPage($pagename);
143 $rev = $page->getCurrentRevision();
144 $version = $current->getVersion();
145 return (double)$version;
147 // require 'change' or 'view' access ?
148 function getPageMeta($pagename,$credentials=false) {
150 checkCredentials($server,$credentials,'view',$pagename);
151 $dbi = WikiDB::open($GLOBALS['DBParams']);
152 $page = $dbi->getPage($pagename);
153 $rev = $page->getCurrentRevision();
155 //todo: reformat the meta hash
158 // require 'view' access to AllPages
159 function getAllPagenames($credentials=false) {
161 checkCredentials($server,$credentials,'view',_("AllPages"));
162 $dbi = WikiDB::open($GLOBALS['DBParams']);
163 $page_iter = $dbi->getAllPages();
165 while ($page = $page_iter->next()) {
166 $pages[] = array('pagename' => $page->_pagename);
170 // require 'view' access
171 function getBacklinks($pagename,$credentials=false) {
173 checkCredentials($server,$credentials,'view',$pagename);
174 $dbi = WikiDB::open($GLOBALS['DBParams']);
175 $backend = &$dbi->_backend;
176 $result = $backend->get_links($pagename);
177 $page_iter = new WikiDB_PageIterator($dbi, $result);
179 while ($page = $page_iter->next()) {
180 $pages[] = array('pagename' => $page->getName());
184 // require 'view' access to TitleSearch
185 function doTitleSearch($s, $credentials=false) {
187 checkCredentials($server,$credentials,'view',_("TitleSearch"));
188 $dbi = WikiDB::open($GLOBALS['DBParams']);
189 $query = new TextSearchQuery($s);
190 $page_iter = $dbi->titleSearch($query);
192 while ($page = $page_iter->next()) {
193 $pages[] = array('pagename' => $page->getName());
197 // require 'view' access to FullTextSearch
198 function doFullTextSearch($s, $credentials=false) {
200 checkCredentials($server,$credentials,'view',_("FullTextSearch"));
201 $dbi = WikiDB::open($GLOBALS['DBParams']);
202 $query = new TextSearchQuery($s);
203 $page_iter = $dbi->fullSearch($query);
205 while ($page = $page_iter->next()) {
206 $pages[] = array('pagename' => $page->getName());
211 // require 'view' access to RecentChanges
212 function getRecentChanges($limit=false, $since=false, $include_minor=false, $credentials=false) {
214 checkCredentials($server,$credentials,'view',_("RecentChanges"));
215 $dbi = WikiDB::open($GLOBALS['DBParams']);
216 $params = array('limit' => $limit, 'since' => $since,
217 'include_minor_revisions' => $include_minor);
218 $page_iter = $dbi->mostRecent($params);
220 while ($page = $page_iter->next()) {
221 $pages[] = array('pagename' => $page->getName(),
222 'lastModified' => $page->get('mtime'),
223 'author' => $page->get('author'),
224 'summary' => $page->get('summary'), // added with 1.3.13
225 'version' => $page->getVersion()
230 // require 'view' access
231 function listLinks($pagename, $credentials=false) {
233 checkCredentials($server,$credentials,'view',$pagename);
234 $dbi = WikiDB::open($GLOBALS['DBParams']);
235 $page = $dbi->getPage($pagename);
236 $linkiterator = $page->getPageLinks();
238 while ($currentpage = $linkiterator->next()) {
239 if ($currentpage->exists())
240 $links[] = array('pagename' => $currentpage->getName());
244 function listPlugins($credentials=false) {
246 checkCredentials($server,$credentials,'change',_("HomePage"));
247 $plugin_dir = 'lib/plugin';
248 if (defined('PHPWIKI_DIR'))
249 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
250 $pd = new fileSet($plugin_dir, '*.php');
251 $plugins = $pd->getFiles();
255 if (!empty($plugins)) {
256 require_once("lib/WikiPlugin.php");
257 $w = new WikiPluginLoader;
258 foreach ($plugins as $plugin) {
259 $pluginName = str_replace(".php", "", $plugin);
260 $p = $w->getPlugin($pluginName, false); // second arg?
261 // trap php files which aren't WikiPlugin~s: wikiplugin + wikiplugin_cached only
262 if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
263 $RetArray[] = $pluginName;
269 function getPluginSynopsis($pluginname, $credentials=false) {
271 checkCredentials($server,$credentials,'change',"Help/".$pluginname."Plugin");
272 require_once("lib/WikiPlugin.php");
273 $w = new WikiPluginLoader;
275 $p = $w->getPlugin($pluginName, false); // second arg?
276 // trap php files which aren't WikiPlugin~s: wikiplugin + wikiplugin_cached only
277 if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
279 $desc = $p->getArgumentsDescription();
280 $src = array("\n",'"',"'",'|','[',']','\\');
281 $replace = array('%0A','%22','%27','%7C','%5B','%5D','%5C');
282 $desc = str_replace("<br />",' ',$desc->asXML());
284 $plugin_args = '\n'.str_replace($src, $replace, $desc);
285 $synopsis = "<?plugin ".$pluginName.$plugin_args."?>"; // args?
289 // only plugins returning pagelists will return something useful. so omit the html output
290 function callPlugin($pluginname, $pluginargs, $credentials=false) {
292 checkCredentials($server,$credentials,'change',"Help/".$pluginname."Plugin");
295 require_once("lib/WikiPlugin.php");
296 $w = new WikiPluginLoader;
297 $p = $w->getPlugin($pluginName, false); // second arg?
298 $pagelist = $p->run($dbi, $pluginargs, $request, $basepage);
300 if (is_object($pagelist) and isa($pagelist, 'PageList')) {
301 foreach ($pagelist->pageNames() as $name)
302 $pages[] = array('pagename' => $name);
307 * array listRelations([ Integer option = 1 ])
309 * Returns an array of all available relation names.
310 * option: 1 relations only ( with 0 also )
311 * option: 2 attributes only
312 * option: 3 both, all names of relations and attributes
313 * option: 4 unsorted, this might be added as bitvalue: 7 = 4+3. default: sorted
314 * For some semanticweb autofill methods.
316 * @author: Reini Urban
318 function listRelations($option = 1, $credentials=false) {
320 checkCredentials($server,$credentials,'view',_("HomePage"));
321 $also_attributes = $option & 2;
322 $only_attributes = $option & 2 and !($option & 1);
323 $sorted = !($option & 4);
324 return $dbh->listRelations($also_attributes,
328 // some basic semantic search
329 function linkSearch($linktype, $search, $pages="*", $relation="*", $credentials=false) {
331 checkCredentials($server,$credentials,'view',_("HomePage"));
332 $dbi = WikiDB::open($GLOBALS['DBParams']);
333 require_once("lib/TextSearchQuery.php");
334 $pagequery = new TextSearchQuery($pages);
335 $linkquery = new TextSearchQuery($search);
336 if ($linktype == 'relation') {
337 $relquery = new TextSearchQuery($relation);
338 $links = $dbi->_backend->link_search($pagequery, $linkquery, $linktype, $relquery);
339 } elseif ($linktype == 'attribute') { // only numeric search withh attributes!
340 $relquery = new TextSearchQuery($relation);
341 require_once("lib/SemanticWeb.php");
342 // search: "population > 1 million and area < 200 km^2" relation="*" pages="*"
343 $linkquery = new SemanticAttributeSearchQuery($search, $relation);
344 $links = $dbi->_backend->link_search($pagequery, $linkquery, $linktype, $relquery);
346 // we already do have forward and backlinks as SOAP
347 $links = $dbi->_backend->link_search($pagequery, $linkquery, $linktype);
349 return $links->asArray();
352 $server->service($GLOBALS['HTTP_RAW_POST_DATA']);
354 // (c-file-style: "gnu")
359 // c-hanging-comment-ender-p: nil
360 // indent-tabs-mode: nil