From aa2bde93b9af71c694c58d9445e2799bfa5b02af Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 22 Feb 2006 00:55:25 +0000 Subject: [PATCH] Maximum article size, since max_allowed_packet is too large on wikimedia these days to form an effective limit. --- RELEASE-NOTES | 3 ++- includes/DefaultSettings.php | 1 + includes/EditPage.php | 35 +++++++++++++++++++++++++++++------ languages/Messages.php | 2 ++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index b435f02311..582a9d80d5 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -137,6 +137,7 @@ Maintenance: * Maintenance script to wipe a page and all revisions from the database * Maintenance script to reassign edits from one user to another * Maintenance script to find and remove links to a given domain (cleanupSpam.php) +* Fix --report interval option for dumpTextPass i18n / Languages: * Partial support for Basque language (from wikipedia and meta) @@ -643,8 +644,8 @@ fully support the editing toolbar, but was found to be too confusing. * Fix explicit s-maxage=0 on raw pages; should help with proxy issues in generated stylesheets... hopefully... * (bug 4685) More fixes for Slovenian project namespace -* Fix --report interval option for dumpTextPass * Fixed and enhanced a little the Live Preview, which had been broken for some time +* Added article size limit, $wgMaxArticleSize === Caveats === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index a11d082ac8..9d526567e3 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -683,6 +683,7 @@ $wgRedirectSources = false; $wgShowIPinHeader = true; # For non-logged in users $wgMaxNameChars = 255; # Maximum number of bytes in username +$wgMaxArticleSize = 2048; # Maximum article size in kilobytes $wgExtraSubtitle = ''; $wgSiteSupportPage = ''; # A page where you users can receive donations diff --git a/includes/EditPage.php b/includes/EditPage.php index f90e13522e..1aad75fc1e 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -24,6 +24,8 @@ class EditPage { var $firsttime; var $lastDelete; var $mTokenOk = true; + var $tooBig = false; + var $kblength = false; # Form values var $save = false, $preview = false, $diff = false; @@ -451,6 +453,7 @@ class EditPage { */ function attemptSave() { global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut; + global $wgMaxArticleSize; $fname = 'EditPage::attemptSave'; wfProfileIn( $fname ); @@ -486,7 +489,15 @@ class EditPage { wfProfileOut( $fname ); return false; } - + $this->kblength = (int)(strlen( $this->textbox1 ) / 1024); + if ( $this->kblength > $wgMaxArticleSize ) { + // Error will be displayed by showEditForm() + $this->tooBig = true; + wfProfileOut( "$fname-checks" ); + wfProfileOut( $fname ); + return true; + } + if ( !$wgUser->isAllowed('edit') ) { if ( $wgUser->isAnon() ) { $this->userNotLoggedInPage(); @@ -641,6 +652,14 @@ class EditPage { $this->textbox1 = $text; $this->section = ''; + // Check for length errors again now that the section is merged in + $this->kblength = (int)(strlen( $text ) / 1024); + if ( $this->kblength > $wgMaxArticleSize ) { + $this->tooBig = true; + wfProfileOut( $fname ); + return true; + } + # update the article here if( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, $this->watchthis, '', $sectionanchor ) ) { @@ -673,7 +692,7 @@ class EditPage { * near the top, for captchas and the like. */ function showEditForm( $formCallback=null ) { - global $wgOut, $wgUser, $wgLang, $wgContLang; + global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize; $fname = 'EditPage::showEditForm'; wfProfileIn( $fname ); @@ -745,10 +764,14 @@ class EditPage { } $wgOut->addWikiText( $notice ); } - - $kblength = (int)(strlen( $this->textbox1 ) / 1024); - if( $kblength > 29 ) { - $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) ) ); + + if ( $this->kblength === false ) { + $this->kblength = (int)(strlen( $this->textbox1 ) / 1024); + } + if ( $this->tooBig || $this->kblength > $wgMaxArticleSize ) { + $wgOut->addWikiText( wfMsg( 'longpageerror', $wgLang->formatNum( $this->kblength ), $wgMaxArticleSize ) ); + } elseif( $this->kblength > 29 ) { + $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength ) ) ); } $rows = $wgUser->getOption( 'rows' ); diff --git a/languages/Messages.php b/languages/Messages.php index cd0e8727ec..e9a810cffe 100644 --- a/languages/Messages.php +++ b/languages/Messages.php @@ -523,6 +523,8 @@ public domain or similar free resource (see $1 for details). 'longpagewarning' => "WARNING: This page is $1 kilobytes long; some browsers may have problems editing pages approaching or longer than 32kb. Please consider breaking the page into smaller sections.", +'longpageerror' => "ERROR: The text you have submitted is $1 kilobytes +long, which is longer than the maximum of $2 kilobytes. It cannot be saved.", 'readonlywarning' => 'WARNING: The database has been locked for maintenance, so you will not be able to save your edits right now. You may wish to cut-n-paste the text into a text file and save it for later.', -- 2.20.1