r24505 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24504‎ | r24505 | r24506 >
Date:01:45, 1 August 2007
Author:robchurch
Status:old
Tags:
Comment:
(bug 10683) Fix inconsistent handling of URL-encoded titles in links used in redirects (i.e. they now work)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -269,32 +269,27 @@
270270 }
271271
272272 /**
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
277278 */
278279 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;
296291 }
297292 }
298 - return $rt;
 293+ return null;
299294 }
300295
301296 #----------------------------------------------------------------------------
Index: trunk/phase3/RELEASE-NOTES
@@ -338,6 +338,8 @@
339339 used on a non-existent page with "action=info"
340340 * Fix escaping of raw message text when used on a non-existent page with
341341 "action=info"
 342+* (bug 10683) Fix inconsistent handling of URL-encoded titles in links
 343+ used in redirects (i.e. they now work)
342344
343345 == API changes since 1.10 ==
344346

Follow-up revisions

RevisionCommit summaryAuthorDate
r24631Merged revisions 24480-24600 via svnmerge from...david18:39, 6 August 2007
r25161Fix regression caused by r24505 for bug 10683 -- was breaking redirects to pa...brion14:52, 26 August 2007
r25223Merged revisions 25126-25214 via svnmerge from...david07:39, 28 August 2007

Status & tagging log