From b6fce440b719882adc46a6f29f245d70e2a67e6f Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Mon, 27 Jun 2016 11:34:28 -0400 Subject: [PATCH] Apply $wgMaxArticleSize more exactly $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 | 22 +++++++++++----------- includes/import/WikiImporter.php | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 2a80ea68d8d..b17a9c13ad0 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -259,9 +259,6 @@ class EditPage { public $tooBig = false; /** @var bool */ - public $kblength = false; - - /** @var bool */ public $missingComment = false; /** @var bool */ @@ -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' => "
\n$1
" ] ); } - 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( "
\n$1\n
", [ 'longpageerror', - $wgLang->formatNum( $this->kblength ), + $wgLang->formatNum( round( $this->contentLength / 1024, 3 ) ), $wgLang->formatNum( $wgMaxArticleSize ) ] ); diff --git a/includes/import/WikiImporter.php b/includes/import/WikiImporter.php index 259d5148701..826bb59caf4 100644 --- a/includes/import/WikiImporter.php +++ b/includes/import/WikiImporter.php @@ -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'] ) ? -- 2.11.4.GIT