Topic on Project:Support desk

Ability to write extensions in other languages with a PHP "connector"

4
69.191.241.48 (talkcontribs)

Hi, I am quite new to the MediaWiki community, and would love to learn more about the options with regards to creating new MediaWiki extensions:

Specifically, is there a feature to create a non PHP extension (i.e. a C++ task or a Python script) and use some sort of PHP connector (still fleshing this thought out) to appropriately meet the API required by the MediaWiki.

From a language perspective, from my understanding, Python etc may only be called through an `exec` call from PHP. From the MediaWiki side, I have gotten a chance to read through some documentation on developing extensions here, here, and have also look through past tasks / feature requests but haven't been able to find an answer to this.

I understand there are various client libraries in other languages, and my question is specifically with regards to extensions. Is there a precedence for this or are there some best practices / examples of this happening?

Apologies in advance if this is a silly question and is completely unfeasible.

Bawolff (talkcontribs)

Its generally discouraged in extensions aimed at Wikimedia wikis (unless you have a good reason).

Most exceptions use shelling out (exec). Some notable examples are EasyTimeline, scribunto (in luastandalone mode) or SyntaxHighlight.

Sometimes people develop features that call out to separate apis not part of mediawiki, most commonly written in node.js. See RestBase, mathoid, Parsoid.

The last option is to write a php extension and then use it in your mediawiki extension. The only example i am aware of is Scribunto when using luasandox as the lua engine

Nnaka1 (talkcontribs)

@Bawolffthanks for the feedback. I just want to clarify a few things that you said:

  1. may I know why extensions for MediaWiki in other languages are discouraged? Is that due to PHP language or something related to the MediaWiki architecture?
  2. when you say "call out to separate APIs not part of MediaWiki", does that mean, an extension would be making separate HTTP calls (for example) to a standalone Node.js server (I see in the example of Parsoid there's a separate Parsoid Node.js service that needs to be running)? Are there any pitfalls in taking this approach?
  3. to make sure I'm fully understanding, for the last option do you mean that a PHP extension can make a call out to a non PHP extension? In the example of Scribunto (in PHP), I can see that it can use LuaSandbox (in C). In the case of LuaSandbox, where can I learn more about the interfaces necessary to work as a non-PHP extensions (from my very basic searching, I found something called Zend although I'm not sure whether it's relevant here)?
Bawolff (talkcontribs)

For 1 - i think its a bit of preference. If you have a proliferation of languages it can be difficult to manage. It can also be hard to integrate with mediawiki if you have to shell out all the time. Generally calling other (rest) apis over https is considered much better than executing a separate binary.

2 yes. All approaches have pros and cons. Pitfalls tend to be it can be difficult to integrate closely (especially if you need to maintain state). All approaches have pros and cons.

3. When i say php-extension, i mean an extension to php (written in c), not an extension written in php. But yes, you would have to lookup the php/zend docs for that. Writing php extensions are a somewhat heavier approach, so people usually only do that if they have a good reason to.

Reply to "Ability to write extensions in other languages with a PHP "connector""