devel:remote_plugins
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
devel:remote_plugins [2013-01-22 02:52] – Klap-in | devel:remote_plugins [2024-02-06 14:12] (current) – andi | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Remote Plugins ====== | ====== Remote Plugins ====== | ||
- | Remote plugins | + | Remote plugins |
+ | |||
+ | You can check the list of extensions for available [[plugintype> | ||
===== How to write a remote plugin? ===== | ===== How to write a remote plugin? ===== | ||
- | You have to add the '' | + | A Remote Plugin //Example// needs: |
- | * Your plugin class must inherit from [[xref>DokuWiki_Remote_Plugin]]. | + | |
- | * Implement **'' | + | * class name |
- | * write your methods. | + | * which extends |
+ | * to be stored in a file '' | ||
+ | |||
+ | Moreover, a [[plugin_info|plugin.info.txt]] file is needed. For full details of plugins and their files and how to create more remote components refer to [[plugin file structure]]. | ||
+ | |||
+ | All // | ||
+ | |||
+ | Remote plugins have access to API specific methods (even though they are usually not required): | ||
- | Remote plugins specific function: | + | |
- | | + | * **'' |
Inherited functions | Inherited functions | ||
* See [[common plugin functions]] for inherited functions available to all plugins. e.g. localisation, | * See [[common plugin functions]] for inherited functions available to all plugins. e.g. localisation, | ||
- | \\ | ||
A simple skeleton is: | A simple skeleton is: | ||
- | <code php remote.php> | ||
- | <? | ||
- | class remote_plugin_time extends DokuWiki_Remote_Plugin { | ||
- | function _getMethods() { | ||
- | return array( | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ) | ||
- | ); | ||
- | } | ||
- | function getTime() { | + | <code php lib/ |
- | return | + | <?php |
+ | |||
+ | use dokuwiki\Extension\AdminPlugin; | ||
+ | |||
+ | class remote_plugin_time extends RemotePlugin { | ||
+ | |||
+ | /** | ||
+ | | ||
+ | * | ||
+ | * @return int timestamp | ||
+ | */ | ||
+ | public | ||
+ | return | ||
} | } | ||
} | } | ||
Line 39: | Line 49: | ||
===== Writing your methods ===== | ===== Writing your methods ===== | ||
- | Simple | + | Simply |
- | The only thing you cannot | + | |
+ | It is recommended to use primitive | ||
+ | |||
+ | * Dates should always be passed as Unix timestamps (seconds as Integer) | ||
+ | * Binary data should always be passed as [[wp> | ||
+ | |||
+ | For example, instead of having a method | ||
+ | |||
+ | Use docblocks to document your methods, especially your parameter | ||
- | Beside these types there are two special types, file and date. These type have to be encoded using the '' | ||
- | The '' | ||
==== Security ==== | ==== Security ==== | ||
- | The API will take care of basic security checks, i.e. user is logged in and user can access the web service. | + | The API will take care of basic security checks |
- | Every more detailed access, like per page, has to be done by the plugin. | + | |
+ | Here's an example using the [[xref> | ||
- | Take a look at the '' | ||
<code php> | <code php> | ||
- | function | + | /** |
+ | * Get page contents | ||
+ | * @param string $id The page ID | ||
+ | * @return string The page content | ||
+ | */ | ||
+ | public | ||
$id = cleanID($id); | $id = cleanID($id); | ||
- | if(auth_quickaclcheck($id) < AUTH_READ){ | + | if (auth_quickaclcheck($id) < AUTH_READ) { |
- | throw new RemoteAccessDeniedException(' | + | throw new RemoteAccessDeniedException( |
- | } | + | |
- | $text = rawWiki($id, | + | |
- | if(!$text) { | + | ); |
- | | + | |
- | } else { | + | |
- | return $text; | + | |
} | } | ||
+ | return rawWiki($id); | ||
} | } | ||
</ | </ | ||
- | Here is the '' | ||
==== Errors ==== | ==== Errors ==== | ||
- | When an error occurs you have to throw an instance of '' | + | When an error occurs you have to throw an instance of [[xref> |
- | ===== The _getMethods Method ===== | + | For permission errors |
- | The '' | + | |
- | <code php> | + | Your plugin |
- | array( | + | |
- | ' | + | |
- | ' | + | |
- | [' | + | |
- | ' | + | |
- | ' | + | |
- | [' | + | |
- | ), [next method] | + | |
- | ) | + | |
- | </ | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | Note: It is possible to have two entries in the '' | ||
- | ===== Custom remote names ===== | + | ===== Further reading |
- | In some circumstances you need a full custom name for the remote call. | + | * [[Plugin programming tips]] |
- | The [[devel:event:rpc_call_add|RPC_CALL_ADD]] event allows you to map a custom name to a remoteName of your plugin. | + | * [[plugins|Plugin Development]] |
+ | * [[devel:Remote API]] | ||
+ | * [[devel:xmlrpc|XML-RPC]] | ||
+ | * [[devel: | ||
+ | * [[plugintype> |
devel/remote_plugins.1358819554.txt.gz · Last modified: 2013-01-22 02:52 by Klap-in