From d8fa89156eb03949c2f4e4f5da738fe42863c93c Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sun, 8 Jun 2014 00:45:52 +0200 Subject: [PATCH 1/9] Added autoloader info --- composer.json | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) mode change 100644 => 100755 composer.json diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index 7d56a90..7c2f9f1 --- a/composer.json +++ b/composer.json @@ -1,18 +1,23 @@ { - "name": "enko/dokuwikiobjectrepresentation", - "type": "library", - "description": "DokuWiki data abstraction from the future", - "keywords": ["dokuwiki","abstraction"], - "homepage": "https://bk-dev.hacked.jp/project/view/1/", - "license": "GPL2", - "authors": [ - { - "name": "Tim Schumacher", - "email": "tim@bandenkrieg.hacked.jp", - "role": "Developer" + "name": "enko/dokuwikiobjectrepresentation", + "type": "library", + "description": "DokuWiki data abstraction from the future", + "keywords": ["dokuwiki", "abstraction"], + "homepage": "https://bk-dev.hacked.jp/project/view/1/", + "license": "GPL2", + "authors": [ + { + "name": "Tim Schumacher", + "email": "tim@bandenkrieg.hacked.jp", + "role": "Developer" + } + ], + "require": { + "php": ">=5.3.0" + }, + "autoload": { + "psr-4": { + "enko\\dokuwiki\\objectrepresentation\\": "lib/enko/dokuwiki/objectrepresentation" + } } - ], - "require": { - "php": ">=5.3.0" - } } \ No newline at end of file From 5be961ccab993aef207b5be110f14b9c6c2fad9f Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sun, 8 Jun 2014 00:52:58 +0200 Subject: [PATCH 2/9] Updated the project url --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 7c2f9f1..92c8c18 100755 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "description": "DokuWiki data abstraction from the future", "keywords": ["dokuwiki", "abstraction"], - "homepage": "https://bk-dev.hacked.jp/project/view/1/", + "homepage": "https://phablab.krautspace.de/project/view/1/", "license": "GPL2", "authors": [ { @@ -20,4 +20,4 @@ "enko\\dokuwiki\\objectrepresentation\\": "lib/enko/dokuwiki/objectrepresentation" } } -} \ No newline at end of file +} From e9576d0d581d117ede6e4223c01e7a517a062e5a Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sun, 8 Jun 2014 01:57:48 +0200 Subject: [PATCH 3/9] Create a class that represents a changeset of dokuwiki page. --- .../DokuWikiChangeset.php | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100755 lib/enko/dokuwiki/objectrepresentation/DokuWikiChangeset.php diff --git a/lib/enko/dokuwiki/objectrepresentation/DokuWikiChangeset.php b/lib/enko/dokuwiki/objectrepresentation/DokuWikiChangeset.php new file mode 100755 index 0000000..97b10bc --- /dev/null +++ b/lib/enko/dokuwiki/objectrepresentation/DokuWikiChangeset.php @@ -0,0 +1,100 @@ +content; + } + + /** + * @return \DateTime + */ + public function getDate() + { + return $this->date; + } + + /** + * @return mixed + */ + public function getExtra() + { + return $this->extra; + } + + /** + * @return mixed + */ + public function getId() + { + return $this->id; + } + + /** + * @return mixed + */ + public function getIp() + { + return $this->ip; + } + + /** + * @return mixed + */ + public function getSum() + { + return $this->sum; + } + + /** + * @return mixed + */ + public function getType() + { + return $this->type; + } + + /** + * @return mixed + */ + public function getUser() + { + return $this->user; + } + + function __construct($date,$extra, $id, $ip, $sum, $type, $user) + { + $this->date = new \DateTime(); + $this->date->setTimestamp($date); + $this->extra = $extra; + $this->id = $id; + $this->ip = $ip; + $this->sum = $sum; + $this->type = $type; + $this->user = $user; + $this->content = rawWiki($id,$this->date->format('U')); + } + + +} \ No newline at end of file From 29ebda487aa2d866ef63e882830681a5513fa60b Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sun, 8 Jun 2014 01:58:27 +0200 Subject: [PATCH 4/9] Extract the changesets of a dokuwikipage and put it into DokuWikiPage::ChangeLog. --- .../dokuwiki/objectrepresentation/DokuWikiPage.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php b/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php index f4691a4..fdffa68 100755 --- a/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php +++ b/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php @@ -11,6 +11,8 @@ namespace enko\dokuwiki\objectrepresentation; class DokuWikiPage extends DokuWikiNode { + public $ChangeLog; + /** * @param $filename * @param null $parent @@ -26,6 +28,17 @@ class DokuWikiPage extends DokuWikiNode foreach ($metadata as $key => $value) { $this->setMetaData($key, $value); } + // extract changelog + $this->ChangeLog = new \ArrayObject(); + $file = metaFN($this->getFullID(), '.changes'); + if (file_exists($file)) { + $changelog_entries = explode("\n", file_get_contents($file)); + foreach ($changelog_entries as $raw_entry) { + $entry = parseChangelogLine($raw_entry); + $changelog = new DokuWikiChangeset($entry['date'], $entry['extra'], $entry['id'], $entry['ip'], $entry['sum'], $entry['type'], $entry['user']); + $this->ChangeLog->append($changelog); + } + } } } \ No newline at end of file From 0b248d7dec6336bf76b154b75318474ca5ac0228 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 14 Jun 2014 09:29:13 +0200 Subject: [PATCH 5/9] Add a option to load the changesets. The default is, not to load the changesets. --- .../objectrepresentation/DokuWikiIterator.php | 4 ++-- .../DokuWikiNameSpace.php | 8 +++---- .../objectrepresentation/DokuWikiNode.php | 10 +++++++- .../objectrepresentation/DokuWikiPage.php | 24 +++++++++++-------- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/lib/enko/dokuwiki/objectrepresentation/DokuWikiIterator.php b/lib/enko/dokuwiki/objectrepresentation/DokuWikiIterator.php index e938875..0c3b983 100755 --- a/lib/enko/dokuwiki/objectrepresentation/DokuWikiIterator.php +++ b/lib/enko/dokuwiki/objectrepresentation/DokuWikiIterator.php @@ -55,12 +55,12 @@ class DokuWikiIterator /** * */ - public function __construct() + public function __construct($loadChangesets = false, \DateTime $maxChangeSetAge = null) { global $conf; $basedir = $conf['datadir']; - $this->root = new DokuWikiNameSpace($basedir); + $this->root = new DokuWikiNameSpace($basedir, null, $loadChangesets, $maxChangeSetAge); } /** diff --git a/lib/enko/dokuwiki/objectrepresentation/DokuWikiNameSpace.php b/lib/enko/dokuwiki/objectrepresentation/DokuWikiNameSpace.php index cee50bc..f57d030 100755 --- a/lib/enko/dokuwiki/objectrepresentation/DokuWikiNameSpace.php +++ b/lib/enko/dokuwiki/objectrepresentation/DokuWikiNameSpace.php @@ -19,9 +19,9 @@ class DokuWikiNameSpace extends DokuWikiNode * @param $path * @param null $parent */ - function __construct($path, $parent = null) + function __construct($path, $parent = null,$loadChangesets = false, \DateTime $maxChangeSetAge = null) { - parent::__construct($path, $parent); + parent::__construct($path, $parent, $loadChangesets, $maxChangeSetAge); $files = dir($path); $this->nodes = new \ArrayObject(); @@ -31,10 +31,10 @@ class DokuWikiNameSpace extends DokuWikiNode $file = $path . DIRECTORY_SEPARATOR . $realfile; if (is_dir($file)) { if (!(($realfile == '.') or ($realfile == '..'))) { - $node = new DokuWikiNameSpace($file, $this); + $node = new DokuWikiNameSpace($file, $this, $loadChangesets, $maxChangeSetAge); } } else { - $node = new DokuWikiPage($file, $this); + $node = new DokuWikiPage($file, $this, $loadChangesets, $maxChangeSetAge); } if ($node) { $this->nodes->append($node); diff --git a/lib/enko/dokuwiki/objectrepresentation/DokuWikiNode.php b/lib/enko/dokuwiki/objectrepresentation/DokuWikiNode.php index 866e27a..138f805 100755 --- a/lib/enko/dokuwiki/objectrepresentation/DokuWikiNode.php +++ b/lib/enko/dokuwiki/objectrepresentation/DokuWikiNode.php @@ -32,6 +32,12 @@ abstract class DokuWikiNode /** @var DokuWikiNameSpace */ protected $parent = null; + /** @var bool */ + protected $loadChangesets = false; + + /** @var \DateTime */ + protected $maxChangeSetAge = null; + /** * @return string @@ -81,11 +87,13 @@ abstract class DokuWikiNode * @param $filename * @param null $parent */ - function __construct($filename, $parent = null) + function __construct($filename, $parent = null, $loadChangesets = false, \DateTime $maxChangeSetAge = null) { $this->filename = $filename; $this->parent = $parent; $this->metadata = new \ArrayObject(); + $this->loadChangesets = $loadChangesets; + $this->maxChangeSetAge = $maxChangeSetAge; if (is_null($parent) && is_dir($filename)) { $this->name = 'root'; } else { diff --git a/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php b/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php index fdffa68..4be402c 100755 --- a/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php +++ b/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php @@ -17,9 +17,9 @@ class DokuWikiPage extends DokuWikiNode * @param $filename * @param null $parent */ - public function __construct($filename, $parent = null) + public function __construct($filename, $parent = null,$loadChangesets = false, \DateTime $maxChangeSetAge = null) { - parent::__construct($filename, $parent); + parent::__construct($filename, $parent,$loadChangesets,$maxChangeSetAge); $this->content = file_get_contents($this->filename); if (($this->name == 'start') && ($this->parent->name != 'root')) { $this->parent->content = $this->content; @@ -28,15 +28,19 @@ class DokuWikiPage extends DokuWikiNode foreach ($metadata as $key => $value) { $this->setMetaData($key, $value); } - // extract changelog $this->ChangeLog = new \ArrayObject(); - $file = metaFN($this->getFullID(), '.changes'); - if (file_exists($file)) { - $changelog_entries = explode("\n", file_get_contents($file)); - foreach ($changelog_entries as $raw_entry) { - $entry = parseChangelogLine($raw_entry); - $changelog = new DokuWikiChangeset($entry['date'], $entry['extra'], $entry['id'], $entry['ip'], $entry['sum'], $entry['type'], $entry['user']); - $this->ChangeLog->append($changelog); + if ($this->loadChangesets) { + // extract changelog + $file = metaFN($this->getFullID(), '.changes'); + if (file_exists($file)) { + $changelog_entries = explode("\n", file_get_contents($file)); + foreach ($changelog_entries as $raw_entry) { + $entry = parseChangelogLine($raw_entry); + if ((!is_null($this->maxChangeSetAge)) && ($this->maxChangeSetAge->format('U') > $entry['date'])) + continue; + $changelog = new DokuWikiChangeset($entry['date'], $entry['extra'], $entry['id'], $entry['ip'], $entry['sum'], $entry['type'], $entry['user']); + $this->ChangeLog->append($changelog); + } } } From 8bda3d90f6cd7d0f47b8ffa1e919cf2f3b2bd40d Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 14 Jun 2014 10:19:19 +0200 Subject: [PATCH 6/9] Generate the title for the page. --- .../dokuwiki/objectrepresentation/DokuWikiChangeset.php | 8 +++++++- lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/enko/dokuwiki/objectrepresentation/DokuWikiChangeset.php b/lib/enko/dokuwiki/objectrepresentation/DokuWikiChangeset.php index 97b10bc..67451a4 100755 --- a/lib/enko/dokuwiki/objectrepresentation/DokuWikiChangeset.php +++ b/lib/enko/dokuwiki/objectrepresentation/DokuWikiChangeset.php @@ -18,6 +18,7 @@ class DokuWikiChangeset { private $sum; private $extra; private $content; + private $page; /** * @return mixed @@ -75,6 +76,10 @@ class DokuWikiChangeset { return $this->type; } + public function getPage() { + return $this->page; + } + /** * @return mixed */ @@ -83,7 +88,7 @@ class DokuWikiChangeset { return $this->user; } - function __construct($date,$extra, $id, $ip, $sum, $type, $user) + function __construct($date,$extra, $id, $ip, $sum, $type, $user, DokuWikiPage $page) { $this->date = new \DateTime(); $this->date->setTimestamp($date); @@ -94,6 +99,7 @@ class DokuWikiChangeset { $this->type = $type; $this->user = $user; $this->content = rawWiki($id,$this->date->format('U')); + $this->page = $page; } diff --git a/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php b/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php index fdffa68..c78dad3 100755 --- a/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php +++ b/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php @@ -35,10 +35,14 @@ class DokuWikiPage extends DokuWikiNode $changelog_entries = explode("\n", file_get_contents($file)); foreach ($changelog_entries as $raw_entry) { $entry = parseChangelogLine($raw_entry); - $changelog = new DokuWikiChangeset($entry['date'], $entry['extra'], $entry['id'], $entry['ip'], $entry['sum'], $entry['type'], $entry['user']); + $changelog = new DokuWikiChangeset($entry['date'], $entry['extra'], $entry['id'], $entry['ip'], $entry['sum'], $entry['type'], $entry['user'],$this); $this->ChangeLog->append($changelog); } } } + + public function getTitle() { + return strlen($this->getMetaData('title')) > 0 ? $this->getMetaData('title') : $this->getName(); + } } \ No newline at end of file From 040a3fbd8af686f440ac30eff1451be0218bc8d3 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 14 Jun 2014 10:24:20 +0200 Subject: [PATCH 7/9] fix typo --- lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php b/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php index eca314d..caf5f5c 100755 --- a/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php +++ b/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php @@ -38,7 +38,7 @@ class DokuWikiPage extends DokuWikiNode $entry = parseChangelogLine($raw_entry); if ((!is_null($this->maxChangeSetAge)) && ($this->maxChangeSetAge->format('U') > $entry['date'])) continue; - $changelog = new DokuWikiChangeset($entry['date'], $entry['extra'], $entry['id'], $entry['ip'], $entry['sum'], $entry['type'], $entry['user'],$page); + $changelog = new DokuWikiChangeset($entry['date'], $entry['extra'], $entry['id'], $entry['ip'], $entry['sum'], $entry['type'], $entry['user'],$this); $this->ChangeLog->append($changelog); } } From 56ce743994220670647387f59d6a004b25a49b28 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sun, 15 Jun 2014 16:39:47 +0200 Subject: [PATCH 8/9] Suply a getter for the node parent. --- lib/enko/dokuwiki/objectrepresentation/DokuWikiNode.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/enko/dokuwiki/objectrepresentation/DokuWikiNode.php b/lib/enko/dokuwiki/objectrepresentation/DokuWikiNode.php index 138f805..b49bce2 100755 --- a/lib/enko/dokuwiki/objectrepresentation/DokuWikiNode.php +++ b/lib/enko/dokuwiki/objectrepresentation/DokuWikiNode.php @@ -83,6 +83,13 @@ abstract class DokuWikiNode return $this->name; } + /** + * @return DokuWikiNameSpace + */ + public function getParent() { + return $this->parent; + } + /** * @param $filename * @param null $parent From 174d217f1145164578cd55f5d46aa08055354b59 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sun, 15 Jun 2014 16:40:08 +0200 Subject: [PATCH 9/9] Sort the changelog. --- lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php b/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php index caf5f5c..eacc13a 100755 --- a/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php +++ b/lib/enko/dokuwiki/objectrepresentation/DokuWikiPage.php @@ -42,6 +42,14 @@ class DokuWikiPage extends DokuWikiNode $this->ChangeLog->append($changelog); } } + if ($this->ChangeLog->count() > 0) { + $this->ChangeLog->uasort(function(DokuWikiChangeset $a, DokuWikiChangeset $b){ + if ($a->getDate() == $b->getDate()) { + return 0; + } + return ($a->getDate() > $b->getDate()) ? -1 : 1; + }); + } } }