Not logged in. · Lost password · Register
Forum: General Help and Support Development RSS
How to properly subclass DokuWiki_Remote_Plugin and use RemoteAPICore functionality
Avatar
mforkel #1
Member since Jun 2007 · 123 posts
Group memberships: Members
Show profile · Link to this post
Subject: How to properly subclass DokuWiki_Remote_Plugin and use RemoteAPICore functionality
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!
Avatar
andi (Administrator) #2
User title: splitbrain
Member since May 2006 · 3539 posts · Location: Berlin Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by mforkel:
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.

Let me stop you right there. All XML produced by the API should be valid. If it isn't, it is a bug and needs to be fixed. Instead of putting energy into a workaround, please use it to create a proper bug report (or even better, a fix).
Read this if you don't get any useful answers.
Lies dies wenn du keine hilfreichen Antworten bekommst.
Avatar
mforkel #3
Member since Jun 2007 · 123 posts
Group memberships: Members
Show profile · Link to this post
Don't worry, the XML produced by the API is fine :-). If there is a bug to fix, its in Python's XML-RCP client.

The XML-RPC spec allows almost any unicode characters to be transmitted, the XML 1.0 spec does not. Python's current implementation of XML-RPC is using expat, which is XML 1.0 compliant. To better support XML-RPC, Python should be using an XML 1.1 spec complient XML parser.

Because I'm using a Python client to access my wiki via XML-RPC, I had to write the remote plugin for the base64 encoded transfer of pages that contain characters not supported by XML 1.0.
This post was edited on 2020-02-04, 15:54 by mforkel.
Avatar
mforkel #4
Member since Jun 2007 · 123 posts
Group memberships: Members
Show profile · Link to this post
Could anybody please explain to me why the superclass constructor does not seem to work?
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2020-04-04, 11:14:56 (UTC +02:00)