Extensão:TextExtracts
![]() | This extension is maintained by the Reading Web team. |
![]() | For obtaining summaries in production environments, the Page Content Service is recommended and used by Wikimedia products. |
TextExtracts Estado de lançamento: estável |
|
---|---|
Implementação | API |
Descrição | Fornece API com texto simples ou extratos de HTML limitados do conteúdo da página |
Autor(es) | Max Semenik (MaxSemdiscussão) |
MediaWiki | 1.23+ |
PHP | 5.4+ |
Alterações à base de dados | Não |
Licença | GNU - Licença Pública Geral 2.0 ou superior |
Transferência | |
|
|
Traduza a extensão TextExtracts se ela estiver disponível em translatewiki.net | |
Problemas | Tarefas em aberto · Reportar um erro |
A extensão TextExtracts fornece uma API que permite obter texto simples ou extratos de HTML limitado (HTML com conteúdo para algumas classes de CSS removidas) do conteúdo de página.
Transferência
The extension can be retrieved directly from Git [?]:
- Browse code
- Some extensions have tags for stable releases.
- Browse tags
- Select the tag
- Click "snapshot"
- 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).
- Browse branches
- Select a branch name
- Click "Continue"
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/mediawiki/extensions/TextExtracts.git
Instalação
- Exporte e coloque o ficheiro, ou ficheiros, num diretório chamado
TextExtracts
, na sua pastaextensions/
. - Acrescente o seguinte código ao fundo do ficheiro LocalSettings.php:
wfLoadExtension( 'TextExtracts' );
Pronto – Na página especial Special:Version da sua wiki verifique se a extensão foi instalada.
Para utilizadores que tenham o MediaWiki versão 1.26 ou anteriores:
As instruções acima descrevem a nova forma de instalar esta extensão, usando a extensão wfLoadExtension()
.
Se precisar de instalar esta extensão nestas versões anteriores (MediaWiki 1.26 e anteriores), em vez de wfLoadExtension( 'TextExtracts' );
, use:
require_once "$IP/extensions/TextExtracts/TextExtracts.php";
Definições de Configuração
$wgExtractsRemoveClasses
é uma matriz de <tag>, <tag>.class, .<class>, e #<id> que irá ser excluída da extração.- Por exemplo,
$wgExtractsRemoveClasses[] = 'dl';
remove o texto indentado, normalmente utilizado para "hatnotes" de não modelos que não desejados nos resumos. - extension.json defines as predefinições, das quais a classe "noexcerpt" é uma - isto poderá ser adicionado a qualquer modelo para excluí-lo.
- Por exemplo,
$wgExtractsExtendOpenSearchXml
defines se "TextExtracts" deverá fornecer os seus extratos para o módulo da API Opensearch. A predefinição é "false
".
API
extracts | |
---|---|
Devolve texto simples ou extrações de HTML limitadas das páginas indicadas Este módulo não pode ser utilizado como um $generator. |
|
Prefixo | ex |
Permissões requeridas | nenhuma |
Só publicação? | Não |
Ajuda gerada | Atual |
![]() | A documentação a seguir é a saída de Special:ApiHelp/query+extracts, gerada automaticamente pela versão de pré-lançamento do MediaWiki em execução neste site (MediaWiki.org). |
prop=extracts (ex)
- This module requires read rights.
- Source: TextExtracts
- License: GPL-2.0-or-later
Returns plain-text or limited HTML extracts of the given pages.
- exchars
How many characters to return. Actual text returned might be slightly longer.
- Type: integer
- The value must be between 1 and 1,200.
- exsentences
How many sentences to return.
- Type: integer
- The value must be between 1 and 10.
- exlimit
How many extracts to return. (Multiple extracts can only be returned if exintro is set to true.)
- Type: integer or max
- The value must be between 1 and 20.
- 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, raw, wiki
- Default: wiki
- excontinue
When more results are available, use this to continue.
- Type: integer
- Get a 175-character extract
- api.php?action=query&prop=extracts&exchars=175&titles=Therion [open in sandbox]
Outro exemplo
Resultado |
---|
{
"query": {
"pages": {
"9228": {
"pageid": 9228,
"ns": 0,
"title": "Earth",
"extract": "Earth, also called the world and, less frequently, Gaia, (or Terra in some works of science fiction)..."
}
}
}
}
|
Caveats
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 or malformed.
- In plaintext mode:
- citations may not be stripped (see phab:T197266)
- if a paragraph ends with an HTML tag e.g. ref tag, new lines may be dropped (see phab:T201946),
- new lines may be dropped after lists phab:T208132
FAQ
How can I remove content from a page preview/extract?
TextExtracts will strip any element that is marked with the class noexcerpt. This is provided by the global wgExtractsRemoveClasses.
Consulte também
![]() | Este extensão está a ser utilizado em um ou mais projetos da Wikimedia. Isso provavelmente significa que a extensão é estável e funciona bem o suficiente para ser usada por esses sites de alto tráfego. Procure o nome desta extensão nos arquivos de configuração CommonSettings.php e InitialiseSettings.php da Wikimedia para ver onde está instalado. Uma lista completa das extensões instaladas em um determinado wiki pode ser vista na página Special:Version do wiki. |