Tutorial: Sahana Wiki Module

Line 5: Line 5:
*A working copy of Sahana
*A working copy of Sahana
*An IDE such as Eclipse
*An IDE such as Eclipse
-
*A MySQL browser such as phpMyAdmin (optional, but helpful)
+
*A MySQL browser such as [http://www.phpmyadmin.net/ phpMyAdmin] (optional, but helpful)
=Set up the database=
=Set up the database=

Revision as of 19:42, 6 June 2008

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

Contents

Preparing

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:

Image:wiki_tablestructure.png

  • 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
}

</source>

Build the Wiki