r37999 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37998‎ | r37999 | r38000 >
Date:16:25, 24 July 2008
Author:tstarling
Status:old
Tags:
Comment:
* Fix bug 14904: fragments lost when redirects are fixed.
* Add $fragment parameter to Title::makeTitle() and friends
Modified paths:
  • /trunk/phase3/includes/DoubleRedirectJob.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DoubleRedirectJob.php
@@ -78,11 +78,15 @@
7979 wfDebug( __METHOD__.": skipping, already good\n" );
8080 }
8181
 82+ # Preserve fragment (bug 14904)
 83+ $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(),
 84+ $currentDest->getFragment() );
 85+
8286 # Fix the text
8387 # Remember that redirect pages can have categories, templates, etc.,
8488 # so the regex has to be fairly general
8589 $newText = preg_replace( '/ \[ \[ [^\]]* \] \] /x',
86 - '[[' . $newTitle->getPrefixedText() . ']]',
 90+ '[[' . $newTitle->getFullText() . ']]',
8791 $text, 1 );
8892
8993 if ( $newText === $text ) {
Index: trunk/phase3/includes/Title.php
@@ -250,12 +250,13 @@
251251 *
252252 * @param int $ns the namespace of the article
253253 * @param string $title the unprefixed database key form
 254+ * @param string $fragment The link fragment (after the "#")
254255 * @return Title the new object
255256 */
256 - public static function &makeTitle( $ns, $title ) {
 257+ public static function &makeTitle( $ns, $title, $fragment = '' ) {
257258 $t = new Title();
258259 $t->mInterwiki = '';
259 - $t->mFragment = '';
 260+ $t->mFragment = $fragment;
260261 $t->mNamespace = $ns = intval( $ns );
261262 $t->mDbkeyform = str_replace( ' ', '_', $title );
262263 $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
@@ -271,11 +272,12 @@
272273 *
273274 * @param int $ns the namespace of the article
274275 * @param string $title the database key form
 276+ * @param string $fragment The link fragment (after the "#")
275277 * @return Title the new object, or NULL on an error
276278 */
277 - public static function makeTitleSafe( $ns, $title ) {
 279+ public static function makeTitleSafe( $ns, $title, $fragment = '' ) {
278280 $t = new Title();
279 - $t->mDbkeyform = Title::makeName( $ns, $title );
 281+ $t->mDbkeyform = Title::makeName( $ns, $title, $fragment );
280282 if( $t->secureAndSplit() ) {
281283 return $t;
282284 } else {
@@ -391,13 +393,18 @@
392394 * Make a prefixed DB key from a DB key and a namespace index
393395 * @param int $ns numerical representation of the namespace
394396 * @param string $title the DB key form the title
 397+ * @param string $fragment The link fragment (after the "#")
395398 * @return string the prefixed form of the title
396399 */
397 - public static function makeName( $ns, $title ) {
 400+ public static function makeName( $ns, $title, $fragment = '' ) {
398401 global $wgContLang;
399402
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;
402409 }
403410
404411 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r38837Backported the following:...tstarling04:02, 8 August 2008

Status & tagging log