wtf_wikipedia icon indicating copy to clipboard operation
wtf_wikipedia copied to clipboard

Link rendering options

Open niebert opened this issue 6 years ago • 4 comments

For a proper url processing, the URL rendering in /src/output with sentence needs to have awareness about the currently processed article (e.g. article "Water" language "en" domain "wikiversity". The mediawiki allows subdirectory references like

[[/My Subdir/]] or [[/My Subdir/|my subdirectory of the article]] 

With the knowledge about currently processed wiki article, the url to wiki source must be expanded to: ./Water/My_Subdir or https://en.wikiversity.org/wiki/Water/My_Subdir and not to .//My_Subdir. See also an example in relative link to a subdirectory/article in a Wikibook https://en.wikibooks.org/wiki/JavaScript/Operators

I guess, that the output render engine needs to know about currently processed article. These info can be submitted to the output renderers via options. Furthermore this information will allow the expansion of relative links to absolute links. The expansion of relative links to absolute links is necessary, when the wtf_wikipedia runs in browser and the fetched article from the mediawiki API is handled in browser environment where relative links do not work anymore.

Spencer, but I may be wrong with this and it is not a problem at all, because you solved that differently from passing this information via options to the renderer.

niebert avatar Jun 03 '18 18:06 niebert

hi Engelbert, Yeah, good point. I think you're right.

I'm open to any solutions to this. I agree that relative links will probably be the most-common usage, but passing some kinda absolute_links:true options param would be great, and would require the lang getting passed-around too.

wanna do this?

spencermountain avatar Jun 05 '18 16:06 spencermountain

Hi Spencer, after a bit of analysis it seems, that the following solution might be helpful. The Wiki-ID e.g. enwikiversity consists of two components combined in the Wiki-ID:

  • en: english language and
  • wikiversity: the domain or wiki product of the Wiki Foundation from which wtf_wikipedia will fetch the raw MediaWiki markdown.
  • path: used for relative links

I think the easiest and most versatile approach would be just to pass the language and domain as key, value pairs to the output renderers. Even images in HTML might benefit from that key value pairs, see https://github.com/spencermountain/wtf_wikipedia/blob/master/src/output/html/image.js in which the full size button with an appended link and icon might be rendered along with the thumbnail image, that is already used by image.thumbnail(). So the object image might have the attribute image.source.language="en", image.source.domain="wikiversity" and image.source.path="Water/My_Subdir". Does that make sense to you or are there other issues that I am not aware of?

Even handling of images can benefit from access to language and domain

  • Assume the image Annweiler_Rathaus.JPGis embedded in the english Wikipedia, ... article. Image is stored in Wiki Commons.
  • The link https://en.wikipedia.org/wiki/Special:Redirect/file/Annweiler_Rathaus.JPG refers to the current version of the image Annweiler_Rathaus.JPG in Wiki Commons via an redirect.
  • Size of image can be determined by http://en.wikipedia.org/wiki/Special:FilePath/Annweiler_Rathaus.JPG?width=300 (here resize the width to 300 pixels.
  • along with wtf_wikipedia developers could use wgetjs with browserfiy-fs to generate offline documents and return a zipped bundle of Wiki article (especially useful as an offline complement for the Wiki Book Creator - wtf_wikipedia is really a great repository to accomplish that goal to have client side document generator, that does not create performance issues on the Media Wiki servers of the Wiki Foundation)
  • Download of images for local use will be performed by Javascript implementation of wget, i.e. a browserified version the wgetjs NPM module which replaces the fs module of writing to the file system by browserify-fs that runs a file system replacement completely in a browser. Zipping of the wtf_wikipedia output together with downloaded full size images can be performed by zipjs https://stuk.github.io/jszip/ and access the zip in the browser by FileSaver.js and allow the user to "locally download" the generated file in the browser to the file system of the client.

best regards, Bert

niebert avatar Jul 15 '18 07:07 niebert

Need to update https://niebert.github.io/Wiki2Reveal/ with the current version of wtf_wikipedia when I understood everthing properly. Thank you Spencer

niebert avatar Jul 15 '18 07:07 niebert

ah, sorry for the delay on this. yeah, lets do this. I agree on the proposal, to add an options to output methods, to supply more configuration in rendering links.

would this be enough?

{
  path:'http://mysite.com/wiki/'
}

spencermountain avatar Jul 31 '18 15:07 spencermountain