Remote Wiki Transclusion

    Due to the nature of the web.* functions, this can only be used if the remote wiki allows Anonymous content retrieval.

    External Wiki Page Transclusion

    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")
    }}

     

    Pass Arguments And Use Them

    Test ability to use __request.args remotely.

    { include : "contents" }

    This is my test !

     

    Why Not Web.HTML()?

    Symbols like > < & (anything HTML encoded) seem to have an issue when using web.html().

     

    What's With Pictures?

    Crystal_Clear_app_advancedsettings.png

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

    lolcatz

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

     

    Modifying Source-Wiki Internal Links or Other Text

    Link Test

    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=&quot;/@api', 'src=&quot;http://wiki.developer.mindtouch.com/@api'], [ 'class=&quot;editable&quot;', '']];
    var page_text = web.text('http://wiki.developer.mindtouch.com/@api/deki/pages/='..uri.encode(uri.encode('Sandbox/Remote_API_Test'))..'/contents?mode=view&amp;format=xhtml&amp;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>.

    Parameters

    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 ? '' : '&lt;p&gt;RemoteWikiPage: server value required.&lt;/p&gt;';
    let page_text ..= args.p_path ? '' : '&lt;p&gt;RemoteWikiPage: p_path value required.&lt;/p&gt;';
    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 ? '&amp;format='..args.p_format : '&amp;format=xhtml';
    let append_params ..= args.p_section ? '&amp;section='..args.p_section : '';
    if ( args.p_parameters != nil ) {
    foreach (var param in args.p_parameters) {
    let append_params ..= '&amp;'..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('&lt;p&gt;&lt;span style="font-size: smaller; color: #999;"&gt;Content retreived from &lt;a href="'..args.server..args.p_path..'"&gt;'..args.server..args.p_path..'&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;') } }}</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"} ] } }}
    

     

    Tag page
    Viewing 4 of 4 comments: view all
    The remote transclusion stuff needs to go into the DekiScript FAQ!! :)
    Posted 23:19, 15 Sep 2008
    Will do! Just need a little time to make it easy to follow instead of wandering to the end result. :)
    Posted 23:22, 18 Sep 2008
    Actually, I think I'm going to experiment a bit with remote searching as well before bundling the whole thing into a FAQ.
    Posted 18:35, 19 Sep 2008
    How can I make remote wiki to allow Anonymous content retrieval?
    Posted 02:51, 17 Dec 2008
    Viewing 4 of 4 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by