From b87d714a93fb426b85b0cb7adc17406641240099 Mon Sep 17 00:00:00 2001 From: Leon Weber Date: Sat, 24 May 2008 14:55:54 +0000 Subject: [PATCH] * Refactored Article::getAutosummary(), so there's not a very simple static function called for every autosummary case, instead just include the appropriate code, which makes the whole thing much shorter and cleaner. * Removed Article::getRedirectAutosummary() and Article::getBlankingAutosummary(), which were obsolete then. * Article::getRedirectAutosummary() was called from EditPage::internalAttemptSave() as check if the page being edited is a redirect. Replaced that function call with the one-line routine which was used in the former Article::getRedirectAutosummary() function. We should have this check in some general static function, though. --- includes/Article.php | 92 ++++++++++++++----------------------------- includes/EditPage.php | 7 +++- 2 files changed, 35 insertions(+), 64 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index bc2d594f9c..0cda45638f 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1368,7 +1368,7 @@ class Article { * @return bool success */ function doEdit( $text, $summary, $flags = 0, $baseRevId = false ) { - global $wgUser, $wgDBtransactions; + global $wgUser, $wgDBtransactions, $wgUseAutomaticEditSummaries; wfProfileIn( __METHOD__ ); $good = true; @@ -1398,9 +1398,10 @@ class Article { $oldtext = $this->getContent(); $oldsize = strlen( $oldtext ); - # Provide autosummaries if one is not provided. - if ($flags & EDIT_AUTOSUMMARY && $summary == '') + # Provide autosummaries if one is not provided and autosummaries are enabled. + if( $wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY && $summary == '' ) { $summary = $this->getAutosummary( $oldtext, $text, $flags ); + } $editInfo = $this->prepareTextForEdit( $text ); $text = $editInfo->pst; @@ -3299,41 +3300,6 @@ class Article { 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->getFullText() ); - 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 An appropriate autosummary, or an empty string. - */ - 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 ''; - } - } - /** * Return an applicable autosummary if one exists for the given edit. * @param string $oldtext The previous text of the page. @@ -3342,40 +3308,42 @@ class Article { * @return string An appropriate autosummary, or an empty string. */ public static function getAutosummary( $oldtext, $newtext, $flags ) { - global $wgUseAutomaticEditSummaries; - if ( !$wgUseAutomaticEditSummaries ) return ''; - - # This code is UGLY UGLY UGLY. - # Somebody PLEASE come up with a more elegant way to do it. - - #Redirect autosummaries - $summary = self::getRedirectAutosummary( $newtext ); - - if ($summary) - return $summary; - - #Blanking autosummaries - if (!($flags & EDIT_NEW)) - $summary = self::getBlankingAutosummary( $oldtext, $newtext ); + # Decide what kind of autosummary is needed. - if ($summary) - return $summary; + # Redirect autosummaries + $rt = Title::newFromRedirect( $newtext ); + if( is_object( $rt ) ) { + return wfMsgForContent( 'autoredircomment', $rt->getFullText() ); + } - #New page autosummaries - if ($flags & EDIT_NEW && strlen($newtext)) { - #If they're making a new article, give its text, truncated, in the summary. + # New page autosummaries + if( $flags & EDIT_NEW && strlen( $newtext ) ) { + # If they're making a new article, give its text, truncated, in the summary. global $wgContLang; $truncatedtext = $wgContLang->truncate( str_replace("\n", ' ', $newtext), max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new') ) ), '...' ); - $summary = wfMsgForContent( 'autosumm-new', $truncatedtext ); + return wfMsgForContent( 'autosumm-new', $truncatedtext ); } - if ($summary) - return $summary; + # Blanking autosummaries + if( $oldtext != '' && $newtext == '' ) { + return wfMsgForContent('autosumm-blank'); + } elseif( strlen( $oldtext ) > 10 * strlen( $newtext ) && strlen( $newtext ) < 500) { + # Removing more than 90% of the article + global $wgContLang; + $truncatedtext = $wgContLang->truncate( + $newtext, + max( 0, 200 - strlen( wfMsgForContent( 'autosumm-replace' ) ) ), + '...' + ); + return wfMsgForContent( 'autosumm-replace', $truncatedtext ); + } - return $summary; + # If we reach this point, there's no applicable autosummary for our case, so our + # autosummary is empty. + return ''; } /** diff --git a/includes/EditPage.php b/includes/EditPage.php index a9855ad31c..80c44717f2 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -923,8 +923,11 @@ 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) && !Article::getRedirectAutosummary( $text )) { + if( $this->section != 'new' && !$this->allowBlankSummary && $wgUser->getOption( 'forceeditsummary') && + 0 != strcmp($oldtext, $text) && + !is_object( Title::newFromRedirect( $text ) ) # check if it's not a redirect + ) { + if( md5( $this->summary ) == $this->autoSumm ) { $this->missingSummary = true; wfProfileOut( $fname ); -- 2.20.1