[dokuwiki] [Patch] XMLRPC listLinks support

Hi everyone,

attached is a patch that adds support for the listLinks() method
(suggested in the Wiki RPC Interface 2 specs) to DokuWikis xmlrpc
interface (and another one which fixes a little typo).

Unfortunately the docs aren't very clear about what links should be
returned - they only say local and external. With this patch
interwikilinks are treated as external links and other "links" like
windows shares or mail links are completely ignored. Changing that would
be easy though.

And another thing: I know the XMLRPC support of DokuWiki isn't high
priority, however I still like the idea. My question is - are we
strictly bound to the RPC Interface 2 specs or would it be OK to
introduce some own additional methods (only if they're actually useful
of course)?

Cheers,
    chi

-- 
Michael Klier

mail:   chi@xxxxxxxxxxx
www:    http://www.chimeric.de
icq:    206179334
jabber: chi@xxxxxxxxxxxxxxxxxx
key:    http://downloads.chimeric.de/chi.asc
key-id: 0x8308F551
New patches:

[XMLRPC added listLinks() support
Michael Klier <chi@xxxxxxxxxxx>**20071030012026] {
hunk ./lib/exe/xmlrpc.php 95
-
hunk ./lib/exe/xmlrpc.php 101
+        $this->addCallback(
+            'wiki.listLinks',
+            'this:listLinks',
+            array('struct','string'),
+            'Lists all links contained in a wiki page'
+        );
hunk ./lib/exe/xmlrpc.php 110
-            'wiki.listLinks'
hunk ./lib/exe/xmlrpc.php 179
-
-    function putPage($put_id, $put_text, $put_summary='', $put_minor=0, 
$put_rev = '', $put_pre = '', $put_suf = '') {
-
+    function putPage($put_id, $put_text, $put_summary='', $put_minor=0, 
$put_rev='', $put_pre='', $put_suf='') {
hunk ./lib/exe/xmlrpc.php 185
-
-        if (checklock($put_id) !== false) {
-
+        if (checklock($put_id) !== false) 
hunk ./lib/exe/xmlrpc.php 188
-        }
-
hunk ./lib/exe/xmlrpc.php 189
-        if(checkwordblock())
+        if(checkwordblock()) 
hunk ./lib/exe/xmlrpc.php 192
-        // lock the page
-
hunk ./lib/exe/xmlrpc.php 194
-        // save it
-
-        
saveWikiText($put_id,con($put_pre,$put_text,$put_suf,1),$put_summary,$put_minor);
 //use pretty mode for con
-
-        // unlock it
+        
saveWikiText($put_id,con($put_pre,$put_text,$put_suf,1),$put_summary,$put_minor);
hunk ./lib/exe/xmlrpc.php 199
+    }
+
+    /**
+     * Lists all links contained in a wiki page
+     */
+    function listLinks($id) {
+        $links = array();
+
+        // resolve page instructions
+        $ins   = p_cached_instructions(wikiFN(cleanID($id)));
+
+        // instantiate new Renderer - needed for interwiki links
+        include(DOKU_INC.'inc/parser/xhtml.php');
+        $Renderer = new Doku_Renderer_xhtml();
+        $Renderer->interwiki = getInterwiki();
+
+        // parse parse instructions
+        foreach($ins as $in) {
+            $link = array();
+            switch($in[0]) {
+                case 'internallink':
+                    $link['type'] = 'local';
+                    $link['page'] = $in[1][0];
+                    $link['href'] = wl($in[1][0]);
+                    array_push($links,$link);
+                    break;
+                case 'externallink':
+                    $link['type'] = 'extern';
+                    $link['page'] = $in[1][0];
+                    $link['href'] = $in[1][0];
+                    array_push($links,$link);
+                    break;    
+                case 'interwikilink':
+                    $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]);
+                    $link['type'] = 'extern';
+                    $link['page'] = $url;
+                    $link['href'] = $url;
+                    array_push($links,$link);
+                    break;
+            }
+        }
hunk ./lib/exe/xmlrpc.php 241
+        return $links;
}

Context:

[Revert change to DOKU_INC introduced by xmlrpc_putpage patch
Guy Brand <gb@xxxxxxxxxxxxxxxxx>**20071027202616] 
[Add the Universal Wiki Edit Button to the deafault template
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20071026213115
 
 The "Universal Wiki Edit Button" is a movement to make Wikis easily
 recognizable to users regardless of the used engine or template. The
 aim is to create an icon which is as easy to recognize as the now well
 known RSS icon. The hope is to spread the Wiki idea and make more people
 aware of the use of Wikis outside the scope of Wikipedia.
 
 The logo is added through a background CSS defined in UWEB.css
 
 More info about the Universal Wiki Edit Button can be found at
 http://www.aboutus.org/uweb - you may also add your thoughts about it
 there.
 
] 
[added makeFileField method to form class
Michael Klier <chi@xxxxxxxxxxx>**20071029141013] 
[CSS update for media form
Michael Klier <chi@xxxxxxxxxxx>**20071029135607] 
[refactored media upload form
Michael Klier <chi@xxxxxxxxxxx>**20071029134739] 
[allow enctype setting in form class
Michael Klier <chi@xxxxxxxxxxx>**20071029134359] 
[adds a second class to action buttons
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20071026210930] 
[Galician language update
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20071026205405] 
[Turkish update
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20071026185916] 
[Translatable JavaScript strings for plugins
Gabriel Birke <Gabriel.Birke@xxxxxxxxx>**20071026131130
 
 Strings to be used in plugin provided JavaScript can now be put into the 
plugin's
 lang.php files. It has to be stored as subkeys of $lang['js']. Eg the 
following in
 lib/plugins/blah/lang/en/lang.php
 
 $lang['js']['foo'] = "bar";
 
 will be available from JavaScript code as
 
 LANG['plugins']['blah']['foo']
 
 
] 
[Brasilian Portuguese Update
Frederico Goncalves Guimaraes <frederico@xxxxxxxxxxx>**20071026110711] 
[Malagasy translation added
infogasy.net <contact@xxxxxxxxxxxx>**20071026105801] 
[Latvian language update
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20071019063310] 
[Allow HTML from inline RSS (typo fix)
Tom N Harris <tnharris@xxxxxxxxxxxxx>**20071015225606] 
[Fix border condition on recent change update
Tom N Harris <tnharris@xxxxxxxxxxxxx>**20071015225711] 
[header support for renderer plugins
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20071016185626
 Renderer plugins now can store HTTP header information in 'format <mode>' which
 will be used to send their output. Also fixes a problem with loading cache 
files.
] 
[fixed Thai romanization
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20071015170603] 
[tiny compatibility fix for FeedParser
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20071015121248
 
 This should make older plugins working with a SimplePie Beta wor with 
Dokuwiki's
 current SimplePie version
] 
[Reduce memory requirement for indexer
Tom N Harris <tnharris@xxxxxxxxxxxxx>**20071012000327] 
[fixed URLs in plugin and user manager
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20071013191842
 For the new plugin repository, plugins should use a page named after their
 class at wiki.splitbrain.org
] 
[xmlrpc_putpage
Dennis Ploeger <develop@xxxxxxxxxxxxxx>**20071012135930
 
 Adds the putpage-method to the xmlrpc-server-code
 
] 
[X-Sendfile support for fetch.php
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20071008185019
 This patch enables the use of the X-Sendfile extension offered by certain
 webservers to deliver static files after running a dynamic script. This
 combines the flexibility of a PHP file to check for authorization, caching
 and resizing with the low memory footprint and high performance of static
 file delivery of the webserver.
 
 See http://blog.lighttpd.net/articles/2006/07/02/x-sendfile for details
] 
[esperanto update
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20071007191109] 
[corrections for earlier MAIL_MESSAGE_SEND patch :)
Chris Smith <chris@xxxxxxxxxxxxx>**20070930124603] 
[fixes for p_get_metadata() & p_set_metadata (incl. resolution of FS#1254)
Chris Smith <chris@xxxxxxxxxxxxx>**20070930022739
 
 - add page existence check to prevent attempts to render metadata for 
non-existent pages (FS#1254)
 - add key & subkey existence checks to avoid PHP warnings
] 
[add page_exists function (inc/pageutils.php)
Chris Smith <chris@xxxxxxxxxxxxx>**20070930021040
 
 bool page_exists($id, $rev='', $clean=true)
 
 checks wiki page existence, returns true if page exists, false if it doesn't.  
Parameters are the same as for wikiFN()
 
 $id    -- page id
 $rev   -- page revision
 $clean -- flag indicating whether or not $id requires cleaning
 
] 
[ptln parameter spelling correction
Chris Smith <chris@xxxxxxxxxxxxx>**20070930020815] 
[Add MAIL_MESSAGE_SEND event (resolution of FS#1007)
Chris Smith <chris@xxxxxxxxxxxxx>**20070930014728
 
 Wrapper around DokuWiki's mail_send() function.
 For full details refer 
http://wiki.splitbrain.org/wiki:events_list#mail_message_send
 
 Also see discussion at 
http://www.freelists.org/archives/dokuwiki/09-2007/msg00077.html
 
] 
[Avoid duplicate attributes in forms
Tom N Harris <tnharris@xxxxxxxxxxxxx>**20071006195720] 
[Remove extraneous print statement
Tom N Harris <tnharris@xxxxxxxxxxxxx>**20071001192639] 
[TAG develsnap 2007-10-01
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20070930230001] 
Patch bundle hash:
8eddcad872693a2137df440bd1ca3cfedadb28dd

Other related posts: