A partial archive of https://discourse-mediawiki.wmflabs.org as of Saturday May 21, 2022.

Embedding/executing PHP in MediaWiki pages

abeason

Is there a method to embed and execute non-MW PHP within a MediaWiki page? For instance if we want to embed a link-shortening script into a page and run it directly within MediaWiki without having to host separately/externally and embed using an I-frame?

The idea here is that we would like to leverage the existing authentication system of MediaWiki to protect this script, which we’d like only registered users to be able to access.

Looks like there used to be a variety of ways to do this but most of the extensions that once accomplished this task are no longer maintained. Is that because the functionality was built into MW with hooks?

Any ideas appreciated. Thanks!

FlorianSW

If you mean by typing the PHP code into the wikitext: Hopefully not (and will never officially be). This would open doors for multiple possible attacks against a wiki and/or the whole web server hosting the wiki.

If you mean by adding an extension: Kind of. There’re several hooks you can use to post-process wikitext after it was parsed (or even before iirc), or hooks for whatever point you want to inject your own code in (manipulating the current data or something like that). That’s called an extension. You can add your own extension by developing it or use one of the existing ones. If you describe what you want to achieve a bit clearer and with more details, we might be able to give you a hint to an already existing extension, which does that.

RazeSoldier

UrlShortener extension work well for my wiki. You can try using it.

abeason

We had looked at this as a possible solution: https://www.mediawiki.org/wiki/Extension:Widgets

Basically we just want to be able to embed a form that allows users to input a URL and have the script shorten it according to our parameters (think bitly, but with our corporate branding).

Would widgets do the trick?

Thanks!