Merge "Add .pipeline/ with dev image variant"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderUserStylesModule.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 * @author Trevor Parscal
20 * @author Roan Kattouw
21 */
22
23 /**
24 * Module for user customizations styles.
25 *
26 * @ingroup ResourceLoader
27 * @internal
28 */
29 class ResourceLoaderUserStylesModule extends ResourceLoaderWikiModule {
30
31 protected $origin = self::ORIGIN_USER_INDIVIDUAL;
32 protected $targets = [ 'desktop', 'mobile' ];
33
34 /**
35 * @param ResourceLoaderContext $context
36 * @return array List of pages
37 */
38 protected function getPages( ResourceLoaderContext $context ) {
39 $config = $this->getConfig();
40 $user = $context->getUserObj();
41 if ( $user->isAnon() ) {
42 return [];
43 }
44
45 // Use localised/normalised variant to ensure $excludepage matches
46 $userPage = $user->getUserPage()->getPrefixedDBkey();
47 $pages = [];
48
49 if ( $config->get( 'AllowUserCss' ) ) {
50 $pages["$userPage/common.css"] = [ 'type' => 'style' ];
51 $pages["$userPage/" . $context->getSkin() . '.css'] = [ 'type' => 'style' ];
52 }
53
54 // User group pages are maintained site-wide and enabled with site JS/CSS.
55 if ( $config->get( 'UseSiteCss' ) ) {
56 foreach ( $user->getEffectiveGroups() as $group ) {
57 if ( $group == '*' ) {
58 continue;
59 }
60 $pages["MediaWiki:Group-$group.css"] = [ 'type' => 'style' ];
61 }
62 }
63
64 // This is obsolete since 1.32 (T112474). It was formerly used by
65 // OutputPage to implement previewing of user CSS and JS.
66 // @todo: Remove it once we're sure nothing else is using the parameter
67 $excludepage = $context->getRequest()->getVal( 'excludepage' );
68 if ( isset( $pages[$excludepage] ) ) {
69 unset( $pages[$excludepage] );
70 }
71
72 return $pages;
73 }
74
75 /**
76 * @return string
77 */
78 public function getType() {
79 return self::LOAD_STYLES;
80 }
81
82 /**
83 * Get group name
84 *
85 * @return string
86 */
87 public function getGroup() {
88 return 'user';
89 }
90 }