Add wfUnserialize() wrapper around unserialize to prevent E_NOTICE and use it in...
[lhc/web/wiklou.git] / includes / SpecialPageFactory.php
index 0da2956..88c549a 100644 (file)
@@ -25,6 +25,7 @@
 /**
  * Factory for handling the special page list and generating SpecialPage objects
  * @ingroup SpecialPage
+ * @since 1.17
  */
 class SpecialPageFactory {
 
@@ -73,6 +74,7 @@ class SpecialPageFactory {
                'Unblock'                   => 'SpecialUnblock',
                'BlockList'                 => 'SpecialBlockList',
                'ChangePassword'            => 'SpecialChangePassword',
+               'PasswordReset'             => 'SpecialPasswordReset',
                'DeletedContributions'      => 'DeletedContributionsPage',
                'Preferences'               => 'SpecialPreferences',
                'Contributions'             => 'SpecialContributions',
@@ -152,6 +154,8 @@ class SpecialPageFactory {
        /**
         * Initialise the special page list
         * This must be called before accessing SpecialPage::$mList
+        *
+        * @return array
         */
        static function getList() {
                global $wgSpecialPages;
@@ -188,6 +192,14 @@ class SpecialPageFactory {
                return self::$mList;
        }
 
+       /**
+        * Initialise and return the list of special page aliases.  Returns an object with
+        * properties which can be accessed $obj->pagename - each property is an array of
+        * aliases; the first in the array is the cannonical alias.  All registered special
+        * pages are guaranteed to have a property entry, and for that property array to
+        * contain at least one entry (English fallbacks will be added if necessary).
+        * @return Object
+        */
        static function getAliasList() {
                if ( !is_object( self::$mAliases ) ) {
                        global $wgContLang;
@@ -255,7 +267,7 @@ class SpecialPageFactory {
        }
 
        /**
-        * Add a page to a certain display group for Special:SpecialPages
+        * Get the group that the special page belongs in on Special:SpecialPage
         *
         * @param $page SpecialPage
         */
@@ -303,7 +315,7 @@ class SpecialPageFactory {
                        $rec = self::getList()->$realName;
                        if ( is_string( $rec ) ) {
                                $className = $rec;
-                               self::getList()->$realName = new $className;
+                               return new $className;
                        } elseif ( is_array( $rec ) ) {
                                // @deprecated, officially since 1.18, unofficially since forever
                                wfDebug( "Array syntax for \$wgSpecialPages is deprecated, define a subclass of SpecialPage instead." );
@@ -388,11 +400,13 @@ class SpecialPageFactory {
         * @param $title          Title object
         * @param $context        RequestContext
         * @param $including      Bool output is being captured for use in {{special:whatever}}
+        *
+        * @return bool
         */
        public static function executePath( Title &$title, RequestContext &$context, $including = false ) {
                wfProfileIn( __METHOD__ );
 
-               // FIXME: redirects broken due to this call
+               // @todo FIXME: Redirects broken due to this call
                $bits = explode( '/', $title->getDBkey(), 2 );
                $name = $bits[0];
                if ( !isset( $bits[1] ) ) { // bug 2087
@@ -403,10 +417,10 @@ class SpecialPageFactory {
                $page = self::getPage( $name );
                // Nonexistent?
                if ( !$page ) {
-                       $context->output->setArticleRelated( false );
-                       $context->output->setRobotPolicy( 'noindex,nofollow' );
-                       $context->output->setStatusCode( 404 );
-                       $context->output->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
+                       $context->getOutput()->setArticleRelated( false );
+                       $context->getOutput()->setRobotPolicy( 'noindex,nofollow' );
+                       $context->getOutput()->setStatusCode( 404 );
+                       $context->getOutput()->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
                        wfProfileOut( __METHOD__ );
                        return false;
                }
@@ -414,41 +428,23 @@ class SpecialPageFactory {
                // Page exists, set the context
                $page->setContext( $context );
 
-               // Check for redirect
                if ( !$including ) {
-                       if( $page instanceof SpecialRedirectToSpecial ){
-                               $redirect = $page->getRedirect( $par );
-                               $query = $page->getRedirectQuery();
-                               if ( $redirect instanceof Title ) {
-                                       $url = $redirect->getFullUrl( $query );
-                                       $context->output->redirect( $url );
-                                       wfProfileOut( __METHOD__ );
-                                       return $redirect;
-                               } elseif ( $redirect === true ) {
-                                       global $wgScript;
-                                       $url = $wgScript . '?' . wfArrayToCGI( $query );
-                                       $context->output->redirect( $url );
-                                       wfProfileOut( __METHOD__ );
-                                       return $redirect;
-                               }
-                       }
-
                        // Redirect to canonical alias for GET commands
                        // Not for POST, we'd lose the post data, so it's best to just distribute
                        // the request. Such POST requests are possible for old extensions that
                        // generate self-links without being aware that their default name has
                        // changed.
-                       if ( $name != $page->getLocalName() && !$context->request->wasPosted() ) {
-                               $query = $_GET;
+                       if ( $name != $page->getLocalName() && !$context->getRequest()->wasPosted() ) {
+                               $query = $context->getRequest()->getQueryValues();
                                unset( $query['title'] );
                                $query = wfArrayToCGI( $query );
                                $title = $page->getTitle( $par );
                                $url = $title->getFullUrl( $query );
-                               $context->output->redirect( $url );
+                               $context->getOutput()->redirect( $url );
                                wfProfileOut( __METHOD__ );
                                return $title;
                        } else {
-                               $context->title = $page->getTitle();
+                               $context->setTitle( $page->getTitle() );
                        }
 
                } elseif ( !$page->isIncludable() ) {
@@ -472,16 +468,23 @@ class SpecialPageFactory {
         * Returns false if there was no such special page, or a title object if it was
         * a redirect.
         *
+        * @param $title Title
+        *
         * @return String: HTML fragment
         */
        static function capturePath( &$title ) {
-               global $wgOut, $wgTitle;
+               global $wgOut, $wgTitle, $wgRequest;
 
                $oldTitle = $wgTitle;
                $oldOut = $wgOut;
+               $oldRequest = $wgRequest;
+
+               // Don't want special pages interpreting ?feed=atom parameters.
+               $wgRequest = new FauxRequest( array() );
 
                $context = new RequestContext;
                $context->setTitle( $title );
+               $context->setRequest( $wgRequest );
                $wgOut = $context->getOutput();
 
                $ret = self::executePath( $title, $context, true );
@@ -490,6 +493,7 @@ class SpecialPageFactory {
                }
                $wgTitle = $oldTitle;
                $wgOut = $oldOut;
+               $wgRequest = $oldRequest;
                return $ret;
        }
 
@@ -504,6 +508,7 @@ class SpecialPageFactory {
        static function getLocalNameFor( $name, $subpage = false ) {
                global $wgContLang;
                $aliases = $wgContLang->getSpecialPageAliases();
+               
                if ( isset( $aliases[$name][0] ) ) {
                        $name = $aliases[$name][0];
                } else {
@@ -532,14 +537,16 @@ class SpecialPageFactory {
        /**
         * Get a title for a given alias
         *
+        * @param $alias String
+        *
         * @return Title or null if there is no such alias
         */
        static function getTitleForAlias( $alias ) {
                $name = self::resolveAlias( $alias );
                if ( $name ) {
-                       return self::getTitleFor( $name );
+                       return SpecialPage::getTitleFor( $name );
                } else {
                        return null;
                }
        }
-}
\ No newline at end of file
+}