2010-10-19 18:25:42 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @author Trevor Parscal
|
|
|
|
|
* @author Roan Kattouw
|
|
|
|
|
*/
|
|
|
|
|
|
2021-07-01 10:32:24 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
|
2010-10-19 18:25:42 +00:00
|
|
|
/**
|
2019-09-14 04:32:54 +00:00
|
|
|
* Module for user customizations scripts.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup ResourceLoader
|
|
|
|
|
* @internal
|
2010-10-19 18:25:42 +00:00
|
|
|
*/
|
|
|
|
|
class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
|
2011-02-04 16:39:17 +00:00
|
|
|
protected $origin = self::ORIGIN_USER_INDIVIDUAL;
|
2016-05-10 19:47:04 +00:00
|
|
|
protected $targets = [ 'desktop', 'mobile' ];
|
2010-10-19 18:25:42 +00:00
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return array[]
|
2011-05-21 17:45:20 +00:00
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
protected function getPages( ResourceLoaderContext $context ) {
|
2016-05-10 19:47:04 +00:00
|
|
|
$config = $this->getConfig();
|
2015-03-01 15:25:39 +00:00
|
|
|
$user = $context->getUserObj();
|
2021-10-23 19:27:44 +00:00
|
|
|
if ( !$user->isRegistered() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [];
|
2012-04-09 08:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-10 19:47:04 +00:00
|
|
|
// Use localised/normalised variant to ensure $excludepage matches
|
2015-03-01 15:25:39 +00:00
|
|
|
$userPage = $user->getUserPage()->getPrefixedDBkey();
|
2016-02-17 09:09:32 +00:00
|
|
|
$pages = [];
|
2016-05-10 19:47:04 +00:00
|
|
|
|
|
|
|
|
if ( $config->get( 'AllowUserJs' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$pages["$userPage/common.js"] = [ 'type' => 'script' ];
|
|
|
|
|
$pages["$userPage/" . $context->getSkin() . '.js'] = [ 'type' => 'script' ];
|
2013-04-03 20:50:08 +00:00
|
|
|
}
|
2016-05-10 19:47:04 +00:00
|
|
|
|
|
|
|
|
// User group pages are maintained site-wide and enabled with site JS/CSS.
|
2016-07-26 23:54:30 +00:00
|
|
|
if ( $config->get( 'UseSiteJs' ) ) {
|
2021-07-01 10:32:24 +00:00
|
|
|
$userGroupManager = MediaWikiServices::getInstance()->getUserGroupManager();
|
|
|
|
|
foreach ( $userGroupManager->getUserEffectiveGroups( $user ) as $group ) {
|
2016-05-10 19:47:04 +00:00
|
|
|
if ( $group == '*' ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-07-26 23:54:30 +00:00
|
|
|
$pages["MediaWiki:Group-$group.js"] = [ 'type' => 'script' ];
|
2016-05-10 19:47:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 20:52:17 +00:00
|
|
|
// This is obsolete since 1.32 (T112474). It was formerly used by
|
|
|
|
|
// OutputPage to implement previewing of user CSS and JS.
|
|
|
|
|
// @todo: Remove it once we're sure nothing else is using the parameter
|
2012-04-09 08:30:50 +00:00
|
|
|
$excludepage = $context->getRequest()->getVal( 'excludepage' );
|
2020-11-10 15:52:14 +00:00
|
|
|
unset( $pages[$excludepage] );
|
2016-05-10 19:47:04 +00:00
|
|
|
|
2012-04-09 08:30:50 +00:00
|
|
|
return $pages;
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
2011-05-21 17:45:20 +00:00
|
|
|
|
|
|
|
|
/**
|
2014-10-21 00:43:26 +00:00
|
|
|
* Get group name
|
|
|
|
|
*
|
2011-05-21 17:45:20 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getGroup() {
|
|
|
|
|
return 'user';
|
|
|
|
|
}
|
|
|
|
|
}
|