GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing www.mediawiki.org — Manual:HTMLForm Tutorial - MediaWiki HTMLForm is a powerful and easy helper to build forms within MediaWiki. This tutorial will help Manual:Special pages developers to get started with HTMLForm. (HTMLForm being a front-end helper, it's assumed that you are developing a front-end extension. ie: a special page) The rest of this page is about the basics of creating a generic special page extension called MyForm. This is not directly related to this tutorial, but it won't hurt to show how the extension should look like. At the bottom of the page the Special:MyForm displays "Hello World". Skip the newbie part and directly go to the HTMLForm stuff Otherwise, let's get started... Files and environment
HTMLForm classes are located at Your SpecialPage is in an extension called MyForm. You'll find it by accessing Special:MyForm. Your SpecialPage's front-end code can be at:
MyForm.phpNew extensions should use Extension registration instead.
<?php /** * Necessary description of @file, @authors and license * @FILLME! * Always good to remind that important part */ // Avoid illegal processing, doesn't cost much, but unnecessary on a correct installation if ( !defined( 'MEDIAWIKI' ) ) { die( -1 ); } // Extension Declaration $wgExtensionCredits['specialpage'][] = [ 'path' => __FILE__, 'name' => 'MyForm', 'author' => 'My Name', 'version' => '0.1.0', 'url' => 'https://www.mediawiki.org/', 'descriptionmsg' => 'myf-desc', ]; // A var to ease the referencing of files $dir = __DIR__ . '/'; // i18n file referencing $wgExtensionMessagesFiles['MyForm'] = $dir . 'MyForm.i18n.php'; // View file referencing $wgAutoloadClasses['SpecialMyForm'] = $dir . 'MyForm_body.php'; // SpecialPage referencing $wgSpecialPages['MyForm'] = 'SpecialMyForm'; // The Logic for your extension should be somewhere around here. // NO PHP Closing bracket "? >". This is pure code. LocalSettings.phpDo not forget to install your extension by adding: MyForm.i18n.php
This file will hold all the messages used within your form. Be careful with the messages' IDs, they will be specified later in this tutorial. <?php // Internationalisation for MyForm extension // @FILLME! $messages = []; // English $messages['en'] = [ 'myf-desc' => 'A generic extension used by the HTMLForm tutorial' ]; // Message documentation (Message documentation) $messages['qqq'] = [ 'myf-desc' => '{{desc}}' ]; // French $messages['fr'] = [ 'myf-desc' => 'Une extension générique utilisée par le tutoriel d\'HTMLForm' ]; // More langages… // NO PHP Closing bracket "? >". This is pure code. MyForm_body.phpFinally, the file that interests us the most. <?php /** * Necessary description of @file, @authors and license * @FILLME! * Always good to remind that important part */ // Avoid illegal processing, doesn't cost much, but unnecessary on a correct installation if ( !defined( 'MEDIAWIKI' ) ) { die( -1 ); } // Our SpecialPage class SpecialMyForm extends SpecialPage { public function __construct() { // The first argument must be the name of your special page // A second argument "right" can be added to restrict access to the SpecialPage parent::__construct( 'MyForm' ); } /** * Special page entry point * @param string|null $par */ public function execute( $par ) { $this->setHeaders(); $this->getOutput()->addHTML( 'Hello World' ); } protected function getGroupName() { return 'other'; } } // NO PHP Closing bracket "? >". This is pure code. | ||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |