Difference between revisions of "Extension talk:SimpleForms.php"

From Organic Design wiki
m ([[Talk:Extension:SimpleForms.php]] moved to Foo talk:SimpleForms.php)
(using sajax_do_call)
Line 1: Line 1:
 
{{ext-talk-msg|Simple Forms}}
 
{{ext-talk-msg|Simple Forms}}
  
 +
== Using MediaWiki Ajax instead of MooTools ==
 +
0.3.13 has had the following snippet of code added in preparation for the 0.4 release which will no longer depend on Mootools for its ajax functionality.
 +
<php>
 +
if ($wgUseAjax && $_REQUEST['action'] == 'ajax' && $_REQUEST['rs'] == 'wfSimpleFormsAjax') {
 +
$_REQUEST['action'] = 'render';
 +
if (is_array($_REQUEST['rsargs']))
 +
foreach ($_REQUEST['rsargs'] as $arg)
 +
if (preg_match('/^(.+?)=(.+)$/',$arg,$m))
 +
$_REQUEST[$m[1]] = $m[2];
 +
}
 +
</php>
 +
This allows us to use the ''sajax_do_call'' function from MediaWiki's ''ajax.js'', but this works by requesting the ''AjaxDispatcher'' class to execute a function specified in the request and to return the results of the function. This is not quite the way SimpleForms needs it to work because the ''AjaxDispatcher'' is instantiated before any high-level MediaWiki objects have been instantiated, but SimpleForms needs to return the fully rendered page content with all extension activated etc.
 +
 +
The code above gets around this problem by detecting if incoming requests from ''sajax_do_call'' are specifying a function called "wfSimpleFormsAjax", and if so the ''action'' is changed to ''render'' so the request will no be handled by the ''AjaxDispatcher''. The ''sajax_do_call'' argument list is shifted into the main ''$_REQUEST'' array as if it came from a normal GET or POST request.
 +
 +
Here is an example SimpleForms input which makes an ajax request using the ''sajax_do_call'' function:
 +
 +
{{#input:type=button|onClick=sajax_do_call('wfSimpleFormsAjax',['title=no-such-article'],document.getElementById('test2'))|value=test2}}
 +
 +
<div id=test2>''this is a '''div''' tag with '''id''' attribute set to "test2"''</div>
 +
 +
The button has the following JavaScript code in its ''onClick'' event:
 +
<js>onClick=sajax_do_call('wfSimpleFormsAjax',['title=no-such-article'],document.getElementById('test2'))</js>
 +
 +
== MediaWiki API ==
 
There is a [[M:API|MediaWiki API]] under development which will allow modifcation of content via request variables inherently.
 
There is a [[M:API|MediaWiki API]] under development which will allow modifcation of content via request variables inherently.
 
: It appears that links do not parser in the edit summary e.g. [http://www.organicdesign.co.nz/wiki/index.php?title=SimpleForms_categorisation_example&diff=72521&oldid=72506 this diff]. Would be a nice to be able to link to the form deriving content--[[User:Sven|Sven]] 21:29, 30 June 2007 (NZST)
 
: It appears that links do not parser in the edit summary e.g. [http://www.organicdesign.co.nz/wiki/index.php?title=SimpleForms_categorisation_example&diff=72521&oldid=72506 this diff]. Would be a nice to be able to link to the form deriving content--[[User:Sven|Sven]] 21:29, 30 June 2007 (NZST)

Revision as of 10:23, 3 October 2007

Info.svg This talk page pertains specifically to the development of this extension. For more general discussion about bugs and usage etc, please refer to the mediawiki.org talk page at MW:Extension talk:Simple Forms


Using MediaWiki Ajax instead of MooTools

0.3.13 has had the following snippet of code added in preparation for the 0.4 release which will no longer depend on Mootools for its ajax functionality. <php> if ($wgUseAjax && $_REQUEST['action'] == 'ajax' && $_REQUEST['rs'] == 'wfSimpleFormsAjax') { $_REQUEST['action'] = 'render'; if (is_array($_REQUEST['rsargs'])) foreach ($_REQUEST['rsargs'] as $arg) if (preg_match('/^(.+?)=(.+)$/',$arg,$m)) $_REQUEST[$m[1]] = $m[2]; } </php> This allows us to use the sajax_do_call function from MediaWiki's ajax.js, but this works by requesting the AjaxDispatcher class to execute a function specified in the request and to return the results of the function. This is not quite the way SimpleForms needs it to work because the AjaxDispatcher is instantiated before any high-level MediaWiki objects have been instantiated, but SimpleForms needs to return the fully rendered page content with all extension activated etc.

The code above gets around this problem by detecting if incoming requests from sajax_do_call are specifying a function called "wfSimpleFormsAjax", and if so the action is changed to render so the request will no be handled by the AjaxDispatcher. The sajax_do_call argument list is shifted into the main $_REQUEST array as if it came from a normal GET or POST request.

Here is an example SimpleForms input which makes an ajax request using the sajax_do_call function:

{{#input:type=button|onClick=sajax_do_call('wfSimpleFormsAjax',['title=no-such-article'],document.getElementById('test2'))|value=test2}}

this is a div tag with id attribute set to "test2"

The button has the following JavaScript code in its onClick event: <js>onClick=sajax_do_call('wfSimpleFormsAjax',['title=no-such-article'],document.getElementById('test2'))</js>

MediaWiki API

There is a MediaWiki API under development which will allow modifcation of content via request variables inherently.

It appears that links do not parser in the edit summary e.g. this diff. Would be a nice to be able to link to the form deriving content--Sven 21:29, 30 June 2007 (NZST)
SimpleForms expects wikitext with links etc to be passed, but you have to put <nowiki> around it so that it's not parsed before being assigned to the form attribute. --Nad 22:01, 30 June 2007 (NZST)

Edit forms

Initially I was thinking of having an #edit parser-function which extends the #form functionality to behave differently from action=edit and the CreateArticle specialpage.

After starting the SimpleDatabase specialpage I realised that being able to open a form ajaxly that is connected to another articles content (that article acts as the forms data-source) is more intuitive, and doesn't require two different ways of defining forms.

Possibly a better solution still could be to use an editform parameter with action=edit. The parameter would determine which definition to update (by template name, with id too if necessary to disambiguate). The parameter should also be able to specify to update all (which could be a good setting for the normal edit action's url too). Maybe allowing a list of template/id's would be good too.

  • Each template definition needs to be able specify a list of forms which are able to edit it.
  • Using action=edit with forms could be the best way to handle article updating since it would use MediaWiki's edit tokens properly

Semantic Forms

This way of integrating with the existing edit system is how the SemanticForms CreateForm special-page works. Maybe SimpleForms should not try and handle the structured data side of things at all and should only handle the functionality-based inputs.