From 918eca3af2b468c9ff03c8cd5d10a2b604f17d09 Mon Sep 17 00:00:00 2001 From: Robert Vogel <1201528+osnard@users.noreply.github.com> Date: Thu, 5 Dec 2024 07:56:29 +0100 Subject: [PATCH] Add details and details summary macro (#126) * Add processors for "details" and "detailsummary" macros Fixes - https://github.com/hallowelt/migrate-confluence/issues/101 - https://github.com/hallowelt/migrate-confluence/issues/103 * Register macros * Add new templates to README --------- Co-authored-by: Robert Vogel --- README.md | 18 ++++++--- src/Composer/_defaultpages/Template/Details | 5 +++ .../_defaultpages/Template/DetailsSummary | 6 +++ src/Composer/_defaultpages/Template/Excerpt | 6 +++ src/Converter/ConfluenceConverter.php | 8 +++- src/Converter/Processor/DetailsMacro.php | 27 ++++++++++++++ .../Processor/DetailsSummaryMacro.php | 28 ++++++++++++++ .../Converter/Processor/DetailsMacroTest.php | 37 +++++++++++++++++++ .../Processor/DetailsSummaryMacroTest.php | 37 +++++++++++++++++++ tests/phpunit/data/details-macro-input.xml | 8 ++++ tests/phpunit/data/details-macro-output.xml | 9 +++++ .../data/detailssummary-macro-input.xml | 8 ++++ .../data/detailssummary-macro-output.xml | 9 +++++ 13 files changed, 199 insertions(+), 7 deletions(-) create mode 100644 src/Composer/_defaultpages/Template/Details create mode 100644 src/Composer/_defaultpages/Template/DetailsSummary create mode 100644 src/Converter/Processor/DetailsMacro.php create mode 100644 src/Converter/Processor/DetailsSummaryMacro.php create mode 100644 tests/phpunit/Converter/Processor/DetailsMacroTest.php create mode 100644 tests/phpunit/Converter/Processor/DetailsSummaryMacroTest.php create mode 100644 tests/phpunit/data/details-macro-input.xml create mode 100644 tests/phpunit/data/details-macro-output.xml create mode 100644 tests/phpunit/data/detailssummary-macro-input.xml create mode 100644 tests/phpunit/data/detailssummary-macro-output.xml diff --git a/README.md b/README.md index d063a65..c5f2e60 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,10 @@ In confluence user spaces are protected. In MediaWiki this is not possible for n #### Included MediaWiki wikitext templates - `AttachmentsSectionEnd` - `AttachmentsSectionStart` +- `Details` +- `DetailsSummary` - `Excerpt` +- `ExcerptInclude` - `Info` - `InlineComment` - `Layout` @@ -105,12 +108,15 @@ Be aware that those files may be overwritten by the import if they already exist #### Required MediaWiki extensions The output generated by the tool contains certain elements that need additonal extensions to be enabled. -1. TemplateStyles -2. ParserFunctions -3. SimpleTasks (https://www.mediawiki.org/wiki/Extension:SimpleTasks) -4. Semantic MediaWiki -5. HeaderTabs -5. SubPageList (https://www.mediawiki.org/wiki/Extension:SubPageList) +1. [TemplateStyles](https://www.mediawiki.org/wiki/Extension:DateTimeTools) +2. [ParserFunctions] (https://www.mediawiki.org/wiki/Extension:DateTimeTools) +3. [DateTimeTools](https://www.mediawiki.org/wiki/Extension:DateTimeTools) +4. [Checklists](https://www.mediawiki.org/wiki/Extension:Checklists) +5. [SimpleTasks](https://www.mediawiki.org/wiki/Extension:SimpleTasks) +6. [EnhancedUploads](https://www.mediawiki.org/wiki/Extension:EnhancedUploads) +7. [Semantic MediaWiki](https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki) +8. [HeaderTabs](https://www.mediawiki.org/wiki/Extension:HeaderTabs) +9. [SubPageList](https://www.mediawiki.org/wiki/Extension:SubPageList) ### Manual post-import maintenance #### Cleanup Categories diff --git a/src/Composer/_defaultpages/Template/Details b/src/Composer/_defaultpages/Template/Details new file mode 100644 index 0000000..21ceff7 --- /dev/null +++ b/src/Composer/_defaultpages/Template/Details @@ -0,0 +1,5 @@ +{{SimplePanel +|type=info +|title={{{headings|}}} +|body={{{cql|}}} +}} \ No newline at end of file diff --git a/src/Composer/_defaultpages/Template/DetailsSummary b/src/Composer/_defaultpages/Template/DetailsSummary new file mode 100644 index 0000000..f15e86a --- /dev/null +++ b/src/Composer/_defaultpages/Template/DetailsSummary @@ -0,0 +1,6 @@ +{| class="mw-collapsible mw-collapsed wikitable" +! {{{title|}}} +|- +| +{{{body|}}} +|} \ No newline at end of file diff --git a/src/Composer/_defaultpages/Template/Excerpt b/src/Composer/_defaultpages/Template/Excerpt index e69de29..f15e86a 100644 --- a/src/Composer/_defaultpages/Template/Excerpt +++ b/src/Composer/_defaultpages/Template/Excerpt @@ -0,0 +1,6 @@ +{| class="mw-collapsible mw-collapsed wikitable" +! {{{title|}}} +|- +| +{{{body|}}} +|} \ No newline at end of file diff --git a/src/Converter/ConfluenceConverter.php b/src/Converter/ConfluenceConverter.php index 4125a6a..22d69b0 100644 --- a/src/Converter/ConfluenceConverter.php +++ b/src/Converter/ConfluenceConverter.php @@ -26,6 +26,8 @@ use HalloWelt\MigrateConfluence\Converter\Processor\ConvertTaskListMacro; use HalloWelt\MigrateConfluence\Converter\Processor\ConvertTipMacro; use HalloWelt\MigrateConfluence\Converter\Processor\ConvertWarningMacro; +use HalloWelt\MigrateConfluence\Converter\Processor\DetailsMacro; +use HalloWelt\MigrateConfluence\Converter\Processor\DetailsSummaryMacro; use HalloWelt\MigrateConfluence\Converter\Processor\Emoticon; use HalloWelt\MigrateConfluence\Converter\Processor\ExpandMacro; use HalloWelt\MigrateConfluence\Converter\Processor\Image; @@ -251,6 +253,8 @@ private function runProcessors( $dom ) { ), new StructuredMacroContenByLabel( $this->currentPageTitle ), new ExpandMacro(), + new DetailsMacro(), + new DetailsSummaryMacro(), new MacroAlign(), new StructuredMacroJira(), new StructuredMacroViewFile( @@ -385,7 +389,9 @@ private function processMacro( $sender, $match, $dom, $xpath ) { 'align', 'pagetree', 'view-file', - 'space-details' + 'space-details', + 'details', + 'detailssummary', ] ) ) { return; diff --git a/src/Converter/Processor/DetailsMacro.php b/src/Converter/Processor/DetailsMacro.php new file mode 100644 index 0000000..3268462 --- /dev/null +++ b/src/Converter/Processor/DetailsMacro.php @@ -0,0 +1,27 @@ + + * control + * + *

Control details

+ * + */ +class DetailsMacro extends ConvertMacroToTemplateBase { + + /** + * @inheritDoc + */ + protected function getMacroName(): string { + return 'details'; + } + + /** + * @inheritDoc + */ + protected function getWikiTextTemplateName(): string { + return 'Details'; + } +} diff --git a/src/Converter/Processor/DetailsSummaryMacro.php b/src/Converter/Processor/DetailsSummaryMacro.php new file mode 100644 index 0000000..f3b30eb --- /dev/null +++ b/src/Converter/Processor/DetailsSummaryMacro.php @@ -0,0 +1,28 @@ + + * ... + * ... + * Title + * label = "..." and parent = currentContent ( ) + * + */ +class DetailsSummaryMacro extends ConvertMacroToTemplateBase { + + /** + * @inheritDoc + */ + protected function getMacroName(): string { + return 'detailssummary'; + } + + /** + * @inheritDoc + */ + protected function getWikiTextTemplateName(): string { + return 'DetailsSummary'; + } +} diff --git a/tests/phpunit/Converter/Processor/DetailsMacroTest.php b/tests/phpunit/Converter/Processor/DetailsMacroTest.php new file mode 100644 index 0000000..75535cf --- /dev/null +++ b/tests/phpunit/Converter/Processor/DetailsMacroTest.php @@ -0,0 +1,37 @@ +dir = dirname( dirname( __DIR__ ) ) . '/data'; + + $input = file_get_contents( "$this->dir/details-macro-input.xml" ); + + $dom = new DOMDocument(); + $dom->loadXML( $input ); + + $processor = new DetailsMacro(); + $processor->process( $dom ); + + $actualOutput = $dom->saveXML( $dom->documentElement ); + $expectedOutput = file_get_contents( "$this->dir/details-macro-output.xml" ); + + $this->assertEquals( $expectedOutput, $actualOutput ); + } + +} diff --git a/tests/phpunit/Converter/Processor/DetailsSummaryMacroTest.php b/tests/phpunit/Converter/Processor/DetailsSummaryMacroTest.php new file mode 100644 index 0000000..4d2c57a --- /dev/null +++ b/tests/phpunit/Converter/Processor/DetailsSummaryMacroTest.php @@ -0,0 +1,37 @@ +dir = dirname( dirname( __DIR__ ) ) . '/data'; + + $input = file_get_contents( "$this->dir/detailssummary-macro-input.xml" ); + + $dom = new DOMDocument(); + $dom->loadXML( $input ); + + $processor = new DetailsSummaryMacro(); + $processor->process( $dom ); + + $actualOutput = $dom->saveXML( $dom->documentElement ); + $expectedOutput = file_get_contents( "$this->dir/detailssummary-macro-output.xml" ); + + $this->assertEquals( $expectedOutput, $actualOutput ); + } + +} diff --git a/tests/phpunit/data/details-macro-input.xml b/tests/phpunit/data/details-macro-input.xml new file mode 100644 index 0000000..58a3801 --- /dev/null +++ b/tests/phpunit/data/details-macro-input.xml @@ -0,0 +1,8 @@ + + + Lorem + +

Ipsum dolor

+
+
+
\ No newline at end of file diff --git a/tests/phpunit/data/details-macro-output.xml b/tests/phpunit/data/details-macro-output.xml new file mode 100644 index 0000000..6352641 --- /dev/null +++ b/tests/phpunit/data/details-macro-output.xml @@ -0,0 +1,9 @@ + + {{Details###BREAK### + |id = Lorem###BREAK### + |body = ###BREAK### + +

Ipsum dolor

+ }}###BREAK### + +
\ No newline at end of file diff --git a/tests/phpunit/data/detailssummary-macro-input.xml b/tests/phpunit/data/detailssummary-macro-input.xml new file mode 100644 index 0000000..1e6c674 --- /dev/null +++ b/tests/phpunit/data/detailssummary-macro-input.xml @@ -0,0 +1,8 @@ + + + Col 1 + Heading 1, Heading 2, Heading 3, Heading 4 + Title + label = "Label 1" and parent = currentContent ( ) + + \ No newline at end of file diff --git a/tests/phpunit/data/detailssummary-macro-output.xml b/tests/phpunit/data/detailssummary-macro-output.xml new file mode 100644 index 0000000..876a886 --- /dev/null +++ b/tests/phpunit/data/detailssummary-macro-output.xml @@ -0,0 +1,9 @@ + + {{DetailsSummary###BREAK### + |firstcolumn = Col 1###BREAK### + |headings = Heading 1, Heading 2, Heading 3, Heading 4###BREAK### + |sortBy = Title###BREAK### + |cql = label = "Label 1" and parent = currentContent ( )###BREAK### +}}###BREAK### + + \ No newline at end of file