MediaWiki.php: Redirect non-standard title urls to canonical
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 19 Jun 2015 20:07:24 +0000 (21:07 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 23 Jun 2015 06:19:07 +0000 (06:19 +0000)
commit155d555b83eca6403e07d2094b074a8ed2f301ae
treee1104f0abda6cb90748cf6add889aa88c2f12366
parent64431fcf8e467a006073ba6dc7f72f48011e5709
MediaWiki.php: Redirect non-standard title urls to canonical

Urls that use the page's title and no extra query parameters now redirect
to the standard url format.

Previously we only did this for variations of the title value (e.g. "Foo%20Bar"),
not for variations of the overall url structure (like title=Foo -> /wiki/Foo).

Existing redirect (unchanged):
 /wiki/Foo%20Bar
 /w/index.php?title=Foo%20Bar

New redirects:
 /wiki/Foo_Bar?action=view
 /w/index.php?title=Foo_Bar
 /w/index.php?title=Foo_Bar&action=view

Any intentional (or unintentional) ways a url can be rewritten by the server,
such as "/?title=Foo_Bar" in case of Wikimedia, are redirected as well.

While this has been a problem for many years, it went unnoticed until
recently when Google started to index significantly more results of
the "/?title=<name>" form. This query returns "About 3,220,000 results":
https://google.com/search?q=site:en.wikipedia.org+inurl:title+-intitle:title

The only change in logic is that the titlekey comparison is now no longer a
factor in deciding whether to redirect. Instead the existing comparison for the
entire url is used to cover this.

However I kept titlekey comparison in the redirect-loop check as otherwise this
check would throw on all canonical page views where no redirect can be made.
Added a comment explaining how this redirect loop was possible.

Bug: T67402
Change-Id: I88ed3525141c765910e66188427b9aab36b958a9
includes/MediaWiki.php
tests/phpunit/includes/MediaWikiTest.php