ResourceLoaderUserModule.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 scripts.
  24. *
  25. * @ingroup ResourceLoader
  26. * @internal
  27. */
  28. class ResourceLoaderUserModule 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( 'AllowUserJs' ) ) {
  45. $pages["$userPage/common.js"] = [ 'type' => 'script' ];
  46. $pages["$userPage/" . $context->getSkin() . '.js'] = [ 'type' => 'script' ];
  47. }
  48. // User group pages are maintained site-wide and enabled with site JS/CSS.
  49. if ( $config->get( 'UseSiteJs' ) ) {
  50. foreach ( $user->getEffectiveGroups() as $group ) {
  51. if ( $group == '*' ) {
  52. continue;
  53. }
  54. $pages["MediaWiki:Group-$group.js"] = [ 'type' => 'script' ];
  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. * Get group name
  68. *
  69. * @return string
  70. */
  71. public function getGroup() {
  72. return 'user';
  73. }
  74. }