Revision [2563]
This is an old revision of IncludeRemote made by DarTar on 2004-11-27 19:11:04.
Fetching Remote Wikka Content
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:
- the user of a wikka distribution opens a local WikkaDocumentation page containing {{help page="HelpInfo"}};
- the plugin connects to the main wikka server,
- it retrieves a raw version of HelpInfo with no header and footer (i.e. the mere page content in wikka syntax),
- 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
- and finally, it prints locally the documentation contents.
- 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:
- no MySQL connection to the central database is needed, provided that a method exists for retrieving pure page content with the header and footer stripped;
- when displaying locally a remote page, a box (like a grey float at the top of each fetched page) should alert the user that he is actually retrieving remote content. Otherwise the risk is to be "trapped" on the main wikka server without realizing it!
- when local and remote pages with the same name exist, the user should be given the choice which of the two pages he wants to display. This can be easily implemented with a check for tag existence on the local server and then by appending to <a href="WikkaDocumentation?page=ACLInfo">Access Control Documentation</a> something like [[ACLInfo (*)]].
Clicking on (*), the user will switch to local pages.
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
- Connects to the main Wikka server and fetches Wikka Documentation Pages
A "rawcontent" method must be available on the main Wikka server, in order to produce raw wikka-formatted content with header and footer stripped.
- Parses the fetched page and rewrites forced links as links to fetchable pages
- Prints the fetched page locally, together with a header
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:
- Forced link rewriting: change regex to match actual wikka formatters
- CamelCase link rewriting
- Check for local pages with the same name of remote pages
- Prevent non-existing remote pages from being fetched
Here's a three-step installation:
1. Create 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;
}
?>
if ($this->HasAccess("read")) {
if (!$this->page) {
return;
} else {
// display raw page
print($this->page["body"]);
}
} else {
return;
}
?>
2. Update wikka.php
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));
}
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));
}
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);
}
{
$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);
}
{
$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 the 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("Click [[http://wikka.jsnx.com/HelpInfo here]] to visit the **Official Wikka Documentation**");
} else {
// connection established: start fetching remote page
// print header
$header = "----@@You are currently browsing the **Official Wikka Documentation** --- from the [[http://wikka.jsnx.com/ WikkaWiki 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 still to be improved to match current wikka formatters)
$content = ereg_replace("\[\[([A-Za-z]+) ([A-Za-z \"]+)\]\]", "\"\"<a href='".$this->page."?page=\\1'>\\2</a>\"\"", $content);
print $this->Format($header.$content);
}
fclose($remote_page);
?>
// 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("Click [[http://wikka.jsnx.com/HelpInfo here]] to visit the **Official Wikka Documentation**");
} else {
// connection established: start fetching remote page
// print header
$header = "----@@You are currently browsing the **Official Wikka Documentation** --- from the [[http://wikka.jsnx.com/ WikkaWiki 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 still to be improved to match current wikka formatters)
$content = ereg_replace("\[\[([A-Za-z]+) ([A-Za-z \"]+)\]\]", "\"\"<a href='".$this->page."?page=\\1'>\\2</a>\"\"", $content);
print $this->Format($header.$content);
}
fclose($remote_page);
?>
-- DarTar
CategoryDevelopment