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 23use MediaWiki\MediaWikiServices; 24 25/** 26 * Module for user customizations styles. 27 * 28 * @ingroup ResourceLoader 29 * @internal 30 */ 31class ResourceLoaderUserStylesModule extends ResourceLoaderWikiModule { 32 33 protected $origin = self::ORIGIN_USER_INDIVIDUAL; 34 protected $targets = [ 'desktop', 'mobile' ]; 35 36 /** 37 * @param ResourceLoaderContext $context 38 * @return array[] 39 */ 40 protected function getPages( ResourceLoaderContext $context ) { 41 $config = $this->getConfig(); 42 $user = $context->getUserObj(); 43 if ( $user->isAnon() ) { 44 return []; 45 } 46 47 // Use localised/normalised variant to ensure $excludepage matches 48 $userPage = $user->getUserPage()->getPrefixedDBkey(); 49 $pages = []; 50 51 if ( $config->get( 'AllowUserCss' ) ) { 52 $pages["$userPage/common.css"] = [ 'type' => 'style' ]; 53 $pages["$userPage/" . $context->getSkin() . '.css'] = [ 'type' => 'style' ]; 54 } 55 56 // User group pages are maintained site-wide and enabled with site JS/CSS. 57 if ( $config->get( 'UseSiteCss' ) ) { 58 $effectiveGroups = MediaWikiServices::getInstance()->getUserGroupManager() 59 ->getUserEffectiveGroups( $user ); 60 foreach ( $effectiveGroups as $group ) { 61 if ( $group == '*' ) { 62 continue; 63 } 64 $pages["MediaWiki:Group-$group.css"] = [ 'type' => 'style' ]; 65 } 66 } 67 68 // This is obsolete since 1.32 (T112474). It was formerly used by 69 // OutputPage to implement previewing of user CSS and JS. 70 // @todo: Remove it once we're sure nothing else is using the parameter 71 $excludepage = $context->getRequest()->getVal( 'excludepage' ); 72 unset( $pages[$excludepage] ); 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 'user'; 91 } 92} 93