ResourceLoaderUserOptionsModule.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 preferences.
  24. *
  25. * @ingroup ResourceLoader
  26. * @internal
  27. */
  28. class ResourceLoaderUserOptionsModule extends ResourceLoaderModule {
  29. protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
  30. protected $targets = [ 'desktop', 'mobile' ];
  31. /**
  32. * @param ResourceLoaderContext|null $context
  33. * @return array List of module names as strings
  34. */
  35. public function getDependencies( ResourceLoaderContext $context = null ) {
  36. return [ 'user.defaults' ];
  37. }
  38. /**
  39. * @return bool
  40. */
  41. public function enableModuleContentVersion() {
  42. return true;
  43. }
  44. /**
  45. * @param ResourceLoaderContext $context
  46. * @return string JavaScript code
  47. */
  48. public function getScript( ResourceLoaderContext $context ) {
  49. // Use FILTER_NOMIN annotation to prevent needless minification and caching (T84960).
  50. return ResourceLoader::FILTER_NOMIN
  51. . 'mw.user.options.set('
  52. . $context->encodeJson(
  53. $context->getUserObj()->getOptions( User::GETOPTIONS_EXCLUDE_DEFAULTS )
  54. )
  55. . ');';
  56. }
  57. /**
  58. * @return bool
  59. */
  60. public function supportsURLLoading() {
  61. return false;
  62. }
  63. /**
  64. * @param ResourceLoaderContext $context
  65. * @return bool
  66. */
  67. public function isKnownEmpty( ResourceLoaderContext $context ) {
  68. return !$context->getUserObj()->getOptions( User::GETOPTIONS_EXCLUDE_DEFAULTS );
  69. }
  70. /**
  71. * @return string
  72. */
  73. public function getGroup() {
  74. return 'private';
  75. }
  76. }