jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/402810 )

Change subject: Check each file revision size against max allowed before 
previewing.
......................................................................


Check each file revision size against max allowed before previewing.

Bug: T182062
Change-Id: I33c89325f802e676e7865f0ba17b539065194f1a
---
M i18n/en.json
M i18n/qqq.json
M src/Remote/MediaWiki/ApiDetailRetriever.php
M src/ServiceWiring.php
4 files changed, 21 insertions(+), 4 deletions(-)

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



diff --git a/i18n/en.json b/i18n/en.json
index a33bf1b..2ad222e 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -48,5 +48,6 @@
        "fileimporter-heading-filehistory": "File history",
        "fileimporter-revision-removed-text": "Suppressed text removed by 
FileImporter.",
        "fileimporter-revision-removed-comment": "Suppressed comment removed by 
FileImporter.",
-       "fileimporter-in-beta": "File import is in beta mode: We tested it 
carefully but it still might have some problems. If you encounter problems, 
please [//www.mediawiki.org/w/index.php?title=Extension_talk:FileImporter 
report them on our help page] - ideally with a step by step way to reproduce 
the problem, so we can understand and fix it."
+       "fileimporter-in-beta": "File import is in beta mode: We tested it 
carefully but it still might have some problems. If you encounter problems, 
please [//www.mediawiki.org/w/index.php?title=Extension_talk:FileImporter 
report them on our help page] - ideally with a step by step way to reproduce 
the problem, so we can understand and fix it.",
+       "fileimporter-filetoolarge": "The file you are currently trying to 
import exceeds the maximum file size limit."
 }
\ No newline at end of file
diff --git a/i18n/qqq.json b/i18n/qqq.json
index a53a0f3..fcd6857 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -51,5 +51,6 @@
        "fileimporter-heading-filehistory": "Heading of the file history on the 
import page.",
        "fileimporter-revision-removed-text": "Text inserted if the original 
text is suppressed.",
        "fileimporter-revision-removed-comment": "Text inserted as a revision 
comment if the original comment is suppressed.",
-       "fileimporter-in-beta": "Text shown when the special page is loaded 
warning the user that the extension is in beta."
+       "fileimporter-in-beta": "Text shown when the special page is loaded 
warning the user that the extension is in beta.",
+       "fileimporter-filetoolarge": "Text shown when a user tries to upload a 
file (or file revision) which exceeds the maximum file size limit."
 }
diff --git a/src/Remote/MediaWiki/ApiDetailRetriever.php 
b/src/Remote/MediaWiki/ApiDetailRetriever.php
index 9ed5ebf..da5a251 100644
--- a/src/Remote/MediaWiki/ApiDetailRetriever.php
+++ b/src/Remote/MediaWiki/ApiDetailRetriever.php
@@ -36,14 +36,21 @@
         */
        private $logger;
 
+       /**
+        * @var int|null
+        */
+       private $maxBytes;
+
        public function __construct(
                HttpApiLookup $httpApiLookup,
                HttpRequestExecutor $httpRequestExecutor,
-               LoggerInterface $logger
+               LoggerInterface $logger,
+               $maxBytes = null
        ) {
                $this->httpApiLookup = $httpApiLookup;
                $this->httpRequestExecutor = $httpRequestExecutor;
                $this->logger = $logger;
+               $this->maxBytes = $maxBytes;
        }
 
        /**
@@ -264,6 +271,12 @@
                                $revisionInfo['sha1'] = sha1( 
$revisionInfo['*'] );
                        }
 
+                       if ( array_key_exists( 'size', $revisionInfo ) && 
$this->maxBytes !== null ) {
+                               if ( $revisionInfo['size'] > $this->maxBytes ) {
+                                       throw new LocalizedImportException( 
'fileimporter-filetoolarge' );
+                               }
+                       }
+
                        /**
                         * Convert from API sha1 format to DB sha1 format.
                         * The conversion can be se inside ApiQueryImageInfo.
diff --git a/src/ServiceWiring.php b/src/ServiceWiring.php
index 5acde84..cfffbfb 100644
--- a/src/ServiceWiring.php
+++ b/src/ServiceWiring.php
@@ -107,13 +107,15 @@
                $httpApiLookup = $services->getService( 
'FileImporterMediaWikiHttpApiLookup' );
                $httpRequestExecutor = $services->getService( 
'FileImporterHttpRequestExecutor' );
                $logger = LoggerFactory::getInstance( 'FileImporter' );
+               $maxFileSize = UploadBase::getMaxUploadSize( 'import' );
 
                $site = new SourceSite(
                        new AnyMediaWikiFileUrlChecker(),
                        new Remote\MediaWiki\ApiDetailRetriever(
                                $httpApiLookup,
                                $httpRequestExecutor,
-                               $logger
+                               $logger,
+                               $maxFileSize
                        ),
                        new Remote\MediaWiki\RemoteApiImportTitleChecker(
                                $httpApiLookup,

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I33c89325f802e676e7865f0ba17b539065194f1a
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/FileImporter
Gerrit-Branch: master
Gerrit-Owner: Andrew-WMDE <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Siebrand <[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

Reply via email to