MediaWiki  REL1_20
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;
00037 
00038                 $userName = $context->getUser();
00039                 if ( $userName === null ) {
00040                         return array();
00041                 }
00042 
00043                 // Use $wgUser is possible; allows to skip a lot of code
00044                 if ( is_object( $wgUser ) && $wgUser->getName() == $userName ) {
00045                         $user = $wgUser;
00046                 } else {
00047                         $user = User::newFromName( $userName );
00048                         if ( !$user instanceof User ) {
00049                                 return array();
00050                         }
00051                 }
00052 
00053                 $pages = array();
00054                 foreach( $user->getEffectiveGroups() as $group ) {
00055                         if ( in_array( $group, array( '*', 'user' ) ) ) {
00056                                 continue;
00057                         }
00058                         $pages["MediaWiki:Group-$group.js"] = array( 'type' => 'script' );
00059                         $pages["MediaWiki:Group-$group.css"] = array( 'type' => 'style' );
00060                 }
00061                 return $pages;
00062         }
00063 
00064         /* Methods */
00065 
00069         public function getGroup() {
00070                 return 'user';
00071         }
00072 }