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
12 * Installer helper which changes server url of the default PhpWiki.wdsl
13 * Or do it dynamically in the soap class? No, the client must connect to us.
15 * @author: Reini Urban
17 define ("WIKI_SOAP", "true");
19 include_once("my-index.php");
20 include_once("lib/main.php");
21 require_once('lib/nusoap/nusoap.php');
24 // bypass auth and request loop for now.
25 // require_once('lib/prepend.php');
26 include_once("index.php");
28 //require_once('lib/stdlib.php');
29 require_once('lib/WikiDB.php');
30 require_once('lib/config.php');
31 class WikiRequest extends Request {}
32 $request = new WikiRequest();
33 require_once('lib/PagePerm.php');
34 require_once('lib/WikiUserNew.php');
35 require_once('lib/WikiGroup.php');
38 function checkCredentials(&$server, &$credentials, $access, $pagename) {
39 // check the "Authorization: Basic '.base64_encode("$this->username:$this->password").'\r\n'" header
40 if (isset($server->header['Authorization'])) {
41 $line = base64_decode(str_replace("Basic ","",trim($server->header['Authorization'])));
42 list($credentials['username'],$credentials['password']) = explode(':',$line);
44 // TODO: where in the header is the client IP
45 if (!isset($credentials['username'])) {
46 if (isset($_SERVER['REMOTE_ADDR']))
47 $credentials['username'] = $_SERVER['REMOTE_ADDR'];
48 elseif (isset($GLOBALS['REMOTE_ADDR']))
49 $credentials['username'] = $GLOBALS['REMOTE_ADDR'];
51 $credentials['username'] = $server->host;
54 if (!isset($credentials['password'])) $credentials['password'] = '';
56 //Fixme: set the GLOBALS['request']->_user object
57 if (!mayAccessPage ($access,$pagename))
58 $server->fault(401,'',"no permission");
61 $GLOBALS['SERVER_NAME'] = SERVER_URL;
62 $GLOBALS['SCRIPT_NAME'] = DATA_PATH . "/SOAP.php";
63 $url = SERVER_URL . DATA_PATH . "/SOAP.php";
65 // Local or external wdsl support is experimental.
66 // It works without also. Just the client has to
67 // know the wdsl definitions.
68 $server = new soap_server(/* 'PhpWiki.wdsl' */);
69 // Now change the server url to ours, because in the wdsl is the original PhpWiki address
70 // <soap:address location="http://phpwiki.sourceforge.net/phpwiki/SOAP.php"/>
71 // <soap:operation soapAction="http://phpwiki.sourceforge.net/phpwiki/SOAP.php" />
73 $server->ports[$server->currentPort]['location'] = $url;
74 $server->bindings[ $server->ports[$server->currentPort]['binding'] ]['endpoint'] = $url;
75 $server->soapaction = $url; // soap_transport_http
78 $actions = array('getPageContent','getPageRevision','getCurrentRevision',
79 'getPageMeta','doSavePage','getAllPagenames',
80 'getBackLinks','doTitleSearch','doFullTextSearch');
81 foreach ($actions as $action) {
82 $server->register($actions);
83 $server->operations[$actions]['soapaction'] = $url;
86 //todo: check and set credentials
87 // requiredAuthorityForPage($action);
88 // require 'edit' access
89 function doSavePage($pagename,$content,$credentials=false) {
90 checkCredentials(&$server,&$credentials,'edit',$pagename);
91 $dbi = WikiDB::open($GLOBALS['DBParams']);
92 $page = $dbi->getPage($pagename);
93 $current = $page->getCurrentRevision();
94 $meta = $current->_data;
95 $meta['summary'] = sprintf(_("SOAP Request %s", $credentials['username'])); // from user or IP ?
96 $version = $current->getVersion();
97 return $page->save($content, $version + 1, $meta);
100 // require 'view' access
101 function getPageContent($pagename,$credentials=false) {
102 checkCredentials(&$server,&$credentials,'view',$pagename);
103 $dbi = WikiDB::open($GLOBALS['DBParams']);
104 $page = $dbi->getPage($pagename);
105 $rev = $page->getCurrentRevision();
106 $text = $rev->getPackedContent();
109 // require 'view' access
110 function getPageRevision($pagename,$revision,$credentials=false) {
111 checkCredentials(&$server,&$credentials,'view',$pagename);
112 $dbi = WikiDB::open($GLOBALS['DBParams']);
113 $page = $dbi->getPage($pagename);
114 $rev = $page->getCurrentRevision();
115 $text = $rev->getPackedContent();
118 // require 'view' access
119 function getCurrentRevision($pagename,$credentials=false) {
120 checkCredentials(&$server,&$credentials,'view',$pagename);
121 if (!mayAccessPage ('view',$pagename))
122 $server->fault(401,'',"no permission");
123 $dbi = WikiDB::open($GLOBALS['DBParams']);
124 $page = $dbi->getPage($pagename);
125 $rev = $page->getCurrentRevision();
126 $version = $current->getVersion();
127 return (double)$version;
129 // require 'change' or 'view' access ?
130 function getPageMeta($pagename,$credentials=false) {
131 checkCredentials(&$server,&$credentials,'view',$pagename);
132 $dbi = WikiDB::open($GLOBALS['DBParams']);
133 $page = $dbi->getPage($pagename);
134 $rev = $page->getCurrentRevision();
136 //todo: reformat the meta hash
139 // require 'view' access to AllPages
140 function getAllPagenames($credentials=false) {
141 checkCredentials(&$server,&$credentials,'view',_("AllPages"));
142 $dbi = WikiDB::open($GLOBALS['DBParams']);
143 $page_iter = $dbi->getAllPages();
145 while ($page = $page_iter->next()) {
146 $pages[] = array('pagename' => $page->_pagename);
150 // require 'view' access
151 function getBacklinks($pagename,$credentials=false) {
152 checkCredentials(&$server,&$credentials,'view',$pagename);
153 $dbi = WikiDB::open($GLOBALS['DBParams']);
154 $backend = &$dbi->_backend;
155 $result = $backend->get_links($pagename);
156 $page_iter = new WikiDB_PageIterator($dbi, $result);
158 while ($page = $page_iter->next()) {
159 $pages[] = array('pagename' => $page->_pagename);
163 // require 'view' access to TitleSearch
164 function doTitleSearch($query,$credentials=false) {
165 checkCredentials(&$server,&$credentials,'view',_("TitleSearch"));
166 $dbi = WikiDB::open($GLOBALS['DBParams']);
167 $page_iter = $dbi->titleSearch($query);
169 while ($page = $page_iter->next()) {
170 $pages[] = array('pagename' => $page->_pagename);
174 // require 'view' access to FullTextSearch
175 function doFullTextSearch($query,$credentials=false) {
176 checkCredentials(&$server,&$credentials,'view',_("FullTextSearch"));
177 $dbi = WikiDB::open($GLOBALS['DBParams']);
178 $page_iter = $dbi->fullSearch($query);
180 while ($page = $page_iter->next()) {
181 $pages[] = array('pagename' => $page->_pagename);
186 $server->service($GLOBALS['HTTP_RAW_POST_DATA']);
188 // (c-file-style: "gnu")
193 // c-hanging-comment-ender-p: nil
194 // indent-tabs-mode: nil