Extension:WikipediaExtracts

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
WikipediaExtracts

Release status:Extension status beta

ImplementationTemplate:Extension#type Tag, Parser function
DescriptionTemplate:Extension#description Adds a parser function that inserts content extracted directly from Wikipedia.
Author(s)Template:Extension#username Felipe Schenonetalk
Latest versionTemplate:Extension#version 1.2 (2016-09-08)
MediaWikiTemplate:Extension#mediawiki 1.25+
PHPTemplate:Extension#php 5.3+
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GNU General Public License 3.0 or later
Download
ExampleTemplate:Extension#example http://en.docu.wiki/Cowspiracy
TagsTemplate:Extension#tags
<WikipediaExtract>
Hooks usedTemplate:Extension#hook
ParserFirstCallInitManual:Hooks/ParserFirstCallInit

Translate the WikipediaExtracts extension if it is available at translatewiki.net

Check usage and version matrix.

IssuesPhabricator

Open tasks · Report a bug

The WikipediaExtracts extension allows you to insert content extracted directly from Wikipedia into any MediaWiki wiki. The content extracted comes in the form of limited wikitext, omitting leading templates, links to files or pages, etc., so it looks great on any wiki.

Installation[edit]

  • Download and place the file(s) in a directory called WikipediaExtracts in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'WikipediaExtracts' );
    
  • YesY Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration[edit]

The only configuration variable of this extension allows you to specify the user agent of your application, like so:

$WikipediaExtractsUserAgent = "CoolTool/1.1 (http://cooltool.org; contact@cooltool.org)";

By default, the user agent will be WikipediaExtracts, but you should use a customized user agent.

Usage[edit]

To insert the content of any Wikipedia article into any page, simply write:

{{#WikipediaExtract:Title of the article}}

If you omit the title, then the title of the current page will be used. You can also use the link to the article:

{{#WikipediaExtract:https://en.wikipedia.org/wiki/Title_of_the_article}}

You can control several aspects of the content you get from Wikipedia by passing parameters to the parser function, using the familiar template syntax. For example:

{{#WikipediaExtract: Title of the article
|sentences = 1
|plaintext = true
}}

The available parameters are:

  • language - The language of the Wikipedia you query ("en", "es", "de", etc.) The default is the content language of your wiki.
  • chars - The number of characters you get. Cannot be used together with the "sentences" parameter.
  • sentences - The number of sentences you get. Cannot be used together with the "chars" parameter.
  • intro - Whether or not to get content only before the first section. Any value means true.
  • plaintext - Whether or not to get content as plain text rather than limited HTML. Any value means true.
  • sectionformat - Either "plain", "wiki" or "raw". Default is "wiki".

Most of these parameters are based on the API of the Extension:TextExtracts, check its documentation for more details.

Templates[edit]

Usually you'll want to wrap the parser function in a template, to simplify the syntax and set sensible defaults. For example, if you plan on using this extension for inserting the introductions of Wikipedia articles, you could create a template called Template:WikipediaIntro with the following content:

{{#WikipediaExtract: {{{1|{{PAGENAME}}}}}
|intro = true
}}

Calling this template without any parameters will insert the introduction of the Wikipedia article with the same title as the page you're currently at. If you want the introduction of a different article, you can pass the desired title through the first parameter, like so:

{{WikipediaIntro|Title of the article}}

Similarly, if you want to use this extension for inserting mostly definitions extracted from Wikipedia, you could create a template called Template:WikipediaDefinition with the following content:

{{#WikipediaExtract: {{{1|{{PAGENAME}}}}}
|sentences = {{{2|1}}}
}}

Calling this template without any parameters will insert the first sentence of the Wikipedia article with the same title as the page you're currently at. If you want the first sentence of a different article, you can pass the desired title through the first parameter, and if you want more than one sentence from the article, you can pass the second parameter, like so:

{{WikipediaDefinition|Title of the article|2}}

Crediting Wikipedia[edit]

When using this extension, you should credit Wikipedia for the extracted content. You can easily do so by including a link to Wikipedia at the bottom of your templates. For example:

{{#WikipediaExtract: {{{1|{{PAGENAME}}}}}
|intro = true
}}
<div style="text-align: right;">Extracted from [{{fullurl:wikipedia:{{{1|{{PAGENAME}}}}}}} Wikipedia]</div>

Or maybe with a "Read more..." message:

{{#WikipediaExtract: {{{1|{{PAGENAME}}}}}
|intro = true
}}
<div style="text-align: right;">[{{fullurl:wikipedia:{{{1|{{PAGENAME}}}}}}} Read more...]</div>

See also[edit]