phphtmlmediawikimediawiki-extensions

Raw HTML in mediawiki extension


I'm writing a mediawiki extension and the code works great in a standalone model. The goal is to generate an HTML select widget that fires off some javascript with the onchange event. When I take the same code and put it in mediawiki it shows the raw code instead of interpreting it.

This is for an internal wiki and I'm the only editor, my team of volunteers will be the viewers. That said I'm not too worried about being somewhat liberal on permissions especially while testing.

I've turned on $wgRawHtml = true; in LocalSettings.php

And also tried return [ $html , markerType => 'nowiki' ];

But I get back the actual HTML on the wiki page

<html>
<select onchange='processSelect ( this.value )'><option value='0' >SWR MV1</option><option value='1' >SWR 2 NA</option><option value='2' >SWR MV2</option><option value='3' >SWR 4 NA</option></select>
</html>

Solution

  • You are on the right track with returning [$html, 'markerType' => 'nowiki'], but you also need to tell MediaWiki that the returned output is HTML. Otherwise, the MediaWiki Sanitizer will sanitize the output of your parser function:

    return [$html, 'noparse' => true, 'isHTML' => true];

    I recommend you turn off $wgRawHtml, since it can be extremely dangerous for publicly editable websites, since it allows your users to insert arbitrary HTML into a page. It will not affect the sanitation of parser functions.