Extension:Page Forms/Developers' documentation

From MediaWiki.org
Jump to navigation Jump to search
Page Forms - navigation (viewTemplate:Page Forms navigation)
Basics Main pageExtension:Page Forms (talk) · Download and installationExtension:Page Forms/Download and installation · Quick start guideExtension:Page Forms/Quick start guide · HostingExtension:Page Forms/Hosting · Special pagesExtension:Page Forms/Special pages
Using Page Forms PF and templatesExtension:Page Forms/Page Forms and templates · Defining formsExtension:Page Forms/Defining forms   (Input typesExtension:Page Forms/Input types) · The "Edit with form" tabExtension:Page Forms/The "edit with form" tab · Linking to formsExtension:Page Forms/Linking to forms · Creating query formsExtension:Page Forms/Creating query forms
Resources for help Common problemsExtension:Page Forms/Common problems · Known bugs and planned featuresExtension:Page Forms/Known bugs and planned features · Getting supportExtension:Page Forms/Getting support · Developers' documentationExtension:Page Forms/Developers' documentation · TestingExtension:Page Forms/Testing
About Page Forms Authors and creditsExtension:Page Forms/Authors and credits · Version historyExtension:Page Forms/Version history · Sites that use Page FormsExtension:Page Forms/Sites that use Page Forms · Related extensionsExtension:Page Forms/Related extensions

This page holds information about the Page Forms code, for developers who want to better understand it, modify it, or create code that ties into it.

Code structure[edit]

For the complete listing of files in Page Forms and a short description of each one, see the Code structure page.

To view the code online, including version history for each file, you can go here.

Modifying or improving Page Forms[edit]

There's certainly no shortage of ways to improve Page Forms, including bugs that can be fixed, interface elements that can be improved, or new features that can be added. If you are a developer, or simply a user with some technical skill, any help you can provide in improving the software is welcome: Page Forms would not be at its current state without the contributions of many people.

If you encounter some issue or limitation in Page Forms, and have an interest in fixing it, please either write Yaron, write about it on the talk page, or post a task on Phabricator.

You can also see the current list of Known bugs and planned features.

Defining new inputs[edit]

To create a new input type, you need to define a class for that input, and have it inherit (using the "extends" keyword) from the class PFFormInput, or one of its child classes. There are a number of methods that this class can or should define; the following are the crucial ones:

  • getName() - sets the name of the input within the form definition.
  • getParameters() - defines which parameters can be be passed in to this input, for use within Special:CreateForm.
  • getHtmlText() - defines the HTML to display this input.
  • getResourceModuleNames() - sets the name(s) of the ResourceLoader modules used by this input; if the input contains any JavaScript or CSS, they should be packaged into one or more modules, which are then specified here.

Other methods that can be overridden include the following:

  • getHandledPropertyTypes()
  • getDefaultParameters()
  • canHandleLists()
  • getDefaultCargoTypes()
  • getDefaultCargoTypeLists()
  • getOtherCargoTypesHandled()
  • getOtherCargoTypeListsHandled()

It's useful to look at the existing form input classes to see how all these functions are called.

One note on getting other parameters: let's say that your input is named "myinput", and is called in the form definition in the following way:

{{{field|Some Field|input type=myinput|color=orange|height=200}}}

Within your class's getHtmlText() method, $this->mOtherArgs will contain the "color=orange" and "height=200" key-value pairs, which the function can then use however it wants.

Finally, once your new input is defined, it needs to be registered. You do that by using the 'PageForms::FormPrinterSetup' hook. You need to register with that hook a function that looks like the following:

public static function onFormPrinterSetup( &$pfFormPrinter ) {
    $pfFormPrinter->registerInputType( 'MyInputClass' );
}

Testing[edit]

You can find information on testing the code at the page Extension:Page Forms/Testing.