Revision [2668]

This is an old revision of IncludeRemote made by DarTar on 2004-11-30 17:05:33.

 

Fetching Remote Wikka Content

Last edited by DarTar:
FetchRemote action v.0.2
Tue, 30 Nov 2004 17:05 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.


Screenshot:
http://wikka.jsnx.com/images/fetchremote.jpg


Now, here comes some code.

FetchRemote: a plugin for fetching remote documentation


FetchRemote Action
Version 0.2

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
// FetchRemote Action
// Written by DarTar <http://wikka.jsnx.com/DarTar>
// Version 0.2
//
// 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
//


// Set remote Wikka server root
//$remote_server_root = "http://wikka.jsnx.com/";
$remote_server_root="http://test/wikka-1.1.5.0/wikka.php?wakka=";

//set default remote page if no page parameter or GET value is specified
$page = $_REQUEST["page"]? $_REQUEST["page"] : $page;
if ($page == "") $page = "HelpInfo";

// redirect to home on disconnection
if ($_POST["action"] == "Disconnect") $this->Redirect($this->GetConfigValue("root_page"));

// open connection
$remote_page = fopen($remote_server_root.$page."/rawcontent", "r");
if (!$remote_page) {
    // connection failed: print static link
    echo $this->Format("=====Wikka Documentation===== --- Visit the **[[http://wikka.jsnx.com/HelpInfo Official Wikka Documentation Project]]**");
} else {
    // connection established: start fetching remote page

    // build header
    $style = "text-align: center; margin: 30px 25%; border: 1px dotted #333; background-color: #EEE; padding: 5px;";

    if ($_POST["action"] == "Download this page") {
        if ($this->LoadPage($page)) {
            // display error message: local page with the same name already exists
            $header = "@@A page named **[[".$page."]]** already exists on this site!@@ --- ";
        } else {
            // write page to database and display message
            $note = "fetched from the Wikka server";
            $this->SavePage($page, $content, $note);
            $header = "@@**[[".$page."]]** is now available on your site!@@ --- ";
        }
        $form = $this->FormOpen()."<input type='submit' name='action' value='Return to Wikka Documentation' /><input type='submit' name='action' value='Disconnect' />".$this->FormClose();
    } else {
        $header = "You are currently browsing: **";
        $header .=  "\"\"<a href='".$this->Href("","","page=".$page)."'>".$page."</a>\"\"";
        $header .= "** --- from the **[[".$this->GetPageTag()." Official Wikka Documentation]]** --- (fetched from the [[".$remote_server_root.$page." Wikka server]])";
        $form = $this->FormOpen()."<input type='hidden' name='page' value='".$page."' /><input type='submit' name='action' value='Download this page' /><input type='submit' name='action' value='Disconnect' />".$this->FormClose();
    }

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

    $forced = "/\[\[([^ ]+) ([^\]]+)\]\]/";
    $camel = "/[^a-z=>\[\/]([A-Z]+[a-z]+[A-Z][A-Za-z0-9]+)+/";

    // rewrite forced links
    $content = preg_replace($forced, "\"\"<a href='".$this->Href("","","page=\\1")."'>\\2</a>\"\"", $content);

    // rewrite camelcase links
    $content = preg_replace($camel, "\"\"<a href='".$this->Href("","","page=\\1")."'>\\1</a>\"\"", $content);

    // print rewritten content 
    print "<div style='".$style."'>".$this->Format($header).$form."</div>".$this->Format($content);

}
fclose($remote_page);
?>


<?php
// LINK REWRITING PLAYGROUND

/*
    echo $this->Format("=====Link Translation Test===== --- --- (Source: ".$remote_server_root.$page.") --- --- ");

    if (preg_match_all($forced, $content, $forcedlinks)) {
        echo $this->Format("==Forced links:==");
        foreach ($forcedlinks[0] as $fkey => $fitem) {
            $ftag = $forcedlinks[1][$fkey];
            $fanchor = $forcedlinks[2][$fkey];
            // display link and rewritten link
            echo $this->Format($fkey.": ".$fitem." => ")."<a href='".$this->Href("","","page=".$ftag)."'>".$fanchor."</a><br />";
            // add rewritten link to array 
            $fsearch[$fkey] = $fitem;  
            $freplace[$fkey] = "\"\"<a href='".$this->Href("","","page=".$ftag)."'>".$fanchor."</a>\"\"";
        }
        // rewrite forced links
        //$content = preg_replace($fsearch, $freplace, $content);
    }

       if (preg_match_all($camel, $content, $camellinks)) {
        echo $this->Format(" --- ==Camelcase links:==");
        foreach ($camellinks[0] as $ckey => $citem) {
                        $citem = ltrim($citem);
            echo $this->Format($ckey.": ".$citem." => ")."<a href='".$this->Href("","","page=".$citem)."'>".$citem."</a><br />";
            $csearch[$ckey] = $citem;
            $creplace[$ckey] = " \"\"<a href='".$this->Href("","","page=".$citem)."'>".$citem."</a>\"\"";
                }
        // rewrite CamelCase links
        //$content = preg_replace($csearch, $creplace, $content);
        }

*/

?>



-- DarTar


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