Page MenuHomePhabricator

Reduce reliance on global state in PageForms extension
Open, Needs TriagePublic

Description

Among all extensions known to codesearch, PageForms relies by far the most on global state, in particular the wgOut and wgRequest variables:
https://codesearch.wmcloud.org/things/?q=global%5B%5E%3B%5D%2B%5C%24wg%28Request%7COut%29%5B%2C%3B%5D#Extension:PageForms

Considering current efforts to deprecate the wg variables, these should be removed eventually.
Skimming through the different callsites for a while, I think the best way to deal with this would be to have PFFormPrinter::formHTML accept an IContextSource as an argument, which will usually be available at its callers. As a side-effect, this will get rid of some hacks regarding the request and allow to replace a few calls of RequestContext::getMain()->getUser().
The context (or the associated OutputPage) can then be passed to the various functions called as needed -- most of the other sites using global variables seem to be exclusively called from here. Do you agree?

Of course, this may change quite a few of the method signatures involved, so it would be great to obtain an understanding early whether these can just be changed or whether in some cases, we should be more careful.
In particular, PFFormInput::getHTML and PFFormInput::getHtmlText could be candidates to be assumed stable to overwrite and should be kept compatible for now?

Details

Related Changes in Gerrit:

Event Timeline

Adding another parameter to PFFormPrinter::formHTML() makes sense. I think modifying those other methods is fine also - as far as I know, there's currently only one other extension that defines a Page Forms form input, MintyDocs, and it can easily be modified to switch to the new header style.

Change #1268087 had a related patch set uploaded (by MGChecker; author: MGChecker):

[mediawiki/extensions/PageForms@master] Replace wgOut and wgRequest

https://gerrit.wikimedia.org/r/1268087

Change #1268087 merged by jenkins-bot:

[mediawiki/extensions/PageForms@master] Replace wgOut and wgRequest

https://gerrit.wikimedia.org/r/1268087