DifferenceEngineSlotDiffRenderer.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Adapter for turning a DifferenceEngine into a SlotDiffRenderer.
  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. * B/C adapter for turning a DifferenceEngine into a SlotDiffRenderer.
  25. * Before SlotDiffRenderer was introduced, getDiff() functionality was provided by DifferenceEngine
  26. * subclasses. Convert such a subclass into a SlotDiffRenderer.
  27. * @deprecated
  28. * @ingroup DifferenceEngine
  29. */
  30. class DifferenceEngineSlotDiffRenderer extends SlotDiffRenderer {
  31. /** @var DifferenceEngine */
  32. private $differenceEngine;
  33. public function __construct( DifferenceEngine $differenceEngine ) {
  34. $this->differenceEngine = clone $differenceEngine;
  35. // Set state to loaded. This should not matter to any of the methods invoked by
  36. // the adapter, but just in case a load does get triggered somehow, make sure it's a no-op.
  37. $fakeContent = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT )->makeEmptyContent();
  38. $this->differenceEngine->setContent( $fakeContent, $fakeContent );
  39. $this->differenceEngine->markAsSlotDiffRenderer();
  40. }
  41. /** @inheritDoc */
  42. public function getDiff( Content $oldContent = null, Content $newContent = null ) {
  43. $this->normalizeContents( $oldContent, $newContent );
  44. return $this->differenceEngine->generateContentDiffBody( $oldContent, $newContent );
  45. }
  46. public function addModules( OutputPage $output ) {
  47. $oldContext = null;
  48. if ( $output !== $this->differenceEngine->getOutput() ) {
  49. $oldContext = $this->differenceEngine->getContext();
  50. $newContext = new DerivativeContext( $oldContext );
  51. $newContext->setOutput( $output );
  52. $this->differenceEngine->setContext( $newContext );
  53. }
  54. $this->differenceEngine->showDiffStyle();
  55. if ( $oldContext ) {
  56. $this->differenceEngine->setContext( $oldContext );
  57. }
  58. }
  59. public function getExtraCacheKeys() {
  60. return $this->differenceEngine->getExtraCacheKeys();
  61. }
  62. }