From c64d6366f30d92bbba9af4e62efc78f4997b5359 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Mon, 20 Nov 2006 11:48:03 +0000 Subject: [PATCH] * 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\! --- RELEASE-NOTES | 3 ++ includes/Article.php | 68 ++++++++++++++++++++++++------- languages/messages/MessagesEn.php | 1 + 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index eea8240ab7..ccbdf8bece 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/Article.php b/includes/Article.php index a5badb7ec4..726bba06df 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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; + } } ?> diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 82daa7f598..dc280c9eb7 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', ); ?> -- 2.20.1