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
|
|
|
|
|
*/
|
|
|
|
|
|
2022-05-06 09:09:56 +00:00
|
|
|
namespace MediaWiki\ResourceLoader;
|
|
|
|
|
|
2022-04-26 15:48:03 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2021-07-01 10:32:24 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-09-18 13:56:39 +00:00
|
|
|
use MediaWiki\Title\TitleValue;
|
2021-07-01 10:32:24 +00:00
|
|
|
|
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
|
|
|
*/
|
2022-05-06 09:09:56 +00:00
|
|
|
class UserModule extends WikiModule {
|
2011-02-04 16:39:17 +00:00
|
|
|
protected $origin = self::ORIGIN_USER_INDIVIDUAL;
|
2010-10-19 18:25:42 +00:00
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
2022-05-06 09:09:56 +00:00
|
|
|
* @param Context $context
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return array[]
|
2011-05-21 17:45:20 +00:00
|
|
|
*/
|
2022-05-06 09:09:56 +00:00
|
|
|
protected function getPages( Context $context ) {
|
2021-10-26 20:34:00 +00:00
|
|
|
$user = $context->getUserIdentity();
|
|
|
|
|
if ( !$user || !$user->isRegistered() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [];
|
2012-04-09 08:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-26 20:34:00 +00:00
|
|
|
$config = $this->getConfig();
|
2016-02-17 09:09:32 +00:00
|
|
|
$pages = [];
|
2016-05-10 19:47:04 +00:00
|
|
|
|
2022-04-26 15:48:03 +00:00
|
|
|
if ( $config->get( MainConfigNames::AllowUserJs ) ) {
|
2021-10-26 20:34:00 +00:00
|
|
|
$titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
|
|
|
|
|
// Use localised/normalised variant to ensure $excludepage matches
|
|
|
|
|
$userPage = $titleFormatter->getPrefixedDBkey( new TitleValue( NS_USER, $user->getName() ) );
|
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.
|
2022-04-26 15:48:03 +00:00
|
|
|
if ( $config->get( MainConfigNames::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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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() {
|
2022-01-12 14:34:02 +00:00
|
|
|
return self::GROUP_USER;
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-05-06 09:09:56 +00:00
|
|
|
|
|
|
|
|
/** @deprecated since 1.39 */
|
|
|
|
|
class_alias( UserModule::class, 'ResourceLoaderUserModule' );
|