Extension:Form

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Form

Release status: experimental

Implementation Special page
Description Form interface for creating new articles according to a template
Author(s) Evan Prodromoutalk
Latest version 0.4.1 (July 2, 2009)
MediaWiki 1.11+
License GPL v2+
Download Template:WikimediaDownload/svn
README (SVN)
Example New Wine form on Vinismo.com
Parameters

$wgSpecialFormRecaptcha

Translate the Form extension if possible

Check usage and version matrix; code metrics

The extension lets users create new articles with a form. Administrators create a form in the MediaWiki namespace, and this form can be used to create a new article using a particular template.

Typical uses:

  • "New X" interfaces for wiki newbies.

This is the README file for the Form extension for MediaWiki software. The extension is only useful if you've got a MediaWiki installation; it can only be installed by the administrator of the site.

This is a testing version of the extension and it's almost sure to have bugs. See the BUGS section below for info on how to report problems.

The author is Evan Prodromou <evan@vinismo.com>

Pre-requisites[edit | edit source]

This software was tested with MediaWiki 1.10.0 (which is what Vinismo was running at the time). Current version of the extension requires at least MediaWiki 1.11 or a newer version.

Installation[edit | edit source]

  1. Download the extension
  2. Create a new folder called Form in your extensions folder.[1]
  3. Add the downloaded material to the SpecialForm folder

In your MediaWiki LocalSettings.php, add the following line some place towards the bottom of the file:

require_once("$IP/extensions/Form/Form.php");

Preparing forms[edit | edit source]

To create a new form do the following two steps:

  • Create a "form definition" in the MediaWiki namespace.[2]
  • Create an output template that describes the structure of the resulting articles.

Output templates are just regular MediaWiki templates. They should use named parameters rather than numbered parameters.

There is a sample form in "MediaWiki:Sample-form.wiki" and output template, "Template:Sample.wiki" in the form folder, also below

Sample form
title=Ew-nay Ample-say
namePattern={{{topic}}}
instructions=You can use this page to create a new article on a sample topic.
topic|Topic|text|Topic of the article.
purpose|Purpose|select|Purpose of the
article|items=Business;Pleasure;Other
intro|Introduction|textarea|An introductory paragraph about the topic.
color|Color|radio|Color of the article|items=Red;Blue;Green
conclusion|Conclusion|textarea|The conclusions of the topic.
Sample template
The topic is {{{topic}}}.

The purpose is {{{purpose}}}.

== Introduction ==

{{{intro}}}

== Color ==

{{{color}}}

== Conclusion ==

{{{conclusion}}}

Form definitions[edit | edit source]

A form definition article must be named "MediaWiki:Nameofform-form", where "Nameofform" is the name you are going to use for the form.[3]

Each line in the form page is either a form attribute or a form field definition. Each is described below.

Form attributes[edit | edit source]

Form attributes define information for the form as a whole. Each attribute line looks like:

 name=value

Note that no whitespace is tolerated before and after the name. Typically form attributes appear at the beginning of an article, but they are tolerated anywhere in the article, if you need things that way.

Valid names for form attributes are as follows:

  • template: name of the output template (without the namespace prefix) that will be used for creating new articles. If this is not defined, the default name will be "Template:Name", where "name" is the name of the form.
  • title: title that's shown on the form. By default, this is "Add New $1", where $1 is the name of the form. You can change the default title pattern with by changing MediaWiki:Formtemplatepattern.
  • namePattern: the pattern for new article names. This is based on the fields in the form, and uses MediaWiki template-substitution syntax (badly... only the simplest syntax is now supported). For example, if you are creating articles about sporting events results, and there are two form fields "year" and "event", the name pattern might be "{{{year}}} {{{event}}} Results". If the user fills in "2004" and "World Series", the resulting article will be "2004 World Series Results".
  • instructions: wikitext instructions for users of the form. Will be shown at the top of the form before any fields.

Form field definitions[edit | edit source]

Each field in the form has a line defining it in the form definition file. The structure of the field definition lines is:

 name|label|type|description|options

The parts of the field definition are separated by pipe ("|") characters and cannot include pipes themselves (even with "escape" characters). The parts of the definition are defined below:

  • name: name of the field. It must be unique, and contain only alphabetic or numeric characters or the underscore ("_"). This will be the parameter name used for the output template.
  • label: readable name for the field, used for labels. No restrictions, except for the lack of a pipe. No HTML or wikitext allowed (yet).
  • type: type of the form field (see below).
  • description: a user-readable wikitext description of the purpose and restrictions on the form field. Only shown for 'textarea' fields right now, but will eventually be shown for all fields once I figure out the layout correctly.
  • options: optional parameters for the field, mostly dependent on the field type. options always take the form "name=value", and are separated by commas (",").

The description and options parts are optional.

Form field types[edit | edit source]

The following types of form fields can be created.

  • textarea: an HTML textarea, e.g. a big multi-line entry area. These are usually used for lots of paragraphs. The following options are supported:
    • rows: number of rows; defaults to 6.
    • cols: number of columns; defaults to 80.
  • text: a one-line text input. Takes these options:
    • size: length of the text input; defaults to 30.
  • checkbox: a yes-no, on-off choice for the user. Takes no options.
  • radio: a group of radio buttons; exclusive choices. Radio button groups take the following options:
    • items: semicolon-separated (";") list of choices for the user. For example, "Blue;Green;Red" will give the user three radio buttons labeled "Blue", "Green", and "Red".
  • select: a drop-down box showing multiple exclusive choices for the user. Select boxes take the following options:
    • items: semicolon-separated (";") list of choices for the user. For example, "Blue;Green;Red" will give the user a drop-down box with three choices, "Blue", "Green", and "Red".

Example[edit | edit source]

First
Create the page MediaWiki:Test-form and paste the following:
template=Test 
title=Test of Form extension 
namePattern={{{Name}}} 
Name|Naming|radio|description|items=Name1;Name2;Name3 
Foobar|Foobar|text|Enter some text 
Second
Create a Template:Test and add:
This is simply a test template which uses one {{{Foobar}}} parameter.  

This template will fill the content of the page, using information entered in the form. In this test example, it is simply a short piece of text defined in the {{{Foobar}}} parameter.

Special:Form/Test
Third
Go to the page Special:Form/Test you will see the form.
Fourth
On the page Test paste:

[[Special:Form/Test]]

Testing the extension

This Test page has three radio buttons l where you pick Name1, Name2 or Name3. You will then see a box labeled "Foobar" where you enter text.

If you type "hello" into the text field, and select the Name2 button, you will create a new page called Name2 which contains the following:

This is simply a test template which uses one hello parameter.

Capitalization matters; if you use foobar in the template, and Foobar in the form, the parameter will not be passed.

Using forms[edit | edit source]

To show a user a form, use the following special-page format:

  Special:Form/Name

Where "Name" is the name of the form. This will load the form definition from "MediaWiki:Name-form", and by default use Template:Name for the output template.

The user can fill in the form fields and hit "save" to save the article. Note that currently no validation is performed; if the user fails to complete a required field, it will be rendered empty.

Translation[edit | edit source]

The user interface strings for this extension are configurable through the same Special:Allmessages page as MediaWiki itself. They all start with "form", and they're no more or less cryptic than MediaWiki's.

Translations to other languages besides English are welcome; please send them along.

Bugs and enhancements[edit | edit source]

Bugs or feature requests can be sent to the author at evan@vinismo.com. The TODO file in this distribution has stuff I think needs to be todone; + marks show things I've already done, and - shows things that are yet to be done.

License[edit | edit source]

Copyright 2007 Vinismo, Inc. (http://vinismo.com/)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

References[edit | edit source]

  1. The software depends on having its code all in the "Form" folder; naming it "Form-Test" or "newextension1" or whatever won't work.
  2. Form definitions use a special idiosyncratic syntax that may change in the future.
  3. You can change this pattern by changing MediaWiki:Formpattern, but note that this will affect all of your forms.

See also[edit | edit source]