FallbackSlotRoleHandler.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * This file is part of MediaWiki.
  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. namespace MediaWiki\Revision;
  23. use MediaWiki\Linker\LinkTarget;
  24. /**
  25. * A SlotRoleHandler for providing basic functionality for undefined slot roles.
  26. *
  27. * This class is intended to be used when encountering slots with a role that used to be defined
  28. * by an extension, but no longer is backed by hany specific handler, since the extension in
  29. * question has been uninstalled. It may also be used for pages imported from another wiki.
  30. *
  31. * @since 1.33
  32. */
  33. class FallbackSlotRoleHandler extends SlotRoleHandler {
  34. public function __construct( $role ) {
  35. // treat unknown content as plain text
  36. parent::__construct( $role, CONTENT_MODEL_TEXT );
  37. }
  38. /**
  39. * @param LinkTarget $page
  40. *
  41. * @return bool Always false, to prevent undefined slots from being used in new revisions.
  42. */
  43. public function isAllowedOn( LinkTarget $page ) {
  44. return false;
  45. }
  46. /**
  47. * @param string $model
  48. * @param LinkTarget $page
  49. *
  50. * @return bool Always false, to prevent undefined slots from being used for
  51. * arbitrary content.
  52. */
  53. public function isAllowedModel( $model, LinkTarget $page ) {
  54. return false;
  55. }
  56. public function getOutputLayoutHints() {
  57. // TODO: should be return [ 'display' => 'none'] here, causing undefined slots
  58. // to be hidden? We'd still need some place to surface the content of such
  59. // slots, see T209923.
  60. return parent::getOutputLayoutHints(); // TODO: Change the autogenerated stub
  61. }
  62. }