Use case:
- Page A:
- A form with an edit field and a submit button is provided on some page A.
- The user enters a new (non existing) page name in the form field and clicks the button.
- Page B:
- A new Wiki page is opened (= page B) in edit mode, but already pre-filled with some text for convenience.
Technical details behind the scene:
- There could be two extensions in this scenario: An extension A providing a button in a page and an extension B filling a new page with boilerplate text.
- Extension A:
- The button is rendered by extension A. A variety of parameters is provided. Here this extension A is used in page A. If clicked this extension executes JavaScript code that simply redirects to an URL that allows the creation/editing of a new page. Very simple.
- Extension B:
- Extension B hooks into the page creation process using hook EditFormPreloadText.
- Specific parameters provided with the button can be received by extension B as they are passed along with other URL parameters.
- This allows the extension B to pick a specific boilerplate: This way a boilerplate is not defined by namespace (as typical boilerplate extensions do) but by a parameter originally originating from page A.
- The extension B inserts a boilerplate text and then the user can edit the new page using this text.
The problem:
- The parser hook EditFormPreloadText currently only receives two arguments by reference:
- a text string
- a title object
- Currently there is no way to pass specific arguments to a hook function such as information about a boilerplate to use. Current implementations can *only* depend on configuration information to select a boilerplate, but not on parameters passed on along with a page.
The suggested solution:
- Hooks for EditFormPreloadText should be able to receive parameters. For that I recommend a very simple change to EditPage.php:
- replace line 667: Hooks::run( 'EditFormPreloadText', [ &$this->textbox1, &$this->mTitle ] );
- with: Hooks::run( 'EditFormPreloadText', [ &$this->textbox1, &$this->mTitle, $request->getText( 'extra' ) ] );
Explanation:
- The parameter extra if provided in an URL could contain additional data to pass along to the code in extension B loading the correct boilerplate.
- The parameter extra could be kept generic as any additional details about the boilerplate loading (and/or fabrication) should not be defined in the MediaWiki core software itself but by the extensions communicating with each other.
Disclaimer:
Maybe there's a better way how to do this. If so, please tell me: The volume of the MediaWiki software is quite large and as not having written it myself there might of course be a more elegant solution than the one I propose here and which I'm not aware of. If that is the case I'd be happy to learn about it.