DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:pagemod

pagemod Plugin

Compatible with DokuWiki

  • 2017-02-19 "Frusterick Manners" unknown
  • 2016-06-26 "Elenor Of Tsort" yes
  • 2015-08-10 "Detritus" yes
  • 2014-09-29 "Hrun" yes

plugin A plugin which allows you to add information to existing pages via forms. It works with the Bureaucracy Plugin

Last updated on
2014-11-10
Provides
Syntax
Repository
Source
Requires
bureaucracy

Tagged with create, editing, form, update

Download and Installation

Download and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

Overview

I created this plugin because I have long wished for a way to add data structured in a specific way to a page in a repetitive fashion. A clear example of this is adding data to a table. How about a form on that page which could ask the right questions and when submitted add the information submitted as an additional row at the end of the table.

It works loosely in the following way:

  1. A form exists on a page (created by the bureaucracy plugin)
    • this can be the page to be modified or it can be another page.
    • this form contains the action field action pagemod <targetpage> <pagemod_id>
  2. A results placeholder sits on a target page
    • this placeholder is enclosed by the <pagemod> </pagemod> tags
  3. The form is filled in and submitted. Subsequently the pagemod action extends the target page by including a copy of the placeholder wherein the variables are replaced with the form values.

So here are the features:

  • A page with a form can update itself or another page.
  • Each <pagemod> enclosure has an id, so multiple forms can be used to update different parts of a page.
  • The form can update multiple sections of a page.
    • All the sections needs to have the same pagemod_id as the submitting form
  • A person can update page that they don't have write access to.
    • Only read access is required to modify a page via the form. (This is not a bug, its a feature.)
    • It means you can prevent people from modifying a page unless they do it via a form.
    • If want people to only have access to read the resultant page, but not change it, protect the form page.
    • No read access to result page for a user, prevents modifying it via form.
  • Updating more pages at once is possible by adding an action field for each page

That's it.

Usage

Form Syntax

Defining a form is done via the bureaucracy plugin, please check that for complete syntax. But here are the additions by this plugin:

<form>
action pagemod <target namespace:page> <pagemod_id>
 
<...various fields for submit...>
submit
</form>

To make bureaucracy use the pagemod action, you need to add action pagemod with the following parameters:

  • target : The target page, allowed notations:
    • absolute pageids (e.g. page, namespace:otherpage)
    • Relative pageids, which are solved with respect to current page (e.g. .:neighbourpage)
    • _self to denote the same page as the form
  • pagemod_id : If using multiple pagemod enclosures in a page, this is to identify which enclosure to fill and include in the page.

Template Syntax

Defining a pagemod template is done within a page with the following code:

<pagemod <pagemod_id> <params>>
The wiki text will be parsed to transform tags like @@Field from form@@ 
or ##Field2 from form##
 
The contents of this section are invisible and will not show up on this page.
</pagemod>
 
Some other wiki text around, that is visible again.

Or an real example for adding rows to a table:

Some more text, and a table with as last row the pagemod placeholder.
 
^ Table header 1 ^ Table header 2 ^
<pagemod table_adder output_before>| @@table value 1@@ | @@table value 2@@ |
</pagemod>

Note: If the resulting table is later edited with EditTable Plugin, then the above pagemod code will disappear (only existing contents remain).

The pagemod enclosure starts with:

<pagemod <pagemod_id> <params>>

where the following is true:

  • pagemod_id : This is the id of the pagemod. The form has an pagemod_id, it will modify all the pagemod enclosures with the same id.
  • params : params are separated by , and can be one of the following:
    • output_after : indicates that the output of the translation must come after the rewrite of the pagemod enclosure, the default is to output before the rewrite
    • output_before : this is the default behaviour, to output the translation before the rewrite of the pagemod enclosure

The pagemod enclosure ends with the following:

</pagemod>

and the contents are not shown when the wiki page is viewed. Converting of the contents of the pagemod enclosure is done with the bureaucracy plugin's replacements function. So similar patterns are available.

Meta variables

The meta variable are some extra variables for the pagemod plugin. The meta variables values are generated by the plugin at runtime. They are the following:

  • @@meta.date@@ : The current date in dd/mm/yyyy
  • @@meta.datetime@@ : The current datetime according to ISO 8601
  • @@meta.date.format.format@@ : The current date in the format you specify. This format is the one used by the PHP date() function found here (e.g. @@meta.date.format.d/m/Y@@ will achieve the same as @@meta.date@@)
  • @@meta.user.id@@ : The user who submitted the form's username
  • @@meta.user.mail@@ : The users email address (if we know it)
  • @@meta.user.name@@ : The users full name (if we know it)
  • @@meta.page.id@@ : The full id of the page
  • @@meta.page.name@@ : The name of the page
  • @@meta.page.namespace@@ : The namespace of the page

New meta information tag requests should be sent to me for implementation.

FAQ

Incrementing number possible?

The bureaucracy plugin has some an number field and a hiddenautoinc which has auto incrementing counter on each succesfull submit.

Development

In November 2014 the pagemod plugin is updated to use a helper for the pagemod action. The Bureaucracy Plugin is updated in November 2014 as well, it will load this helper automatically if used in a form. The new version of Bureaucracy supports only the new version of Pagemod.

Remark: the file bureaucracy/actions/pagemod.php is now unused. You may remove it manually.

Previous versions

IMPORTANT NOTE: When you have installed these previous versions, you WILL need to UPDATE it once. This is because it installs some stuff into the bureaucracy directory, but this action doesn't happen on install, but does happen on update. To update the plugin, click “Update” in the Admin/Plugins section of your DokuWiki.

Manual installation of previous version
In [wiki-root]/lib/plugins/ this plugin adds:

pagemod/      
pagemod/syntax.php     
bureaucracy/            
bureaucracy/actions/   
bureaucracy/actions/pagemod.php  

(note: since November 2014 no files are copied to bureaucracy plugin folder anymore)

Bugs and feature requests

The pagemod plugin is strong related with the bureaucracy plugin. For general questions and issues see also the Bureaucracy plugin wiki page and the Bureaucracy issue tracker.

Please report issues and requests for Pagemod Plugin at https://github.com/rendezz/dokuwiki-pagemod/issues

QUESTION: Can pagemod be triggerd conditionaly? Let's say there is a form with a yesno field. Could pagemod be called only when the yesno field is checked?

Problem and solution

The standard pagemod helper code does not do any substitution of page names according to bureaucracy variables. I have designed a form which contains:

textbox Hnode
action  smg:config:@@Hnode@@ add_hwchange

the problem being that @@Hnode@@ is interpreted as “Hnode” and not the entered value. The problem seems to lie in the helper script in public function run. I have added a call to $this→replace (as is done in public function parsePagemod) just before the resolve_pageid call. It now appears to be working.

diff:

39,40d38
<             //Allow for the substitution os elements of the page name
<             $page_to_modify = $this->replace($page_to_modify);



Example usecases

An bundle of example pages is available:

Content:

  • Some forms which modify the page of the form, or just another page.
  • Extending an existing table
  • Adding additional list items

Minimalistic Guestbook

I used this plugin for a minimalistic guestbook. Although my wiki can be edited by everyone, I think visitors would be more willing to leave a message through a little form. See http://windhoff.net/wiki/playground/playground how it works. An javascript based alternative to this is the plugin:disqus.

======Guestbook=====
===== New Comment =====
<form>
action pagemod _self add_comment
fieldset "Write new comment"
textbox  "Name" /^((?!<\/nowiki>).)*$/
email "Email (optional)" /^((?!<\/nowiki>).)*$/ !
textarea "Comment" /^((?!<\/nowiki>).|\n)*$/
submit
</form>
 
===== Comments =====
<pagemod add_comment output_after>
//@@meta.date.format.r@@://
^<nowiki>@@Name@@</nowiki> |<nowiki>@@Email (optional)| @@</nowiki>|
|<nowiki>@@Comment@@</nowiki> ||
</pagemod>

M. 2010/04/02

plugin/pagemod.txt · Last modified: 2017-01-13 16:09 by 125.26.181.98 · Currently locked by: 68.180.230.227