SlotDiffRenderer.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Renders a diff for a single slot.
  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 DifferenceEngine
  22. */
  23. /**
  24. * Renders a diff for a single slot (that is, a diff between two content objects).
  25. *
  26. * Callers should obtain this class by invoking ContentHandler::getSlotDiffRendererClass
  27. * on the content handler of the new content object (ie. the one shown on the right side
  28. * of the diff), or of the old one if the new one does not exist.
  29. *
  30. * The default implementation just does a text diff on the native text representation.
  31. * Content handler extensions can subclass this to provide a more appropriate diff method by
  32. * overriding ContentHandler::getSlotDiffRendererClass. Other extensions that want to interfere
  33. * with diff generation in some way can use the GetSlotDiffRenderer hook.
  34. *
  35. * @ingroup DifferenceEngine
  36. */
  37. abstract class SlotDiffRenderer {
  38. /**
  39. * Get a diff between two content objects. One of them might be null (meaning a slot was
  40. * created or removed), but both cannot be. $newContent (or if it's null then $oldContent)
  41. * must have the same content model that was used to obtain this diff renderer.
  42. * @param Content|null $oldContent
  43. * @param Content|null $newContent
  44. * @return string
  45. */
  46. abstract public function getDiff( Content $oldContent = null, Content $newContent = null );
  47. /**
  48. * Add modules needed for correct styling/behavior of the diff.
  49. * @param OutputPage $output
  50. */
  51. public function addModules( OutputPage $output ) {
  52. }
  53. /**
  54. * Return any extra keys to split the diff cache by.
  55. * @return array
  56. */
  57. public function getExtraCacheKeys() {
  58. return [];
  59. }
  60. }