Apply $wgMaxArticleSize more exactly
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 27 Jun 2016 15:34:28 +0000 (11:34 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 27 Jun 2016 15:45:13 +0000 (11:45 -0400)
$wgMaxArticleSize is defined as "maximum article size in kilobytes",
however the way it was being used in WikiImporter and EditPage was
actually allowing 1023 bytes more than the limit. Other code using the
variable was limiting it to the specified value.

Change-Id: I85e4d2146643c5ac65f27cf464a51b28d68440b0

includes/EditPage.php
includes/import/WikiImporter.php

index 2a80ea6..b17a9c1 100644 (file)
@@ -258,9 +258,6 @@ class EditPage {
        /** @var bool */
        public $tooBig = false;
 
-       /** @var bool */
-       public $kblength = false;
-
        /** @var bool */
        public $missingComment = false;
 
@@ -394,6 +391,9 @@ class EditPage {
        /** @var bool */
        protected $edit;
 
+       /** @var bool|int */
+       protected $contentLength = false;
+
        /**
         * @var bool Set in ApiEditPage, based on ContentHandler::allowsDirectApiEditing
         */
@@ -1750,8 +1750,8 @@ class EditPage {
                        return $status;
                }
 
-               $this->kblength = (int)( strlen( $this->textbox1 ) / 1024 );
-               if ( $this->kblength > $wgMaxArticleSize ) {
+               $this->contentLength = strlen( $this->textbox1 );
+               if ( $this->contentLength > $wgMaxArticleSize * 1024 ) {
                        // Error will be displayed by showEditForm()
                        $this->tooBig = true;
                        $status->setResult( false, self::AS_CONTENT_TOO_BIG );
@@ -2038,8 +2038,8 @@ class EditPage {
                }
 
                // Check for length errors again now that the section is merged in
-               $this->kblength = (int)( strlen( $this->toEditText( $content ) ) / 1024 );
-               if ( $this->kblength > $wgMaxArticleSize ) {
+               $this->contentLength = strlen( $this->toEditText( $content ) );
+               if ( $this->contentLength > $wgMaxArticleSize * 1024 ) {
                        $this->tooBig = true;
                        $status->setResult( false, self::AS_MAX_ARTICLE_SIZE_EXCEEDED );
                        return $status;
@@ -2944,15 +2944,15 @@ class EditPage {
                                        'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ] );
                }
 
-               if ( $this->kblength === false ) {
-                       $this->kblength = (int)( strlen( $this->textbox1 ) / 1024 );
+               if ( $this->contentLength === false ) {
+                       $this->contentLength = strlen( $this->textbox1 );
                }
 
-               if ( $this->tooBig || $this->kblength > $wgMaxArticleSize ) {
+               if ( $this->tooBig || $this->contentLength > $wgMaxArticleSize * 1024 ) {
                        $wgOut->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
                                [
                                        'longpageerror',
-                                       $wgLang->formatNum( $this->kblength ),
+                                       $wgLang->formatNum( round( $this->contentLength / 1024, 3 ) ),
                                        $wgLang->formatNum( $wgMaxArticleSize )
                                ]
                        );
index 259d514..826bb59 100644 (file)
@@ -840,7 +840,7 @@ class WikiImporter {
                                'text',
                                ''
                        ] ) ) &&
-                       (int)( strlen( $revisionInfo['text'] ) / 1024 ) > $wgMaxArticleSize
+                       strlen( $revisionInfo['text'] ) > $wgMaxArticleSize * 1024
                ) {
                        throw new MWException( 'The text of ' .
                                ( isset( $revisionInfo['id'] ) ?