Sophivorus has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/350013 )
Change subject: Properly transclude sections inside extension tags
......................................................................
Properly transclude sections inside extension tags
Bug: T163411
Change-Id: I92fdfdc83f5e4a93220c65981491825b3818bf8f
---
M LabeledSectionTransclusion.class.php
A lstParserTestsExt.txt
2 files changed, 97 insertions(+), 10 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/LabeledSectionTransclusion
refs/changes/13/350013/1
diff --git a/LabeledSectionTransclusion.class.php
b/LabeledSectionTransclusion.class.php
index f4ae2c6..dc00141 100644
--- a/LabeledSectionTransclusion.class.php
+++ b/LabeledSectionTransclusion.class.php
@@ -375,18 +375,30 @@
if ( $begin != '' ) {
// Find the begin node
$found = false;
- for ( ; $node; $node = $node->getNextSibling()
) {
- if ( $node->getName() != 'ext' ) {
- continue;
- }
- $parts = $node->splitExt();
- $parts = array_map( array( $newFrame,
'expand' ), $parts );
- if ( self::isSection( $parts['name'] )
) {
- if ( preg_match( $beginRegex,
$parts['attr'] ) ) {
- $found = true;
- break;
+ $queue = array( $node );
+ while ( $queue ) {
+ $node = array_shift( $queue );
+ if ( $node->getName() === 'ext' ) {
+ $parts = $node->splitExt();
+ $parts = array_map( array(
$newFrame, 'expand' ), $parts );
+ if ( self::isSection(
$parts['name'] ) ) {
+ if ( preg_match(
$beginRegex, $parts['attr'] ) ) {
+ $found = true;
+ break;
+ }
+ } else {
+ // If we're in an
extension tag (such as <poem> or <ref>), add the 'ext' nodes inside to the queue
+ $dom =
$parser->preprocessToDom( $parts['inner'] );
+ foreach (
$dom->getChildrenOfType( 'ext' )->node as $child ) {
+ $child = new
PPNode_DOM( $child );
+ $queue[] =
$child;
+ }
}
}
+ $next = $node->getNextSibling();
+ if ( $next ) {
+ $queue[] = $next;
+ }
}
if ( !$found || !$node ) {
break;
diff --git a/lstParserTestsExt.txt b/lstParserTestsExt.txt
new file mode 100644
index 0000000..1f9ecb0
--- /dev/null
+++ b/lstParserTestsExt.txt
@@ -0,0 +1,75 @@
+# Many MediaWiki extensions introduce their own tags, and extracting marked
sections from within them requires special DOM traversal.
+# These parser tests are designed to test proper transclusion of sections
within extension tags.
+# In order to run them, first install the Poem extension, that introduces the
<poem> tag.
+
+# Force the test runner to ensure LST and Poem are loaded
+!! hooks
+section
+poem
+!! endhooks
+
+!! functionhooks
+lst
+!! endfunctionhooks
+
+# Article with a poem
+!! article
+Poem
+!! text
+<section begin=poem /><poem><section begin=content />poem<section end=content
/></poem><section end=poem />
+!! endarticle
+
+!! test
+LST: Transclude a poem with #lst
+!! input
+{{#lst:Poem|poem}}
+!! result
+<div class="poem">
+<p>poem
+</p>
+</div>
+
+!! end
+
+!! test
+LST: Transclude only the content of a poem with #lst
+!! input
+{{#lst:Poem|content}}
+!! result
+<p>poem
+</p>
+!! end
+
+# Article with a nested poem
+# Nested poems never happen IRL, but some other extensions (like DebateTree)
do use nested tags
+# so it's important to ensure that transclusion from inside nested tags works
properly
+!! article
+Nested
+!! text
+<poem>a
+ <poem>
+ <section begin=poem /><poem><section begin=content
/>poem<section end=content /></poem><section end=poem />
+ </poem>
+</poem>
+!! endarticle
+
+!! test
+LST: Transclude a nested poem with #lst
+!! input
+{{#lst:Nested|poem}}
+!! result
+<div class="poem">
+<p>poem
+</p>
+</div>
+
+!! end
+
+!! test
+LST: Transclude only the content of a nested poem with #lst
+!! input
+{{#lst:Nested|content}}
+!! result
+<p>poem
+</p>
+!! end
--
To view, visit https://gerrit.wikimedia.org/r/350013
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I92fdfdc83f5e4a93220c65981491825b3818bf8f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/LabeledSectionTransclusion
Gerrit-Branch: master
Gerrit-Owner: Sophivorus <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits