Wiki
Clone wikiinfo.bliki.wiki / WikiModels
How to use the WikiModel
Introduction
For this page we assume that we use the following code snippet with a MyWikiModel
which is derived from the info.bliki.wiki.model.WikiModel
class or info.bliki.wiki.model.IWikiModel
interface:
#!java MyWikiModel wikiModel = new MyWikiModel("https://www.mywiki.com/wiki/${image}", "https://www.mywiki.com/wiki/${title}"); String wikiText = "some wiki text we would like to convert to HTML"; String htmlStr = wikiModel.render(wikiText); System.out.print(htmlStr);
How to expand templates found in a wiki text
If our model should support Transclusion (i.e. expanding templates within a document) we have to implement the IWikiModel#getRawWikiContent()
method.
If we would like to expand the my template
template with the text "foo" in the following string:
#!java wikiText = "This is a simple [[Hello World]] wiki tag {{my template}}";
our implementation method MyWikiModel#getRawWikiContent()
looks something like this:
#!java public final static String MY_TEMPLATE = "foo"; ... ... @Override public String getRawWikiContent(String namespace, String articleName, Map<String, String> map) { String result = super.getRawWikiContent(namespace, articleName, map); if (result != null) { // found magic word template return result; } // replace SPACES with underscore('_') and first character as uppercase String name = encodeTitleToUrl(articleName, true); if (isTemplateNamespace(namespace)) { if (name.equals("My_template")) { return MY_TEMPLATE; } } return null; }
In the APIWikiModel.java
class you can find a more sophisticated example in the method getRawWikiContent()
.
There the template content is cached in an internal Apache Derby database.
If the template is not available in the database we import it directly from a wiki which supports the
Mediawiki API with the info.bliki.api.User#queryContent(String[] listOfTitleStrings)
method.
The [https://www.mediawiki.org/wiki/Help:Magic_words#Variables Magic words Variables] are not completely supported.
In the MagicWord.java
you can find the currently implemented magic words variables.
How to substitute template calls
If the model should support a special substituting or extracting of template calls, which differs from the default implementation,
we have to implement the IWikiModel#substituteTemplateCall(templateName, parameterTreeMap, writer)
method.
Simply override the default implementation of the info.bliki.wiki.model.AbstractWikiModel
(or info.bliki.wiki.model.WikiModel
),
to get your own behaviour inside your wiki model.
For example it's useful, if you would like to extract an Infobox
template like this one from the Tom Hanks Wikipedia page:
#!java {{Infobox Actor | image = TomHanksApr09.jpg | caption = Hanks in April 2009 | birthname = Thomas Jeffrey Hanks | birthdate = {{birth date and age|1956|7|9}} | birthplace = [[Concord, California]], [[United States|U.S.]] | yearsactive = 1979�present | occupation = Actor, producer, director, voice over artist, writer, speaker | spouse = Samantha Lewes (1978�1987)<br>[[Rita Wilson]] (1988�present) }}
Updated