ResourceLoaderUserStylesModule.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * Module for user customizations styles.
  24. *
  25. * @ingroup ResourceLoader
  26. * @internal
  27. */
  28. class ResourceLoaderUserStylesModule extends ResourceLoaderWikiModule {
  29. protected $origin = self::ORIGIN_USER_INDIVIDUAL;
  30. protected $targets = [ 'desktop', 'mobile' ];
  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. // Use localised/normalised variant to ensure $excludepage matches
  42. $userPage = $user->getUserPage()->getPrefixedDBkey();
  43. $pages = [];
  44. if ( $config->get( 'AllowUserCss' ) ) {
  45. $pages["$userPage/common.css"] = [ 'type' => 'style' ];
  46. $pages["$userPage/" . $context->getSkin() . '.css'] = [ 'type' => 'style' ];
  47. }
  48. // User group pages are maintained site-wide and enabled with site JS/CSS.
  49. if ( $config->get( 'UseSiteCss' ) ) {
  50. foreach ( $user->getEffectiveGroups() as $group ) {
  51. if ( $group == '*' ) {
  52. continue;
  53. }
  54. $pages["MediaWiki:Group-$group.css"] = [ 'type' => 'style' ];
  55. }
  56. }
  57. // This is obsolete since 1.32 (T112474). It was formerly used by
  58. // OutputPage to implement previewing of user CSS and JS.
  59. // @todo: Remove it once we're sure nothing else is using the parameter
  60. $excludepage = $context->getRequest()->getVal( 'excludepage' );
  61. if ( isset( $pages[$excludepage] ) ) {
  62. unset( $pages[$excludepage] );
  63. }
  64. return $pages;
  65. }
  66. /**
  67. * @return string
  68. */
  69. public function getType() {
  70. return self::LOAD_STYLES;
  71. }
  72. /**
  73. * Get group name
  74. *
  75. * @return string
  76. */
  77. public function getGroup() {
  78. return 'user';
  79. }
  80. }