The situation is, I have a private wiki, say at http://mysite.com/wiki, which is behind a password. What I’d like to do, is have a separate location on the same server, that could read arbitrary text files with wiki text (code), and use the particular engine of http://mysite.com/wiki to render HTML from it (because of installed templates/plugins).
As example, I would have a /tmppub directory on http://mysite.com; and in it, I’d have a text file with wiki text source code in it, say Example.wiki, and a process.php page; then I’d call:
http://mysite.com/tmppub/process.php?file=Example.wiki
… where process.php would read the file Example.wiki in the same directory, pass the contents somehow to the ../wiki installation, and retrieve the HTML output and display it.
I guess, what I want is similar to the example in Mediawiki2HTML – gwtwiki – How to convert Mediawiki text to HTML – Java Wikipedia API (Bliki engine) – except this Mediawiki2HTML is in Java (I’d want PHP) and possibly uses internal rendering engine (I’d want an already existing specific installation of Mediawiki).
The thing is, I can cook me up a PHP script which will read the file, handle the password of /wiki, and pass GET and POST variables – except I’m not sure how I would address the Mediawiki installation:
- I could try to fake a call to
&action=edit(e.g. Editing Wikipedia:Sandbox) and ask for a preview; but that would return the edit buttons and text fields, which I’d have to manually clean – no like - I could try to address the API, but as I can see in API:Parsing wikitext – MediaWiki, it will only work with pages already in the Mediawiki installation – not with pages off of it.
Finally, I’d like to obtain just the raw HTML of the content (without HTML for sidebars and such), as when using action parameter render (example).
Does anyone one if there is already such a PHP application available – and if not, what would be the proper way to address the Mediawiki installation, to obtain a ‘raw’ HTML rendering of the wiki text source?
Thanks in advance for any answers,
Cheers!
You can actually use the API even to parse custom wikitext using the
parseaction. (Thetitleparameter is maybe a bit misleading, but it’s really just a pointer for the parser when using, for example,{{PAGENAME}}.) To parse existing page, therenderaction is used.If the authentication is HTTP-based and you have access to the MediaWiki installation, you can abuse the code that is used for maintenance scripts to load the important stuff and parse on top of that. (This is maybe a little dirty, though.) The following code is taken from
includes/api/ApiParse.phpand edited a little (of course, adjust the file path to your needs):The parsed HTML is now in the
$parsedTextvariable. If you need to perform pre-save transform on the text (expand{{subst:}}s, tildes to signatures, etc.), take a look to theApiParse.phpfile for reference.