Revision [16727]
This is an old revision of IncludeRemote made by Io1Wnj on 2007-05-31 10:42:19.
Fetching Remote Wikka Content
FetchRemote v.0.6 available for testing
Download the source and save it as:
actions/fetchremote.php
Feedback is welcome!
See also:
Download the source and save it as:
actions/fetchremote.php
Feedback is welcome!
See also:
FetchRemote Action
Version 0.7Note:
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:
- the fetched content integrates seamlessly with the layout and structure of the Wikka-client;
- 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
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 withdefine('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', 'Unknown action; the action name must not contain special characters.'); # 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:]\/@:\.,_\?
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', 'Unknown action; the action name must not contain special characters.'); # 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:]\/@:\.,_\?