| @@ 26-86 (lines=61) @@ | ||
| 23 | /** |
|
| 24 | * Module for user customizations scripts |
|
| 25 | */ |
|
| 26 | class ResourceLoaderUserModule extends ResourceLoaderWikiModule { |
|
| 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( 'AllowUserJs' ) ) { |
|
| 47 | $pages["$userPage/common.js"] = [ 'type' => 'script' ]; |
|
| 48 | $pages["$userPage/" . $context->getSkin() . '.js'] = [ 'type' => 'script' ]; |
|
| 49 | } |
|
| 50 | ||
| 51 | // User group pages are maintained site-wide and enabled with site JS/CSS. |
|
| 52 | if ( $config->get( 'UseSiteJs' ) ) { |
|
| 53 | foreach ( $user->getEffectiveGroups() as $group ) { |
|
| 54 | if ( $group == '*' ) { |
|
| 55 | continue; |
|
| 56 | } |
|
| 57 | $pages["MediaWiki:Group-$group.js"] = [ 'type' => 'script' ]; |
|
| 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 | * Get group name |
|
| 73 | * |
|
| 74 | * @return string |
|
| 75 | */ |
|
| 76 | public function getGroup() { |
|
| 77 | return 'user'; |
|
| 78 | } |
|
| 79 | ||
| 80 | /** |
|
| 81 | * @return array |
|
| 82 | */ |
|
| 83 | public function getDependencies( ResourceLoaderContext $context = null ) { |
|
| 84 | return [ 'user.styles' ]; |
|
| 85 | } |
|
| 86 | } |
|
| 87 | ||
| @@ 26-86 (lines=61) @@ | ||
| 23 | /** |
|
| 24 | * Module for user customizations styles |
|
| 25 | */ |
|
| 26 | class ResourceLoaderUserStylesModule extends ResourceLoaderWikiModule { |
|
| 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 | ||