See also
Coding Guidelines for Wikka contributors
Technically, "actions" are nothing else than
PHP files, which are included and run by the Wikka engine.
As you know from
this tutorial, to use an action in a page you simply put the name of an action (and parameters if necessary) between double braces (
{{action_name [parameter1="A"][ parameter2="B"]}}). The Wikka formatter then sends the text between the two brackets to the
Action() core method . Everything after the first word is treated as a parameter of the action. If the corresponding action-file is found in the action directory, parameters are passed to it in the form of an array.
You can easily extend Wikka's functionality by writing your own actions and saving them in the actions directory. This page will give you some examples and hints on custom action creation.
The first step before writing an action is to understand what the goal of the action is and whether writing an action is the best choice for this goal.
Often you will have to decide whether your code must be written as an
action or a
handler. The simplest way to decide between these two option is the following question:
Do you wish to
add something to a page, or to
do something with the page?
- for code that adds content or a service to a page (e.g. a google search form, a weather forecast, a table etc.), an action is probably your best choice.
- for code that does something to a page (like cloning, deleting, editing...), you would probably use a handler
Don't reinvent the wheel
There are many PHP developers out there, so chances are someone has already written the code you need. You are probably familiar with the official
feature list but the (unofficial)
code contributions directory and the
User Contributions category could be a good place to start from. Many existing PHP scripts can easily be adapted to be plugged into Wikka as actions.
Find someone to help
When you start working on a new action, announce this at
PluginsInDevelopment, someone else may be willing to help. The
community mailing list and
IRC channel are also a good place to find help and support from other Wikka users and contributors.
You should always keep in mind that any user with [ACLInfo write-access]] to your wiki will be able to use an action by default. This means if you want your action to be limited to administrators or registered users, you have to take care of it in the action itself.
As said above, parameters are passed as an array to the action. A special name,
$vars, is reserved for this array. You can use the following code to get the values of an action's parameters:
A string representation of all specified parameters is also available through the special variable,
$vars['wikka_vars']. It is supported for backward compatibility, and is documented here to help you understand at a glance some actions like {{rss}}, but it's not recommended for use it in your action scripts.
Using
$this as a reference in your actions you can invoke any of Wikka's core methods. Every methods and members defined in the
Wakka.class.php can be called by your actions.
Defining a function inside an action
Because an action can be called more than once, all the code that is inside it can be executed twice or more. The following is the general rule to be followed to avoid errors due to redeclarations:
- if you use a define statement, make it conditional using the syntax if (!defined(...))
- if you define a function, make it conditional using the syntax if (!function_exists(...))
Deletions:
[177] The oldest known version of this page was created on
2006-07-13 03:27:38 by
DarTar [reverting]