r108323 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108322‎ | r108323 | r108324 >
Date:15:48, 7 January 2012
Author:ialex
Status:ok
Tags:
Comment:
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) (history)

Diff [purge]

Index: trunk/phase3/includes/WikiPage.php
@@ -205,36 +205,39 @@
206206 * @return mixed false, Title object of local target, or string with URL
207207 */
208208 public function getRedirectURL( $rt ) {
209 - if ( $rt ) {
210 - if ( $rt->getInterwiki() != '' ) {
211 - if ( $rt->isLocal() ) {
212 - // Offsite wikis need an HTTP redirect.
213 - //
214 - // This can be hard to reverse and may produce loops,
215 - // so they may be disabled in the site configuration.
216 - $source = $this->mTitle->getFullURL( 'redirect=no' );
217 - return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
218 - }
 209+ if ( !$rt ) {
 210+ return false;
 211+ }
 212+
 213+ if ( $rt->isExternal() ) {
 214+ if ( $rt->isLocal() ) {
 215+ // Offsite wikis need an HTTP redirect.
 216+ //
 217+ // This can be hard to reverse and may produce loops,
 218+ // so they may be disabled in the site configuration.
 219+ $source = $this->mTitle->getFullURL( 'redirect=no' );
 220+ return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
219221 } else {
220 - if ( $rt->isSpecialPage() ) {
221 - // Gotta handle redirects to special pages differently:
222 - // Fill the HTTP response "Location" header and ignore
223 - // the rest of the page we're on.
224 - //
225 - // This can be hard to reverse, so they may be disabled.
226 - if ( $rt->isSpecial( 'Userlogout' ) ) {
227 - // rolleyes
228 - } else {
229 - return $rt->getFullURL();
230 - }
231 - }
 222+ // External pages pages without "local" bit set are not valid
 223+ // redirect targets
 224+ return false;
 225+ }
 226+ }
232227
233 - return $rt;
 228+ if ( $rt->isSpecialPage() ) {
 229+ // Gotta handle redirects to special pages differently:
 230+ // Fill the HTTP response "Location" header and ignore
 231+ // the rest of the page we're on.
 232+ //
 233+ // Some pages are not valid targets
 234+ if ( $rt->isValidRedirectTarget() ) {
 235+ return $rt->getFullURL();
 236+ } else {
 237+ return false;
234238 }
235239 }
236240
237 - // No or invalid redirect
238 - return false;
 241+ return $rt;
239242 }
240243
241244 /**

Status & tagging log