Merge "Import: Importing no longer accepts too big revisions"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 23 Dec 2015 09:40:13 +0000 (09:40 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 23 Dec 2015 09:40:13 +0000 (09:40 +0000)
includes/Import.php

index 0999931..67f7ba5 100644 (file)
@@ -825,6 +825,30 @@ class WikiImporter {
         * @return bool|mixed
         */
        private function processRevision( $pageInfo, $revisionInfo ) {
+               global $wgMaxArticleSize;
+
+               // Make sure revisions won't violate $wgMaxArticleSize, which could lead to
+               // database errors and instability. Testing for revisions with only listed
+               // content models, as other content models might use serialization formats
+               // which aren't checked against $wgMaxArticleSize.
+               if ( ( !isset( $revisionInfo['model'] ) ||
+                       in_array( $revisionInfo['model'], array(
+                               'wikitext',
+                               'css',
+                               'json',
+                               'javascript',
+                               'text',
+                               ''
+                       ) ) ) &&
+                       (int)( strlen( $revisionInfo['text'] ) / 1024 ) > $wgMaxArticleSize
+               ) {
+                       throw new MWException( 'The text of ' .
+                               ( isset( $revisionInfo['id'] ) ?
+                                       "the revision with ID $revisionInfo[id]" :
+                                       'a revision'
+                               ) . " exceeds the maximum allowable size ($wgMaxArticleSize KB)" );
+               }
+
                $revision = new WikiRevision( $this->config );
 
                if ( isset( $revisionInfo['id'] ) ) {