"WikiModel" - "render()" - Some "Wikitext" chunks not converted

9 views
Skip to first unread message

Lmhelp

unread,
Aug 6, 2010, 10:26:30 AM8/6/10
to Bliki - Java/Eclipse Wikipedia API
Hi,

Thank you for reading my post.

I have been using the "WikiModel" "render()" method.
-----------------------------------------------------------------------------------------------------------
String htmlString = wikiModel.render(rawWikiText);
-----------------------------------------------------------------------------------------------------------

After executing that code line,

-----------------------------------------------------------------------------------------------------------
> "rawWikiText" contains:
-----------------------------------------------------------------------------------------------------------
'''Cokot''', en [[serbe]] [[Alphabet cyrillique serbe|cyrillique]]
{{lang|sr|?????}}, est une localité de [[Serbie]] située dans la
municipalité de [[Palilula (Niš)]], district de [[Nišava (district)|
Nišava]]. En [[2002]], elle comptait {{formatnum:1401}} habitants<ref
name="stats1">{{Historique de la population (Serbie)}}</ref>, dont une
majorité de [[Serbes]].
-----------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------
> "htmlString" contains:
-----------------------------------------------------------------------------------------------------------
<p><b>Cokot</b>, en <a href="http://fr.wikipedia.org/wiki/Serbe"
title="serbe">serbe</a> <a href="http://fr.wikipedia.org/wiki/
Alphabet_cyrillique_serbe" title="Alphabet cyrillique
serbe">cyrillique</a> {{lang}}, est une localité de <a href="http://
fr.wikipedia.org/wiki/Serbie" title="Serbie">Serbie</a> située dans la
municipalité de <a href="http://fr.wikipedia.org/wiki/Palilula_(Ni
%C2%9A)" title="Palilula (Niš)">Palilula (Niš)</a>, district de <a
href="http://fr.wikipedia.org/wiki/Ni%C2%9Aava_(district)"
title="Nišava (district)">Nišava</a>. En <a href="http://
fr.wikipedia.org/wiki/2002" title="2002">2002</a>, elle comptait
{{formatnum:1401}} habitants<sup id="_ref-stats1_a"
class="reference"><a href="#_note-stats1" title="">[1]</a></sup>, dont
une majorité de <a href="http://fr.wikipedia.org/wiki/Serbes"
title="Serbes">Serbes</a>.</p>
-----------------------------------------------------------------------------------------------------------

"htmlString" still contains two "Wikitext" chunks:
- {{lang}}
and
- {{formatnum:1401}}.

=> "{{lang}}" should have been suppressed.
=> "{{formatnum:1401}}" should have been replaced by "1401".

Is it normal it didn't happened?
Is there another way to make it work?

Thank you for your help.
All the best,
--
Lmhelp

Axel Kramer

unread,
Aug 6, 2010, 10:53:41 AM8/6/10
to Bliki - Java/Eclipse Wikipedia API


On Aug 6, 4:26 pm, Lmhelp <lea.mass...@ign.fr> wrote:
...
> "htmlString" still contains two "Wikitext" chunks:
> - {{lang}}
> and
> - {{formatnum:1401}}.
>
> => "{{lang}}" should have been suppressed.
> => "{{formatnum:1401}}" should have been replaced by "1401".
>
> Is it normal it didn't happened?
> Is there another way to make it work?

Lang is a template defined here:
http://fr.wikipedia.org/wiki/Mod%C3%A8le:Lang

You can return the templates code in the raw getRawWikiContent()
method of your wikimodel as described here:
http://code.google.com/p/gwtwiki/wiki/WikiModels#How_to_expand_templates_found_in_a_wiki_text

A more advanced example how to get the test throught the api.php could
be found here:
http://code.google.com/p/gwtwiki/wiki/Mediawiki2HTML#Advanced_example_for_converting_Wikipedia_texts_to_HTML

The formatnum function is currently not implemented. You need to
implement a AbstractTemplateFunction. For example take the following
code as a simple example to start with:

public class Formatnum extends AbstractTemplateFunction {
public final static ITemplateFunction CONST = new Formatnum();

public Formatnum() {

}

public String parseFunction(List<String> list, IWikiModel model,
char[] src, int beginIndex, int endIndex) {
if (list.size() > 0) {
String result = parse(list.get(0), model);
return result;
}
return null;
}
}

and define a static block in your IWikiModel class similar to this
static {
Configuration.DEFAULT_CONFIGURATION.addTemplateFunction("formatnum",
Formatnum.CONST);
}

Axel Kramer

unread,
Aug 6, 2010, 11:20:57 AM8/6/10
to Bliki - Java/Eclipse Wikipedia API
I added these changes for "formatnum" and "plural" to SVN:
http://code.google.com/p/gwtwiki/source/detail?r=1904

Lmhelp

unread,
Aug 6, 2010, 12:00:49 PM8/6/10
to Bliki - Java/Eclipse Wikipedia API
Ok. Thank you for your answers.

After doing the modifications described in:
http://code.google.com/p/gwtwiki/source/detail?r=1904
am I supposed to get what I want: the HTML string
without the chunk of "Wikitext" "{{lang}}"
and with "1401" instead of "{{formatnum:1401}}"
because it is not so easy to understand... ?

Moreover, once I have modified some files and created
others how to I make the ".jar" file so that everything
doesn't fail?

Thanks.
--
Lmhelp
Reply all
Reply to author
Forward
0 new messages