Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adapting wp-mediawiki for bbPress

  • @jefgodesky

    Member

    There’s been some discussion of integrating WordPress, bbPress and MediaWiki before (“MediaWiki, bbPress, and WordPress integration” from spencerp and “Wiki Integration: WordPress & bbPress” from XXP), but this goes beyond authorization, because once users can log into forums, blogs and wikis with the same login, they naturally assume they can start mixing the wikitext they use on the wiki with forum posts and blog comments.

    Zechs’ MediaWiki Markup for WordPress does precisely that–for WordPress. It seems to be working all right, but it’s not one of the plugins that magically works in bbPress just by dropping it in. I tried that. The general lack of documentation yet on writing plugins for bbPress does not mix well with the lack of documentation for this plugin, written by a fellow who seems to live a few blocks away from me, but for whom English is a second language.

    So, given that I’m obviously not the only person trying to get MediaWiki and the *Presses to play nice, perhaps someone would be willing to point me in the right direction of where I’d get started getting this plugin to work for bbPress as nicely as it does for WordPress?

Viewing 8 replies - 1 through 8 (of 8 total)
  • @jefgodesky

    Member

    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");

    @jefgodesky

    Member

    As far as I can tell, it looks like it’s because “the_content” is not a valid hook for bbPress. Is that true? Does anyone know what hook I should be using instead?

    @nateolson

    Member

    @jefgodesky: I don’t want to sidetrack this thread, but I’m more interested for now in the authorization/integration issue. As you point out in your first post, there have been a number of fragmented discussions on this forum about MediaWiki integration, but it seems like a bit more persistent and focused effort would benefit a lot of people. I’m interested to learn how you’ve fared on this front with your own setup, what you think the best way forward would be for a community-wide effort to develop a more integrated framework, etc.

    As I say, I want this thread to yield something useful for you regarding your question about markup–I can’t offer any help there, so my apologies–so if you’d rather take this up somewhere else, we can start a new thread.

    @jefgodesky

    Member

    I’ve yet to find any way of significantly improving on spencerp’s method, linked above. I am hoping to get them all to share a single login cookie, but I haven’t figured out how to do that yet. As far as a unified user table, though, spencerp’s solution really hits the spot; he also blogged the solution in full here. If I figure out the unified cookie problem, I’ll post it here and on spencerp’s thread

    The markup issue has me really frustrated with bbPress’ lack of documentation, though. I haven’t even been able to find the proper filter by looking through the source code. In terms of functionality, this should be a fairly straightforward filter, but it seems to be completely stuck on so simple a question as what the right hook is called…

    @jefgodesky

    Member

    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.

    <?php
    /*
    Plugin Name: MediaWiki Markup for bbPress
    Plugin URI: https://bbpress.org/forums/topic/713
    Description: Add a subset of MediaWiki markups to bbPress
    Version: 0.1
    Author: Jason Godesky
    Author URI: http://anthropik.com/
    */

    /* Copyright 2006 Jason Godesky (email : jason@anthropik.com)

    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
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    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"] = "http://en.wikipedia.org/wiki/";

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

    function bb_mediawikitext($text) {
    global $mediawiki_filter_params;
    // BASIC FORMATTING
    // 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);

    // LINKS
    // Internal links with aliases
    $text = preg_replace("|((.*?)()|",
    "<a href=".'"'.$mediawiki_filter_params["wiki"]."2".'"'.">3</a>",
    $text);
    // Internal links without aliases
    $text = preg_replace("|()(.*?)()|",
    "<a href=".'"'.$mediawiki_filter_params["wiki"]."2".'"'.">2</a>",
    $text);
    // 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; }
    $count++;
    }

    // HEADINGS
    $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
    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.

    @jefgodesky

    Member

    This is now a full-fledged plugin. It could certainly use some expansion and improvement, but this satisfies my requirements, and I suspect it will satisfy many others’ requirements, as well.

    I’ve decided that I’m OK with two separate logins against the same user table, as spencerp’s solution leaves us with. I’m further integrating them now with OpenID. The VerseLogic WordPress OpenID plugin works perfectly, but I have not yet installed the MediaWiki OpenID extension, which will remain necessary since logging in will still be handled by MediaWiki itself.

    After that, we’ll get to a level of integration I’ve yet to really even think about: user preferences and profiles. My initial thoughts on that are to point the bbPress profiles to the MediaWiki User pages, and develop an extension to display forum user information. Editing preferences might be easier by learning how each program stores that information and writing a whole new script to handle it. I’m certainly open to alternative ideas.

    @nateolson

    Member

    Wow. Who’s the man?! I’ve yet really to dive in and understand all the technical issues in play here–it’s probably beyond me, to be frank–but all the same, your persistence is quite impressive. Many thanks. I think you’re right in guessing that others are going to benefit. Hopefully some of the more capable among them will join forces with you to keep pushing forward the larger integration magic.

    @jefgodesky

    Member

    I hope so, because I’m running into the limits of my abilities and patience quite a bit short of what we’d really like to have.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar