In the deletion default reasons, calculate how much text to get from the article...
authorRotem Liss <rotem@users.mediawiki.org>
Sun, 4 Nov 2007 16:20:58 +0000 (16:20 +0000)
committerRotem Liss <rotem@users.mediawiki.org>
Sun, 4 Nov 2007 16:20:58 +0000 (16:20 +0000)
RELEASE-NOTES
includes/Article.php

index 75c0537..a401f23 100644 (file)
@@ -130,6 +130,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Remove all commas when parsing float numbers in sorted tables
 * Limit text field of deletion, protection and user rights changes reasons to
   255 characters (already restricted in the database)
+* In the deletion default reasons, calculate how much text to get from the
+  article text, rather than getting 150 characters (which may be too much)
 
 === API changes in 1.12 ===
 
index e5c658d..660220b 100644 (file)
@@ -1930,23 +1930,36 @@ class Article {
                        }
 
                        if( $reason === '' ) {
-                               # comment field=255, let's grep the first 150 to have some user
-                               # space left
-                               global $wgContLang;
-                               $text = $wgContLang->truncate( $text, 150, '...' );
-
-                               # let's strip out newlines
-                               $text = preg_replace( "/[\n\r]/", '', $text );
-
                                if( !$blanked ) {
                                        if( $authorOfAll === false ) {
-                                               $reason = wfMsgForContent( 'excontent', $text );
+                                               $reason = wfMsgForContent( 'excontent', '$1' );
                                        } else {
-                                               $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
+                                               $reason = wfMsgForContent( 'excontentauthor', '$1', $authorOfAll );
                                        }
                                } else {
-                                       $reason = wfMsgForContent( 'exbeforeblank', $text );
+                                       $reason = wfMsgForContent( 'exbeforeblank', '$1' );
+                               }
+
+                               # comment field=255, find the max length of the content from page
+                               # Max content length is max comment length, minus length of the actual
+                               # comment (except for the $1), and minus the possible ... chars
+                               $maxLength = 255 - ( strlen( $reason ) - 2 ) - 3;
+                               if( $maxLength < 0 ) {
+                                       $maxLength = 0;
                                }
+
+                               # let's strip out newlines
+                               $text = preg_replace( "/[\n\r]/", '', $text );
+
+                               # Truncate to max length
+                               global $wgContLang;
+                               $text = $wgContLang->truncate( $text, $maxLength, '...' );
+
+                               # Remove possible unfinished links
+                               $text = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $text );
+
+                               # Add to the reason field
+                               $reason = str_replace( '$1', $text, $reason );
                        }
                }