resourceloader: Clean up UserModule to be more like UserGroupsModule
authorTimo Tijhof <krinklemail@gmail.com>
Sun, 1 Mar 2015 15:25:39 +0000 (16:25 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 3 Mar 2015 17:01:38 +0000 (18:01 +0100)
Change-Id: Ic988c36c034b2862e6404bb6b6b7fe24d171fef1

includes/resourceloader/ResourceLoaderUserModule.php

index 1b6d1de..e2d39d0 100644 (file)
@@ -38,36 +38,28 @@ class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
         * @return array
         */
        protected function getPages( ResourceLoaderContext $context ) {
-               $username = $context->getUser();
-
-               if ( $username === null ) {
-                       return array();
-               }
-
                $allowUserJs = $this->getConfig()->get( 'AllowUserJs' );
                $allowUserCss = $this->getConfig()->get( 'AllowUserCss' );
-
                if ( !$allowUserJs && !$allowUserCss ) {
                        return array();
                }
 
-               // Get the normalized title of the user's user page
-               $userpageTitle = Title::makeTitleSafe( NS_USER, $username );
-
-               if ( !$userpageTitle instanceof Title ) {
+               $user = $context->getUserObj();
+               if ( !$user || $user->isAnon() ) {
                        return array();
                }
 
-               $userpage = $userpageTitle->getPrefixedDBkey(); // Needed so $excludepages works
+               // Needed so $excludepages works
+               $userPage = $user->getUserPage()->getPrefixedDBkey();
 
                $pages = array();
                if ( $allowUserJs ) {
-                       $pages["$userpage/common.js"] = array( 'type' => 'script' );
-                       $pages["$userpage/" . $context->getSkin() . '.js'] = array( 'type' => 'script' );
+                       $pages["$userPage/common.js"] = array( 'type' => 'script' );
+                       $pages["$userPage/" . $context->getSkin() . '.js'] = array( 'type' => 'script' );
                }
                if ( $allowUserCss ) {
-                       $pages["$userpage/common.css"] = array( 'type' => 'style' );
-                       $pages["$userpage/" . $context->getSkin() . '.css'] = array( 'type' => 'style' );
+                       $pages["$userPage/common.css"] = array( 'type' => 'style' );
+                       $pages["$userPage/" . $context->getSkin() . '.css'] = array( 'type' => 'style' );
                }
 
                // Hack for bug 26283: if we're on a preview page for a CSS/JS page,