Manual talk:Developing extensions

From MediaWiki.org
Jump to: navigation, search

This section could use a tutorial if anyone feels inclined to write one. --Sjledet 21:57, 22 January 2011 (UTC)

Well, lets start small... How do I Making your extension user configurable? --Dmb 16:18, 22 April 2011 (UTC)

[edit] Canonical extension 'setup' script?

I know different extension types need different extension types require different setup, but I wan't to create a nice 'template' setup script where sections you don't need can be commented out.

<?php
 
// This line should be included for security reasons apparently
if ( !defined( 'MEDIAWIKI' ) ) die();
 
/**
 * It's usual to create a header like this, describing your
 * extension a bit...
 */
 
 
// This is where you 'register' your extension with Special:Version
$wgExtensionCredits['parserhook'][] = array(
        'path' => __FILE__,
        'name' => 'MyExtension',
        'description' => 'an extension that...',
        'author' => 'My Name'
);
 
 
// Register a 'callback' function for your extension in a hook
$wgHooks['ParserFirstCallInit'][] = 'wfParserHook';
 
function wfParserHook( $parser ) {
        // Set a hook in the parser
        $parser->setHook( 'hook' , 'wfMyExtension' );
        return true;
}
 
/**
 * @param string $in The input passed to <hook>
 * @param array $argv The attributes of the <hook>
 * element in array form
 */
function wfParserHookParse( $data, $params, $parser ) {
        if ( !count( $params ) ) {
                return $data;
        } else {
                return '<pre>' . $data . "\n" . print_r( $params, true ) . '</pre>';
        }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox