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 * check native pecl extension
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 require_once('lib/nusoap/nusoap.php');
25 // bypass auth and request loop for now.
26 // require_once('lib/prepend.php');
27 include_once("index.php");
29 //require_once('lib/stdlib.php');
30 require_once('lib/WikiDB.php');
31 require_once('lib/config.php');
32 class WikiRequest extends Request {}
33 $request = new WikiRequest();
34 require_once('lib/PagePerm.php');
35 require_once('lib/WikiUserNew.php');
36 require_once('lib/WikiGroup.php');
39 function checkCredentials(&$server, &$credentials, $access, $pagename) {
40 // check the "Authorization: Basic '.base64_encode("$this->username:$this->password").'\r\n'" header
41 if (isset($server->header['Authorization'])) {
42 $line = base64_decode(str_replace("Basic ","",trim($server->header['Authorization'])));
43 list($credentials['username'],$credentials['password']) = explode(':',$line);
46 $_SERVER =& $GLOBALS['HTTP_SERVER_VARS'];
47 // TODO: where in the header is the client IP
48 if (!isset($credentials['username'])) {
49 if (isset($_SERVER['REMOTE_ADDR']))
50 $credentials['username'] = $_SERVER['REMOTE_ADDR'];
51 elseif (isset($GLOBALS['REMOTE_ADDR']))
52 $credentials['username'] = $GLOBALS['REMOTE_ADDR'];
54 $credentials['username'] = $server->host;
57 if (!isset($credentials['password'])) $credentials['password'] = '';
59 //Fixme: set the GLOBALS['request']->_user object
60 if (!mayAccessPage ($access,$pagename))
61 $server->fault(401,'',"no permission");
64 $GLOBALS['SERVER_NAME'] = SERVER_URL;
65 $GLOBALS['SCRIPT_NAME'] = DATA_PATH . "/SOAP.php";
66 $url = SERVER_URL . DATA_PATH . "/SOAP.php";
68 // Local or external wdsl support is experimental.
69 // It works without also. Just the client has to
70 // know the wdsl definitions.
71 $server = new soap_server(/* 'PhpWiki.wdsl' */);
72 // Now change the server url to ours, because in the wdsl is the original PhpWiki address
73 // <soap:address location="http://phpwiki.sourceforge.net/phpwiki/SOAP.php"/>
74 // <soap:operation soapAction="http://phpwiki.sourceforge.net/phpwiki/SOAP.php" />
76 $server->ports[$server->currentPort]['location'] = $url;
77 $server->bindings[ $server->ports[$server->currentPort]['binding'] ]['endpoint'] = $url;
78 $server->soapaction = $url; // soap_transport_http
81 $actions = array('getPageContent','getPageRevision','getCurrentRevision',
82 'getPageMeta','doSavePage','getAllPagenames',
83 'getBackLinks','doTitleSearch','doFullTextSearch');
84 foreach ($actions as $action) {
85 $server->register($actions);
86 $server->operations[$actions]['soapaction'] = $url;
89 //todo: check and set credentials
90 // requiredAuthorityForPage($action);
91 // require 'edit' access
92 function doSavePage($pagename,$content,$credentials=false) {
93 checkCredentials($server,$credentials,'edit',$pagename);
94 $dbi = WikiDB::open($GLOBALS['DBParams']);
95 $page = $dbi->getPage($pagename);
96 $current = $page->getCurrentRevision();
97 $meta = $current->_data;
98 $meta['summary'] = sprintf(_("SOAP Request %s", $credentials['username'])); // from user or IP ?
99 $version = $current->getVersion();
100 return $page->save($content, $version + 1, $meta);
103 // require 'view' access
104 function getPageContent($pagename,$credentials=false) {
105 checkCredentials($server,$credentials,'view',$pagename);
106 $dbi = WikiDB::open($GLOBALS['DBParams']);
107 $page = $dbi->getPage($pagename);
108 $rev = $page->getCurrentRevision();
109 $text = $rev->getPackedContent();
112 // require 'view' access
113 function getPageRevision($pagename,$revision,$credentials=false) {
114 checkCredentials($server,$credentials,'view',$pagename);
115 $dbi = WikiDB::open($GLOBALS['DBParams']);
116 $page = $dbi->getPage($pagename);
117 $rev = $page->getCurrentRevision();
118 $text = $rev->getPackedContent();
121 // require 'view' access
122 function getCurrentRevision($pagename,$credentials=false) {
123 checkCredentials($server,$credentials,'view',$pagename);
124 if (!mayAccessPage ('view',$pagename))
125 $server->fault(401,'',"no permission");
126 $dbi = WikiDB::open($GLOBALS['DBParams']);
127 $page = $dbi->getPage($pagename);
128 $rev = $page->getCurrentRevision();
129 $version = $current->getVersion();
130 return (double)$version;
132 // require 'change' or 'view' access ?
133 function getPageMeta($pagename,$credentials=false) {
134 checkCredentials($server,$credentials,'view',$pagename);
135 $dbi = WikiDB::open($GLOBALS['DBParams']);
136 $page = $dbi->getPage($pagename);
137 $rev = $page->getCurrentRevision();
139 //todo: reformat the meta hash
142 // require 'view' access to AllPages
143 function getAllPagenames($credentials=false) {
144 checkCredentials($server,$credentials,'view',_("AllPages"));
145 $dbi = WikiDB::open($GLOBALS['DBParams']);
146 $page_iter = $dbi->getAllPages();
148 while ($page = $page_iter->next()) {
149 $pages[] = array('pagename' => $page->_pagename);
153 // require 'view' access
154 function getBacklinks($pagename,$credentials=false) {
155 checkCredentials($server,$credentials,'view',$pagename);
156 $dbi = WikiDB::open($GLOBALS['DBParams']);
157 $backend = &$dbi->_backend;
158 $result = $backend->get_links($pagename);
159 $page_iter = new WikiDB_PageIterator($dbi, $result);
161 while ($page = $page_iter->next()) {
162 $pages[] = array('pagename' => $page->getName());
166 // require 'view' access to TitleSearch
167 function doTitleSearch($s, $credentials=false) {
168 checkCredentials($server,$credentials,'view',_("TitleSearch"));
169 $dbi = WikiDB::open($GLOBALS['DBParams']);
170 $query = new TextSearchQuery($s);
171 $page_iter = $dbi->titleSearch($query);
173 while ($page = $page_iter->next()) {
174 $pages[] = array('pagename' => $page->getName());
178 // require 'view' access to FullTextSearch
179 function doFullTextSearch($s, $credentials=false) {
180 checkCredentials($server,$credentials,'view',_("FullTextSearch"));
181 $dbi = WikiDB::open($GLOBALS['DBParams']);
182 $query = new TextSearchQuery($s);
183 $page_iter = $dbi->fullSearch($query);
185 while ($page = $page_iter->next()) {
186 $pages[] = array('pagename' => $page->getName());
191 $server->service($GLOBALS['HTTP_RAW_POST_DATA']);
193 // (c-file-style: "gnu")
198 // c-hanging-comment-ender-p: nil
199 // indent-tabs-mode: nil