Merge "+Test for Status->CleanParams with a callback"
[lhc/web/wiklou.git] / includes / specials / SpecialRedirect.php
index 210cee6..8ec6f85 100644 (file)
@@ -135,6 +135,25 @@ 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.
+        */
+       function dispatchPage() {
+               $curid = $this->mValue;
+               if ( !ctype_digit( $curid ) ) {
+                       return null;
+               }
+               $curid = (int)$curid;
+               if ( $curid === 0 ) {
+                       return null;
+               }
+               return wfAppendQuery( wfScript( 'index' ), array(
+                       'curid' => $curid
+               ) );
+       }
+
        /**
         * Use appropriate dispatch* method to obtain a redirection URL,
         * and either: redirect, set a 404 error code and error message,
@@ -145,7 +164,7 @@ class SpecialRedirect extends FormSpecialPage {
         */
        function dispatch() {
                // the various namespaces supported by Special:Redirect
-               switch( $this->mType ) {
+               switch ( $this->mType ) {
                case 'user':
                        $url = $this->dispatchUser();
                        break;
@@ -155,6 +174,9 @@ class SpecialRedirect extends FormSpecialPage {
                case 'revision':
                        $url = $this->dispatchRevision();
                        break;
+               case 'page':
+                       $url = $this->dispatchPage();
+                       break;
                default:
                        $this->getOutput()->setStatusCode( 404 );
                        $url = null;
@@ -166,6 +188,7 @@ class SpecialRedirect extends FormSpecialPage {
                }
                if ( !is_null( $this->mValue ) ) {
                        $this->getOutput()->setStatusCode( 404 );
+                       // Message: redirect-not-exists
                        $msg = $this->getMessagePrefix() . '-not-exists';
                        return Status::newFatal( $msg );
                }
@@ -176,24 +199,27 @@ class SpecialRedirect extends FormSpecialPage {
                $mp = $this->getMessagePrefix();
                $ns = array(
                        // subpage => message
+                       // Messages: redirect-user, redirect-page, redirect-revision,
+                       // redirect-file
                        'user' => $mp . '-user',
+                       'page' => $mp . '-page',
                        'revision' => $mp . '-revision',
                        'file' => $mp . '-file',
                );
                $a = array();
                $a['type'] = array(
                        'type' => 'select',
-                       'label-message' => $mp . '-lookup',
+                       'label-message' => $mp . '-lookup', // Message: redirect-lookup
                        'options' => array(),
                        'default' => current( array_keys( $ns ) ),
                );
-               foreach( $ns as $n => $m ) {
+               foreach ( $ns as $n => $m ) {
                        $m = $this->msg( $m )->text();
                        $a['type']['options'][$m] = $n;
                }
                $a['value'] = array(
                        'type' => 'text',
-                       'label-message' => $mp . '-value'
+                       'label-message' => $mp . '-value' // Message: redirect-value
                );
                // set the defaults according to the parsed subpage path
                if ( !empty( $this->mType ) ) {
@@ -220,7 +246,8 @@ class SpecialRedirect extends FormSpecialPage {
        protected function alterForm( HTMLForm $form ) {
                /* display summary at top of page */
                $this->outputHeader();
-               /* tweak label on submit button */
+               // tweak label on submit button
+               // Message: redirect-submit
                $form->setSubmitTextMsg( $this->getMessagePrefix() . '-submit' );
                /* submit form every time */
                $form->setMethod( 'get' );