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/RemoteAPICore.php') 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 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 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'inc/RemoteAPICore.php') 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); } -- 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/RemoteAPICore.php') 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 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 150 insertions(+), 24 deletions(-) (limited to 'inc/RemoteAPICore.php') 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); -- 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/RemoteAPICore.php') 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 bb680e43a5c33747ab844580e1e80c4fdc2fe580 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann 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/RemoteAPICore.php') 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/RemoteAPICore.php') 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 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 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'inc/RemoteAPICore.php') 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); } -- 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 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'inc/RemoteAPICore.php') 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; -- 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/RemoteAPICore.php') 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 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/RemoteAPICore.php') 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