MediaWiki r13070 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r13069‎ | r13070 (on ViewVC)‎ | r13071 >
Date:00:55, 22 February 2006
Author:timstarling
Status:old
Tags:
Comment:
Maximum article size, since max_allowed_packet is too large on wikimedia these days to form an effective limit.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
===================================================================
--- trunk/phase3/includes/EditPage.php	(revision 13069)
+++ trunk/phase3/includes/EditPage.php	(revision 13070)
@@ -24,6 +24,8 @@
 	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 @@
 	 */
 	function attemptSave() {
 		global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut;
+		global $wgMaxArticleSize;
 
 		$fname = 'EditPage::attemptSave';
 		wfProfileIn( $fname );
@@ -486,7 +489,15 @@
 			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 @@
 		$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 @@
 	 *                      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,11 +764,15 @@
 			}
 			$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' );
 		$cols = $wgUser->getOption( 'cols' );
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 13069)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 13070)
@@ -683,6 +683,7 @@
 
 $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
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 13069)
+++ trunk/phase3/RELEASE-NOTES	(revision 13070)
@@ -137,6 +137,7 @@
 * 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 @@
 * 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 ===
Index: trunk/phase3/languages/Messages.php
===================================================================
--- trunk/phase3/languages/Messages.php	(revision 13069)
+++ trunk/phase3/languages/Messages.php	(revision 13070)
@@ -523,6 +523,8 @@
 'longpagewarning' => "<strong>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.</strong>",
+'longpageerror' => "<strong>ERROR: The text you have submitted is $1 kilobytes 
+long, which is longer than the maximum of $2 kilobytes. It cannot be saved.</strong>",
 'readonlywarning' => '<strong>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.</strong>',

Status & tagging log

  • 01:58, 13 October 2010 ^demon (Talk | contribs) changed the status of r13070 [removed: new added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox