Before you start
This "Create an interactive production wiki using PHP" series is designed for PHP application developers who want to to take a run at making their own custom wikis. You'll define everything about the application, from the database all the way up to the wiki markup you want to use. In the final product, you will be able to configure much of the application at a granular level, from who can edit pages to how open the blog really is.
At the end of this tutorial, Part 2 of a five-part series, you will have the basics of your wiki up and running, including user registration, page creation and editing, history tracking, and file uploads. It sounds like a lot, but if you've completed Part 1, you're well over halfway there.
Part 1 of this series draws the big picture. You determine how you want the application to look, flow, work, and behave. You'll design the database and rough-out some scaffolding. Part 2 focuses on the primary wiki development, including defining the markup, tracking changes, and file uploads. In Part 3, you define some users and groups, as well as a way to control access to certain aspects of individual wiki pages and uploaded files. Part 4 deals with a Calendaring and Milestones feature to track tasks, to-dos, and progress against set goals. And in Part 5, you put together an open blog to allow discussion of production topics and concerns.
This tutorial focuses on writing the core code for the wiki engine. With the database in place, your next task is getting the wiki engine up and running, including user creation, signing in, rendering the markup, page creation, file uploads, and more. With these tasks done, your application ("Criki") will take a definite shape. Covered topics include:
- User registration
- Page creation
- Rendering markup
- File uploads
It is assumed that you have some experience working with PHP and MySQL. We won't be doing a lot of deep database tuning, so as long as you know the basic ins and outs, you should be fine. You may find it helpful to download and install phpMyAdmin, a browser-based administration console for your MySQL database.
Before you begin, you need to have an environment in which you can work. The general requirements are reasonably minimal:
- An HTTP server that supports sessions (and preferably mod_rewrite). This tutorial was written using Apache V1.3 with mod_rewrite enabled.
- PHP V4.3.2 or later (including PHP V5). This was written using PHP V5.0.4
- Any version of MySQL from the last few years will do. This was written using MySQL V4.1.15.
You'll also need a database and database user ready for your application to use. The tutorial will provide syntax for creating any necessary tables in MySQL.
Additionally, to save time, we will be developing Criki using a PHP framework called CakePHP. Download CakePHP by visiting CakeForge.org and downloading the latest stable version. This tutorial was written using V1.1.13.
At the end of Part 1, you were given the opportunity to redesign the default layout into something that better suited your own tastes. How did you do? It's OK if you didn't get a chance to work on this particular piece. The source code for this tutorial contains a basic layout that includes links to the various controllers. You will be editing this as the series goes on. Copy the file app/views/layouts/default.thtml from the code archive into your own app/views/layouts/ directory. It should look like Figure 1.
Figure 1. Criki so far
If you did get a chance to work on the layout and didn't link to the various controllers yourself, you can work the following code into your layout wherever you want. The code in Listing 1 will give you a horizontal menu. Feel free to rework it as you see fit to suit your own design.
Listing 1. The horizontal menu
[ <?php echo $html->link('home','/') ?> | <?php echo $html->link('users','/users') ?> | <?php echo $html->link('entries', '/entries') ?> | <?php echo $html->link('entry revisions', '/entry_revisions') ?> | <?php echo $html->link('uploads', '/uploads') ?> | <?php echo $html->link('upload revisions', '/upload_revisions') ?> | <?php echo $html->link('settings', '/settings') ?> ]
Now that you have the layouts taken care of, you can get to work on the core code for Criki. A logical place to start would be with the user registration code.