* Fix bug 14904: fragments lost when redirects are fixed.
authorTim Starling <tstarling@users.mediawiki.org>
Thu, 24 Jul 2008 16:25:19 +0000 (16:25 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Thu, 24 Jul 2008 16:25:19 +0000 (16:25 +0000)
* Add $fragment parameter to Title::makeTitle() and friends

includes/DoubleRedirectJob.php
includes/Title.php

index 41f5a2e..dd6549c 100644 (file)
@@ -78,11 +78,15 @@ class DoubleRedirectJob extends Job {
                        wfDebug( __METHOD__.": skipping, already good\n" );
                }
 
+               # Preserve fragment (bug 14904)
+               $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(), 
+                       $currentDest->getFragment() );
+
                # Fix the text
                # Remember that redirect pages can have categories, templates, etc.,
                # so the regex has to be fairly general
                $newText = preg_replace( '/ \[ \[  [^\]]*  \] \] /x', 
-                       '[[' . $newTitle->getPrefixedText() . ']]',
+                       '[[' . $newTitle->getFullText() . ']]',
                        $text, 1 );
 
                if ( $newText === $text ) {
index b64d2c9..ad425c5 100644 (file)
@@ -250,12 +250,13 @@ class Title {
         *
         * @param int $ns the namespace of the article
         * @param string $title the unprefixed database key form
+        * @param string $fragment The link fragment (after the "#")
         * @return Title the new object
         */
-       public static function &makeTitle( $ns, $title ) {
+       public static function &makeTitle( $ns, $title, $fragment = '' ) {
                $t = new Title();
                $t->mInterwiki = '';
-               $t->mFragment = '';
+               $t->mFragment = $fragment;
                $t->mNamespace = $ns = intval( $ns );
                $t->mDbkeyform = str_replace( ' ', '_', $title );
                $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
@@ -271,11 +272,12 @@ class Title {
         *
         * @param int $ns the namespace of the article
         * @param string $title the database key form
+        * @param string $fragment The link fragment (after the "#")
         * @return Title the new object, or NULL on an error
         */
-       public static function makeTitleSafe( $ns, $title ) {
+       public static function makeTitleSafe( $ns, $title, $fragment = '' ) {
                $t = new Title();
-               $t->mDbkeyform = Title::makeName( $ns, $title );
+               $t->mDbkeyform = Title::makeName( $ns, $title, $fragment );
                if( $t->secureAndSplit() ) {
                        return $t;
                } else {
@@ -391,13 +393,18 @@ class Title {
         * Make a prefixed DB key from a DB key and a namespace index
         * @param int $ns numerical representation of the namespace
         * @param string $title the DB key form the title
+        * @param string $fragment The link fragment (after the "#")
         * @return string the prefixed form of the title
         */
-       public static function makeName( $ns, $title ) {
+       public static function makeName( $ns, $title, $fragment = '' ) {
                global $wgContLang;
 
-               $n = $wgContLang->getNsText( $ns );
-               return $n == '' ? $title : "$n:$title";
+               $namespace = $wgContLang->getNsText( $ns );
+               $name = $namespace == '' ? $title : "$namespace:$title";
+               if ( strval( $fragment ) != '' ) {
+                       $name .= '#' . $fragment;
+               }
+               return $name;
        }
 
        /**