Skip to content

Multiple string selection for fieldsets, readonly for textboxes with #, class for submit buttons #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions .github/workflows/dokuwiki.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: DokuWiki Default Tasks
on:
push:
pull_request:
schedule:
- cron: '1 9 8 * *'


jobs:
all:
uses: dokuwiki/github-action/.github/workflows/all.yml@main
51 changes: 0 additions & 51 deletions .github/workflows/phpTestLinux.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1 @@
name: PHP Tests on Linux

on: [push, pull_request]

jobs:
run:
name: PHP ${{ matrix.php-versions }} DokuWiki ${{ matrix.dokuwiki-branch }}
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
dokuwiki-branch: [ 'master', 'stable']
exclude:
- dokuwiki-branch: 'stable'
php-versions: '8.0'
fail-fast: true

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, PDO, pdo_sqlite, bz2

- name: Setup problem matchers
run: |
echo ::add-matcher::${{ runner.tool_cache }}/php.json
echo ::add-matcher::${{ runner.tool_cache }}/phpunit.json

- name: Download DokuWiki Test-setup
run: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh

- name: Run DokuWiki Test-setup
env:
CI_SERVER: 1
DOKUWIKI: ${{ matrix.dokuwiki-branch }}
run: sh travis.sh

- name: Setup PHPUnit
run: |
php _test/fetchphpunit.php
cd _test

- name: Run PHPUnit
run: |
cd _test
php phpunit.phar --verbose --stderr --group plugin_bureaucracy
3 changes: 2 additions & 1 deletion conf/default.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$conf['runas'] = '';
$conf['maxEmailAttachmentSize'] = 3*1024*1024; //3MB
$conf['namespaces'] = array();
$conf['maxEmailAttachmentSize'] = 3*1024*1024; //3MB
3 changes: 2 additions & 1 deletion conf/metadata.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

$meta['runas'] = array('string');
$meta['runas'] = array('string');
$meta['namespaces'] = array('array');
$meta['maxEmailAttachmentSize'] = array('numeric');

8 changes: 5 additions & 3 deletions helper/actionscript.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public function run($fields, $thanks, $argv) {
/** @var dokuwiki\plugin\bureaucracy\interfaces\bureaucracy_handler_interface $handler */
$handler = new $className;

if (!is_a($handler, dokuwiki\plugin\bureaucracy\interfaces\bureaucracy_handler_interface::class)) {
if (is_a($handler, dokuwiki\plugin\bureaucracy\interfaces\bureaucracy_handler_interface::class)) {
return $handler->handleData($fields, $thanks);
} elseif (is_a($handler, dokuwiki\plugin\bureaucracy\interfaces\bureaucracy_handler_interface_ex::class)) {
return $handler->handleData($fields, $thanks,$argv);
} else {
throw new InvalidArgumentException('The handler must implement the interface <code>dokuwiki\\plugin\\bureaucracy\\interfaces\\bureaucracy_handler_interface</code> !');
}

return $handler->handleData($fields, $thanks);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions helper/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ protected function standardArgs($args) {
}
} elseif($arg == '@') {
$this->opt['pagename'] = true;
} elseif($arg == '#') {
$this->opt['readonly'] = true;
} elseif($arg == '@@') {
$this->opt['replyto'] = true;
} elseif(preg_match('/x\d/', $arg)) {
Expand Down
3 changes: 1 addition & 2 deletions helper/fieldfieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function handle_post($value, &$fields, $index, $formid) {
if(empty($this->depends_on)) {
return true;
}

// search the field where fieldset depends on in fields before fieldset
$hidden = false;
for ($n = 0 ; $n < $index; ++$n) {
Expand All @@ -78,7 +77,7 @@ public function handle_post($value, &$fields, $index, $formid) {
continue;
}
if(count($this->depends_on) > 1) {
$hidden = $field->getParam('value') != $this->depends_on[1];
$hidden = (in_array($field->getParam('value'), explode("|",$this->depends_on[1]))==false);
} else {
$hidden = !$field->isSet_();
}
Expand Down
44 changes: 41 additions & 3 deletions helper/fieldsubmit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
* Creates a submit button
*/

class helper_plugin_bureaucracy_fieldsubmit extends helper_plugin_bureaucracy_field {
protected $mandatory_args = 1;
static $captcha_displayed = array();
Expand All @@ -23,6 +24,14 @@ public function initialize($args) {
$this->opt['optional'] = true;
}

function form_button($attrs)
{
$p = (!empty($attrs['_action'])) ? 'name="do[' . $attrs['_action'] . ']" ' : '';
$label = $attrs['label'];
unset($attrs['label']);
return '<button ' . $p . buildAttributes($attrs, true) . '>' . $label . '</button>';
}

/**
* Render the field as XHTML
*
Expand All @@ -40,12 +49,37 @@ public function renderfield($params, Doku_Form $form, $formid) {
$form->addElement($helper->getHTML());
}
}

$attr = array();
$attr['name'] = 'submit';
if(isset($this->opt['value'])) {
$attr['value'] = $this->opt['value'];
}
if(isset($this->opt['label'])) {
$attr['label'] = $this->opt['label'];
}
if(isset($this->opt['id'])) {
$attr['id'] = $this->opt['id'];
}
if(isset($this->opt['class'])) {
$attr['class'] = $this->opt['class'];
}

$this->tpl = form_makeButton('submit','', '@@DISPLAY|' . $this->getLang('submit') . '@@', $attr);
parent::renderfield($params, $form, $formid);

$this->_handlePreload();

if(!$form->_infieldset){
$form->startFieldset('');
}
if ($this->error) {
$params['class'] = 'bureaucracy_error';
}

$params = array_merge($this->opt, $params);
$element = $this->_parse_tpl($this->tpl, $params);
$form->addElement($this->form_button($element));

}

/**
Expand All @@ -57,9 +91,13 @@ public function renderfield($params, Doku_Form $form, $formid) {
* @param helper_plugin_bureaucracy_field[] $fields (reference) form fields (POST handled upto $this field)
* @param int $index index number of field in form
* @param int $formid unique identifier of the form which contains this field
* @return bool Whether the posted form has a valid captcha
* @return bool Whether the posted f$_POSTorm has a valid captcha
*/
public function handle_post($value, &$fields, $index, $formid) {

// Set the value of the submit filed to the label of the button which was pressed
$this->setVal($_POST['submit']);

if ($this->hidden) {
return true;
}
Expand All @@ -83,7 +121,7 @@ public function handle_post($value, &$fields, $index, $formid) {
* @return mixed|null
*/
public function getParam($name) {
return ($name === 'value') ? null : parent::getParam($name);
return ($name === 'value') ? (($this->hidden)? null : parent::getParam($name)) : parent::getParam($name);
}

}
4 changes: 4 additions & 0 deletions helper/fieldtextbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ function initialize($args) {
$attr['required'] = 'required';
}

if(isset($this->opt['readonly'])) {
$attr['readonly'] = 'readonly';
}

$this->tpl = form_makeTextField('@@NAME@@', '@@VALUE@@', '@@DISPLAY@@', '@@ID@@', '@@CLASS@@', $attr);
if(isset($this->opt['class'])){
$this->tpl['class'] .= ' '.$this->opt['class'];
Expand Down
19 changes: 19 additions & 0 deletions interfaces/bureaucracy_handler_interface_ex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace dokuwiki\plugin\bureaucracy\interfaces;

interface bureaucracy_handler_interface_ex {

/**
* Handle the data incoming from the form.
*
* @param \helper_plugin_bureaucracy_field[] $fields the list of fields in the form
* @param string $thanks the thank you message as defined in the form
* or default one. Might be modified by the action
* before returned
*
* @return bool|string false on error, $thanks on success
*
*/
public function handleData($fields, $thanks, $argv);
}
3 changes: 2 additions & 1 deletion lang/cs/settings.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$lang['runas'] = 'Ovlivňuje "template mode". Použijte práva (virtuálníh)o uživatele pro kontrolu ACL (přístupová práva) při čtení a vytváření stránek.';

$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'Max size of mail attachments in Bytes. (per File)';
1 change: 1 addition & 0 deletions lang/de/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
$lang['e_pageexists'] = 'Die Seite "%s" exisistiert bereits. Bitte wählen Sie einen anderen Namen.';
$lang['e_template'] = 'Das Template "%s" konnte nicht geladen werden. Möglicherweise existiert es nicht oder Sie verfügen nicht über die benötigten Rechte.';
$lang['e_denied'] = 'Sie sind nicht berechtigt diese Seite anzulegen. Haben Sie vielleicht vergessen sich anzumelden?';
$lang['e_namespace'] = 'Forulare sind in diesem Namensraum nicht zulässig.';
$lang['mailsubject'] = 'Formulardaten übermittelt von %s';
$lang['mailintro'] = 'Die folgenden Daten wurden am %s abgeschickt.';
$lang['mail_thanks'] = 'Ihre Daten wurden erfolgreich versandt. Vielen Dank.';
Expand Down
1 change: 1 addition & 0 deletions lang/de/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
*
*/
$lang['runas'] = 'Affects the template mode. Use this (virtual) user\'s permissions when checking ACLs for reading templates and creating pages.';
$lang['namespaces'] = 'Wenn diese Option nicht leer ist, sind forms nur auf den spezifizierten Seiten möglich. Das Zeichen * is ein beliebiger Platzhalter und ** umfasst alle unterräume.';
$lang['maxEmailAttachmentSize'] = 'Maximale größe eines Mail-Anhangs in Bytes (pro Datei).';
3 changes: 3 additions & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
$lang['e_template'] = 'Could not read template "%s". Maybe it doesn\'t exist or you have no read permissions?';
$lang['e_denied'] = 'You are not allowed to create this page, maybe you forgot to log in?';

$lang['e_namespace'] = 'Forms are not allowed in this namespace.';


$lang['mailsubject'] = 'Form data submitted at %s';
$lang['mailintro'] = 'The following data was submitted on %s.';

Expand Down
1 change: 1 addition & 0 deletions lang/en/settings.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

$lang['runas'] = 'Affects the template mode. Use this (virtual) user\'s permissions when checking ACLs for reading templates and creating pages.';
$lang['namespaces'] = 'If set it limits the usage of forms to the given list of namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'Max size of mail attachments in Bytes. (per File)';

1 change: 1 addition & 0 deletions lang/es/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
* @author Vicente <tirantet@gmail.com>
*/
$lang['runas'] = 'Afecta el modo plantilla. Use los permisos de este usuario (virtual) cuando compruebe los ACLs para leer plantillas y crear páginas.';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'Maximo tamaño, en Bytes, de los elementos incrustados en un eMail. (por fichero)';
1 change: 1 addition & 0 deletions lang/fa/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
* @author nima <nima.hamidian@gmail.com>
*/
$lang['runas'] = 'روی حالت قالب اثر می‌گذارد. از این اجازه‌های کاربر (مجازی) وقتی استفاده کنید که ACL ها برای خواندن قالبها و ایجاد صفحات بررسی می‌شوند. ';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'اندازه حداکثر پیوست‌های ایمیل بر حسب بایت. (به ازای هر فایل)';
1 change: 1 addition & 0 deletions lang/fr/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
* @author Schplurtz le Déboulonné <schplurtz@laposte.net>
*/
$lang['runas'] = 'Mode «template» : teste les ACL avec les permissions de cet utilisateur (virtuel) pour la lecture des modèles et la création de page.';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'Taille max en octet des pièces jointes dans les courriels. (par fichier)';
1 change: 1 addition & 0 deletions lang/hr/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
* @author Davor Turkalj <turki.bsc@gmail.com>
*/
$lang['runas'] = 'Utječe na mod predloška. Koristi ove (virtualne) ovlasti kada provjeravaš ACL za čitanje predloška i stvaranje stranice.';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'Maksimalna veličina priloga pošti u Bajtovima. (po datoteci)';
6 changes: 6 additions & 0 deletions lang/it/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

$lang['runas'] = 'Affects the template mode. Use this (virtual) user\'s permissions when checking ACLs for reading templates and creating pages.';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'Max size of mail attachments in Bytes. (per File)';

1 change: 1 addition & 0 deletions lang/ja/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
* @author HokkaidoPerson <dosankomali@yahoo.co.jp>
*/
$lang['runas'] = 'テンプレートモードに影響があります。テンプレートを読み込み、ページを作成するために ACL チェックする場合、この(仮想)ユーザーの権限を使用してください。';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'メールに添付するファイルの最大サイズ(バイト数/1ファイルごと)';
6 changes: 6 additions & 0 deletions lang/lv/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

$lang['runas'] = 'Affects the template mode. Use this (virtual) user\'s permissions when checking ACLs for reading templates and creating pages.';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'Max size of mail attachments in Bytes. (per File)';

1 change: 1 addition & 0 deletions lang/nl/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
* @author Gerrit Uitslag <klapinklapin@gmail.com>
*/
$lang['runas'] = 'Gebruikt in de template mode. Gebruik de rechten van deze (virtuele) gebruiker bij het controleren van de ACL gebruiker voor het lezen van templates en het maken van pagina\'s';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'Max grootte van e-mailbijlages in Bytes. (per bestand)';
1 change: 1 addition & 0 deletions lang/no/settings.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

$lang['runas'] = 'Påvirker malenes virkemåte. Bruk tillatelse for virituell bruker når du sjekker ACL for lesing av maler og opprettelse av sider.';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'Maksimalstørrelse for epostvedlegg i bytes. (pr. fil)';

1 change: 1 addition & 0 deletions lang/pt-br/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
* @author Nilton Röhricht Junior <rohricht@gmail.com>
*/
$lang['runas'] = 'Afeta o modo de template. Use estas permissões de usuário (virtual) quando verificando ACLs para leitura de templates e criação de páginas.';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'Tamanho máximo para anexos de e-mail em Bytes. (por arquivo)';
1 change: 1 addition & 0 deletions lang/pt/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
* @author Rafael Grando <r.grando@live.com>
*/
$lang['runas'] = 'Afeta o modo template. Use essas permissões (virtuais) de usuário quando checar ACLs para ler modelos e criar páginas.';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'Tamanho máximo de anexos em bytes. (por arquivo)';
1 change: 1 addition & 0 deletions lang/ru/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
* @author Yuriy Skalko <yuriy.skalko@gmail.com>
*/
$lang['runas'] = '(Влияет на режим шаблона.) Использовать права этого (виртуального) пользователя при проверке доступа для чтения шаблонов и создания страниц.';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = 'Максимальный размер почтовых вложений в байтах. (на файл)';
1 change: 1 addition & 0 deletions lang/zh/settings.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

$lang['runas'] = '在template模式下起效。当读取模板和创建页面需要检查ACLs权限时,使用此(虚拟的)用户权限。';
$lang['namespaces'] = 'If set it limits the usage of forms to the given namspaces and page ids. The character * is a wildcard sysmbol and ** includes all subnamespaces';
$lang['maxEmailAttachmentSize'] = '邮件附件大小上限,以Bytes为单位。(每份附件)';

21 changes: 16 additions & 5 deletions script/fieldsets.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@
jQuery(function () {

jQuery('form.bureaucracy__plugin').each(function () {
function isShowOrHide(input,dp) {

try { var tvals=dp.tval.split('|'); }
catch(err) {var tvals=[dp.tval]; }
var soh=false;

for (const tval of tvals[Symbol.iterator]()) {
soh ||=
input.parentNode.parentNode.style.display !== 'none' && // input/checkbox is displayed AND
((input.checked === tval) || // ( checkbox is checked
(input.type !== 'checkbox' && (tval === true && input.value !== '')) || // OR no checkbox, but input is set
input.value === tval); // OR input === tval )
}
return soh
}
//show/hide fieldset and trigger depending children
function updateFieldset(input) {
jQuery.each(jQuery(input).data('dparray'), function (i, dp) {
var showOrHide =
input.parentNode.parentNode.style.display !== 'none' && // input/checkbox is displayed AND
((input.checked === dp.tval) || // ( checkbox is checked
(input.type !== 'checkbox' && (dp.tval === true && input.value !== '')) || // OR no checkbox, but input is set
input.value === dp.tval); // OR input === dp.tval )

var showOrHide = isShowOrHide(input,dp);

dp.fset.toggle(showOrHide);

Expand Down
Loading