Tutorial: Sahana Wiki Module

As an exercise to familiarize ourselves with the Sahana framework, we wrote a wiki module.



To follow along, you'll need:

  • A working copy of Sahana
  • An IDE such as Eclipse
  • A MySQL browser such as phpMyAdmin (optional, but helpful)

Set up the database

We'll be storing the articles for our wiki in a database. For our example we need just one table, which we'll call . We will be storing past revisions of articles, so our database needs to take this into account.

Run the following SQL on your database to create the table:

create table wiki_article (
 id mediumint(9) not null auto_increment,
 `name` varchar(64) not null,
 rev_date datetime default null,
 author varchar(60) default null,
 content text,
 primary key (id),
 key `name` (`name`),
 key author (author),
 fulltext key content (content)

You can view this in the phpMyAdmin browser and see the structure of the table it created:


  • id is a unique identifier for a revision of an article.
  • rev_date is the date the revision was submitted.
  • author is the ID of the Sahana user who submitted the revision.
  • content stores the text in the article.

Creating the module

First, make the three files needed: main.inc, menu.inc, and conf.inc.

conf.inc is the simplest file, so do that first:

$conf['mod_wiki_name'] = _("Swikana");
$conf['mod_wiki_menuorder'] = 0;

These two lines are required for every module. Feel free to rename the module. Next, turn to main.inc:

include ($global ['approot']."inc/lib_menu.inc");
function shn_wiki_mainmenu(){
 global $global;
 require_once $global['approot'].'/mod/wiki/menu.inc';
function shn_wiki_default(){
 shn_wiki_showPage("Main Page");
The function delegates to menu.inc for organizational purposes. is the function used to display any wiki page. Make the function:

<source lang=php>

function shn_wiki_showPage($name = null, $rev = null){
 global $global


Build the Wiki