Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
UserStylesModule | |
0.00% |
0 / 21 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
getPages | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
72 | |||
getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getGroup | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
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 | * @author Trevor Parscal |
20 | * @author Roan Kattouw |
21 | */ |
22 | |
23 | namespace MediaWiki\ResourceLoader; |
24 | |
25 | use MediaWiki\MainConfigNames; |
26 | use MediaWiki\MediaWikiServices; |
27 | use MediaWiki\Title\TitleValue; |
28 | |
29 | /** |
30 | * Module for user customizations styles. |
31 | * |
32 | * @ingroup ResourceLoader |
33 | * @internal |
34 | */ |
35 | class UserStylesModule extends WikiModule { |
36 | |
37 | /** @inheritDoc */ |
38 | protected $origin = self::ORIGIN_USER_INDIVIDUAL; |
39 | |
40 | /** |
41 | * @param Context $context |
42 | * @return array[] |
43 | */ |
44 | protected function getPages( Context $context ) { |
45 | $user = $context->getUserIdentity(); |
46 | $tempUserConfig = MediaWikiServices::getInstance()->getTempUserConfig(); |
47 | if ( !$user || !$user->isRegistered() || $tempUserConfig->isTempName( $user->getName() ) ) { |
48 | return []; |
49 | } |
50 | |
51 | $config = $this->getConfig(); |
52 | $pages = []; |
53 | |
54 | if ( $config->get( MainConfigNames::AllowUserCss ) ) { |
55 | $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter(); |
56 | // Use localised/normalised variant to ensure $excludepage matches |
57 | $userPage = $titleFormatter->getPrefixedDBkey( new TitleValue( NS_USER, $user->getName() ) ); |
58 | $pages["$userPage/common.css"] = [ 'type' => 'style' ]; |
59 | $pages["$userPage/" . $context->getSkin() . '.css'] = [ 'type' => 'style' ]; |
60 | } |
61 | |
62 | // User group pages are maintained site-wide and enabled with site JS/CSS. |
63 | if ( $config->get( MainConfigNames::UseSiteCss ) ) { |
64 | $effectiveGroups = MediaWikiServices::getInstance()->getUserGroupManager() |
65 | ->getUserEffectiveGroups( $user ); |
66 | foreach ( $effectiveGroups as $group ) { |
67 | if ( $group == '*' ) { |
68 | continue; |
69 | } |
70 | $pages["MediaWiki:Group-$group.css"] = [ 'type' => 'style' ]; |
71 | } |
72 | } |
73 | |
74 | return $pages; |
75 | } |
76 | |
77 | /** |
78 | * @return string |
79 | */ |
80 | public function getType() { |
81 | return self::LOAD_STYLES; |
82 | } |
83 | |
84 | /** |
85 | * Get group name |
86 | * |
87 | * @return string |
88 | */ |
89 | public function getGroup() { |
90 | return self::GROUP_USER; |
91 | } |
92 | } |