On TV.com: ANGELINA JOLIE photos

Extend MediaWiki with custom extensions

Tags: Vincent Danen, Wiki, MediaWiki, Linux Tips Newsletter

  • Save
  • Print
  • Recommend
  • 1

Takeaway: Learn to write your own custom extensions for the PHP-based MediaWiki.

MediaWiki is a great PHP-based wiki implementation that is used to power many sites, including Wikipedia. It's quite flexible, very secure, and extremely easy to use. It's also extremely simple to write plugins for it.

Assume for a moment you want to include the contents of an external file in your wiki. The file changes often and the wiki must reflect the current state of the underlying file. You could write a quick extension to handle this. Extensions live in the extensions/ subdirectory and while there are many extensions you can download, if you have a basic understanding of PHP, you can write your own custom extensions that will look seamless on the wiki.

The extension in Listing A will display the contents of the file passed to it via the wiki page (more on that in a moment); the file must be readable by the Web server user.

Keep in mind that this extension could be dangerous if you don't filter the input at all. In this code, we explicitly test to see if $input is one of two files: /var/lib/foo or /tmp/status. If it is neither, the $file variable is not set and remains NULL; If the passed filename is either of the two allowed files, then it is retrieved and returned to MediaWiki to display.

Add the following to LocalSettings.php to include the extension file (assuming it's called plugin_file.php):

include("./extensions/plugin_file.php");

Finally, to use this plugin in MediaWiki itself, create or edit a page in the wiki with the following code:

<file>/tmp/status</file>

We defined <file> as the code to use in the plugin_file.php via the $wgParser->setHook call; we defined it as file with the associated function being renderFile, which we then defined.

As you can see, this is extremely simple, and being able to add your own custom PHP code to a site gives you limitless possibilities of extending your wiki.

Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

  • Save
  • Print
  • Recommend
  • 1

What do you think?

Article Categories

Security
Security Solutions, IT Locksmith
Networking and Communications
E-mail Administration NetNote, Cisco Routers and Switches
CIO and IT Management
Project Management, CIO Issues, Strategies that Scale
Desktops, Laptops & OS
Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
Data Management
Oracle, SQL Server
Servers
Windows NT, Linux NetNote, Windows Server 2003
Career Development
Geek Trivia
Software/Web Development
Web Development Zone, Visual Basic, .NET

Fusion

advertisement
Click Here