ResourceLoaderJqueryMsgModule.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * ResourceLoader module for mediawiki.jqueryMsg that provides generated data.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. */
  22. /**
  23. * ResourceLoader module for mediawiki.jqueryMsg and its generated data
  24. */
  25. class ResourceLoaderJqueryMsgModule extends ResourceLoaderFileModule {
  26. /**
  27. * @param ResourceLoaderContext $context
  28. * @return string JavaScript code
  29. */
  30. public function getScript( ResourceLoaderContext $context ) {
  31. $fileScript = parent::getScript( $context );
  32. $tagData = Sanitizer::getRecognizedTagData();
  33. $allowedHtmlElements = array_merge(
  34. array_keys( $tagData['htmlpairs'] ),
  35. array_diff(
  36. array_keys( $tagData['htmlsingle'] ),
  37. array_keys( $tagData['htmlsingleonly'] )
  38. )
  39. );
  40. $magicWords = [
  41. 'SITENAME' => $this->getConfig()->get( 'Sitename' ),
  42. ];
  43. Hooks::run( 'ResourceLoaderJqueryMsgModuleMagicWords', [ $context, &$magicWords ] );
  44. $parserDefaults = [
  45. 'allowedHtmlElements' => $allowedHtmlElements,
  46. 'magic' => $magicWords,
  47. ];
  48. $setDataScript = Xml::encodeJsCall( 'mw.jqueryMsg.setParserDefaults', [
  49. $parserDefaults,
  50. // Pass deep=true because mediawiki.jqueryMsg.js contains
  51. // page-specific magic words that must not be overwritten.
  52. true,
  53. ] );
  54. return $fileScript . $setDataScript;
  55. }
  56. /**
  57. * @param ResourceLoaderContext $context
  58. * @return array
  59. */
  60. public function getScriptURLsForDebug( ResourceLoaderContext $context ) {
  61. // Bypass file module urls
  62. return ResourceLoaderModule::getScriptURLsForDebug( $context );
  63. }
  64. /**
  65. * @return bool
  66. */
  67. public function enableModuleContentVersion() {
  68. return true;
  69. }
  70. }