From fb65c224cd7eb28af6e40b738c886b53de9707cf Mon Sep 17 00:00:00 2001 From: Erik Moeller Date: Wed, 13 Jul 2005 21:25:30 +0000 Subject: [PATCH] * (bug 2768) section=new on nonexistent talk page does not add heading * (bug ?) show comment subject in preview when using section=new * support preload= parameter for section=new * use section=new edit form when creating a new talk page --- RELEASE-NOTES | 4 ++++ includes/Article.php | 50 ++++++++++++++++++++++++++++--------------- includes/EditPage.php | 22 +++++++++++++++---- 3 files changed, 55 insertions(+), 21 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3db158b6ec..0c6b485480 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -570,6 +570,10 @@ of MediaWiki:Newpagetext) to &action=edit, if page is new. * (bug 2832) [[Special:Listadmins]] redirects to [[Special:Listusers/sysop]] * (bug 785) Parser did not get out of
 with list elements
 * Some shared upload fixes
+* (bug 2768) section=new on nonexistent talk page does not add heading
+* support preload= parameter for section=new
+* show comment subject in preview when using section=new
+* use comment form when creating a new talk page
 * (bug 460) Properly handle 
tags as a block. === Caveats === diff --git a/includes/Article.php b/includes/Article.php index 6a5ecaa484..e3ac744bde 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -94,22 +94,14 @@ class Article { if ( 0 == $this->getID() ) { if ( 'edit' == $action ) { wfProfileOut( $fname ); - # Should we put something in the textarea? - # if &preload=Pagename is set, we try to get - # the revision text and put it in. - if($preload) { - $preloadTitle=Title::newFromText($preload); - if(isset($preloadTitle) && $preloadTitle->userCanRead()) { - $rev=Revision::newFromTitle($preloadTitle); - if($rev) { - return $rev->getText(); - } - } - } - # Don't preload anything. - # We used to put MediaWiki:Newarticletext here. + + # If requested, preload some text. + $text=$this->getPreloadedText($preload); + + # We used to put MediaWiki:Newarticletext here if + # $text was empty at this point. # This is now shown above the edit box instead. - return ''; + return $text; } wfProfileOut( $fname ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); @@ -128,7 +120,8 @@ class Article { if($section!='') { if($section=='new') { wfProfileOut( $fname ); - return ''; + $text=$this->getPreloadedText($preload); + return $text; } # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML @@ -144,6 +137,24 @@ class Article { } } + /** + This function accepts a title string as parameter + ($preload). If this string is non-empty, it attempts + to fetch the current revision text. + */ + function getPreloadedText($preload) { + if($preload) { + $preloadTitle=Title::newFromText($preload); + if(isset($preloadTitle) && $preloadTitle->userCanRead()) { + $rev=Revision::newFromTitle($preloadTitle); + if($rev) { + return $rev->getText(); + } + } + } + return ''; + } + /** * This function returns the text of a section, specified by a number ($section). * A section is text under a heading like == Heading == or

Heading

, or @@ -956,7 +967,7 @@ class Article { * errors at some point. * @private */ - function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false ) { + function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) { global $wgOut, $wgUser; global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer; @@ -967,6 +978,11 @@ class Article { $ns = $this->mTitle->getNamespace(); $ttl = $this->mTitle->getDBkey(); + + # If this is a comment, add the summary as headline + if($comment && $summary!="") { + $text="== {$summary} ==\n\n".$text; + } $text = $this->preSaveTransform( $text ); $isminor = ( $isminor && $wgUser->isLoggedIn() ) ? 1 : 0; $now = wfTimestampNow(); diff --git a/includes/EditPage.php b/includes/EditPage.php index 562682a4a3..5c047e9139 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -306,6 +306,11 @@ class EditPage { // css / js subpages of user pages get a special treatment $isCssJsSubpage = $wgTitle->isCssJsSubpage(); + # If we're creating a discussion page, use the standard comment + # form. + if(!$wgTitle->exists() && $wgTitle->isTalkPage()) { + $this->section='new'; + } if(!$this->mTitle->getArticleID()) { # new article $editintro = $wgRequest->getText( 'editintro' ); @@ -321,7 +326,7 @@ class EditPage { } } if($addstandardintro) { - $wgOut->addWikiText(wfmsg('newarticletext')); + $wgOut->addWikiText(wfmsg('newarticletext')); } } @@ -385,9 +390,11 @@ class EditPage { } if (wfRunHooks('ArticleSave', array(&$this->mArticle, &$wgUser, &$this->textbox1, &$this->summary, &$this->minoredit, &$this->watchthis, NULL))) - { + { + + $isComment=($this->section=='new'); $this->mArticle->insertNewArticle( $this->textbox1, $this->summary, - $this->minoredit, $this->watchthis ); + $this->minoredit, $this->watchthis, false, $isComment); wfRunHooks('ArticleSaveComplete', array(&$this->mArticle, &$wgUser, $this->textbox1, $this->summary, $this->minoredit, $this->watchthis, NULL)); @@ -788,7 +795,14 @@ END $this->textbox1 = $this->mArticle->getContent(true); } - $toparse = $this->textbox1 ; + $toparse = $this->textbox1; + + # If we're adding a comment, we need to show the + # summary as the headline + if($this->section=="new" && $this->summary!="") { + $toparse="== {$this->summary} ==\n\n".$toparse; + } + if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData ; $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ) ."\n\n", -- 2.20.1