I'm working on a small remote plugin that base64 encodes/decodes page data for transfer, because some of my pages contain characters that cause the XML 1.0 compliant parser used by Python's xmlrpc package to choke.
Since I don't know any PHP, this is copy & paste programming. So while my plugin is working, there are (at least :-)) two things I'd like to understand a little better. May be some kind soul could explain?
Question 1 - Subclassing DokuWiki_Remote_Plugin1:
The class DokuWiki_Remote_Plugin is defined in lib/plugins/remote.php with this constructor:
public function __construct() {
$this->api = new RemoteAPI();
}
My class extends DokuWiki_Remote_Plugin, but to my surprise $this-api is not defined when I try to use it in one of my class' methods. Currently, I use the following constructor in my class:
public function __construct() {
parent::__construct(); // XXX does not initialize $this->api as expected
$this->api = new RemoteAPI(); // XXX duplicates base class constructor
$this->apicore = new RemoteAPICore($this->api);
}
That does not look right to me, but without the explicit assignment to $this->api, it will stay undefined.
But then, also in lib/plugins/remote.php, there is
protected function getApi() {
return $this->api;
}
If I call this method, I do get an instance auf RemoteAPI. I don't understand why.
Question 2 - Using RemoteAPICore functionality:
As my methods just wrap core methods into base64 encoding / decoding, I use an instance of RemoteAPICore (see constructor above), e.g.
public function encodedRawPage($id, $rev='') {
$text = $this->apicore->rawPage($id, $rev);
return base64_encode($text);
}
Would it be more PHP'ish or DokuWiki'ish not to use RemoteAPICore and write something like
$text = $this->getApi()->call('wiki.getPage', array($id));
Thanks for your help!