pagemod plugin

pagemod plugin by Baseline IT
A plugin which allows you to add information to pages in a structured way (via forms), it works with the bureaucracy plugin

Last updated on 2009-10-12. Provides Syntax.
Compatible with DokuWiki 20080505.

Requires bureaucracy.
Similar to data, datapdo.

Tagged with create, editing, form, update.

    Download and Installation

    Download and install the plugin using the Plugin Manager using the following URL. Refer to Plugins on how to install plugins manually.

    IMPORTANT NOTE: When you have installed it, 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 (BUG), but does happen on update. To update the plugin, click “Update” in the Admin/Plugins section of your DokuWiki.

    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.

    When I saw the 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 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 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

    Form Syntax

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

    <form>
    action pagemod <target page/namespace> <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 : 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:

    <pagemod <pagemod_id> <params>>
    wiki text while will be parsed for 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 
    
    then some more
    
    ^ table header 1 ^ table header 2 ^
    <pagemod table_adder output_before>| @@table value 1@@ | @@table value 2@@ |
    </pagemod>
    

    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. Translation of the contents of the pagemod enclosure is done inline with the 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 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…

    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 :-)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 backlinks2 plugin does) ? For example :

    <form>
    action pagemod auto new_comment
    fieldset "Add your comments below"
    textbox  "Name"
    select   "Rate it" "Excellent|Good|Bad"
    textarea "Comment"
    submit
    </form>

    It would save an incredible amount of time when you have to insert forms in many pages ! — Laynee 2009/10/05 16:22

    From Author : This is now possible using the _self target described in the documentation above

    Woohooh! The new version works like a charm ! Thank you very much :) — Laynee 2009/10/12 16:00

    Bugs

    Error message in combination with bureaucracy plugin

    Hi, I installed pagemod together with the bureaucracy plugin, but I can't get them to work. After submitting data through a bureaucracy form (e.g. the demo-page) I receive the following error:

    Fatal error: Class 'syntax_plugin_bureaucracy_actions' not found in /lib/plugins/bureaucracy/actions/pagemod.php on line 7

    What am I doing wrong? I tried this on DokuWiki 2009-12-25c as well as on older versions, with same error.

    I've updated my installation to DokuWiki 2009-12-25c, Pagemod 2009-10-12 and Bureaucracy 2010-01-22. I now encounter the same error. I guess Pagemod needs to be updated to work with the latest versions of Bureaucracy. I reinstalled my old version of Bureaucracy (it should be this one) and now it works — Laynee 2010/02/03 18:03
    Replace in the file bureaucracy/actions/pagemod.php from line 32 to 40 with that
            // 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 :-(Ph LAPEYRIE 2010/03/16 23:25
    THE SOLUTION = Rdemont + Gerione. It's all right for me. LOLPh LAPEYRIE 2010/03/16 23:51

    Shows an empty screen after submitting the form

    After I submit the form the page reloads but shows only the header, footer and sidebar without the content. The results output doesn't work regardless that I try to add them to the same or another page.

    The other bureaucracy actions (email and template) work fine.

    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

    From Author : This bug is fixed by redeploying bureaucracy with the file with my patch detailed here, I have mailed Andreas and asked him to include my fix in his code.

    From Author : This bug appears to have been fixed, many thanks to the bureaucracy maintainer for this

    small bug for @@meta.user.id@@

    Great plugin ! I use it all the time. small bug for @@meta.user.id@@ which doesn't work for me : I think it should use return $INFO['user']; instead of return $INFO['userinfo']['user'];

    Question on Period Use in Field Name

    I was wondering if there is a way to use the period in field names, so you could make numbered items like “1. What is your name?”, etc. (using a period currently breaks the template) The only way I'm able to do this currently is writing a static “1. What is your name?” which is followed immediately by a “Name [ ]” line, which gets really cluttered if you're trying to do something like a numbered questionnaire.

    On the other hand, is there any way to show a field title like “Please enter you name”, but assign it to a variable like @@name@@ for use in the pagemod tag? I apologize if this question is better asked on the bureaucracy plugin page.— Kououken 2010/03/02

    Is it possible to check the value of a placeholder?

    Hi! I am quite new to wikis, so please forward me to the right place if my question is wrong here. Is there any way to check the value of a placeholder and treat the form depending on its value? Something like “if @@name@@=='Green' then <show output of the form>”? Anna 2010/03/03

     
    plugin/pagemod.txt · Last modified: 2010/03/20 22:02 by laplix
     
    Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
    Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
    WikiForumIRCBugsGitXRefTranslate