Merge "(bug 34956) Parser should use mUrlProtocol instead of wfUrlProtocols()"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderUserGroupsModule.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 /**
22 * Module for user customizations
23 */
24 class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule {
25
26 /* Protected Methods */
27 protected $origin = self::ORIGIN_USER_SITEWIDE;
28
29 /**
30 * @param $context ResourceLoaderContext
31 * @return array
32 */
33 protected function getPages( ResourceLoaderContext $context ) {
34 global $wgUser;
35
36 $userName = $context->getUser();
37 if ( !$userName ) {
38 return array();
39 }
40
41 // Use $wgUser is possible; allows to skip a lot of code
42 if ( is_object( $wgUser ) && $wgUser->getName() == $userName ) {
43 $user = $wgUser;
44 } else {
45 $user = User::newFromName( $userName );
46 if ( !$user instanceof User ) {
47 return array();
48 }
49 }
50
51 $pages = array();
52 foreach( $user->getEffectiveGroups() as $group ) {
53 if ( in_array( $group, array( '*', 'user' ) ) ) {
54 continue;
55 }
56 $pages["MediaWiki:Group-$group.js"] = array( 'type' => 'script' );
57 $pages["MediaWiki:Group-$group.css"] = array( 'type' => 'style' );
58 }
59 return $pages;
60 }
61
62 /* Methods */
63
64 /**
65 * @return string
66 */
67 public function getGroup() {
68 return 'user';
69 }
70 }