diff --git a/_test/general.test.php b/_test/general.test.php index 2a9cf40..27931c8 100644 --- a/_test/general.test.php +++ b/_test/general.test.php @@ -41,11 +41,11 @@ public function test_plugin_conf() { $conf_file = __DIR__ . '/../conf/default.php'; if (file_exists($conf_file)) { - include($conf_file); + include $conf_file; } $meta_file = __DIR__ . '/../conf/metadata.php'; if (file_exists($meta_file)) { - include($meta_file); + include $meta_file; } $this->assertEquals( diff --git a/_test/revision.test.php b/_test/revision.test.php index ace644a..06f88c1 100644 --- a/_test/revision.test.php +++ b/_test/revision.test.php @@ -12,7 +12,9 @@ */ class revision_plugin_structpublish_test extends DokuWikiTest { - /** @inheritdoc **/ + /** + * @inheritdoc + **/ protected $pluginsEnabled = ['sqlite', 'struct', 'structpublish']; /** @@ -31,7 +33,9 @@ public function setUp(): void $USERINFO['grps'] = ['user', 'approver', 'publisher']; // our database migrations - /** @var action_plugin_structpublish_migration $migration */ + /** + * @var action_plugin_structpublish_migration $migration +*/ $migration = plugin_load('action', 'structpublish_migration'); $data = ''; $migration->handleMigrations(new Doku_Event('DUMMY_EVENT', $data)); diff --git a/action/banner.php b/action/banner.php index c6ccf42..6a9bc02 100644 --- a/action/banner.php +++ b/action/banner.php @@ -9,13 +9,19 @@ */ class action_plugin_structpublish_banner extends DokuWiki_Action_Plugin { - /** @var \helper_plugin_structpublish_db */ + /** + * @var \helper_plugin_structpublish_db + */ protected $dbHelper; - /** @var bool */ + /** + * @var bool + */ protected $compactView; - /** @inheritDoc */ + /** + * @inheritDoc + */ public function register(Doku_Event_Handler $controller) { $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'renderBanner'); @@ -69,10 +75,9 @@ public function renderBanner(Doku_Event $event) } // link to newest draft, if exists, is not shown already and user has a role - if ( - $newestRevision->getRev() != $shownRevision->getRev() && - $newestRevision->getStatus() != Constants::STATUS_PUBLISHED && - $this->dbHelper->checkAccess($ID) + if ($newestRevision->getRev() != $shownRevision->getRev() + && $newestRevision->getStatus() != Constants::STATUS_PUBLISHED + && $this->dbHelper->checkAccess($ID) ) { $banner .= $this->getBannerText('latest_draft', $newestRevision, $shownRevision->getRev()); } @@ -92,8 +97,8 @@ public function renderBanner(Doku_Event $event) /** * Fills place holder texts with data from the given Revision * - * @param string $name - * @param Revision $rev + * @param string $name + * @param Revision $rev * @return string */ protected function getBannerText($name, $rev, $diff = '') @@ -128,9 +133,9 @@ protected function getBannerText($name, $rev, $diff = '') /** * Create a HTML link to a specific revision * - * @param string $id page id - * @param int $rev revision to link to - * @param int $text the link text to use + * @param string $id page id + * @param int $rev revision to link to + * @param int $text the link text to use * @return string */ protected function makeLink($id, $rev, $text) @@ -142,44 +147,61 @@ protected function makeLink($id, $rev, $text) /** * Create the form for approval and publishing * - * @param string $status current status - * @param string $newVersion suggested new Version + * @param string $status current status + * @param string $newVersion suggested new Version * @return string */ protected function actionButtons($status, $newVersion) { + global $ID; + + // If the status is published, return an empty string if ($status === Constants::STATUS_PUBLISHED) { return ''; } + // Create a new form instance $form = new dokuwiki\Form\Form(); - if ( - $status !== Constants::STATUS_APPROVED && - $this->dbHelper->checkAccess($ID, [Constants::ACTION_APPROVE]) + + if ($status !== Constants::STATUS_APPROVED + && $this->dbHelper->checkAccess($ID, [Constants::ACTION_APPROVE]) ) { - $form->addButton( - 'structpublish[' . Constants::ACTION_APPROVE . ']', - $this->getLang('action_' . Constants::ACTION_APPROVE) - )->attr('type', 'submit'); + $form->addButton( + 'structpublish[' . Constants::ACTION_APPROVE . ']', + $this->getLang('action_' . Constants::ACTION_APPROVE) + )->attr('type', 'submit'); } - if ($this->dbHelper->checkAccess($ID, [Constants::ACTION_PUBLISH])) { - $form->addTextInput('version', $this->getLang('newversion'))->val($newVersion); - $form->addButton( - 'structpublish[' . Constants::ACTION_PUBLISH . ']', - $this->getLang('action_' . Constants::ACTION_PUBLISH) - )->attr('type', 'submit'); - } + // Add the publish button only if the status is approved and the user has access + if ((bool)$this->getConf('publish_needs_approve')) { + if ($status === Constants::STATUS_APPROVED && $this->dbHelper->checkAccess($ID, [Constants::ACTION_PUBLISH])) { + $form->addTextInput('version', $this->getLang('newversion'))->val($newVersion); + $form->addButton( + 'structpublish[' . Constants::ACTION_PUBLISH . ']', + $this->getLang('action_' . Constants::ACTION_PUBLISH) + )->attr('type', 'submit'); + } + } else { + if ($this->dbHelper->checkAccess($ID, [Constants::ACTION_PUBLISH])) { + $form->addTextInput('version', $this->getLang('newversion'))->val($newVersion); + $form->addButton( + 'structpublish[' . Constants::ACTION_PUBLISH . ']', + $this->getLang('action_' . Constants::ACTION_PUBLISH) + )->attr('type', 'submit'); + } + } + // Return the HTML representation of the form return $form->toHTML(); } + /** * Tries to increase a given version * - * @param string $version + * @param string $version * @return string */ protected function increaseVersion($version) diff --git a/action/cache.php b/action/cache.php index 3620b69..bb09144 100644 --- a/action/cache.php +++ b/action/cache.php @@ -11,7 +11,7 @@ class action_plugin_structpublish_cache extends DokuWiki_Action_Plugin /** * Registers a callback function for a given event * - * @param Doku_Event_Handler $controller DokuWiki's event controller object + * @param Doku_Event_Handler $controller DokuWiki's event controller object * @return void */ public function register(Doku_Event_Handler $controller) @@ -23,15 +23,19 @@ public function register(Doku_Event_Handler $controller) * For pages containing an aggregation, add structpublish flag to cache key * to differentiate between caches for regular and privileged users * - * @param Doku_Event $event event object by reference + * @param Doku_Event $event event object by reference * @return bool */ public function handleCacheAggregation(Doku_Event $event) { - /** @var \dokuwiki\Cache\CacheParser $cache */ + /** + * @var \dokuwiki\Cache\CacheParser $cache +*/ $cache = $event->data; - if ($cache->mode != 'xhtml') return true; - if (!$cache->page) return true; // not a page cache + if ($cache->mode != 'xhtml') { return true; + } + if (!$cache->page) { return true; // not a page cache + } $meta = p_get_metadata($cache->page, 'plugin struct'); if (isset($meta['hasaggregation'])) { diff --git a/action/dw2pdf.php b/action/dw2pdf.php new file mode 100644 index 0000000..a1b94c6 --- /dev/null +++ b/action/dw2pdf.php @@ -0,0 +1,115 @@ + + * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html + */ + +class action_plugin_structpublish_dw2pdf extends DokuWiki_Action_Plugin +{ + /** + * @var \helper_plugin_structpublish_db + */ + protected $dbHelper; + + public function register(Doku_Event_Handler $controller) + { + $controller->register_hook('PLUGIN_DW2PDF_REPLACE', 'BEFORE', $this, 'provide_structpublish_replacements'); + $controller->register_hook('PLUGIN_DW2PDF_REPLACE', 'AFTER', $this, 'clean_structpublish_replacements'); + } + + /** + * Provide StructPublish values for DW2PDF replacements + */ + public function provide_structpublish_replacements(Doku_Event $event) + { + global $ID; + global $INFO; + global $REV; + + $this->dbHelper = plugin_load('helper', 'structpublish_db'); + + if (!$this->dbHelper->isPublishable()) { + return; + } + + // get revisions + $newestRevision = new Revision($ID, $INFO['currentrev']); + if ($REV) { + $shownRevision = new Revision($ID, $REV); + } else { + $shownRevision = $newestRevision; + } + $latestpubRevision = $newestRevision->getLatestPublishedRevision(); + $prevpubRevision = $shownRevision->getLatestPublishedRevision($REV ?: $INFO['currentrev']); + $prevapprovedRevision = $shownRevision->getLatestApprovedRevision($REV ?: $INFO['currentrev']); + + //get redactor + $pageMeta = p_get_metadata($ID); + $event->data['replace']['@REDACTOR@'] = $pageMeta['last_change']['user']; + + // get last published version + if ($latestpubRevision != null) { + $event->data['replace']['@LATESTVERSION@'] = $latestpubRevision->getVersion(); + }else{ + $event->data['replace']['@LATESTVERSION@'] = $this->getLang("status_na"); + } + + // get status + $event->data['replace']['@STATUS@'] = $this->getLang("status_" . $shownRevision->getStatus()); + + // status draft + if ($event->data['replace']['@STATUS@'] === $this->getLang("status_draft")) { + $event->data['replace']['@VERSION@'] = $this->getLang("status_draft"); + $event->data['replace']['@APPROVER@'] = $this->getLang("status_na"); + $event->data['replace']['@APPROVALDATE@'] = $this->getLang("status_na"); + $event->data['replace']['@PUBLISHER@'] = $this->getLang("status_na"); + $event->data['replace']['@PUBLISHDATE@'] = $this->getLang("status_na"); + } + + // status approved + if ($event->data['replace']['@STATUS@'] === $this->getLang("status_approved")) { + $event->data['replace']['@VERSION@'] = $this->getLang("status_approved"); + $event->data['replace']['@APPROVER@'] = $shownRevision->getUser(); + $event->data['replace']['@APPROVALDATE@'] = $shownRevision->getDateTime(); + $event->data['replace']['@PUBLISHER@'] = $this->getLang("status_na"); + $event->data['replace']['@PUBLISHDATE@'] = $this->getLang("status_na"); + } + + // status published + if ($event->data['replace']['@STATUS@'] === $this->getLang("status_published")) { + $event->data['replace']['@VERSION@'] = $shownRevision->getVersion(); + $event->data['replace']['@APPROVER@'] = $prevapprovedRevision->getUser(); + $event->data['replace']['@APPROVALDATE@'] = $prevapprovedRevision->getDateTime(); + $event->data['replace']['@PUBLISHER@'] = $shownRevision->getUser(); + $event->data['replace']['@PUBLISHDATE@'] = $shownRevision->getDateTime(); + } + + } + + + /** + * Clean up replacements in DW2PDF content + */ + public function clean_structpublish_replacements(Doku_Event $event) + { + $event->data['content'] = str_replace( + ['@APPROVER@', '@APPROVALDATE@', '@PUBLISHER@', '@PUBLISHDATE@', '@VERSION@', '@STATUS@', '@REDACTOR@' , '@LATESTVERSION@'], + ['', '', '', '', '', '', '', ''], + $event->data['content'] + ); + } +} diff --git a/action/migration.php b/action/migration.php index 74944fd..e83734a 100644 --- a/action/migration.php +++ b/action/migration.php @@ -6,7 +6,9 @@ class action_plugin_structpublish_migration extends DokuWiki_Action_Plugin { public const MIN_DB_STRUCT = 19; - /** @var string */ + /** + * @var string + */ protected $table = 'data_structpublish'; /** @@ -22,13 +24,15 @@ public function register(Doku_Event_Handler $controller) * so we cannot use the mechanism in sqlite init() * which processes updateXXXX.sql files * - * @param Doku_Event $event + * @param Doku_Event $event * @return bool * @throws Exception */ public function handleMigrations(Doku_Event $event) { - /** @var \helper_plugin_struct_db $helper */ + /** + * @var \helper_plugin_struct_db $helper +*/ $helper = plugin_load('helper', 'struct_db'); // abort if struct is not installed @@ -79,7 +83,7 @@ public function handleMigrations(Doku_Event $event) /** * Read the current versions for struct and struct publish from the database * - * @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite + * @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite * @return array [structversion, structpublishversion] */ protected function getDbVersions($sqlite) @@ -112,7 +116,7 @@ protected function getLatestVersion() /** * Database setup * - * @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite + * @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite * @return bool */ protected function migration1($sqlite) @@ -137,7 +141,7 @@ protected function migration1($sqlite) * Reset 'latest' flag to 0 for all rows except actually latest ones * for each pid / status combination. * - * @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite + * @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite * @return bool */ protected function migration2($sqlite) @@ -155,7 +159,7 @@ protected function migration2($sqlite) * Set 'latest' flag to 0 for all rows except actually latest ones * for each page, * - * @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite + * @param \dokuwiki\plugin\sqlite\SQLiteDB $sqlite * @return bool */ protected function migration3($sqlite) diff --git a/action/publish.php b/action/publish.php index 859c3ca..575c331 100644 --- a/action/publish.php +++ b/action/publish.php @@ -4,7 +4,9 @@ class action_plugin_structpublish_publish extends DokuWiki_Action_Plugin { - /** @inheritDoc */ + /** + * @inheritDoc + */ public function register(Doku_Event_Handler $controller) { $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'changeStatus'); @@ -13,7 +15,7 @@ public function register(Doku_Event_Handler $controller) /** * Handle the publish button and version field * - * @param Doku_Event $event + * @param Doku_Event $event * @return void * @throws Exception */ @@ -31,13 +33,18 @@ public function changeStatus(Doku_Event $event) return; } - if (!checkSecurityToken()) return; + if (!checkSecurityToken()) { return; + } - /** @var helper_plugin_structpublish_publish $helper */ + /** + * @var helper_plugin_structpublish_publish $helper +*/ $helper = plugin_load('helper', 'structpublish_publish'); $newRevision = $helper->saveRevision(key($in), $INPUT->str('version')); - /** @var helper_plugin_structpublish_notify $notifyHelper */ + /** + * @var helper_plugin_structpublish_notify $notifyHelper +*/ $notifyHelper = plugin_load('helper', 'structpublish_notify'); $notifyHelper->sendEmails($action, $newRevision); } diff --git a/action/revisions.php b/action/revisions.php index 108bb7c..3200798 100644 --- a/action/revisions.php +++ b/action/revisions.php @@ -13,17 +13,21 @@ public function register(Doku_Event_Handler $controller) /** * Adds publish info to page revisions * - * @param Doku_Event $event + * @param Doku_Event $event * @return void */ public function handleRevisions(Doku_Event $event) { global $INFO; - /** @var dokuwiki\Form\Form $form */ + /** + * @var dokuwiki\Form\Form $form +*/ $form = $event->data; - /** @var helper_plugin_structpublish_db $helper */ + /** + * @var helper_plugin_structpublish_db $helper +*/ $helper = plugin_load('helper', 'structpublish_db'); if (!$helper->isPublishable()) { @@ -53,10 +57,9 @@ public function handleRevisions(Doku_Event $event) $version = $revision->getVersion(); // insert status for published revisions - if ( - is_a($el, \dokuwiki\Form\HTMLElement::class) && - !empty(trim($el->val())) && - $status === Constants::STATUS_PUBLISHED + if (is_a($el, \dokuwiki\Form\HTMLElement::class) + && !empty(trim($el->val())) + && $status === Constants::STATUS_PUBLISHED ) { $val = $el->val(); $label = '' . diff --git a/action/save.php b/action/save.php index 8ebee3b..bd84f87 100644 --- a/action/save.php +++ b/action/save.php @@ -10,7 +10,9 @@ */ class action_plugin_structpublish_save extends DokuWiki_Action_Plugin { - /** @inheritDoc */ + /** + * @inheritDoc + */ public function register(Doku_Event_Handler $controller) { $controller->register_hook('COMMON_WIKIPAGE_SAVE', 'AFTER', $this, 'handleSave'); @@ -19,12 +21,14 @@ public function register(Doku_Event_Handler $controller) /** * Handle the page save event to store revision meta data * - * @param Doku_Event $event + * @param Doku_Event $event * @return void */ public function handleSave(Doku_Event $event) { - /** @var helper_plugin_structpublish_db $dbHelper */ + /** + * @var helper_plugin_structpublish_db $dbHelper +*/ $dbHelper = plugin_load('helper', 'structpublish_db'); $id = $event->data['id']; diff --git a/action/show.php b/action/show.php index e1c7144..03d9cab 100644 --- a/action/show.php +++ b/action/show.php @@ -5,10 +5,14 @@ class action_plugin_structpublish_show extends DokuWiki_Action_Plugin { - /** @var int */ + /** + * @var int + */ protected static $latestPublishedRev; - /** @inheritDoc */ + /** + * @inheritDoc + */ public function register(Doku_Event_Handler $controller) { $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleShow'); @@ -18,7 +22,7 @@ public function register(Doku_Event_Handler $controller) /** * Decide which revision to show based on role assignments * - * @param Doku_Event $event + * @param Doku_Event $event * @return void */ public function handleShow(Doku_Event $event) @@ -31,12 +35,13 @@ public function handleShow(Doku_Event $event) global $REV; global $INFO; - /** @var helper_plugin_structpublish_db $dbHelper */ + /** + * @var helper_plugin_structpublish_db $dbHelper +*/ $dbHelper = plugin_load('helper', 'structpublish_db'); - if ( - !$dbHelper->isPublishable() || - (auth_isadmin() && !$this->getConf('restrict_admin')) + if (!$dbHelper->isPublishable() + || (auth_isadmin() && !$this->getConf('restrict_admin')) ) { return; } @@ -67,17 +72,18 @@ public function handleShow(Doku_Event $event) * Suppress message about viewing an old revision if it is the latest one * that the current user is allowed to see. * - * @param Doku_Event $event + * @param Doku_Event $event * @return void */ public function handleShowrev(Doku_Event $event) { - /** @var helper_plugin_structpublish_db $dbHelper */ + /** + * @var helper_plugin_structpublish_db $dbHelper +*/ $dbHelper = plugin_load('helper', 'structpublish_db'); - if ( - !$dbHelper->isPublishable() || - (auth_isadmin() && !$this->getConf('restrict_admin')) + if (!$dbHelper->isPublishable() + || (auth_isadmin() && !$this->getConf('restrict_admin')) ) { return; } diff --git a/helper/assignments.php b/helper/assignments.php index 29201ec..3765bfa 100644 --- a/helper/assignments.php +++ b/helper/assignments.php @@ -11,9 +11,9 @@ class helper_plugin_structpublish_assignments extends DokuWiki_Plugin /** * Check if the given pattern matches the given page * - * @param string $pattern the pattern to check against - * @param string $page the cleaned pageid to check - * @param string|null $pns optimization, the colon wrapped namespace of the page, set null for automatic + * @param string $pattern the pattern to check against + * @param string $page the cleaned pageid to check + * @param string|null $pns optimization, the colon wrapped namespace of the page, set null for automatic * @return bool * @author Andreas Gohr */ diff --git a/helper/db.php b/helper/db.php index 2c28159..4a84f46 100644 --- a/helper/db.php +++ b/helper/db.php @@ -15,7 +15,9 @@ class helper_plugin_structpublish_db extends DokuWiki_Plugin */ public function getDB() { - /** @var helper_plugin_struct_db $struct */ + /** + * @var helper_plugin_struct_db $struct +*/ $struct = plugin_load('helper', 'struct_db'); if (!$struct) { // FIXME show message? @@ -77,8 +79,8 @@ public function isPublishable($pid = null) /** * Check if the current user has the given roles on the current page * - * @param string $pid The page ID to check access for - * @param string[] $roles Roles needed. Empty for any role + * @param string $pid The page ID to check access for + * @param string[] $roles Roles needed. Empty for any role * @return bool */ public function checkAccess($pid, $roles = []) @@ -91,7 +93,7 @@ public function checkAccess($pid, $roles = []) * * Params are read via function args * - * @param ...string $pid, $userId, $groups... + * @param ...string $pid, $userId, $groups... * @return int Return an integer instead of boolean for better sqlite compatibility */ public function isPublisher() @@ -120,10 +122,10 @@ public function isPublisher() /** * Check if a given user has role assignment for a given page * - * @param string $pid Page to check - * @param string $userId User login name, current user if empty - * @param string[] $grps Groups the user has, current user's groups if empty user - * @param string[] $roles Roles the user should have, empty for any role + * @param string $pid Page to check + * @param string $userId User login name, current user if empty + * @param string[] $grps Groups the user has, current user's groups if empty user + * @param string[] $roles Roles the user should have, empty for any role * @return bool */ public static function userHasRole($pid, $userId = '', $grps = [], $roles = []) diff --git a/helper/notify.php b/helper/notify.php index abf87d8..3241383 100644 --- a/helper/notify.php +++ b/helper/notify.php @@ -10,7 +10,9 @@ */ class helper_plugin_structpublish_notify extends DokuWiki_Plugin { - /** @var helper_plugin_structpublish_db */ + /** + * @var helper_plugin_structpublish_db + */ protected $dbHelper; public function __construct() @@ -21,8 +23,8 @@ public function __construct() /** * If activated, send emails on configured status changes. * - * @param string $action - * @param Revision $newRevision + * @param string $action + * @param Revision $newRevision * @return void * @throws Exception */ @@ -62,8 +64,8 @@ public function sendEmails($action, $newRevision) } /** - * @param string $recipients Comma separated list of emails - * @param string $mailText + * @param string $recipients Comma separated list of emails + * @param string $mailText * @return void */ public function sendMail($recipients, $mailText) @@ -83,7 +85,7 @@ public function sendMail($recipients, $mailText) * and returns an array of emails * with user groups resolved to individual users * - * @param array $recipients + * @param array $recipients * @return array * @throws Exception */ @@ -108,14 +110,16 @@ public function resolveRecipients($recipients) } /** - * @param array $resolved - * @param string $recipient + * @param array $resolved + * @param string $recipient * @return void * @throws Exception */ protected function resolveGroup(&$resolved, $recipient) { - /** @var AuthPlugin $auth */ + /** + * @var AuthPlugin $auth +*/ global $auth; if (!$auth->canDo('getUsers')) { throw new \Exception('Auth cannot fetch users by group.'); @@ -129,13 +133,15 @@ protected function resolveGroup(&$resolved, $recipient) } /** - * @param array $resolved - * @param string $recipient + * @param array $resolved + * @param string $recipient * @return void */ protected function resolveUser(&$resolved, $recipient) { - /** @var AuthPlugin $auth */ + /** + * @var AuthPlugin $auth +*/ global $auth; $user = $auth->getUserData($recipient); if ($user) { diff --git a/helper/publish.php b/helper/publish.php index fd0773f..6dad4f7 100644 --- a/helper/publish.php +++ b/helper/publish.php @@ -12,7 +12,9 @@ */ class helper_plugin_structpublish_publish extends DokuWiki_Plugin { - /** @var helper_plugin_structpublish_db */ + /** + * @var helper_plugin_structpublish_db + */ protected $dbHelper; public function __construct() @@ -23,7 +25,7 @@ public function __construct() /** * Save publish data * - * @param string $action + * @param string $action * @return Revision * @throws Exception */ @@ -38,6 +40,15 @@ public function saveRevision($action, $newversion = '') $revision = new Revision($ID, $INFO['currentrev']); + //do nothing if the current revison have already been approved + if ($action === Constants::ACTION_APPROVE && $revision->getLatestApprovedRevision() !== null && $revision->getRev() == $revision->getLatestApprovedRevision()->getRev()) { + return $revision; + } + //do nothing if the current revison have already been published + if ($action === Constants::ACTION_PUBLISH && $revision->getLatestPublishedRevision() !== null && $revision->getRev() == $revision->getLatestPublishedRevision()->getRev()) { + return $revision; + } + if ($action === Constants::ACTION_PUBLISH) { $revision->setVersion($newversion); } diff --git a/lang/de/lang.php b/lang/de/lang.php index 27535e0..ea545ae 100644 --- a/lang/de/lang.php +++ b/lang/de/lang.php @@ -16,6 +16,7 @@ $lang['status_draft'] = 'Entwurf'; $lang['status_approved'] = 'Zur Freigabe bereit'; $lang['status_published'] = 'Freigegeben'; +$lang['status_na'] = 'k.A.'; $lang['action_approve'] = 'Zur Freigabe bereitstellen'; $lang['action_publish'] = 'Freigeben'; diff --git a/lang/de/settings.php b/lang/de/settings.php index f6d41e4..28709e8 100644 --- a/lang/de/settings.php +++ b/lang/de/settings.php @@ -4,3 +4,5 @@ $lang['email_enable'] = 'E-Mails aktivieren'; $lang['email_status'] = 'Bei welchen Statusänderungen sollen E-Mails versendet werden?'; $lang['compact_view'] = 'Kompakter Banner'; +$lang['publish_needs_approve'] = 'Seiten müssen vor ihrer Veröffentlichung genehmigt werden'; + diff --git a/lang/en/lang.php b/lang/en/lang.php index 3ee9718..9f01a0b 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -16,6 +16,7 @@ $lang['status_draft'] = 'Draft'; $lang['status_approved'] = 'Approved'; $lang['status_published'] = 'Published'; +$lang['status_na'] = 'N/A'; $lang['action_approve'] = 'Approve'; $lang['action_publish'] = 'Publish'; diff --git a/lang/en/settings.php b/lang/en/settings.php index 6c161b7..3b3b9a5 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -4,3 +4,5 @@ $lang['email_enable'] = 'Send emails'; $lang['email_status'] = 'Status changes that trigger emails'; $lang['compact_view'] = 'Compact banner'; +$lang['publish_needs_approve'] = 'Pages must be approved before being published'; + diff --git a/lang/es/lang.php b/lang/es/lang.php new file mode 100644 index 0000000..0a87990 --- /dev/null +++ b/lang/es/lang.php @@ -0,0 +1,44 @@ +borrador en progreso, creado el {revision}.'; +$lang['banner_status_approved'] = 'Esta revisión de la página ha sido aprobada para su publicación el {datetime} por {user}.'; +$lang['banner_status_published'] = 'Esta revisión de la página ha sido publicada como versión "{version}" el {datetime} por {user}.'; +$lang['banner_latest_publish'] = 'La página fue publicada más recientemente como versión {version} por {user} el {datetime}.'; +$lang['banner_previous_publish'] = 'La página fue publicada anteriormente como versión {version} por {user} el {datetime}.'; +$lang['banner_latest_draft'] = 'Existe un borrador más reciente creado el {revision}.'; +$lang['compact_banner_status_draft'] = 'Borrador'; +$lang['compact_banner_status_approved'] = 'Aprobado'; +$lang['compact_banner_status_published'] = 'Publicado como versión "{version}" el {datetime} por {user}'; +$lang['compact_banner_latest_publish'] = ''; +$lang['compact_banner_previous_publish'] = ''; +$lang['compact_banner_latest_draft'] = 'Borrador más reciente: {revision}'; + +// administración +$lang['assign_pattern'] = 'Patrón'; +$lang['assign_user'] = 'Usuario o @grupo'; +$lang['assign_status'] = 'Estado'; +$lang['assign_add'] = 'Añadir asignación'; +$lang['assign_del'] = 'Eliminar asignación'; + +// correo electrónico +$lang['email_subject'] = 'El estado de publicación de una página wiki ha cambiado'; +$lang['email_error_norecipients'] = '¡No se encontraron destinatarios para notificar!'; diff --git a/lang/es/mail.txt b/lang/es/mail.txt new file mode 100644 index 0000000..0b5e4ed --- /dev/null +++ b/lang/es/mail.txt @@ -0,0 +1,6 @@ +Hola, + +Te informamos que el estado de la página “@PAGE@” ha cambiado a @STATUS_CURRENT@. + +Puedes tomar medidas aquí: @URL@ + diff --git a/lang/es/settings.php b/lang/es/settings.php new file mode 100644 index 0000000..3edd4a8 --- /dev/null +++ b/lang/es/settings.php @@ -0,0 +1,7 @@ +brouillon en cours, créé le {revision}.'; +$lang['banner_status_approved'] = 'Cette révision de la page a été approuvée pour publication le {datetime} par {user}.'; +$lang['banner_status_published'] = 'Cette révision de la page a été publiée en tant que version "{version}" le {datetime} par {user}.'; +$lang['banner_latest_publish'] = 'La page a été publiée pour la dernière fois en tant que version {version} par {user} le {datetime}.'; +$lang['banner_previous_publish'] = 'La page a été précédemment publiée en tant que version {version} par {user} le {datetime}.'; +$lang['banner_latest_draft'] = 'Un brouillon plus récent a été créé le {revision}.'; +$lang['compact_banner_status_draft'] = 'Brouillon'; +$lang['compact_banner_status_approved'] = 'Approuvé'; +$lang['compact_banner_status_published'] = 'Publié en tant que version "{version}" le {datetime} par {user}'; +$lang['compact_banner_latest_publish'] = ''; +$lang['compact_banner_previous_publish'] = ''; +$lang['compact_banner_latest_draft'] = 'Brouillon plus récent : {revision}'; + +// admin +$lang['assign_pattern'] = 'Modèle'; +$lang['assign_user'] = 'Utilisateur ou @group'; +$lang['assign_status'] = 'Statut'; +$lang['assign_add'] = 'Ajouter une attribution'; +$lang['assign_del'] = 'Supprimer une attribution'; + +// email +$lang['email_subject'] = 'Le statut de publication d’une page wiki a changé'; +$lang['email_error_norecipients'] = 'Aucun destinataire trouvé pour la notification !'; + diff --git a/lang/fr/mail.txt b/lang/fr/mail.txt new file mode 100644 index 0000000..5080b6a --- /dev/null +++ b/lang/fr/mail.txt @@ -0,0 +1,5 @@ +Bonjour, + +Ceci est une notification pour vous informer que le statut de la page « @PAGE@ » a changé pour @STATUS_CURRENT@. + +Vous pouvez agir dessus ici : @URL@ diff --git a/lang/fr/settings.php b/lang/fr/settings.php new file mode 100644 index 0000000..2310306 --- /dev/null +++ b/lang/fr/settings.php @@ -0,0 +1,8 @@ +published = (int) $published; } - /** @inheritDoc */ + /** + * @inheritDoc + */ protected function getSingleSql() { $cols = array_merge($this->getSingleNoninputCols(), $this->singleCols); @@ -37,19 +39,25 @@ protected function getSingleSql() VALUES ($rid," . trim(str_repeat('?,', count($vals)), ',') . ');'; } - /** @inheritDoc */ + /** + * @inheritDoc + */ protected function getMultiSql() { return ''; } - /** @inheritDoc */ + /** + * @inheritDoc + */ protected function getSingleNoninputCols() { return ['pid', 'rev', 'latest', 'published']; } - /** @inheritDoc */ + /** + * @inheritDoc + */ protected function getSingleNoninputValues() { return [$this->pid, AccessTable::DEFAULT_REV, AccessTable::DEFAULT_LATEST, $this->published]; @@ -57,7 +65,7 @@ protected function getSingleNoninputValues() /** * @inheritdoc - * @return int|bool + * @return int|bool */ protected function getLastRevisionTimestamp() { @@ -69,7 +77,9 @@ protected function getLastRevisionTimestamp() $opts[] = $this->ts; } - /** @noinspection SqlResolve */ + /** + * @noinspection SqlResolve +*/ $sql = "SELECT rev FROM $table $where ORDER BY rev DESC LIMIT 1"; $ret = $this->sqlite->queryValue($sql, $opts); @@ -86,7 +96,9 @@ protected function getLastRevisionTimestamp() */ protected function beforeSave() { - /** @noinspection SqlResolve */ + /** + * @noinspection SqlResolve +*/ return $this->sqlite->query( "UPDATE $this->stable SET latest = 0 WHERE latest = 1 AND pid = ?", [$this->pid] diff --git a/meta/Assignments.php b/meta/Assignments.php index 9658acd..9f16716 100644 --- a/meta/Assignments.php +++ b/meta/Assignments.php @@ -14,19 +14,25 @@ */ class Assignments { - /** @var SQLiteDB */ + /** + * @var SQLiteDB + */ protected $sqlite; - /** @var array All the assignments patterns */ + /** + * @var array All the assignments patterns + */ protected $patterns; - /** @var Assignments */ + /** + * @var Assignments + */ protected static $instance = null; /** * Get the singleton instance of the Assignments * - * @param bool $forcereload create a new instance to reload the assignment data + * @param bool $forcereload create a new instance to reload the assignment data * @return Assignments */ public static function getInstance($forcereload = false) @@ -45,7 +51,9 @@ public static function getInstance($forcereload = false) */ protected function __construct() { - /** @var \helper_plugin_structpublish_db $helper */ + /** + * @var \helper_plugin_structpublish_db $helper +*/ $helper = plugin_load('helper', 'struct_db'); $this->sqlite = $helper->getDB(); @@ -64,9 +72,9 @@ protected function loadPatterns() /** * Add a new assignment pattern to the pattern table * - * @param string $pattern - * @param string $user - * @param string $status + * @param string $pattern + * @param string $user + * @param string $status * @return bool */ public function addPattern($pattern, $user, $status) @@ -80,7 +88,9 @@ public function addPattern($pattern, $user, $status) // update assignments // fetch known pages - /** @var \helper_plugin_structpublish_db $dbHelper */ + /** + * @var \helper_plugin_structpublish_db $dbHelper +*/ $dbHelper = plugin_load('helper', 'structpublish_db'); $pids = $dbHelper->getPages(); @@ -102,9 +112,9 @@ public function addPattern($pattern, $user, $status) /** * Remove an existing assignment pattern from the pattern table * - * @param string $pattern - * @param string $user - * @param string $status + * @param string $pattern + * @param string $user + * @param string $status * @return bool */ public function removePattern($pattern, $user, $status) @@ -155,7 +165,7 @@ public function updatePageAssignments($pid, $reload = false) * * This is mostly useful for testing and not used in the interface currently * - * @param bool $full fully delete all previous assignments + * @param bool $full fully delete all previous assignments * @return bool */ public function clear($full = false) @@ -179,9 +189,9 @@ public function clear($full = false) /** * Add page to assignments * - * @param string $page - * @param string $user - * @param string $status + * @param string $page + * @param string $user + * @param string $status * @return bool */ public function assignPage($page, $user = null, $status = null) @@ -193,8 +203,8 @@ public function assignPage($page, $user = null, $status = null) /** * Remove page from assignments * - * @param string $page - * @param string $user + * @param string $page + * @param string $user * @return bool */ public function deassignPage($page, $user, $status) @@ -216,8 +226,8 @@ public function getAllPatterns() /** * Returns a list of user/group string lists per status assigned to the given page * - * @param string $page - * @param bool $checkpatterns Should the current patterns be re-evaluated? + * @param string $page + * @param bool $checkpatterns Should the current patterns be re-evaluated? * @return array users assigned [role => [user, ...], ...] */ public function getPageAssignments($page, $checkpatterns = true) @@ -249,7 +259,7 @@ public function getPageAssignments($page, $checkpatterns = true) /** * Get the pages known to struct and their assignment state * - * @param bool $assignedonly limit results to currently assigned only + * @param bool $assignedonly limit results to currently assigned only * @return array */ public function getPages($assignedOnly = false) diff --git a/meta/Constants.php b/meta/Constants.php index e2c3979..8f94cb9 100644 --- a/meta/Constants.php +++ b/meta/Constants.php @@ -21,7 +21,7 @@ class Constants /** * Convenience function mapping transition actions to resulting status * - * @param string $action + * @param string $action * @return string */ public static function transitionBy($action) diff --git a/meta/Revision.php b/meta/Revision.php index 3f1e3a7..0175c7d 100644 --- a/meta/Revision.php +++ b/meta/Revision.php @@ -13,7 +13,9 @@ */ class Revision { - /** @var SQLiteDB */ + /** + * @var SQLiteDB + */ protected $sqlite; protected $schema; @@ -25,7 +27,9 @@ class Revision protected $version; protected $user; protected $datetime; - /** @var bool|\dokuwiki\plugin\struct\meta\Column */ + /** + * @var bool|\dokuwiki\plugin\struct\meta\Column + */ protected $statusCol; protected $versionCol; protected $userCol; @@ -35,8 +39,8 @@ class Revision /** * Constructor * - * @param string $id page id - * @param int $rev revision + * @param string $id page id + * @param int $rev revision */ public function __construct($id, $rev) { @@ -52,7 +56,9 @@ public function __construct($id, $rev) $this->datetimeCol = $this->schema->findColumn('datetime'); $this->revisionCol = $this->schema->findColumn('revision'); - /** @var Value[] $values */ + /** + * @var Value[] $values +*/ $values = $this->getCoreData(['revision=' . $this->rev]); if (!empty($values)) { @@ -210,7 +216,7 @@ public function getId() * Update publish status in the core table * * @param string $pid - * @param int $rid + * @param int $rid */ protected function updateCoreData($pid, $rid = 0) { @@ -234,7 +240,7 @@ protected function updateCoreData($pid, $rid = 0) * * @see https://www.dokuwiki.org/plugin:struct:filters * - * @param array $andFilters + * @param array $andFilters * @return array|Value[] */ public function getCoreData($andFilters = []) @@ -268,7 +274,7 @@ public function getCoreData($andFilters = []) * Return "latest" published revision of a given page. * If $rev is specified, "latest" means relative to the $rev revision. * - * @param int|null $rev + * @param int|null $rev * @return Revision|null */ public function getLatestPublishedRevision($rev = null) @@ -295,4 +301,36 @@ public function getLatestPublishedRevision($rev = null) return $published; } + + /** + * Return "latest" approved revision of a given page. + * If $rev is specified, "latest" means relative to the $rev revision. + * + * @param int|null $rev + * @return Revision|null + */ + public function getLatestApprovedRevision($rev = null) + { + $andFilters[] = 'status=' . Constants::STATUS_APPROVED; + if ($rev) { + $andFilters[] .= 'revision=' . $rev; + } + $latestApproved = $this->getCoreData($andFilters); + + if (empty($latestApproved)) { + return null; + } + + $approved = new Revision( + $this->id, + $latestApproved[$this->revisionCol->getColref() - 1]->getRawValue() + ); + + $approved->setStatus($latestApproved[$this->statusCol->getColref() - 1]->getRawValue()); + $approved->setUser($latestApproved[$this->userCol->getColref() - 1]->getRawValue()); + $approved->setDatetime($latestApproved[$this->datetimeCol->getColref() - 1]->getRawValue()); + $approved->setVersion($latestApproved[$this->versionCol->getColref() - 1]->getRawValue()); + + return $approved; + } } diff --git a/plugin.info.txt b/plugin.info.txt index 66b98b0..8893110 100644 --- a/plugin.info.txt +++ b/plugin.info.txt @@ -1,7 +1,7 @@ base structpublish author Anna Dabrowska email dokuwiki@cosmocode.de -date 2024-05-20 +date 2025-03-11 name structpublish plugin desc Publishing workflows based on struct url https://dokuwiki.org/plugin:structpublish diff --git a/syntax/table.php b/syntax/table.php index fcce570..36e60e0 100644 --- a/syntax/table.php +++ b/syntax/table.php @@ -12,13 +12,17 @@ class syntax_plugin_structpublish_table extends syntax_plugin_struct_serial { protected $tableclass = AggregationTable::class; - /** @inheritdoc */ + /** + * @inheritdoc + */ public function connectTo($mode) { $this->Lexer->addSpecialPattern('----+ *structpublish *-+\n.*?\n?----+', $mode, 'plugin_structpublish_table'); } - /** @inheritdoc */ + /** + * @inheritdoc + */ protected function addTypeFilter($config) { $config['schemas'][] = ['structpublish', 'structpublish'];