https://www.mediawiki.org/wiki/Special:Code/MediaWiki/108323
Revision: 108323
Author: ialex
Date: 2012-01-07 15:48:42 +0000 (Sat, 07 Jan 2012)
Log Message:
-----------
Cleanup in WikiPage::getRedirectURL():
* Call Title::isValidRedirectTarget() in case of special page instead of
checking only for Special:Userlogout
* Refactor the code a bit to be more readable and remove unneeded nested
conditions
Modified Paths:
--------------
trunk/phase3/includes/WikiPage.php
Modified: trunk/phase3/includes/WikiPage.php
===================================================================
--- trunk/phase3/includes/WikiPage.php 2012-01-07 15:43:21 UTC (rev 108322)
+++ trunk/phase3/includes/WikiPage.php 2012-01-07 15:48:42 UTC (rev 108323)
@@ -205,36 +205,39 @@
* @return mixed false, Title object of local target, or string with URL
*/
public function getRedirectURL( $rt ) {
- if ( $rt ) {
- if ( $rt->getInterwiki() != '' ) {
- if ( $rt->isLocal() ) {
- // Offsite wikis need an HTTP redirect.
- //
- // This can be hard to reverse and may
produce loops,
- // so they may be disabled in the site
configuration.
- $source = $this->mTitle->getFullURL(
'redirect=no' );
- return $rt->getFullURL( 'rdfrom=' .
urlencode( $source ) );
- }
+ if ( !$rt ) {
+ return false;
+ }
+
+ if ( $rt->isExternal() ) {
+ if ( $rt->isLocal() ) {
+ // Offsite wikis need an HTTP redirect.
+ //
+ // This can be hard to reverse and may produce
loops,
+ // so they may be disabled in the site
configuration.
+ $source = $this->mTitle->getFullURL(
'redirect=no' );
+ return $rt->getFullURL( 'rdfrom=' . urlencode(
$source ) );
} else {
- if ( $rt->isSpecialPage() ) {
- // Gotta handle redirects to special
pages differently:
- // Fill the HTTP response "Location"
header and ignore
- // the rest of the page we're on.
- //
- // This can be hard to reverse, so they
may be disabled.
- if ( $rt->isSpecial( 'Userlogout' ) ) {
- // rolleyes
- } else {
- return $rt->getFullURL();
- }
- }
+ // External pages pages without "local" bit set
are not valid
+ // redirect targets
+ return false;
+ }
+ }
- return $rt;
+ if ( $rt->isSpecialPage() ) {
+ // Gotta handle redirects to special pages differently:
+ // Fill the HTTP response "Location" header and ignore
+ // the rest of the page we're on.
+ //
+ // Some pages are not valid targets
+ if ( $rt->isValidRedirectTarget() ) {
+ return $rt->getFullURL();
+ } else {
+ return false;
}
}
- // No or invalid redirect
- return false;
+ return $rt;
}
/**
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs