diff --git a/_test/publish.test.php b/_test/publish.test.php
index f96a0b8..2bcdc0f 100644
--- a/_test/publish.test.php
+++ b/_test/publish.test.php
@@ -44,7 +44,7 @@ public function setUp(){
public function test_unaprroved_banner_exists() {
saveWikiText('foo', 'bar', 'foobar');
$request = new TestRequest();
- $response = $request->get(array('id' => 'foo'), '/doku.php?id=foo');
+ $response = $request->get(array(), '/doku.php?id=foo');
$this->assertTrue(
strpos($response->getContent(), '
') !== false,
'The "not approved banner" is missing on a page which has not yet been aprroved with standard config.'
@@ -56,6 +56,8 @@ public function test_unaprroved_banner_exists() {
* @coversNothing
*/
public function test_aprroval_succesful() {
+ global $conf;
+ $conf['plugin']['publish']['auto_self_approve'] = 0;
saveWikiText('foo', 'bar', 'foobar');
$request = new TestRequest();
$response = $request->get(array(), '/doku.php?id=foo&publish_approve=1');
@@ -81,6 +83,21 @@ public function test_no_aprroved_banner() {
strpos($response->getContent(), '
register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_io_write', array());
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'approveNS', array());
+ $controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'self_approve', array(), -1000);
}
function approveNS(Doku_Event &$event, $param) {
@@ -70,17 +71,25 @@ function handle_io_write(Doku_Event &$event, $param) {
send_redirect(wl($ID, array('rev' => $this->helper->getRevision()), true, '&'));
}
- function addApproval() {
+ function addApproval($approvalRevision = null) {
global $USERINFO;
global $ID;
global $INFO;
+ global $REV;
- if (!$INFO['exists']) {
- msg($this->getLang('cannot approve a non-existing revision'), -1);
- return;
+ if($approvalRevision){
+ if ($approvalRevision !== $REV && !page_exists($ID, $approvalRevision)) {
+ msg($this->getLang('cannot approve a non-existing revision'), -1);
+ return;
+ }
+ }else{
+ $approvalRevision = $this->helper->getRevision();
+ if (!$INFO['exists']) {
+ msg($this->getLang('cannot approve a non-existing revision'), -1);
+ return;
+ }
}
- $approvalRevision = $this->helper->getRevision();
$approvals = $this->helper->getApprovals();
if (!isset($approvals[$approvalRevision])) {
@@ -115,4 +124,34 @@ function addApproval() {
}
+ function self_approve(Doku_Event &$event, $param){
+ global $ID;
+ global $ACT;
+ global $INFO;
+ global $conf;
+ $data = pageinfo();
+
+ if ($ACT != 'save' || !$event->result) {
+ return true;
+ }
+
+ // IO_WIKIPAGE_WRITE is always called twice when saving a page. This makes sure to only send the mail once.
+ if (!$event->data[3]) {
+ return true;
+ }
+
+ // Does the publish plugin apply to this page?
+ if (!$this->helper->isActive($ID)) {
+ return true;
+ }
+
+ // are we supposed to auto approve?
+ if (!$this->getConf('auto_self_approve') || !$this->helper->canApprove()) {
+ return true;
+ }
+
+ $this->addApproval($event->data[3]);
+ return true;
+ }
+
}
diff --git a/action/mail.php b/action/mail.php
index 63fb90a..8acc9c2 100644
--- a/action/mail.php
+++ b/action/mail.php
@@ -25,7 +25,7 @@ function __construct() {
public function register(Doku_Event_Handler $controller) {
- $controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'send_change_mail', array());
+ $controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'send_change_mail', array(), 1000);
}
/**
diff --git a/conf/default.php b/conf/default.php
index 8d52fae..695a7ee 100644
--- a/conf/default.php
+++ b/conf/default.php
@@ -6,6 +6,7 @@
$conf['hidereaderbanner'] = 0;
$conf['hide drafts'] = 0;
$conf['hide_approved_banner'] = 0;
+$conf['auto_self_approve'] = 0;
$conf['author groups'] = '';
$conf['internal note'] = '';
$conf['delete attic on first approve'] = 0;
diff --git a/conf/metadata.php b/conf/metadata.php
index cb9ea4b..15349f9 100644
--- a/conf/metadata.php
+++ b/conf/metadata.php
@@ -6,6 +6,7 @@
$meta['hide drafts'] = array('onoff');
$meta['hidereaderbanner'] = array('onoff');
$meta['hide_approved_banner'] = array('onoff');
+$meta['auto_self_approve'] = array('onoff');
$meta['author groups'] = array('string');
$meta['internal note'] = array('string');
$meta['delete attic on first approve'] = array('onoff');
diff --git a/lang/en/settings.php b/lang/en/settings.php
index 9f25083..c3f00a4 100644
--- a/lang/en/settings.php
+++ b/lang/en/settings.php
@@ -6,6 +6,7 @@
$lang['hidereaderbanner'] = 'Hide banner to read only users';
$lang['hide drafts'] = 'Hide drafts to read only users';
$lang['hide_approved_banner'] = 'Hide banner on approved pages';
+$lang['auto_self_approve'] = 'Self approve if possible when submitting edit';
$lang['author groups'] = 'Groups that can see drafts (separate by blank)';
$lang['internal note'] = 'Note on unapproved pages';
$lang['delete attic on first approve'] = 'Delete attic on first approve';