Introduction
MakeArticle is an extension that, given a template, presents the user with a form in which they can fill in:
- An article name
- Values for the template's parameters
When they then click the 'create' button , it builds an article with that name based on the template parameterised by those values.
Essentially, it takes the idea from extensions like CreateArticle and extends it by allowing the text pre-loaded into the new page to be configurable on the fly, so one can specify any template in the markup and create a parameterised article. So it provides a handy tool for creating new pages by filling in a form.
Functionality
The extension takes a two-pass approach:
- Building a web-form based on the structure of the specified extension. This uses the hook ParserFirstCallInit.
- This includes using a style-sheet to format the form, that the wiki manager can customise)
- In response to the button-click, using the provided parameter values to build a new article and take the user there. This uses the hook UnknownAction.
Pass One : Hook ParserFirstCallInit
This pass registers a loader function with the hook, the loader function associating the tag <makearticle>
with the function wfMakeArticle
(line 40). This creates an instance of the class MakeArticle
(line 46) and then invokes the member function render()
of that instance.
The function render()
:
- Uses the stylesheet pointed to by the global variable
$wgMakeArticleCSS
(defaults to$IP/extensions/makearticle/Style.css
) to insert formatting information into a page header. - Attempts to read in the contents of the template file named in the text between the tags.
- Extracts the names of the parameters from the template.
- Builds an HTML form styled by the stylesheet which:
- Asks the user for a name for the new article to be created.
- Asks for values for the template's parameters.
- Provides a 'create' button.
When the user hits 'create' the form sends this information back to MediaWiki, together with additional parameters:
- The name of the template.
- An identifier tag
___makePage
to allow the second pass to identify which UnknownActions belong to this extension.
Pass Two: Hook UnknownAction
This pass registers the function wfActionMakeArticle
(line 127) with UnknownAction. The function filters out those events that are relevant by looking for the ___makePage
tag. It then:
- Attempts to create a new article with the specified name.
- Inserts into the article the text:
- {{{template name | parm1="value1" | . . .}}}
- Redirects MediaWiki to the new page.
The Stylesheet
The stylesheet is used to format the web form generated in pass 1. Here is a quick run down of what it does:
Class | Function |
---|---|
.mpForm | Applies to the <div> encompassing the entire form. Essentially used to set the total width of the form. |
.mpForm h2 | Formats the form's heading. |
.mpR | Additional formatting for the name of the template in the heading (default is red text). |
.mpTable | Formats the table containing the parameter names and textareas. |
.mpForm textarea | Formats textareas used for user input; includes setting height and a width hack to stop them overlapping at the right-hand edge of the table. |
.mpForm textarea.mpSingle | Used for the textarea containing the page name, to make it a different height to the parameter textareas. |
.mpHeader | Sets the width of the field-name column. |
.mpForm td | Formats table cells; background colour, border, etc. |
.mpButton | Formats the 'create' button. |
Acknowledgements
I would like to acknowledge the following extensions:
- CreateArticle by Lisa Ridley, from which I took the basic two-pass approach.
- PageCSS by Ævar Arnfjörð Bjarmason, from which I took the code to inject a CSS into the generated page containing the form.