(bug 7889) Don't show "blank edit summary" notice if a redirect autosummary will...
authorAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 20 Nov 2006 05:41:53 +0000 (05:41 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 20 Nov 2006 05:41:53 +0000 (05:41 +0000)
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
includes/EditPage.php

index 832d806..a5badb7 100644 (file)
@@ -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 '';
+               }
+       }
 }
 
 ?>
index 762f045..27e5408 100644 (file)
@@ -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 );