Jump to content

Extension:InterwikiExtracts

From mediawiki.org
MediaWiki extensions manual
InterwikiExtracts
Release status: stable
Implementation Parser function
Description Allows to reuse content from other wikis
Author(s) Sophivorustalk
Latest version 4.5
MediaWiki >= 1.34.0
Database changes No
License GNU General Public License 3.0 or later
Download
Example [1]
Quarterly downloads 3 (Ranked 130th)
Translate the InterwikiExtracts extension if it is available at translatewiki.net
Issues Open tasks · Report a bug

InterwikiExtracts (formerly WikipediaExtracts) is an extension to reuse content from other wikis. It introduces the {{#InterwikiExtract}} parser function that gets content from any wiki defined in your interwiki table. See #Add new wikis for adding new wikis to the interwiki table.

The content can be returned in three formats: HTML, wikitext or plain text. See the #Usage section for details about each format.

Installation

  • Download and move the extracted InterwikiExtracts folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/InterwikiExtracts
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'InterwikiExtracts' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Usage

Add new wikis

To use content from a wiki, it should be loaded in the interwiki table. MediaWiki comes with a bunch of wikis already loaded, including the English Wikipedia and many other Wikimedia projects, so these wikis work out of the box.

To easily add new wikis to the interwiki table, install Extension:Interwiki, visit Special:Interwiki and follow the interface. Be sure to include the URL of the API of the wiki you want to add, or it won't work.

In older versions of the Interwiki extension, it isn't possible to set the URL of the API from the special page, so you must set it directly from the database by running a SQL command like the following: UPDATE interwiki SET iw_api = "https://es.wikipedia.org/w/api.php" WHERE iw_prefix = "eswiki";

If you don't have access to Special:Interwiki, or if you don't want to meddle with the interwiki table, you can also specify the api endpoint directly using the "api" parameter, like so:

{{#InterwikiExtract: Title of the article
| api = https://www.somewiki.org/w/api.php
}}

HTML extracts

By default, the extension gets content from Wikipedia in HTML format. So to get the HTML of any Wikipedia article, just write:

{{#InterwikiExtract:Title of the article}}

If you omit the title, then the title of the current page will be used. If you enter the title of a redirect page, the redirect will be followed and the content of the target article will be returned. If the redirect is to a section of the target article it will extract the full article and not just the section.

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

{{#InterwikiExtract: Title of the article
| section = 0
}}

Wikitext extracts

You can get content in wikitext format with the following syntax:

{{#InterwikiExtract: Title of the article
| format = wiki
}}

The content will be parsed after getting it, which means that any links to pages in your wiki that don't exist yet will show red, including templates!

The wikitext format is unlikely to be useful with content from Wikipedia, but it may be more useful with content from smaller wikis, with less internal links and templates.

Plain text extracts

To get content in plain text format, the target wiki needs to have the TextExtracts extension enabled. All Wikimedia wikis have it enabled, but other wikis may not!

To get content in plain text format, use the following syntax:

{{#InterwikiExtract: Title of the article
| format = text
}}

The available parameters are:

  • section – Title of the section to get (excluding subsections).
  • paragraphs – Number of paragraphs to get
  • intro – Whether or not to get content only before the first section. Any value means true.
  • sentences – Number of sentences to get from the intro. Cannot be used together with the "chars" parameter.
  • chars – Number of characters you get. Cannot be used together with the "sentences" parameter.
  • 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".

Except for 'section' and 'paragraphs', all parameters are based on the API of the Extension:TextExtracts. Check its documentation for more details.

Wrapper templates

Usually you'll want to wrap the parser function in a template, to simplify the syntax and set sensible defaults. For example, if you want to use the extension to get the introductions of Wikipedia articles, you could create a template called Template:WikipediaLead with the following content:

{{#InterwikiExtract: {{{1|{{PAGENAME}}}}}
| wiki = wikipedia
| format = text
| intro = true
}}

Calling this template without any parameters will get the lead section of the Wikipedia article with the same title as the current page. If you want the lead of a different article, you can specify the article through the first parameter, like so:

{{WikipediaLead|Title of the article}}

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

{{#InterwikiExtract: {{{1|{{PAGENAME}}}}}
| wiki = wikipedia
| format = text
| sentences = 1
}}

Calling this template without any parameters will get you the first sentence of the Wikipedia article with the same title as the current page. If you want the first sentence of a different article, you can specify the article through the first parameter.

Crediting the authors

When using this extension, you should always credit the authors of the content you're reusing. You can easily do so by including a link in your wrapper template. For example:

{{#InterwikiExtract: {{{1|{{PAGENAME}}}}}
| wiki = wikipedia
| format = text
| intro = true
}}
[{{fullurl:wikipedia:{{{1|{{PAGENAME}}}}}}} From Wikipedia]

See also