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 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'] = '';
60 if (ENABLE_USER_NEW) {
61 $request->_user = WikiUser($credentials['username']);
63 $request->_user = new WikiUser($request, $credentials['username']);
65 $request->_user->AuthCheck(array('userid' => $credentials['username'], 'passwd' => $credentials['password']));
67 if (! mayAccessPage ($access, $pagename))
68 $server->fault(401,'',"no permission");
71 $GLOBALS['SERVER_NAME'] = SERVER_URL;
72 $GLOBALS['SCRIPT_NAME'] = DATA_PATH . "/SOAP.php";
73 $url = SERVER_URL . DATA_PATH . "/SOAP.php";
75 // Local or external wdsl support is experimental.
76 // It works without also. Just the client has to
77 // know the wdsl definitions.
78 $server = new soap_server(/* 'PhpWiki.wdsl' */);
79 // Now change the server url to ours, because in the wdsl is the original PhpWiki address
80 // <soap:address location="http://phpwiki.sourceforge.net/phpwiki/SOAP.php"/>
81 // <soap:operation soapAction="http://phpwiki.sourceforge.net/phpwiki/SOAP.php" />
83 $server->ports[$server->currentPort]['location'] = $url;
84 $server->bindings[ $server->ports[$server->currentPort]['binding'] ]['endpoint'] = $url;
85 $server->soapaction = $url; // soap_transport_http
88 $actions = array('getPageContent','getPageRevision','getCurrentRevision',
89 'getPageMeta','doSavePage','getAllPagenames',
90 'getBackLinks','doTitleSearch','doFullTextSearch');
91 foreach ($actions as $action) {
92 $server->register($actions);
93 $server->operations[$actions]['soapaction'] = $url;
96 //todo: check and set credentials
97 // requiredAuthorityForPage($action);
98 // require 'edit' access
99 function doSavePage($pagename,$content,$credentials=false) {
101 checkCredentials($server, $credentials,'edit',$pagename);
102 $dbi = WikiDB::open($GLOBALS['DBParams']);
103 $page = $dbi->getPage($pagename);
104 $current = $page->getCurrentRevision();
105 $meta = $current->_data;
106 $meta['summary'] = sprintf(_("SOAP Request %s", $credentials['username'])); // from user or IP ?
107 $version = $current->getVersion();
108 return $page->save($content, $version + 1, $meta);
111 // require 'view' access
112 function getPageContent($pagename,$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 getPageRevision($pagename,$revision,$credentials=false) {
124 checkCredentials($server,$credentials,'view',$pagename);
125 $dbi = WikiDB::open($GLOBALS['DBParams']);
126 $page = $dbi->getPage($pagename);
127 $rev = $page->getCurrentRevision();
128 $text = $rev->getPackedContent();
131 // require 'view' access
132 function getCurrentRevision($pagename,$credentials=false) {
134 checkCredentials($server,$credentials,'view',$pagename);
135 if (!mayAccessPage ('view',$pagename))
136 $server->fault(401,'',"no permission");
137 $dbi = WikiDB::open($GLOBALS['DBParams']);
138 $page = $dbi->getPage($pagename);
139 $rev = $page->getCurrentRevision();
140 $version = $current->getVersion();
141 return (double)$version;
143 // require 'change' or 'view' access ?
144 function getPageMeta($pagename,$credentials=false) {
146 checkCredentials($server,$credentials,'view',$pagename);
147 $dbi = WikiDB::open($GLOBALS['DBParams']);
148 $page = $dbi->getPage($pagename);
149 $rev = $page->getCurrentRevision();
151 //todo: reformat the meta hash
154 // require 'view' access to AllPages
155 function getAllPagenames($credentials=false) {
157 checkCredentials($server,$credentials,'view',_("AllPages"));
158 $dbi = WikiDB::open($GLOBALS['DBParams']);
159 $page_iter = $dbi->getAllPages();
161 while ($page = $page_iter->next()) {
162 $pages[] = array('pagename' => $page->_pagename);
166 // require 'view' access
167 function getBacklinks($pagename,$credentials=false) {
169 checkCredentials($server,$credentials,'view',$pagename);
170 $dbi = WikiDB::open($GLOBALS['DBParams']);
171 $backend = &$dbi->_backend;
172 $result = $backend->get_links($pagename);
173 $page_iter = new WikiDB_PageIterator($dbi, $result);
175 while ($page = $page_iter->next()) {
176 $pages[] = array('pagename' => $page->getName());
180 // require 'view' access to TitleSearch
181 function doTitleSearch($s, $credentials=false) {
183 checkCredentials($server,$credentials,'view',_("TitleSearch"));
184 $dbi = WikiDB::open($GLOBALS['DBParams']);
185 $query = new TextSearchQuery($s);
186 $page_iter = $dbi->titleSearch($query);
188 while ($page = $page_iter->next()) {
189 $pages[] = array('pagename' => $page->getName());
193 // require 'view' access to FullTextSearch
194 function doFullTextSearch($s, $credentials=false) {
196 checkCredentials($server,$credentials,'view',_("FullTextSearch"));
197 $dbi = WikiDB::open($GLOBALS['DBParams']);
198 $query = new TextSearchQuery($s);
199 $page_iter = $dbi->fullSearch($query);
201 while ($page = $page_iter->next()) {
202 $pages[] = array('pagename' => $page->getName());
207 $server->service($GLOBALS['HTTP_RAW_POST_DATA']);
209 // (c-file-style: "gnu")
214 // c-hanging-comment-ender-p: nil
215 // indent-tabs-mode: nil