Return empty extract for articles in File namespace

Bug: T114418
Change-Id: I2dfccbcf27284ecfdd0669b004151824ece79b73
This commit is contained in:
Baha 2017-07-07 13:05:07 -04:00 committed by jdlrobson
parent 6ffc0a557c
commit 97a25e2183
3 changed files with 18 additions and 6 deletions

View file

@ -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."
}

View file

@ -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."
}

View file

@ -90,16 +90,23 @@ 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;
}
$text = $this->getExtract( $t );
$text = $this->truncate( $text );
if ( $this->params['plaintext'] ) {
$text = $this->doSections( $text );
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 ) {
@ -112,6 +119,9 @@ class ApiQueryExtracts extends ApiQueryBase {
break;
}
}
if ( $titleInFileNamespace ) {
$this->addWarning( 'apiwarn-textextracts-title-in-file-namespace' );
}
}
public function getCacheMode( $params ) {