When calling edit page for nonexistent section, generate error inside of just discard...
authorSteve Sanbeg <sanbeg@users.mediawiki.org>
Wed, 14 Mar 2007 18:20:21 +0000 (18:20 +0000)
committerSteve Sanbeg <sanbeg@users.mediawiki.org>
Wed, 14 Mar 2007 18:20:21 +0000 (18:20 +0000)
RELEASE-NOTES
includes/EditPage.php
includes/Parser.php
includes/SkinTemplate.php
languages/messages/MessagesEn.php
maintenance/nukePage.inc

index c04fc45..42d7c5b 100644 (file)
@@ -268,6 +268,7 @@ lighter making things easier to read.
 * Default tidy.conf has been moved from extensions module into includes.
 * Ignore lonely '''''
 * (bug 3984) Searching in logs by title%
+* (bug 9244) When calling edit page for nonexistent section, generate error inside of just discarding edits, since edit links sometimes go to the wrong place.
 * Private logs can now be created using $wgLogRestrictions
 * (bug 3576) Revisiondelete completed (RSS feeds checked, carries over delete/undelete)
 * Log events, file revisions, archived revisions can be deleted with revisiondelete
index 8aca2d6..7cb3abf 100644 (file)
@@ -67,7 +67,7 @@ class EditPage {
        /**
         * Fetch initial editing page content.
         */
-       private function getContent() {
+       private function getContent( $def_text = '' ) {
                global $wgOut, $wgRequest, $wgParser;
 
                # Get variables from query string :P
@@ -143,7 +143,7 @@ class EditPage {
                                if( $section == 'new' ) {
                                        $text = $this->getPreloadedText( $preload );
                                } else {
-                               $text = $wgParser->getSection( $text, $section );
+                                       $text = $wgParser->getSection( $text, $section, $def_text );
                                }
                        }
                }
@@ -430,7 +430,12 @@ class EditPage {
                # First time through: get contents, set time for conflict
                # checking, etc.
                if ( 'initial' == $this->formtype || $this->firsttime ) {
-                       $this->initialiseForm();
+                       if ($this->initialiseForm() === false) {
+                               $this->noSuchSectionPage();
+                               wfProfileOut( "$fname-business-end" );
+                               wfProfileOut( $fname );
+                               return;
+                       }
                        if( !$this->mTitle->getArticleId() ) 
                                wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1, &$this->mTitle ) );
                }
@@ -871,10 +876,13 @@ class EditPage {
        function initialiseForm() {
                $this->edittime = $this->mArticle->getTimestamp();
                $this->summary = '';
-               $this->textbox1 = $this->getContent();
+               $this->textbox1 = $this->getContent(false);
+               if ($this->textbox1 === false) return false;
+               
                if ( !$this->mArticle->exists() && $this->mArticle->mTitle->getNamespace() == NS_MEDIAWIKI )
                        $this->textbox1 = wfMsgWeirdKey( $this->mArticle->mTitle->getText() );
                wfProxyCheck();
+               return true;
        }
 
        /**
@@ -1470,6 +1478,21 @@ END
                $wgOut->returnToMain( false );
        }
 
+       /**
+        * Creates a basic error page which informs the user that
+        * they have attempted to edit a nonexistant section.
+        */
+       function noSuchSectionPage() {
+               global $wgOut;
+
+               $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
+               $wgOut->setArticleRelated( false );
+
+               $wgOut->addWikiText( wfMsg( 'nosuchsectiontext', $this->section ) );
+               $wgOut->returnToMain( false );
+       }
+
        /**
         * Produce the stock "your edit contains spam" page
         *
index b5f984c..6ac0467 100644 (file)
@@ -4537,24 +4537,6 @@ class Parser
                $uniq = preg_quote( $this->uniqPrefix(), '/' );
                $comment = "(?:$uniq-!--.*?QINU)";
                $secs = preg_split(
-               /*
-                       "/
-                       ^(
-                       (?:$comment|<\/?noinclude>)* # Initial comments will be stripped
-                       (?:
-                               (=+) # Should this be limited to 6?
-                               .+?  # Section title...
-                               \\2  # Ending = count must match start
-                       |
-                               ^
-                               <h([1-6])\b.*?>
-                               .*?
-                               <\/h\\3\s*>
-                       )
-                       (?:$comment|<\/?noinclude>|\s+)* # Trailing whitespace ok
-                       )$
-                       /mix",
-               */
                        "/
                        (
                                ^
@@ -4578,7 +4560,8 @@ class Parser
                                // "Section 0" returns the content before any other section.
                                $rv = $secs[0];
                        } else {
-                               $rv = "";
+                               //track missing section, will replace if found.
+                               $rv = $newtext;
                        }
                } elseif( $mode == "replace" ) {
                        if( $section == 0 ) {
@@ -4633,8 +4616,10 @@ class Parser
                                }
                        }
                }
-               # reinsert stripped tags
-               $rv = trim( $stripState->unstripBoth( $rv ) );
+               if (is_string($rv))
+                       # reinsert stripped tags
+                       $rv = trim( $stripState->unstripBoth( $rv ) );
+
                return $rv;
        }
 
@@ -4647,10 +4632,11 @@ class Parser
         *
         * @param $text String: text to look in
         * @param $section Integer: section number
+        * @param $deftext: default to return if section is not found
         * @return string text of the requested section
         */
-       public function getSection( $text, $section ) {
-               return $this->extractSections( $text, $section, "get" );
+       public function getSection( $text, $section, $deftext='' ) {
+               return $this->extractSections( $text, $section, "get", $deftext );
        }
 
        public function replaceSection( $oldtext, $section, $text ) {
index 7c4cf12..9643b17 100644 (file)
@@ -752,6 +752,7 @@ class SkinTemplate extends Skin {
                                        );
                                }
                        }
+                       
 
                        wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) )   ;
                } else {
index dbe8333..5d26e5b 100644 (file)
@@ -946,6 +946,8 @@ You cannot use the 'email this user' feature unless a valid email address is spe
 'whitelistacctext' => 'To be allowed to create accounts in this wiki you have to [[Special:Userlogin|log]] in and have the appropriate permissions.',
 'confirmedittitle' => 'E-mail confirmation required to edit',
 'confirmedittext' => 'You must confirm your e-mail address before editing pages. Please set and validate your e-mail address through your [[Special:Preferences|user preferences]].',
+'nosuchsectiontitle' => 'No such section',
+'nosuchsectiontext' => "You tried to edit a section that doesn't exist.  Since there is no section \$1, there's no place to save your edit.",
 'loginreqtitle'        => 'Login Required',
 'loginreqlink' => 'log in',
 'loginreqpagetext'     => 'You must $1 to view other pages.',
index 7b17261..804651b 100644 (file)
@@ -73,6 +73,14 @@ function DeleteRevisions( $ids ) {
        $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" );
        
        $dbw->commit(); 
+
+       #TODO: see if this is a "good" page, to decrement that as well.
+       $pages = $dbw->selectField('site_stats', 'ss_total_pages');
+       $pages--;
+       $dbw->update( 'site_stats', 
+                     array('ss_total_pages' => $pages ), 
+                     array( 'ss_row_id' => 1),
+                     __METHOD__ );
        
 }