devel:plugin_programming_tips
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
devel:plugin_programming_tips [2015-05-27 13:51] – [Disabling syntax plugins in user comments] 130.112.1.3 | devel:plugin_programming_tips [2023-09-20 23:34] (current) – Klap-in | ||
---|---|---|---|
Line 5: | Line 5: | ||
On this page are some tips (see ToC right). Useful resources elsewhere in the wiki are: | On this page are some tips (see ToC right). Useful resources elsewhere in the wiki are: | ||
* [[common plugin functions# | * [[common plugin functions# | ||
- | * [[common plugin functions#Localisation]] | + | * [[common plugin functions#Localization]] |
* Plugin [[plugin file structure|file structure]] and [[plugin file structure|name conventions]] | * Plugin [[plugin file structure|file structure]] and [[plugin file structure|name conventions]] | ||
+ | * [[devel: | ||
Line 20: | Line 20: | ||
<code php> | <code php> | ||
- | | + | global $auth; |
- | if($auth-> | + | if ($auth-> |
- | $auth-> | + | $auth-> |
- | } | + | } |
</ | </ | ||
Where '' | Where '' | ||
- | Several values in each using ' | + | Several values in each using ''|'' as a separator. |
For example, to retrieve all users in the group ' | For example, to retrieve all users in the group ' | ||
<code php> | <code php> | ||
- | | + | $filter[' |
- | $array_of_matches = retrieveUsers(0, | + | $array_of_matches = $auth->retrieveUsers(0, |
</ | </ | ||
- | Be aware that the user backend | + | Be aware that the authentication plugin |
- | See also [[devel:authentication_backends#optional_methods|authentication | + | See also [[devel:auth_plugins#retrieveusers|authentication |
===== DokuWiki Global Variables ===== | ===== DokuWiki Global Variables ===== | ||
Line 53: | Line 54: | ||
===Protect forms and action urls=== | ===Protect forms and action urls=== | ||
- | If you use forms in your plugins or urls that initiate actions, you should include a hidden form field with the session-based security token. In the current version of DokuWiki you can generate this field by calling the function | + | If you use forms in your plugins or urls that initiate actions, you should include a hidden form field with the session-based security token. In the current version of DokuWiki you can generate this field by calling the function |
// | // | ||
Line 163: | Line 164: | ||
* in PHP: | * in PHP: | ||
* set a value '' | * set a value '' | ||
- | * delete an entry '' | + | * delete an entry '' |
* and retrieve its value with '' | * and retrieve its value with '' | ||
* and in javascript: | * and in javascript: | ||
Line 177: | Line 178: | ||
setCookie(" | setCookie(" | ||
</ | </ | ||
- | and in javascript | + | and in javascript: |
<code javascript> | <code javascript> | ||
jQuery.cookie(" | jQuery.cookie(" | ||
expires: 7, //days | expires: 7, //days | ||
- | path: (typeof | + | path: DOKU_COOKIE_PARAM.path, |
- | | + | secure: DOKU_COOKIE_PARAM.secure |
}); | }); | ||
- | </ | ||
- | |||
- | As long '' | ||
- | <code php> | ||
- | public function register(Doku_Event_Handler $controller) { | ||
- | $controller-> | ||
- | } | ||
- | /** | ||
- | * Fallback cookie parameters for releases before the release 2013-12-08 " | ||
- | * | ||
- | * @deprecated 2013-12-08 Temporary fallback to JSINFO.DOKU_COOKIE_PARAM | ||
- | */ | ||
- | public function _cookiepath(Doku_Event $event, $param) { | ||
- | global $JSINFO, $conf; | ||
- | $JSINFO[' | ||
- | ' | ||
- | ' | ||
- | ); | ||
- | } | ||
</ | </ | ||
Line 209: | Line 191: | ||
===== Handle JSON ajax request ===== | ===== Handle JSON ajax request ===== | ||
- | An action plugin that register the [[devel: | + | An action plugin that register the [[devel: |
Create an [[Action Plugin]] which should contain: | Create an [[Action Plugin]] which should contain: | ||
<code php lib/ | <code php lib/ | ||
- | /* | + | use dokuwiki\Extension\ActionPlugin; |
- | * plugin should use this method to register its handlers | + | use dokuwiki\Extension\EventHandler; |
- | * with the dokuwiki' | + | use dokuwiki\Extension\Event; |
- | */ | + | |
- | function register(Doku_Event_Handler | + | class action_plugin_example extends ActionPlugin { |
- | $controller-> | + | |
- | } | + | |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | $controller-> | ||
+ | } | ||
| | ||
- | /** | + | |
- | * handle ajax requests | + | |
- | */ | + | |
- | function | + | |
- | if ($event-> | + | if ($event-> |
- | return; | + | return; |
- | } | + | } |
- | //no other ajax call handlers needed | + | //no other ajax call handlers needed |
- | $event-> | + | $event-> |
- | $event-> | + | $event-> |
- | | + | |
- | global $INPUT; | + | global $INPUT; |
- | $name = $INPUT-> | + | $name = $INPUT-> |
| | ||
- | | + | |
- | $data = array(); | + | $data = []; |
- | //json library of DokuWiki | + | |
- | require_once DOKU_INC . ' | + | header(' |
- | $json = new JSON(); | + | echo json_encode($data); |
- | + | } | |
- | | + | |
- | header(' | + | |
- | echo $json-> | + | |
} | } | ||
</ | </ | ||
Line 295: | Line 280: | ||
Example: | Example: | ||
<code php> | <code php> | ||
+ | global $INPUT; | ||
+ | |||
// we are parsing a submitted comment... | // we are parsing a submitted comment... | ||
- | if (isset($_REQUEST[' | + | if ($INPUT-> |
return false; | return false; | ||
} | } | ||
Line 302: | Line 289: | ||
===== Sending popularity data ===== | ===== Sending popularity data ===== | ||
- | [[devel: | + | Since release 2015-08-10 " |
- | /!\ As a plugin developer, beware: since popularity data is public, you must not send sensitive information with this feature | + | :!: As a plugin developer, beware: since popularity data is public, you must not send sensitive information with this feature. |
The [[plugin: | The [[plugin: | ||
- | It also let the possibility to developers, to send more data about usage. It can be used by plugins developers to know if a given obsolete feature is still used. To do it, you need to subscribe to the [[devel: | + | It also let the possibility to developers, to send more data about usage. It can be used by plugins developers to know if a given obsolete feature is still used. To do it, you need to subscribe to the [[devel: |
Example: | Example: | ||
<code php action.php> | <code php action.php> | ||
- | public function register(Doku_Event_Handler | + | use dokuwiki\Extension\ActionPlugin; |
- | $controller-> | + | use dokuwiki\Extension\EventHandler; |
- | } | + | use dokuwiki\Extension\Event; |
+ | |||
+ | class action_plugin_example extends ActionPlugin { | ||
+ | | ||
+ | $controller-> | ||
+ | } | ||
| | ||
- | public function | + | |
- | $event-> | + | $event-> |
- | //or: $event-> | + | |
+ | | ||
+ | | ||
+ | | ||
+ | ]; | ||
+ | */ | ||
+ | } | ||
} | } | ||
</ | </ | ||
- | FIXME link to a plugin which uses this feature | + | A plugin which uses this feature |
devel/plugin_programming_tips.1432727511.txt.gz · Last modified: 2015-05-27 13:51 by 130.112.1.3