Skip to content

Commit

Permalink
delegate file and date transformation to remote library
Browse files Browse the repository at this point in the history
  • Loading branch information
dom-mel committed Jan 8, 2012
1 parent 1232df5 commit f950178
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
26 changes: 16 additions & 10 deletions inc/RemoteAPICore.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

class RemoteAPICore {

private $api;

public function __construct(RemoteAPI $api) {
$this->api = $api;
}

function __getRemoteInfo() {
return array(
'dokuwiki.getVersion' => array(
Expand Down Expand Up @@ -217,7 +223,7 @@ function getAttachment($id){
}

$data = io_readFile($file, false);
return new RemoteFile($data);
return $this->api->toFile($data);
}

/**
Expand All @@ -228,13 +234,13 @@ function getAttachment($id){
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);
}

Expand Down Expand Up @@ -269,7 +275,7 @@ function listPages(){
$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;
}

Expand Down Expand Up @@ -362,7 +368,7 @@ function listAttachments($ns, $options = array()) {

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 {
Expand Down Expand Up @@ -395,7 +401,7 @@ function pageInfo($id,$rev=''){

$data = array(
'name' => $id,
'lastModified' => new RemoteDate($time),
'lastModified' => $this->api->toDate($time),
'author' => (($info['user']) ? $info['user'] : $info['ip']),
'version' => $time
);
Expand Down Expand Up @@ -477,7 +483,7 @@ function appendPage($id, $text, $params) {
*
* Michael Klier <chi@chimeric.de>
*/
function putAttachment($id, RemoteFile $file, $params) {
function putAttachment($id, $file, $params) {
$id = cleanID($id);
$auth = auth_quickaclcheck(getNS($id).':*');

Expand Down Expand Up @@ -596,7 +602,7 @@ function getRecentChanges($timestamp) {
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'];
Expand Down Expand Up @@ -629,7 +635,7 @@ function getRecentMediaChanges($timestamp) {
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'];
Expand Down Expand Up @@ -693,7 +699,7 @@ function pageVersions($id, $first) {
$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);
}
Expand Down
33 changes: 29 additions & 4 deletions inc/remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ function getValue() {
}
}

class RemoteDate extends RemoteDataType {}
class RemoteFile extends RemoteDataType {}

/**
* This class provides information about remote access to the wiki.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -191,11 +196,31 @@ public function getPluginMethods() {
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;
}
}
10 changes: 10 additions & 0 deletions lib/exe/xmlrpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class dokuwiki_xmlrpc_server extends IXR_Server {
*/
function dokuwiki_xmlrpc_server(){
$this->remote = new RemoteAPI();
$this->remote->setDateTransformation(array($this, 'toDate'));
$this->remote->setFileTransformation(array($this, 'toFile'));
$this->IXR_Server();
}

Expand All @@ -47,6 +49,14 @@ function call($methodname, $args){
}
}

function toDate($data) {
return new IXR_Date($data);
}

function toFile($data) {
return new IXR_Base64($data);
}

}

$server = new dokuwiki_xmlrpc_server();
Expand Down

0 comments on commit f950178

Please sign in to comment.