Revision history for IncludeRemote


Revision [19173]

Last edited on 2008-01-28 00:14:25 by DarTar [Modified links pointing to docs server]

No Differences

Revision [16928]

Edited on 2007-05-31 23:27:21 by DarTar [Reverted]
Additions:
#define('PATTERN_URL', '\b[a-z]+:\/\/\S+'); # copied from formatter
define('PATTERN_URL', '[a-z]+:\/\/\S+'); # copied from formatter - adapted
#define('PATTERN_URL2', '^([a-z]+:\/\/\S+?)([^[:alnum:]^\/])?$'); # copied from formatter
define('PATTERN_URL2', '\b[a-z]+:\/\/[[:alnum:]][-_[:alnum:]\/@:\.,_\?&;=]+[-_[:alnum:]\/\?&;=]'); # copied from formatter - adapted to recognize more URLs, @@@ not perfect yet
define('PATTERN_INTERWIKI', '\b[A-Zƒ÷‹][A-Za-zƒ÷‹?‰ˆ¸]+[:](?![=_])\S*\b'); # copied from formatter
define('PATTERN_FORCEDURL', '\[\[(?!")'.PATTERN_URL2.'(\s+(.*?))?\]\]'); # forced link with URL (ignore) @@@ (?!") still needed??
// regex pattern for forced links: accept "internal pages" (camelwords) on remote server but ignore URLs
define('PATTERN_FORCED', '\[\[(?!")([^\s\/\]]+)(\s+(.*?))?\]\]'); # forced link not with URL (rewrite) @@@ (?!") still needed??
// regex patterns to recognize a "CamelWord"
#define('PATTERN_CAMELWORD', '[A-Z]+[a-z]+[A-Z][A-Za-z0-9]+'); # @@@ make equivalent to formatter (see below)
#define('PATTERN_CAMELWORD', '\b[A-Zƒ÷‹]+[a-z?‰ˆ¸]+[A-Z0-9ƒ÷‹][A-Za-z0-9ƒ÷‹?‰ˆ¸]*\b'); # copied from formatter but removed brackets
define('PATTERN_CAMELWORD', '[A-Zƒ÷‹]+[a-z?‰ˆ¸]+[A-Z0-9ƒ÷‹][A-Za-z0-9ƒ÷‹?‰ˆ¸]*'); # copied from formatter but removed brackets
#define('PATTERN_FREECAMEL', '(\s*)('.PATTERN_CAMELWORD.')'); # @@@ not needed? leave for now
// regex pattern to recognize an image link (imaghe links with URLs are left to the formatter)
define('PATTERN_IMGLINK', 'link="('.PATTERN_CAMELWORD.')"');
/* problems solved so far
forced links:
- a forced link like [[MHM]] just disappeared (see CreateNewPage)
- forced links of the form [[WikiName]]s are misinterpreted (mangled result) (example on WikkaBugsResolved "Interwiki is broken")
- some URLs (in forced links) not recognized but should be ignored (see DarTar)
- forced links on NotifyOnChange not recognized at all (caused by the credits in (single) [] ?) => No: solution: single LinkRewrite!
camelwords:
- JsnX not recognised (see WikkaBugsResolved) => incorrect RE
- Words like Mod040fSmartPageTitles not recognized (see WikkaBugsResolved) => incorrect RE
ignores:
- ignore literals ""[[double bracket]]"" or ""WikiWord"" were rewritten when they shouldn't be (see also CreateNewPage)
- ignore code blocks (may contain forced links or WikiWords)
- ignore URLs that contain camelwords => simply ignore URLs
- URL with embedded camelword on its own on a line: URL not recognized (see Mod039fMindMapMod) => error in preg_replace_callback RE
- ignore InterWiki links (see WikiName for an example; better xmp at WikkaBugsResolved "Interwiki is broken")
- code not recognized on LoggedUsersHomepage and RedirectOnLogin => solution: single LinkRewrite!
- literal not recognized on LoggedUsersHomepage (Camel matched first on ""IntraNet"" - why?) => solution: single LinkRewrite!
- interwiki links broken again in single-function rewrite (see WikkaBugsResolved "Interwiki is broken") => clumsy fix with extra function
- OrphanedPages shows error message:
"Unknown action; an action name can consist only of US-ASCII characters and/or digits." but no page names at all...
=> add ignore for actions
other:
- code blocks may disappear or be broken (see FeedbackAction for an example) => incorrect code block ignore; RE must be match over multiple lines
*/
/* outstanding problems
- rewritten image links show up as external links - unavoidable, I think: the image does link to an external URL after rewriting! (see AddingLinks for an example)
*/
/* list of important TEST pages
- CreateNewPage - forced link without description (test correct RE and matching elements for forced links)
- literals that should be ignored (including literal containing URL containing camelword)
- NotifyOnChange - more forced links (test not getting confused by extra [] around forced links)
- WikkaBugsResolved - forced links of the form [[WikiName]]s - see "Interwiki is broken"
- InterWiki links
- camelwords like JsnX and Mod040fSmartPageTitles (test correct RE for camelwords)
- DarTar - forced links with external URLs (test not rewriting such forced links)
- LoggedUsersHomepage - literals to be ignored (such as ""IntraNet"") as well as code blocks
- FeedbackAction - code blocks (containing camelwords, literals and forced links) to be ignored
- FreeMind - forced link with URL containing underscore (test correct URL RE)
- Mod039fMindMapMod - lone camelword on one line followed by lone URL with camelword on next line (test URL RE and preg_replace_callback RE)
- OrphanedPages - action (with camelword!) should be ignored
- AddingLinks - image actions should NOT be ignored
*/
/* (possible) server-side bugs
- XBUG: problem with googleform on UsingActions => cause: bug in googleform itself! => REPORTED on WikkaBugs
- XBUG? OrphanedPages - shown directly starts with an "orphan" '12Action!' (does not exist) followed by page names; database problem?
*/
// SET DEFAULTS
$remote_server_root = 'http://wikka.jsnx.com/'; # set remote server root
//$remote_server_root = "http://test/wikka-1.1.5.0/wikka.php?wakka="; # debug server
$defaultpage = 'WikkaDocumentation'; # define default page to be fetched
if (isset($page)) $defaultpage = $page; # pick up action parameter
if (isset($_REQUEST['page'])) $defaultpage = $_REQUEST['page']; # pick up URL parameter
$page = $defaultpage; # ready to roll
// PERFORM REDIRECTIONS
// redirect to main documentation page
if ($_POST['action'] == 'Return to Wikka Documentation') $this->Redirect($this->GetPageTag());
// redirect to Wikka homepage on disconnection
if ($_POST['action'] == 'Disconnect') $this->Redirect($this->GetConfigValue('root_page'));
// switch to local version of the page
if ($_POST['action'] == 'See local version') $this->Redirect($page);
// automatically redirect to local page if it exists
// NOTE: the use of this feature is discouraged since it traps users 'locally'
// and prevents them from accessing recently updated versions of the Wikka documentation
//if ($this->LoadPage($page)) $this->Redirect($page);
// SET HEADER & FORM ELEMENTS
// header style
// to be replaced by a CSS selector in the definitive version
$style = 'text-align: center; margin: 30px 25%; border: 1px dotted #333; background-color: #EEE; padding: 5px;';
// build form chunks
$form_local = '<input type="submit" name="action" value="See local version" />'; # i18n
$form_main = '<input type="submit" name="action" value="Return to Wikka Documentation" />'; # i18n
$form_disconnect = '<input type="submit" name="action" value="Disconnect" />'; # i18n
$form_page = '<input type="hidden" name="page" value="'.$page.'" />';
$form_download = '<input type="submit" name="action" value="Download this page" />'; # i18n
// TRY TO CONNECT
$remote_page = fopen($remote_server_root.$page."/raw", "r");
if (!$remote_page) {
// NO CONNECTION AVAILABLE
echo $this->Format('=====Wikka Documentation===== --- Visit the **[[http://wikka.jsnx.com/WikkaDocumentation Wikka Documentation Project]]** --- --- ');
// if a local version of the starting page is available:
if ($this->LoadPage($page)) print $this->FormOpen().$form_local.$this->FormClose();
} else {
// CONNECTION ESTABLISHED
// fetch raw content of remote page
while (!feof($remote_page)) {
$content .= fgets($remote_page, 1024);
}
if (!$content)
{
// missing or empty page: show error message
$header = 'Sorry, **';
$header .= '""<a href="'.$this->Href('','','page='.$page).'">'.$page.'</a>""';
$header .= '** cannot be found on the [['.$remote_server_root.$page.' Wikka server]]! --- --- ';
$form = $this->FormOpen().$form_page;
$form .= ($this->LoadPage($page)) ? $form_local : '';
$form .= $form_main.$this->FormClose();
}
else
{
// START LINK-REWRITING ENGINE
// define callback functions
// mark strings to be ignored for rewriting
function MarkIgnore($things)
{
/* DEBUG - remove later
if ('' != $things[0])
{
echo '<br/>START MarkIgnore - $things:<pre>';
print_r($things);
echo '</pre>';
}
/**/
$thing = $things[0];
// ignore things BEFORE looking at forced links or camels
if (
// s modifier to match over multiple lines
// i modifier to make case-insensitive
preg_match('/'.PATTERN_CODE.'/s',$thing) # ignore code block
|| preg_match('/'.PATTERN_LITERAL.'/s',$thing) # ignore literals
|| preg_match('/'.PATTERN_ACTION.'/is',$thing) # ignore actions (keywords are case-insensitive and may be camelword!)
|| preg_match('/'.PATTERN_INTERWIKI.'/',$thing) # ignore Interwiki links
)
{
/* DEBUG - remove later
echo 'CODE, LITERAL or INTERWIKI match: {'.htmlspecialchars($thing).'}<br/>';
/**/
$output = IGNOREMARKER.$thing.IGNOREMARKER; # mark to be ignored
}
// ignore attributes except in image (action) links - MUST come before checking URLs
elseif (preg_match('/'.PATTERN_ATTRIB.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>ATTRIB match:<pre>';
print_r($matches);
echo '</pre>';
/**/
if ('link' != $matches[1])
{
$output = $matches[1].IGNOREMARKER.$matches[2].IGNOREMARKER;
/* DEBUG - remove later
echo 'ATTRIB output: {'.htmlspecialchars($output).'}<br/>';
/**/
}
else
{
$output = $thing;
/* DEBUG - remove later
echo 'ATTRIB output in image link: {'.htmlspecialchars($output).'}<br/>';
/**/
}
}
// ignore forced links with URLs and 'free' URLs
elseif (
preg_match('/'.PATTERN_FORCEDURL.'/', $thing) # ignore forced links with URLs
|| preg_match('/'.PATTERN_URL2.'/', $thing) # ignore URLs
)
{
/* DEBUG - remove later
if (preg_match('/'.PATTERN_FORCEDURL.'/', $thing)) {
echo '<br/>FORCEDURL or URL match:<pre>';
echo htmlspecialchars($thing);
echo '</pre>';
}
/**/
$output = IGNOREMARKER.$thing.IGNOREMARKER; # mark to be ignored
/* DEBUG - remove later
echo 'REWRITE IGNORE (FORCED) URL - output: {'.htmlentities($output).'}<br/><br/>';
/**/
}
/* DEBUG - remove later
echo 'IGNORE - output: {'.htmlentities($output).'}<br/><br/>';
/**/
return $output;
}
// rewrite links (unless in a to be ignored string)
function RewriteLink($things)
{
/* DEBUG - remove later
if ('' != $things[0])
{
echo '<br/>START RewriteLink - $things:<pre>';
print_r($things);
echo '</pre>';
}
/**/
global $wakka;
$thing = $things[0];
if (preg_match('/'.PATTERN_IGNORE.'/s',$thing)) # already marked as ignore: nothing to do
{
/* DEBUG - remove later
echo 'IGNORE match: {'.htmlspecialchars($thing).'}<br/>';
/**/
$output = $thing;
}
// rewrite forced (non-URL) links
elseif (preg_match('/'.PATTERN_FORCED.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>FORCED match:<pre>';
print_r($matches);
echo '</pre>';
/**/
if (isset($matches[3]))
#$linktext = preg_replace('/'.PATTERN_CAMELWORD.'/', IGNOREMARKER."$0".IGNOREMARKER, $matches[3]);
$linktext = $matches[3];
else
$linktext = $matches[1]; # use name for forced link without a description (like [[MHM]])
$output = IGNOREMARKER.'""<a href="'.$wakka->Href('','',"page=".$matches[1]).'">'.$linktext.'</a>""'.IGNOREMARKER;
/* DEBUG - remove later
echo 'REWRITE FORCED - output: {'.htmlentities($output).'}<br/><br/>';
/**/
}
// rewrite image links - MUST come before rewriting Camelwords!
elseif (preg_match('/'.PATTERN_IMGLINK.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>IMGLINK match:<pre>';
print_r($matches);
echo '</pre>';
/**/
$output = 'link="'.$wakka->Href('','',"page=".$matches[1]).'"';
/* DEBUG - remove later/
echo 'REWRITE IMGLINK - output: {'.htmlspecialchars($output).'}<br/><br/>';
/**/
}
// rewrite Camelwords
elseif (preg_match('/'.PATTERN_CAMELWORD.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>CAMEL match:<pre>';
print_r($matches);
echo '</pre>';
/**/
#$output = $matches[1].'""<a href="'.$wakka->Href('','',"page=".$matches[2]).'">'.$matches[2].'</a>""';`# freecamel
$output = '""<a href="'.$wakka->Href('','',"page=".$matches[0]).'">'.$matches[0].'</a>""'; # camelword
/* DEBUG - remove later/
echo 'REWRITE CAMEL - output: {'.htmlentities($output).'}<br/><br/>';
/**/
}
// nothing to do
else
{
$output = $thing;
}
return $output;
}
// 1) mark things to be ignored for rewriting (formatter wil take care of these when necessary)
$content = preg_replace_callback('/'.
PATTERN_CODE.
'|'.
PATTERN_LITERAL.
'|'.
PATTERN_ACTION.
'|'.
PATTERN_INTERWIKI.
'|'.
PATTERN_FORCEDURL.
'|'.
PATTERN_URL.
'|'.
PATTERN_ATTRIB.
'/s', 'MarkIgnore', $content);
/* DEBUG (!) - remove later
echo '<br/>content before rewriting links:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/
// 2) rewrite links (unless to be ignored)
$content = preg_replace_callback('/'.
PATTERN_IGNORE. # needed to be able to skip strings to be ignored
'|'.
PATTERN_FORCED. # rewrite
'|'.
PATTERN_IMGLINK. # rewrite
'|'.
PATTERN_CAMELWORD. # rewrite
'/s', 'RewriteLink', $content);
/* DEBUG - remove later
echo '<br/>content before cleaning up ignore markers:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/
// 3)strip "ignore markers" from content
$content = str_replace(IGNOREMARKER, '', $content);
/* DEBUG - remove later
echo '<br/>content after cleaning up ignore markers:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/
if ("Download this page" == $_POST['action']) # i18n
{
// SAVING FETCHED PAGE
if ($this->LoadPage($page))
{
// local page with this name already exists => display error message
// in the future we might show a form to ask if the local version should be overwritten
$header = 'Sorry, a page named **[['.$page.']]** already exists on this site! --- '; # i18n
$form = $this->FormOpen().$form_main.$form_disconnect.$this->FormClose();
}
else
{
// local page does not exist => proceed
// write page to database and display message
$note = "fetched from the Wikka server"; # i18n
$this->SavePage($page, $content, $note);
$header = 'This page is now available on your site! --- --- '; # i18n
$form = $this->FormOpen().$form_page.$form_local.$form_main.$this->FormClose();
}
}
else
{
// display default header & form # @@@ i18n!!
$header = 'You are currently browsing: **';
$header .= '""<a href="'.$this->Href('','','page='.$page).'">'.$page.'</a>""';
$header .= '** --- from the **[['.$this->GetPageTag().' Wikka Documentation Project]]** --- ';
$header .= '(fetched from the [['.$remote_server_root.$page.' Wikka server]])';
$form = $this->FormOpen().$form_page;
$form .= ($this->LoadPage($page)) ? $form_local : $form_download;
$form .= $form_disconnect.$this->FormClose();
}
}
/* DEBUG - remove later
echo '<br/>content after defining form:<br/>';
echo '{<pre>'.$content.'</pre>}<br/>';
/**/
// PRINT HEADER AND CONTENT
print '<div style="'.$style.'">'.$this->Format($header).$form.'</div>'.$this->Format($content);
}
// CLOSE CONNECTION
fclose($remote_page);
?>
%%
-- DarTar
''The code contains references to ""HelpInfo"" which has now disappeared and been replaced by WikkaDocumentation - I haven't updated your code here, but I //am// updating the copy I'm working on... --JavaWoman''
~done -- DarTar
''Thanks for posting this code, DarTar! (No I don't mind.) A few notes about testing this though:''
~1)''Note my just-added comment - somehow some of the regular expressions (copied from the formatter as noted, sometimes changed minimally) have become changed in transit. Compare with the corresponding code in ./formatters/wakka.php!''
~1)''You see a lot of little comment blocks starting with the line'' ##/* DEBUG - remove later## ''and ending with'' ##""/**/""## ''. They are intended to trace the inner workings of the rewrite engine while it does its work. Each of these traces can be "turned on" simply by adding'' ## */## ''to the first line so it reads'' ##/* DEBUG - remove later */## ''. Don't do that for all of them at once: you'd end up with a huge amount of output - rather, pick and choose to concentrate on a particular aspect of the link rewriting. Simply remove the'' ## */## ''from the first line of the block again to suppress the debug output, but leave the lines in place so you can later turn them on again.''
~1)''Finally, a lot still needs to be done... most of the work now was on the actual rewriting guts of the action. There are still matters of code organization, internationalization (preparation) and other things to address - but work on those aspects is pretty futile untile the rewrite engine itself works properly.''
''Have fun testing! --JavaWoman''
----
CategoryDevelopmentActions
Deletions:
#define('PATTERN_URL', '\b[a-z] :\/\/\S '); # copied from formatter
define('PATTERN_URL', '[a-z] :\/\/\S '); # copied from formatter - adapted
#define('PATTERN_URL2', '^([a-z] :\/\/\S ?)([^[:alnum:]^\/])?$'); # copied from formatter
define('PATTERN_URL2', '\b[a-z] :\/\/[[:alnum:]][-_[:alnum:]\/@:\.,_\?


Revision [16727]

Edited on 2007-05-31 10:42:19 by Io1Wnj [Reverted]
Additions:
#define('PATTERN_URL', '\b[a-z] :\/\/\S '); # copied from formatter
define('PATTERN_URL', '[a-z] :\/\/\S '); # copied from formatter - adapted
#define('PATTERN_URL2', '^([a-z] :\/\/\S ?)([^[:alnum:]^\/])?$'); # copied from formatter
define('PATTERN_URL2', '\b[a-z] :\/\/[[:alnum:]][-_[:alnum:]\/@:\.,_\?
Deletions:
#define('PATTERN_URL', '\b[a-z]+:\/\/\S+'); # copied from formatter
define('PATTERN_URL', '[a-z]+:\/\/\S+'); # copied from formatter - adapted
#define('PATTERN_URL2', '^([a-z]+:\/\/\S+?)([^[:alnum:]^\/])?$'); # copied from formatter
define('PATTERN_URL2', '\b[a-z]+:\/\/[[:alnum:]][-_[:alnum:]\/@:\.,_\?&;=]+[-_[:alnum:]\/\?&;=]'); # copied from formatter - adapted to recognize more URLs, @@@ not perfect yet
define('PATTERN_INTERWIKI', '\b[A-Zƒ÷‹][A-Za-zƒ÷‹?‰ˆ¸]+[:](?![=_])\S*\b'); # copied from formatter
define('PATTERN_FORCEDURL', '\[\[(?!")'.PATTERN_URL2.'(\s+(.*?))?\]\]'); # forced link with URL (ignore) @@@ (?!") still needed??
// regex pattern for forced links: accept "internal pages" (camelwords) on remote server but ignore URLs
define('PATTERN_FORCED', '\[\[(?!")([^\s\/\]]+)(\s+(.*?))?\]\]'); # forced link not with URL (rewrite) @@@ (?!") still needed??
// regex patterns to recognize a "CamelWord"
#define('PATTERN_CAMELWORD', '[A-Z]+[a-z]+[A-Z][A-Za-z0-9]+'); # @@@ make equivalent to formatter (see below)
#define('PATTERN_CAMELWORD', '\b[A-Zƒ÷‹]+[a-z?‰ˆ¸]+[A-Z0-9ƒ÷‹][A-Za-z0-9ƒ÷‹?‰ˆ¸]*\b'); # copied from formatter but removed brackets
define('PATTERN_CAMELWORD', '[A-Zƒ÷‹]+[a-z?‰ˆ¸]+[A-Z0-9ƒ÷‹][A-Za-z0-9ƒ÷‹?‰ˆ¸]*'); # copied from formatter but removed brackets
#define('PATTERN_FREECAMEL', '(\s*)('.PATTERN_CAMELWORD.')'); # @@@ not needed? leave for now
// regex pattern to recognize an image link (imaghe links with URLs are left to the formatter)
define('PATTERN_IMGLINK', 'link="('.PATTERN_CAMELWORD.')"');
/* problems solved so far
forced links:
- a forced link like [[MHM]] just disappeared (see CreateNewPage)
- forced links of the form [[WikiName]]s are misinterpreted (mangled result) (example on WikkaBugsResolved "Interwiki is broken")
- some URLs (in forced links) not recognized but should be ignored (see DarTar)
- forced links on NotifyOnChange not recognized at all (caused by the credits in (single) [] ?) => No: solution: single LinkRewrite!
camelwords:
- JsnX not recognised (see WikkaBugsResolved) => incorrect RE
- Words like Mod040fSmartPageTitles not recognized (see WikkaBugsResolved) => incorrect RE
ignores:
- ignore literals ""[[double bracket]]"" or ""WikiWord"" were rewritten when they shouldn't be (see also CreateNewPage)
- ignore code blocks (may contain forced links or WikiWords)
- ignore URLs that contain camelwords => simply ignore URLs
- URL with embedded camelword on its own on a line: URL not recognized (see Mod039fMindMapMod) => error in preg_replace_callback RE
- ignore InterWiki links (see WikiName for an example; better xmp at WikkaBugsResolved "Interwiki is broken")
- code not recognized on LoggedUsersHomepage and RedirectOnLogin => solution: single LinkRewrite!
- literal not recognized on LoggedUsersHomepage (Camel matched first on ""IntraNet"" - why?) => solution: single LinkRewrite!
- interwiki links broken again in single-function rewrite (see WikkaBugsResolved "Interwiki is broken") => clumsy fix with extra function
- OrphanedPages shows error message:
"Unknown action; an action name can consist only of US-ASCII characters and/or digits." but no page names at all...
=> add ignore for actions
other:
- code blocks may disappear or be broken (see FeedbackAction for an example) => incorrect code block ignore; RE must be match over multiple lines
*/
/* outstanding problems
- rewritten image links show up as external links - unavoidable, I think: the image does link to an external URL after rewriting! (see AddingLinks for an example)
*/
/* list of important TEST pages
- CreateNewPage - forced link without description (test correct RE and matching elements for forced links)
- literals that should be ignored (including literal containing URL containing camelword)
- NotifyOnChange - more forced links (test not getting confused by extra [] around forced links)
- WikkaBugsResolved - forced links of the form [[WikiName]]s - see "Interwiki is broken"
- InterWiki links
- camelwords like JsnX and Mod040fSmartPageTitles (test correct RE for camelwords)
- DarTar - forced links with external URLs (test not rewriting such forced links)
- LoggedUsersHomepage - literals to be ignored (such as ""IntraNet"") as well as code blocks
- FeedbackAction - code blocks (containing camelwords, literals and forced links) to be ignored
- FreeMind - forced link with URL containing underscore (test correct URL RE)
- Mod039fMindMapMod - lone camelword on one line followed by lone URL with camelword on next line (test URL RE and preg_replace_callback RE)
- OrphanedPages - action (with camelword!) should be ignored
- AddingLinks - image actions should NOT be ignored
*/
/* (possible) server-side bugs
- XBUG: problem with googleform on UsingActions => cause: bug in googleform itself! => REPORTED on WikkaBugs
- XBUG? OrphanedPages - shown directly starts with an "orphan" '12Action!' (does not exist) followed by page names; database problem?
*/
// SET DEFAULTS
$remote_server_root = 'http://wikka.jsnx.com/'; # set remote server root
//$remote_server_root = "http://test/wikka-1.1.5.0/wikka.php?wakka="; # debug server
$defaultpage = 'WikkaDocumentation'; # define default page to be fetched
if (isset($page)) $defaultpage = $page; # pick up action parameter
if (isset($_REQUEST['page'])) $defaultpage = $_REQUEST['page']; # pick up URL parameter
$page = $defaultpage; # ready to roll
// PERFORM REDIRECTIONS
// redirect to main documentation page
if ($_POST['action'] == 'Return to Wikka Documentation') $this->Redirect($this->GetPageTag());
// redirect to Wikka homepage on disconnection
if ($_POST['action'] == 'Disconnect') $this->Redirect($this->GetConfigValue('root_page'));
// switch to local version of the page
if ($_POST['action'] == 'See local version') $this->Redirect($page);
// automatically redirect to local page if it exists
// NOTE: the use of this feature is discouraged since it traps users 'locally'
// and prevents them from accessing recently updated versions of the Wikka documentation
//if ($this->LoadPage($page)) $this->Redirect($page);
// SET HEADER & FORM ELEMENTS
// header style
// to be replaced by a CSS selector in the definitive version
$style = 'text-align: center; margin: 30px 25%; border: 1px dotted #333; background-color: #EEE; padding: 5px;';
// build form chunks
$form_local = '<input type="submit" name="action" value="See local version" />'; # i18n
$form_main = '<input type="submit" name="action" value="Return to Wikka Documentation" />'; # i18n
$form_disconnect = '<input type="submit" name="action" value="Disconnect" />'; # i18n
$form_page = '<input type="hidden" name="page" value="'.$page.'" />';
$form_download = '<input type="submit" name="action" value="Download this page" />'; # i18n
// TRY TO CONNECT
$remote_page = fopen($remote_server_root.$page."/raw", "r");
if (!$remote_page) {
// NO CONNECTION AVAILABLE
echo $this->Format('=====Wikka Documentation===== --- Visit the **[[http://wikka.jsnx.com/WikkaDocumentation Wikka Documentation Project]]** --- --- ');
// if a local version of the starting page is available:
if ($this->LoadPage($page)) print $this->FormOpen().$form_local.$this->FormClose();
} else {
// CONNECTION ESTABLISHED
// fetch raw content of remote page
while (!feof($remote_page)) {
$content .= fgets($remote_page, 1024);
}
if (!$content)
{
// missing or empty page: show error message
$header = 'Sorry, **';
$header .= '""<a href="'.$this->Href('','','page='.$page).'">'.$page.'</a>""';
$header .= '** cannot be found on the [['.$remote_server_root.$page.' Wikka server]]! --- --- ';
$form = $this->FormOpen().$form_page;
$form .= ($this->LoadPage($page)) ? $form_local : '';
$form .= $form_main.$this->FormClose();
}
else
{
// START LINK-REWRITING ENGINE
// define callback functions
// mark strings to be ignored for rewriting
function MarkIgnore($things)
{
/* DEBUG - remove later
if ('' != $things[0])
{
echo '<br/>START MarkIgnore - $things:<pre>';
print_r($things);
echo '</pre>';
}
/**/
$thing = $things[0];
// ignore things BEFORE looking at forced links or camels
if (
// s modifier to match over multiple lines
// i modifier to make case-insensitive
preg_match('/'.PATTERN_CODE.'/s',$thing) # ignore code block
|| preg_match('/'.PATTERN_LITERAL.'/s',$thing) # ignore literals
|| preg_match('/'.PATTERN_ACTION.'/is',$thing) # ignore actions (keywords are case-insensitive and may be camelword!)
|| preg_match('/'.PATTERN_INTERWIKI.'/',$thing) # ignore Interwiki links
)
{
/* DEBUG - remove later
echo 'CODE, LITERAL or INTERWIKI match: {'.htmlspecialchars($thing).'}<br/>';
/**/
$output = IGNOREMARKER.$thing.IGNOREMARKER; # mark to be ignored
}
// ignore attributes except in image (action) links - MUST come before checking URLs
elseif (preg_match('/'.PATTERN_ATTRIB.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>ATTRIB match:<pre>';
print_r($matches);
echo '</pre>';
/**/
if ('link' != $matches[1])
{
$output = $matches[1].IGNOREMARKER.$matches[2].IGNOREMARKER;
/* DEBUG - remove later
echo 'ATTRIB output: {'.htmlspecialchars($output).'}<br/>';
/**/
}
else
{
$output = $thing;
/* DEBUG - remove later
echo 'ATTRIB output in image link: {'.htmlspecialchars($output).'}<br/>';
/**/
}
}
// ignore forced links with URLs and 'free' URLs
elseif (
preg_match('/'.PATTERN_FORCEDURL.'/', $thing) # ignore forced links with URLs
|| preg_match('/'.PATTERN_URL2.'/', $thing) # ignore URLs
)
{
/* DEBUG - remove later
if (preg_match('/'.PATTERN_FORCEDURL.'/', $thing)) {
echo '<br/>FORCEDURL or URL match:<pre>';
echo htmlspecialchars($thing);
echo '</pre>';
}
/**/
$output = IGNOREMARKER.$thing.IGNOREMARKER; # mark to be ignored
/* DEBUG - remove later
echo 'REWRITE IGNORE (FORCED) URL - output: {'.htmlentities($output).'}<br/><br/>';
/**/
}
/* DEBUG - remove later
echo 'IGNORE - output: {'.htmlentities($output).'}<br/><br/>';
/**/
return $output;
}
// rewrite links (unless in a to be ignored string)
function RewriteLink($things)
{
/* DEBUG - remove later
if ('' != $things[0])
{
echo '<br/>START RewriteLink - $things:<pre>';
print_r($things);
echo '</pre>';
}
/**/
global $wakka;
$thing = $things[0];
if (preg_match('/'.PATTERN_IGNORE.'/s',$thing)) # already marked as ignore: nothing to do
{
/* DEBUG - remove later
echo 'IGNORE match: {'.htmlspecialchars($thing).'}<br/>';
/**/
$output = $thing;
}
// rewrite forced (non-URL) links
elseif (preg_match('/'.PATTERN_FORCED.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>FORCED match:<pre>';
print_r($matches);
echo '</pre>';
/**/
if (isset($matches[3]))
#$linktext = preg_replace('/'.PATTERN_CAMELWORD.'/', IGNOREMARKER."$0".IGNOREMARKER, $matches[3]);
$linktext = $matches[3];
else
$linktext = $matches[1]; # use name for forced link without a description (like [[MHM]])
$output = IGNOREMARKER.'""<a href="'.$wakka->Href('','',"page=".$matches[1]).'">'.$linktext.'</a>""'.IGNOREMARKER;
/* DEBUG - remove later
echo 'REWRITE FORCED - output: {'.htmlentities($output).'}<br/><br/>';
/**/
}
// rewrite image links - MUST come before rewriting Camelwords!
elseif (preg_match('/'.PATTERN_IMGLINK.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>IMGLINK match:<pre>';
print_r($matches);
echo '</pre>';
/**/
$output = 'link="'.$wakka->Href('','',"page=".$matches[1]).'"';
/* DEBUG - remove later/
echo 'REWRITE IMGLINK - output: {'.htmlspecialchars($output).'}<br/><br/>';
/**/
}
// rewrite Camelwords
elseif (preg_match('/'.PATTERN_CAMELWORD.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>CAMEL match:<pre>';
print_r($matches);
echo '</pre>';
/**/
#$output = $matches[1].'""<a href="'.$wakka->Href('','',"page=".$matches[2]).'">'.$matches[2].'</a>""';`# freecamel
$output = '""<a href="'.$wakka->Href('','',"page=".$matches[0]).'">'.$matches[0].'</a>""'; # camelword
/* DEBUG - remove later/
echo 'REWRITE CAMEL - output: {'.htmlentities($output).'}<br/><br/>';
/**/
}
// nothing to do
else
{
$output = $thing;
}
return $output;
}
// 1) mark things to be ignored for rewriting (formatter wil take care of these when necessary)
$content = preg_replace_callback('/'.
PATTERN_CODE.
'|'.
PATTERN_LITERAL.
'|'.
PATTERN_ACTION.
'|'.
PATTERN_INTERWIKI.
'|'.
PATTERN_FORCEDURL.
'|'.
PATTERN_URL.
'|'.
PATTERN_ATTRIB.
'/s', 'MarkIgnore', $content);
/* DEBUG (!) - remove later
echo '<br/>content before rewriting links:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/
// 2) rewrite links (unless to be ignored)
$content = preg_replace_callback('/'.
PATTERN_IGNORE. # needed to be able to skip strings to be ignored
'|'.
PATTERN_FORCED. # rewrite
'|'.
PATTERN_IMGLINK. # rewrite
'|'.
PATTERN_CAMELWORD. # rewrite
'/s', 'RewriteLink', $content);
/* DEBUG - remove later
echo '<br/>content before cleaning up ignore markers:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/
// 3)strip "ignore markers" from content
$content = str_replace(IGNOREMARKER, '', $content);
/* DEBUG - remove later
echo '<br/>content after cleaning up ignore markers:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/
if ("Download this page" == $_POST['action']) # i18n
{
// SAVING FETCHED PAGE
if ($this->LoadPage($page))
{
// local page with this name already exists => display error message
// in the future we might show a form to ask if the local version should be overwritten
$header = 'Sorry, a page named **[['.$page.']]** already exists on this site! --- '; # i18n
$form = $this->FormOpen().$form_main.$form_disconnect.$this->FormClose();
}
else
{
// local page does not exist => proceed
// write page to database and display message
$note = "fetched from the Wikka server"; # i18n
$this->SavePage($page, $content, $note);
$header = 'This page is now available on your site! --- --- '; # i18n
$form = $this->FormOpen().$form_page.$form_local.$form_main.$this->FormClose();
}
}
else
{
// display default header & form # @@@ i18n!!
$header = 'You are currently browsing: **';
$header .= '""<a href="'.$this->Href('','','page='.$page).'">'.$page.'</a>""';
$header .= '** --- from the **[['.$this->GetPageTag().' Wikka Documentation Project]]** --- ';
$header .= '(fetched from the [['.$remote_server_root.$page.' Wikka server]])';
$form = $this->FormOpen().$form_page;
$form .= ($this->LoadPage($page)) ? $form_local : $form_download;
$form .= $form_disconnect.$this->FormClose();
}
}
/* DEBUG - remove later
echo '<br/>content after defining form:<br/>';
echo '{<pre>'.$content.'</pre>}<br/>';
/**/
// PRINT HEADER AND CONTENT
print '<div style="'.$style.'">'.$this->Format($header).$form.'</div>'.$this->Format($content);
}
// CLOSE CONNECTION
fclose($remote_page);
?>
%%
-- DarTar
''The code contains references to ""HelpInfo"" which has now disappeared and been replaced by WikkaDocumentation - I haven't updated your code here, but I //am// updating the copy I'm working on... --JavaWoman''
~done -- DarTar
''Thanks for posting this code, DarTar! (No I don't mind.) A few notes about testing this though:''
~1)''Note my just-added comment - somehow some of the regular expressions (copied from the formatter as noted, sometimes changed minimally) have become changed in transit. Compare with the corresponding code in ./formatters/wakka.php!''
~1)''You see a lot of little comment blocks starting with the line'' ##/* DEBUG - remove later## ''and ending with'' ##""/**/""## ''. They are intended to trace the inner workings of the rewrite engine while it does its work. Each of these traces can be "turned on" simply by adding'' ## */## ''to the first line so it reads'' ##/* DEBUG - remove later */## ''. Don't do that for all of them at once: you'd end up with a huge amount of output - rather, pick and choose to concentrate on a particular aspect of the link rewriting. Simply remove the'' ## */## ''from the first line of the block again to suppress the debug output, but leave the lines in place so you can later turn them on again.''
~1)''Finally, a lot still needs to be done... most of the work now was on the actual rewriting guts of the action. There are still matters of code organization, internationalization (preparation) and other things to address - but work on those aspects is pretty futile untile the rewrite engine itself works properly.''
''Have fun testing! --JavaWoman''
----
CategoryDevelopmentActions


Revision [11576]

Edited on 2005-10-25 09:53:35 by DarTar [link]
Additions:
>>**""FetchRemote"" v.0.6** available for testing
**See also:**
~-SyndicatingWikka
>>===""FetchRemote"" Action===
Deletions:
<<**""FetchRemote"" v.0.6** available for testing
<<::c::
**""FetchRemote"" Action**


Revision [8589]

Edited on 2005-05-28 12:05:38 by JavaWoman [move to subcategory]
Additions:
===== Fetching Remote Wikka Content =====
{{lastedit}}

<<**""FetchRemote"" v.0.6** available for testing
Download the [[http://wikka.openformats.org/fetchremote.phps source]] and save it as:
##actions/fetchremote.php##
''Feedback is welcome!''
<<::c::

**""FetchRemote"" Action**
Version 0.7

__Note:__
JavaWoman has done a **huge** work in improving/debugging the link rewrite engine, which now works almost perfectly.
Hope she won't mind if I post here the 0.7 'debugging version' of the code ;)

==What it does==
~-Connects to the main Wikka server and fetches Wikka Documentation Pages. --- A "raw" handler must be available on the main Wikka server, in order to produce raw wikka-formatted content with header and footer stripped.
~-Displays an error message if remote pages do not exist on the server or if a connection is not available.
~-Parses the fetched page and rewrites internal links as links to fetchable pages.
~-Prints the fetched page locally, together with a header.
~-Allows fetched pages to be safely stored on the Wikka client.
~-If a page with the same name already exists on the Wikka client, a "see local version" button instead of the "download" button is displayed.

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

==Notes==
~-Basically, the idea is to make the main Wikka site work as a //server// providing wikka-formatted content to //Wikka-clients//. There are several advantages in this approach, compared to merely fetching HTML:
~~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.
~-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;
~-Remote fetching of pages through ##fopen()## must be allowed by php (by default it is).

== Long-term development ideas ==
The potential utility of such a plugin is pretty large. Just think of scenarios in which central Mother-wikis distribute //wiki-formatted content// to Child-wikis.
Providing up-to-date documentation is only one of the possible uses of this plugin.
//And now, for something completely different//
##<mode sci-fi="on">##
Imagine that the set of patterns used by the rewrite engine to format the local version of the fetched page might be user-configurable and extended beyond link formatting. One day, we could have a plugin to retrieve content from remote 'non-wikka-powered' wikis, translate the wiki-content in wikka syntax and seamlessly integrate/save it locally. Sounds exciting, doesn't it? :)
##<mode sci-fi="off">##

==The code (##actions/fetchremote.php##) ==

__Note__ I had to modify a line in the code below because it contained two "%" in a row (which broke the code display on this page):

Before testing this code please remove the space I added between the two "%":

**original:**
##""define('PATTERN_CODE', '% %.*?% %'); # ignore code block""##

**modified:**
##""define('PATTERN_CODE', '%%.*?%%'); # ignore code block""##


%%(php)
<?php

/**
* Connects to a specified Wikka server, fetches a remote page and formats it for local use.
*
* This action allows the user to locally browse in a Wikka client content fetched from a
* remote Wikka server. It displays an error message if the remote page does not exist
* on the server or if a connection is not available.
* Once a connection is established, the fetched page is parsed for internal links, which
* are rewritten as links to fetchable pages, and printed on the screen.
* Fetched pages can then be safely stored on the Wikka client. If a local version
* of a fetched page is available, a "see local version" button replaces the default
* "download" button.
*
* A "raw" method must be available on the main Wikka server, in order to
* produce raw wikka-formatted content with header and footer stripped.
*
* @package Actions
* @name FetchRemote
*
* @author {@link http://wikka.jsnx.com/DarTar DarTar}
* @author {@link http://wikka.jsnx.com/JavaWoman JavaWoman} - replacing double by single quotes, better patterns
* @version 0.7
* @since Wikka 1.1.X
*
* @input string $page optional: Starting page on the main Wikka server;
* default: WikkaDocumentation
* can be overridden by a $_REQUEST['page'] parameter.
* @output prints fetched documentation pages
*
* @todo -CamelCase link rewriting: check regex for consistency with wikka formatters.
* -Interwiki link rewriting => don't rewrite! just prevent CamelCase rewriting here
*/


// pattern defines
// NOTE: (initial) REs for URL taken from wakka.php formatter - same potential problems.. - now adapted since there WERE indeed problems!
// string to mark a "don't replace me" camel words and other strings with
define('IGNOREMARKER', '!!!');
define('PATTERN_IGNOREMARKER', '!!!'); # @@@ PHP function to escape for RE?

// patterns to be ignored for rewriting
define('PATTERN_IGNORE', PATTERN_IGNOREMARKER.'.*?'.PATTERN_IGNOREMARKER); # string "marked up" to be ignored
//Note: REMOVE spaces between % % in the following line before using the plugin
define('PATTERN_CODE', '% %.*?% %'); # ignore code block
define('PATTERN_LITERAL', '"".*?""'); # ignore Wikka literal
define('PATTERN_ACTION', '{{(?!image).*?}}'); # ignore action _except_ image
define('PATTERN_ATTRIB', '\b(\w*?\s*)(=\s?"[^\n]*?"|=\s?\'[^\n]*?\')'); # attributes (HTML, action)
#define('PATTERN_URL', '\b[a-z]+:\/\/\S+'); # copied from formatter
define('PATTERN_URL', '[a-z]+:\/\/\S+'); # copied from formatter - adapted
#define('PATTERN_URL2', '^([a-z]+:\/\/\S+?)([^[:alnum:]^\/])?$'); # copied from formatter
define('PATTERN_URL2', '\b[a-z]+:\/\/[[:alnum:]][-_[:alnum:]\/@:\.,_\?&;=]+[-_[:alnum:]\/\?&;=]'); # copied from formatter - adapted to recognize more URLs, @@@ not perfect yet
define('PATTERN_INTERWIKI', '\b[A-Zƒ÷‹][A-Za-zƒ÷‹?‰ˆ¸]+[:](?![=_])\S*\b'); # copied from formatter
define('PATTERN_FORCEDURL', '\[\[(?!")'.PATTERN_URL2.'(\s+(.*?))?\]\]'); # forced link with URL (ignore) @@@ (?!") still needed??

// regex pattern for forced links: accept "internal pages" (camelwords) on remote server but ignore URLs
define('PATTERN_FORCED', '\[\[(?!")([^\s\/\]]+)(\s+(.*?))?\]\]'); # forced link not with URL (rewrite) @@@ (?!") still needed??

// regex patterns to recognize a "CamelWord"
#define('PATTERN_CAMELWORD', '[A-Z]+[a-z]+[A-Z][A-Za-z0-9]+'); # @@@ make equivalent to formatter (see below)
#define('PATTERN_CAMELWORD', '\b[A-Zƒ÷‹]+[a-z?‰ˆ¸]+[A-Z0-9ƒ÷‹][A-Za-z0-9ƒ÷‹?‰ˆ¸]*\b'); # copied from formatter but removed brackets
define('PATTERN_CAMELWORD', '[A-Zƒ÷‹]+[a-z?‰ˆ¸]+[A-Z0-9ƒ÷‹][A-Za-z0-9ƒ÷‹?‰ˆ¸]*'); # copied from formatter but removed brackets
#define('PATTERN_FREECAMEL', '(\s*)('.PATTERN_CAMELWORD.')'); # @@@ not needed? leave for now

// regex pattern to recognize an image link (imaghe links with URLs are left to the formatter)
define('PATTERN_IMGLINK', 'link="('.PATTERN_CAMELWORD.')"');

/* problems solved so far
forced links:
- a forced link like [[MHM]] just disappeared (see CreateNewPage)
- forced links of the form [[WikiName]]s are misinterpreted (mangled result) (example on WikkaBugsResolved "Interwiki is broken")
- some URLs (in forced links) not recognized but should be ignored (see DarTar)
- forced links on NotifyOnChange not recognized at all (caused by the credits in (single) [] ?) => No: solution: single LinkRewrite!
camelwords:
- JsnX not recognised (see WikkaBugsResolved) => incorrect RE
- Words like Mod040fSmartPageTitles not recognized (see WikkaBugsResolved) => incorrect RE
ignores:
- ignore literals ""[[double bracket]]"" or ""WikiWord"" were rewritten when they shouldn't be (see also CreateNewPage)
- ignore code blocks (may contain forced links or WikiWords)
- ignore URLs that contain camelwords => simply ignore URLs
- URL with embedded camelword on its own on a line: URL not recognized (see Mod039fMindMapMod) => error in preg_replace_callback RE
- ignore InterWiki links (see WikiName for an example; better xmp at WikkaBugsResolved "Interwiki is broken")
- code not recognized on LoggedUsersHomepage and RedirectOnLogin => solution: single LinkRewrite!
- literal not recognized on LoggedUsersHomepage (Camel matched first on ""IntraNet"" - why?) => solution: single LinkRewrite!
- interwiki links broken again in single-function rewrite (see WikkaBugsResolved "Interwiki is broken") => clumsy fix with extra function
- OrphanedPages shows error message:
"Unknown action; an action name can consist only of US-ASCII characters and/or digits." but no page names at all...
=> add ignore for actions
other:
- code blocks may disappear or be broken (see FeedbackAction for an example) => incorrect code block ignore; RE must be match over multiple lines
*/

/* outstanding problems
- rewritten image links show up as external links - unavoidable, I think: the image does link to an external URL after rewriting! (see AddingLinks for an example)
*/

/* list of important TEST pages
- CreateNewPage - forced link without description (test correct RE and matching elements for forced links)
- literals that should be ignored (including literal containing URL containing camelword)
- NotifyOnChange - more forced links (test not getting confused by extra [] around forced links)
- WikkaBugsResolved - forced links of the form [[WikiName]]s - see "Interwiki is broken"
- InterWiki links
- camelwords like JsnX and Mod040fSmartPageTitles (test correct RE for camelwords)
- DarTar - forced links with external URLs (test not rewriting such forced links)
- LoggedUsersHomepage - literals to be ignored (such as ""IntraNet"") as well as code blocks
- FeedbackAction - code blocks (containing camelwords, literals and forced links) to be ignored
- FreeMind - forced link with URL containing underscore (test correct URL RE)
- Mod039fMindMapMod - lone camelword on one line followed by lone URL with camelword on next line (test URL RE and preg_replace_callback RE)
- OrphanedPages - action (with camelword!) should be ignored
- AddingLinks - image actions should NOT be ignored
*/

/* (possible) server-side bugs
- XBUG: problem with googleform on UsingActions => cause: bug in googleform itself! => REPORTED on WikkaBugs
- XBUG? OrphanedPages - shown directly starts with an "orphan" '12Action!' (does not exist) followed by page names; database problem?
*/

// SET DEFAULTS

$remote_server_root = 'http://wikka.jsnx.com/'; # set remote server root
//$remote_server_root = "http://test/wikka-1.1.5.0/wikka.php?wakka="; # debug server

$defaultpage = 'WikkaDocumentation'; # define default page to be fetched
if (isset($page)) $defaultpage = $page; # pick up action parameter
if (isset($_REQUEST['page'])) $defaultpage = $_REQUEST['page']; # pick up URL parameter
$page = $defaultpage; # ready to roll

// PERFORM REDIRECTIONS

// redirect to main documentation page
if ($_POST['action'] == 'Return to Wikka Documentation') $this->Redirect($this->GetPageTag());

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

// switch to local version of the page
if ($_POST['action'] == 'See local version') $this->Redirect($page);

// automatically redirect to local page if it exists
// NOTE: the use of this feature is discouraged since it traps users 'locally'
// and prevents them from accessing recently updated versions of the Wikka documentation
//if ($this->LoadPage($page)) $this->Redirect($page);

// SET HEADER & FORM ELEMENTS

// header style
// to be replaced by a CSS selector in the definitive version
$style = 'text-align: center; margin: 30px 25%; border: 1px dotted #333; background-color: #EEE; padding: 5px;';

// build form chunks
$form_local = '<input type="submit" name="action" value="See local version" />'; # i18n
$form_main = '<input type="submit" name="action" value="Return to Wikka Documentation" />'; # i18n
$form_disconnect = '<input type="submit" name="action" value="Disconnect" />'; # i18n
$form_page = '<input type="hidden" name="page" value="'.$page.'" />';
$form_download = '<input type="submit" name="action" value="Download this page" />'; # i18n


// TRY TO CONNECT
$remote_page = fopen($remote_server_root.$page."/raw", "r");

if (!$remote_page) {

// NO CONNECTION AVAILABLE
echo $this->Format('=====Wikka Documentation===== --- Visit the **[[http://wikka.jsnx.com/WikkaDocumentation Wikka Documentation Project]]** --- --- ');
// if a local version of the starting page is available:
if ($this->LoadPage($page)) print $this->FormOpen().$form_local.$this->FormClose();

} else {

// CONNECTION ESTABLISHED

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

if (!$content)
{
// missing or empty page: show error message
$header = 'Sorry, **';
$header .= '""<a href="'.$this->Href('','','page='.$page).'">'.$page.'</a>""';
$header .= '** cannot be found on the [['.$remote_server_root.$page.' Wikka server]]! --- --- ';
$form = $this->FormOpen().$form_page;
$form .= ($this->LoadPage($page)) ? $form_local : '';
$form .= $form_main.$this->FormClose();
}
else
{

// START LINK-REWRITING ENGINE

// define callback functions
// mark strings to be ignored for rewriting
function MarkIgnore($things)
{
/* DEBUG - remove later
if ('' != $things[0])
{
echo '<br/>START MarkIgnore - $things:<pre>';
print_r($things);
echo '</pre>';
}
/**/
$thing = $things[0];
// ignore things BEFORE looking at forced links or camels
if (
// s modifier to match over multiple lines
// i modifier to make case-insensitive
preg_match('/'.PATTERN_CODE.'/s',$thing) # ignore code block
|| preg_match('/'.PATTERN_LITERAL.'/s',$thing) # ignore literals
|| preg_match('/'.PATTERN_ACTION.'/is',$thing) # ignore actions (keywords are case-insensitive and may be camelword!)
|| preg_match('/'.PATTERN_INTERWIKI.'/',$thing) # ignore Interwiki links
)
{
/* DEBUG - remove later
echo 'CODE, LITERAL or INTERWIKI match: {'.htmlspecialchars($thing).'}<br/>';
/**/
$output = IGNOREMARKER.$thing.IGNOREMARKER; # mark to be ignored
}
// ignore attributes except in image (action) links - MUST come before checking URLs
elseif (preg_match('/'.PATTERN_ATTRIB.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>ATTRIB match:<pre>';
print_r($matches);
echo '</pre>';
/**/
if ('link' != $matches[1])
{
$output = $matches[1].IGNOREMARKER.$matches[2].IGNOREMARKER;
/* DEBUG - remove later
echo 'ATTRIB output: {'.htmlspecialchars($output).'}<br/>';
/**/
}
else
{
$output = $thing;
/* DEBUG - remove later
echo 'ATTRIB output in image link: {'.htmlspecialchars($output).'}<br/>';
/**/
}
}
// ignore forced links with URLs and 'free' URLs
elseif (
preg_match('/'.PATTERN_FORCEDURL.'/', $thing) # ignore forced links with URLs
|| preg_match('/'.PATTERN_URL2.'/', $thing) # ignore URLs
)
{
/* DEBUG - remove later
if (preg_match('/'.PATTERN_FORCEDURL.'/', $thing)) {
echo '<br/>FORCEDURL or URL match:<pre>';
echo htmlspecialchars($thing);
echo '</pre>';
}
/**/
$output = IGNOREMARKER.$thing.IGNOREMARKER; # mark to be ignored
/* DEBUG - remove later
echo 'REWRITE IGNORE (FORCED) URL - output: {'.htmlentities($output).'}<br/><br/>';
/**/
}
/* DEBUG - remove later
echo 'IGNORE - output: {'.htmlentities($output).'}<br/><br/>';
/**/
return $output;
}

// rewrite links (unless in a to be ignored string)
function RewriteLink($things)
{
/* DEBUG - remove later
if ('' != $things[0])
{
echo '<br/>START RewriteLink - $things:<pre>';
print_r($things);
echo '</pre>';
}
/**/
global $wakka;
$thing = $things[0];
if (preg_match('/'.PATTERN_IGNORE.'/s',$thing)) # already marked as ignore: nothing to do
{
/* DEBUG - remove later
echo 'IGNORE match: {'.htmlspecialchars($thing).'}<br/>';
/**/
$output = $thing;
}
// rewrite forced (non-URL) links
elseif (preg_match('/'.PATTERN_FORCED.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>FORCED match:<pre>';
print_r($matches);
echo '</pre>';
/**/
if (isset($matches[3]))
#$linktext = preg_replace('/'.PATTERN_CAMELWORD.'/', IGNOREMARKER."$0".IGNOREMARKER, $matches[3]);
$linktext = $matches[3];
else
$linktext = $matches[1]; # use name for forced link without a description (like [[MHM]])
$output = IGNOREMARKER.'""<a href="'.$wakka->Href('','',"page=".$matches[1]).'">'.$linktext.'</a>""'.IGNOREMARKER;
/* DEBUG - remove later
echo 'REWRITE FORCED - output: {'.htmlentities($output).'}<br/><br/>';
/**/
}
// rewrite image links - MUST come before rewriting Camelwords!
elseif (preg_match('/'.PATTERN_IMGLINK.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>IMGLINK match:<pre>';
print_r($matches);
echo '</pre>';
/**/
$output = 'link="'.$wakka->Href('','',"page=".$matches[1]).'"';
/* DEBUG - remove later/
echo 'REWRITE IMGLINK - output: {'.htmlspecialchars($output).'}<br/><br/>';
/**/
}
// rewrite Camelwords
elseif (preg_match('/'.PATTERN_CAMELWORD.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>CAMEL match:<pre>';
print_r($matches);
echo '</pre>';
/**/
#$output = $matches[1].'""<a href="'.$wakka->Href('','',"page=".$matches[2]).'">'.$matches[2].'</a>""';`# freecamel
$output = '""<a href="'.$wakka->Href('','',"page=".$matches[0]).'">'.$matches[0].'</a>""'; # camelword
/* DEBUG - remove later/
echo 'REWRITE CAMEL - output: {'.htmlentities($output).'}<br/><br/>';
/**/
}
// nothing to do
else
{
$output = $thing;
}
return $output;
}

// 1) mark things to be ignored for rewriting (formatter wil take care of these when necessary)
$content = preg_replace_callback('/'.
PATTERN_CODE.
'|'.
PATTERN_LITERAL.
'|'.
PATTERN_ACTION.
'|'.
PATTERN_INTERWIKI.
'|'.
PATTERN_FORCEDURL.
'|'.
PATTERN_URL.
'|'.
PATTERN_ATTRIB.
'/s', 'MarkIgnore', $content);

/* DEBUG (!) - remove later
echo '<br/>content before rewriting links:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/

// 2) rewrite links (unless to be ignored)
$content = preg_replace_callback('/'.
PATTERN_IGNORE. # needed to be able to skip strings to be ignored
'|'.
PATTERN_FORCED. # rewrite
'|'.
PATTERN_IMGLINK. # rewrite
'|'.
PATTERN_CAMELWORD. # rewrite
'/s', 'RewriteLink', $content);

/* DEBUG - remove later
echo '<br/>content before cleaning up ignore markers:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/

// 3)strip "ignore markers" from content
$content = str_replace(IGNOREMARKER, '', $content);

/* DEBUG - remove later
echo '<br/>content after cleaning up ignore markers:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/

if ("Download this page" == $_POST['action']) # i18n
{
// SAVING FETCHED PAGE
if ($this->LoadPage($page))
{
// local page with this name already exists => display error message
// in the future we might show a form to ask if the local version should be overwritten
$header = 'Sorry, a page named **[['.$page.']]** already exists on this site! --- '; # i18n
$form = $this->FormOpen().$form_main.$form_disconnect.$this->FormClose();
}
else
{
// local page does not exist => proceed
// write page to database and display message
$note = "fetched from the Wikka server"; # i18n
$this->SavePage($page, $content, $note);
$header = 'This page is now available on your site! --- --- '; # i18n
$form = $this->FormOpen().$form_page.$form_local.$form_main.$this->FormClose();
}
}
else
{
// display default header & form # @@@ i18n!!
$header = 'You are currently browsing: **';
$header .= '""<a href="'.$this->Href('','','page='.$page).'">'.$page.'</a>""';
$header .= '** --- from the **[['.$this->GetPageTag().' Wikka Documentation Project]]** --- ';
$header .= '(fetched from the [['.$remote_server_root.$page.' Wikka server]])';
$form = $this->FormOpen().$form_page;
$form .= ($this->LoadPage($page)) ? $form_local : $form_download;
$form .= $form_disconnect.$this->FormClose();
}
}
/* DEBUG - remove later
echo '<br/>content after defining form:<br/>';
echo '{<pre>'.$content.'</pre>}<br/>';
/**/

// PRINT HEADER AND CONTENT
print '<div style="'.$style.'">'.$this->Format($header).$form.'</div>'.$this->Format($content);
}

// CLOSE CONNECTION
fclose($remote_page);
?>
%%

-- DarTar

''The code contains references to ""HelpInfo"" which has now disappeared and been replaced by WikkaDocumentation - I haven't updated your code here, but I //am// updating the copy I'm working on... --JavaWoman''

~done -- DarTar

''Thanks for posting this code, DarTar! (No I don't mind.) A few notes about testing this though:''
~1)''Note my just-added comment - somehow some of the regular expressions (copied from the formatter as noted, sometimes changed minimally) have become changed in transit. Compare with the corresponding code in ./formatters/wakka.php!''
~1)''You see a lot of little comment blocks starting with the line'' ##/* DEBUG - remove later## ''and ending with'' ##""/**/""## ''. They are intended to trace the inner workings of the rewrite engine while it does its work. Each of these traces can be "turned on" simply by adding'' ## */## ''to the first line so it reads'' ##/* DEBUG - remove later */## ''. Don't do that for all of them at once: you'd end up with a huge amount of output - rather, pick and choose to concentrate on a particular aspect of the link rewriting. Simply remove the'' ## */## ''from the first line of the block again to suppress the debug output, but leave the lines in place so you can later turn them on again.''
~1)''Finally, a lot still needs to be done... most of the work now was on the actual rewriting guts of the action. There are still matters of code organization, internationalization (preparation) and other things to address - but work on those aspects is pretty futile untile the rewrite engine itself works properly.''
''Have fun testing! --JavaWoman''
----
CategoryDevelopmentActions
Deletions:
===== Fetching Remote Wikka Content =====
{{lastedit}}

<<**""FetchRemote"" v.0.6** available for testing
Download the [[http://wikka.openformats.org/fetchremote.phps source]] and save it as:
##actions/fetchremote.php##
''Feedback is welcome!''
<<::c::

**""FetchRemote"" Action**
Version 0.7

__Note:__
JavaWoman has done a **huge** work in improving/debugging the link rewrite engine, which now works almost perfectly.
Hope she won't mind if I post here the 0.7 'debugging version' of the code ;)

==What it does==
~-Connects to the main Wikka server and fetches Wikka Documentation Pages. --- A "raw" handler must be available on the main Wikka server, in order to produce raw wikka-formatted content with header and footer stripped.
~-Displays an error message if remote pages do not exist on the server or if a connection is not available.
~-Parses the fetched page and rewrites internal links as links to fetchable pages.
~-Prints the fetched page locally, together with a header.
~-Allows fetched pages to be safely stored on the Wikka client.
~-If a page with the same name already exists on the Wikka client, a "see local version" button instead of the "download" button is displayed.

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

==Notes==
~-Basically, the idea is to make the main Wikka site work as a //server// providing wikka-formatted content to //Wikka-clients//. There are several advantages in this approach, compared to merely fetching HTML:
~~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.
~-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;
~-Remote fetching of pages through ##fopen()## must be allowed by php (by default it is).

== Long-term development ideas ==
The potential utility of such a plugin is pretty large. Just think of scenarios in which central Mother-wikis distribute //wiki-formatted content// to Child-wikis.
Providing up-to-date documentation is only one of the possible uses of this plugin.
//And now, for something completely different//
##<mode sci-fi="on">##
Imagine that the set of patterns used by the rewrite engine to format the local version of the fetched page might be user-configurable and extended beyond link formatting. One day, we could have a plugin to retrieve content from remote 'non-wikka-powered' wikis, translate the wiki-content in wikka syntax and seamlessly integrate/save it locally. Sounds exciting, doesn't it? :)
##<mode sci-fi="off">##

==The code (##actions/fetchremote.php##) ==

__Note__ I had to modify a line in the code below because it contained two "%" in a row (which broke the code display on this page):

Before testing this code please remove the space I added between the two "%":

**original:**
##""define('PATTERN_CODE', '% %.*?% %'); # ignore code block""##

**modified:**
##""define('PATTERN_CODE', '%%.*?%%'); # ignore code block""##


%%(php)
<?php

/**
* Connects to a specified Wikka server, fetches a remote page and formats it for local use.
*
* This action allows the user to locally browse in a Wikka client content fetched from a
* remote Wikka server. It displays an error message if the remote page does not exist
* on the server or if a connection is not available.
* Once a connection is established, the fetched page is parsed for internal links, which
* are rewritten as links to fetchable pages, and printed on the screen.
* Fetched pages can then be safely stored on the Wikka client. If a local version
* of a fetched page is available, a "see local version" button replaces the default
* "download" button.
*
* A "raw" method must be available on the main Wikka server, in order to
* produce raw wikka-formatted content with header and footer stripped.
*
* @package Actions
* @name FetchRemote
*
* @author {@link http://wikka.jsnx.com/DarTar DarTar}
* @author {@link http://wikka.jsnx.com/JavaWoman JavaWoman} - replacing double by single quotes, better patterns
* @version 0.7
* @since Wikka 1.1.X
*
* @input string $page optional: Starting page on the main Wikka server;
* default: WikkaDocumentation
* can be overridden by a $_REQUEST['page'] parameter.
* @output prints fetched documentation pages
*
* @todo -CamelCase link rewriting: check regex for consistency with wikka formatters.
* -Interwiki link rewriting => don't rewrite! just prevent CamelCase rewriting here
*/


// pattern defines
// NOTE: (initial) REs for URL taken from wakka.php formatter - same potential problems.. - now adapted since there WERE indeed problems!
// string to mark a "don't replace me" camel words and other strings with
define('IGNOREMARKER', '!!!');
define('PATTERN_IGNOREMARKER', '!!!'); # @@@ PHP function to escape for RE?

// patterns to be ignored for rewriting
define('PATTERN_IGNORE', PATTERN_IGNOREMARKER.'.*?'.PATTERN_IGNOREMARKER); # string "marked up" to be ignored
//Note: REMOVE spaces between % % in the following line before using the plugin
define('PATTERN_CODE', '% %.*?% %'); # ignore code block
define('PATTERN_LITERAL', '"".*?""'); # ignore Wikka literal
define('PATTERN_ACTION', '{{(?!image).*?}}'); # ignore action _except_ image
define('PATTERN_ATTRIB', '\b(\w*?\s*)(=\s?"[^\n]*?"|=\s?\'[^\n]*?\')'); # attributes (HTML, action)
#define('PATTERN_URL', '\b[a-z]+:\/\/\S+'); # copied from formatter
define('PATTERN_URL', '[a-z]+:\/\/\S+'); # copied from formatter - adapted
#define('PATTERN_URL2', '^([a-z]+:\/\/\S+?)([^[:alnum:]^\/])?$'); # copied from formatter
define('PATTERN_URL2', '\b[a-z]+:\/\/[[:alnum:]][-_[:alnum:]\/@:\.,_\?&;=]+[-_[:alnum:]\/\?&;=]'); # copied from formatter - adapted to recognize more URLs, @@@ not perfect yet
define('PATTERN_INTERWIKI', '\b[A-Zƒ÷‹][A-Za-zƒ÷‹?‰ˆ¸]+[:](?![=_])\S*\b'); # copied from formatter
define('PATTERN_FORCEDURL', '\[\[(?!")'.PATTERN_URL2.'(\s+(.*?))?\]\]'); # forced link with URL (ignore) @@@ (?!") still needed??

// regex pattern for forced links: accept "internal pages" (camelwords) on remote server but ignore URLs
define('PATTERN_FORCED', '\[\[(?!")([^\s\/\]]+)(\s+(.*?))?\]\]'); # forced link not with URL (rewrite) @@@ (?!") still needed??

// regex patterns to recognize a "CamelWord"
#define('PATTERN_CAMELWORD', '[A-Z]+[a-z]+[A-Z][A-Za-z0-9]+'); # @@@ make equivalent to formatter (see below)
#define('PATTERN_CAMELWORD', '\b[A-Zƒ÷‹]+[a-z?‰ˆ¸]+[A-Z0-9ƒ÷‹][A-Za-z0-9ƒ÷‹?‰ˆ¸]*\b'); # copied from formatter but removed brackets
define('PATTERN_CAMELWORD', '[A-Zƒ÷‹]+[a-z?‰ˆ¸]+[A-Z0-9ƒ÷‹][A-Za-z0-9ƒ÷‹?‰ˆ¸]*'); # copied from formatter but removed brackets
#define('PATTERN_FREECAMEL', '(\s*)('.PATTERN_CAMELWORD.')'); # @@@ not needed? leave for now

// regex pattern to recognize an image link (imaghe links with URLs are left to the formatter)
define('PATTERN_IMGLINK', 'link="('.PATTERN_CAMELWORD.')"');

/* problems solved so far
forced links:
- a forced link like [[MHM]] just disappeared (see CreateNewPage)
- forced links of the form [[WikiName]]s are misinterpreted (mangled result) (example on WikkaBugsResolved "Interwiki is broken")
- some URLs (in forced links) not recognized but should be ignored (see DarTar)
- forced links on NotifyOnChange not recognized at all (caused by the credits in (single) [] ?) => No: solution: single LinkRewrite!
camelwords:
- JsnX not recognised (see WikkaBugsResolved) => incorrect RE
- Words like Mod040fSmartPageTitles not recognized (see WikkaBugsResolved) => incorrect RE
ignores:
- ignore literals ""[[double bracket]]"" or ""WikiWord"" were rewritten when they shouldn't be (see also CreateNewPage)
- ignore code blocks (may contain forced links or WikiWords)
- ignore URLs that contain camelwords => simply ignore URLs
- URL with embedded camelword on its own on a line: URL not recognized (see Mod039fMindMapMod) => error in preg_replace_callback RE
- ignore InterWiki links (see WikiName for an example; better xmp at WikkaBugsResolved "Interwiki is broken")
- code not recognized on LoggedUsersHomepage and RedirectOnLogin => solution: single LinkRewrite!
- literal not recognized on LoggedUsersHomepage (Camel matched first on ""IntraNet"" - why?) => solution: single LinkRewrite!
- interwiki links broken again in single-function rewrite (see WikkaBugsResolved "Interwiki is broken") => clumsy fix with extra function
- OrphanedPages shows error message:
"Unknown action; an action name can consist only of US-ASCII characters and/or digits." but no page names at all...
=> add ignore for actions
other:
- code blocks may disappear or be broken (see FeedbackAction for an example) => incorrect code block ignore; RE must be match over multiple lines
*/

/* outstanding problems
- rewritten image links show up as external links - unavoidable, I think: the image does link to an external URL after rewriting! (see AddingLinks for an example)
*/

/* list of important TEST pages
- CreateNewPage - forced link without description (test correct RE and matching elements for forced links)
- literals that should be ignored (including literal containing URL containing camelword)
- NotifyOnChange - more forced links (test not getting confused by extra [] around forced links)
- WikkaBugsResolved - forced links of the form [[WikiName]]s - see "Interwiki is broken"
- InterWiki links
- camelwords like JsnX and Mod040fSmartPageTitles (test correct RE for camelwords)
- DarTar - forced links with external URLs (test not rewriting such forced links)
- LoggedUsersHomepage - literals to be ignored (such as ""IntraNet"") as well as code blocks
- FeedbackAction - code blocks (containing camelwords, literals and forced links) to be ignored
- FreeMind - forced link with URL containing underscore (test correct URL RE)
- Mod039fMindMapMod - lone camelword on one line followed by lone URL with camelword on next line (test URL RE and preg_replace_callback RE)
- OrphanedPages - action (with camelword!) should be ignored
- AddingLinks - image actions should NOT be ignored
*/

/* (possible) server-side bugs
- XBUG: problem with googleform on UsingActions => cause: bug in googleform itself! => REPORTED on WikkaBugs
- XBUG? OrphanedPages - shown directly starts with an "orphan" '12Action!' (does not exist) followed by page names; database problem?
*/

// SET DEFAULTS

$remote_server_root = 'http://wikka.jsnx.com/'; # set remote server root
//$remote_server_root = "http://test/wikka-1.1.5.0/wikka.php?wakka="; # debug server

$defaultpage = 'WikkaDocumentation'; # define default page to be fetched
if (isset($page)) $defaultpage = $page; # pick up action parameter
if (isset($_REQUEST['page'])) $defaultpage = $_REQUEST['page']; # pick up URL parameter
$page = $defaultpage; # ready to roll

// PERFORM REDIRECTIONS

// redirect to main documentation page
if ($_POST['action'] == 'Return to Wikka Documentation') $this->Redirect($this->GetPageTag());

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

// switch to local version of the page
if ($_POST['action'] == 'See local version') $this->Redirect($page);

// automatically redirect to local page if it exists
// NOTE: the use of this feature is discouraged since it traps users 'locally'
// and prevents them from accessing recently updated versions of the Wikka documentation
//if ($this->LoadPage($page)) $this->Redirect($page);

// SET HEADER & FORM ELEMENTS

// header style
// to be replaced by a CSS selector in the definitive version
$style = 'text-align: center; margin: 30px 25%; border: 1px dotted #333; background-color: #EEE; padding: 5px;';

// build form chunks
$form_local = '<input type="submit" name="action" value="See local version" />'; # i18n
$form_main = '<input type="submit" name="action" value="Return to Wikka Documentation" />'; # i18n
$form_disconnect = '<input type="submit" name="action" value="Disconnect" />'; # i18n
$form_page = '<input type="hidden" name="page" value="'.$page.'" />';
$form_download = '<input type="submit" name="action" value="Download this page" />'; # i18n


// TRY TO CONNECT
$remote_page = fopen($remote_server_root.$page."/raw", "r");

if (!$remote_page) {

// NO CONNECTION AVAILABLE
echo $this->Format('=====Wikka Documentation===== --- Visit the **[[http://wikka.jsnx.com/WikkaDocumentation Wikka Documentation Project]]** --- --- ');
// if a local version of the starting page is available:
if ($this->LoadPage($page)) print $this->FormOpen().$form_local.$this->FormClose();

} else {

// CONNECTION ESTABLISHED

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

if (!$content)
{
// missing or empty page: show error message
$header = 'Sorry, **';
$header .= '""<a href="'.$this->Href('','','page='.$page).'">'.$page.'</a>""';
$header .= '** cannot be found on the [['.$remote_server_root.$page.' Wikka server]]! --- --- ';
$form = $this->FormOpen().$form_page;
$form .= ($this->LoadPage($page)) ? $form_local : '';
$form .= $form_main.$this->FormClose();
}
else
{

// START LINK-REWRITING ENGINE

// define callback functions
// mark strings to be ignored for rewriting
function MarkIgnore($things)
{
/* DEBUG - remove later
if ('' != $things[0])
{
echo '<br/>START MarkIgnore - $things:<pre>';
print_r($things);
echo '</pre>';
}
/**/
$thing = $things[0];
// ignore things BEFORE looking at forced links or camels
if (
// s modifier to match over multiple lines
// i modifier to make case-insensitive
preg_match('/'.PATTERN_CODE.'/s',$thing) # ignore code block
|| preg_match('/'.PATTERN_LITERAL.'/s',$thing) # ignore literals
|| preg_match('/'.PATTERN_ACTION.'/is',$thing) # ignore actions (keywords are case-insensitive and may be camelword!)
|| preg_match('/'.PATTERN_INTERWIKI.'/',$thing) # ignore Interwiki links
)
{
/* DEBUG - remove later
echo 'CODE, LITERAL or INTERWIKI match: {'.htmlspecialchars($thing).'}<br/>';
/**/
$output = IGNOREMARKER.$thing.IGNOREMARKER; # mark to be ignored
}
// ignore attributes except in image (action) links - MUST come before checking URLs
elseif (preg_match('/'.PATTERN_ATTRIB.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>ATTRIB match:<pre>';
print_r($matches);
echo '</pre>';
/**/
if ('link' != $matches[1])
{
$output = $matches[1].IGNOREMARKER.$matches[2].IGNOREMARKER;
/* DEBUG - remove later
echo 'ATTRIB output: {'.htmlspecialchars($output).'}<br/>';
/**/
}
else
{
$output = $thing;
/* DEBUG - remove later
echo 'ATTRIB output in image link: {'.htmlspecialchars($output).'}<br/>';
/**/
}
}
// ignore forced links with URLs and 'free' URLs
elseif (
preg_match('/'.PATTERN_FORCEDURL.'/', $thing) # ignore forced links with URLs
|| preg_match('/'.PATTERN_URL2.'/', $thing) # ignore URLs
)
{
/* DEBUG - remove later
if (preg_match('/'.PATTERN_FORCEDURL.'/', $thing)) {
echo '<br/>FORCEDURL or URL match:<pre>';
echo htmlspecialchars($thing);
echo '</pre>';
}
/**/
$output = IGNOREMARKER.$thing.IGNOREMARKER; # mark to be ignored
/* DEBUG - remove later
echo 'REWRITE IGNORE (FORCED) URL - output: {'.htmlentities($output).'}<br/><br/>';
/**/
}
/* DEBUG - remove later
echo 'IGNORE - output: {'.htmlentities($output).'}<br/><br/>';
/**/
return $output;
}

// rewrite links (unless in a to be ignored string)
function RewriteLink($things)
{
/* DEBUG - remove later
if ('' != $things[0])
{
echo '<br/>START RewriteLink - $things:<pre>';
print_r($things);
echo '</pre>';
}
/**/
global $wakka;
$thing = $things[0];
if (preg_match('/'.PATTERN_IGNORE.'/s',$thing)) # already marked as ignore: nothing to do
{
/* DEBUG - remove later
echo 'IGNORE match: {'.htmlspecialchars($thing).'}<br/>';
/**/
$output = $thing;
}
// rewrite forced (non-URL) links
elseif (preg_match('/'.PATTERN_FORCED.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>FORCED match:<pre>';
print_r($matches);
echo '</pre>';
/**/
if (isset($matches[3]))
#$linktext = preg_replace('/'.PATTERN_CAMELWORD.'/', IGNOREMARKER."$0".IGNOREMARKER, $matches[3]);
$linktext = $matches[3];
else
$linktext = $matches[1]; # use name for forced link without a description (like [[MHM]])
$output = IGNOREMARKER.'""<a href="'.$wakka->Href('','',"page=".$matches[1]).'">'.$linktext.'</a>""'.IGNOREMARKER;
/* DEBUG - remove later
echo 'REWRITE FORCED - output: {'.htmlentities($output).'}<br/><br/>';
/**/
}
// rewrite image links - MUST come before rewriting Camelwords!
elseif (preg_match('/'.PATTERN_IMGLINK.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>IMGLINK match:<pre>';
print_r($matches);
echo '</pre>';
/**/
$output = 'link="'.$wakka->Href('','',"page=".$matches[1]).'"';
/* DEBUG - remove later/
echo 'REWRITE IMGLINK - output: {'.htmlspecialchars($output).'}<br/><br/>';
/**/
}
// rewrite Camelwords
elseif (preg_match('/'.PATTERN_CAMELWORD.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>CAMEL match:<pre>';
print_r($matches);
echo '</pre>';
/**/
#$output = $matches[1].'""<a href="'.$wakka->Href('','',"page=".$matches[2]).'">'.$matches[2].'</a>""';`# freecamel
$output = '""<a href="'.$wakka->Href('','',"page=".$matches[0]).'">'.$matches[0].'</a>""'; # camelword
/* DEBUG - remove later/
echo 'REWRITE CAMEL - output: {'.htmlentities($output).'}<br/><br/>';
/**/
}
// nothing to do
else
{
$output = $thing;
}
return $output;
}

// 1) mark things to be ignored for rewriting (formatter wil take care of these when necessary)
$content = preg_replace_callback('/'.
PATTERN_CODE.
'|'.
PATTERN_LITERAL.
'|'.
PATTERN_ACTION.
'|'.
PATTERN_INTERWIKI.
'|'.
PATTERN_FORCEDURL.
'|'.
PATTERN_URL.
'|'.
PATTERN_ATTRIB.
'/s', 'MarkIgnore', $content);

/* DEBUG (!) - remove later
echo '<br/>content before rewriting links:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/

// 2) rewrite links (unless to be ignored)
$content = preg_replace_callback('/'.
PATTERN_IGNORE. # needed to be able to skip strings to be ignored
'|'.
PATTERN_FORCED. # rewrite
'|'.
PATTERN_IMGLINK. # rewrite
'|'.
PATTERN_CAMELWORD. # rewrite
'/s', 'RewriteLink', $content);

/* DEBUG - remove later
echo '<br/>content before cleaning up ignore markers:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/

// 3)strip "ignore markers" from content
$content = str_replace(IGNOREMARKER, '', $content);

/* DEBUG - remove later
echo '<br/>content after cleaning up ignore markers:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/

if ("Download this page" == $_POST['action']) # i18n
{
// SAVING FETCHED PAGE
if ($this->LoadPage($page))
{
// local page with this name already exists => display error message
// in the future we might show a form to ask if the local version should be overwritten
$header = 'Sorry, a page named **[['.$page.']]** already exists on this site! --- '; # i18n
$form = $this->FormOpen().$form_main.$form_disconnect.$this->FormClose();
}
else
{
// local page does not exist => proceed
// write page to database and display message
$note = "fetched from the Wikka server"; # i18n
$this->SavePage($page, $content, $note);
$header = 'This page is now available on your site! --- --- '; # i18n
$form = $this->FormOpen().$form_page.$form_local.$form_main.$this->FormClose();
}
}
else
{
// display default header & form # @@@ i18n!!
$header = 'You are currently browsing: **';
$header .= '""<a href="'.$this->Href('','','page='.$page).'">'.$page.'</a>""';
$header .= '** --- from the **[['.$this->GetPageTag().' Wikka Documentation Project]]** --- ';
$header .= '(fetched from the [['.$remote_server_root.$page.' Wikka server]])';
$form = $this->FormOpen().$form_page;
$form .= ($this->LoadPage($page)) ? $form_local : $form_download;
$form .= $form_disconnect.$this->FormClose();
}
}
/* DEBUG - remove later
echo '<br/>content after defining form:<br/>';
echo '{<pre>'.$content.'</pre>}<br/>';
/**/

// PRINT HEADER AND CONTENT
print '<div style="'.$style.'">'.$this->Format($header).$form.'</div>'.$this->Format($content);
}

// CLOSE CONNECTION
fclose($remote_page);
?>
%%

-- DarTar

''The code contains references to ""HelpInfo"" which has now disappeared and been replaced by WikkaDocumentation - I haven't updated your code here, but I //am// updating the copy I'm working on... --JavaWoman''

~done -- DarTar

''Thanks for posting this code, DarTar! (No I don't mind.) A few notes about testing this though:''
~1)''Note my just-added comment - somehow some of the regular expressions (copied from the formatter as noted, sometimes changed minimally) have become changed in transit. Compare with the corresponding code in ./formatters/wakka.php!''
~1)''You see a lot of little comment blocks starting with the line'' ##/* DEBUG - remove later## ''and ending with'' ##""/**/""## ''. They are intended to trace the inner workings of the rewrite engine while it does its work. Each of these traces can be "turned on" simply by adding'' ## */## ''to the first line so it reads'' ##/* DEBUG - remove later */## ''. Don't do that for all of them at once: you'd end up with a huge amount of output - rather, pick and choose to concentrate on a particular aspect of the link rewriting. Simply remove the'' ## */## ''from the first line of the block again to suppress the debug output, but leave the lines in place so you can later turn them on again.''
~1)''Finally, a lot still needs to be done... most of the work now was on the actual rewriting guts of the action. There are still matters of code organization, internationalization (preparation) and other things to address - but work on those aspects is pretty futile untile the rewrite engine itself works properly.''
''Have fun testing! --JavaWoman''
----
CategoryDevelopment


Revision [3668]

Edited on 2004-12-25 20:32:14 by JavaWoman [added comment and fixed mino typo in code]
Additions:
echo '{<pre>'.$content.'</pre>}<br/>';
~done -- DarTar
''Thanks for posting this code, DarTar! (No I don't mind.) A few notes about testing this though:''
~1)''Note my just-added comment - somehow some of the regular expressions (copied from the formatter as noted, sometimes changed minimally) have become changed in transit. Compare with the corresponding code in ./formatters/wakka.php!''
~1)''You see a lot of little comment blocks starting with the line'' ##/* DEBUG - remove later## ''and ending with'' ##""/**/""## ''. They are intended to trace the inner workings of the rewrite engine while it does its work. Each of these traces can be "turned on" simply by adding'' ## */## ''to the first line so it reads'' ##/* DEBUG - remove later */## ''. Don't do that for all of them at once: you'd end up with a huge amount of output - rather, pick and choose to concentrate on a particular aspect of the link rewriting. Simply remove the'' ## */## ''from the first line of the block again to suppress the debug output, but leave the lines in place so you can later turn them on again.''
~1)''Finally, a lot still needs to be done... most of the work now was on the actual rewriting guts of the action. There are still matters of code organization, internationalization (preparation) and other things to address - but work on those aspects is pretty futile untile the rewrite engine itself works properly.''
''Have fun testing! --JavaWoman''
Deletions:
echo '|<pre>'.$content.'</pre>|<br/>';
~''done -- DarTar''


Revision [3667]

Edited on 2004-12-25 19:38:41 by DarTar [Posting JW's code and sci-fi ideas]
Additions:
Hope she won't mind if I post here the 0.7 'debugging version' of the code ;)
**original:**
**modified:**
Deletions:
Hope she won't mind if I post here the 'debugging version' of the code ;)


Revision [3666]

Edited on 2004-12-25 19:37:07 by DarTar [Posting JW's code and sci-fi ideas]
Additions:
Version 0.7
__Note:__
JavaWoman has done a **huge** work in improving/debugging the link rewrite engine, which now works almost perfectly.
Hope she won't mind if I post here the 'debugging version' of the code ;)
== Long-term development ideas ==
The potential utility of such a plugin is pretty large. Just think of scenarios in which central Mother-wikis distribute //wiki-formatted content// to Child-wikis.
Providing up-to-date documentation is only one of the possible uses of this plugin.
//And now, for something completely different//
##<mode sci-fi="on">##
Imagine that the set of patterns used by the rewrite engine to format the local version of the fetched page might be user-configurable and extended beyond link formatting. One day, we could have a plugin to retrieve content from remote 'non-wikka-powered' wikis, translate the wiki-content in wikka syntax and seamlessly integrate/save it locally. Sounds exciting, doesn't it? :)
##<mode sci-fi="off">##
__Note__ I had to modify a line in the code below because it contained two "%" in a row (which broke the code display on this page):
##""define('PATTERN_CODE', '% %.*?% %'); # ignore code block""##
Before testing this code please remove the space I added between the two "%":
##""define('PATTERN_CODE', '%%.*?%%'); # ignore code block""##
* This action allows the user to locally browse in a Wikka client content fetched from a
* remote Wikka server. It displays an error message if the remote page does not exist
* Once a connection is established, the fetched page is parsed for internal links, which
* are rewritten as links to fetchable pages, and printed on the screen.
* of a fetched page is available, a "see local version" button replaces the default
* A "raw" method must be available on the main Wikka server, in order to
* @package Actions
* @name FetchRemote
* @author {@link http://wikka.jsnx.com/DarTar DarTar}
* @author {@link http://wikka.jsnx.com/JavaWoman JavaWoman} - replacing double by single quotes, better patterns
* @version 0.7
* @since Wikka 1.1.X
* @input string $page optional: Starting page on the main Wikka server;
* default: WikkaDocumentation
* can be overridden by a $_REQUEST['page'] parameter.
* @output prints fetched documentation pages
* @todo -CamelCase link rewriting: check regex for consistency with wikka formatters.
* -Interwiki link rewriting => don't rewrite! just prevent CamelCase rewriting here
// pattern defines
// NOTE: (initial) REs for URL taken from wakka.php formatter - same potential problems.. - now adapted since there WERE indeed problems!
// string to mark a "don't replace me" camel words and other strings with
define('IGNOREMARKER', '!!!');
define('PATTERN_IGNOREMARKER', '!!!'); # @@@ PHP function to escape for RE?
// patterns to be ignored for rewriting
define('PATTERN_IGNORE', PATTERN_IGNOREMARKER.'.*?'.PATTERN_IGNOREMARKER); # string "marked up" to be ignored
//Note: REMOVE spaces between % % in the following line before using the plugin
define('PATTERN_CODE', '% %.*?% %'); # ignore code block
define('PATTERN_LITERAL', '"".*?""'); # ignore Wikka literal
define('PATTERN_ACTION', '{{(?!image).*?}}'); # ignore action _except_ image
define('PATTERN_ATTRIB', '\b(\w*?\s*)(=\s?"[^\n]*?"|=\s?\'[^\n]*?\')'); # attributes (HTML, action)
#define('PATTERN_URL', '\b[a-z]+:\/\/\S+'); # copied from formatter
define('PATTERN_URL', '[a-z]+:\/\/\S+'); # copied from formatter - adapted
#define('PATTERN_URL2', '^([a-z]+:\/\/\S+?)([^[:alnum:]^\/])?$'); # copied from formatter
define('PATTERN_URL2', '\b[a-z]+:\/\/[[:alnum:]][-_[:alnum:]\/@:\.,_\?&;=]+[-_[:alnum:]\/\?&;=]'); # copied from formatter - adapted to recognize more URLs, @@@ not perfect yet
define('PATTERN_INTERWIKI', '\b[A-Zƒ÷‹][A-Za-zƒ÷‹?‰ˆ¸]+[:](?![=_])\S*\b'); # copied from formatter
define('PATTERN_FORCEDURL', '\[\[(?!")'.PATTERN_URL2.'(\s+(.*?))?\]\]'); # forced link with URL (ignore) @@@ (?!") still needed??
// regex pattern for forced links: accept "internal pages" (camelwords) on remote server but ignore URLs
define('PATTERN_FORCED', '\[\[(?!")([^\s\/\]]+)(\s+(.*?))?\]\]'); # forced link not with URL (rewrite) @@@ (?!") still needed??
// regex patterns to recognize a "CamelWord"
#define('PATTERN_CAMELWORD', '[A-Z]+[a-z]+[A-Z][A-Za-z0-9]+'); # @@@ make equivalent to formatter (see below)
#define('PATTERN_CAMELWORD', '\b[A-Zƒ÷‹]+[a-z?‰ˆ¸]+[A-Z0-9ƒ÷‹][A-Za-z0-9ƒ÷‹?‰ˆ¸]*\b'); # copied from formatter but removed brackets
define('PATTERN_CAMELWORD', '[A-Zƒ÷‹]+[a-z?‰ˆ¸]+[A-Z0-9ƒ÷‹][A-Za-z0-9ƒ÷‹?‰ˆ¸]*'); # copied from formatter but removed brackets
#define('PATTERN_FREECAMEL', '(\s*)('.PATTERN_CAMELWORD.')'); # @@@ not needed? leave for now
// regex pattern to recognize an image link (imaghe links with URLs are left to the formatter)
define('PATTERN_IMGLINK', 'link="('.PATTERN_CAMELWORD.')"');
/* problems solved so far
forced links:
- a forced link like [[MHM]] just disappeared (see CreateNewPage)
- forced links of the form [[WikiName]]s are misinterpreted (mangled result) (example on WikkaBugsResolved "Interwiki is broken")
- some URLs (in forced links) not recognized but should be ignored (see DarTar)
- forced links on NotifyOnChange not recognized at all (caused by the credits in (single) [] ?) => No: solution: single LinkRewrite!
camelwords:
- JsnX not recognised (see WikkaBugsResolved) => incorrect RE
- Words like Mod040fSmartPageTitles not recognized (see WikkaBugsResolved) => incorrect RE
ignores:
- ignore literals ""[[double bracket]]"" or ""WikiWord"" were rewritten when they shouldn't be (see also CreateNewPage)
- ignore code blocks (may contain forced links or WikiWords)
- ignore URLs that contain camelwords => simply ignore URLs
- URL with embedded camelword on its own on a line: URL not recognized (see Mod039fMindMapMod) => error in preg_replace_callback RE
- ignore InterWiki links (see WikiName for an example; better xmp at WikkaBugsResolved "Interwiki is broken")
- code not recognized on LoggedUsersHomepage and RedirectOnLogin => solution: single LinkRewrite!
- literal not recognized on LoggedUsersHomepage (Camel matched first on ""IntraNet"" - why?) => solution: single LinkRewrite!
- interwiki links broken again in single-function rewrite (see WikkaBugsResolved "Interwiki is broken") => clumsy fix with extra function
- OrphanedPages shows error message:
"Unknown action; an action name can consist only of US-ASCII characters and/or digits." but no page names at all...
=> add ignore for actions
other:
- code blocks may disappear or be broken (see FeedbackAction for an example) => incorrect code block ignore; RE must be match over multiple lines
*/
/* outstanding problems
- rewritten image links show up as external links - unavoidable, I think: the image does link to an external URL after rewriting! (see AddingLinks for an example)
*/
/* list of important TEST pages
- CreateNewPage - forced link without description (test correct RE and matching elements for forced links)
- literals that should be ignored (including literal containing URL containing camelword)
- NotifyOnChange - more forced links (test not getting confused by extra [] around forced links)
- WikkaBugsResolved - forced links of the form [[WikiName]]s - see "Interwiki is broken"
- InterWiki links
- camelwords like JsnX and Mod040fSmartPageTitles (test correct RE for camelwords)
- DarTar - forced links with external URLs (test not rewriting such forced links)
- LoggedUsersHomepage - literals to be ignored (such as ""IntraNet"") as well as code blocks
- FeedbackAction - code blocks (containing camelwords, literals and forced links) to be ignored
- FreeMind - forced link with URL containing underscore (test correct URL RE)
- Mod039fMindMapMod - lone camelword on one line followed by lone URL with camelword on next line (test URL RE and preg_replace_callback RE)
- OrphanedPages - action (with camelword!) should be ignored
- AddingLinks - image actions should NOT be ignored
*/
/* (possible) server-side bugs
- XBUG: problem with googleform on UsingActions => cause: bug in googleform itself! => REPORTED on WikkaBugs
- XBUG? OrphanedPages - shown directly starts with an "orphan" '12Action!' (does not exist) followed by page names; database problem?
*/
$remote_server_root = 'http://wikka.jsnx.com/'; # set remote server root
if (isset($_REQUEST['page'])) $defaultpage = $_REQUEST['page']; # pick up URL parameter
if ($_POST['action'] == 'Return to Wikka Documentation') $this->Redirect($this->GetPageTag());
if ($_POST['action'] == 'Disconnect') $this->Redirect($this->GetConfigValue('root_page'));
if ($_POST['action'] == 'See local version') $this->Redirect($page);
// NOTE: the use of this feature is discouraged since it traps users 'locally'
//if ($this->LoadPage($page)) $this->Redirect($page);
$style = 'text-align: center; margin: 30px 25%; border: 1px dotted #333; background-color: #EEE; padding: 5px;';
$form_local = '<input type="submit" name="action" value="See local version" />'; # i18n
$form_main = '<input type="submit" name="action" value="Return to Wikka Documentation" />'; # i18n
$form_disconnect = '<input type="submit" name="action" value="Disconnect" />'; # i18n
$form_page = '<input type="hidden" name="page" value="'.$page.'" />';
$form_download = '<input type="submit" name="action" value="Download this page" />'; # i18n
echo $this->Format('=====Wikka Documentation===== --- Visit the **[[http://wikka.jsnx.com/WikkaDocumentation Wikka Documentation Project]]** --- --- ');
while (!feof($remote_page)) {
$content .= fgets($remote_page, 1024);
if (!$content)
{
$header = 'Sorry, **';
$header .= '""<a href="'.$this->Href('','','page='.$page).'">'.$page.'</a>""';
$header .= '** cannot be found on the [['.$remote_server_root.$page.' Wikka server]]! --- --- ';
$form .= ($this->LoadPage($page)) ? $form_local : '';
else
{
// define callback functions
// mark strings to be ignored for rewriting
function MarkIgnore($things)
{
/* DEBUG - remove later
if ('' != $things[0])
{
echo '<br/>START MarkIgnore - $things:<pre>';
print_r($things);
echo '</pre>';
/**/
$thing = $things[0];
// ignore things BEFORE looking at forced links or camels
if (
// s modifier to match over multiple lines
// i modifier to make case-insensitive
preg_match('/'.PATTERN_CODE.'/s',$thing) # ignore code block
|| preg_match('/'.PATTERN_LITERAL.'/s',$thing) # ignore literals
|| preg_match('/'.PATTERN_ACTION.'/is',$thing) # ignore actions (keywords are case-insensitive and may be camelword!)
|| preg_match('/'.PATTERN_INTERWIKI.'/',$thing) # ignore Interwiki links
)
{
/* DEBUG - remove later
echo 'CODE, LITERAL or INTERWIKI match: {'.htmlspecialchars($thing).'}<br/>';
/**/
$output = IGNOREMARKER.$thing.IGNOREMARKER; # mark to be ignored
// ignore attributes except in image (action) links - MUST come before checking URLs
elseif (preg_match('/'.PATTERN_ATTRIB.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>ATTRIB match:<pre>';
print_r($matches);
echo '</pre>';
/**/
if ('link' != $matches[1])
{
$output = $matches[1].IGNOREMARKER.$matches[2].IGNOREMARKER;
/* DEBUG - remove later
echo 'ATTRIB output: {'.htmlspecialchars($output).'}<br/>';
/**/
}
else
{
$output = $thing;
/* DEBUG - remove later
echo 'ATTRIB output in image link: {'.htmlspecialchars($output).'}<br/>';
/**/
}
// ignore forced links with URLs and 'free' URLs
elseif (
preg_match('/'.PATTERN_FORCEDURL.'/', $thing) # ignore forced links with URLs
|| preg_match('/'.PATTERN_URL2.'/', $thing) # ignore URLs
)
{
/* DEBUG - remove later
if (preg_match('/'.PATTERN_FORCEDURL.'/', $thing)) {
echo '<br/>FORCEDURL or URL match:<pre>';
echo htmlspecialchars($thing);
echo '</pre>';
/**/
$output = IGNOREMARKER.$thing.IGNOREMARKER; # mark to be ignored
/* DEBUG - remove later
echo 'REWRITE IGNORE (FORCED) URL - output: {'.htmlentities($output).'}<br/><br/>';
/**/
/* DEBUG - remove later
echo 'IGNORE - output: {'.htmlentities($output).'}<br/><br/>';
/**/
// rewrite links (unless in a to be ignored string)
function RewriteLink($things)
{
/* DEBUG - remove later
if ('' != $things[0])
{
echo '<br/>START RewriteLink - $things:<pre>';
print_r($things);
echo '</pre>';
/**/
$thing = $things[0];
if (preg_match('/'.PATTERN_IGNORE.'/s',$thing)) # already marked as ignore: nothing to do
{
/* DEBUG - remove later
echo 'IGNORE match: {'.htmlspecialchars($thing).'}<br/>';
/**/
$output = $thing;
// rewrite forced (non-URL) links
elseif (preg_match('/'.PATTERN_FORCED.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>FORCED match:<pre>';
print_r($matches);
echo '</pre>';
/**/
if (isset($matches[3]))
#$linktext = preg_replace('/'.PATTERN_CAMELWORD.'/', IGNOREMARKER."$0".IGNOREMARKER, $matches[3]);
$linktext = $matches[3];
else
$linktext = $matches[1]; # use name for forced link without a description (like [[MHM]])
$output = IGNOREMARKER.'""<a href="'.$wakka->Href('','',"page=".$matches[1]).'">'.$linktext.'</a>""'.IGNOREMARKER;
/* DEBUG - remove later
echo 'REWRITE FORCED - output: {'.htmlentities($output).'}<br/><br/>';
/**/
// rewrite image links - MUST come before rewriting Camelwords!
elseif (preg_match('/'.PATTERN_IMGLINK.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>IMGLINK match:<pre>';
print_r($matches);
echo '</pre>';
/**/
$output = 'link="'.$wakka->Href('','',"page=".$matches[1]).'"';
/* DEBUG - remove later/
echo 'REWRITE IMGLINK - output: {'.htmlspecialchars($output).'}<br/><br/>';
/**/
// rewrite Camelwords
elseif (preg_match('/'.PATTERN_CAMELWORD.'/',$thing,$matches))
{
/* DEBUG - remove later
echo '<br/>CAMEL match:<pre>';
print_r($matches);
echo '</pre>';
/**/
#$output = $matches[1].'""<a href="'.$wakka->Href('','',"page=".$matches[2]).'">'.$matches[2].'</a>""';`# freecamel
$output = '""<a href="'.$wakka->Href('','',"page=".$matches[0]).'">'.$matches[0].'</a>""'; # camelword
/* DEBUG - remove later/
echo 'REWRITE CAMEL - output: {'.htmlentities($output).'}<br/><br/>';
/**/
// nothing to do
else
{
$output = $thing;
// 1) mark things to be ignored for rewriting (formatter wil take care of these when necessary)
$content = preg_replace_callback('/'.
PATTERN_CODE.
'|'.
PATTERN_LITERAL.
'|'.
PATTERN_ACTION.
'|'.
PATTERN_INTERWIKI.
'|'.
PATTERN_FORCEDURL.
'|'.
PATTERN_URL.
'|'.
PATTERN_ATTRIB.
'/s', 'MarkIgnore', $content);
/* DEBUG (!) - remove later
echo '<br/>content before rewriting links:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/
// 2) rewrite links (unless to be ignored)
$content = preg_replace_callback('/'.
PATTERN_IGNORE. # needed to be able to skip strings to be ignored
'|'.
PATTERN_FORCED. # rewrite
'|'.
PATTERN_IMGLINK. # rewrite
'|'.
PATTERN_CAMELWORD. # rewrite
'/s', 'RewriteLink', $content);
/* DEBUG - remove later
echo '<br/>content before cleaning up ignore markers:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/
// 3)strip "ignore markers" from content
$content = str_replace(IGNOREMARKER, '', $content);
/* DEBUG - remove later
echo '<br/>content after cleaning up ignore markers:<br/>';
echo '{<pre>'.htmlspecialchars($content).'</pre>}<br/>';
/**/
if ("Download this page" == $_POST['action']) # i18n
{
if ($this->LoadPage($page))
{
$header = 'Sorry, a page named **[['.$page.']]** already exists on this site! --- '; # i18n
$form = $this->FormOpen().$form_main.$form_disconnect.$this->FormClose();
else
{
$note = "fetched from the Wikka server"; # i18n
$header = 'This page is now available on your site! --- --- '; # i18n
$form = $this->FormOpen().$form_page.$form_local.$form_main.$this->FormClose();
else
{
// display default header & form # @@@ i18n!!
$header = 'You are currently browsing: **';
$header .= '""<a href="'.$this->Href('','','page='.$page).'">'.$page.'</a>""';
$header .= '** --- from the **[['.$this->GetPageTag().' Wikka Documentation Project]]** --- ';
$header .= '(fetched from the [['.$remote_server_root.$page.' Wikka server]])';
$form = $this->FormOpen().$form_page;
$form .= ($this->LoadPage($page)) ? $form_local : $form_download;
$form .= $form_disconnect.$this->FormClose();
/* DEBUG - remove later
echo '<br/>content after defining form:<br/>';
echo '|<pre>'.$content.'</pre>|<br/>';
/**/
print '<div style="'.$style.'">'.$this->Format($header).$form.'</div>'.$this->Format($content);
Deletions:
Version 0.6
==Todo:==
~-Forced link rewriting: '' done'' - check regex for consistency with wikka formatters.
~-CamelCase link rewriting: ''done'' - check regex for consistency with wikka formatters.
~-Interwiki link rewriting
* This action allows the user to locally browse in a Wikka client content fetched from a
* remote Wikka server. It displays an error message if the remote page does not exist
* Once a connection is established, the fetched page is parsed for internal links, which
* are rewritten as links to fetchable pages, and printed on the screen.
* of a fetched page is available, a "see local version" button replaces the default
*
* A "raw" method must be available on the main Wikka server, in order to
* @package Actions
* @name FetchRemote
* @author {@link http://wikka.jsnx.com/DarTar DarTar}
* @version 0.6
* @since Wikka 1.1.X
* @input string $page optional: Starting page on the main Wikka server;
* default: WikkaDocumentation
* can be overridden by a $_REQUEST["page"] parameter.
* @output prints fetched documentation pages
* @todo -Forced link rewriting: check regex for consistency with wikka formatters.
* -CamelCase link rewriting: check regex for consistency with wikka formatters.
* -Interwiki link rewriting.
$remote_server_root = "http://wikka.jsnx.com/"; # set remote server root
if (isset($_REQUEST["page"])) $defaultpage = $_REQUEST["page"]; # pick up URL parameter
if ($_POST["action"] == "Return to Wikka Documentation") $this->Redirect($this->GetPageTag());
if ($_POST["action"] == "Disconnect") $this->Redirect($this->GetConfigValue("root_page"));
if ($_POST["action"] == "See local version") $this->Redirect($page);
// NOTE: the use of this feature is discouraged since it traps users 'locally'
//if ($this->LoadPage($page)) $this->Redirect($page);
$style = "text-align: center; margin: 30px 25%; border: 1px dotted #333; background-color: #EEE; padding: 5px;";
$form_local = "<input type='submit' name='action' value='See local version' />";
$form_main = "<input type='submit' name='action' value='Return to Wikka Documentation' />";
$form_disconnect = "<input type='submit' name='action' value='Disconnect' />";
$form_page = "<input type='hidden' name='page' value='".$page."' />";
$form_download = "<input type='submit' name='action' value='Download this page' />";
echo $this->Format("=====Wikka Documentation===== --- Visit the **[[http://wikka.jsnx.com/WikkaDocumentation Wikka Documentation Project]]** --- --- ");
while (!feof($remote_page)) {
$content .= fgets($remote_page, 1024);
if (!$content) {
$header = "Sorry, **";
$header .= "\"\"<a href='".$this->Href("","","page=".$page)."'>".$page."</a>\"\"";
$header .= "** cannot be found on the [[".$remote_server_root.$page." Wikka server]]! --- --- ";
$form .= ($this->LoadPage($page))? $form_local : "";
} else {
// regex pattern for forced links to *internal pages* on remote server
//$forced = "/\[\[([^ \/]+) ([^\]]+)\]\]/"; #original
//$forced = "/\[\[(\S*)(\s+(.+))?\]\]/"; #JW's suggestion
//$forced = "/\[\[([^\s\/]+)(\s+(.+))??\]\]/"; #patched
$forced = "/\[\[([^\s\/]+)(\s+([^\]]+))?\]\]/"; # patched & working
// regex pattern for CamelCase links to *internal pages* on remote server
$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);
// build callback function for marking CamelCase words within forced links
function MarkCamel($fmatches) {
$camel = "/([A-Z]+[a-z]+[A-Z][A-Za-z0-9]+)+/";
$markedcamel = preg_replace($camel, "|||\\1|||", $fmatches[2]);
$output = '""<a href="'.$wakka->Href('','',"page=".$fmatches[1]).'">'.$markedcamel.'</a>""';
// rewrite forced links
$content = preg_replace_callback($forced, 'MarkCamel', $content);
// rewrite camelcase links
$content = preg_replace($camel, ' ""<a href="'.$this->Href('','',"page=\\1").'">'."\\1".'</a>""', $content);
//strip "|||" markers from content
$content = str_replace("|||", "", $content);

if ($_POST["action"] == "Download this page") {
if ($this->LoadPage($page)) {
$header = "Sorry, a page named **[[".$page."]]** already exists on this site! --- ";
$form = $this->FormOpen().$form_main.$form_disconnect.$this->FormClose();
} else {
$note = "fetched from the Wikka server";
$header = "This page is now available on your site! --- --- ";
$form = $this->FormOpen().$form_page.$form_local.$form_main.$this->FormClose();
} else {

// display default header & form
$header = "You are currently browsing: **";
$header .= "\"\"<a href='".$this->Href("","","page=".$page)."'>".$page."</a>\"\"";
$header .= "** --- from the **[[".$this->GetPageTag()." Wikka Documentation Project]]** --- ";
$header .= "(fetched from the [[".$remote_server_root.$page." Wikka server]])";
$form = $this->FormOpen().$form_page;
$form .= ($this->LoadPage($page))? $form_local : $form_download;
$form .= $form_disconnect.$this->FormClose();
print "<div style='".$style."'>".$this->Format($header).$form."</div>".$this->Format($content);


Revision [3276]

Edited on 2004-12-15 22:56:59 by DarTar [Renaming default fetched page and uploading fixed source]
Additions:
* default: WikkaDocumentation
echo $this->Format("=====Wikka Documentation===== --- Visit the **[[http://wikka.jsnx.com/WikkaDocumentation Wikka Documentation Project]]** --- --- ");
Deletions:
* default: HelpInfo
echo $this->Format("=====Wikka Documentation===== --- Visit the **[[http://wikka.jsnx.com/HelpInfo Wikka Documentation Project]]** --- --- ");


Revision [3275]

Edited on 2004-12-15 22:52:28 by DarTar [Renaming default fetched page and uploading fixed source]
Additions:
$defaultpage = 'WikkaDocumentation'; # define default page to be fetched
~''done -- DarTar''
Deletions:
$defaultpage = 'HelpInfo'; # define default page to be fetched


Revision [3258]

Edited on 2004-12-15 19:53:01 by JavaWoman [*not* replacing HelpInfo by WikkaDocumentation: comment]
Additions:
* @input string $page optional: Starting page on the main Wikka server;
''The code contains references to ""HelpInfo"" which has now disappeared and been replaced by WikkaDocumentation - I haven't updated your code here, but I //am// updating the copy I'm working on... --JavaWoman''
Deletions:
* @input string  $page  optional: Starting page on the main Wikka server;


Revision [2908]

Edited on 2004-12-07 10:27:42 by DarTar [FetchRemote action v.0.6 - download link + better pattern for forced links]
Additions:
//$remote_server_root = "http://test/wikka-1.1.5.0/wikka.php?wakka="; # debug server
//$forced = "/\[\[([^\s\/]+)(\s+(.+))??\]\]/"; #patched
$forced = "/\[\[([^\s\/]+)(\s+([^\]]+))?\]\]/"; # patched & working
Deletions:
//$forced = "/\[\[([^\s\/]+)(\s+([^\]]+))?\]\]/"; # patched
$forced = "/\[\[([^\s\/]+)(\s+(.+))??\]\]/"; # this is clean and working
// 1) This is working
$output = '""<a href="'.$fmatches[1].'">'.$markedcamel.'</a>""';
// 2) This is NOT working
// How do I call a global function from within a callback function?


Revision [2905]

Edited on 2004-12-07 10:18:55 by DarTar [FetchRemote action v.0.6 - download link + better pattern for forced links]
Additions:
* A "raw" method must be available on the main Wikka server, in order to
* produce raw wikka-formatted content with header and footer stripped.
// fetch raw content of remote page
//$forced = "/\[\[([^\s\/]+)(\s+([^\]]+))?\]\]/"; # patched
$forced = "/\[\[([^\s\/]+)(\s+(.+))??\]\]/"; # this is clean and working
Deletions:
* A "raw" handler must be available on the main Wikka server, in order to
* produce raw wikka-formatted content with header and footer stripped).
// fetch rawcontent of remote page
$forced = "/\[\[([^ \/]+)(\s+([^\]]+))?\]\]/"; #patched


Revision [2894]

Edited on 2004-12-06 18:53:42 by DarTar [FetchRemote action v.0.6 - download link + better pattern for forced links]
Additions:
//$forced = "/\[\[([^ \/]+) ([^\]]+)\]\]/"; #original
$forced = "/\[\[([^ \/]+)(\s+([^\]]+))?\]\]/"; #patched
Deletions:
$forced = "/\[\[([^ \/]+) ([^\]]+)\]\]/";


Revision [2888]

Edited on 2004-12-06 16:45:56 by DarTar [FetchRemote action v.0.6 - adding download link]
Additions:
<<**""FetchRemote"" v.0.6** available for testing
==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;
~-Remote fetching of pages through ##fopen()## must be allowed by php (by default it is).
Deletions:
<<**''FetchRemote'' v.0.6** available for testing
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 ##""{{fetchremote page="PageName"}}""## plugin allowing to retrieve content from the main wikka server, using something like the //raw// method.
==== The idea ====
Here's how it might function:
~1) the user of a wikka distribution opens a local **""WikkaDocumentation""** page containing ##""{{fetchremote page="HelpInfo"}}""##;
~1) the plugin connects to the main wikka server,
~1) it fetches a //raw// version of HelpInfo with no header and footer (i.e. the mere page content in wikka syntax),
~1) it parses the fetched page for internal links and translates them into //local links// to fetchable pages (links pointing to remote URLs need not be translated),
~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:==
~-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.
==Screenshot:==
http://wikka.jsnx.com/images/fetchremote.jpg
Now, here comes some code.
====""FetchRemote"": a plugin for fetching remote documentation ====
==Note==
Remote fetching of pages through ##fopen()## must be allowed by php (by default it is).


Revision [2887]

Edited on 2004-12-06 16:35:05 by DarTar [FetchRemote action v.0.6 - adding download link]
Additions:
<<**''FetchRemote'' v.0.6** available for testing
Download the [[http://wikka.openformats.org/fetchremote.phps source]] and save it as:
##actions/fetchremote.php##
''Feedback is welcome!''
<<::c::


Revision [2886]

Edited on 2004-12-06 16:02:18 by DarTar ["raw" handler created - removing useless server-side infos]
Additions:
~-Connects to the main Wikka server and fetches Wikka Documentation Pages. --- A "raw" handler must be available on the main Wikka server, in order to produce raw wikka-formatted content with header and footer stripped.
==The code (##actions/fetchremote.php##) ==
* A "raw" handler must be available on the main Wikka server, in order to
$remote_page = fopen($remote_server_root.$page."/raw", "r");
Deletions:
~-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.
Here's a three-step installation:
==1. Create on the target server a ##rawcontent## handler (##handlers/page/rawcontent.php##)==
if ($this->HasAccess("read")) {
if (!$this->page) {
return;
// display raw page
print($this->page["body"]);
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##) ==
* A "rawcontent" method must be available on the main Wikka server, in order to
//$remote_server_root = "http://test/wikka-1.1.5.0/wikka.php?wakka="; # debug server
$remote_page = fopen($remote_server_root.$page."/rawcontent", "r");


Revision [2881]

Edited on 2004-12-06 08:49:05 by DarTar [FetchRemote action v.0.6 - link rewriting engine working!]
Additions:
~-Parses the fetched page and rewrites internal links as links to fetchable pages.
Deletions:
~-Parses the fetched page and rewrites links as links to fetchable pages.
~-Bug: prevent ""WikiWords"" in the context of a forced link from being parsed:
~~ e.g. ""WikkaWiki"" in: ""[[HomePage Go to the starting page of this WikkaWiki]]""


Revision [2880]

Edited on 2004-12-06 08:46:24 by DarTar [FetchRemote action v.0.6 - link rewriting engine working!]
Additions:
$remote_server_root = "http://wikka.jsnx.com/"; # set remote server root
//$remote_server_root = "http://test/wikka-1.1.5.0/wikka.php?wakka="; # debug server
Deletions:
//$remote_server_root = "http://wikka.jsnx.com/"; # set remote server root
$remote_server_root = "http://test/wikka-1.1.5.0/wikka.php?wakka=";
/*
//JW's defaults
*/
// read pagename from a $_REQUEST first, or from a $page action parameter if specified
$page = $_REQUEST["page"]? $_REQUEST["page"] : $page;
// set default pagename if pagename is still empty
if ($page == "") $page = "HelpInfo";


Revision [2879]

Edited on 2004-12-06 08:33:29 by DarTar [FetchRemote action v.0.6 - link rewriting engine working]
Additions:
Version 0.6
~-Bug: prevent ""WikiWords"" in the context of a forced link from being parsed:
* @version 0.6
//$remote_server_root = "http://wikka.jsnx.com/"; # set remote server root
$remote_server_root = "http://test/wikka-1.1.5.0/wikka.php?wakka=";
/*
//JW's defaults
*/
// read pagename from a $_REQUEST first, or from a $page action parameter if specified
$page = $_REQUEST["page"]? $_REQUEST["page"] : $page;
// set default pagename if pagename is still empty
if ($page == "") $page = "HelpInfo";
//$forced = "/\[\[(\S*)(\s+(.+))?\]\]/"; #JW's suggestion
$camel = "/[^a-z=>\|\"\[\/\{]([A-Z]+[a-z]+[A-Z][A-Za-z0-9]+)+/";
//$content = preg_replace($forced, '""<a href="'.$this->Href('','',"page=\\1").'">'."\\2".'</a>""', $content);
// build callback function for marking CamelCase words within forced links
function MarkCamel($fmatches) {
global $wakka;
$camel = "/([A-Z]+[a-z]+[A-Z][A-Za-z0-9]+)+/";
$markedcamel = preg_replace($camel, "|||\\1|||", $fmatches[2]);
// 1) This is working
$output = '""<a href="'.$fmatches[1].'">'.$markedcamel.'</a>""';
// 2) This is NOT working
// How do I call a global function from within a callback function?
$output = '""<a href="'.$wakka->Href('','',"page=".$fmatches[1]).'">'.$markedcamel.'</a>""';
return $output;
$content = preg_replace_callback($forced, 'MarkCamel', $content);
$content = preg_replace($camel, ' ""<a href="'.$this->Href('','',"page=\\1").'">'."\\1".'</a>""', $content);
//strip "|||" markers from content
$content = str_replace("|||", "", $content);
Deletions:
Version 0.5
~-Bug: prevent ""WikiWords"" in the context of a forced link from being parsed (see LinkRewriting):
* @version 0.5
* -Bug: prevent WikiWords in the context of a forced link from being parsed:
* e.g. WikkaWiki in: [[HomePage Go to the starting page of this WikkaWiki]].
$remote_server_root = "http://wikka.jsnx.com/"; # set remote server root
$camel = "/[^a-z=>\"\[\/\{]([A-Z]+[a-z]+[A-Z][A-Za-z0-9]+)+/";
$content = preg_replace($forced, "\"\"<a href='".$this->Href("","","page=\\1")."'>\\2</a>\"\"", $content);
$content = preg_replace($camel, "\"\" <a href='".$this->Href("","","page=\\1")."'>\\1</a>\"\"", $content);


Revision [2757]

Edited on 2004-12-02 11:15:21 by DarTar [Fixing defaults: thanks JW]
Additions:
~-Bug: prevent ""WikiWords"" in the context of a forced link from being parsed (see LinkRewriting):
Deletions:
~-Bug: prevent ""WikiWords"" in the context of a forced link from being parsed:


Revision [2744]

Edited on 2004-12-02 10:03:32 by DarTar [Fixing defaults: thanks JW]
Additions:
* Connects to a specified Wikka server, fetches a remote page and formats it for local use.
* @package Actions
* @name FetchRemote
* @author {@link http://wikka.jsnx.com/DarTar DarTar}
* @version 0.5
* @since Wikka 1.1.X
* @input string  $page  optional: Starting page on the main Wikka server;
* default: HelpInfo
* @output prints fetched documentation pages
* @todo -Forced link rewriting: check regex for consistency with wikka formatters.
*/
Deletions:
 * Connects to a specified Wikka server, fetches a remote page and formats it for local use.
 *
 * @package Actions
 * @name FetchRemote
 *
 * @author {@link http://wikka.jsnx.com/DarTar DarTar}
 * @version 0.5
 * @since Wikka 1.1.X
 *
 * @input string  $page  optional: Starting page on the main Wikka server;
 * default: HelpInfo
 * @output prints fetched documentation pages
 *
 * @todo -Forced link rewriting: check regex for consistency with wikka formatters.
 */


Revision [2743]

Edited on 2004-12-02 10:00:12 by DarTar [Fixing defaults: thanks JW]
Additions:
$remote_server_root = "http://wikka.jsnx.com/"; # set remote server root
$defaultpage = 'HelpInfo'; # define default page to be fetched
if (isset($_REQUEST["page"])) $defaultpage = $_REQUEST["page"]; # pick up URL parameter
if (isset($page)) $defaultpage = $page; # pick up action parameter
$page = $defaultpage; # ready to roll
Deletions:
// set remote Wikka server root
$remote_server_root = "http://wikka.jsnx.com/";
// read pagename from a $_REQUEST first, or from a $page action parameter if specified
$page = $_REQUEST["page"]? $_REQUEST["page"] : $page;
// set default pagename if pagename is still empty
if ($page == "") $page = "HelpInfo";


Revision [2727]

Edited on 2004-12-01 20:26:26 by DarTar [Some minor mods and phpdoc header fixed]
Additions:
~-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.
~-Displays an error message if remote pages do not exist on the server or if a connection is not available.
~-Parses the fetched page and rewrites links as links to fetchable pages.
~-Prints the fetched page locally, together with a header.
~-Allows fetched pages to be safely stored on the Wikka client.
~-If a page with the same name already exists on the Wikka client, a "see local version" button instead of the "download" button is displayed.
~-Forced link rewriting: '' done'' - check regex for consistency with wikka formatters.
~-CamelCase link rewriting: ''done'' - check regex for consistency with wikka formatters.
* are rewritten as links to fetchable pages, and printed on the screen.
* Fetched pages can then be safely stored on the Wikka client. If a local version
* of a fetched page is available, a "see local version" button replaces the default
* "download" button.
// read pagename from a $_REQUEST first, or from a $page action parameter if specified
// set default pagename if pagename is still empty
Deletions:
~-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
~-Displays an error message if remote pages do not exist on the server or if a connection is not available
~-Parses the fetched page and rewrites links as links to fetchable pages
~-Prints the fetched page locally, together with a header
~-Allows fetched pages to be safely stored on the Wikka client
~-If a page with the same name exists on the Wikka client, show a "see local version" button instead of the "download" button
~-Forced link rewriting: '' done'' - check regex for consistency with wikka formatters
~-CamelCase link rewriting: ''done'' - check regex for consistency with wikka formatters
* are rewritten as links to fetchable pages.
* Fetched pages can then be safely stored on the Wikka client. When a local version
* of a fetched are available, the download button is masked.
// read pagename from a $_REQUEST first, or from a $page action parameter
// set default pagename if no pagename is specified


Revision [2726]

Edited on 2004-12-01 20:02:33 by DarTar [Some minor mods and phpdoc header fixed]
Additions:
 * Connects to a specified Wikka server, fetches a remote page and formats it for local use.
* This action allows the user to locally browse in a Wikka client content fetched from a
* remote Wikka server. It displays an error message if the remote page does not exist
* on the server or if a connection is not available.
* Once a connection is established, the fetched page is parsed for internal links, which
* are rewritten as links to fetchable pages.
* Fetched pages can then be safely stored on the Wikka client. When a local version
* of a fetched are available, the download button is masked.
 * @package Actions
 * @name FetchRemote
 * @author {@link http://wikka.jsnx.com/DarTar DarTar}
 * @version 0.5
 * @since Wikka 1.1.X
 * @input string  $page  optional: Starting page on the main Wikka server;
 * default: HelpInfo
* can be overridden by a $_REQUEST["page"] parameter.
 * @output prints fetched documentation pages
 * @todo -Forced link rewriting: check regex for consistency with wikka formatters.
* -CamelCase link rewriting: check regex for consistency with wikka formatters.
* -Bug: prevent WikiWords in the context of a forced link from being parsed:
* e.g. WikkaWiki in: [[HomePage Go to the starting page of this WikkaWiki]].
* -Interwiki link rewriting.
// set remote Wikka server root
$remote_server_root = "http://wikka.jsnx.com/";
// read pagename from a $_REQUEST first, or from a $page action parameter
// set default pagename if no pagename is specified
// redirect to main documentation page
// redirect to Wikka homepage on disconnection
// NOTE: the use of this feature is discouraged since it traps users 'locally'
// to be replaced by a CSS selector in the definitive version
// build form chunks
// TRY TO CONNECT
// missing or empty page: show error message
Deletions:
 * Connects to the main Wikka server and fetches Wikka Documentation Pages
* Displays an error message if remote pages do not exist on the server
* Displays an error message if a connection is not available
* If a connection is established, parses the fetched page and rewrites links
* Finally, Prints the fetched page locally, together with a header
* This action allows fetched pages to be safely stored on the Wikka client
 * When local versions are available, the download button is masked
 * @package Actions
 * @name FetchRemote
 * @author {@link http://wikka.jsnx.com/DarTar DarTar}
 * @version 0.5
 * @since Wikka 1.1.6.X
 * @input string  $page  optional: Starting page on the main Wikka server;
 * default: HelpInfo
 * @output prints fetched documentation pages
 * @todo -Forced link rewriting: check regex for consistency with wikka formatters
* -CamelCase link rewriting: check regex for consistency with wikka formatters
* -Bug: prevent WikiWords in the context of a forced link from being parsed:
* e.g. WikkaWiki in: [[HomePage Go to the starting page of this WikkaWiki]]
* -Interwiki link rewriting
// Set remote Wikka server root
//$remote_server_root = "http://wikka.jsnx.com/";
// Debugging server
$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
// redirect to main Documentation page
// redirect to home on disconnection
// NOTE: the use of this feature is discouraged since it traps the users 'locally'
// form chunks
// TRY CONNECTION
// missing page: show error message


Revision [2719]

Edited on 2004-12-01 15:05:07 by DarTar [FetchRemote action v.0.5 - more compact code and tentative phpdoc header :)]
Deletions:
// 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>\"\"";
//$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);
}
*/


Revision [2718]

Edited on 2004-12-01 14:57:10 by DarTar [FetchRemote action v.0.5 - more compact code and tentative phpdoc header :)]
Additions:
Version 0.5
~-Bug: prevent ""WikiWords"" in the context of a forced link from being parsed:
~~ e.g. ""WikkaWiki"" in: ""[[HomePage Go to the starting page of this WikkaWiki]]""
/**
 * Connects to the main Wikka server and fetches Wikka Documentation Pages
*
* Displays an error message if remote pages do not exist on the server
* Displays an error message if a connection is not available
* If a connection is established, parses the fetched page and rewrites links
* Finally, Prints the fetched page locally, together with a header
*
* This action allows fetched pages to be safely stored on the Wikka client
 * When local versions are available, the download button is masked
*
* A "rawcontent" method must be available on the main Wikka server, in order to
* produce raw wikka-formatted content with header and footer stripped).
 *
 * @package Actions
 * @name FetchRemote
 *
 * @author {@link http://wikka.jsnx.com/DarTar DarTar}
 * @version 0.5
 * @since Wikka 1.1.6.X
 *
 * @input string  $page  optional: Starting page on the main Wikka server;
 * default: HelpInfo
 * @output prints fetched documentation pages
 *
 * @todo -Forced link rewriting: check regex for consistency with wikka formatters
* -CamelCase link rewriting: check regex for consistency with wikka formatters
* -Bug: prevent WikiWords in the context of a forced link from being parsed:
* e.g. WikkaWiki in: [[HomePage Go to the starting page of this WikkaWiki]]
* -Interwiki link rewriting
 */
// SET DEFAULTS
// Debugging server
$remote_server_root="http://test/wikka-1.1.5.0/wikka.php?wakka=";
// PERFORM REDIRECTIONS
// redirect to main Documentation page
if ($_POST["action"] == "Return to Wikka Documentation") $this->Redirect($this->GetPageTag());
// switch to local version of the page
if ($_POST["action"] == "See local version") $this->Redirect($page);
// automatically redirect to local page if it exists
// NOTE: the use of this feature is discouraged since it traps the users 'locally'
// and prevents them from accessing recently updated versions of the Wikka documentation
//if ($this->LoadPage($page)) $this->Redirect($page);
// SET HEADER & FORM ELEMENTS
// header style
$style = "text-align: center; margin: 30px 25%; border: 1px dotted #333; background-color: #EEE; padding: 5px;";
// form chunks
$form_local = "<input type='submit' name='action' value='See local version' />";
$form_main = "<input type='submit' name='action' value='Return to Wikka Documentation' />";
$form_disconnect = "<input type='submit' name='action' value='Disconnect' />";
$form_page = "<input type='hidden' name='page' value='".$page."' />";
$form_download = "<input type='submit' name='action' value='Download this page' />";
// TRY CONNECTION
// NO CONNECTION AVAILABLE
// if a local version of the starting page is available:
if ($this->LoadPage($page)) print $this->FormOpen().$form_local.$this->FormClose();
// CONNECTION ESTABLISHED
$header .= "** cannot be found on the [[".$remote_server_root.$page." Wikka server]]! --- --- ";
$form = $this->FormOpen().$form_page;
$form .= ($this->LoadPage($page))? $form_local : "";
$form .= $form_main.$this->FormClose();
// START LINK-REWRITING ENGINE
// regex pattern for forced links to *internal pages* on remote server
// regex pattern for CamelCase links to *internal pages* on remote server
// SAVING FETCHED PAGE
// in the future we might show a form to ask if the local version should be overwritten
$header = "Sorry, a page named **[[".$page."]]** already exists on this site! --- ";
$form = $this->FormOpen().$form_main.$form_disconnect.$this->FormClose();
$header = "This page is now available on your site! --- --- ";
$form = $this->FormOpen().$form_page.$form_local.$form_main.$this->FormClose();
// display default header & form
$header .= "** --- from the **[[".$this->GetPageTag()." Wikka Documentation Project]]** --- ";
$header .= "(fetched from the [[".$remote_server_root.$page." Wikka server]])";
$form = $this->FormOpen().$form_page;
$form .= ($this->LoadPage($page))? $form_local : $form_download;
$form .= $form_disconnect.$this->FormClose();
// PRINT HEADER AND CONTENT
// CLOSE CONNECTION
Deletions:
Version 0.4
// FetchRemote Action
// Written by DarTar <http://wikka.jsnx.com/DarTar>
// Version 0.4
//
// * 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).
// * Displays an error message if remote pages do not exist on the server or if a connection is not available
// * Parses the fetched page and rewrites links as links to fetchable pages
// * Prints the fetched page locally, together with a header
// * Allows fetched pages to be safely stored on the Wikka client
//
// Parameters: page - specifies starting page on the remote server
// debugging
$remote_server_root="http://test/wikka-1.1.5.0/wikka.php?wakka=";
// open connection
// connection failed: print static link
// connection established: start fetching remote page
// header style
$style = "text-align: center; margin: 30px 25%; border: 1px dotted #333; background-color: #EEE; padding: 5px;";
$header .= "** cannot be found on the [[".$remote_server_root.$page." Wikka server]]! --- Return to the **[[".$this->GetPageTag()." Wikka Documentation Project]]** --- ";
$form = "";
// regex pattern for forced links to internal pages
// regex pattern for CamelCase links
// trying to save page
// in the future we might show a form to ask if local version should be overwritten
$header = "@@Sorry, a page named **[[".$page."]]** already exists on this site!@@ --- ";
$form = $this->FormOpen()."<input type='submit' name='action' value='Return to Wikka Documentation' /><input type='submit' name='action' value='Disconnect' />".$this->FormClose();
$header = "@@This page is now available on your site!@@ --- ";
$form = $this->FormOpen()."<input type='hidden' name='page' value='".$page."' /><input type='submit' name='action' value='See local version' /><input type='submit' name='action' value='Return to Wikka Documentation' />".$this->FormClose();
} else if ($_POST["action"] == "See local version") {
// switch to local version of the page
$this->Redirect($page);
// main header & form
$header .= "** --- from the **[[".$this->GetPageTag()." Wikka Documentation Project]]** --- (fetched from the [[".$remote_server_root.$page." Wikka server]])";
$buttontext = ($this->LoadPage($page))? "See local version" : "Download this page";
$form = $this->FormOpen()."<input type='hidden' name='page' value='".$page."' /><input type='submit' name='action' value='".$buttontext."' /><input type='submit' name='action' value='Disconnect' />".$this->FormClose();
// last step: print header and rewritten content


Revision [2713]

Edited on 2004-12-01 12:46:21 by DarTar [FetchRemote action v.0.4]
Additions:
Version 0.4
~-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
~-If a page with the same name exists on the Wikka client, show a "see local version" button instead of the "download" button
// Version 0.4
//$remote_server_root = "http://wikka.jsnx.com/";
$remote_server_root="http://test/wikka-1.1.5.0/wikka.php?wakka=";
// header style
// regex pattern for forced links to internal pages
$forced = "/\[\[([^ \/]+) ([^\]]+)\]\]/";
// regex pattern for CamelCase links
$camel = "/[^a-z=>\"\[\/\{]([A-Z]+[a-z]+[A-Z][A-Za-z0-9]+)+/";

$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);
if ($_POST["action"] == "Download this page") {
// trying to save page
if ($this->LoadPage($page)) {
// local page with this name already exists => display error message
// in the future we might show a form to ask if local version should be overwritten
$header = "@@Sorry, a page named **[[".$page."]]** already exists on this site!@@ --- ";
$form = $this->FormOpen()."<input type='submit' name='action' value='Return to Wikka Documentation' /><input type='submit' name='action' value='Disconnect' />".$this->FormClose();
} else {
// local page does not exist => proceed
// write page to database and display message
$note = "fetched from the Wikka server";
$this->SavePage($page, $content, $note);
$header = "@@This page is now available on your site!@@ --- ";
$form = $this->FormOpen()."<input type='hidden' name='page' value='".$page."' /><input type='submit' name='action' value='See local version' /><input type='submit' name='action' value='Return to Wikka Documentation' />".$this->FormClose();
}
} else if ($_POST["action"] == "See local version") {
// switch to local version of the page
$this->Redirect($page);

// main header & form
$header = "You are currently browsing: **";
$header .= "\"\"<a href='".$this->Href("","","page=".$page)."'>".$page."</a>\"\"";
$header .= "** --- from the **[[".$this->GetPageTag()." Wikka Documentation Project]]** --- (fetched from the [[".$remote_server_root.$page." Wikka server]])";
$buttontext = ($this->LoadPage($page))? "See local version" : "Download this page";
$form = $this->FormOpen()."<input type='hidden' name='page' value='".$page."' /><input type='submit' name='action' value='".$buttontext."' /><input type='submit' name='action' value='Disconnect' />".$this->FormClose();
// last step: print header and rewritten content
Deletions:
Version 0.3
~-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.
// Version 0.3
$remote_server_root = "http://wikka.jsnx.com/";
// $remote_server_root="http://test/wikka-1.1.5.0/wikka.php?wakka=";
// build header
if ($_POST["action"] == "Download this page") {
if ($this->LoadPage($page)) {
// display error message: local page with the same name already exists
$header = "@@Sorry, a page named **[[".$page."]]** already exists on this site!@@ --- ";
// 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();
$header = "You are currently browsing: **";
$header .= "\"\"<a href='".$this->Href("","","page=".$page)."'>".$page."</a>\"\"";
$header .= "** --- from the **[[".$this->GetPageTag()." Wikka Documentation Project]]** --- (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();
// regex pattern for forced links to internal pages
$forced = "/\[\[([^ \/]+) ([^\]]+)\]\]/";
// regex pattern for CamelCase links
$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


Revision [2710]

Edited on 2004-12-01 08:14:52 by DarTar [FetchRemote action v.0.3]
Additions:
~1) the user of a wikka distribution opens a local **""WikkaDocumentation""** page containing ##""{{fetchremote page="HelpInfo"}}""##;
~1) it fetches a //raw// version of HelpInfo with no header and footer (i.e. the mere page content in wikka syntax),
~1) it parses the fetched page for internal links and translates them into //local links// to fetchable pages (links pointing to remote URLs need not be translated),
==Notes:==
~-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.
Version 0.3
~-Displays an error message if remote pages do not exist on the server or if a connection is not available
~-Forced link rewriting: '' done'' - check regex for consistency with wikka formatters
~-CamelCase link rewriting: ''done'' - check regex for consistency with wikka formatters
~-Interwiki link rewriting
// Version 0.3
// * 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).
// * Displays an error message if remote pages do not exist on the server or if a connection is not available
// * Parses the fetched page and rewrites links as links to fetchable pages
// * Prints the fetched page locally, together with a header
// * Allows fetched pages to be safely stored on the Wikka client
$remote_server_root = "http://wikka.jsnx.com/";
// debugging
// $remote_server_root="http://test/wikka-1.1.5.0/wikka.php?wakka=";
echo $this->Format("=====Wikka Documentation===== --- Visit the **[[http://wikka.jsnx.com/HelpInfo Wikka Documentation Project]]** --- --- ");
$header = "@@Sorry, a page named **[[".$page."]]** already exists on this site!@@ --- ";
$header .= "** --- from the **[[".$this->GetPageTag()." Wikka Documentation Project]]** --- (fetched from the [[".$remote_server_root.$page." Wikka server]])";
if (!$content) {
// missing page: show error message
$header = "Sorry, **";
$header .= "\"\"<a href='".$this->Href("","","page=".$page)."'>".$page."</a>\"\"";
$header .= "** cannot be found on the [[".$remote_server_root.$page." Wikka server]]! --- Return to the **[[".$this->GetPageTag()." Wikka Documentation Project]]** --- ";
$form = "";
// regex pattern for forced links to internal pages
$forced = "/\[\[([^ \/]+) ([^\]]+)\]\]/";
// regex pattern for CamelCase links
$content = preg_replace($camel, "\"\" <a href='".$this->Href("","","page=\\1")."'>\\1</a>\"\"", $content);
Deletions:
~1) the user of a wikka distribution opens a local **""WikkaDocumentation""** page containing ##""{{help page="HelpInfo"}}""##;
~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
__Notes:__
~-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.
Version 0.2
~-Forced link rewriting: '' done'' - regex should match actual wikka formatters
~-CamelCase link rewriting: ''done'' - regex should match actual wikka formatters
~-Check for local pages with the same name of remote pages
~-Prevent non-existing remote pages from being fetched
// 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
//$remote_server_root = "http://wikka.jsnx.com/";
$remote_server_root="http://test/wikka-1.1.5.0/wikka.php?wakka=";
echo $this->Format("=====Wikka Documentation===== --- Visit the **[[http://wikka.jsnx.com/HelpInfo Official Wikka Documentation Project]]**");
$header = "@@A page named **[[".$page."]]** already exists on this site!@@ --- ";
$header .= "** --- from the **[[".$this->GetPageTag()." Official Wikka Documentation]]** --- (fetched from the [[".$remote_server_root.$page." Wikka server]])";
$forced = "/\[\[([^ ]+) ([^\]]+)\]\]/";
$content = preg_replace($camel, "\"\"<a href='".$this->Href("","","page=\\1")."'>\\1</a>\"\"", $content);


Revision [2679]

Edited on 2004-11-30 17:59:34 by DarTar [FetchRemote action v.0.2]
Additions:
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 ##""{{fetchremote page="PageName"}}""## plugin allowing to retrieve content from the main wikka server, using something like the //raw// method.
==== The idea ====
if ($this->HasAccess("read")) {
if (!$this->page) {
return;
// display raw page
print($this->page["body"]);
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##) ==
Deletions:
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.


Revision [2668]

Edited on 2004-11-30 17:05:33 by DarTar [FetchRemote action v.0.2]
Additions:
Now, here comes some code.
====""FetchRemote"": a plugin for fetching remote documentation ====
Version 0.2
~-Parses the fetched page and rewrites links as links to fetchable pages
~-Allows fetched pages to be safely stored on the Wikka client
~-Forced link rewriting: '' done'' - regex should match actual wikka formatters
~-CamelCase link rewriting: ''done'' - regex should match actual wikka formatters
// Version 0.2
// Set remote Wikka server root
$remote_server_root="http://test/wikka-1.1.5.0/wikka.php?wakka=";
if ($page == "") $page = "HelpInfo";
// redirect to home on disconnection
if ($_POST["action"] == "Disconnect") $this->Redirect($this->GetConfigValue("root_page"));
echo $this->Format("=====Wikka Documentation===== --- Visit the **[[http://wikka.jsnx.com/HelpInfo Official Wikka Documentation Project]]**");
// display error message: local page with the same name already exists
$header = "@@A page named **[[".$page."]]** already exists on this site!@@ --- ";
$note = "fetched from the Wikka server";
$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]])";
$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);
$content = preg_replace($camel, "\"\"<a href='".$this->Href("","","page=\\1")."'>\\1</a>\"\"", $content);
// print rewritten content
// 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);
}
*/
Deletions:
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 ====
Version 0.1
~-Parses the fetched page and rewrites forced links as links to fetchable pages
~-Forced link rewriting: change regex to match actual wikka formatters
~-CamelCase link rewriting: to be added
~-Add a button to save the fetched page locally
if ($this->HasAccess("read")) {
if (!$this->page) {
return;
// display raw page
print($this->page["body"]);
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##) ==
// Version 0.1
// Wikka Server root
if ($page == "") {$page = "HelpInfo";}
if ($_POST["action"] == "Disconnect") { $this->Redirect($this->GetConfigValue("root_page")); }
echo $this->Format("=====Wikka Documentation===== --- Click [[http://wikka.jsnx.com/HelpInfo here]] to visit the **Official Wikka Documentation**");
// display error message: page already exists
// eventually display dialog for overwriting local page.
$header = "@@A page named **[[".$page."]]** already exists in your site!@@ --- ";
$header = "@@You are currently browsing the --- **[[".$this->GetPageTag()." Official Wikka Documentation]]** --- (fetched from the main [[http://wikka.jsnx.com/ Wikka server]])@@";
$camel = "/^([A-Z]+[a-z]+[A-Z][A-Z,a-z,0-9]+)$/s";
$content = ereg_replace($camel, "\"\"<a href='".$this->Href("","","page=\\0")."'>\\0</a>\"\"", $content);

// 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 content


Revision [2665]

Edited on 2004-11-30 10:55:43 by DarTar [Code changed]
Additions:
//$remote_server_root = "http://wikka.jsnx.com/";
//set default remote page if no page parameter or GET value is specified
$page = $_REQUEST["page"]? $_REQUEST["page"] : $page;
if ($_POST["action"] == "Disconnect") { $this->Redirect($this->GetConfigValue("root_page")); }
echo $this->Format("=====Wikka Documentation===== --- Click [[http://wikka.jsnx.com/HelpInfo here]] to visit the **Official Wikka Documentation**");
$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: page already exists
// eventually display dialog for overwriting local page.
$header = "@@A page named **[[".$page."]]** already exists in your site!@@ --- ";
} else {
// write page to database and display message
$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();
$header = "@@You are currently browsing the --- **[[".$this->GetPageTag()." Official Wikka Documentation]]** --- (fetched from the main [[http://wikka.jsnx.com/ 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);
// rewrite camelcase links
$camel = "/^([A-Z]+[a-z]+[A-Z][A-Z,a-z,0-9]+)$/s";
$content = ereg_replace($camel, "\"\"<a href='".$this->Href("","","page=\\0")."'>\\0</a>\"\"", $content);

// print content
print "<div style='".$style."'>".$this->Format($header).$form."</div>".$this->Format($content);
Deletions:
$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;
echo $this->Format("View the **[[http://wikka.jsnx.com/HelpInfo Official Wikka Documentation]]**");
$header = "---- @@You are currently browsing the **[[".$this->GetPageTag()." Official Wikka Documentation]]** --- (fetched from the main [[http://wikka.jsnx.com/ Wikka server]]) --- [[".$this->GetConfigValue("root_page")." close the connection]]@@ ---- --- ";
// fetch rawcontent of the page
while (!feof ($remote_page)) {
$content .= fgets ($remote_page, 1024);

print $this->Format($header.$content);


Revision [2627]

Edited on 2004-11-29 14:00:41 by DarTar [Adding screenshot]
Additions:
==Screenshot:==
http://wikka.jsnx.com/images/fetchremote.jpg
Deletions:
<<[[http://skins.openformats.org/images/fetchremote.jpg Screenshot]]<<


Revision [2580]

Edited on 2004-11-28 16:21:36 by JavaWoman [squashed another "click here"]
Additions:
$header = "---- @@You are currently browsing the **[[".$this->GetPageTag()." Official Wikka Documentation]]** --- (fetched from the main [[http://wikka.jsnx.com/ Wikka server]]) --- [[".$this->GetConfigValue("root_page")." close the connection]]@@ ---- --- ";
Deletions:
$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@@ ---- --- ";


Revision [2579]

Edited on 2004-11-28 16:18:33 by JavaWoman [action code: got rid of "click here" in favor of semantic link]
Additions:
echo $this->Format("View the **[[http://wikka.jsnx.com/HelpInfo Official Wikka Documentation]]**");
Deletions:
echo $this->Format("Click [[http://wikka.jsnx.com/HelpInfo here]] to visit the **Official Wikka Documentation**");


Revision [2571]

Edited on 2004-11-28 11:17:53 by DarTar [Adding screenshot]
Additions:
<<[[http://skins.openformats.org/images/fetchremote.jpg Screenshot]]<<
==1. Create on the target server a ##rawcontent## handler (##handlers/page/rawcontent.php##)==
== 2. Update ##wikka.php## on the target server==
== 3. Create in the Wikka client a ""FetchRemote"" action (##actions/fetchremote.php##) ==
Deletions:
==1. Create a ##rawcontent## handler (##handlers/page/rawcontent.php##)==
== 2. Update ##wikka.php## ==
== 3. Create the ""FetchRemote"" action (##actions/fetchremote.php##) ==


Revision [2569]

Edited on 2004-11-28 09:58:50 by DarTar [Code slightly improved]
Additions:
~-Basically, the idea is to make the main Wikka site work as a //server// providing wikka-formatted content to //Wikka-clients//. There are several advantages in this approach, compared to merely fetching HTML:
~~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.
~-CamelCase link rewriting: to be added
~-Add a button to save the fetched page locally
// 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@@ ---- --- ";
// 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);
Deletions:
~-CamelCase link rewriting
// 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@@ ---- --- ";
// 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);


Revision [2563]

Edited on 2004-11-27 19:11:04 by DarTar [Here comes some code...]
Additions:
$content = ereg_replace("\[\[([A-Za-z]+) ([A-Za-z \"]+)\]\]", "\"\"<a href='".$this->page."?page=\\1'>\\2</a>\"\"", $content);
Deletions:
$content = ereg_replace("\[\[([A-Za-z]+) ([A-Za-z \"]+)\]\]", "\"\"<a href='".$this->GetPageTag()."?page=\\1'>\\2</a>\"\"", $content);


Revision [2561]

Edited on 2004-11-27 19:07:25 by DarTar [Here comes some code...]
Additions:
if ($page == "") {$page = "HelpInfo";}
Deletions:
if ($page == "") {$page = "WikkaAdmin";}


Revision [2558]

Edited on 2004-11-27 19:02:29 by DarTar [Here comes some code...]
Additions:
// A "rawcontent" method must be available on the main Wikka server
// fetch rawcontent of the page
Deletions:
// A "rawbody" method must be available on the main Wikka server
// fetch rawbody of the page


Revision [2557]

Edited on 2004-11-27 18:58:06 by DarTar [Here comes some code...]
Additions:
===== Fetching Remote Wikka Content =====
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)
<?php
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**
%%(php)
if (preg_match('/\.(xml|mm)$/', $this->method)) {
header("Content-type: text/xml");
print($this->Method($this->method));
}
%%
**modified**
%%(php)
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**
%%(php)
// 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**
%%(php)
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 the ""FetchRemote"" action (##actions/fetchremote.php##) ==
%%(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 "rawbody" 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 = "WikkaAdmin";}
// 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 rawbody 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->GetPageTag()."?page=\\1'>\\2</a>\"\"", $content);

print $this->Format($header.$content);
}
fclose($remote_page);
?>
%%
Deletions:
===== Including Remote Wikka Content =====


Revision [2537]

Edited on 2004-11-27 14:15:02 by DarTar [Replying to Jsnx and adding notes]
Additions:
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
Deletions:
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]]""## -- DarTar


Revision [2536]

Edited on 2004-11-27 14:09:04 by DarTar [Replying to Jsnx and adding notes]
Additions:
~-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.
Deletions:
~-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.


Revision [2535]

Edited on 2004-11-27 14:08:43 by DarTar [Replying to Jsnx and adding notes]
Additions:
~-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.
Deletions:
~-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.


Revision [2534]

Edited on 2004-11-27 14:08:24 by DarTar [Replying to Jsnx and adding notes]
Additions:
~-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.
Deletions:
~-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 (*)]]""##


Revision [2533]

Edited on 2004-11-27 14:06:19 by DarTar [Replying to Jsnx and adding notes]
Additions:
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]]""## -- DarTar
Deletions:
The link might be translated as a local link to the //same page// with a GET parameter read by the plugin, for instance: ##""[[ACLInfo Access Control documentation]]""## will be translated into something like: ##<a href="""WikkaDocumentation""?page=ACLInfo">Access Control Documentation</a>##. Alternatively, we might restrict local navigation of remote pages to "one" page and show links to other remote pages as masked //interwikilinks//: ##""[[Wikka:ACLInfo Access Control Documentation]]""## -- DarTar


Revision [2532]

Edited on 2004-11-27 14:04:50 by DarTar [Replying to Jsnx and adding notes]
Additions:
The link might be translated as a local link to the //same page// with a GET parameter read by the plugin, for instance: ##""[[ACLInfo Access Control documentation]]""## will be translated into something like: ##<a href="""WikkaDocumentation""?page=ACLInfo">Access Control Documentation</a>##. Alternatively, we might restrict local navigation of remote pages to "one" page and show links to other remote pages as masked //interwikilinks//: ##""[[Wikka:ACLInfo Access Control Documentation]]""## -- DarTar
Deletions:
The link might be translated as a local link to the //same page// with a GET parameter read by the plugin, for instance: ##""[[ACLInfo Access Control documentation]]""## will be translated into something like: ##<a href="""WikkaDocumentation""?page=ACLInfo">Access Control Documentation</a>##. -- DarTar


Revision [2531]

Edited on 2004-11-27 13:58:11 by DarTar [Replying to Jsnx and adding notes]
Additions:
~-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 (*)]]""##
Deletions:
~-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!


Revision [2530]

Edited on 2004-11-27 13:51:33 by DarTar [Replying to Jsnx]
Additions:
~-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!
Deletions:
~-that 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!


Revision [2529]

Edited on 2004-11-27 13:51:11 by DarTar [Replying to Jsnx]
Additions:
__Notes:__
~-that 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!
Deletions:
Note that 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.


Revision [2528]

Edited on 2004-11-27 13:45:45 by DarTar [Replying to Jsnx (fixed)]
Additions:
The link might be translated as a local link to the //same page// with a GET parameter read by the plugin, for instance: ##""[[ACLInfo Access Control documentation]]""## will be translated into something like: ##<a href="""WikkaDocumentation""?page=ACLInfo">Access Control Documentation</a>##. -- DarTar
Deletions:
Actually, it's quite simple: if the remote page contains a link to ##""[[ACLInfo Access Control documentation]]""## it will be rendered locally as ##""[[Wikka:ACLInfo Acces Control documentation]]""## -- DarTar;


Revision [2527]

Edited on 2004-11-27 13:38:41 by DarTar [Replying to Jsnx]
Additions:
Actually, it's quite simple: if the remote page contains a link to ##""[[ACLInfo Access Control documentation]]""## it will be rendered locally as ##""[[Wikka:ACLInfo Acces Control documentation]]""## -- DarTar;


Revision [2526]

Edited on 2004-11-27 13:36:24 by JsnX [intriguing idea]
Additions:
~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
Deletions:
~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


Revision [2525]

Edited on 2004-11-27 13:35:44 by JsnX [intriguing idea]
Additions:
~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
~1) and finally, it prints //locally// the documentation contents.
Deletions:
~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), and finally
~1) it prints //locally// the documentation contents.


Revision [2522]

Edited on 2004-11-27 13:15:45 by DarTar [An alternative approach for distributing documentation]
Additions:
~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), and finally
~1) it prints //locally// the documentation contents.
Deletions:
~1) parses the page for internal links and translates them into //local links// for retrieving remote content (links to remore URLs need not be replaced), and finally
~1) prints //locally// the documentation contents.


Revision [2521]

The oldest known version of this page was created on 2004-11-27 13:14:18 by DarTar [An alternative approach for distributing documentation]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki