MediaWiki  REL1_22
ResourceLoaderUserGroupsModule.php
Go to the documentation of this file.
00001 <?php
00026 class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule {
00027 
00028     /* Protected Methods */
00029     protected $origin = self::ORIGIN_USER_SITEWIDE;
00030 
00035     protected function getPages( ResourceLoaderContext $context ) {
00036         global $wgUser, $wgUseSiteJs, $wgUseSiteCss;
00037 
00038         $userName = $context->getUser();
00039         if ( $userName === null ) {
00040             return array();
00041         }
00042         if ( !$wgUseSiteJs && !$wgUseSiteCss ) {
00043             return array();
00044         }
00045 
00046         // Use $wgUser is possible; allows to skip a lot of code
00047         if ( is_object( $wgUser ) && $wgUser->getName() == $userName ) {
00048             $user = $wgUser;
00049         } else {
00050             $user = User::newFromName( $userName );
00051             if ( !$user instanceof User ) {
00052                 return array();
00053             }
00054         }
00055 
00056         $pages = array();
00057         foreach ( $user->getEffectiveGroups() as $group ) {
00058             if ( in_array( $group, array( '*', 'user' ) ) ) {
00059                 continue;
00060             }
00061             if ( $wgUseSiteJs ) {
00062                 $pages["MediaWiki:Group-$group.js"] = array( 'type' => 'script' );
00063             }
00064             if ( $wgUseSiteCss ) {
00065                 $pages["MediaWiki:Group-$group.css"] = array( 'type' => 'style' );
00066             }
00067         }
00068         return $pages;
00069     }
00070 
00071     /* Methods */
00072 
00076     public function getGroup() {
00077         return 'user';
00078     }
00079 }