Some of Magnus's recent work inspired me to dig into Article.php and rework how redirects are handled.
My current in-progress code is attached on this bug: http://bugzilla.wikimedia.org/show_bug.cgi?id=1103
Formerly, the following of redirects was handled inside Article's getContent/fetchContent functions, and which would get called inside the view() action handler. This is problematic for several reasons:
* When loading text for other purposes, you could trip a global redirect by accident. Ugly parameters got hacked in to try to work around that.
* Redirecting from one type of page to another required all kinds of extra hacks or just plain didn't work; regular articles, image pages, and category pages are handled by different variants of the Article class while Special pages do something else entirely.
* It's daaaaaamn ugly; lots of checks of globals and URL parameters in the middle of text-loading code, and the global title might change while you're halfway through a function.
In the new code, the setup code in Wiki.php creates an Article object, asks if it's a redirect, and if so follows it to get another Article object. It feels like a cleaner interface to me, and minimizes the amount of weird global changes appearing as side effects of low-level content-loading methods.
With some further work, it should even be possible to handle redirects to Special pages properly; currently those are done with a URL redirect (or not at all, if interwiki redirects are disabled). Instead, we could load up the special page and shove the 'redirected from' link+subheading at it like we do for regular pages.
Since this changes some of the guts of the wiki, I haven't committed it quite yet but plan to soon. Please test, and let me know about anything that breaks or post a fix to the patch. (Remember, CVS HEAD is our production code and code should always be carefully tested before committing there.)
-- brion vibber (brion @ pobox.com)
wikitech-l@lists.wikimedia.org