====== pagemod plugin ======
===== Overview =====
I created [[doku>plugin:pagemod|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.
When I saw the [[doku>plugin:bureaucracy]] plugin I knew it could be done and the way that plugin is written lends itself well to extension and so here it is and it works loosely in the following way:
* A form exists on a page (created by the [[doku>plugin:bureaucracy]] plugin), this can be the page to be modified or it can be another page.
* A results placeholder sits on a page, this placeholder is enclosed by the **pagemod** tags
* The form is filled in and submitted inline with the [[doku>plugin:bureaucracy]] requirements and the pagemod action rewrites the target page, replacing the placeholders with the output of parsing. It then adds another placeholder, so that you can continue to add to the page.
That's really the functionality, its quite simple.
So here are the features:
* The form and the target can be the same page or different pages (i.e. a page 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. That is there can be multiple **pagemod** enclosures with different parts of the data in each, it will parse all of them as long as they have the same **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.
* If you don't want people to have access to read the resultant page, deny them read access, then the form will also not work for them.
* FIXME (Does this mean they still have access to the form, but it generates an error when they try to use it?)
That's it.
===== Usage =====
==== Examples ====
Example Files can be found here:
* http://freecode.baselineit.net/dokuwiki/pagemod-namespace.tar.bz2
==== Form Syntax ====
Defining a form is done via the [[doku>plugin:bureaucracy]] plugin, please check that for complete syntax. But here are the changes:
To make bureaucracy use the pagemod action, you need to add **action pagemod** with the following parameters:
* target : This is a page id which can include a namespace, so pagemod:same_page or whatever. **Since 2009/10/12 release :** You can use the special target **_self** to denote the same page as the enclosure.
* pagemod_id : This is to identify which pagemod enclosures to translate
==== Template Syntax ====
Defining a pagemod template is done within a page with the following code:
The pagemod enclosure starts with:
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:
and the contents are not shown when the wiki page is viewed. Translation of the contents of the pagemod enclosure is done inline with the [[plugin:bureaucracy]] plugin's template function.
** Since release 2009/10/12 ** There also exists the concept of meta variables, they are variables that 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 [[http://www.php.net/manual/en/function.date.php|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.
> 2010-03-20 I added a auto-increment meta tag to your plugin. I needed it for a bug tracker/feature request system. If you're interested, I'll send it to you. Just send me an email to laplix¢2010¢at$gmail$dot¢com (remove the money symbols). It is not fully tested yet (right now, I only tested it with _self) but it does what I want, so...
>>Sounds like a useful addition.. Could you share your code here?? Cheers!
===== Conclusion =====
Please let me know of any bugs or issues, requests. I know a large number of people have requested a plugin like this, so I hope people find it useful.
===== Feedback =====
==== Non-editable runtime values (ADDED 2009-10-12) ====
We're using this plugin to log activity reports so I required the feature to include some non-editable runtime values like current date and user attributes in pagemod's output. I've done it this way:
13a14
> global $INFO;
32a34,41
> $patterns[] = '/(@@|##)@DATE@(@@|##)/';
> $values[] = strftime($conf['dformat']);
> $patterns[] = '/(@@|##)@USER@(@@|##)/';
> $values[] = $_SERVER['REMOTE_USER'];
> $patterns[] = '/(@@|##)@NAME@(@@|##)/';
> $values[] = $INFO['userinfo']['name'];
> $patterns[] = '/(@@|##)@MAIL@(@@|##)/';
> $values[] = $INFO['userinfo']['mail'];
I've no experience in PHP so maybe this solution isn't optimal but it does work :-) --- [[lost@infidel.name|Dmitry Rubinstain]].
** From Author : This is now possible using the meta tags described in the documentation above **
==== Autodetect current page id (ADDED 2009-10-12) ====
This plugin rocks ! IMHO, it provides such great features that it should be advertised on the front page. I'm planning to use it as a commenting system. Would it be possible to auto-detect the current page id (like the [[doku>plugin:backlinks2]] plugin does) ? For example :
// run through fields and prepare replacements
foreach($data as $opt) {
$label = preg_quote($opt->getParam('label'));
$value = $opt->getParam('value');
if(in_array($opt->getParam('cmd'),$this->nofield)) continue;
$label = preg_replace('/([\/\.])/','\\\$1',$label);
$patterns[] = '/(@@|##)'.$label.'(@@|##)/i';
$values[] = $value;
}
--- // Rdemont 2010/02/19 //
>> I tried both solutions above, but still remain with the same error. Something else I might be missing? --- // LWolf 2010/02/25 //
>> Its a type syntax_plugin_bureaucracy_actions needs to be replaced by syntax_plugin_bureaucracy_action. At least, this worked for me --- //Gerione 2010/3/4//
>> I have the same big problem ! Help me please :-( --- //[[philippe@lapeyrie.fr|Ph LAPEYRIE]] 2010/03/16 23:25//
>> **THE SOLUTION** = //Rdemont// + //Gerione//. It's all right for me. LOL --- //[[philippe@lapeyrie.fr|Ph LAPEYRIE]] 2010/03/16 23:51//
** From Author : Fixed, now working with the new bureacracy, thanks for the help. **
==== Multiple forms on one page (RESOLVED) ====
Multiple forms + pagemod sections on one page (and not only, read more) do not work.
**Scenario 1**: I have one page (name it: ''materials'') with two pagemod forms and two datasets,
* each pair with different id (exactly: ''am311'' and ''cm113'' if that matters),
* both pairs identical otherwise (same fields, same structure).
**Scenario 2**: I have one page with form (''materials'') and two datasets with data (''materials:am311'' and ''materials:cm113'')
* each pair with different id (exactly: ''am311'' and ''cm113'' if that matters),
* both pairs forms/datasets identical otherwise (same fields, same structure).
In both scenarios, data gets added to both datasets, instead of one of them (''am311'' or ''cm113'').
**From Author : This is not a bug in this module, its a bug in bureaucracy. If you have multiple bureaucracy forms on a page, the result is always generated from the first's parameters (action parameters) since it doesn't set these in the form, but re-reads them from the page**
**
run($data, $thanks, $pagemodargs);
$class = 'syntax_plugin_bureaucracy_action_mail';
$emailer = new $class();
$emailsuccess = $emailer->run($data, $thanks, $emailargs);
$rmsg = '';
if (!$pagemodsuccess) {$rmsg .= "Pagemod failed";}
if (!$emailsuccess) {$rmsg .= "Emailing failed";}
if ($rmsg=='') {return $thanks;}
else {return $rmsg.join(',',$errors);}
}
}
Use the following notation in the form:
action pagemodandmail ....
Example:
The page support:subsystem:registered_bugs must be edited with the following pagemod entry
^ Name ^ Subsystem ^ Description ^ Error message(s) ^
|@@Name@@ |@@Email@@ |@@Subsystem@@ |@@Description@@ |@@Error message(s)@@ |
// [[knutsd@met.no|Knut S. Dale]] 2010/12/27 //
==== Multiple Pages changed from one form ====
Would such syntax be possible:
making it possible to have one form which places the info on more than one page? - Andy
===== Bugs =====
* I experienced this: if the %%@@Variable@@%% is on the begining of the line, it allways expand into empty string, even if I fill the form. And I found another difference - with bureaucracy template mode, not filled variables were kept as were, but with pagemod mode, they are replaced with empty strings.
* Use of plugin is problematic if you use it with tables AND use ''edittable'' plugin - see description in [[plugin:edittable]].
* Is there a size/length constraint? I am responding to a new page question and it will not let me post a long response.