wtf_wikipedia
wtf_wikipedia copied to clipboard
Link rendering options
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.
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?
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 whichwtf_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.JPG
is 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 usewgetjs
withbrowserfiy-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 thefs
module of writing to the file system bybrowserify-fs
that runs a file system replacement completely in a browser. Zipping of thewtf_wikipedia
output together with downloaded full size images can be performed byzipjs
https://stuk.github.io/jszip/ and access the zip in the browser byFileSaver.js
and allow the user to "locally download" the generated file in the browser to the file system of the client.
best regards, Bert
Need to update https://niebert.github.io/Wiki2Reveal/ with the current version of wtf_wikipedia
when I understood everthing properly. Thank you Spencer
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/'
}