DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:wikipediasnippet

This is an old revision of the document!


WikipediaSnippet Plugin

Compatible with DokuWiki

2007-06-26, 2008-05-05, 2009-02-14, 2009-12-25 "Lemming", 2010-11-07 "Anteater", 2011-05-25 "Rincewind", 2012-01-25 "Angua", 2012-10-13 "Adora Belle", "Weatherwax"

plugin Includes a snippet from a Wikipedia article.

Last updated on
2013-04-06
Provides
Syntax
Repository
Source

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Tagged with include, wikipedia

Download and Installation

Download and install the plugin using the Plugin Manager using the URL given above. Refer to Plugins on how to install plugins manually.

Syntax and Usage

The syntax is very simple:

{{wp>Article_Name}}

It's intentional that it's similar to the interwiki link: [[wp>Article_Name]]

The difference is that

  • it includes the first paragraphs of the according Wikipedia page and
  • it uses automatically the language of the wiki (lang)

If you'd like to use a different language than the language of the wiki page, you can add the according language code as another parameter, e.g. the French article for “DokuWiki” would need:

{{wp:fr>DokuWiki}}

{{wp>DokuWiki}} will look like this (in the default template with default configuration):

Configuration

  • snippetLength (default: 0): Number of sentences to show per snippet; leave empty or '0' to show the whole intro section
  • useHtml (default: 1): Display HTML formatting in the snippet? (otherwise display unformatted text only)
  • includeTables (default: 0) will include tables, e.g. the usual infobox. This can make the snippet more interesting, but some infoboxes can also get unproportionately big and will look strange. removed in latest version
  • includeImages (default: 0) will include all images that appear within the first few paragraphs and tables. If you enable this, please set your fetchsize config option, so that external images will automatically be cached by DokuWiki. (The HTML will get cached anyway.) removed in latest version

Changelog

Feedback

Remove disambiguation notice

I realize this is the wrong place but Github is throwing a server error @ the above link:

Many topics have disambiguation pages:
i.e. http://en.wikipedia.org/wiki/Avatar_(computing)
includes before 1st paragraph:

This article is about virtual user representations. For other uses, see avatar (disambiguation).

in the source as:

<div class="dablink">This article is about virtual user representations.  For other uses, see <a href="/wiki/Avatar_(disambiguation)" title="Avatar (disambiguation)">avatar (disambiguation)</a>.</div>

It would be really nice to have these eliminated, as with this plugin we already know that we want this particular page.

–Jeff 2010-04-25

Yes, that makes sense. I just removed the disambiguation link as you suggested in the latest version. — Anika Henke 2010/06/12 17:48

Problems

I've installed the wikipediasnipped plugin, but instead of a text snippet from the WP article, I see only something like:

Object id #94 

The link from the snippet title still forwards to the correct WP article, however.

–Andrew 2010-10-25

It's difficult to help without further information. I just released a new version which includes some (hopefully helpful) error message which will help you to debug the problem. — Anika Henke 2011/05/29 16:24

Usefulness

Is this plugin useful ?

Interwiki

chtiland 2011-04-24

I guess, as with any other plugin: To some people it is useful, to others it isn't. This plugin doesn't do the same as interwiki links. It doesn't just display the link, but also fetches the first paragraph of the article. — Anika Henke 2011/05/29 16:24
To me, this plugin really is useful. I add it at the end of some of my articles on my website (check out here for example) , as a way to dig further on the topics I dealt with. I could just add a link inside the article itself, but I find this plugin more pleasant to the eyes than a simple link, it's more obvious and more knowledge is instantly accessible to the reader! Only thing I'd like to see in a next release is a way to specify the maximal amount of text to retrieve from the Wikipedia page and to include in the snippet, so that a snippet don't take too much space. — Grégory Gutierez 2012/01/10, 11:54

Problem, Language: de-informal

… doesn't work with dokuwiki's custom lang-ids: This http://de-informal.wikipedia.org/ does not exist.

I think this plugin should work according to the interwiki entries: “wp” looks up Englisch entries, “wpde” looks up German entries etc. But it does not. Why?

I just fixed that. It does work like the interwiki entries, but “wpde-informal” obviously doesn't exist, so you cannot really compare it. As “de-informal” is not an officially recognised language code, I implemented it so it gets substituted with “de” (and the same is true for some other non-standard language codes). Please update your plugin to make it work. — Anika Henke 2012/08/19 14:23

Problem with images that start with "//"

I've a problem with pages like http://en.wikipedia.org/wiki/Modal_logic that have an image in the snippet: the image is of the form <img src="//..." that is an absolute link (on Wikipedia it works, of course 1)) but when processed by Dokuwiki it becomes a (broken) relative link.

I propose this fix: to add at line 102 of syntax.php the following code:

  // <img src="//.." becomes <img src="http://.."
  $text = str_replace('src="//', 'src="http://' , $text);

It works! On my own system at least ;-).

Fabrizio

I have fixed this in the latest version. However, I also changed the way the articles are retrieved, which (probably) got rid of images altogether. — Anika Henke 2013/04/06 23:54

A syntax {{wpXX>}} to select a specific Wikipedia site?

Another proposal: I like that the syntax {{wp>page name}} automatically uses the default wiki language: I have a wiki site in italian language and in 99% of the circumstances I would like to show a snippet from an italian Wikipedia page. But in a few circumstances I would like to show a snippet from an English Wikipedia page too!

So my proposal is to add a second syntax {{wpXX>page name}} where XX stands for the language (it/en/de etc..).

I've tried to implement: I've changed the implementation of both the connectTo() and handle() methods with this code:

  function connectTo($mode) {
    $this->Lexer->addSpecialPattern('{{wp(?:\w\w)?>[^}]+}}',$mode,'plugin_wikipediasnippet');
  }
 
  function handle($match, $state, $pos, & $handler) {
    // remove braces  {{....}}
    $match = substr($match, 2, -2);
    // separate the command from the link and set the language
    list($command, $data) = split('>', $match, 2);
    if (strlen($command) == 4) {
      $lang = substr($command, 2, 2);
    } else {
      global $conf;
      $lang = $conf['lang'];
    }
 
    return $lang . ':' . trim($data);
  }

In the render() method I've replaced this code:

  if ($data) {
     global $conf;
     $lang = $conf['lang'];

with this:

  if ($data) {
    $lang, $data) = split(':', $data, 2);

It works fine!

Warning: with this specific implementation this syntax :

{{wpit>page name}}

is the same of:

{{wp>it:page name}}

I thought that this second syntax was nice.

Fabrizio

P.S.: good plugin, really! one of my best favorites

Thanks, I have implemented this, but with a slightly different syntax: {{wp:it>page name}}. — Anika Henke 2013/04/06 23:54

Hello Anika. Relly nice plugin. But this plugin doesn't work in local modi. When i'm using it on localhost (127.0.0.1:8800) with apache there is the error: “Error: Fetching the article from Wikipedia failed. Could not connect to de.wikipedia.org:80 php_network_getaddresses: getaddrinfo failed: Der angegebene Host ist unbekannt (0).” Internet connection is active. What i have to do? Thanks in advance.

–Marcus 2013/07/02

1)
e.g. //upload.wikimedia.org/math/1/2/9/129903ad25d869abdae7434a7a0d0fe4.png
plugin/wikipediasnippet.1372764503.txt.gz · Last modified: 2013-07-02 13:28 by 193.201.183.198

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki