Add SpecialPage::getLinkRenderer()
[lhc/web/wiklou.git] / includes / specialpage / SpecialPageFactory.php
index 4c869f9..b69b28a 100644 (file)
@@ -21,6 +21,7 @@
  * @ingroup SpecialPage
  * @defgroup SpecialPage SpecialPage
  */
+use MediaWiki\Linker\LinkRenderer;
 
 /**
  * Factory for handling the special page list and generating SpecialPage objects.
@@ -81,18 +82,23 @@ class SpecialPageFactory {
                'PagesWithProp' => 'SpecialPagesWithProp',
                'TrackingCategories' => 'SpecialTrackingCategories',
 
-               // Login/create account
-               'Userlogin' => 'LoginForm',
-               'CreateAccount' => 'SpecialCreateAccount',
+               // Authentication
+               'Userlogin' => 'SpecialUserLogin',
+               'Userlogout' => 'SpecialUserlogoutPreAuthManager',
+               'CreateAccount' => 'SpecialCreateAccountPreAuthManager',
+               'LinkAccounts' => 'SpecialLinkAccounts',
+               'UnlinkAccounts' => 'SpecialUnlinkAccounts',
+               'ChangeCredentials' => 'SpecialChangeCredentials',
+               'RemoveCredentials' => 'SpecialRemoveCredentials',
 
                // Users and rights
                'Activeusers' => 'SpecialActiveUsers',
                'Block' => 'SpecialBlock',
                'Unblock' => 'SpecialUnblock',
                'BlockList' => 'SpecialBlockList',
-               'ChangePassword' => 'SpecialChangePassword',
+               'ChangePassword' => 'SpecialChangePasswordPreAuthManager',
                'BotPasswords' => 'SpecialBotPasswords',
-               'PasswordReset' => 'SpecialPasswordReset',
+               'PasswordReset' => 'SpecialPasswordResetPreAuthManager',
                'DeletedContributions' => 'DeletedContributionsPage',
                'Preferences' => 'SpecialPreferences',
                'ResetTokens' => 'SpecialResetTokens',
@@ -178,7 +184,6 @@ class SpecialPageFactory {
                'Revisiondelete' => 'SpecialRevisionDelete',
                'RunJobs' => 'SpecialRunJobs',
                'Specialpages' => 'SpecialSpecialpages',
-               'Userlogout' => 'SpecialUserlogout',
        ];
 
        private static $list;
@@ -226,6 +231,7 @@ class SpecialPageFactory {
                global $wgDisableInternalSearch, $wgEmailAuthentication;
                global $wgEnableEmail, $wgEnableJavaScriptTest;
                global $wgPageLanguageUseDB, $wgContentHandlerUseDB;
+               global $wgDisableAuthManager;
 
                if ( !is_array( self::$list ) ) {
 
@@ -241,7 +247,7 @@ class SpecialPageFactory {
                        }
 
                        if ( $wgEnableEmail ) {
-                               self::$list['ChangeEmail'] = 'SpecialChangeEmail';
+                               self::$list['ChangeEmail'] = 'SpecialChangeEmailPreAuthManager';
                        }
 
                        if ( $wgEnableJavaScriptTest ) {
@@ -255,6 +261,20 @@ class SpecialPageFactory {
                                self::$list['ChangeContentModel'] = 'SpecialChangeContentModel';
                        }
 
+                       // horrible hack to allow selection between old and new classes via a feature flag - T110756
+                       // will be removed once AuthManager is stable
+                       if ( !$wgDisableAuthManager ) {
+                               self::$list = array_map( function ( $class ) {
+                                       return preg_replace( '/PreAuthManager$/', '', $class );
+                               }, self::$list );
+                               self::$list['Userlogout'] = 'SpecialUserLogout'; // case matters
+                       } else {
+                               self::$list['Userlogin'] = 'LoginForm';
+                               self::$list = array_diff_key( self::$list, array_fill_keys( [
+                                       'LinkAccounts', 'UnlinkAccounts', 'ChangeCredentials', 'RemoveCredentials',
+                               ], true ) );
+                       }
+
                        // Add extension special pages
                        self::$list = array_merge( self::$list, $wgSpecialPages );
 
@@ -504,10 +524,13 @@ class SpecialPageFactory {
         * @param Title $title
         * @param IContextSource $context
         * @param bool $including Bool output is being captured for use in {{special:whatever}}
+        * @param LinkRenderer|null $linkRenderer (since 1.28)
         *
         * @return bool
         */
-       public static function executePath( Title &$title, IContextSource &$context, $including = false ) {
+       public static function executePath( Title &$title, IContextSource &$context, $including = false,
+               LinkRenderer $linkRenderer = null
+       ) {
                // @todo FIXME: Redirects broken due to this call
                $bits = explode( '/', $title->getDBkey(), 2 );
                $name = $bits[0];
@@ -567,6 +590,9 @@ class SpecialPageFactory {
                }
 
                $page->including( $including );
+               if ( $linkRenderer ) {
+                       $page->setLinkRenderer( $linkRenderer );
+               }
 
                // Execute special page
                $page->run( $par );
@@ -586,9 +612,12 @@ class SpecialPageFactory {
         *
         * @param Title $title
         * @param IContextSource $context
+        * @param LinkRenderer|null $linkRenderer (since 1.28)
         * @return string HTML fragment
         */
-       public static function capturePath( Title $title, IContextSource $context ) {
+       public static function capturePath(
+               Title $title, IContextSource $context, LinkRenderer $linkRenderer = null
+       ) {
                global $wgTitle, $wgOut, $wgRequest, $wgUser, $wgLang;
                $main = RequestContext::getMain();
 
@@ -621,7 +650,7 @@ class SpecialPageFactory {
                $main->setLanguage( $context->getLanguage() );
 
                // The useful part
-               $ret = self::executePath( $title, $context, true );
+               $ret = self::executePath( $title, $context, true, $linkRenderer );
 
                // Restore old globals and context
                $wgTitle = $glob['title'];