I am trying to use Wikipedia's MediaWiki parser to parse Wikipedia mark up text to HTML. I went through the manual here - https://www.mediawiki.org/wiki/Manual:Parser.php However, since I am completely new to PHP, I am unable to write a test script,
Here is a sample input that I would want to parse and convert to HTML:
Shakespeare's sonnets
==Characters==
When analysed as characters, the subjects of the sonnets are usually referred
to as the Fair Youth, the Rival Poet, and the Dark Lady. The speaker expresses
admiration for the Fair Youth's beauty, and later has an affair with the Dark
Lady. It is not known whether the poems and their characters are fiction or
autobiographical; scholars who find the sonnets to be autobiographical, notably
[[A. L. Rowse]], have attempted to identify the characters with historical
individuals.
Here is the minimal code for parsing wikitext (tested on MediaWiki 1.32):
$text = "Your [[wikitext]]";
$title = $skin->getTitle(); // Get the title object from somewhere or use $wgTitle
$parser = new Parser;
$parserOptions = new ParserOptions;
$parserOutput = $parser->parse( $text, $title, $parserOptions );
$html = $parserOutput->getText();
echo $html;
Bye!
You don't even have to use PHP. You can use Wikipedia's API (or the API on your own MediaWiki installation). See Parsing wikitext for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With