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("./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);
45 $_SERVER =& $GLOBALS['HTTP_SERVER_VARS'];
46 // TODO: where in the header is the client IP
47 if (!isset($credentials['username'])) {
48 if (isset($_SERVER['REMOTE_ADDR']))
49 $credentials['username'] = $_SERVER['REMOTE_ADDR'];
50 elseif (isset($GLOBALS['REMOTE_ADDR']))
51 $credentials['username'] = $GLOBALS['REMOTE_ADDR'];
53 $credentials['username'] = $server->host;
56 if (!isset($credentials['password'])) $credentials['password'] = '';
58 //Fixme: set the GLOBALS['request']->_user object
59 if (!mayAccessPage ($access,$pagename))
60 $server->fault(401,'',"no permission");
63 $GLOBALS['SERVER_NAME'] = SERVER_URL;
64 $GLOBALS['SCRIPT_NAME'] = DATA_PATH . "/SOAP.php";
65 $url = SERVER_URL . DATA_PATH . "/SOAP.php";
67 // Local or external wdsl support is experimental.
68 // It works without also. Just the client has to
69 // know the wdsl definitions.
70 $server = new soap_server(/* 'PhpWiki.wdsl' */);
71 // Now change the server url to ours, because in the wdsl is the original PhpWiki address
72 // <soap:address location="http://phpwiki.sourceforge.net/phpwiki/SOAP.php"/>
73 // <soap:operation soapAction="http://phpwiki.sourceforge.net/phpwiki/SOAP.php" />
75 $server->ports[$server->currentPort]['location'] = $url;
76 $server->bindings[ $server->ports[$server->currentPort]['binding'] ]['endpoint'] = $url;
77 $server->soapaction = $url; // soap_transport_http
80 $actions = array('getPageContent','getPageRevision','getCurrentRevision',
81 'getPageMeta','doSavePage','getAllPagenames',
82 'getBackLinks','doTitleSearch','doFullTextSearch');
83 foreach ($actions as $action) {
84 $server->register($actions);
85 $server->operations[$actions]['soapaction'] = $url;
88 //todo: check and set credentials
89 // requiredAuthorityForPage($action);
90 // require 'edit' access
91 function doSavePage($pagename,$content,$credentials=false) {
92 checkCredentials($server,$credentials,'edit',$pagename);
93 $dbi = WikiDB::open($GLOBALS['DBParams']);
94 $page = $dbi->getPage($pagename);
95 $current = $page->getCurrentRevision();
96 $meta = $current->_data;
97 $meta['summary'] = sprintf(_("SOAP Request %s", $credentials['username'])); // from user or IP ?
98 $version = $current->getVersion();
99 return $page->save($content, $version + 1, $meta);
102 // require 'view' access
103 function getPageContent($pagename,$credentials=false) {
104 checkCredentials($server,$credentials,'view',$pagename);
105 $dbi = WikiDB::open($GLOBALS['DBParams']);
106 $page = $dbi->getPage($pagename);
107 $rev = $page->getCurrentRevision();
108 $text = $rev->getPackedContent();
111 // require 'view' access
112 function getPageRevision($pagename,$revision,$credentials=false) {
113 checkCredentials($server,$credentials,'view',$pagename);
114 $dbi = WikiDB::open($GLOBALS['DBParams']);
115 $page = $dbi->getPage($pagename);
116 $rev = $page->getCurrentRevision();
117 $text = $rev->getPackedContent();
120 // require 'view' access
121 function getCurrentRevision($pagename,$credentials=false) {
122 checkCredentials($server,$credentials,'view',$pagename);
123 if (!mayAccessPage ('view',$pagename))
124 $server->fault(401,'',"no permission");
125 $dbi = WikiDB::open($GLOBALS['DBParams']);
126 $page = $dbi->getPage($pagename);
127 $rev = $page->getCurrentRevision();
128 $version = $current->getVersion();
129 return (double)$version;
131 // require 'change' or 'view' access ?
132 function getPageMeta($pagename,$credentials=false) {
133 checkCredentials($server,$credentials,'view',$pagename);
134 $dbi = WikiDB::open($GLOBALS['DBParams']);
135 $page = $dbi->getPage($pagename);
136 $rev = $page->getCurrentRevision();
138 //todo: reformat the meta hash
141 // require 'view' access to AllPages
142 function getAllPagenames($credentials=false) {
143 checkCredentials($server,$credentials,'view',_("AllPages"));
144 $dbi = WikiDB::open($GLOBALS['DBParams']);
145 $page_iter = $dbi->getAllPages();
147 while ($page = $page_iter->next()) {
148 $pages[] = array('pagename' => $page->_pagename);
152 // require 'view' access
153 function getBacklinks($pagename,$credentials=false) {
154 checkCredentials($server,$credentials,'view',$pagename);
155 $dbi = WikiDB::open($GLOBALS['DBParams']);
156 $backend = &$dbi->_backend;
157 $result = $backend->get_links($pagename);
158 $page_iter = new WikiDB_PageIterator($dbi, $result);
160 while ($page = $page_iter->next()) {
161 $pages[] = array('pagename' => $page->_pagename);
165 // require 'view' access to TitleSearch
166 function doTitleSearch($query,$credentials=false) {
167 checkCredentials($server,$credentials,'view',_("TitleSearch"));
168 $dbi = WikiDB::open($GLOBALS['DBParams']);
169 $page_iter = $dbi->titleSearch($query);
171 while ($page = $page_iter->next()) {
172 $pages[] = array('pagename' => $page->_pagename);
176 // require 'view' access to FullTextSearch
177 function doFullTextSearch($query,$credentials=false) {
178 checkCredentials($server,$credentials,'view',_("FullTextSearch"));
179 $dbi = WikiDB::open($GLOBALS['DBParams']);
180 $page_iter = $dbi->fullSearch($query);
182 while ($page = $page_iter->next()) {
183 $pages[] = array('pagename' => $page->_pagename);
188 $server->service($GLOBALS['HTTP_RAW_POST_DATA']);
190 // (c-file-style: "gnu")
195 // c-hanging-comment-ender-p: nil
196 // indent-tabs-mode: nil