Due to the nature of the web.* functions, this can only be used if the remote wiki allows Anonymous content retrieval.
Use this code on a page of your own wiki ---
{{
web.xml("http://wiki.developer.mindtouch.com/@api/deki/pages/="..uri.encode(uri.encode("Sandbox/Remote_API_Test")).."/contents?mode=view&format=xhtml&testparam=parameter",
"/content/body")
}}
Test ability to use __request.args remotely.
{ include : "contents" }
This is my test !
Symbols like > < & (anything HTML encoded) seem to have an issue when using web.html().

This image probably doesn't show up remotely in your wiki, due to the src path getting interpreted as a local @api call.

Insert an image and change the src from relative/local @api to an external address.
<img src="http://i198.photobucket.com/albums/aa299/yupko/fMAIucxfrI.jpg" alt="lolcatz" class="external default" />
Treat the page as text, then use string.replace() to change localized wiki-links or other text if need be. With earlier web.xml() remote transclusion, local links will still have the source wiki as the server. Do the following DekiScript to change it... and Link Test should now reference your wiki.
{{
web.xml(string.replace(web.text("http://wiki.developer.mindtouch.com/@api/deki/pages/="..uri.encode(uri.encode("Sandbox/Remote_API_Test")).."/contents?mode=view&format=xhtml&testparam=parameter"), "http://wiki.developer.mindtouch.com", "http://yourserver"), "/content/body")
}}
Accomplish the same thing with images or other files. Try this to fix the image inserted above...
{{
web.xml(string.replace(web.text("http://wiki.developer.mindtouch.com/@api/deki/pages/="..uri.encode(uri.encode("Sandbox/Remote_API_Test")).."/contents?mode=view&format=xhtml&testparam=parameter"), "src=\"/@api", "src=\"http://wiki.developer.mindtouch.com/@api"), "/content/body")
}}
Probably don't want the local wiki treating a page that is from another wiki as if it were local/editable...
{{
web.xml(string.replace(web.text("http://wiki.developer.mindtouch.com/@api/deki/pages/="..uri.encode(uri.encode("Sandbox/Remote_API_Test")).."/contents?mode=view&format=xhtml&testparam=parameter"), "class=\"editable\"", ""), "/content/body")
}}
Roll everything together. Create an array of the text rewrites to be processed and then run through with a foreach loop. Careful on the rewrite order; things like the image src path could get ruined by doing it in the wrong order. This fancy example places them in a <div block> statement to do all the calculations... nice and easy to turn into a parameterized template too.
<div block="var string_replacements = [ [ 'http://wiki.developer.mindtouch.com', 'http://yourserver'], [ 'src="/@api', 'src="http://wiki.developer.mindtouch.com/@api'], [ 'class="editable"', '']];
var page_text = web.text('http://wiki.developer.mindtouch.com/@api/deki/pages/='..uri.encode(uri.encode('Sandbox/Remote_API_Test'))..'/contents?mode=view&format=xhtml&testparam=parameter');
foreach ( var rep_pair in string_replacements ) { let page_text = string.replace(page_text,rep_pair[0],rep_pair[1]); }" class="remote_wiki_trans">
{{ web.xml(page_text, "/content/body") }}
</div>
Create a parameterized template based on earlier <div>.
| Name | Type | Description |
| server | str | Exact address of the source server. Example: { server: "http://wiki.developer.mindtouch.com/" } |
| p_path | str | Path to the wiki page. Example: { p_path: "Sandbox/Remote_API_Test" } |
| p_format | str | (optional, default: "xhtml") Format request from remote wiki: "xhtml", "html". Example: { p_format: "html" } |
| p_mode | str | (optional, default: "view") The mode that the remote wiki will return the content in: "view", "viewnoexecute", "raw", "edit". Example: { p_mode: "viewnoexecute" } |
| p_section | num | (optional, default: nil) Use to request only a single section of a page. Example: { p_section: 3 } |
| p_parameters | list | (optional, default: nil) A list of mapped values (name and value) used to pass additional parameters to the remote wiki when it is preparing the content. The parameter name is expected to be URI safe, but the value will get URI encoded before being passed to the remote wiki. Example: { p_parameters: [ {name: "testparam", value: "testvalue"}, {name: "testuri", value: "URI encoded #@!$%^ values"} ] } |
| p_rewrites | list | (optional, default: nil) A list of mapped values (old and new) used to rewrite the contents of the page retrieved from the remote wiki. This can be used to fix things such as links or style/class assignments. Example: { p_rewrites: [ { old: "src=\"/@api", new: "src=\"http://wiki.developer.mindtouch.com/@api" } ] } |
| ref | bool | (optional, default: true) Template will display a reference link to the source page unless explicitly told not to. |
<h1>Template:RemoteWikiPage</h1>
<div block="var page_text = '';
var source_ok = false;
let page_text ..= args.server ? '' : '<p>RemoteWikiPage: server value required.</p>';
let page_text ..= args.p_path ? '' : '<p>RemoteWikiPage: p_path value required.</p>';
if ( page_text == '' ) {
let source_ok = true;
var append_params = args.p_mode ? 'mode='..args.p_mode : 'mode=view';
let append_params ..= args.p_format ? '&format='..args.p_format : '&format=xhtml';
let append_params ..= args.p_section ? '&section='..args.p_section : '';
if ( args.p_parameters != nil ) {
foreach (var param in args.p_parameters) {
let append_params ..= '&'..param.name..'='..uri.encode(param.value);
}}
let page_text = web.text(args.server..'/@api/deki/pages/='..uri.encode(uri.encode(args.p_path))..'/contents?'..append_params);
if (args.p_rewrites != nil) {
foreach (var rewrite in args.p_rewrites) {
let page_text = string.replace(page_text,rewrite.old,rewrite.new);
}}}" class="remote_wiki_trans">{{ source_ok ? web.xml(page_text, "/content/body") : web.html(page_text); if (args.ref === nil || args.ref === true) { web.html('<p><span style="font-size: smaller; color: #999;">Content retreived from <a href="'..args.server..args.p_path..'">'..args.server..args.p_path..'</a></span></p>') } }}</div>
Test the template:
{{ template.RemoteWikiPage{ p_path: "User:Anbrcyp/Remote_Wiki_Transclusion/Remote_Template_Test", server: "http://wiki.developer.mindtouch.com/", p_parameters: [ {name: "testuri", value: "URI encoded $%^&#@ values"}, { name: "testdoubleuri", value: "URI double-encoded"..uri.encode("$%^&#@").." values"} ] } }}
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |
Copyright © 2011 MindTouch, Inc. Powered by