diff --git a/i18n/en.json b/i18n/en.json index 567f72c..c84dba3 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -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": "exlimit 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." } diff --git a/i18n/qqq.json b/i18n/qqq.json index 66c2d1b..8b86f0e 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -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." } diff --git a/includes/ApiQueryExtracts.php b/includes/ApiQueryExtracts.php index 2a84bae..04e833e 100644 --- a/includes/ApiQueryExtracts.php +++ b/includes/ApiQueryExtracts.php @@ -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 ) {