Manual:Forms

Out-of-the-box MediaWiki uses Form-based data entry for a variety of page maintenance and administrative functions. MediaWiki articles themselves are created using free-form wiki-text. Like most other features of MediaWiki, there are numerous customization possibilities available. These include ready-made extensions, various techniques for customizing the default set of forms, and even techniques for creating and installing custom forms.

Customizing built-in forms
Please see the following articles:


 * General:
 * Manual:Interface, Manual:System message - describes how to customize/localize the text that appears on the built-in forms used by MediaWiki.
 * User authentication forms:
 * hooks - functions attached to this hook can define a replacement for the standard form to create a new user.
 * hooks - functions attached to this hook can define a replacement for the standard login form.

Creating/editing articles with structured data
Some articles contain a mix of structured data and free form text. For example, an article that holds a description of a marketing contact or a bug report would normally have a set of questions that must always be answered to create a complete article. In this case, a form or an article with some preloaded wiki text might be more appropriate.

MediaWiki has three strategies for handling these kinds of situations:


 * Creating pages with preloaded text: Typically the freeform text includes a template with blank parameter values. The user fills in the template parameters as a kind of form within the wiki-text. The advantage of this approach is that, with the help of a few extensions, it can be easily implemented by end-users with basic wiki text and template knowledge.  The disadvantage is that the forms are in wiki text and can be typed over by a careless user.  For more information on this approach, please see Manual:Creating pages with preloaded text.
 * Special page extensions: A special page is a "virtual" mediawiki article whose page content is generated by PHP code. One method for structured input is to install an extension that generates a form to create or edit an article.  A list of extensions currently available, can be found at Category:Special page extensions.
 * You can also write your own such form. Writing your own extension requires PHP coding skill and comfort with object oriented design and databases also is helpful.  You will also need to know how to use code to create and edit MediaWiki articles. For more information, please see Manual:Special pages and the discussion of  below.
 * Articles with embedded forms: Another approach to form based data entry is to create an article whose sole purpose is to define a data entry form. This can be viewed as kind of hard coded special page. The main advantage of this approach over the special forms approach is that one can easily put together an infrastructure that will let users create the data entry forms as part of the normal MediaWiki editing process.   for more information.
 * Intercepting the edit action: A forth approach is to take over all or part of the MediaWiki editing process. When MediaWiki loads a page, it checks the action query parameter and calls one or more hook functions based on its value.  By attaching a function to one of these hooks you can reinvent the entire page editing process.  For more information, please see.

Special pages with embedded forms
For a list of available special-page based extensions, see Category:Special page extensions.

Articles with embedded forms
Creating an article with an embedded page creation form involves two design steps:


 * 1) Embed the form in an article
 * 2) Edit the page programatically

Embedding the form in an article
For security reasons MediaWiki limits the kinds of HTML you can embed directly in wiki text. Plain vanilla MediaWiki won't let you create data entry forms directly in the wiki text. However, a variety extensions exist to allowed the controlled reintroduction of HTML. For example, Extension:HTMLets lets one define files containing HTML forms. These files are stored in a subdirectory of the MediaWiki installation (permissions set appropriately to prevent random editing or direct server access), and can be inserted into wiki text using the tag   where name is.

Creating/editing the page programmatically
Once you've defined your form file, you'll need to use the data collected by it to create an article. You can do this by having your form generate a URL that contains an  query parameter. When MediaWiki loads a page, it checks the action query parameter and calls one or more hook functions based on its value.

Most of these actions have set meanings, so you won't want to use any of the standard actions. Rather you will want to create your own "autocreate" or "autoedit" action. To do this, you add a function to the hook.

For more information on programmatically creating or changing page content, please see:
 * Manual:Edit token
 * Manual:Edit token

Intercepting the edit action
An alternative to either special pages or forms embedded in articles is to take over the page editing process. This is accomplished by adding a custom function to one or more of the several hooks that get invoked during the course of the editing process.


 * - is called when action=edit. It gives MediaWiki installations an opportunity to provide an alternate response to the edit action. For an example of an extension that uses this approach to form-based editing, see User:Barrylb/Custom_article_editing_form_with_fields.
 * is called when the text window used to enter MediaWiki text is displayed. It gives extension writers the ability to define an alternative to the simple edit box.