From f2fbd58aa202b801e4bc7e9ba794333ca3bbec66 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 24 Jul 2008 16:25:19 +0000 Subject: [PATCH] * Fix bug 14904: fragments lost when redirects are fixed. * Add $fragment parameter to Title::makeTitle() and friends --- includes/DoubleRedirectJob.php | 6 +++++- includes/Title.php | 21 ++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/includes/DoubleRedirectJob.php b/includes/DoubleRedirectJob.php index 41f5a2e250..dd6549ce17 100644 --- a/includes/DoubleRedirectJob.php +++ b/includes/DoubleRedirectJob.php @@ -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 ) { diff --git a/includes/Title.php b/includes/Title.php index b64d2c9c87..ad425c5e41 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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; } /** -- 2.20.1