Index: trunk/phase3/includes/DoubleRedirectJob.php |
— | — | @@ -78,11 +78,15 @@ |
79 | 79 | wfDebug( __METHOD__.": skipping, already good\n" ); |
80 | 80 | } |
81 | 81 | |
| 82 | + # Preserve fragment (bug 14904) |
| 83 | + $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(), |
| 84 | + $currentDest->getFragment() ); |
| 85 | + |
82 | 86 | # Fix the text |
83 | 87 | # Remember that redirect pages can have categories, templates, etc., |
84 | 88 | # so the regex has to be fairly general |
85 | 89 | $newText = preg_replace( '/ \[ \[ [^\]]* \] \] /x', |
86 | | - '[[' . $newTitle->getPrefixedText() . ']]', |
| 90 | + '[[' . $newTitle->getFullText() . ']]', |
87 | 91 | $text, 1 ); |
88 | 92 | |
89 | 93 | if ( $newText === $text ) { |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -250,12 +250,13 @@ |
251 | 251 | * |
252 | 252 | * @param int $ns the namespace of the article |
253 | 253 | * @param string $title the unprefixed database key form |
| 254 | + * @param string $fragment The link fragment (after the "#") |
254 | 255 | * @return Title the new object |
255 | 256 | */ |
256 | | - public static function &makeTitle( $ns, $title ) { |
| 257 | + public static function &makeTitle( $ns, $title, $fragment = '' ) { |
257 | 258 | $t = new Title(); |
258 | 259 | $t->mInterwiki = ''; |
259 | | - $t->mFragment = ''; |
| 260 | + $t->mFragment = $fragment; |
260 | 261 | $t->mNamespace = $ns = intval( $ns ); |
261 | 262 | $t->mDbkeyform = str_replace( ' ', '_', $title ); |
262 | 263 | $t->mArticleID = ( $ns >= 0 ) ? -1 : 0; |
— | — | @@ -271,11 +272,12 @@ |
272 | 273 | * |
273 | 274 | * @param int $ns the namespace of the article |
274 | 275 | * @param string $title the database key form |
| 276 | + * @param string $fragment The link fragment (after the "#") |
275 | 277 | * @return Title the new object, or NULL on an error |
276 | 278 | */ |
277 | | - public static function makeTitleSafe( $ns, $title ) { |
| 279 | + public static function makeTitleSafe( $ns, $title, $fragment = '' ) { |
278 | 280 | $t = new Title(); |
279 | | - $t->mDbkeyform = Title::makeName( $ns, $title ); |
| 281 | + $t->mDbkeyform = Title::makeName( $ns, $title, $fragment ); |
280 | 282 | if( $t->secureAndSplit() ) { |
281 | 283 | return $t; |
282 | 284 | } else { |
— | — | @@ -391,13 +393,18 @@ |
392 | 394 | * Make a prefixed DB key from a DB key and a namespace index |
393 | 395 | * @param int $ns numerical representation of the namespace |
394 | 396 | * @param string $title the DB key form the title |
| 397 | + * @param string $fragment The link fragment (after the "#") |
395 | 398 | * @return string the prefixed form of the title |
396 | 399 | */ |
397 | | - public static function makeName( $ns, $title ) { |
| 400 | + public static function makeName( $ns, $title, $fragment = '' ) { |
398 | 401 | global $wgContLang; |
399 | 402 | |
400 | | - $n = $wgContLang->getNsText( $ns ); |
401 | | - return $n == '' ? $title : "$n:$title"; |
| 403 | + $namespace = $wgContLang->getNsText( $ns ); |
| 404 | + $name = $namespace == '' ? $title : "$namespace:$title"; |
| 405 | + if ( strval( $fragment ) != '' ) { |
| 406 | + $name .= '#' . $fragment; |
| 407 | + } |
| 408 | + return $name; |
402 | 409 | } |
403 | 410 | |
404 | 411 | /** |