1

I have a MediaWiki installation and I'm writing a custom script that reads some database entries and produces a custom output for client.

However, the text are in wiki format, and I need to convert them to HTML. Is there some PHP API I could call -- well there must be, but what and how exactly?

What files to include and what to call?

Nemo
  • 2,441
  • 2
  • 29
  • 63
Tower
  • 98,741
  • 129
  • 357
  • 507
  • did you have a look at [mediawiki2html](http://code.google.com/p/gwtwiki/wiki/Mediawiki2HTML) ? –  Aug 20 '12 at 11:28
  • I'm using PHP just like the MediaWiki itself. The library seems to be for Java. – Tower Aug 20 '12 at 11:36
  • right - i thought that was a black box to which you gave the page name for example and it generates the html page. –  Aug 20 '12 at 11:46

2 Answers2

4

You use the global object $wgParser to do this:

<?php

require(dirname(__FILE__) . '/includes/WebStart.php');

$output = $wgParser->parse(
    "some ''wikitext''",
    Title::newFromText('Some page title'),
    new ParserOptions());
echo $output->getText();

?>

Although I have no idea whether doing it this way is a good practice, or whether there is some better way.

svick
  • 236,525
  • 50
  • 385
  • 514
  • This works otherwise great, but I want to get rid of images -- I am doing this for "an offline print" and we don't want images, is there a way to configure it or should I try to `preg_replace()` them off? – Tower Aug 21 '12 at 13:20
  • Can't you hide them using CSS? I think that would be a clean solution. [I would be very careful with using regular expressions to process HTML.](http://stackoverflow.com/a/1732454/41071) – svick Aug 21 '12 at 17:50
2

All I found is dumpHTML.php that will dump all your mediawiki ; or may be better API:Parser wiki text which tells :

If you are interested in simply getting the rendered content of a page, you can bypass the api and simply add action=render to your url, like so: /w/index.php?title=API:Parsing_wikitext&action=render

Once you add action=render it seems you can get the html page ; dont you think ?

hope this could help.

regards.

  • It's a shame I have to call an URL, because that can't be very fast for a large wiki... – Tower Aug 20 '12 at 11:58
  • i agree :/ i just give you what seems to be the possible answer from the existing resources - this last suggestion should be enough for some page ; but if you need it for the complete wiki dumpHTML may be do the trick ? –  Aug 20 '12 at 12:00