From 707e800d20f08dbecfddfa2b2cb0fa92ff293ce7 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Mon, 20 Nov 2006 05:41:53 +0000 Subject: [PATCH] (bug 7889) Don't show "blank edit summary" notice if a redirect autosummary will be added. Do show it if a blanking autosummary will be added, however. Also, I separated out the blanking autosummary thing into its own static function, mainly because I almost included it in this too. I decided not to, but why not keep the function separate, doEdit is huge. --- includes/Article.php | 49 +++++++++++++++++++++++++++++++++---------- includes/EditPage.php | 2 +- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 832d806b6e..a5badb7ec4 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -48,7 +48,7 @@ class Article { $this->mOldId = $oldId; $this->clear(); } - + /** * Tell the page view functions that this view was redirected * from another page on the wiki. @@ -1277,9 +1277,7 @@ class Article { # If no edit comment was given when creating a new page, and what's being # created is a redirect, be smart and fill in a neat auto-comment if ( $flags & EDIT_AUTOSUMMARY && $summary == '' ) { - $rt = Title::newFromRedirect( $text ); - if( is_object( $rt ) ) - $summary = wfMsgForContent( 'autoredircomment', $rt->getPrefixedText() ); + $summary = self::getRedirectAutosummary( $text ); } $text = $this->preSaveTransform( $text ); @@ -1318,13 +1316,7 @@ class Article { if ($flags & EDIT_AUTOSUMMARY && $summary == '') { #If they're blanking an article, note it in the summary. - if ($oldtext!='' && $text=='') { - $summary = wfMsgForContent('autosumm-blank'); - } elseif (strlen($oldtext) > 10 * strlen($text) && strlen($text) < 500) { #Removing more than 90% of the article - global $wgContLang; - $truncatedtext = $wgContLang->truncate($text, max(0, 200 - strlen(wfMsgForContent('autosumm-replace'))), '...'); - $summary = wfMsgForContent('autosumm-replace', $truncatedtext); - } + $summary = self::getBlankingAutosummary( $oldtext, $text ); } $revision = new Revision( array( @@ -2675,6 +2667,41 @@ class Article { $dbr->freeResult( $res ); return $result; } + + /** + * Return an auto-generated summary if the text provided is a redirect. + * + * @param string $text The wikitext to check + * @return string '' or an appropriate summary + */ + public static function getRedirectAutosummary( $text ) { + $rt = Title::newFromRedirect( $text ); + if( is_object( $rt ) ) + return wfMsgForContent( 'autoredircomment', $rt->getPrefixedText() ); + else + return ''; + } + + /** + * Return an auto-generated summary if the new text is much shorter than + * the old text. + * + * @param string $oldtext The previous text of the page + * @param string $text The submitted text of the page + * @return string '' or an appropriate summary + */ + public static function getBlankingAutosummary( $oldtext, $text ) { + if ($oldtext!='' && $text=='') { + return wfMsgForContent('autosumm-blank'); + } elseif (strlen($oldtext) > 10 * strlen($text) && strlen($text) < 500) { + #Removing more than 90% of the article + global $wgContLang; + $truncatedtext = $wgContLang->truncate($text, max(0, 200 - strlen(wfMsgForContent('autosumm-replace'))), '...'); + return wfMsgForContent('autosumm-replace', $truncatedtext); + } else { + return ''; + } + } } ?> diff --git a/includes/EditPage.php b/includes/EditPage.php index 762f0453e2..27e5408f52 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -728,7 +728,7 @@ class EditPage { # Handle the user preference to force summaries here, but not for null edits if( $this->section != 'new' && !$this->allowBlankSummary && $wgUser->getOption( 'forceeditsummary') - && 0 != strcmp($oldtext, $text) ) { + && 0 != strcmp($oldtext, $text) && !Article::getRedirectAutosummary( $text )) { if( md5( $this->summary ) == $this->autoSumm ) { $this->missingSummary = true; wfProfileOut( $fname ); -- 2.20.1