Revision [2579]

This is an old revision of IncludeRemote made by JavaWoman on 2004-11-28 16:18:33.

 

Fetching Remote Wikka Content

Last edited by JavaWoman:
action code: got rid of "click here" in favor of semantic link
Sun, 28 Nov 2004 16:18 UTC [diff]





An interesting solution for making freshly-updated HelpInfo wikka documentation available to end users, without distributing the whole documentation package, might be to create a {{help page="PageName"}} plugin allowing to retrieve content from the main wikka server, using something like the raw method.

Here's how it might function:
  1. the user of a wikka distribution opens a local WikkaDocumentation page containing {{help page="HelpInfo"}};
  1. the plugin connects to the main wikka server,
  1. it retrieves a raw version of HelpInfo with no header and footer (i.e. the mere page content in wikka syntax),
  1. it parses the retrieved page for internal links and translates them into local links for retrieving remote content (links pointing to remote URLs need not be translated),
Can you provide an example of this? This is the item that I think will be hardest to implement. -- JsnX
The link might be translated as a local link to the same page with a GET parameter read by the plugin, for instance if the remote page contains: [[ACLInfo Access Control documentation]] this will be rendered locally as: <a href="WikkaDocumentation?page=ACLInfo">Access Control Documentation</a>. Alternatively, we might restrict local navigation of remote pages to one node and render links to other remote pages as masked interwikilinks: [[Wikka:ACLInfo Access Control Documentation]]. But I still prefer the first solution, with some restrictions (see notes below) -- DarTar
  1. and finally, it prints locally the documentation contents.
  1. if a connection is not available, a splash page with a static link to http://wikka.jsnx.com/HelpInfo and a short text is printed;

A similar plugin might be used also for bug notifications and other kinds of "centralized" content.
Notes:
    1. the fetched content integrates seamlessly with the layout and structure of the Wikka-client;
    1. the user can choose to download locally a fetched page, so as to make it available in its Wikka site.


Now, here comes some code. Still very poor, but it's just to give you the idea.

First draft of a plugin for fetching remote documentation


FetchRemote Action
Version 0.1

What it does

How to use it
Simply add {{fetchremote}} in one of your pages.
You can specify a starting page by adding: {{fetchremote page="HomePage"}}

Note
Remote fetching of pages through fopen() must be allowed by php (by default it is).

Todo:

Here's a three-step installation:

1. Create on the target server a rawcontent handler (handlers/page/rawcontent.php)

<?php
if ($this->HasAccess("read")) {
    if (!$this->page) {
        return;
    } else {
        // display raw page
        print($this->page["body"]);
    }
} else {
    return;
}
?>


2. Update wikka.php on the target server

The following blocks of code must be modified to enable the rawcontent handler:

A)

original
    if (preg_match('/\.(xml|mm)$/', $this->method)) {
        header("Content-type: text/xml");
        print($this->Method($this->method));
    }


modified
    if (preg_match('/\.(xml|mm)$/', $this->method)) {
        header("Content-type: text/xml");
        print($this->Method($this->method));
    }
    // rawcontent method
    elseif ($this->method == "rawcontent"){
        header("Content-type: text/plain");
        print($this->Method($this->method));
    }


B)

original
// if (!preg_match("/\.(xml|raw|mm)$/", $method))
{
    $tend = getmicrotime();  
    //Calculate the difference
    $totaltime = ($tend - $tstart);
    //Output result
    printf ("<div class=\"smallprint\">Page was generated in %.4f seconds</div>\n</body>\n</html>", $totaltime);
}  


modified
if (!preg_match("/(xml|raw|mm|rawcontent)$/", $method))
{
    $tend = getmicrotime();  
    //Calculate the difference
    $totaltime = ($tend - $tstart);
    //Output result
    printf ("<div class=\"smallprint\">Page was generated in %.4f seconds</div>\n</body>\n</html>", $totaltime);
}


3. Create in the Wikka client a FetchRemote action (actions/fetchremote.php)

<?php
// FetchRemote Action
// Written by DarTar <http://wikka.jsnx.com/DarTar>
// Version 0.1
//
// Connects to the main Wikka server and fetches Wikka Documentation Pages
// A "rawcontent" method must be available on the main Wikka server
// Forced links on fetched pages are rewritten into links to fetchable pages
//
// Parameters: page - specifies starting page on the remote server
//


// Wikka Server root
$remote_server_root = "http://wikka.jsnx.com/";

//default remote page - if no page parameter or GET value is specified
$page = $_GET["page"]? $_GET["page"] : $page;
if ($page == "") {$page = "HelpInfo";}

// open connection
$remote_page = fopen($remote_server_root.$page."/rawcontent", "r");

if (!$remote_page) {
    // connection failed: print static link
    echo $this->Format("View the **[[http://wikka.jsnx.com/HelpInfo Official Wikka Documentation]]**");

} else {
    // connection established: start fetching remote page

    // build header
    $header = "---- @@You are currently browsing the **[[".$this->GetPageTag()." Official Wikka Documentation]]** --- (fetched from the main [[http://wikka.jsnx.com/ Wikka server]]) --- Click [[".$this->GetConfigValue("root_page")." here]] to close the connection@@ ---- --- ";

    // fetch rawcontent of the page
    while (!feof ($remote_page)) {
        $content .= fgets ($remote_page, 1024);
    }

    // rewrite forced links (regex to be improved to match current wikka formatters)
    $forced = "\[\[([A-Za-z]+) ([A-Za-z \"]+)\]\]";
    $content = ereg_replace($forced, "\"\"<a href='".$this->Href("","","page=\\1")."'>\\2</a>\"\"", $content);

       
    print $this->Format($header.$content);
}
fclose($remote_page);
?>



-- DarTar


CategoryDevelopment
There are 17 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki