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-02-04 19:11] – 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 | ||
===== How to write a remote plugin? ===== | ===== How to write a remote plugin? ===== | ||
A Remote Plugin //Example// needs: | A Remote Plugin //Example// needs: | ||
+ | |||
* class name '' | * class name '' | ||
- | * which extends [[xref>DokuWiki_Remote_Plugin]]((defined in '' | + | * which extends [[xref>RemotePlugin]] |
* to be stored in a file '' | * 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]]. | 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]]. | ||
- | * Implement **'' | + | All //public// methods defined in the plugin's class will be automatically registered as remote API call in the form '' |
- | * write your methods. | + | |
- | Remote plugins specific | + | Remote plugins |
- | * **'' | + | |
+ | |||
+ | * **'' | ||
+ | * **'' | ||
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 43: | 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>\dokuwiki\Remote\RemoteException]]. |
- | + | ||
- | ===== The _getMethods Method ===== | + | |
- | The '' | + | |
- | + | ||
- | <code php> | + | |
- | array( | + | |
- | '< | + | |
- | ' | + | |
- | | + | |
- | ' | + | |
- | ' | + | |
- | | + | |
- | ), [next method] | + | |
- | ) | + | |
- | </code> | + | |
- | * ''< | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | Note: It is possible to have two entries in the '' | + | For permission errors |
- | **Example** See first code snippet on this page for an example. | + | Your plugin should use unique (for your plugin) error codes that you should list in your plugin' |
- | ===== 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 write an [[action plugin]] 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.1360001502.txt.gz · Last modified: 2013-02-04 19:11 by Klap-in