Extension:TextExtracts

From MediaWiki.org
Jump to: navigation, search
Translate this page; This page contains changes which are not marked for translation.

Other languages:
català • ‎Deutsch • ‎English • ‎español • ‎suomi • ‎français • ‎italiano • ‎日本語 • ‎한국어 • ‎occitan • ‎polski • ‎português • ‎português do Brasil • ‎sicilianu • ‎中文
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
TextExtracts

Release status:Extension status stable

ImplementationTemplate:Extension#type API
DescriptionTemplate:Extension#description Provides API with plain-text or limited HTML extracts of page content
Author(s)Template:Extension#username Max Semenik (MaxSemtalk)
MediaWikiTemplate:Extension#mediawiki 1.23+
PHPTemplate:Extension#php 5.4+
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GNU General Public License 2.0 or later
Download
ParametersTemplate:Extension#parameters
  • $wgExtractsRemoveClasses
  • $wgExtractsExtendOpenSearchXml
Hooks usedTemplate:Extension#hook
OpenSearchXml
ApiOpenSearchSuggestManual:Hooks/ApiOpenSearchSuggest

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

Check usage and version matrix.

IssuesPhabricator

Open tasks · Report a bug

The TextExtracts extension provides an API with allows to retrieve plain-text or limited HTML (HTML with content for some CSS classes removed) extracts of page content.

Download[edit]

The extension can be retrieved directly from Git [?]:

  • Browse code
  • Some extensions have tags for stable releases.
  • Each branch is associated with a past MediaWiki release. There is also a "master" branch containing the latest alpha version (might require an alpha version of MediaWiki).

Extract the snapshot and place it in the extensions/TextExtracts/ directory of your MediaWiki installation.

If you are familiar with git and have shell access to your server, you can also obtain the extension as follows:

cd extensions/
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/TextExtracts.git

Installation[edit]

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

To users running MediaWiki 1.24 or earlier:

The instructions above describe the new way of installing this extension using wfLoadExtension() If you need to install this extension on these earlier versions (MediaWiki 1.24 and earlier), instead of wfLoadExtension( 'TextExtracts' );, you need to use:

require_once "$IP/extensions/TextExtracts/TextExtracts.php";

Configuration settings[edit]

  • $wgExtractsRemoveClasses is an array of <tag>, <tag>.class, .<class>, and #<id> which will be excluded from extraction.
    For example, $wgExtractsRemoveClasses[] = 'dl'; removes indented text, often used for non-templated hatnotes that are not desired in summaries.
    TextExtracts.php defines the defaults, of which the class "noexcerpt" is one - this may be added to any template to exclude it.
  • $wgExtractsExtendOpenSearchXml defines whether TextExtracts should provide its extracts to the opensearch API module. The default is "false".

API[edit]



prop=extracts (ex)

(main | query | extracts)
  • This module requires read rights.
  • Source: TextExtracts
  • License: GPL-2.0+

Returns plain-text or limited HTML extracts of the given pages.

Parameters:
exchars

How many characters to return. Actual text returned might be slightly longer.

The value must be between 1 and 1,200.
Type: integer
exsentences

How many sentences to return.

The value must be between 1 and 10.
Type: integer
exlimit

How many extracts to return. (Multiple extracts can only be returned if exintro is set to true.)

No more than 20 (20 for bots) allowed.
Type: integer or max
Default: 20
exintro

Return only content before the first section.

Type: boolean (details)
explaintext

Return extracts as plain text instead of limited HTML.

Type: boolean (details)
exsectionformat

How to format sections in plaintext mode:

plain
No formatting.
wiki
Wikitext-style formatting (== like this ==).
raw
This module's internal representation (section titles prefixed with <ASCII 1><ASCII 2><section level><ASCII 2><ASCII 1>).
One of the following values: plain, wiki, raw
Default: wiki
excontinue

When more results are available, use this to continue.

Type: integer

Another example


Caveats[edit]

There are various things to be aware of when using the API

  • We do not recommend the usage of `exsentences`. It does not work for HTML extracts and there are many edge cases for which it doesn't exist. For example "Arm. gen. Ing. John Smith was a soldier." will be treated as 4 sentences. We do not plan to fix this.
  • Inline images are stripped from the response (even in HTML mode). This means if you are using the Math extension and using formulae in your lead section they may not appear in the summary output.
  • In HTML mode we cannot guarantee well formed HTML. Resulting HTML may be invalid of malformed.

FAQ[edit]

How can I remove content from a page preview/extract?[edit]

TextExtracts will strip any element that is marked with the class noexcerpt. This is provided by the global wgExtractsRemoveClasses.


See also[edit]