Index: trunk/phase3/includes/Title.php |
— | — | @@ -269,32 +269,27 @@ |
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
273 | | - * Create a new Title for a redirect |
274 | | - * @param string $text the redirect title text |
275 | | - * @return Title the new object, or NULL if the text is not a |
276 | | - * valid redirect |
| 273 | + * Extract a redirect destination from a string and return the |
| 274 | + * Title, or null if the text doesn't contain a valid redirect |
| 275 | + * |
| 276 | + * @param string $text Text with possible redirect |
| 277 | + * @return Title |
277 | 278 | */ |
278 | 279 | public static function newFromRedirect( $text ) { |
279 | | - $mwRedir = MagicWord::get( 'redirect' ); |
280 | | - $rt = NULL; |
281 | | - if ( $mwRedir->matchStart( $text ) ) { |
282 | | - $m = array(); |
283 | | - if ( preg_match( '/\[{2}(.*?)(?:\||\]{2})/', $text, $m ) ) { |
284 | | - # categories are escaped using : for example one can enter: |
285 | | - # #REDIRECT [[:Category:Music]]. Need to remove it. |
286 | | - if ( substr($m[1],0,1) == ':') { |
287 | | - # We don't want to keep the ':' |
288 | | - $m[1] = substr( $m[1], 1 ); |
289 | | - } |
290 | | - |
291 | | - $rt = Title::newFromText( $m[1] ); |
292 | | - # Disallow redirects to Special:Userlogout |
293 | | - if ( !is_null($rt) && $rt->isSpecial( 'Userlogout' ) ) { |
294 | | - $rt = NULL; |
295 | | - } |
| 280 | + $redir = MagicWord::get( 'redirect' ); |
| 281 | + if( $redir->matchStart( $text ) ) { |
| 282 | + // Extract the first link and see if it's usable |
| 283 | + if( preg_match( '!\[{2}(.*?)(?:\||\]{2})!', $text, $m ) ) { |
| 284 | + // Strip preceding colon used to "escape" categories, etc. |
| 285 | + // and URL-decode links |
| 286 | + $m[1] = urldecode( ltrim( $m[1], ':' ) ); |
| 287 | + $title = Title::newFromText( $m[1] ); |
| 288 | + // Redirects to Special:Userlogout are not permitted |
| 289 | + if( $title instanceof Title && !$title->isSpecial( 'Userlogout' ) ) |
| 290 | + return $title; |
296 | 291 | } |
297 | 292 | } |
298 | | - return $rt; |
| 293 | + return null; |
299 | 294 | } |
300 | 295 | |
301 | 296 | #---------------------------------------------------------------------------- |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -338,6 +338,8 @@ |
339 | 339 | used on a non-existent page with "action=info" |
340 | 340 | * Fix escaping of raw message text when used on a non-existent page with |
341 | 341 | "action=info" |
| 342 | +* (bug 10683) Fix inconsistent handling of URL-encoded titles in links |
| 343 | + used in redirects (i.e. they now work) |
342 | 344 | |
343 | 345 | == API changes since 1.10 == |
344 | 346 | |