Page MenuHomePhabricator

Suggesting a change to hook EditFormPreloadText
Open, Needs TriagePublic

Description

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.

Event Timeline

Hi @RegisMay, thanks for taking the time to report this and welcome to Wikimedia Phabricator.

Maybe I don't understand correctly, but have you checked out https://www.mediawiki.org/wiki/Extension:Page_Forms ?

(Removing Platform Engineering tag as it's up to teams what they plan to work on; adding MediaWiki-Page-editing.)

To my understanding Page Forms does something completely different. Page Forms is the successor of Semantic Forms which displays a form. I don't want to display a form. I want to enable the user to enter a page name, click a button, and end up editing a fresh new page (without forms) where there is already content in the page. It's quite similar to what you get if you create an error report: The text form field offering you entering your bug report is prefilled with text. That's what everything is about in this feature request here.

The mechanism is simple: Redirect to a new URL allowing users to edit a page but an extension loads a boilerplate text. There are boilerplate extensions around but they rely exclusively on selecting boiler plates by namespace. I do not want that. I want to be able to specify in the page creation process which boilerplate to be used. All pages should reside in the same namespace. This is a very simple thing to accomplish if you would be able to pass information to the hook that is intended for filling a page with a boilerplate text could receive an additional argument.

Please note that form != form. There are HTML forms which are used to provide editing capabilities in web pages. And there are SMW Forms which enable the user to fill out a SMW form. Two completely different things. In this feature request here by "form" I'm referring to the HTML form the page contains where a user can edit the Wiki page.