Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _test/general.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions _test/revision.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
*/
class revision_plugin_structpublish_test extends DokuWikiTest
{
/** @inheritdoc **/
/**
* @inheritdoc
**/
protected $pluginsEnabled = ['sqlite', 'struct', 'structpublish'];

/**
Expand All @@ -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));
Expand Down
80 changes: 51 additions & 29 deletions action/banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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());
}
Expand All @@ -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 = '')
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions action/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'])) {
Expand Down
115 changes: 115 additions & 0 deletions action/dw2pdf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

use dokuwiki\plugin\structpublish\meta\Constants;
use dokuwiki\plugin\structpublish\meta\Revision;

/**
* Action component providing (localized) dw2pdf replacements
*
* @STATUS@ draft / approved / published
* @APPROVER@ user that approved the draft
* @APPROVALDATE@ date of approval
* @PUBLISHER@ user that published the page
* @PUBLISHDATE@ date of publishing
* @VERSION@ draft / approved / published
* @LATESTVERSION@ latest published version
*
* @author Josquin DEHAENE <josquin@moka.works>
* @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']
);
}
}
18 changes: 11 additions & 7 deletions action/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading