* Added autosummary for new pages with 500 or less characters, and refactor the autos...
authorAndrew Garrett <werdna@users.mediawiki.org>
Mon, 20 Nov 2006 11:48:03 +0000 (11:48 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Mon, 20 Nov 2006 11:48:03 +0000 (11:48 +0000)
RELEASE-NOTES
includes/Article.php
languages/messages/MessagesEn.php

index eea8240..ccbdf8b 100644 (file)
@@ -203,6 +203,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 7970) Use current connection explicitly on Database::getServerVersion
 * (bug 2001) Tables with class="sortable" can now be dynamically sorted via
   JavaScript.
+* Added autosummary for new pages with 500 or less characters, and refactor 
+   the autosummary code so it's all done in one function. doEdit is getting too 
+   big!
 
 
 == Languages updated ==
index a5badb7..726bba0 100644 (file)
@@ -1274,11 +1274,13 @@ class Article {
                $isminor = ( $flags & EDIT_MINOR ) && $wgUser->isAllowed('minoredit');
                $bot = $wgUser->isAllowed( 'bot' ) || ( $flags & EDIT_FORCE_BOT );
 
-               # 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 == '' ) {
-                       $summary = self::getRedirectAutosummary( $text );
-               }
+               $oldtext = $this->getContent();
+               $oldsize = strlen( $oldtext );
+               $newsize = strlen( $text );
+
+               # Provide autosummaries if one is not provided.
+               if ($flags & EDIT_AUTOSUMMARY && $summary == '')
+                       $summary = $this->getAutosummary( $oldtext, $text, $flags );
 
                $text = $this->preSaveTransform( $text );
 
@@ -1293,9 +1295,6 @@ class Article {
                                $userAbort = ignore_user_abort( true );
                        }
 
-                       $oldtext = $this->getContent();
-                       $oldsize = strlen( $oldtext );
-                       $newsize = strlen( $text );
                        $lastRevision = 0;
                        $revisionId = 0;
 
@@ -1313,11 +1312,6 @@ class Article {
                                        wfProfileOut( __METHOD__ );
                                        return false;
                                }
-
-                               if ($flags & EDIT_AUTOSUMMARY && $summary == '') {
-                                       #If they're blanking an article, note it in the summary.
-                                       $summary = self::getBlankingAutosummary( $oldtext, $text );
-                               }
                                
                                $revision = new Revision( array(
                                        'page'       => $this->getId(),
@@ -1358,7 +1352,7 @@ class Article {
                                $this->mTitle->invalidateCache();
                        }
 
-                       if( !$wgDBtransactions ) {
+                       if( !$wgDBransactions ) {
                                ignore_user_abort( $userAbort );
                        }
 
@@ -2688,7 +2682,7 @@ class Article {
         *
         * @param  string $oldtext The previous text of the page
         * @param  string $text    The submitted text of the page
-        * @return string '' or an appropriate summary
+        * @return string An appropriate autosummary, or an empty string.
         */
        public static function getBlankingAutosummary( $oldtext, $text ) {
                if ($oldtext!='' && $text=='') {
@@ -2702,6 +2696,50 @@ class Article {
                        return '';
                }
        }
+
+       /**
+       * Return an applicable autosummary if one exists for the given edit.
+       * @param string $oldtext The previous text of the page.
+       * @param string $newtext The submitted text of the page.
+       * @param bitmask $flags A bitmask of flags submitted for the edit.
+       * @return string An appropriate autosummary, or an empty string.
+       */
+       public static function getAutosummary( $oldtext, $newtext, $flags ) {
+
+               # This code is UGLY UGLY UGLY.
+               # Somebody PLEASE come up with a more elegant way to do it.
+
+               $summary = '';
+
+               #Blanking autosummaries
+               if (!($flags & EDIT_NEW))
+                       $summary = self::getBlankingAutosummary( $oldtext, $newtext );
+
+               if ($summary)
+                       return $summary;
+
+               #New redirect autosummaries.
+               if ( $flags & EDIT_NEW ) {
+                       $summary = self::getRedirectAutosummary( $newtext );
+               }
+
+               if ($summary)
+                       return $summary;
+
+               #New page autosummaries
+               if ($flags & EDIT_NEW && strlen($newtext) <= 500) {
+                       #If they're making a new short article, give its text in the summary.
+                       global $wgContLang;
+                       $truncatedtext = $wgContLang->truncate( $newtext, max( 0, 200 - 
+                               strlen( wfMsgForContent( 'autosumm-shortnew') ) ), '...' );
+                       $summary = wfMsgForContent( 'autosumm-shortnew', $truncatedtext );
+               }
+
+               if ($summary)
+                       return $summary;
+
+               return $summary;
+       }
 }
 
 ?>
index 82daa7f..dc280c9 100644 (file)
@@ -2600,6 +2600,7 @@ Please confirm that really want to recreate this page.',
 'autosumm-blank' => 'Removing all content from page',
 'autosumm-replace' => 'Replacing page with \'$1\'',
 'autoredircomment' => 'Redirecting to [[$1]]', # This should be changed to the new naming convention, but existed beforehand.
+'autosumm-shortnew' => 'New page: $1',
 );
 
 ?>