Basic framework for writing Deki Extensions in PHP. I hacked this together pretty quick, so it's probably buggy. I'll be polishing and releasing with more documentation soon.
Goal
- You shouldn't have to figure out how anything works - just write your PHP code and plug the output into this framework to make it magically work!
Setting it up
- You gotta use the .htaccess provided to do the rewrites
- Edit index.php for the first 3 configuration variables
- Open up includes/YourExtensions.php and create a subclass of BaseExtension which is where your functionality will be
Usage
- Your subclass has to be prefixed with "Ext"
- The property $name in your subclass is your fxn name and must be updated
- Property $param can either configed for one or multiple params:
- One param:
var $param = array('name' =>'person', 'type' => 'str', 'hint' => 'Person to say hello to!'); //valid
- One param:
var $param = array(array('name' =>'person', 'type' => 'str', 'hint' => 'Person to say hello to!')); //also valid
- Mult params:
var $param = array(
array('name' =>'person', 'type' => 'str', 'hint' => 'Person to say hello to!'),
array('name' =>'param2', 'type' => 'str', 'hint' => 'Person to say hello to!'),
);
- The invoke() method is used to trigger whatever actions you'd like. It should return a HTML string. You can also add stuff to the <head> of the wiki page by modifying the $head property on your subclass
- Be sure your args for your invoke() method match up with the order of the $param property - you will get your data back in null, bool, or string
Testing
- Calling the URI set in SITE_URI should return all the functions with your namespace; if it's missing, you didn't follow one of the instructions above (or I wrote crappy code, it's prob 50/50)
- If you get a "doc" error when you're trying to view your evaluated extension in your wiki, it's prob a PHP error - do a CURL request on the fxn you're requesting
Todo
- Test on PHP 5 (this was developed on a PHP4 server)
- More documentation
- Prob code cleanup (type checking?)
- Add in debugging tools
- A subclass which actually does something
- It is tricky to get this service running on the same domain as DekiWiki. Better to run it on a separate domain, e.g. http://localhost:81/services, or http://someotherdomain.yourdomain.com/service
- in YourExtensions.php, the $name variable needs to match your class name. E.g. if $name = 'superfunction', then classname should be Extsuperfunction.
- This extension only allows one function per class. If you want multiple functions, you need to create another class in YourExtension.php. Remember that the class name is Ext + the function name.
- If you add additional classes or change function names, you should go into the DekiWiki's Service Management and refresh your service.
- Remember that if you configure $param to use multiple parameters, your invoke() function should also take multiple parameters.
- In my testing, uppercase & lower case didn't really matter for namespaces, function names, or class names. But if you want to be safe, just do lowercase alphanumerics.
- Make sure to test the SITE_URI using curl or your browser. It should return a function list.
- Make sure that your function returns valid XML data, e.g. close all your tags and escape your ampersands. You can't escape the output using CDATA.
Some examples:
Say in YourExtensions.php, your class is named Extfoobar the function name is foobar, and it takes one parameter. In index.php, your namespace is mynamespace.
When you add the service to DekiWiki, go to the servers, add a new Remote service, and specify your SITE_URI parameter.
When you add the service it might say "can't reset the service." That's normal since the service is newly added. But it should say "successfully added the service" or something.
Now edit a wiki page, and use this syntax to call your service (assuming the values mentioned above)
{{ mynamespace.foobar('hello') }}
and it should work. 2007年 11月 27日, 23:41に編集