Skip to content

Commit

Permalink
viewmode is turn off by default
Browse files Browse the repository at this point in the history
  • Loading branch information
solewniczak committed Feb 14, 2023
1 parent eb084c5 commit c708a86
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
7 changes: 4 additions & 3 deletions action/editmode.php → action/viewmode.php
Expand Up @@ -14,7 +14,7 @@
* @author Anika Henke <anika@selfthinker.org>
*/

class action_plugin_approve_editmode extends DokuWiki_Action_Plugin
class action_plugin_approve_viewmode extends DokuWiki_Action_Plugin
{
/** @inheritdoc */
function register(Doku_Event_Handler $controller)
Expand All @@ -26,6 +26,7 @@ function register(Doku_Event_Handler $controller)

public function handleAct(Doku_Event $event)
{
if (!$this->getConf('viewmode')) return;
if ($event->data != 'viewmodesitetools' && $event->data != 'viewmodeedit') return;
$viewmode = get_doku_pref('approve_viewmode', false);
set_doku_pref('approve_viewmode', !$viewmode); // toggle status
Expand All @@ -41,7 +42,7 @@ public function handleAct(Doku_Event $event)
public function addSiteTools(Doku_Event $event)
{
global $INPUT;

if (!$this->getConf('viewmode')) return false;
if (!$INPUT->server->str('REMOTE_USER')) return false;
if ($event->data['view'] != 'user') return false;

Expand All @@ -53,7 +54,7 @@ public function addSiteTools(Doku_Event $event)
public function addPageTools(Doku_Event $event)
{
global $INPUT;

if (!$this->getConf('viewmode')) return false;
if (!$INPUT->server->str('REMOTE_USER')) return false;
if ($event->data['view'] != 'page') return false;

Expand Down
1 change: 1 addition & 0 deletions conf/default.php
Expand Up @@ -12,3 +12,4 @@

$conf['display_banner_for_readonly'] = 1;
$conf['banner_long'] = 1;
$conf['viewmode'] = 0;
1 change: 1 addition & 0 deletions conf/metadata.php
Expand Up @@ -6,3 +6,4 @@
$meta['banner_long'] = array('onoff');
$meta['strict_approver'] = array('onoff', '_caution' => 'security');
$meta['hide_drafts_for_viewers'] = array('onoff', '_caution' => 'security');
$meta['viewmode'] = array('onoff');
3 changes: 3 additions & 0 deletions helper.php
Expand Up @@ -249,6 +249,9 @@ public function client_can_mark_ready_for_approval($id) {
* @return bool
*/
public function client_can_see_drafts($id, $pageApprover) {
// in view mode no one can see drafts
if ($this->getConf('viewmode') && get_doku_pref('approve_viewmode', false)) return false;

if (!$this->getConf('hide_drafts_for_viewers')) return true;

if (auth_quickaclcheck($id) >= AUTH_EDIT) return true;
Expand Down
3 changes: 2 additions & 1 deletion lang/en/settings.php
Expand Up @@ -5,4 +5,5 @@
$lang['strict_approver'] = 'Only approvers can approve their pages.';
$lang['hide_drafts_for_viewers'] = 'Hide draft from users without edit permission and show the latest approved revision instead.';
$lang['display_banner_for_readonly'] = 'Display banner for users with AUTH_READ only.';
$lang['banner_long'] = 'Long banner including version number and approver';
$lang['banner_long'] = 'Long banner including version number and approver.';
$lang['viewmode'] = 'Enables View/Edit mode toggle button. In view mode no one can see drafts.';
2 changes: 1 addition & 1 deletion meta/ViewModeEdit.php
Expand Up @@ -13,6 +13,6 @@ public function __construct() {

$this->svg = DOKU_INC . 'lib/plugins/approve/circle-edit-outline.svg';
$this->label = $helper->getLang('btn_edit_mode');
$this->accesskey = 'z';
$this->accesskey = 'e'; // it replaces the edit button, so the same access key.
}
}
4 changes: 2 additions & 2 deletions meta/ViewModeSiteTools.php
Expand Up @@ -14,10 +14,10 @@ public function __construct() {
$viewmode = get_doku_pref('approve_viewmode', false);
if ($viewmode) {
$this->svg = DOKU_INC . 'lib/plugins/approve/toggle-on-solid.svg';
$this->label = $helper->getLang('btn_edit_mode');
$this->label = $helper->getLang('btn_view_mode');
} else {
$this->svg = DOKU_INC . 'lib/plugins/approve/toggle-off-solid.svg';
$this->label = $helper->getLang('btn_view_mode');
$this->label = $helper->getLang('btn_edit_mode');
}
}
}

0 comments on commit c708a86

Please sign in to comment.