* (bug 2768) section=new on nonexistent talk page does not add heading
authorErik Moeller <erik@users.mediawiki.org>
Wed, 13 Jul 2005 21:25:30 +0000 (21:25 +0000)
committerErik Moeller <erik@users.mediawiki.org>
Wed, 13 Jul 2005 21:25:30 +0000 (21:25 +0000)
* (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
includes/Article.php
includes/EditPage.php

index 3db158b..0c6b485 100644 (file)
@@ -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 <pre> 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 <center> tags as a block.
 
 === Caveats ===
index 6a5ecaa..e3ac744 100644 (file)
@@ -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 <h1>Heading</h1>, 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();
index 562682a..5c047e9 100644 (file)
@@ -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",