Skip to content

Commit

Permalink
Add details and details summary macro (#126)
Browse files Browse the repository at this point in the history
* Add processors for "details" and "detailsummary" macros

Fixes
- #101
- #103

* Register macros

* Add new templates to README

---------

Co-authored-by: Robert Vogel <[email protected]>
  • Loading branch information
osnard and Robert Vogel authored Dec 5, 2024
1 parent 6b9adc9 commit 918eca3
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 7 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/Composer/_defaultpages/Template/Details
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{SimplePanel
|type=info
|title={{{headings|}}}
|body={{{cql|}}}
}}
6 changes: 6 additions & 0 deletions src/Composer/_defaultpages/Template/DetailsSummary
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{| class="mw-collapsible mw-collapsed wikitable"
! {{{title|}}}
|-
|
{{{body|}}}
|}
6 changes: 6 additions & 0 deletions src/Composer/_defaultpages/Template/Excerpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{| class="mw-collapsible mw-collapsed wikitable"
! {{{title|}}}
|-
|
{{{body|}}}
|}
8 changes: 7 additions & 1 deletion src/Converter/ConfluenceConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -251,6 +253,8 @@ private function runProcessors( $dom ) {
),
new StructuredMacroContenByLabel( $this->currentPageTitle ),
new ExpandMacro(),
new DetailsMacro(),
new DetailsSummaryMacro(),
new MacroAlign(),
new StructuredMacroJira(),
new StructuredMacroViewFile(
Expand Down Expand Up @@ -385,7 +389,9 @@ private function processMacro( $sender, $match, $dom, $xpath ) {
'align',
'pagetree',
'view-file',
'space-details'
'space-details',
'details',
'detailssummary',
]
) ) {
return;
Expand Down
27 changes: 27 additions & 0 deletions src/Converter/Processor/DetailsMacro.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace HalloWelt\MigrateConfluence\Converter\Processor;

/**
* <ac:structured-macro ac:name="details" ac:schema-version="1" ac:macro-id="...">
* <ac:parameter ac:name="id">control</ac:parameter>
* <ac:rich-text-body>
* <h3>Control details</h3>
* <table class="wrapped">
*/
class DetailsMacro extends ConvertMacroToTemplateBase {

/**
* @inheritDoc
*/
protected function getMacroName(): string {
return 'details';
}

/**
* @inheritDoc
*/
protected function getWikiTextTemplateName(): string {
return 'Details';
}
}
28 changes: 28 additions & 0 deletions src/Converter/Processor/DetailsSummaryMacro.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace HalloWelt\MigrateConfluence\Converter\Processor;

/**
* <ac:structured-macro ac:name="detailssummary" ac:schema-version="3" ac:macro-id="...">
* <ac:parameter ac:name="firstcolumn">...</ac:parameter>
* <ac:parameter ac:name="headings">...</ac:parameter>
* <ac:parameter ac:name="sortBy">Title</ac:parameter>
* <ac:parameter ac:name="cql">label = "..." and parent = currentContent ( )</ac:parameter>
* </ac:structured-macro>
*/
class DetailsSummaryMacro extends ConvertMacroToTemplateBase {

/**
* @inheritDoc
*/
protected function getMacroName(): string {
return 'detailssummary';
}

/**
* @inheritDoc
*/
protected function getWikiTextTemplateName(): string {
return 'DetailsSummary';
}
}
37 changes: 37 additions & 0 deletions tests/phpunit/Converter/Processor/DetailsMacroTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace HalloWelt\MigrateConfluence\Tests\Converter\Processor;

use DOMDocument;
use HalloWelt\MigrateConfluence\Converter\Processor\DetailsMacro;
use PHPUnit\Framework\TestCase;

class DetailsMacroTest extends TestCase {

/**
* @var string
*/
private $dir = '';

/**
* @covers HalloWelt\MigrateConfluence\Converter\Processor\DetailsMacro::process
* @return void
*/
public function testProcess() {
$this->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 );
}

}
37 changes: 37 additions & 0 deletions tests/phpunit/Converter/Processor/DetailsSummaryMacroTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace HalloWelt\MigrateConfluence\Tests\Converter\Processor;

use DOMDocument;
use HalloWelt\MigrateConfluence\Converter\Processor\DetailsSummaryMacro;
use PHPUnit\Framework\TestCase;

class DetailsSummaryMacroTest extends TestCase {

/**
* @var string
*/
private $dir = '';

/**
* @covers HalloWelt\MigrateConfluence\Converter\Processor\DetailsSummaryMacro::process
* @return void
*/
public function testProcess() {
$this->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 );
}

}
8 changes: 8 additions & 0 deletions tests/phpunit/data/details-macro-input.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<xml xmlns:ac="sample_namespace">
<ac:structured-macro ac:name="details">
<ac:parameter ac:name="id">Lorem</ac:parameter>
<ac:rich-text-body>
<h3>Ipsum dolor</h3>
</ac:rich-text-body>
</ac:structured-macro>
</xml>
9 changes: 9 additions & 0 deletions tests/phpunit/data/details-macro-output.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<xml xmlns:ac="sample_namespace">
{{Details###BREAK###
|id = Lorem###BREAK###
|body = ###BREAK###

<h3>Ipsum dolor</h3>
}}###BREAK###

</xml>
8 changes: 8 additions & 0 deletions tests/phpunit/data/detailssummary-macro-input.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<xml xmlns:ac="sample_namespace">
<ac:structured-macro ac:name="detailssummary">
<ac:parameter ac:name="firstcolumn">Col 1</ac:parameter>
<ac:parameter ac:name="headings">Heading 1, Heading 2, Heading 3, Heading 4</ac:parameter>
<ac:parameter ac:name="sortBy">Title</ac:parameter>
<ac:parameter ac:name="cql">label = "Label 1" and parent = currentContent ( )</ac:parameter>
</ac:structured-macro>
</xml>
9 changes: 9 additions & 0 deletions tests/phpunit/data/detailssummary-macro-output.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<xml xmlns:ac="sample_namespace">
{{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###

</xml>

0 comments on commit 918eca3

Please sign in to comment.