From a935b935ebd0a5e6cded03b3adea8e97987712c4 Mon Sep 17 00:00:00 2001 From: Rotem Liss Date: Sun, 4 Nov 2007 16:20:58 +0000 Subject: [PATCH] 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), and remove possible unfinished links --- RELEASE-NOTES | 2 ++ includes/Article.php | 35 ++++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 75c0537b05..a401f2395b 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/Article.php b/includes/Article.php index e5c658dcaf..660220b130 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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 ); } } -- 2.20.1