CodeContentHandler.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Content handler for the pages with code, such as CSS, JavaScript, JSON.
  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. * @ingroup Content
  22. */
  23. /**
  24. * Content handler for code content such as CSS, JavaScript, JSON, etc
  25. * @since 1.24
  26. * @ingroup Content
  27. */
  28. abstract class CodeContentHandler extends TextContentHandler {
  29. /**
  30. * Returns the English language, because code is English, and should be handled as such.
  31. *
  32. * @param Title $title
  33. * @param Content|null $content
  34. *
  35. * @return Language
  36. *
  37. * @see ContentHandler::getPageLanguage()
  38. */
  39. public function getPageLanguage( Title $title, Content $content = null ) {
  40. return Language::factory( 'en' );
  41. }
  42. /**
  43. * Returns the English language, because code is English, and should be handled as such.
  44. *
  45. * @param Title $title
  46. * @param Content|null $content
  47. *
  48. * @return Language
  49. *
  50. * @see ContentHandler::getPageViewLanguage()
  51. */
  52. public function getPageViewLanguage( Title $title, Content $content = null ) {
  53. return Language::factory( 'en' );
  54. }
  55. /**
  56. * @return string
  57. * @throws MWException
  58. */
  59. protected function getContentClass() {
  60. throw new MWException( 'Subclass must override' );
  61. }
  62. }