jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/402832 )
Change subject: Make limit of importable number revisions (file/file page) into
a $wg
......................................................................
Make limit of importable number revisions (file/file page) into a $wg
Bug: T179647
Change-Id: Ib576917e1cd397391ae189fd2ad0427970923e1c
---
M extension.json
M src/Remote/MediaWiki/ApiDetailRetriever.php
2 files changed, 40 insertions(+), 5 deletions(-)
Approvals:
WMDE-Fisch: Looks good to me, approved
jenkins-bot: Verified
diff --git a/extension.json b/extension.json
index 4a4533f..28ac5af 100644
--- a/extension.json
+++ b/extension.json
@@ -90,7 +90,9 @@
"@FileImporterCommentForPostImportRevision": "Text used for the
edit summary of a post import revision.",
"FileImporterCommentForPostImportRevision": "Imported with
FileImporter from $1",
"@FileImporterTextForPostImportRevision": "Text added to the
top of the imported page's wikitext",
- "FileImporterTextForPostImportRevision": "<!--This file was
moved here using FileImporter from $1-->\n"
+ "FileImporterTextForPostImportRevision": "<!--This file was
moved here using FileImporter from $1-->\n",
+ "@FileImporterMaxRevisions": "Maximum number of revisions (file
or text) a file can have in order to be imported.",
+ "FileImporterMaxRevisions": 1000
},
"ResourceModules": {
"ext.FileImporter.Special": {
diff --git a/src/Remote/MediaWiki/ApiDetailRetriever.php
b/src/Remote/MediaWiki/ApiDetailRetriever.php
index da5a251..5c7679c 100644
--- a/src/Remote/MediaWiki/ApiDetailRetriever.php
+++ b/src/Remote/MediaWiki/ApiDetailRetriever.php
@@ -16,10 +16,10 @@
use Message;
use Psr\Log\LoggerInterface;
use Title;
+use MediaWiki\MediaWikiServices;
+use ConfigException;
class ApiDetailRetriever implements DetailRetriever {
-
- const MAX_REVISIONS = 1000;
/**
* @var HttpApiLookup
@@ -41,6 +41,21 @@
*/
private $maxBytes;
+ /**
+ * @var int
+ */
+ private $maxRevisions;
+
+ /**
+ * ApiDetailRetriever constructor.
+ *
+ * @param HttpApiLookup $httpApiLookup
+ * @param HttpRequestExecutor $httpRequestExecutor
+ * @param LoggerInterface $logger
+ * @param int $maxBytes
+ *
+ * @throws ConfigException
+ */
public function __construct(
HttpApiLookup $httpApiLookup,
HttpRequestExecutor $httpRequestExecutor,
@@ -51,6 +66,8 @@
$this->httpRequestExecutor = $httpRequestExecutor;
$this->logger = $logger;
$this->maxBytes = $maxBytes;
+ $services = MediaWikiServices::getInstance();
+ $this->maxRevisions = (int)$services->getMainConfig()->get(
'FileImporterMaxRevisions' );
}
/**
@@ -167,6 +184,8 @@
throw new LocalizedImportException(
'fileimporter-api-badinfo' );
}
+ $this->checkRevisionCount( $sourceUrl, $requestUrl,
$pageInfoData );
+
while ( array_key_exists( 'continue', $requestData ) ) {
$this->getMoreRevisions( $sourceUrl, $apiUrl,
$requestData, $pageInfoData );
}
@@ -234,8 +253,22 @@
array_merge( $pageInfoData['imageinfo'],
$newPageInfoData['imageinfo'] );
}
- if ( count( $pageInfoData['revisions'] ) > self::MAX_REVISIONS
||
- count( $pageInfoData['imageinfo'] ) >
self::MAX_REVISIONS ) {
+ $this->checkRevisionCount( $sourceUrl, $requestUrl,
$pageInfoData );
+ }
+
+ /**
+ * Throws an exception if the number of revisions to be imported exceeds
+ * the maximum revision limit
+ *
+ * @param SourceUrl $sourceUrl
+ * @param $requestUrl
+ * @param $pageInfoData
+ *
+ * @throws LocalizedImportException
+ */
+ private function checkRevisionCount( SourceUrl $sourceUrl, $requestUrl,
$pageInfoData ) {
+ if ( count( $pageInfoData['revisions'] ) > $this->maxRevisions
||
+ count( $pageInfoData['imageinfo'] ) >
$this->maxRevisions ) {
$this->logger->warning(
'Too many revisions were being fetched',
[
--
To view, visit https://gerrit.wikimedia.org/r/402832
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib576917e1cd397391ae189fd2ad0427970923e1c
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/FileImporter
Gerrit-Branch: master
Gerrit-Owner: Andrew-WMDE <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: WMDE-Fisch <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits