Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Adapting wp-mediawiki for bbPress

I tried writing my own plugin–less functionality, really just a simple filter plugin with some preg_replace’s to get the most basic wiki markup, but even this isn’t working. Can anyone see what might be going awry here? I’ve tested all the regular expressions in a plain PHP file, so I know they’re working; it’s putting it all into a plugin and getting bbPress to use it that seems problematic.

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

$mediawiki_filter_params["wiki"] = "http://en.wikipedia.org/wiki/";

/*
Stop editing; actual plugin functionality follows.
*/

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

// LINKS
// Internal links
$content = preg_replace("|()(.*?)()|",
"<a>2</a>",
$content);
// External links with descriptions
$content = preg_replace("|([)(.*?) (.*?)(])|",
"<a>3</a>", $content);
// External links with no description
$count = 1;
$replace = TRUE;
while ($replace) {
$before = $content;
$content = preg_replace("|([)(.*?)(])|",
"<a>[".$count."]</a>",
$content, 1);
if ($before==$content) { $replace = FALSE; }
$count++;
}

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

// RETURN
return $content;
}

add_filter("the_content", "filter_mediawikitext");

Skip to toolbar