Search code examples
phphtmlmediawikiwikitext

How to manually call MediaWiki to convert wiki text to HTML?


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?


Solution

  • 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.