Make Special:Redirect work for blocked users and in read-only mode
[lhc/web/wiklou.git] / includes / specials / SpecialRedirect.php
index 8ec6f85..553e2b1 100644 (file)
@@ -2,7 +2,6 @@
 /**
  * Implements Special:Redirect
  *
- * @section LICENSE
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -55,6 +54,7 @@ class SpecialRedirect extends FormSpecialPage {
 
        /**
         * Set $mType and $mValue based on parsed value of $subpage.
+        * @param string $subpage
         */
        function setParameter( $subpage ) {
                // parse $subpage to pull out the parts
@@ -66,7 +66,7 @@ class SpecialRedirect extends FormSpecialPage {
        /**
         * Handle Special:Redirect/user/xxxx (by redirecting to User:YYYY)
         *
-        * @return string|null url to redirect to, or null if $mValue is invalid.
+        * @return string|null Url to redirect to, or null if $mValue is invalid.
         */
        function dispatchUser() {
                if ( !ctype_digit( $this->mValue ) ) {
@@ -78,18 +78,19 @@ class SpecialRedirect extends FormSpecialPage {
                        return null;
                }
                $userpage = Title::makeTitle( NS_USER, $username );
+
                return $userpage->getFullURL( '', false, PROTO_CURRENT );
        }
 
        /**
         * Handle Special:Redirect/file/xxxx
         *
-        * @return string|null url to redirect to, or null if $mValue is not found.
+        * @return string|null Url to redirect to, or null if $mValue is not found.
         */
        function dispatchFile() {
                $title = Title::makeTitleSafe( NS_FILE, $this->mValue );
 
-               if ( ! $title instanceof Title ) {
+               if ( !$title instanceof Title ) {
                        return null;
                }
                $file = wfFindFile( $title );
@@ -112,6 +113,7 @@ class SpecialRedirect extends FormSpecialPage {
                                $url = $mto->getURL();
                        }
                }
+
                return $url;
        }
 
@@ -119,7 +121,7 @@ class SpecialRedirect extends FormSpecialPage {
         * Handle Special:Redirect/revision/xxx
         * (by redirecting to index.php?oldid=xxx)
         *
-        * @return string|null url to redirect to, or null if $mValue is invalid.
+        * @return string|null Url to redirect to, or null if $mValue is invalid.
         */
        function dispatchRevision() {
                $oldid = $this->mValue;
@@ -130,6 +132,7 @@ class SpecialRedirect extends FormSpecialPage {
                if ( $oldid === 0 ) {
                        return null;
                }
+
                return wfAppendQuery( wfScript( 'index' ), array(
                        'oldid' => $oldid
                ) );
@@ -138,7 +141,7 @@ class SpecialRedirect extends FormSpecialPage {
        /**
         * Handle Special:Redirect/page/xxx (by redirecting to index.php?curid=xxx)
         *
-        * @return string|null url to redirect to, or null if $mValue is invalid.
+        * @return string|null Url to redirect to, or null if $mValue is invalid.
         */
        function dispatchPage() {
                $curid = $this->mValue;
@@ -149,6 +152,7 @@ class SpecialRedirect extends FormSpecialPage {
                if ( $curid === 0 ) {
                        return null;
                }
+
                return wfAppendQuery( wfScript( 'index' ), array(
                        'curid' => $curid
                ) );
@@ -160,38 +164,41 @@ class SpecialRedirect extends FormSpecialPage {
         * or do nothing (if $mValue wasn't set) allowing the form to be
         * displayed.
         *
-        * @return bool true if a redirect was successfully handled.
+        * @return bool True if a redirect was successfully handled.
         */
        function dispatch() {
                // the various namespaces supported by Special:Redirect
                switch ( $this->mType ) {
-               case 'user':
-                       $url = $this->dispatchUser();
-                       break;
-               case 'file':
-                       $url = $this->dispatchFile();
-                       break;
-               case 'revision':
-                       $url = $this->dispatchRevision();
-                       break;
-               case 'page':
-                       $url = $this->dispatchPage();
-                       break;
-               default:
-                       $this->getOutput()->setStatusCode( 404 );
-                       $url = null;
-                       break;
+                       case 'user':
+                               $url = $this->dispatchUser();
+                               break;
+                       case 'file':
+                               $url = $this->dispatchFile();
+                               break;
+                       case 'revision':
+                               $url = $this->dispatchRevision();
+                               break;
+                       case 'page':
+                               $url = $this->dispatchPage();
+                               break;
+                       default:
+                               $this->getOutput()->setStatusCode( 404 );
+                               $url = null;
+                               break;
                }
                if ( $url ) {
                        $this->getOutput()->redirect( $url );
+
                        return true;
                }
                if ( !is_null( $this->mValue ) ) {
                        $this->getOutput()->setStatusCode( 404 );
                        // Message: redirect-not-exists
                        $msg = $this->getMessagePrefix() . '-not-exists';
+
                        return Status::newFatal( $msg );
                }
+
                return false;
        }
 
@@ -228,6 +235,7 @@ class SpecialRedirect extends FormSpecialPage {
                if ( !empty( $this->mValue ) ) {
                        $a['value']['default'] = $this->mValue;
                }
+
                return $a;
        }
 
@@ -235,6 +243,7 @@ class SpecialRedirect extends FormSpecialPage {
                if ( !empty( $data['type'] ) && !empty( $data['value'] ) ) {
                        $this->setParameter( $data['type'] . '/' . $data['value'] );
                }
+
                /* if this returns false, will show the form */
                return $this->dispatch();
        }
@@ -253,6 +262,34 @@ class SpecialRedirect extends FormSpecialPage {
                $form->setMethod( 'get' );
        }
 
+       /**
+        * Return an array of subpages that this special page will accept.
+        *
+        * @return string[] subpages
+        */
+       protected function getSubpagesForPrefixSearch() {
+               return array(
+                       'file',
+                       'page',
+                       'revision',
+                       'user',
+               );
+       }
+
+       /**
+        * @return bool
+        */
+       public function requiresWrite() {
+               return false;
+       }
+
+       /**
+        * @return bool
+        */
+       public function requiresUnblock() {
+               return false;
+       }
+
        protected function getGroupName() {
                return 'redirects';
        }