Add two new parameters for editing new pages:
authorErik Moeller <erik@users.mediawiki.org>
Sat, 2 Jul 2005 14:38:15 +0000 (14:38 +0000)
committerErik Moeller <erik@users.mediawiki.org>
Sat, 2 Jul 2005 14:38:15 +0000 (14:38 +0000)
&preload=Page_name => Content of [[Page name]] will be loaded into the
textarea.

&&editintro=Page_name => Content of [[Page name]] will be used instead of
[[MediaWiki:Newarticletext]].

Respects read permissions.

Primary purpose: Customizing of edit pages for newbies, use of custom page
templates.

Possible future changes: Make preload work with &section=new, make editintro
work with any edit.

includes/Article.php
includes/EditPage.php

index 57a1fe0..9b86e91 100644 (file)
@@ -86,16 +86,34 @@ class Article {
                # Get variables from query string :P
                $action = $wgRequest->getText( 'action', 'view' );
                $section = $wgRequest->getText( 'section' );
+               $preload = $wgRequest->getText( 'preload' );
+               $newpagetext = $wgRequest->getText('newpagetext');
 
                $fname =  'Article::getContent';
                wfProfileIn( $fname );
 
                if ( 0 == $this->getID() ) {
                        if ( 'edit' == $action ) {
-                               wfProfileOut( $fname );
-                               return ''; # was "newarticletext", now moved above the box)
+                               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($preloadTitle->userCanRead()) {
+                                               $rev=Revision::newFromTitle($preloadTitle);
+                                               if($rev) {
+                                               return $rev->getText();
+                                               }
+                                       }
+                               }
+                               # Don't preload anything.
+                               # We used to put MediaWiki:Newarticletext here.
+                               # This is now shown above the edit box instead.
+                               return ''; 
                        }
                        wfProfileOut( $fname );
+                       
                        return wfMsg( 'noarticletext' );
                } else {
                        $this->loadContent( $noredir );
index a97558f..8729b94 100644 (file)
@@ -298,7 +298,7 @@ class EditPage {
        function editForm( $formtype, $firsttime = false ) {
                global $wgOut, $wgUser;
                global $wgLang, $wgContLang, $wgParser, $wgTitle;
-               global $wgAllowAnonymousMinor;
+               global $wgAllowAnonymousMinor, $wgRequest;
                global $wgSpamRegex, $wgFilterCallback;
 
                $sk = $wgUser->getSkin();
@@ -308,7 +308,21 @@ class EditPage {
                
 
                if(!$this->mTitle->getArticleID()) { # new article
-                       $wgOut->addWikiText(wfmsg('newarticletext'));
+                       $editintro = $wgRequest->getText( 'editintro' );
+                       $addstandardintro=true;
+                       if($editintro) {
+                               $introtitle=Title::newFromText($editintro);
+                               if($introtitle->userCanRead()) {
+                                       $rev=Revision::newFromTitle($introtitle);
+                                       if($rev) {
+                                               $wgOut->addWikiText($rev->getText());   
+                                               $addstandardintro=false;
+                                       }
+                               }
+                       }
+                       if($addstandardintro) {
+                               $wgOut->addWikiText(wfmsg('newarticletext'));
+                       }
                }
 
                if( $this->mTitle->isTalkPage() ) {