mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TextExtracts
synced 2024-11-24 00:04:35 +00:00
Return empty extract for articles in File namespace
Bug: T114418 Change-Id: I2dfccbcf27284ecfdd0669b004151824ece79b73
This commit is contained in:
parent
6ffc0a557c
commit
97a25e2183
|
@ -13,5 +13,6 @@
|
|||
"apihelp-query+extracts-param-sectionformat": "How to format sections in plaintext mode:\n;plain:No formatting.\n;wiki:Wikitext-style formatting (== like this ==).\n;raw:This module's internal representation (section titles prefixed with <ASCII 1><ASCII 2><section level><ASCII 2><ASCII 1>).",
|
||||
"apihelp-query+extracts-example-1": "Get a 175-character extract",
|
||||
"apiwarn-textextracts-limit": "<var>exlimit</var> was too large for a whole article extracts request, lowered to $1.",
|
||||
"apiwarn-textextracts-unsupportedmodel": "$1 has content model $2, which is not supported; returning an empty extract."
|
||||
"apiwarn-textextracts-unsupportedmodel": "$1 has content model $2, which is not supported; returning an empty extract.",
|
||||
"apiwarn-textextracts-title-in-file-namespace": "Extract for a title in File namespace was requested, none returned."
|
||||
}
|
||||
|
|
|
@ -15,5 +15,6 @@
|
|||
"apihelp-query+extracts-param-sectionformat": "{{doc-apihelp-param|query+extracts|sectionformat}}",
|
||||
"apihelp-query+extracts-example-1": "{{doc-apihelp-example|query+extracts}}",
|
||||
"apiwarn-textextracts-limit": "{{doc-apierror}}\n\nParameters:\n* $1 - Limit that will be used",
|
||||
"apiwarn-textextracts-unsupportedmodel": "{{doc-apierror}}\n\nParameters:\n* $1 - Page title\n* $2 - Content model"
|
||||
"apiwarn-textextracts-unsupportedmodel": "{{doc-apierror}}\n\nParameters:\n* $1 - Page title\n* $2 - Content model",
|
||||
"apiwarn-textextracts-title-in-file-namespace": "{{doc-apierror}}\n\nWarning message displayed when an extract for a title in File namespace is requested."
|
||||
}
|
||||
|
|
|
@ -90,17 +90,24 @@ class ApiQueryExtracts extends ApiQueryBase {
|
|||
$titles = array_slice( $titles, $continue, null, true );
|
||||
}
|
||||
$count = 0;
|
||||
$titleInFileNamespace = false;
|
||||
/** @var Title $t */
|
||||
foreach ( $titles as $id => $t ) {
|
||||
if ( ++$count > $limit ) {
|
||||
$this->setContinueEnumParameter( 'continue', $continue + $count - 1 );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( $t->inNamespace( NS_FILE ) ) {
|
||||
$text = '';
|
||||
$titleInFileNamespace = true;
|
||||
} else {
|
||||
$text = $this->getExtract( $t );
|
||||
$text = $this->truncate( $text );
|
||||
if ( $this->params['plaintext'] ) {
|
||||
$text = $this->doSections( $text );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $isXml ) {
|
||||
$fit = $result->addValue( [ 'query', 'pages', $id ], 'extract', [ '*' => $text ] );
|
||||
|
@ -112,6 +119,9 @@ class ApiQueryExtracts extends ApiQueryBase {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if ( $titleInFileNamespace ) {
|
||||
$this->addWarning( 'apiwarn-textextracts-title-in-file-namespace' );
|
||||
}
|
||||
}
|
||||
|
||||
public function getCacheMode( $params ) {
|
||||
|
|
Loading…
Reference in a new issue