[dokuwiki] More powerful AJAX programming interface

  • From: Adrian Lang <lang@xxxxxxxxxxxx>
  • To: DokuWiki Mailinglist <dokuwiki@xxxxxxxxxxxxx>
  • Date: Tue, 7 Sep 2010 20:04:11 +0200

Hi list,

I created a temporary fork containing a patch of mine [1] introducing a
leaner AJAX interface for plugins. To date, AJAX endpoints are realized
either with lib/exe/ajax.php using AJAX_CALL_UNKNOWN or with an own
endpoint in the plugin directory. The latter is rather popular for its
reduced DokuWiki overhead, but it leaves everything to the plugin
author.

My proposal simplifies calling as well as providing AJAX endpoints. On
the JavaScript site, a new function wrapping the old «sack» is
provided: 

    var ajax = new doku_ajax('plugin_myplugin_myfunc',
                             {fixedparam: NS});
    ajax.onCompletion = function () {
        alert(this.response);
    }
    for (var i = 0 ; i < 4 ; ++i) {
        ajax.runAJAX({varparam: i});
    }

Note that I also added a function «serialize_form» for POSTing forms
via AJAX.

On the providing PHP site, the AJAX call is automatically dispatched to
lib/plugins/myplugin/ajax/myfunc.php. This file contains the actual
handler:

    <?php
    echo str_repeat($_POST['fixedparam'], (int) $_POST['varparam']);

If your plugin only needs one AJAX call, you might drop the «myfunc»
part: «doku_ajax('plugin_myplugin')» would dispatch to
«lib/plugins/myplugin/ajax.php».

Open questions:

  * How much initialization should happen in lib/exe/ajax.php before
    dispatching to the plugins? MIME-Type header? inc/init.php?
  * Should we provide a more general minimal endpoint?
  * Good idea at all?

[1]
http://github.com/adrianlang/dokuwiki/commit/ea151d066148ef30f93d2af0a40960d90d09a694

Regards,
Adrian
--
DokuWiki mailing list - more info at
http://www.dokuwiki.org/mailinglist

Other related posts: