From: Rob Church Date: Wed, 1 Aug 2007 01:45:58 +0000 (+0000) Subject: (bug 10683) Fix inconsistent handling of URL-encoded titles in links used in redirect... X-Git-Tag: 1.31.0-rc.0~51907 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=9d8350262818d0d6f81c2198beb9cee2a9dd753a;p=lhc%2Fweb%2Fwiklou.git (bug 10683) Fix inconsistent handling of URL-encoded titles in links used in redirects (i.e. they now work) --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 16156aebf3..c30696f363 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -338,6 +338,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN used on a non-existent page with "action=info" * Fix escaping of raw message text when used on a non-existent page with "action=info" +* (bug 10683) Fix inconsistent handling of URL-encoded titles in links + used in redirects (i.e. they now work) == API changes since 1.10 == diff --git a/includes/Title.php b/includes/Title.php index 7a459bd618..d5e9d9fc9e 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -269,32 +269,27 @@ class Title { } /** - * Create a new Title for a redirect - * @param string $text the redirect title text - * @return Title the new object, or NULL if the text is not a - * valid redirect + * Extract a redirect destination from a string and return the + * Title, or null if the text doesn't contain a valid redirect + * + * @param string $text Text with possible redirect + * @return Title */ public static function newFromRedirect( $text ) { - $mwRedir = MagicWord::get( 'redirect' ); - $rt = NULL; - if ( $mwRedir->matchStart( $text ) ) { - $m = array(); - if ( preg_match( '/\[{2}(.*?)(?:\||\]{2})/', $text, $m ) ) { - # categories are escaped using : for example one can enter: - # #REDIRECT [[:Category:Music]]. Need to remove it. - if ( substr($m[1],0,1) == ':') { - # We don't want to keep the ':' - $m[1] = substr( $m[1], 1 ); - } - - $rt = Title::newFromText( $m[1] ); - # Disallow redirects to Special:Userlogout - if ( !is_null($rt) && $rt->isSpecial( 'Userlogout' ) ) { - $rt = NULL; - } + $redir = MagicWord::get( 'redirect' ); + if( $redir->matchStart( $text ) ) { + // Extract the first link and see if it's usable + if( preg_match( '!\[{2}(.*?)(?:\||\]{2})!', $text, $m ) ) { + // Strip preceding colon used to "escape" categories, etc. + // and URL-decode links + $m[1] = urldecode( ltrim( $m[1], ':' ) ); + $title = Title::newFromText( $m[1] ); + // Redirects to Special:Userlogout are not permitted + if( $title instanceof Title && !$title->isSpecial( 'Userlogout' ) ) + return $title; } } - return $rt; + return null; } #----------------------------------------------------------------------------