Skip to:

Re: Adapting wp-mediawiki for bbPress

Success! The Allow Images plugin does nearly the same thing I’m trying to do here. The “pre_post” hook applies the filter when the post is saved, and ideally I’d prefer if the filter were applied when the post is displayed instead, but this can manage all the same. I’ve had to make some changes to accomodate escaping of single quotes, and I’ve expanded the filter to also include aliases for “internal” links, so this will cover MediaWiki’s markup for:

  • Bolding
  • Italicizing
  • Basic internal links

    • With aliases
    • Not including template transclusion, image embedding, or anything fancy like that.

  • External links

    • External links without descriptions are numbered
    • Descriptions are handled

So, fairly basic mockup, but already meeting all the most common usage. Here’s the working plugin in whole as I have it now. I’ve put in a request to include it in Subversion repository with the other plugins.

Plugin Name: MediaWiki Markup for bbPress
Plugin URI:
Description: Add a subset of MediaWiki markups to bbPress
Version: 0.1
Author: Jason Godesky
Author URI:

/* Copyright 2006 Jason Godesky (email :

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

These parameters specify the functioning of this plugin.
Edit accordingly for your specific situation.

# Wiki root; "internal" links will point to the concatenation
# of this root and the link specified.
$mediawiki_filter_params["wiki"] = "";

Stop editing; actual plugin functionality follows.

function bb_mediawikitext($text) {
global $mediawiki_filter_params;
// Bold and italic
$text = preg_replace("|(''''')(.*?)(''''')|",
"<strong><em>2</em></strong>", $text);
// Bold
$text = preg_replace("|(''')(.*?)(''')|",
"<strong>2</strong>", $text);
// Italic
$text = preg_replace("|('')(.*?)('')|",
"<em>2</em>", $text);

// Internal links with aliases
$text = preg_replace("|((.*?)()|",
"<a href=".'"'.$mediawiki_filter_params["wiki"]."2".'"'.">3</a>",
// Internal links without aliases
$text = preg_replace("|()(.*?)()|",
"<a href=".'"'.$mediawiki_filter_params["wiki"]."2".'"'.">2</a>",
// External links with descriptions
$text = preg_replace("|([)(.*?) (.*?)(])|",
"<a href=".'"'."2".'"'.">3</a>", $text);
// External links with no description
$count = 1;
$replace = TRUE;
while ($replace) {
$before = $text;
$text = preg_replace("|([)(.*?)(])|",
"<a href=".'"'."2".'"'.">[".$count."]</a>",
$text, 1);
if ($before==$text) { $replace = FALSE; }

$text = preg_replace("|(======)(.*?)(======)|",
"<h6>2</h6>", $text);
$text = preg_replace("|(=====)(.*?)(=====)|",
"<h5>2</h5>", $text);
$text = preg_replace("|(====)(.*?)(====)|",
"<h4>2</h4>", $text);
$text = preg_replace("|(===)(.*?)(===)|",
"<h3>2</h3>", $text);
$text = preg_replace("|(==)(.*?)(==)|",
"<h2>2</h2>", $text);

return $text;

add_filter('pre_post', 'bb_mediawikitext', 1);


The parameter array is overkill at the moment, but hopefully this plugin will continue to expand, and that array could become much more useful.

Note: Heh, well, it looks like the formatting I needed to get the bold and italics to work got stripped out. What you need to do is to replace ”’ with \’\’\’ — it’s a Perl regex so that basically means ‘ which is what you’ll get from the escaped MySQL string.

Skip to toolbar