]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - SOAP.php
rewording, php-4.0.6 fixes, Log removed from index.php
[SourceForge/phpwiki.git] / SOAP.php
1 <?php
2 /**
3  * SOAP server
4  * Taken from http://www.wlug.org.nz/archive/
5  * Please see http://phpwiki.sourceforge.net/phpwiki/PhpWiki.wdsl
6  * for the wdsl discussion.
7  *
8  * Todo: 
9  * checkCredentials: set the $GLOBALS['request']->_user object for 
10  *                   mayAccessPage
11  * serverurl: 
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.
14  *
15  * @author: Reini Urban
16  */
17 define ("WIKI_SOAP", "true");
18
19 include_once("./index.php");
20 include_once("lib/main.php");
21 require_once('lib/nusoap/nusoap.php');
22
23 /*
24 // bypass auth and request loop for now.
25 // require_once('lib/prepend.php');
26 include_once("index.php");
27
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');
36 */
37
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);
43     } else {
44         if (!isset($_SERVER))
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'];
52             else 
53                 $credentials['username'] = $server->host;
54         }
55     }
56     if (!isset($credentials['password'])) $credentials['password'] = '';
57
58     //Fixme: set the GLOBALS['request']->_user object
59     if (!mayAccessPage ($access,$pagename))
60         $server->fault(401,'',"no permission");
61 }
62
63 $GLOBALS['SERVER_NAME'] = SERVER_URL;
64 $GLOBALS['SCRIPT_NAME'] = DATA_PATH . "/SOAP.php";
65 $url = SERVER_URL . DATA_PATH . "/SOAP.php";
66
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" />
74 /*
75 $server->ports[$server->currentPort]['location'] = $url;
76 $server->bindings[ $server->ports[$server->currentPort]['binding'] ]['endpoint'] = $url;
77 $server->soapaction = $url; // soap_transport_http
78 */
79
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;
86 }
87
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);
100 }
101
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();
109     return $text;
110 }
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();
118     return $text;
119 }
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;
130 }
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();
137     $meta = $rev->_data;
138     //todo: reformat the meta hash
139     return $meta;
140 }
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();
146     $pages = array();
147     while ($page = $page_iter->next()) {
148         $pages[] = array('pagename' => $page->_pagename);
149     }
150     return $pages;
151 }
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);
159     $pages = array();
160     while ($page = $page_iter->next()) {
161         $pages[] = array('pagename' => $page->_pagename);
162     }
163     return $pages;
164 }
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);
170     $pages = array();
171     while ($page = $page_iter->next()) {
172         $pages[] = array('pagename' => $page->_pagename);
173     }
174     return $pages;
175 }
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);
181     $pages = array();
182     while ($page = $page_iter->next()) {
183         $pages[] = array('pagename' => $page->_pagename);
184     }
185     return $pages;
186 }
187
188 $server->service($GLOBALS['HTTP_RAW_POST_DATA']);
189
190 // (c-file-style: "gnu")
191 // Local Variables:
192 // mode: php
193 // tab-width: 8
194 // c-basic-offset: 4
195 // c-hanging-comment-ender-p: nil
196 // indent-tabs-mode: nil
197 // End:   
198 ?>