Jump to content
TNG Community
thewillistree

Adding Wikipedia links to 'Places'

Recommended Posts

thewillistree

In the 'Places' page is there a way to include a link to the appropriate Wikipedia entry for a place? This would be great so that visitors to the page could read more about the location.

Share this post


Link to post
Share on other sites
Ken Roy

In the 'Places' page is there a way to include a link to the appropriate Wikipedia entry for a place? This would be great so that visitors to the page could read more about the location.

Paul,

You could add it as an external link to the Histories media collection, or create a new Place media collection and add the external link. See my Saint-Jean Joigny page which has both an externally linked Photo and Histories.

Share this post


Link to post
Share on other sites
thewillistree

Paul,

You could add it as an external link to the Histories media collection, or create a new Place media collection and add the external link. See my Saint-Jean Joigny page which has both an externally linked Photo and Histories.

Thanks Ken - the idea of a new media collection sounds most appealing!

Paul

Share this post


Link to post
Share on other sites
Jerome Liebowitz

Or you could add the link simply as a "note," as I have done here.

In the 'Places' page is there a way to include a link to the appropriate Wikipedia entry for a place? This would be great so that visitors to the page could read more about the location.

Share this post


Link to post
Share on other sites
Luke

In the 'Places' page is there a way to include a link to the appropriate Wikipedia entry for a place? This would be great so that visitors to the page could read more about the location.

Hi Paul,

With a slight modification to placesearch.php, you can turn the placename heading into a Wikipedia link. This means it would be generated by php automatically without you having to add something to each link with notes or media.

The php code presumes that you have a standard comma separated placename of the form city, county, state, country. (Actually county is optional.) The code uses the first segment for location and the second to last segment for state/province unless there are only one or two segments. You will have to add USA to any names where that is assumed.

It will properly handle eg.

Goodhue, Goodhue County, Minnesota, USA

Goodhue, Minnesota, USA

Goodhue County, Minnesota, USA

Minnesota, USA

USA

England

London, England

and all of these with two letter state abbreviations

To try it out go to here:

http://www.cousinfolk.net/placesearch.php?...innesota%2C+USA

To modify 'placesearch.php', search for this line of code:

echo tng_DrawHeading( $photostr, $psearchns, "" );
Replace this line with the eight lines below (Note that line 7 is a repeat of the line above)
$citst = explode(",", $psearchns);
$ct = count($citst);
end($citst);
$ct = $ct > 1 ? "," . ($ct > 2 ? prev($citst): current($citst)) : "";
echo "<a href=\"http://en.wikipedia.org/wiki/".
    str_ireplace( " ", "_",$citst[0] . $ct) . "\">";
echo tng_DrawHeading( $photostr, $psearchns, "" );
echo "</a>";

this turns the heading into a Wikipedia link.

I've only tested this on TNG 6.1.3 so let me know if it works on 7.0.

Luke

Share this post


Link to post
Share on other sites
thewillistree

Thanks Luke!

Sounds a fairly simple process - most of my locations are in the UK but I assume this process will work for those as well...

I'll give it a go in the next few days and see if it works!

Hi Paul,

With a slight modification to placesearch.php, you can turn the placename heading into a Wikipedia link. This means it would be generated by php automatically without you having to add something to each link with notes or media.

The php code presumes that you have a standard comma separated placename of the form city, county, state, country. (Actually county is optional.) The code uses the first segment for location and the second to last segment for state/province unless there are only one or two segments. You will have to add USA to any names where that is assumed.

It will properly handle eg.

Goodhue, Goodhue County, Minnesota, USA

Goodhue, Minnesota, USA

Goodhue County, Minnesota, USA

Minnesota, USA

USA

England

London, England

and all of these with two letter state abbreviations

To try it out go to here:

http://www.cousinfolk.net/placesearch.php?...innesota%2C+USA

To modify 'placesearch.php', search for this line of code:

echo tng_DrawHeading( $photostr, $psearchns, "" );
Replace this line with the eight lines below (Note that line 7 is a repeat of the line above)
$citst = explode(",", $psearchns);
$ct = count($citst);
end($citst);
$ct = $ct > 1 ? "," . ($ct > 2 ? prev($citst): current($citst)) : "";
echo "<a href=\"http://en.wikipedia.org/wiki/".
    str_ireplace( " ", "_",$citst[0] . $ct) . "\">";
echo tng_DrawHeading( $photostr, $psearchns, "" );
echo "</a>";

this turns the heading into a Wikipedia link.

I've only tested this on TNG 6.1.3 so let me know if it works on 7.0.

Luke

Share this post


Link to post
Share on other sites
theKiwi

I've only tested this on TNG 6.1.3 so let me know if it works on 7.0.

Another great piece of script changing Luke!!!

It works on TNG 7 also.

However it didn't find a number of my places in New Zealand and Scotland. For example from this page about

"Blackball, West Coast, New Zealand"

http://testing.lisaandroger.com/placesearc...%2C+New+Zealand

its linking to

Blackball,_West_Coast

when the wikipedia article is under

Blackball,_New_Zealand

But this page

http://testing.lisaandroger.com/placesearc...ire%2C+Scotland

doesn't work as the article is under just

Chirnside

rather than either of Chirnside, Scotland, or Chirnside, Berwickshire

Of course I don't know what the answer is - apart from creating a bunch of re-direct pages on Wikipedia so that places can always be found by the same convention of place,_Country for example.

Roger

Share this post


Link to post
Share on other sites
gleehan

Tnx Luke! Works like a charm.

Jerry

Hi Paul,

With a slight modification to placesearch.php, you can turn the placename heading into a Wikipedia link. This means it would be generated by php automatically without you having to add something to each link with notes or media.

The php code presumes that you have a standard comma separated placename of the form city, county, state, country. (Actually county is optional.) The code uses the first segment for location and the second to last segment for state/province unless there are only one or two segments. You will have to add USA to any names where that is assumed.

It will properly handle eg.

Goodhue, Goodhue County, Minnesota, USA

Goodhue, Minnesota, USA

Goodhue County, Minnesota, USA

Minnesota, USA

USA

England

London, England

and all of these with two letter state abbreviations

To try it out go to here:

http://www.cousinfolk.net/placesearch.php?...innesota%2C+USA

To modify 'placesearch.php', search for this line of code:

echo tng_DrawHeading( $photostr, $psearchns, "" );
Replace this line with the eight lines below (Note that line 7 is a repeat of the line above)
$citst = explode(",", $psearchns);
$ct = count($citst);
end($citst);
$ct = $ct > 1 ? "," . ($ct > 2 ? prev($citst): current($citst)) : "";
echo "<a href=\"http://en.wikipedia.org/wiki/".
    str_ireplace( " ", "_",$citst[0] . $ct) . "\">";
echo tng_DrawHeading( $photostr, $psearchns, "" );
echo "</a>";

this turns the heading into a Wikipedia link.

I've only tested this on TNG 6.1.3 so let me know if it works on 7.0.

Luke

Share this post


Link to post
Share on other sites
Luke

Another great piece of script changing Luke!!!

It works on TNG 7 also.

However it didn't find a number of my places in New Zealand and Scotland. For example from this page about

"Blackball, West Coast, New Zealand"

http://testing.lisaandroger.com/placesearc...%2C+New+Zealand

its linking to

Blackball,_West_Coast

when the wikipedia article is under

Blackball,_New_Zealand

But this page

http://testing.lisaandroger.com/placesearc...ire%2C+Scotland

doesn't work as the article is under just

Chirnside

rather than either of Chirnside, Scotland, or Chirnside, Berwickshire

Of course I don't know what the answer is - apart from creating a bunch of re-direct pages on Wikipedia so that places can always be found by the same convention of place,_Country for example.

Roger

Hi all

Thanks for the words of encouragement. I appreciate it.

Roger, for those exceptions you mentioned, I found the best and easiest method was a wikipedia link for each of the individual segments of the placename. At least the user will get to a disambiguation page this way. Then he can find the correct one for himself.

Instructions are the same -- I've added seven more lines of code so if you've already done the first mod copy only the final seven lines below

otherwise

To modify 'placesearch.php', search for this line of code:

echo tng_DrawHeading( $photostr, $psearchns, "" );
Replace this line with the fifteen lines below (Note that line 7 is a repeat of the line above)
$citst = explode(",", $psearchns);
$ct = count($citst);
end($citst);
$ct = $ct > 1 ? "," . ($ct > 2 ? prev($citst): current($citst)) : "";
echo "<a href=\"http://en.wikipedia.org/wiki/".
    str_ireplace( " ", "_",$citst[0] . $ct) . "\">";
echo tng_DrawHeading( $photostr, $psearchns, "" );
echo "</a>";
function wikis($nam,$nu)
{
$nam = trim($nam);
echo " [<a href=\"http://en.wikipedia.org/wiki/".
    str_ireplace( " ", "_",$nam) . "\">". $nam . "</a>] ";
};
array_walk($citst, 'wikis');

this turns the heading into a Wikipedia link and produces a more general wikipedia link for each segment of the placename.

I've only tested this on TNG 6.1.3 so let me know if it works on 7.0.

Luke

Share this post


Link to post
Share on other sites
thewillistree

I've adding the mod but for some reason I'm getting the following error message when I try viewing a place page:

Fatal error: Call to undefined function: str_ireplace() in /home/sites/thewillistree.me.uk/public_html/genealogy/placesearch.php on line 74
Can you help? Paul
Hi all Thanks for the words of encouragement. I appreciate it. Roger, for those exceptions you mentioned, I found the best and easiest method was a wikipedia link for each of the individual segments of the placename. At least the user will get to a disambiguation page this way. Then he can find the correct one for himself. Instructions are the same -- I've added seven more lines of code so if you've already done the first mod copy only the final seven lines below otherwise To modify 'placesearch.php', search for this line of code:
echo tng_DrawHeading( $photostr, $psearchns, "" );
Replace this line with the fifteen lines below (Note that line 7 is a repeat of the line above)
$citst = explode(",", $psearchns);
$ct = count($citst);
end($citst);
$ct = $ct > 1 ? "," . ($ct > 2 ? prev($citst): current($citst)) : "";
echo "<a href=\"http://en.wikipedia.org/wiki/".
    str_ireplace( " ", "_",$citst[0] . $ct) . "\">";
echo tng_DrawHeading( $photostr, $psearchns, "" );
echo "</a>";
function wikis($nam,$nu)
{
$nam = trim($nam);
echo " [<a href=\"http://en.wikipedia.org/wiki/".
    str_ireplace( " ", "_",$nam) . "\">". $nam . "</a>] ";
};
array_walk($citst, 'wikis');

this turns the heading into a Wikipedia link and produces a more general wikipedia link for each segment of the placename.

I've only tested this on TNG 6.1.3 so let me know if it works on 7.0.

Luke

Share this post


Link to post
Share on other sites
Luke

I've adding the mod but for some reason I'm getting the following error message when I try viewing a place page:

Fatal error: Call to undefined function: str_ireplace() in /home/sites/thewillistree.me.uk/public_html/genealogy/placesearch.php on line 74

Can you help?

Paul

Probably your website uses PHP4, not PHP5.

Use 'str_replace' rather than 'str_ireplace' (remove the 'i') in the two places its used. I didn't really need to ignore case for 'replace.'

Does that work?

Luke

Share this post


Link to post
Share on other sites
klaas

This Wiki-link is a nice feature, but as not al places end-up with a proper link in wikipedia, as there are a lot of national wiki's that do have the correct place information, it would be nice to have a mechanisme that uses the countryname, to change the href to the correct national wiki. This gives a better change of succeeding to find a relevant wiki-page.

So for the dutch places I had to change the link in nl.wiki.org, for german places, de.wiki.org would work the best.

Is any-one able to help me on this, as I'm not really a programmer, but would like to use this effectively.

Share this post


Link to post
Share on other sites
Luke

This Wiki-link is a nice feature, but as not al places end-up with a proper link in wikipedia, as there are a lot of national wiki's that do have the correct place information, it would be nice to have a mechanisme that uses the countryname, to change the href to the correct national wiki. This gives a better change of succeeding to find a relevant wiki-page.

So for the dutch places I had to change the link in nl.wiki.org, for german places, de.wiki.org would work the best.

Is any-one able to help me on this, as I'm not really a programmer, but would like to use this effectively.

Hi Klaas,

Thanks for your perspective on Wiki-link.

I'm thinking that the user's lanquage choice would determine which wikipedia to use rather than the country of the placename, at least for those who only know a single language. What do you think about this solution?

The other issue however is a way to change which fields are used from the placename to create the Wiki-link

to match the standard you use for inputting placenames. What's your format?

Right now I use first field and second to last field which for me in the USA is city/town and state unless there are only one or two fields then I take the whole thing which handles many of my out of US names

However, as we all know:

US != WE

I need to know which comma separated fields of the placename make up the wiki entry. These must be relative to the beginning of the name( first, second, third) or end of the name(last,second to last). Hopefully I can think of a way for you to choose the fields with variables.

So if you could give me several examples of placenames as you use them. I can probably make the code more generic.

Luke

Share this post


Link to post
Share on other sites
tmcguire

I'm thinking that the user's lanquage choice would determine which wikipedia to use rather than the country of the placename, at least for those who only know a single language. What do you think about this solution?

If only Googlemaps had this sensible approach instead of a "one size fits all" approach.

It is best to remember that Wikipedia, for example, is written by anybody and everybody. As a result, it can be as wrong as it it is correct.

Regards,

T. McGuire

Share this post


Link to post
Share on other sites
dougcouch

Just a footnote from first attempt at using the initial 8-line code for Wiki place name links:

For me, adding a label just before the place name such as "Wiki Page: " is useful.

Also, adding a target to the href link code, causing the Wiki to open in a new window helps keep my database visitors from flying off several pages lost in Wiki, and then discovering they don't know where the database page is anymore...without using back, back, back, etc.

The resulting code (below) replaced lines 5 & 6 (it may wrap to appear as 3 lines of code):

echo "<font size='2' color='#0000FF'>Wiki Page: </font><a href=\"http://en.wikipedia.org/wiki/".

str_replace( " ", "_",$citst[0] . $ct) . "\" target='_blank'>";

(Substitute whatever size setting and hexidecimal color code you want.)

Thanks for the code examples!

Doug

Share this post


Link to post
Share on other sites
Ken Roy

Just a footnote from first attempt at using the initial 8-line code for Wiki place name links:

For me, adding a label just before the place name such as "Wiki Page: " is useful.

Also, adding a target to the href link code, causing the Wiki to open in a new window helps keep my database visitors from flying off several pages lost in Wiki, and then discovering they don't know where the database page is anymore...without using back, back, back, etc.

The resulting code (below) replaced lines 5 & 6 (it may wrap to appear as 3 lines of code):

echo "<font size='2' color='#0000FF'>Wiki Page: </font><a href=\"http://en.wikipedia.org/wiki/".

str_replace( " ", "_",$citst[0] . $ct) . "\" target='_blank'>";

(Substitute whatever size setting and hexidecimal color code you want.)

Thanks for the code examples!

Doug

TNG Wiki article on Wikipedia Link mod was documented using a separate heading rather than making the Header a link and to also open in separate window

Share this post


Link to post
Share on other sites
majdan

What would be the easiest way to modify this script to replace any instance of "Co." with "County"?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×