Skip to content

Commit

Permalink
Allow custom label for submit button
Browse files Browse the repository at this point in the history
By specifying `{{NEWPAGE?label=xxxx}}`, it is now possible to set a
custom label on the Add New Page form's submit button, instead of using
the `Add page` default.

The specified value for the *label* parameter is a DokuWiki language
string, allowing localization; if no matching translation is found, then
`xxxx` will be displayed as-is.

Fixes #108
  • Loading branch information
dregad committed Nov 10, 2024
1 parent 6666849 commit 2c27907
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function connectTo($mode) {
* - {{NEWPAGE>your:namespace:@INPUT@:start}}
* - {{NEWPAGE>your:namespace:[date formats]}} {@see strftime()}
* - {{NEWPAGE?config_overrides}}
* - {{NEWPAGE?label=custom}}
* - {{NEWPAGE#newtpl1,newtpl2}}
* - {{NEWPAGE#newtpl1|Title1,newtpl2|Title1}}
* - {{NEWPAGE>your:namespace#newtpl1|Title1,newtpl2|Title1}}
Expand Down Expand Up @@ -87,6 +88,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler) {
'hide' => $this->getConf('addpage_hide'),
'hideacl' => $this->getConf('addpage_hideACL'),
'autopage' => $this->getConf('addpage_autopage'),
'label' => 'okbutton',
)
);

Expand Down Expand Up @@ -141,6 +143,12 @@ public function render($format, Doku_Renderer $renderer, $data) {
$input = 'text';
if($this->options['autopage']) $input = 'hidden';

// Button label. If given string is not localized, use it as-is
$label = $this->getLang($this->options['label']);
if (!$label) {
$label = $this->options['label'];
}

$form = '<div class="addnewpage"><p>'
. '<form name="addnewpage" method="get" action="' . DOKU_BASE . DOKU_SCRIPT
. '" accept-charset="' . $lang['encoding'] . '">'
Expand All @@ -151,7 +159,7 @@ public function render($format, Doku_Renderer $renderer, $data) {
. '<input type="hidden" name="newpagevars" value="' . $data['newpagevars'] . '"/>'
. '<input type="hidden" name="do" value="edit" />'
. '<input type="hidden" name="id" />'
. '<input class="button" type="submit" value="' . $this->getLang('okbutton') . '" tabindex="4" />'
. '<input class="button" type="submit" value="' . $label . '" tabindex="4" />'
. '</form>'
. '</p></div>';

Expand Down

0 comments on commit 2c27907

Please sign in to comment.