jefgodesky (@jefgodesky)

Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • @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.

    @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.

    @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

    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

    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?

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

Viewing 6 replies - 1 through 6 (of 6 total)