From 5446f3ffde77013d4eaea1fb166bcbd905a777a4 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sat, 22 Oct 2011 16:01:07 +0200 Subject: use correct phpdoc @return tag. --- inc/auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/auth.php b/inc/auth.php index eff984b36..a52c14731 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -422,7 +422,7 @@ function auth_isadmin($user=null,$groups=null){ * @param $memberlist string commaseparated list of allowed users and groups * @param $user string user to match against * @param $groups array groups the user is member of - * @returns bool true for membership acknowledged + * @return bool true for membership acknowledged */ function auth_isMember($memberlist,$user,array $groups){ global $auth; -- cgit v1.2.3 From a4e0e797f6bce4aaabf4e115a277db8c9a1fa285 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sat, 19 Nov 2011 14:40:11 +0100 Subject: enabled remote as plugintype --- inc/init.php | 2 +- inc/load.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/init.php b/inc/init.php index b3acf2e33..ba62fe079 100644 --- a/inc/init.php +++ b/inc/init.php @@ -200,7 +200,7 @@ init_paths(); init_files(); // setup plugin controller class (can be overwritten in preload.php) -$plugin_types = array('admin','syntax','action','renderer', 'helper'); +$plugin_types = array('admin','syntax','action','renderer', 'helper','remote'); global $plugin_controller_class, $plugin_controller; if (empty($plugin_controller_class)) $plugin_controller_class = 'Doku_Plugin_Controller'; diff --git a/inc/load.php b/inc/load.php index d30397f6e..b69d58140 100644 --- a/inc/load.php +++ b/inc/load.php @@ -89,7 +89,7 @@ function load_autoload($name){ } // Plugin loading - if(preg_match('/^(helper|syntax|action|admin|renderer)_plugin_([^_]+)(?:_([^_]+))?$/', + if(preg_match('/^(helper|syntax|action|admin|renderer|remote)_plugin_([^_]+)(?:_([^_]+))?$/', $name, $m)) { //try to load the wanted plugin file // include, but be silent. Maybe some other autoloader has an idea -- cgit v1.2.3 From 1017f6f159386699a10d2529c50fb5e28b5c1889 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sat, 19 Nov 2011 14:40:29 +0100 Subject: begin with remote api --- inc/remote.php | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 inc/remote.php (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php new file mode 100644 index 000000000..ea5e23af3 --- /dev/null +++ b/inc/remote.php @@ -0,0 +1,120 @@ + array( + * 'args' => array( + * 'type' => 'string|int|...', + * ) + * ) + * ) + * + * plugin names are formed the following: + * core methods begin by a 'dokuwiki' or 'wiki' followed by a . and the method name itself. + * i.e.: dokuwiki.version or wiki.getPage + * + * plugin methods are formed like 'plugin..'. + * i.e.: plugin.clock.getTime or plugin.clock_gmt.getTime + * + * + * + * @throws RemoteException + */ +class RemoteAPI { + + /** + * @var array remote methods provided by dokuwiki. + */ + private $coreMethods = array(); + + /** + * @var array remote methods provided by dokuwiki plugins - will be filled lazy via + * {@see RemoteAPI#getPluginMethods} + */ + private $pluginMethods = null; + + /** + * Get all available methods with remote access. + * + * @return array with information to all available methods + */ + public function getMethods() { + $this->forceAccess(); + return array_merge($this->getCoreMethods(), $this->getPluginMethods()); + } + + /** + * call a method via remote api. + * + * @param string $method name of the method to call. + * @param array $args arguments to pass to the given method + * @return mixed result of method call, must be a primitive type. + */ + public function call($method, $args) { + $this->forceAccess(); + $method = explode('.', $method); + if ($method[0] === 'plugin') { + $plugin = plugin_load('remote', $method[1]); + if (!$plugin) { + throw new RemoteException('Method unavailable'); + } + return call_user_func_array(array($plugin, $method[2]), $args); + } else { + // TODO call core method + } + + } + + /** + * @return bool true if the current user has access to remote api. + */ + public function hasAccess() { + global $conf; + if (!isset($conf['remote'])) { + return false; + } + return $conf['remote']; + } + + /** + * @throws RemoteException On denied access. + * @return void + */ + private function forceAccess() { + if (!$this->hasAccess()) { + throw new RemoteException('Access denied'); + } + } + + /** + * @return array all plugin methods. + */ + public function getPluginMethods() { + if ($this->pluginMethods === null) { + // TODO: find plugin methods + $this->pluginMethods = array(); + } + return $this->pluginMethods; + } + + /** + * @return array all core methods. + */ + public function getCoreMethods() { + return $this->coreMethods; + } +} + + +class RemoteException extends Exception {} \ No newline at end of file -- cgit v1.2.3 From 457ad80ad7c53870fc033997bfbf36e3904f9c4e Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 23 Nov 2011 20:25:58 +0100 Subject: introduced remote api class --- inc/load.php | 2 ++ inc/remote.php | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/load.php b/inc/load.php index b69d58140..3f1f3429f 100644 --- a/inc/load.php +++ b/inc/load.php @@ -76,10 +76,12 @@ function load_autoload($name){ 'SafeFN' => DOKU_INC.'inc/SafeFN.class.php', 'Sitemapper' => DOKU_INC.'inc/Sitemapper.php', 'PassHash' => DOKU_INC.'inc/PassHash.class.php', + 'RemoteAPI' => DOKU_INC.'inc/remote.php', 'DokuWiki_Action_Plugin' => DOKU_PLUGIN.'action.php', 'DokuWiki_Admin_Plugin' => DOKU_PLUGIN.'admin.php', 'DokuWiki_Syntax_Plugin' => DOKU_PLUGIN.'syntax.php', + 'DokuWiki_Remote_Plugin' => DOKU_PLUGIN.'remote.php', ); diff --git a/inc/remote.php b/inc/remote.php index ea5e23af3..13a38aa17 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -17,6 +17,7 @@ if (!defined('DOKU_INC')) die(); * 'args' => array( * 'type' => 'string|int|...', * ) + * 'return' => 'type' * ) * ) * @@ -102,8 +103,20 @@ class RemoteAPI { */ public function getPluginMethods() { if ($this->pluginMethods === null) { - // TODO: find plugin methods $this->pluginMethods = array(); + $plugins = plugin_list('remote'); + + foreach ($plugins as $pluginName) { + $plugin = plugin_load('remote', $pluginName); + if (!is_subclass_of($plugin, 'DokuWiki_Remote_Plugin')) { + throw new RemoteException("Plugin $pluginName dose not implement DokuWiki_Remote_Plugin"); + } + + $methods = $plugin->_getMethods(); + foreach ($methods as $method => $meta) { + $this->pluginMethods["plugin.$pluginName.$method"] = $meta; + } + } } return $this->pluginMethods; } -- cgit v1.2.3 From 2d2d9d0f3a410b31d76a2be193fe16b3dbd79096 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Mon, 28 Nov 2011 19:09:48 +0100 Subject: collect remote functions in a class --- inc/RemoteAPICore.php | 617 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 617 insertions(+) create mode 100644 inc/RemoteAPICore.php (limited to 'inc') diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php new file mode 100644 index 000000000..c4324ba29 --- /dev/null +++ b/inc/RemoteAPICore.php @@ -0,0 +1,617 @@ + + * @param string $id file id + * @return media file + */ + function getAttachment($id){ + $id = cleanID($id); + if (auth_quickaclcheck(getNS($id).':*') < AUTH_READ) { + throw new RemoteAccessDenied(); + } + + $file = mediaFN($id); + if (!@ file_exists($file)) { + throw new RemoteException('The requested file does not exist'); + } + + $data = io_readFile($file, false); + $base64 = base64_encode($data); + return $base64; + } + + /** + * Return info about a media file + * + * @author Gina Haeussge + */ + function getAttachmentInfo($id){ + $id = cleanID($id); + $info = array( + 'lastModified' => 0, + 'size' => 0, + ); + + $file = mediaFN($id); + if ((auth_quickaclcheck(getNS($id).':*') >= AUTH_READ) && file_exists($file)){ + $info['lastModified'] = new IXR_Date(filemtime($file)); + $info['size'] = filesize($file); + } + + return $info; + } + + /** + * Return a wiki page rendered to html + */ + function htmlPage($id,$rev=''){ + $id = cleanID($id); + if(auth_quickaclcheck($id) < AUTH_READ){ + throw new RemoteAccessDenied(1, 'You are not allowed to read this page'); + } + return p_wiki_xhtml($id,$rev,false); + } + + /** + * List all pages - we use the indexer list here + */ + function listPages(){ + $list = array(); + $pages = idx_get_indexer()->getPages(); + $pages = array_filter(array_filter($pages,'isVisiblePage'),'page_exists'); + + foreach(array_keys($pages) as $idx) { + $perm = auth_quickaclcheck($pages[$idx]); + if($perm < AUTH_READ) { + continue; + } + $page = array(); + $page['id'] = trim($pages[$idx]); + $page['perms'] = $perm; + $page['size'] = @filesize(wikiFN($pages[$idx])); + $page['lastModified'] = new IXR_Date(@filemtime(wikiFN($pages[$idx]))); + $list[] = $page; + } + + return $list; + } + + /** + * List all pages in the given namespace (and below) + */ + function readNamespace($ns,$opts){ + global $conf; + + if(!is_array($opts)) $opts=array(); + + $ns = cleanID($ns); + $dir = utf8_encodeFN(str_replace(':', '/', $ns)); + $data = array(); + $opts['skipacl'] = 0; // no ACL skipping for XMLRPC + search($data, $conf['datadir'], 'search_allpages', $opts, $dir); + return $data; + } + + /** + * List all pages in the given namespace (and below) + */ + function search($query){ + require_once(DOKU_INC.'inc/fulltext.php'); + + $regex = ''; + $data = ft_pageSearch($query,$regex); + $pages = array(); + + // prepare additional data + $idx = 0; + foreach($data as $id => $score){ + $file = wikiFN($id); + + if($idx < FT_SNIPPET_NUMBER){ + $snippet = ft_snippet($id,$regex); + $idx++; + }else{ + $snippet = ''; + } + + $pages[] = array( + 'id' => $id, + 'score' => $score, + 'rev' => filemtime($file), + 'mtime' => filemtime($file), + 'size' => filesize($file), + 'snippet' => $snippet, + ); + } + return $pages; + } + + /** + * Returns the wiki title. + */ + function getTitle(){ + global $conf; + return $conf['title']; + } + + /** + * List all media files. + * + * Available options are 'recursive' for also including the subnamespaces + * in the listing, and 'pattern' for filtering the returned files against + * a regular expression matching their name. + * + * @author Gina Haeussge + */ + function listAttachments($ns, $options = array()) { + global $conf; + global $lang; + + $ns = cleanID($ns); + + if (!is_array($options)) $options = array(); + $options['skipacl'] = 0; // no ACL skipping for XMLRPC + + + if(auth_quickaclcheck($ns.':*') >= AUTH_READ) { + $dir = utf8_encodeFN(str_replace(':', '/', $ns)); + + $data = array(); + search($data, $conf['mediadir'], 'search_media', $options, $dir); + $len = count($data); + if(!$len) return array(); + + for($i=0; $i<$len; $i++) { + unset($data[$i]['meta']); + $data[$i]['lastModified'] = new IXR_Date($data[$i]['mtime']); + } + return $data; + } else { + throw new RemoteAccessDenied(1, 'You are not allowed to list media files.'); + } + } + + /** + * Return a list of backlinks + */ + function listBackLinks($id){ + return ft_backlinks(cleanID($id)); + } + + /** + * Return some basic data about a page + */ + function pageInfo($id,$rev=''){ + $id = cleanID($id); + if(auth_quickaclcheck($id) < AUTH_READ){ + throw new RemoteAccessDenied(1, 'You are not allowed to read this page'); + } + $file = wikiFN($id,$rev); + $time = @filemtime($file); + if(!$time){ + throw new RemoteException(10, 'The requested page does not exist'); + } + + $info = getRevisionInfo($id, $time, 1024); + + $data = array( + 'name' => $id, + 'lastModified' => new IXR_Date($time), + 'author' => (($info['user']) ? $info['user'] : $info['ip']), + 'version' => $time + ); + + return ($data); + } + + /** + * Save a wiki page + * + * @author Michael Klier + */ + function putPage($id, $text, $params) { + global $TEXT; + global $lang; + global $conf; + + $id = cleanID($id); + $TEXT = cleanText($text); + $sum = $params['sum']; + $minor = $params['minor']; + + if(empty($id)) { + throw new RemoteException(1, 'Empty page ID'); + } + + if(!page_exists($id) && trim($TEXT) == '' ) { + throw new RemoteException(1, 'Refusing to write an empty new wiki page'); + } + + if(auth_quickaclcheck($id) < AUTH_EDIT) { + throw new RemoteAccessDenied(1, 'You are not allowed to edit this page'); + } + + // Check, if page is locked + if(checklock($id)) { + throw new RemoteException(1, 'The page is currently locked'); + } + + // SPAM check + if(checkwordblock()) { + throw new RemoteException(1, 'Positive wordblock check'); + } + + // autoset summary on new pages + if(!page_exists($id) && empty($sum)) { + $sum = $lang['created']; + } + + // autoset summary on deleted pages + if(page_exists($id) && empty($TEXT) && empty($sum)) { + $sum = $lang['deleted']; + } + + lock($id); + + saveWikiText($id,$TEXT,$sum,$minor); + + unlock($id); + + // run the indexer if page wasn't indexed yet + idx_addPage($id); + + return 0; + } + + /** + * Appends text to a wiki page. + */ + function appendPage($id, $text, $params) { + $currentpage = $this->rawPage($id); + if (!is_string($currentpage)) { + return $currentpage; + } + return $this->putPage($id, $currentpage.$text, $params); + } + + /** + * Uploads a file to the wiki. + * + * Michael Klier + */ + function putAttachment($id, $file, $params) { + $id = cleanID($id); + $auth = auth_quickaclcheck(getNS($id).':*'); + + if(!isset($id)) { + throw new RemoteException(1, 'Filename not given.'); + } + + global $conf; + + $ftmp = $conf['tmpdir'] . '/' . md5($id.clientIP()); + + // save temporary file + @unlink($ftmp); + if (preg_match('/^[A-Za-z0-9\+\/]*={0,2}$/', $file) === 1) { + // DEPRECATED: Double-decode file if it still looks like base64 + // after first decoding (which is done by the library) + $file = base64_decode($file); + } + io_saveFile($ftmp, $file); + + $res = media_save(array('name' => $ftmp), $id, $params['ow'], $auth, 'rename'); + if (is_array($res)) { + throw new RemoteException(-$res[1], $res[0]); + } else { + return $res; + } + } + + /** + * Deletes a file from the wiki. + * + * @author Gina Haeussge + */ + function deleteAttachment($id){ + $id = cleanID($id); + $auth = auth_quickaclcheck(getNS($id).':*'); + $res = media_delete($id, $auth); + if ($res & DOKU_MEDIA_DELETED) { + return 0; + } elseif ($res & DOKU_MEDIA_NOT_AUTH) { + throw new RemoteAccessDenied(1, "You don't have permissions to delete files."); + } elseif ($res & DOKU_MEDIA_INUSE) { + throw new RemoteException(1, 'File is still referenced'); + } else { + throw new RemoteException(1, 'Could not delete file'); + } + } + + /** + * Returns the permissions of a given wiki page + */ + function aclCheck($id) { + $id = cleanID($id); + return auth_quickaclcheck($id); + } + + /** + * Lists all links contained in a wiki page + * + * @author Michael Klier + */ + function listLinks($id) { + $id = cleanID($id); + if(auth_quickaclcheck($id) < AUTH_READ){ + throw new RemoteAccessDenied(1, 'You are not allowed to read this page'); + } + $links = array(); + + // resolve page instructions + $ins = p_cached_instructions(wikiFN($id)); + + // instantiate new Renderer - needed for interwiki links + include(DOKU_INC.'inc/parser/xhtml.php'); + $Renderer = new Doku_Renderer_xhtml(); + $Renderer->interwiki = getInterwiki(); + + // parse parse instructions + foreach($ins as $in) { + $link = array(); + switch($in[0]) { + case 'internallink': + $link['type'] = 'local'; + $link['page'] = $in[1][0]; + $link['href'] = wl($in[1][0]); + array_push($links,$link); + break; + case 'externallink': + $link['type'] = 'extern'; + $link['page'] = $in[1][0]; + $link['href'] = $in[1][0]; + array_push($links,$link); + break; + case 'interwikilink': + $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]); + $link['type'] = 'extern'; + $link['page'] = $url; + $link['href'] = $url; + array_push($links,$link); + break; + } + } + + return ($links); + } + + /** + * Returns a list of recent changes since give timestamp + * + * @author Michael Hamann + * @author Michael Klier + */ + function getRecentChanges($timestamp) { + if(strlen($timestamp) != 10) { + throw new RemoteException(20, 'The provided value is not a valid timestamp'); + } + + $recents = getRecentsSince($timestamp); + + $changes = array(); + + foreach ($recents as $recent) { + $change = array(); + $change['name'] = $recent['id']; + $change['lastModified'] = new IXR_Date($recent['date']); + $change['author'] = $recent['user']; + $change['version'] = $recent['date']; + $change['perms'] = $recent['perms']; + $change['size'] = @filesize(wikiFN($recent['id'])); + array_push($changes, $change); + } + + if (!empty($changes)) { + return $changes; + } else { + // in case we still have nothing at this point + return new RemoteException('There are no changes in the specified timeframe'); + } + } + + /** + * Returns a list of recent media changes since give timestamp + * + * @author Michael Hamann + * @author Michael Klier + */ + function getRecentMediaChanges($timestamp) { + if(strlen($timestamp) != 10) + throw new RemoteException(20, 'The provided value is not a valid timestamp'); + + $recents = getRecentsSince($timestamp, null, '', RECENTS_MEDIA_CHANGES); + + $changes = array(); + + foreach ($recents as $recent) { + $change = array(); + $change['name'] = $recent['id']; + $change['lastModified'] = new IXR_Date($recent['date']); + $change['author'] = $recent['user']; + $change['version'] = $recent['date']; + $change['perms'] = $recent['perms']; + $change['size'] = @filesize(mediaFN($recent['id'])); + array_push($changes, $change); + } + + if (!empty($changes)) { + return $changes; + } else { + // in case we still have nothing at this point + throw new RemoteException(30, 'There are no changes in the specified timeframe'); + } + } + + /** + * Returns a list of available revisions of a given wiki page + * + * @author Michael Klier + */ + function pageVersions($id, $first) { + $id = cleanID($id); + if(auth_quickaclcheck($id) < AUTH_READ) { + throw new RemoteAccessDenied(1, 'You are not allowed to read this page'); + } + global $conf; + + $versions = array(); + + if(empty($id)) { + throw new RemoteException(1, 'Empty page ID'); + } + + $revisions = getRevisions($id, $first, $conf['recent']+1); + + if(count($revisions)==0 && $first!=0) { + $first=0; + $revisions = getRevisions($id, $first, $conf['recent']+1); + } + + if(count($revisions)>0 && $first==0) { + array_unshift($revisions, ''); // include current revision + array_pop($revisions); // remove extra log entry + } + + if(count($revisions) > $conf['recent']) { + array_pop($revisions); // remove extra log entry + } + + if(!empty($revisions)) { + foreach($revisions as $rev) { + $file = wikiFN($id,$rev); + $time = @filemtime($file); + // we check if the page actually exists, if this is not the + // case this can lead to less pages being returned than + // specified via $conf['recent'] + if($time){ + $info = getRevisionInfo($id, $time, 1024); + if(!empty($info)) { + $data['user'] = $info['user']; + $data['ip'] = $info['ip']; + $data['type'] = $info['type']; + $data['sum'] = $info['sum']; + $data['modified'] = new IXR_Date($info['date']); + $data['version'] = $info['date']; + array_push($versions, $data); + } + } + } + return $versions; + } else { + return array(); + } + } + + /** + * The version of Wiki RPC API supported + */ + function wiki_RPCVersion(){ + return 2; + } + + + /** + * Locks or unlocks a given batch of pages + * + * Give an associative array with two keys: lock and unlock. Both should contain a + * list of pages to lock or unlock + * + * Returns an associative array with the keys locked, lockfail, unlocked and + * unlockfail, each containing lists of pages. + */ + function setLocks($set){ + $locked = array(); + $lockfail = array(); + $unlocked = array(); + $unlockfail = array(); + + foreach((array) $set['lock'] as $id){ + $id = cleanID($id); + if(auth_quickaclcheck($id) < AUTH_EDIT || checklock($id)){ + $lockfail[] = $id; + }else{ + lock($id); + $locked[] = $id; + } + } + + foreach((array) $set['unlock'] as $id){ + $id = cleanID($id); + if(auth_quickaclcheck($id) < AUTH_EDIT || !unlock($id)){ + $unlockfail[] = $id; + }else{ + $unlocked[] = $id; + } + } + + return array( + 'locked' => $locked, + 'lockfail' => $lockfail, + 'unlocked' => $unlocked, + 'unlockfail' => $unlockfail, + ); + } + + function getAPIVersion(){ + return DOKU_XMLRPC_API_VERSION; + } + + function login($user,$pass){ + global $conf; + global $auth; + if(!$conf['useacl']) return 0; + if(!$auth) return 0; + + @session_start(); // reopen session for login + if($auth->canDo('external')){ + $ok = $auth->trustExternal($user,$pass,false); + }else{ + $evdata = array( + 'user' => $user, + 'password' => $pass, + 'sticky' => false, + 'silent' => true, + ); + $ok = trigger_event('AUTH_LOGIN_CHECK', $evdata, 'auth_login_wrapper'); + } + session_write_close(); // we're done with the session + + return $ok; + } + + +} \ No newline at end of file -- cgit v1.2.3 From f61380cb67f8216ae4c75922511ff5a07fd21ca0 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Mon, 28 Nov 2011 19:06:16 +0100 Subject: introduced first remote test cases --- inc/remote.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index 13a38aa17..6f48d2015 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -92,7 +92,7 @@ class RemoteAPI { * @throws RemoteException On denied access. * @return void */ - private function forceAccess() { + public function forceAccess() { if (!$this->hasAccess()) { throw new RemoteException('Access denied'); } -- cgit v1.2.3 From 3f3bb97fcdd30282632d96a5bb19d2ea61c01504 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Mon, 28 Nov 2011 20:59:49 +0100 Subject: removed dublicated content --- inc/remote.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index 6f48d2015..14f6614f1 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -130,4 +130,5 @@ class RemoteAPI { } -class RemoteException extends Exception {} \ No newline at end of file +class RemoteException extends Exception {} +class RemoteAccessDenied extends RemoteException {} \ No newline at end of file -- cgit v1.2.3 From 4815d222f25c9a31949297223c98cfca7151ae8d Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Thu, 8 Dec 2011 19:57:18 +0100 Subject: RemoteAPI can now handle remote calls. --- inc/RemoteAPICore.php | 43 +++++++++++++++++++++++++++++++- inc/remote.php | 68 +++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 91 insertions(+), 20 deletions(-) (limited to 'inc') diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php index c4324ba29..a2e12c7f1 100644 --- a/inc/RemoteAPICore.php +++ b/inc/RemoteAPICore.php @@ -2,6 +2,47 @@ class RemoteAPICore { + function __getRemoteInfo() { + return array( + 'wiki.getPage' => array( + 'args' => array( + 'id' => array( + 'type' => 'string', + 'doc' => 'wiki page id' + ), + ), + 'return' => 'string', + 'doc' => 'Return a raw wiki page', + 'name' => 'rawPage', + ), + 'wiki.getPageVersion' => array( + 'args' => array( + 'id' => array( + 'type' => 'string', + 'doc' => 'wiki page id' + ), + 'rev' => array( + 'type' => 'int', + 'doc' => 'revision number of the page', + ), + ), + 'name' => 'rawPage', + 'return' => 'string', + 'doc' => 'Return a raw wiki page' + ), + 'wiki.getAttachment' => array( + 'args' => array( + 'type' => 'string', + 'doc' => 'file id', + ), + 'doc' => 'Return a media file', + 'return' => 'file', + 'name' => 'getAttachment', + ), + + ); + } + /** * Return a raw wiki page * @param string $id wiki page id @@ -58,7 +99,7 @@ class RemoteAPICore { $file = mediaFN($id); if ((auth_quickaclcheck(getNS($id).':*') >= AUTH_READ) && file_exists($file)){ - $info['lastModified'] = new IXR_Date(filemtime($file)); + $info['lastModified'] = filemtime($file); $info['size'] = filesize($file); } diff --git a/inc/remote.php b/inc/remote.php index 14f6614f1..5f136a43d 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -2,6 +2,9 @@ if (!defined('DOKU_INC')) die(); +class RemoteException extends Exception {} +class RemoteAccessDenied extends RemoteException {} + /** * This class provides information about remote access to the wiki. * @@ -13,11 +16,16 @@ if (!defined('DOKU_INC')) die(); * == Information structure == * The information about methods will be given in an array with the following structure: * array( - * 'method.name' => array( + * 'method.remoteName' => array( * 'args' => array( - * 'type' => 'string|int|...', + * 'name' => array( + * 'type' => 'string|int|...|date|file', + * ['doc' = 'argument documentation'], + * ), * ) - * 'return' => 'type' + * 'name' => 'method name in class', + * 'return' => 'type', +* ['doc' = 'method documentation'], * ) * ) * @@ -35,9 +43,9 @@ if (!defined('DOKU_INC')) die(); class RemoteAPI { /** - * @var array remote methods provided by dokuwiki. + * @var RemoteAPICore */ - private $coreMethods = array(); + private $coreMethods = null; /** * @var array remote methods provided by dokuwiki plugins - will be filled lazy via @@ -62,19 +70,36 @@ class RemoteAPI { * @param array $args arguments to pass to the given method * @return mixed result of method call, must be a primitive type. */ - public function call($method, $args) { + public function call($method, $args = array()) { $this->forceAccess(); - $method = explode('.', $method); - if ($method[0] === 'plugin') { - $plugin = plugin_load('remote', $method[1]); + list($type, $pluginName, $call) = explode('.', $method, 3); + if ($type === 'plugin') { + $plugin = plugin_load('remote', $pluginName); if (!$plugin) { - throw new RemoteException('Method unavailable'); + throw new RemoteException('Method dose not exists'); } - return call_user_func_array(array($plugin, $method[2]), $args); + return call_user_func_array(array($plugin, $call), $args); } else { - // TODO call core method + $coreMethods = $this->getCoreMethods(); + if (!isset($coreMethods[$method])) { + throw new RemoteException('Method dose not exists'); + } + $this->checkArgumentLength($coreMethods[$method], $args); + return call_user_func_array(array($this->coreMethods, $this->getMethodName($coreMethods, $method)), $args); } + } + private function checkArgumentLength($method, $args) { + if (count($method['args']) < count($args)) { + throw new RemoteException('Method dose not exists - wrong parameter count.'); + } + } + + private function getMethodName($methodMeta, $method) { + if (isset($methodMeta[$method]['name'])) { + return $methodMeta[$method]['name']; + } + return $method; } /** @@ -122,13 +147,18 @@ class RemoteAPI { } /** + * @param RemoteAPICore $apiCore this parameter is used for testing. Here you can pass a non-default RemoteAPICore + * instance. (for mocking) * @return array all core methods. */ - public function getCoreMethods() { - return $this->coreMethods; + public function getCoreMethods($apiCore = null) { + if ($this->coreMethods === null) { + if ($apiCore === null) { + $this->coreMethods = new RemoteAPICore(); + } else { + $this->coreMethods = $apiCore; + } + } + return $this->coreMethods->__getRemoteInfo(); } -} - - -class RemoteException extends Exception {} -class RemoteAccessDenied extends RemoteException {} \ No newline at end of file +} \ No newline at end of file -- cgit v1.2.3 From 647919c9a61d928502b0b45063cc60702d0d310e Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Thu, 8 Dec 2011 20:33:30 +0100 Subject: added remote plugin calls. --- inc/remote.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index 5f136a43d..bc35d525e 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -75,10 +75,12 @@ class RemoteAPI { list($type, $pluginName, $call) = explode('.', $method, 3); if ($type === 'plugin') { $plugin = plugin_load('remote', $pluginName); + $methods = $this->getPluginMethods(); if (!$plugin) { throw new RemoteException('Method dose not exists'); } - return call_user_func_array(array($plugin, $call), $args); + $name = $this->getMethodName($methods, $method); + return call_user_func_array(array($plugin, $name), $args); } else { $coreMethods = $this->getCoreMethods(); if (!isset($coreMethods[$method])) { @@ -99,7 +101,8 @@ class RemoteAPI { if (isset($methodMeta[$method]['name'])) { return $methodMeta[$method]['name']; } - return $method; + $method = explode('.', $method); + return $method[count($method)-1]; } /** -- cgit v1.2.3 From 795114e73f18f06c2b32b433e150cad81da6581f Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sat, 10 Dec 2011 14:05:33 +0100 Subject: changed return types --- inc/remote.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index bc35d525e..7e82b6845 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -5,6 +5,21 @@ if (!defined('DOKU_INC')) die(); class RemoteException extends Exception {} class RemoteAccessDenied extends RemoteException {} +abstract class RemoteDataType { + private $value; + + function __construct($value) { + $this->value = $value; + } + + function getValue() { + return $this->value; + } +} + +class RemoteDate extends RemoteDataType {} +class RemoteFile extends RemoteDataType {} + /** * This class provides information about remote access to the wiki. * -- cgit v1.2.3 From add86630b09f0e91952081112e3fa642ee35e499 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Mon, 12 Dec 2011 17:02:12 +0100 Subject: changed to new Remote Data objects --- inc/RemoteAPICore.php | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'inc') diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php index a2e12c7f1..6b34d257a 100644 --- a/inc/RemoteAPICore.php +++ b/inc/RemoteAPICore.php @@ -81,8 +81,7 @@ class RemoteAPICore { } $data = io_readFile($file, false); - $base64 = base64_encode($data); - return $base64; + return new RemoteFile($data); } /** @@ -134,7 +133,7 @@ class RemoteAPICore { $page['id'] = trim($pages[$idx]); $page['perms'] = $perm; $page['size'] = @filesize(wikiFN($pages[$idx])); - $page['lastModified'] = new IXR_Date(@filemtime(wikiFN($pages[$idx]))); + $page['lastModified'] = new RemoteDate(@filemtime(wikiFN($pages[$idx]))); $list[] = $page; } @@ -181,7 +180,7 @@ class RemoteAPICore { $pages[] = array( 'id' => $id, - 'score' => $score, + 'score' => intval($score), 'rev' => filemtime($file), 'mtime' => filemtime($file), 'size' => filesize($file), @@ -210,7 +209,6 @@ class RemoteAPICore { */ function listAttachments($ns, $options = array()) { global $conf; - global $lang; $ns = cleanID($ns); @@ -228,7 +226,7 @@ class RemoteAPICore { for($i=0; $i<$len; $i++) { unset($data[$i]['meta']); - $data[$i]['lastModified'] = new IXR_Date($data[$i]['mtime']); + $data[$i]['lastModified'] = new RemoteDate($data[$i]['mtime']); } return $data; } else { @@ -261,7 +259,7 @@ class RemoteAPICore { $data = array( 'name' => $id, - 'lastModified' => new IXR_Date($time), + 'lastModified' => new RemoteDate($time), 'author' => (($info['user']) ? $info['user'] : $info['ip']), 'version' => $time ); @@ -344,7 +342,7 @@ class RemoteAPICore { * * Michael Klier */ - function putAttachment($id, $file, $params) { + function putAttachment($id, RemoteFile $file, $params) { $id = cleanID($id); $auth = auth_quickaclcheck(getNS($id).':*'); @@ -358,12 +356,7 @@ class RemoteAPICore { // save temporary file @unlink($ftmp); - if (preg_match('/^[A-Za-z0-9\+\/]*={0,2}$/', $file) === 1) { - // DEPRECATED: Double-decode file if it still looks like base64 - // after first decoding (which is done by the library) - $file = base64_decode($file); - } - io_saveFile($ftmp, $file); + io_saveFile($ftmp, $file->getValue()); $res = media_save(array('name' => $ftmp), $id, $params['ow'], $auth, 'rename'); if (is_array($res)) { @@ -468,7 +461,7 @@ class RemoteAPICore { foreach ($recents as $recent) { $change = array(); $change['name'] = $recent['id']; - $change['lastModified'] = new IXR_Date($recent['date']); + $change['lastModified'] = new RemoteDate($recent['date']); $change['author'] = $recent['user']; $change['version'] = $recent['date']; $change['perms'] = $recent['perms']; @@ -501,7 +494,7 @@ class RemoteAPICore { foreach ($recents as $recent) { $change = array(); $change['name'] = $recent['id']; - $change['lastModified'] = new IXR_Date($recent['date']); + $change['lastModified'] = new RemoteDate($recent['date']); $change['author'] = $recent['user']; $change['version'] = $recent['date']; $change['perms'] = $recent['perms']; @@ -565,7 +558,7 @@ class RemoteAPICore { $data['ip'] = $info['ip']; $data['type'] = $info['type']; $data['sum'] = $info['sum']; - $data['modified'] = new IXR_Date($info['date']); + $data['modified'] = new RemoteDate($info['date']); $data['version'] = $info['date']; array_push($versions, $data); } -- cgit v1.2.3 From 37fa8abdcb4ed0634f9c21c8e6f2d727d1ffd600 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 21 Dec 2011 14:35:48 +0100 Subject: added methods from xmlrpc.php to RemoteAPICore --- inc/RemoteAPICore.php | 174 +++++++++++++++++++++++++++++++++++++++++++------- inc/remote.php | 5 +- 2 files changed, 151 insertions(+), 28 deletions(-) (limited to 'inc') diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php index 6b34d257a..106ed598c 100644 --- a/inc/RemoteAPICore.php +++ b/inc/RemoteAPICore.php @@ -4,40 +4,167 @@ class RemoteAPICore { function __getRemoteInfo() { return array( - 'wiki.getPage' => array( + 'dokuwiki.getVersion' => array( + 'args' => array(), + 'return' => 'string', + 'doc' => 'Returns the running DokuWiki version.' + ), 'dokuwiki.login' => array( + 'args' => array( + 'username' => 'string', + 'password' => 'string' + ), + 'return' => 'int', + 'doc' => 'Tries to login with the given credentials and sets auth cookies.' + ), 'dokuwiki.getPagelist' => array( + 'args' => array( + 'namespace' => 'string', + 'options' => 'array' + ), + 'return' => 'array', + 'doc' => 'List all pages within the given namespace.', + 'name' => 'readNamespace' + ), 'dokuwiki.search' => array( 'args' => array( - 'id' => array( - 'type' => 'string', - 'doc' => 'wiki page id' - ), + 'search' => 'string' ), + 'return' => 'array', + 'doc' => 'Perform a fulltext search and return a list of matching pages' + ), 'dokuwiki.getTime' => array( + 'args' => array(), + 'return' => 'int', + 'doc' => 'Returns the current time at the remote wiki server as Unix timestamp.', + ), 'dokuwiki.setLocks' => array( + 'args' => array('lock' => 'array'), + 'return' => 'array', + 'doc' => 'Lock or unlock pages.' + ), 'dokuwiki.getTitle' => array( + 'args' => array(), 'return' => 'string', - 'doc' => 'Return a raw wiki page', + 'doc' => 'Returns the wiki title.' + ), 'dokuwiki.appendPage' => array( + 'args' => array( + 'pagename' => 'string', + 'rawWikiText' => 'string', + 'attrs' => 'array' + ), + 'return' => 'int', + 'doc' => 'Append text to a wiki page.' + ), 'wiki.getPage' => array( + 'args' => array( + 'id' => 'string' + ), + 'return' => 'string', + 'doc' => 'Get the raw Wiki text of page, latest version.', 'name' => 'rawPage', - ), - 'wiki.getPageVersion' => array( + ), 'wiki.getPageVersion' => array( 'args' => array( - 'id' => array( - 'type' => 'string', - 'doc' => 'wiki page id' - ), - 'rev' => array( - 'type' => 'int', - 'doc' => 'revision number of the page', - ), + 'id' => 'string', + 'rev' => 'int', ), 'name' => 'rawPage', 'return' => 'string', 'doc' => 'Return a raw wiki page' - ), - 'wiki.getAttachment' => array( + ), 'wiki.getPageHTML' => array( + 'args' => array( + 'id' => 'string' + ), + 'return' => 'string', + 'doc' => 'Return page in rendered HTML, latest version.', + 'name' => 'htmlPage' + ), 'wiki.getPageHTMLVersion' => array( 'args' => array( - 'type' => 'string', - 'doc' => 'file id', + 'id' => 'string', + 'rev' => 'int' ), + 'return' => 'string', + 'doc' => 'Return page in rendered HTML.', + 'name' => 'htmlPage' + ), 'wiki.getAllPages' => array( + 'args' => array(), + 'return' => 'array', + 'doc' => 'Returns a list of all pages. The result is an array of utf8 pagenames.', + 'name' => 'listPages' + ), 'wiki.getAttachments' => array( + 'args' => array( + 'namespace' => 'string', + 'options' => 'array' + ), + 'return' => 'array', + 'doc' => 'Returns a list of all media files.', + 'name' => 'listAttachments' + ), 'wiki.getBackLinks' => array( + 'args' => array( + 'id' => 'string' + ), + 'return' => 'array', + 'doc' => 'Returns the pages that link to this page.', + 'name' => 'listBackLinks' + ), 'wiki.getPageInfo' => array( + 'args' => array('id' => 'string'), + 'return' => 'array', + 'doc' => 'Returns a struct with infos about the page.', + 'name' => 'pageInfo' + ), 'wiki.getPageInfoVersion' => array( + 'args' => array( + 'id' => 'string', + 'version' => 'int', + ), + 'return' => 'array', + 'doc' => 'Returns a struct with infos about the page.', + 'name' => 'pageInfo' + ), 'wiki.getPageVersions' => array( + 'args' => array( + 'id' => 'string', + 'offset' => 'int' + ), + 'return' => 'array', + 'doc' => 'Returns the available revisions of the page.', + 'name' => 'pageVersions' + ), 'wiki.putPage' => array( + 'args' => array( + 'id' => 'string', + 'rawText' => 'string', + 'attrs' => 'array' + ), + 'return' => 'int', + 'doc' => 'Saves a wiki page.' + ), 'wiki.listLinks' => array( + 'args' => array('id' => 'string'), + 'return' => 'array', + 'doc' => 'Lists all links contained in a wiki page.' + ), 'wiki.getRecentChanges' => array( + 'args' => array('timestamp' => 'int'), + 'return' => 'array', + 'Returns a struct about all recent changes since given timestamp.' + ), 'wiki.getRecentMediaChanges' => array( + 'args' => array('timestamp' => 'int'), + 'return' => 'array', + 'Returns a struct about all recent media changes since given timestamp.' + ), 'wiki.aclCheck' => array( + 'args' => array('id' => 'string'), + 'return' => 'int', + 'doc' => 'Returns the permissions of a given wiki page.' + ), 'wiki.putAttachment' => array( + 'args' => array( + 'id' => 'string', + 'data' => 'file', + 'params' => 'array' + ), + 'return' => 'array', + 'doc' => 'Upload a file to the wiki.' + ), 'wiki.deleteAttachment' => array( + 'args' => array('id' => 'string'), + 'return' => 'int', + 'doc' => 'Delete a file from the wiki.' + ), 'wiki.getAttachment' => array( + 'args' => array('id' => 'string'), 'doc' => 'Return a media file', 'return' => 'file', 'name' => 'getAttachment', + ), 'wiki.getAttachmentInfo' => array( + 'args' => array('id' => 'string'), + 'return' => 'array', + 'doc' => 'Returns a struct with infos about the attachment.' ), ); @@ -63,7 +190,7 @@ class RemoteAPICore { } /** - * Return a media file encoded in base64 + * Return a media file * * @author Gina Haeussge * @param string $id file id @@ -92,13 +219,13 @@ class RemoteAPICore { function getAttachmentInfo($id){ $id = cleanID($id); $info = array( - 'lastModified' => 0, + 'lastModified' => new RemoteDate(0), 'size' => 0, ); $file = mediaFN($id); if ((auth_quickaclcheck(getNS($id).':*') >= AUTH_READ) && file_exists($file)){ - $info['lastModified'] = filemtime($file); + $info['lastModified'] = new RemoteDate(filemtime($file)); $info['size'] = filesize($file); } @@ -275,7 +402,6 @@ class RemoteAPICore { function putPage($id, $text, $params) { global $TEXT; global $lang; - global $conf; $id = cleanID($id); $TEXT = cleanText($text); diff --git a/inc/remote.php b/inc/remote.php index 7e82b6845..e18c71092 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -33,10 +33,7 @@ class RemoteFile extends RemoteDataType {} * array( * 'method.remoteName' => array( * 'args' => array( - * 'name' => array( - * 'type' => 'string|int|...|date|file', - * ['doc' = 'argument documentation'], - * ), + * 'name' => 'type eg. string|int|...|date|file', * ) * 'name' => 'method name in class', * 'return' => 'type', -- cgit v1.2.3 From a317247b19c498f4292480110cf0e0a1ce9780e8 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 14:54:53 +0100 Subject: updated remote hasAccess function --- inc/remote.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index e18c71092..94d428e8c 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -71,7 +71,6 @@ class RemoteAPI { * @return array with information to all available methods */ public function getMethods() { - $this->forceAccess(); return array_merge($this->getCoreMethods(), $this->getPluginMethods()); } @@ -122,10 +121,18 @@ class RemoteAPI { */ public function hasAccess() { global $conf; - if (!isset($conf['remote'])) { + global $USERINFO; + if (!$conf['remote']) { return false; } - return $conf['remote']; + if(!$conf['useacl']) { + return true; + } + if(trim($conf['remoteuser']) == '') { + return true; + } + + return auth_isMember($conf['remoteuser'], $_SERVER['REMOTE_USER'], (array) $USERINFO['grps']); } /** -- cgit v1.2.3 From 4beb39ea51a46409ab3abd4a1b880bf5d3d5dc4a Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 15:31:46 +0100 Subject: enforce acl on remote method call --- inc/remote.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index 94d428e8c..15d2308f8 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -82,7 +82,6 @@ class RemoteAPI { * @return mixed result of method call, must be a primitive type. */ public function call($method, $args = array()) { - $this->forceAccess(); list($type, $pluginName, $call) = explode('.', $method, 3); if ($type === 'plugin') { $plugin = plugin_load('remote', $pluginName); @@ -90,10 +89,12 @@ class RemoteAPI { if (!$plugin) { throw new RemoteException('Method dose not exists'); } + $this->checkAccess($methods[$method]); $name = $this->getMethodName($methods, $method); return call_user_func_array(array($plugin, $name), $args); } else { $coreMethods = $this->getCoreMethods(); + $this->checkAccess($coreMethods[$method]); if (!isset($coreMethods[$method])) { throw new RemoteException('Method dose not exists'); } @@ -102,6 +103,16 @@ class RemoteAPI { } } + private function checkAccess($methodMeta) { + if (!isset($methodMeta['public'])) { + $this->forceAccess(); + } else{ + if ($methodMeta['public'] == '0') { + $this->forceAccess(); + } + } + } + private function checkArgumentLength($method, $args) { if (count($method['args']) < count($args)) { throw new RemoteException('Method dose not exists - wrong parameter count.'); @@ -141,7 +152,7 @@ class RemoteAPI { */ public function forceAccess() { if (!$this->hasAccess()) { - throw new RemoteException('Access denied'); + throw new RemoteAccessDenied(); } } -- cgit v1.2.3 From 27bf90be7901fc8002eb1f253df9785610d586f1 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 15:56:24 +0100 Subject: set login as public method --- inc/RemoteAPICore.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php index 106ed598c..023fcb803 100644 --- a/inc/RemoteAPICore.php +++ b/inc/RemoteAPICore.php @@ -14,7 +14,8 @@ class RemoteAPICore { 'password' => 'string' ), 'return' => 'int', - 'doc' => 'Tries to login with the given credentials and sets auth cookies.' + 'doc' => 'Tries to login with the given credentials and sets auth cookies.', + 'public' => '1' ), 'dokuwiki.getPagelist' => array( 'args' => array( 'namespace' => 'string', -- cgit v1.2.3 From 3a13cfe7e12afabb47139702b7f118d63ccf42c2 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 18:10:38 +0100 Subject: set login as public method --- inc/remote.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index 15d2308f8..76d07b344 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -1,6 +1,7 @@ Date: Sun, 8 Jan 2012 18:14:44 +0100 Subject: added missing getVersion --- inc/RemoteAPICore.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'inc') diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php index 023fcb803..6b665e083 100644 --- a/inc/RemoteAPICore.php +++ b/inc/RemoteAPICore.php @@ -171,6 +171,10 @@ class RemoteAPICore { ); } + function getVersion() { + return getVersion(); + } + /** * Return a raw wiki page * @param string $id wiki page id -- cgit v1.2.3 From cb0d045e79603fb7f0c6703aaf633c8d0e34c117 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 18:21:48 +0100 Subject: added missing getTime --- inc/RemoteAPICore.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'inc') diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php index 6b665e083..a19c1b84e 100644 --- a/inc/RemoteAPICore.php +++ b/inc/RemoteAPICore.php @@ -175,6 +175,10 @@ class RemoteAPICore { return getVersion(); } + function getTime() { + return time(); + } + /** * Return a raw wiki page * @param string $id wiki page id -- cgit v1.2.3 From 1232df5e9480465ff8b2e24ce5760766b3bd908c Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 18:27:27 +0100 Subject: treat null as empty array --- inc/remote.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index 76d07b344..c18cb3713 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -83,6 +83,9 @@ class RemoteAPI { * @return mixed result of method call, must be a primitive type. */ public function call($method, $args = array()) { + if ($args === null) { + $args = array(); + } list($type, $pluginName, $call) = explode('.', $method, 3); if ($type === 'plugin') { $plugin = plugin_load('remote', $pluginName); -- cgit v1.2.3 From f95017850a515969190f54df3d57a00449245bb9 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 18:37:59 +0100 Subject: delegate file and date transformation to remote library --- inc/RemoteAPICore.php | 26 ++++++++++++++++---------- inc/remote.php | 33 +++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 14 deletions(-) (limited to 'inc') diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php index a19c1b84e..639aa4536 100644 --- a/inc/RemoteAPICore.php +++ b/inc/RemoteAPICore.php @@ -2,6 +2,12 @@ class RemoteAPICore { + private $api; + + public function __construct(RemoteAPI $api) { + $this->api = $api; + } + function __getRemoteInfo() { return array( 'dokuwiki.getVersion' => array( @@ -217,7 +223,7 @@ class RemoteAPICore { } $data = io_readFile($file, false); - return new RemoteFile($data); + return $this->api->toFile($data); } /** @@ -228,13 +234,13 @@ class RemoteAPICore { function getAttachmentInfo($id){ $id = cleanID($id); $info = array( - 'lastModified' => new RemoteDate(0), + 'lastModified' => $this->api->toDate(0), 'size' => 0, ); $file = mediaFN($id); if ((auth_quickaclcheck(getNS($id).':*') >= AUTH_READ) && file_exists($file)){ - $info['lastModified'] = new RemoteDate(filemtime($file)); + $info['lastModified'] = $this->api->toDate(filemtime($file)); $info['size'] = filesize($file); } @@ -269,7 +275,7 @@ class RemoteAPICore { $page['id'] = trim($pages[$idx]); $page['perms'] = $perm; $page['size'] = @filesize(wikiFN($pages[$idx])); - $page['lastModified'] = new RemoteDate(@filemtime(wikiFN($pages[$idx]))); + $page['lastModified'] = $this->api->toDate(@filemtime(wikiFN($pages[$idx]))); $list[] = $page; } @@ -362,7 +368,7 @@ class RemoteAPICore { for($i=0; $i<$len; $i++) { unset($data[$i]['meta']); - $data[$i]['lastModified'] = new RemoteDate($data[$i]['mtime']); + $data[$i]['lastModified'] = $this->api->toDate($data[$i]['mtime']); } return $data; } else { @@ -395,7 +401,7 @@ class RemoteAPICore { $data = array( 'name' => $id, - 'lastModified' => new RemoteDate($time), + 'lastModified' => $this->api->toDate($time), 'author' => (($info['user']) ? $info['user'] : $info['ip']), 'version' => $time ); @@ -477,7 +483,7 @@ class RemoteAPICore { * * Michael Klier */ - function putAttachment($id, RemoteFile $file, $params) { + function putAttachment($id, $file, $params) { $id = cleanID($id); $auth = auth_quickaclcheck(getNS($id).':*'); @@ -596,7 +602,7 @@ class RemoteAPICore { foreach ($recents as $recent) { $change = array(); $change['name'] = $recent['id']; - $change['lastModified'] = new RemoteDate($recent['date']); + $change['lastModified'] = $this->api->toDate($recent['date']); $change['author'] = $recent['user']; $change['version'] = $recent['date']; $change['perms'] = $recent['perms']; @@ -629,7 +635,7 @@ class RemoteAPICore { foreach ($recents as $recent) { $change = array(); $change['name'] = $recent['id']; - $change['lastModified'] = new RemoteDate($recent['date']); + $change['lastModified'] = $this->api->toDate($recent['date']); $change['author'] = $recent['user']; $change['version'] = $recent['date']; $change['perms'] = $recent['perms']; @@ -693,7 +699,7 @@ class RemoteAPICore { $data['ip'] = $info['ip']; $data['type'] = $info['type']; $data['sum'] = $info['sum']; - $data['modified'] = new RemoteDate($info['date']); + $data['modified'] = $this->api->toDate($info['date']); $data['version'] = $info['date']; array_push($versions, $data); } diff --git a/inc/remote.php b/inc/remote.php index c18cb3713..71ceb97b5 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -18,9 +18,6 @@ abstract class RemoteDataType { } } -class RemoteDate extends RemoteDataType {} -class RemoteFile extends RemoteDataType {} - /** * This class provides information about remote access to the wiki. * @@ -66,6 +63,14 @@ class RemoteAPI { */ private $pluginMethods = null; + private $dateTransformation; + private $fileTransformation; + + public function __construct() { + $this->dateTransformation = array($this, 'dummyTransformation'); + $this->fileTransformation = array($this, 'dummyTransformation'); + } + /** * Get all available methods with remote access. * @@ -191,11 +196,31 @@ class RemoteAPI { public function getCoreMethods($apiCore = null) { if ($this->coreMethods === null) { if ($apiCore === null) { - $this->coreMethods = new RemoteAPICore(); + $this->coreMethods = new RemoteAPICore($this); } else { $this->coreMethods = $apiCore; } } return $this->coreMethods->__getRemoteInfo(); } + + public function toFile($data) { + return call_user_func($this->fileTransformation, $data); + } + + public function toDate($data) { + return call_user_func($this->dateTransformation, $data); + } + + public function dummyTransformation($data) { + return $data; + } + + public function setDateTransformation($dateTransformation) { + $this->dateTransformation = $dateTransformation; + } + + public function setFileTransformation($fileTransformation) { + $this->fileTransformation = $fileTransformation; + } } \ No newline at end of file -- cgit v1.2.3 From e61127e4af913a252fbe5c8f427501268501895c Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 19:31:10 +0100 Subject: refactored RemoteAccessDenied to RemoteAccessDeniedException --- inc/RemoteAPICore.php | 18 +++++++++--------- inc/remote.php | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'inc') diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php index 639aa4536..2fecc3032 100644 --- a/inc/RemoteAPICore.php +++ b/inc/RemoteAPICore.php @@ -194,7 +194,7 @@ class RemoteAPICore { function rawPage($id,$rev=''){ $id = cleanID($id); if(auth_quickaclcheck($id) < AUTH_READ){ - throw new RemoteAccessDenied(); + throw new RemoteAccessDeniedException(); } $text = rawWiki($id,$rev); if(!$text) { @@ -214,7 +214,7 @@ class RemoteAPICore { function getAttachment($id){ $id = cleanID($id); if (auth_quickaclcheck(getNS($id).':*') < AUTH_READ) { - throw new RemoteAccessDenied(); + throw new RemoteAccessDeniedException(); } $file = mediaFN($id); @@ -253,7 +253,7 @@ class RemoteAPICore { function htmlPage($id,$rev=''){ $id = cleanID($id); if(auth_quickaclcheck($id) < AUTH_READ){ - throw new RemoteAccessDenied(1, 'You are not allowed to read this page'); + throw new RemoteAccessDeniedException(1, 'You are not allowed to read this page'); } return p_wiki_xhtml($id,$rev,false); } @@ -372,7 +372,7 @@ class RemoteAPICore { } return $data; } else { - throw new RemoteAccessDenied(1, 'You are not allowed to list media files.'); + throw new RemoteAccessDeniedException(1, 'You are not allowed to list media files.'); } } @@ -389,7 +389,7 @@ class RemoteAPICore { function pageInfo($id,$rev=''){ $id = cleanID($id); if(auth_quickaclcheck($id) < AUTH_READ){ - throw new RemoteAccessDenied(1, 'You are not allowed to read this page'); + throw new RemoteAccessDeniedException(1, 'You are not allowed to read this page'); } $file = wikiFN($id,$rev); $time = @filemtime($file); @@ -432,7 +432,7 @@ class RemoteAPICore { } if(auth_quickaclcheck($id) < AUTH_EDIT) { - throw new RemoteAccessDenied(1, 'You are not allowed to edit this page'); + throw new RemoteAccessDeniedException(1, 'You are not allowed to edit this page'); } // Check, if page is locked @@ -519,7 +519,7 @@ class RemoteAPICore { if ($res & DOKU_MEDIA_DELETED) { return 0; } elseif ($res & DOKU_MEDIA_NOT_AUTH) { - throw new RemoteAccessDenied(1, "You don't have permissions to delete files."); + throw new RemoteAccessDeniedException(1, "You don't have permissions to delete files."); } elseif ($res & DOKU_MEDIA_INUSE) { throw new RemoteException(1, 'File is still referenced'); } else { @@ -543,7 +543,7 @@ class RemoteAPICore { function listLinks($id) { $id = cleanID($id); if(auth_quickaclcheck($id) < AUTH_READ){ - throw new RemoteAccessDenied(1, 'You are not allowed to read this page'); + throw new RemoteAccessDeniedException(1, 'You are not allowed to read this page'); } $links = array(); @@ -659,7 +659,7 @@ class RemoteAPICore { function pageVersions($id, $first) { $id = cleanID($id); if(auth_quickaclcheck($id) < AUTH_READ) { - throw new RemoteAccessDenied(1, 'You are not allowed to read this page'); + throw new RemoteAccessDeniedException(1, 'You are not allowed to read this page'); } global $conf; diff --git a/inc/remote.php b/inc/remote.php index 71ceb97b5..8c505911c 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -4,7 +4,7 @@ if (!defined('DOKU_INC')) die(); require_once(DOKU_INC.'inc/RemoteAPICore.php'); class RemoteException extends Exception {} -class RemoteAccessDenied extends RemoteException {} +class RemoteAccessDeniedException extends RemoteException {} abstract class RemoteDataType { private $value; @@ -161,7 +161,7 @@ class RemoteAPI { */ public function forceAccess() { if (!$this->hasAccess()) { - throw new RemoteAccessDenied(); + throw new RemoteAccessDeniedException(); } } -- cgit v1.2.3 From 200ff6b799de7ba300488ec4cb4833c0092761e5 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 22 Jan 2012 11:58:39 +0100 Subject: removed unused class --- inc/remote.php | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index 8c505911c..0a507e95d 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -6,18 +6,6 @@ require_once(DOKU_INC.'inc/RemoteAPICore.php'); class RemoteException extends Exception {} class RemoteAccessDeniedException extends RemoteException {} -abstract class RemoteDataType { - private $value; - - function __construct($value) { - $this->value = $value; - } - - function getValue() { - return $this->value; - } -} - /** * This class provides information about remote access to the wiki. * -- cgit v1.2.3 From 750a55de568a82aaa40ca384a17a64804e94f2b9 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 5 Feb 2012 12:33:35 +0100 Subject: corrected comment --- inc/remote.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index 0a507e95d..82a0d3c08 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -23,7 +23,8 @@ class RemoteAccessDeniedException extends RemoteException {} * ) * 'name' => 'method name in class', * 'return' => 'type', -* ['doc' = 'method documentation'], + * 'public' => 1/0 - method bypass default group check (used by login) + * ['doc' = 'method documentation'], * ) * ) * -- cgit v1.2.3 From 03d7247e047c21d2733f837148a1499f56784ae3 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 5 Feb 2012 12:36:19 +0100 Subject: moved plugin and core method calls to seperate function --- inc/remote.php | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index 82a0d3c08..105969f8b 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -82,23 +82,31 @@ class RemoteAPI { } list($type, $pluginName, $call) = explode('.', $method, 3); if ($type === 'plugin') { - $plugin = plugin_load('remote', $pluginName); - $methods = $this->getPluginMethods(); - if (!$plugin) { - throw new RemoteException('Method dose not exists'); - } - $this->checkAccess($methods[$method]); - $name = $this->getMethodName($methods, $method); - return call_user_func_array(array($plugin, $name), $args); + return $this->callPlugin($pluginName, $method, $args); } else { - $coreMethods = $this->getCoreMethods(); - $this->checkAccess($coreMethods[$method]); - if (!isset($coreMethods[$method])) { - throw new RemoteException('Method dose not exists'); - } - $this->checkArgumentLength($coreMethods[$method], $args); - return call_user_func_array(array($this->coreMethods, $this->getMethodName($coreMethods, $method)), $args); + return $this->callCoreMethod($method, $args); + } + } + + private function callPlugin($pluginName, $method, $args) { + $plugin = plugin_load('remote', $pluginName); + $methods = $this->getPluginMethods(); + if (!$plugin) { + throw new RemoteException('Method dose not exists'); + } + $this->checkAccess($methods[$method]); + $name = $this->getMethodName($methods, $method); + return call_user_func_array(array($plugin, $name), $args); + } + + private function callCoreMethod($method, $args) { + $coreMethods = $this->getCoreMethods(); + $this->checkAccess($coreMethods[$method]); + if (!isset($coreMethods[$method])) { + throw new RemoteException('Method dose not exists'); } + $this->checkArgumentLength($coreMethods[$method], $args); + return call_user_func_array(array($this->coreMethods, $this->getMethodName($coreMethods, $method)), $args); } private function checkAccess($methodMeta) { -- cgit v1.2.3 From 4ea1d54936a1d1e9b919e06639632bc2ac65f6d3 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 21 Mar 2012 11:01:38 +0100 Subject: typo fixes --- inc/remote.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index c8af76420..fb095f517 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -92,7 +92,7 @@ class RemoteAPI { $plugin = plugin_load('remote', $pluginName); $methods = $this->getPluginMethods(); if (!$plugin) { - throw new RemoteException('Method dose not exists', -32603); + throw new RemoteException('Method does not exist', -32603); } $this->checkAccess($methods[$method]); $name = $this->getMethodName($methods, $method); @@ -103,7 +103,7 @@ class RemoteAPI { $coreMethods = $this->getCoreMethods(); $this->checkAccess($coreMethods[$method]); if (!isset($coreMethods[$method])) { - throw new RemoteException('Method dose not exists', -32603); + throw new RemoteException('Method does not exist', -32603); } $this->checkArgumentLength($coreMethods[$method], $args); return call_user_func_array(array($this->coreMethods, $this->getMethodName($coreMethods, $method)), $args); @@ -121,7 +121,7 @@ class RemoteAPI { private function checkArgumentLength($method, $args) { if (count($method['args']) < count($args)) { - throw new RemoteException('Method dose not exists - wrong parameter count.', -32603); + throw new RemoteException('Method does not exist - wrong parameter count.', -32603); } } @@ -173,7 +173,7 @@ class RemoteAPI { foreach ($plugins as $pluginName) { $plugin = plugin_load('remote', $pluginName); if (!is_subclass_of($plugin, 'DokuWiki_Remote_Plugin')) { - throw new RemoteException("Plugin $pluginName dose not implement DokuWiki_Remote_Plugin"); + throw new RemoteException("Plugin $pluginName does not implement DokuWiki_Remote_Plugin"); } $methods = $plugin->_getMethods(); -- cgit v1.2.3 From c2eb026d070a5ba9ba1ee8754c3a862a026a7ea8 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 21 Mar 2012 11:04:12 +0100 Subject: changed error code for unauthorized method calls. --- inc/remote.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index fb095f517..b4cc8e6cc 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -158,7 +158,7 @@ class RemoteAPI { */ public function forceAccess() { if (!$this->hasAccess()) { - throw new RemoteAccessDeniedException('server error. not authorized to call method', -32603); + throw new RemoteAccessDeniedException('server error. not authorized to call method', -32604); } } -- cgit v1.2.3 From 96946cc94d3ecb3832e2a1ce35c49743e25329e1 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 21 Mar 2012 11:25:00 +0100 Subject: replaced $HTTP_RAW_POST_DATA with http_get_raw_post_data function --- inc/IXR_Library.php | 7 ++++--- inc/httputils.php | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'inc') diff --git a/inc/IXR_Library.php b/inc/IXR_Library.php index c8255e6d9..ce5a4d914 100644 --- a/inc/IXR_Library.php +++ b/inc/IXR_Library.php @@ -302,11 +302,12 @@ class IXR_Server { } function serve($data = false) { if (!$data) { - global $HTTP_RAW_POST_DATA; - if (!$HTTP_RAW_POST_DATA) { + + $postData = trim(http_get_raw_post_data()); + if (!$postData) { die('XML-RPC server accepts POST requests only.'); } - $data = $HTTP_RAW_POST_DATA; + $data = $postData; } $this->message = new IXR_Message($data); if (!$this->message->parse()) { diff --git a/inc/httputils.php b/inc/httputils.php index 0ad97a9a1..b815f3ca6 100644 --- a/inc/httputils.php +++ b/inc/httputils.php @@ -249,3 +249,11 @@ function http_cached_finish($file, $content) { print $content; } } + +function http_get_raw_post_data() { + static $postData = null; + if ($postData === null) { + $postData = file_get_contents('php://input'); + } + return $postData; +} -- cgit v1.2.3 From 7c35ac36c1dea2d6f26d8184dcbf1fe5afae59ac Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 21 Mar 2012 13:15:18 +0100 Subject: added RPC_CALL_ADD event. This event enables plugins to register custom method names. --- inc/remote.php | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index b4cc8e6cc..089a5f7d4 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -35,8 +35,6 @@ class RemoteAccessDeniedException extends RemoteException {} * plugin methods are formed like 'plugin..'. * i.e.: plugin.clock.getTime or plugin.clock_gmt.getTime * - * - * * @throws RemoteException */ class RemoteAPI { @@ -52,6 +50,14 @@ class RemoteAPI { */ private $pluginMethods = null; + /** + * @var array contains custom calls to the api. Plugins can use the XML_CALL_REGISTER event. + * The data inside is 'custom.call.something' => array('plugin name', 'remote method name') + * + * The remote method name is the same as in the remote name returned by _getMethods(). + */ + private $pluginCustomCalls = null; + private $dateTransformation; private $fileTransformation; @@ -83,9 +89,34 @@ class RemoteAPI { list($type, $pluginName, $call) = explode('.', $method, 3); if ($type === 'plugin') { return $this->callPlugin($pluginName, $method, $args); - } else { + } + if ($this->coreMethodExist($method)) { return $this->callCoreMethod($method, $args); } + return $this->callCustomCallPlugin($method, $args); + } + + private function coreMethodExist($name) { + $coreMethods = $this->getCoreMethods(); + return array_key_exists($name, $coreMethods); + } + + private function callCustomCallPlugin($method, $args) { + $customCalls = $this->getCustomCallPlugins(); + if (!array_key_exists($method, $customCalls)) { + throw new RemoteException('Method does not exist', -32603); + } + $customCall = $customCalls[$method]; + return $this->callPlugin($customCall[0], $customCall[1], $args); + } + + private function getCustomCallPlugins() { + if ($this->pluginCustomCalls === null) { + $data = array(); + trigger_event('RPC_CALL_ADD', $data); + $this->pluginCustomCalls = $data; + } + return $this->pluginCustomCalls; } private function callPlugin($pluginName, $method, $args) { -- cgit v1.2.3 From 895122581107d99070522a1b5121f01e69d8a4de Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 21 Mar 2012 13:33:00 +0100 Subject: added dokuwiki.getXMLRPCAPIVersion and wiki.getRPCVersionSupported --- inc/RemoteAPICore.php | 99 ++++++++++++++++++--------------------------------- 1 file changed, 35 insertions(+), 64 deletions(-) (limited to 'inc') diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php index d525b17e0..38f7072ad 100644 --- a/inc/RemoteAPICore.php +++ b/inc/RemoteAPICore.php @@ -20,25 +20,17 @@ class RemoteAPICore { 'return' => 'string', 'doc' => 'Returns the running DokuWiki version.' ), 'dokuwiki.login' => array( - 'args' => array( - 'username' => 'string', - 'password' => 'string' - ), + 'args' => array('string', 'string'), 'return' => 'int', 'doc' => 'Tries to login with the given credentials and sets auth cookies.', 'public' => '1' ), 'dokuwiki.getPagelist' => array( - 'args' => array( - 'namespace' => 'string', - 'options' => 'array' - ), + 'args' => array('string', 'array'), 'return' => 'array', 'doc' => 'List all pages within the given namespace.', 'name' => 'readNamespace' ), 'dokuwiki.search' => array( - 'args' => array( - 'search' => 'string' - ), + 'args' => array('string'), 'return' => 'array', 'doc' => 'Perform a fulltext search and return a list of matching pages' ), 'dokuwiki.getTime' => array( @@ -46,7 +38,7 @@ class RemoteAPICore { 'return' => 'int', 'doc' => 'Returns the current time at the remote wiki server as Unix timestamp.', ), 'dokuwiki.setLocks' => array( - 'args' => array('lock' => 'array'), + 'args' => array('array'), 'return' => 'array', 'doc' => 'Lock or unlock pages.' ), 'dokuwiki.getTitle' => array( @@ -54,40 +46,26 @@ class RemoteAPICore { 'return' => 'string', 'doc' => 'Returns the wiki title.' ), 'dokuwiki.appendPage' => array( - 'args' => array( - 'pagename' => 'string', - 'rawWikiText' => 'string', - 'attrs' => 'array' - ), + 'args' => array('string', 'string', 'array'), 'return' => 'int', 'doc' => 'Append text to a wiki page.' ), 'wiki.getPage' => array( - 'args' => array( - 'id' => 'string' - ), + 'args' => array('string'), 'return' => 'string', 'doc' => 'Get the raw Wiki text of page, latest version.', 'name' => 'rawPage', ), 'wiki.getPageVersion' => array( - 'args' => array( - 'id' => 'string', - 'rev' => 'int', - ), + 'args' => array('string', 'int'), 'name' => 'rawPage', 'return' => 'string', 'doc' => 'Return a raw wiki page' ), 'wiki.getPageHTML' => array( - 'args' => array( - 'id' => 'string' - ), + 'args' => array('string'), 'return' => 'string', 'doc' => 'Return page in rendered HTML, latest version.', 'name' => 'htmlPage' ), 'wiki.getPageHTMLVersion' => array( - 'args' => array( - 'id' => 'string', - 'rev' => 'int' - ), + 'args' => array('string', 'int'), 'return' => 'string', 'doc' => 'Return page in rendered HTML.', 'name' => 'htmlPage' @@ -97,86 +75,79 @@ class RemoteAPICore { 'doc' => 'Returns a list of all pages. The result is an array of utf8 pagenames.', 'name' => 'listPages' ), 'wiki.getAttachments' => array( - 'args' => array( - 'namespace' => 'string', - 'options' => 'array' - ), + 'args' => array('string', 'array'), 'return' => 'array', 'doc' => 'Returns a list of all media files.', 'name' => 'listAttachments' ), 'wiki.getBackLinks' => array( - 'args' => array( - 'id' => 'string' - ), + 'args' => array('string'), 'return' => 'array', 'doc' => 'Returns the pages that link to this page.', 'name' => 'listBackLinks' ), 'wiki.getPageInfo' => array( - 'args' => array('id' => 'string'), + 'args' => array('string'), 'return' => 'array', 'doc' => 'Returns a struct with infos about the page.', 'name' => 'pageInfo' ), 'wiki.getPageInfoVersion' => array( - 'args' => array( - 'id' => 'string', - 'version' => 'int', - ), + 'args' => array('string', 'int'), 'return' => 'array', 'doc' => 'Returns a struct with infos about the page.', 'name' => 'pageInfo' ), 'wiki.getPageVersions' => array( - 'args' => array( - 'id' => 'string', - 'offset' => 'int' - ), + 'args' => array('string', 'int'), 'return' => 'array', 'doc' => 'Returns the available revisions of the page.', 'name' => 'pageVersions' ), 'wiki.putPage' => array( - 'args' => array( - 'id' => 'string', - 'rawText' => 'string', - 'attrs' => 'array' - ), + 'args' => array('string', 'string', 'array'), 'return' => 'int', 'doc' => 'Saves a wiki page.' ), 'wiki.listLinks' => array( - 'args' => array('id' => 'string'), + 'args' => array('string'), 'return' => 'array', 'doc' => 'Lists all links contained in a wiki page.' ), 'wiki.getRecentChanges' => array( - 'args' => array('timestamp' => 'int'), + 'args' => array('int'), 'return' => 'array', 'Returns a struct about all recent changes since given timestamp.' ), 'wiki.getRecentMediaChanges' => array( - 'args' => array('timestamp' => 'int'), + 'args' => array('int'), 'return' => 'array', 'Returns a struct about all recent media changes since given timestamp.' ), 'wiki.aclCheck' => array( - 'args' => array('id' => 'string'), + 'args' => array('string'), 'return' => 'int', 'doc' => 'Returns the permissions of a given wiki page.' ), 'wiki.putAttachment' => array( - 'args' => array( - 'id' => 'string', - 'data' => 'file', - 'params' => 'array' - ), + 'args' => array('string', 'file', 'array'), 'return' => 'array', 'doc' => 'Upload a file to the wiki.' ), 'wiki.deleteAttachment' => array( - 'args' => array('id' => 'string'), + 'args' => array('string'), 'return' => 'int', 'doc' => 'Delete a file from the wiki.' ), 'wiki.getAttachment' => array( - 'args' => array('id' => 'string'), + 'args' => array('string'), 'doc' => 'Return a media file', 'return' => 'file', 'name' => 'getAttachment', ), 'wiki.getAttachmentInfo' => array( - 'args' => array('id' => 'string'), + 'args' => array('string'), 'return' => 'array', 'doc' => 'Returns a struct with infos about the attachment.' + ), 'dokuwiki.getXMLRPCAPIVersion' => array( + 'args' => array(), + 'name' => 'getAPIVersion', + 'return' => 'int', + 'doc' => 'Returns the XMLRPC API version.', + 'public' => '1', + ), 'wiki.getRPCVersionSupported' => array( + 'args' => array(), + 'name' => 'wiki_RPCVersion', + 'return' => 'int', + 'doc' => 'Returns 2 with the supported RPC API version.', + 'public' => '1' ), ); -- cgit v1.2.3 From 418431a22a4a8f9d62e60e1d8eaa9bcf321377ce Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 21 Mar 2012 13:34:19 +0100 Subject: updated comment --- inc/remote.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/remote.php b/inc/remote.php index 089a5f7d4..0347bd900 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -19,7 +19,7 @@ class RemoteAccessDeniedException extends RemoteException {} * array( * 'method.remoteName' => array( * 'args' => array( - * 'name' => 'type eg. string|int|...|date|file', + * 'type eg. string|int|...|date|file', * ) * 'name' => 'method name in class', * 'return' => 'type', -- cgit v1.2.3 From 37e579189fae39899d3856598affa31dfd39328b Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Thu, 22 Mar 2012 12:04:56 +0100 Subject: removed require_once for autoloaded fulltext.php --- inc/RemoteAPICore.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'inc') diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php index 38f7072ad..450c6f39e 100644 --- a/inc/RemoteAPICore.php +++ b/inc/RemoteAPICore.php @@ -278,8 +278,6 @@ class RemoteAPICore { * List all pages in the given namespace (and below) */ function search($query){ - require_once(DOKU_INC.'inc/fulltext.php'); - $regex = ''; $data = ft_pageSearch($query,$regex); $pages = array(); -- cgit v1.2.3 From b967e5fc8fd93226eba7926c13b73b93878f182b Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Thu, 22 Mar 2012 12:11:31 +0100 Subject: removed requires, changed conf check in xmlrpc.php --- inc/load.php | 1 + inc/remote.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/load.php b/inc/load.php index 3f1f3429f..f3ab5bcdd 100644 --- a/inc/load.php +++ b/inc/load.php @@ -77,6 +77,7 @@ function load_autoload($name){ 'Sitemapper' => DOKU_INC.'inc/Sitemapper.php', 'PassHash' => DOKU_INC.'inc/PassHash.class.php', 'RemoteAPI' => DOKU_INC.'inc/remote.php', + 'RemoteAPICore' => DOKU_INC.'inc/RemoteAPICore.php', 'DokuWiki_Action_Plugin' => DOKU_PLUGIN.'action.php', 'DokuWiki_Admin_Plugin' => DOKU_PLUGIN.'admin.php', diff --git a/inc/remote.php b/inc/remote.php index 0347bd900..2ef28afd2 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -1,7 +1,6 @@