Completed
Branch master (467086)
by
unknown
30:56
created

ResourceLoaderUserStylesModule::getGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 3
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 3
loc 3
rs 10
c 1
b 0
f 0
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 View Code Duplication
class ResourceLoaderUserStylesModule extends ResourceLoaderWikiModule {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
28
	protected $origin = self::ORIGIN_USER_INDIVIDUAL;
29
	protected $targets = [ 'desktop', 'mobile' ];
30
31
	/**
32
	 * @param ResourceLoaderContext $context
33
	 * @return array List of pages
34
	 */
35
	protected function getPages( ResourceLoaderContext $context ) {
36
		$config = $this->getConfig();
37
		$user = $context->getUserObj();
38
		if ( $user->isAnon() ) {
39
			return [];
40
		}
41
42
		// Use localised/normalised variant to ensure $excludepage matches
43
		$userPage = $user->getUserPage()->getPrefixedDBkey();
44
		$pages = [];
45
46
		if ( $config->get( 'AllowUserCss' ) ) {
47
			$pages["$userPage/common.css"] = [ 'type' => 'style' ];
48
			$pages["$userPage/" . $context->getSkin() . '.css'] = [ 'type' => 'style' ];
49
		}
50
51
		// User group pages are maintained site-wide and enabled with site JS/CSS.
52
		if ( $config->get( 'UseSiteCss' ) ) {
53
			foreach ( $user->getEffectiveGroups() as $group ) {
54
				if ( $group == '*' ) {
55
					continue;
56
				}
57
				$pages["MediaWiki:Group-$group.css"] = [ 'type' => 'style' ];
58
			}
59
		}
60
61
		// Hack for T28283: Allow excluding pages for preview on a CSS/JS page.
62
		// The excludepage parameter is set by OutputPage.
63
		$excludepage = $context->getRequest()->getVal( 'excludepage' );
64
		if ( isset( $pages[$excludepage] ) ) {
65
			unset( $pages[$excludepage] );
66
		}
67
68
		return $pages;
69
	}
70
71
	/**
72
	 * @return string
73
	 */
74
	public function getType() {
75
		return self::LOAD_STYLES;
76
	}
77
78
	/**
79
	 * Get group name
80
	 *
81
	 * @return string
82
	 */
83
	public function getGroup() {
84
		return 'user';
85
	}
86
}
87