Extension:InterwikiExtracts

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
InterwikiExtracts
Release status: beta
Implementation Parser function
Description Reuse content from other wikis
Author(s) Sophivorustalk
Latest version 4.0 (2019-11-01)
MediaWiki 1.25+
PHP 5.5+
Database changes No
License GNU General Public License 3.0 or later
Download
Example https://mediawiki.solutions/Dyslexia
Translate the InterwikiExtracts extension if it is available at translatewiki.net
Check usage and version matrix.
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 (actually, any wiki that has iw_api defined, but most do).

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

Installation[edit]

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

Usage[edit]

HTML[edit]

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[edit]

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[edit]

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:

  • 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".

The 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 want to use the extension to get the introductions of Wikipedia articles, you could create a template called Template:WikipediaIntro with the following content:

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

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

{{WikipediaIntro|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 = {{{2|1}}}
}}

Calling this template without any parameters will get 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, and if you want more than one sentence, you can specify it through the second parameter, like so:

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

Crediting the authors[edit]

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 template. For example:

{{#InterwikiExtract: {{{1|{{PAGENAME}}}}}
|wiki = wikipedia
|format = text
|intro = true
}}
<div style="text-align: right;">[{{fullurl:wikipedia:{{{1|{{PAGENAME}}}}}}} From Wikipedia]</div>

See also[edit]