Merge "Apply $wgMaxArticleSize more exactly"
[lhc/web/wiklou.git] / includes / EditPage.php
index fa5c53d..674cf28 100644 (file)
@@ -260,9 +260,6 @@ class EditPage {
        /** @var bool */
        public $tooBig = false;
 
-       /** @var bool */
-       public $kblength = false;
-
        /** @var bool */
        public $missingComment = false;
 
@@ -396,6 +393,9 @@ class EditPage {
        /** @var bool */
        protected $edit;
 
+       /** @var bool|int */
+       protected $contentLength = false;
+
        /**
         * @var bool Set in ApiEditPage, based on ContentHandler::allowsDirectApiEditing
         */
@@ -1774,8 +1774,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 );
@@ -2062,8 +2062,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;
@@ -2968,15 +2968,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 )
                                ]
                        );