Eureka Moment Wiki

One eureka moment at the time

User Tools

Site Tools


development:misc:mediawiki_pkugin

A simple MediaWiki plugin

Want to write your own MediaWiki plugin? This is a simple 'Hello World' example. Once you get this, there's no limit

First create a folder for your plugin in /lib/plugins folder

/var/www/lib/plugins/myplugin

Now create a file plugin.info.txt containing the following text

base myplugin
author your name
email your email
date 2013-12-20
name plugin name with out spaces
desc plugin name with spaces
url support url

Create a syntax subfolder

/var/www/lib/plugins/myplugin/syntax

and create a php file with the following code

/**
* DokuWiki Plugin myplugin (Syntax Component)
*
* @license 
* @author 
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once DOKU_PLUGIN.'syntax.php';
class syntax_plugin_myplugin_test extends DokuWiki_Syntax_Plugin {
function getType() {
return 'substition';
}
function connectTo($mode) {
$this->Lexer->addSpecialPattern('<myplugin>',$mode,'plugin_myplugin_test');
}
function render($mode, &$renderer, $data) {
if($mode != 'xhtml') return false;
$ren{erer->doc .= "Hello world!";
return true;
}
}
?>

Now you can start using your plugin by adding '<myplugin>' inside DokuWiki document (which will be replaced by your custom html from the plugin)

development/misc/mediawiki_pkugin.txt · Last modified: 2017/12/12 09:22 by tplecko