text-highlightning for wikipedia-links

Creating and modifying plugins.
Post Reply
parday_2003
Posts: 3
Joined: Tue Jun 27, 2006 4:23 pm

text-highlightning for wikipedia-links

Post by parday_2003 »

hi
(ohje, auch noch englisch, na dann mal los ;) )

i used the search function but didn't find an accurate answer. i would like to highlight words, e.g. with [(word)]. then they should be transformed automatically to wikipedia-links: http://de.wikipedia.org/[b]word[/b].
is there already a plugin which is able to do, otherwise i think it's really easy to code (but not for me!!! :) )

thanks in advance


edit: a "[?]" as in the glossary plugin would be great
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: text-highlightning for wikipedia-links

Post by garvinhicking »

Hi!

For that, the easist thing would be to use the "Markup: RegexpMarkup" plugin by Rob Astonishen, from the Spartacus repository.

You could then create your custom RegExp file for this. Save it in the "regexps" subdirectory of the plugin, as Wikipedia.php:

Code: Select all

<?php
// Wiki-Reference.
//
$regexpArray = array(
    'SearchArray'=>array(
		"/\[\((.*)\)\]/"
    ),
    'ReplaceArray'=>array(
		'<a href="http://de.wikipedia.org/\\1" target="_blank">\\1</a>' 
    )
); 
You might need to remove the other files in the regexps/ directory, since else they would be also applied and would lead to confusion.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
parday_2003
Posts: 3
Joined: Tue Jun 27, 2006 4:23 pm

Post by parday_2003 »

wow ;)

seems to work ... a bit:

when i write 2 or more words in one line the plugin is overstrained, eg:
[(hallo)] [(fernseher)]
the result is:
hallo)] [(fernseher ..... linked to http://de.wikipedia.org/wiki/hallo)]%20[(fernseher

do you have an answer to this problem?

thanks!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Yes, this is due to the greedy matching of the regexp. Change it to this:

Code: Select all

<?php
// Wiki-Reference.
//
$regexpArray = array(
    'SearchArray'=>array(
		"/\[\((.*)\)\]/U"
    ),
    'ReplaceArray'=>array(
		'<a href="http://de.wikipedia.org/\\1" target="_blank">\\1</a>' 
    )
); 
(Note the added "/U" in the searcharray)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
gregman
Regular
Posts: 91
Joined: Wed Aug 15, 2007 9:32 pm

Post by gregman »

Hi there,

I added this feature as "external wiki source" in the free wiki-links plugin. You can mark the tags with "{[" . I don't know the Markup Plugin but i guess the advantage in the wiki-links plugin ist that you can configure the url and set a specific style in your templates css file. The only thing is that i can't modify the belgium language file ;-) But if anybody is interested in it...

Greg
stm999999999
Regular
Posts: 1531
Joined: Tue Mar 07, 2006 11:25 pm
Location: Berlin, Germany
Contact:

Re: text-highlightning for wikipedia-links

Post by stm999999999 »

garvinhicking wrote:
You could then create your custom RegExp file for this. Save it in the "regexps" subdirectory of the plugin, as Wikipedia.php:
there is already a wikipedia.php in the regexps-folder!

But, to be more compliant to the wiki-syntax these should work, too:

[(Wikipedia-word|another link text)]

for this:

Code: Select all

<?php
// Wiki-Reference.
//
$regexpArray = array(
    'SearchArray'=>array(
		"/\[\((.*)\)\]/U",
		"/\[\((.*|.*)\)\]/U"
    ),
    'ReplaceArray'=>array(
		'<a href="http://de.wikipedia.org/wiki/\\1" target="_blank">\\1</a>',
		'<a href="http://de.wikipedia.org/wiki/\\1" target="_blank">\\2</a>'
    )
);
perhaps it should be taken in the CVS?
Ciao, Stephan
stm999999999
Regular
Posts: 1531
Joined: Tue Mar 07, 2006 11:25 pm
Location: Berlin, Germany
Contact:

Re: text-highlightning for wikipedia-links

Post by stm999999999 »

parday_2003 wrote:
edit: a "[?]" as in the glossary plugin would be great
this should be for what? As a sign "this is a wikipedia-link"?

If yes: Have a look at http://blog.stephan.manske-net.de/ there every wp-link has an wp-icon. Is this a solution for you?
Ciao, Stephan
Post Reply