My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
WikiModels  
How to use the WikiModel
Phase-Implementation
Updated Mar 18, 2011 by axelclk@gmail.com

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:

  MyWikiModel wikiModel = new MyWikiModel("http://www.mywiki.com/wiki/${image}",
                                          "http://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:

  wikiText = "This is a simple [[Hello World]] wiki tag {{my template}}";

our implementation method MyWikiModel#getRawWikiContent() looks something like this:

	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 info.bliki.wiki.impl.APIWikiModel class you can find a more sophisticated example in the method getRawWikiContent(). There the template content is cached in an internal Java 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 Magic words Variables are not completely supported. In the info.bliki.wiki.filter.MagicWord you can find the currently implemented magic words variables.

How to substitute template calls (currently unreleased)

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:

{{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)
}}
Comment by r3info...@gmail.com, Oct 10, 2009

Hi,

is there a way to render the templates without relying on the wikipedia API? - Somehow cache the template definition and apply them offline.

Thanks so much for this amazing toolset!

Comment by project member axelclk@gmail.com, Oct 11, 2009

Rewrite the getRawWikiContent() method in the info.bliki.wiki.impl.APIWikiModel, so that you store your needed templates in the Derby database and when use the APIWikiModel without using the wikipedia API.

Comment by r3info...@gmail.com, Oct 17, 2009

Hi,

I derived a class from info.bliki.wiki.model.WikiModel? and added getRawWikiContent(), which returns the plain wikiMarkup contained in the page Template:<some_name> . I however did not call super(), and somehow i think that may have something to do with the fact that only very few templates are expanded.

Is there something i miss? - I use this framework just for rendering, the data is coming from a local key-value storage which maps <pagetitle> -> <wikimarkup> generated from a xml-dump.

BTW: Does bliki expand templates like {{CURRENTMONTH}} or {{PAGETITLE}} ? - Or does it rely on the online API?

Many Thanks in advance :)

Comment by project member axelclk@gmail.com, Oct 18, 2009

In the method encodeTitleToUrl(...) all spaces will be replaced by underscores (''). If you additionally set the second parameter to 'true' in this method, the first character will be converted to uppercase. Maybe this is the problem?

{{CURRENTMONTH}} should be expanded but {{PAGETITLE}} not at the moment.

You can use {{PAGENAME}}, if you set the name in the IWikiModel#setPageName() method.

Powered by Google Project Hosting