Skip to content

Commit ed43ceb

Browse files
committed
Don't show WYSIWYG toggle when user has no edit permissions for content
Fixes #86
1 parent e81e853 commit ed43ceb

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

action/editor.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ public function addDataAndToggleButton(Doku_Event $event, $param)
6363
return;
6464
}
6565

66+
/** @var Doku_Form|\dokuwiki\Form\Form $form */
67+
$form = $event->data;
68+
69+
// return early if content is not editable
70+
if ($this->isReadOnly($form)) return;
71+
72+
6673
$useWYSIWYG = get_doku_pref('plugin_prosemirror_useWYSIWYG', false);
6774

6875
$prosemirrorJSON = '';
@@ -85,10 +92,7 @@ public function addDataAndToggleButton(Doku_Event $event, $param)
8592
}
8693
}
8794

88-
/** @var Doku_Form|\dokuwiki\Form\Form $form */
89-
$form = $event->data;
90-
91-
if(is_a($form, \dokuwiki\Form\Form::class)) {
95+
if (is_a($form, \dokuwiki\Form\Form::class)) {
9296
$form->addElement($this->buildToggleButton(), 0);
9397
$form->setHiddenField('prosemirror_json',$prosemirrorJSON);
9498
$form->addHTML('<div class="prosemirror_wrapper" id="prosemirror__editor"></div>', 1);
@@ -322,6 +326,27 @@ public function addJSINFO()
322326
global $JSINFO;
323327
$JSINFO['SMILEY_CONF'] = getSmileys();
324328
}
329+
330+
/**
331+
* Returns true if the current content is read only
332+
*
333+
* @todo remove Doku_Form case when the class is removed
334+
*
335+
* @param $form
336+
* @return bool
337+
*/
338+
protected function isReadOnly($form)
339+
{
340+
if (is_a($form, \dokuwiki\Form\Form::class)) {
341+
$textareaPos = $form->findPositionByType('textarea');
342+
$readonly = $textareaPos !== false && !empty($form->getElementAt($textareaPos)->attr('readonly'));
343+
} else {
344+
/** @var Doku_Form $form */
345+
$textareaPos = $form->findElementByType('wikitext');
346+
$readonly = $textareaPos !== false && !empty($form->getElementAt($textareaPos)['readonly']);
347+
}
348+
return $readonly;
349+
}
325350
}
326351

327352
// vim:ts=4:sw=4:et:

0 commit comments

Comments
 (0)