Bug 774: section=new does not jump to the added section after save
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 26 Oct 2004 05:44:54 +0000 (05:44 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 26 Oct 2004 05:44:54 +0000 (05:44 +0000)
includes/EditPage.php

index 552aaa5..1bacbef 100644 (file)
@@ -222,7 +222,11 @@ class EditPage {
                        if ( ! $isConflict ) {
                                # All's well
                                $sectionanchor = '';
-                               if( $this->section != '' ) {
+                               if( $this->section == 'new' ) {
+                                       if( $this->summary != '' ) {
+                                               $sectionanchor = $this->sectionAnchor( $this->summary );
+                                       }
+                               } elseif( $this->section != '' ) {
                                        # Try to get a section anchor from the section source, redirect to edited section if header found
                                        # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded
                                        # for duplicate heading checking and maybe parsing
@@ -231,17 +235,7 @@ class EditPage {
                                        # headline would need to be parsed to improve this
                                        #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
                                        if($hasmatch and strlen($matches[2]) > 0) {
-                                               global $wgInputEncoding;
-                                               $headline = do_html_entity_decode( $matches[2], ENT_COMPAT, $wgInputEncoding );
-                                               # strip out HTML 
-                                               $headline = preg_replace( "/<.*?" . ">/","",$headline );
-                                               $headline = trim( $headline );
-                                               $sectionanchor = '#'.urlencode( str_replace(' ', '_', $headline ) );
-                                               $replacearray = array(
-                                                       '%3A' => ':',
-                                                       '%' => '.'
-                                               );
-                                               $sectionanchor = str_replace(array_keys($replacearray),array_values($replacearray),$sectionanchor);
+                                               $sectionanchor = $this->sectionAnchor( $matches[2] );
                                        }
                                }
        
@@ -652,6 +646,28 @@ htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) .
                return true;
        }
 
+       /**
+        * Format an anchor fragment as it would appear for a given section name
+        * @param string $text
+        * @return string
+        * @access private
+        */
+       function sectionAnchor( $text ) {
+               global $wgInputEncoding;
+               $headline = do_html_entity_decode( $text, ENT_COMPAT, $wgInputEncoding );
+               # strip out HTML 
+               $headline = preg_replace( '/<.*?' . '>/', '', $headline );
+               $headline = trim( $headline );
+               $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
+               $replacearray = array(
+                       '%3A' => ':',
+                       '%' => '.'
+               );
+               return str_replace(
+                       array_keys( $replacearray ),
+                       array_values( $replacearray ),
+                       $sectionanchor );
+       }
 }
 
 ?>