From eb3214dba5f3e276270f17b809b625b5e310e7f5 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Fri, 8 Mar 2024 12:08:14 -0300 Subject: [PATCH 1/9] Further PHP 8 fixes --- Client.php | 7 ++++--- Profile.php | 42 +++++++++++++++++++++++------------------- sync.js | 2 +- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Client.php b/Client.php index 1ec6cf2..dff2080 100644 --- a/Client.php +++ b/Client.php @@ -23,10 +23,11 @@ public function __construct($server, $user, $pass, $timeout = 15) { } /** @inheritdoc */ - public function query() { + public function query(...$args) { $ok = call_user_func_array('parent::query', func_get_args()); - $code = $this->getErrorCode(); - if($code === -32300) $code = -1 * $this->status; // use http status on transport errors + $code = @$this->getErrorCode(); + $http = $this->getHTTPClient(); + if($code === -32300) $code = -1 * $http->status; // use http status on transport errors if(!$ok) { // when a file context is given include it in the exception if($this->filecontext) { diff --git a/Profile.php b/Profile.php index a6024c7..0e0567a 100644 --- a/Profile.php +++ b/Profile.php @@ -267,7 +267,7 @@ protected function fetchRemoteFileList($type) { } $this->client->query($cmd, $this->config['ns'], $this->syncoptions); - $remote = $this->client->getResponse(); + $remote = @$this->client->getResponse(); // put into synclist foreach($remote as $item) { @@ -317,37 +317,41 @@ protected function itemEnhance($item) { */ protected function consolidateSyncList() { // synctimes - $ltime = (int) $this->config['ltime']; - $rtime = (int) $this->config['rtime']; - $letime = (int) $this->config['letime']; - $retime = (int) $this->config['retime']; + $ltime = isset($this->config['ltime']) ? (int) $this->config['ltime'] : null; + $rtime = isset($this->config['rtime']) ? (int) $this->config['rtime'] : null; + $letime = isset($this->config['letime']) ? (int) $this->config['letime'] : null; + $retime = isset($this->config['retime']) ? (int) $this->config['retime'] : null; foreach([self::TYPE_PAGES, self::TYPE_MEDIA] as $type) { foreach($this->synclist[$type] as $id => $item) { // no sync if hashes match - if($item['remote']['hash'] == $item['local']['hash']) { - unset($this->synclist[$type][$id]); - continue; + if(isset($item['remote']['hash']) && isset($item['local']['hash'])) { + if($item['remote']['hash'] == $item['local']['hash']) { + unset($this->synclist[$type][$id]); + continue; + } } // check direction $dir = self::DIR_NONE; if($ltime && $rtime) { // synced before - if($item['remote']['mtime'] > $rtime && - $item['local']['mtime'] <= $letime - ) { - $dir = self::DIR_PULL; - } - if($item['remote']['mtime'] <= $retime && - $item['local']['mtime'] > $ltime - ) { - $dir = self::DIR_PUSH; + if(isset($item['local']['mtime']) && isset($item['remote']['mtime'])) { + if($item['remote']['mtime'] > $rtime && + $item['local']['mtime'] <= $letime + ) { + $dir = self::DIR_PULL; + } + if($item['remote']['mtime'] <= $retime && + $item['local']['mtime'] > $ltime + ) { + $dir = self::DIR_PUSH; + } } } else { // never synced - if(!$item['local']['mtime'] && $item['remote']['mtime']) { + if(!isset($item['local']['mtime']) && $item['remote']['mtime']) { $dir = self::DIR_PULL; } - if($item['local']['mtime'] && !$item['remote']['mtime']) { + if($item['local']['mtime'] && !isset($item['remote']['mtime'])) { $dir = self::DIR_PUSH; } } diff --git a/sync.js b/sync.js index 8a9e49e..babfe54 100644 --- a/sync.js +++ b/sync.js @@ -278,7 +278,7 @@ jQuery(function () { */ function error(error) { var $err = jQuery('
'); - $err.text(error); + $err.text(error.responseText); $output.append($err); } From ebad79352aa4a76619716d26b481fde832e1a08b Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Fri, 8 Mar 2024 16:34:05 -0300 Subject: [PATCH 2/9] Fix JSON encoding --- SyncException.php | 2 +- SyncFileException.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SyncException.php b/SyncException.php index 843d9e2..d0f4f70 100644 --- a/SyncException.php +++ b/SyncException.php @@ -23,6 +23,6 @@ public function __construct($message = '', $code = 0, $previous = null) { if($code === -403) $message = $plugin->getLang('autherr'); - parent::__construct($message, $code, $previous); + parent::__construct(html_entity_decode($message), $code, $previous); } } diff --git a/SyncFileException.php b/SyncFileException.php index 54d2a8a..ea84f4e 100644 --- a/SyncFileException.php +++ b/SyncFileException.php @@ -28,6 +28,6 @@ public function __construct($message, $id, $code = 0) { // append file name $message = $message . ' ' . $id; - parent::__construct($message, $code); + parent::__construct(html_entity_decode($message), $code); } } From a157a442579d5e88fee3122664bef1d1cf40c728 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Tue, 19 Mar 2024 15:31:12 -0300 Subject: [PATCH 3/9] Sort list, CoreAPI and Bugfix for timeout This commit sorts the list through the namespace key ID, replaces some deprecated calls by CoreAPI (work in progress) and fixes timeout set up on profile not being applied. --- Client.php | 3 +-- Profile.php | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Client.php b/Client.php index dff2080..9aa0e9c 100644 --- a/Client.php +++ b/Client.php @@ -17,8 +17,7 @@ class Client extends \IXR_Client { * @param int $timeout */ public function __construct($server, $user, $pass, $timeout = 15) { - parent::__construct($server); - $this->timeout = $timeout; + parent::__construct($server, $path = false, $port = 80, $timeout); $this->login($user, $pass); } diff --git a/Profile.php b/Profile.php index 0e0567a..a66e051 100644 --- a/Profile.php +++ b/Profile.php @@ -2,6 +2,8 @@ namespace dokuwiki\plugin\sync; +use dokuwiki\Utf8\Sort; + class Profile { const DIR_PULL = -1; @@ -261,13 +263,14 @@ protected function setRemoteLock($id, $state) { */ protected function fetchRemoteFileList($type) { if($type === self::TYPE_PAGES) { - $cmd = 'dokuwiki.getPagelist'; + $cmd = 'core.listPages'; } else { - $cmd = 'wiki.getAttachments'; + $cmd = 'core.listMedia'; } - $this->client->query($cmd, $this->config['ns'], $this->syncoptions); + $this->client->query($cmd, $this->config['ns'], $this->syncoptions['depth'], $this->syncoptions['hash']); $remote = @$this->client->getResponse(); + $http = $this->client->getHTTPClient(); // put into synclist foreach($remote as $item) { @@ -308,7 +311,11 @@ protected function fetchLocalFileList($type) { * @return mixed */ protected function itemEnhance($item) { - $item['info'] = dformat($item['mtime']) . '
' . filesize_h($item['size']); + if(isset($item['mtime'])) { + $item['info'] = dformat($item['mtime']) . '
' . filesize_h($item['size']); + } else { + $item['info'] = dformat($item['revision']) . '
' . filesize_h($item['size']); + } return $item; } @@ -335,28 +342,29 @@ protected function consolidateSyncList() { // check direction $dir = self::DIR_NONE; if($ltime && $rtime) { // synced before - if(isset($item['local']['mtime']) && isset($item['remote']['mtime'])) { - if($item['remote']['mtime'] > $rtime && + if(isset($item['local']['mtime']) && isset($item['remote']['revision'])) { + if($item['remote']['revision'] > $rtime && $item['local']['mtime'] <= $letime ) { $dir = self::DIR_PULL; } - if($item['remote']['mtime'] <= $retime && + if($item['remote']['revision'] <= $retime && $item['local']['mtime'] > $ltime ) { $dir = self::DIR_PUSH; } } } else { // never synced - if(!isset($item['local']['mtime']) && $item['remote']['mtime']) { + if(!isset($item['local']['mtime']) && $item['remote']['revision']) { $dir = self::DIR_PULL; } - if($item['local']['mtime'] && !isset($item['remote']['mtime'])) { + if($item['local']['mtime'] && !isset($item['remote']['revision'])) { $dir = self::DIR_PUSH; } } $this->synclist[$type][$id]['dir'] = $dir; } + Sort::ksort($this->synclist[$type]); } } From 71de9cb13dc19ec62b2d1e2f8d2d3c80504d9240 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Mon, 11 Nov 2024 19:00:54 -0300 Subject: [PATCH 4/9] Add "Select all" feature for Sync plugin Similar to the legacy DokuWiki sync plugin (before refactor), this commit adds the ">", "=" and "<" controller for "Sync direction" header. Also adds "PT-BR" translation. --- Profile.php | 6 +--- lang/pt-br/intro.txt | 4 +++ lang/pt-br/lang.php | 67 ++++++++++++++++++++++++++++++++++++++++++++ style.less | 20 ++++++++++++- sync.js | 25 +++++++++++++++++ 5 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 lang/pt-br/intro.txt create mode 100644 lang/pt-br/lang.php diff --git a/Profile.php b/Profile.php index a66e051..97c627b 100644 --- a/Profile.php +++ b/Profile.php @@ -2,8 +2,6 @@ namespace dokuwiki\plugin\sync; -use dokuwiki\Utf8\Sort; - class Profile { const DIR_PULL = -1; @@ -270,7 +268,6 @@ protected function fetchRemoteFileList($type) { $this->client->query($cmd, $this->config['ns'], $this->syncoptions['depth'], $this->syncoptions['hash']); $remote = @$this->client->getResponse(); - $http = $this->client->getHTTPClient(); // put into synclist foreach($remote as $item) { @@ -358,13 +355,12 @@ protected function consolidateSyncList() { if(!isset($item['local']['mtime']) && $item['remote']['revision']) { $dir = self::DIR_PULL; } - if($item['local']['mtime'] && !isset($item['remote']['revision'])) { + if((isset($item['local']['mtime']) && $item['local']['mtime']) && !isset($item['remote']['revision'])) { $dir = self::DIR_PUSH; } } $this->synclist[$type][$id]['dir'] = $dir; } - Sort::ksort($this->synclist[$type]); } } diff --git a/lang/pt-br/intro.txt b/lang/pt-br/intro.txt new file mode 100644 index 0000000..d87bda1 --- /dev/null +++ b/lang/pt-br/intro.txt @@ -0,0 +1,4 @@ +====== Sincronização do Wiki ====== + +Esta ferramenta permite sincronizar o conteúdo do seu wiki com outros wikis. Vários outros wikis podem ser configurados usando perfis de sincronização. A sincronização pode ser restrita a determinados namespaces. + diff --git a/lang/pt-br/lang.php b/lang/pt-br/lang.php new file mode 100644 index 0000000..fecb2b1 --- /dev/null +++ b/lang/pt-br/lang.php @@ -0,0 +1,67 @@ + label.push input { + &:checked::before { + content: url(pix/arrow-right-bold-circle-outline.svg); + } + } + + th.dir > label.skip input { + &:checked::before { + content: url(pix/pause-circle-outline.svg); + } + } + + th.dir > label.pull input { + &:checked::before { + content: url(pix/arrow-left-bold-circle-outline.svg); + } + } } } diff --git a/sync.js b/sync.js index babfe54..9d73376 100644 --- a/sync.js +++ b/sync.js @@ -32,6 +32,7 @@ jQuery(function () { }); }); $output.append($table); + jQuery('input[name="dir"]').click(function(){ sync_select(this.value); }); var $lbl = jQuery('