[MediaWiki-commits] [Gerrit] mediawiki...TextExtracts[master]: Return empty extract for articles in File namespace

2017-07-07 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/363850 )

Change subject: Return empty extract for articles in File namespace
..


Return empty extract for articles in File namespace

Bug: T114418
Change-Id: I2dfccbcf27284ecfdd0669b004151824ece79b73
---
M i18n/en.json
M i18n/qqq.json
M includes/ApiQueryExtracts.php
3 files changed, 18 insertions(+), 6 deletions(-)

Approvals:
  jenkins-bot: Verified
  Jdlrobson: Looks good to me, approved



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 1ASCII 2section levelASCII 
2ASCII 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 @@
$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 @@
break;
}
}
+   if ( $titleInFileNamespace ) {
+   $this->addWarning( 
'apiwarn-textextracts-title-in-file-namespace' );
+   }
}
 
public function getCacheMode( $params ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/363850
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2dfccbcf27284ecfdd0669b004151824ece79b73
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/TextExtracts
Gerrit-Branch: master
Gerrit-Owner: Bmansurov 
Gerrit-Reviewer: Jdlrobson 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...TextExtracts[master]: Return empty extract for articles in File namespace

2017-07-07 Thread Bmansurov (Code Review)
Bmansurov has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/363850 )

Change subject: Return empty extract for articles in File namespace
..

Return empty extract for articles in File namespace

Bug: T114418
Change-Id: I2dfccbcf27284ecfdd0669b004151824ece79b73
---
M includes/ApiQueryExtracts.php
1 file changed, 9 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TextExtracts 
refs/changes/50/363850/1

diff --git a/includes/ApiQueryExtracts.php b/includes/ApiQueryExtracts.php
index 2a84bae..b9803bd 100644
--- a/includes/ApiQueryExtracts.php
+++ b/includes/ApiQueryExtracts.php
@@ -96,10 +96,15 @@
$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 = '';
+   } else {
+   $text = $this->getExtract( $t );
+   $text = $this->truncate( $text );
+   if ( $this->params['plaintext'] ) {
+   $text = $this->doSections( $text );
+   }
}
 
if ( $isXml ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/363850
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2dfccbcf27284ecfdd0669b004151824ece79b73
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TextExtracts
Gerrit-Branch: master
Gerrit-Owner: Bmansurov 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits