Topic: Wikipedia markup...?

Hi all;

I wanted to ask is there are any kind of mod which can display the key word in [[..]] and link that key workd to wikipedia?

Ex: i like to link "PUNBB" word to wikipedia then in text area i will type like this [[PUNBB]] and it will be linked to http://en.wikipedia.com/PUNBB

I though the code would look like this:

//    $this->currentItem->body = preg_replace( "/\[\[(.+?)\|(.+?)\]\]/", "<a href=\"http://en.wikipedia.org/wiki/\\1\" target=\"_blank\" title=\"Wikipedia: \\2\">\\2</a>", $this->currentItem->body );
//    $this->currentItem->more = preg_replace( "/\[\[(.+?)\|(.+?)\]\]/", "<a href=\"http://en.wikipedia.org/wiki/\\1\" target=\"_blank\" title=\"Wikipedia: \\2\">\\2</a>", $this->currentItem->more );

    
//    $this->currentItem->body = preg_replace( "/\[\[(.+?)\]\]/", "<a href=\"http://en.wikipedia.org/wiki/\\1\" target=\"_blank\" title=\"Wikipedia: \\1\">\\1</a>", $this->currentItem->body );
//    $this->currentItem->more = preg_replace( "/\[\[(.+?)\]\]/", "<a href=\"http://en.wikipedia.org/wiki/\\1\" target=\"_blank\" title=\"Wikipedia: \\1\">\\1</a>", $this->currentItem->more );
  }
    
    function wikiLink( $text ) {
        $links = preg_match_all( "/(\[\[.+?\]\])/", $text, $wiki, PREG_SET_ORDER );
        
        for( $i=0; $i<$links; $i++ ) {
            $link = preg_match( "/^\[\[(.+?)\]\]$/", $wiki[$i][0], $item );
            //$info .= $item[1];
            $split = explode( "|", $item[1] );
            if ( count($split) == 2 ) {
                $linkage = "<a href=\"http://en.wikipedia.org/wiki/$split[0]\" target=\"_blank\" title=\"Wikipedia: $split[0]\">$split[1]</a>";
            } else {
                $linkage = "<a href=\"http://en.wikipedia.org/wiki/$split[0]\" target=\"_blank\" title=\"Wikipedia: $split[0]\">$split[0]</a>";
            }
            $text = str_replace( $item[0], $linkage, $text );
        }
        return($text);

any idea out there please?

Thanks

I love sky - i love flowers - and i love myself :D

Re: Wikipedia markup...?

That would make quite a nice extension.

Re: Wikipedia markup...?

Just use the code hat's already there for bb-code. Something like [wiki]PUNBB[/wiki] could turn into [PUNBB]

echo "deadram"; echo; fortune;

Re: Wikipedia markup...?

[[string]] is much, much better imho.

Re: Wikipedia markup...?

Add this to the current BBCode arrays:

// find
'#\[\[([^\[]*?)\]\]#e',

// replace
'handle_url_tag(\'http://en.wikipedia.org/wiki/\'.str_replace(" ", "_", \'$1\'), \'$1\')',

Re: Wikipedia markup...?

thanks for replies...

i used like this and it works just cool:

'#\[wiki\](.*?)\[/wiki\]#',
 '<a href="http://en.wikipedia.org/wiki/$1" alt="Wiki" target="_blank">$1</a><img src=http://en.wikipedia.org/wiki/external.png />',
I love sky - i love flowers - and i love myself :D

Re: Wikipedia markup...?

how to use this?

PunnyBunny..

Re: Wikipedia markup...?

In include/parser.php, change

    // Do the more complex BBCodes (also strip excessive whitespace and useless quotes)
    $a = array( '#\[url=("|\'|)(.*?)\\1\]\s*#i',
                '#\[url\]\s*#i',
                '#\s*\[/url\]#i',
                '#\[email=("|\'|)(.*?)\\1\]\s*#i',
                '#\[email\]\s*#i',
                '#\s*\[/email\]#i',
                '#\[img\]\s*(.*?)\s*\[/img\]#is',
                '#\[colou?r=("|\'|)(.*?)\\1\](.*?)\[/colou?r\]#is');

    $b = array( '[url=$2]',
                '[url]',
                '[/url]',
                '[email=$2]',
                '[email]',
                '[/email]',
                '[img]$1[/img]',
                '[color=$2]$3[/color]');

to

    // Do the more complex BBCodes (also strip excessive whitespace and useless quotes)
    $a = array( '#\[url=("|\'|)(.*?)\\1\]\s*#i',
                '#\[url\]\s*#i',
                '#\s*\[/url\]#i',
                '#\[email=("|\'|)(.*?)\\1\]\s*#i',
                '#\[email\]\s*#i',
                '#\s*\[/email\]#i',
                '#\[img\]\s*(.*?)\s*\[/img\]#is',
                '#\[wiki\](.*?)\[/wiki\]#',
                '#\[colou?r=("|\'|)(.*?)\\1\](.*?)\[/colou?r\]#is');

    $b = array( '[url=$2]',
                '[url]',
                '[/url]',
                '[email=$2]',
                '[email]',
                '[/email]',
                '[img]$1[/img]',
                '<a href="http://en.wikipedia.org/wiki/$1" alt="Wiki" target="_blank">$1</a><img src=http://en.wikipedia.org/wiki/external.png />',
                '[color=$2]$3[/color]');

@mystic (and thesaint if you use the above code): target="_blank" is invalid XHTML, I'm not sure if alt is a valid attribute for links but in any case using a title attribute instead of alt would make more sense, and you shouldn't direct link Wikipedia's image.

Looking for a certain modification for your forum? Please take a look here before posting.

Re: Wikipedia markup...?

@pogenwurst
many thanks, works great!

PunnyBunny..

Re: Wikipedia markup...?

guardian34 wrote:

Add this to the current BBCode arrays:

'#\[\[([^\[]*?)\]\]#e',

It seems that snippet, for me, doesn't work. It triggers an error at the $text = preg_replace($pattern, $replace, $text); stage. Using PHP 5.2.1

11

Re: Wikipedia markup...?

remove "e" at the end of the mask

Re: Wikipedia markup...?

Thanks.

Re: Wikipedia markup...?

Thanks, vin100. smile